Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(legend): 修复存在legend过大导致layout异常问题 #5945

Merged
merged 1 commit into from
Dec 18, 2023
Merged

fix(legend): 修复存在legend过大导致layout异常问题 #5945

merged 1 commit into from
Dec 18, 2023

Conversation

BENcorry
Copy link
Contributor

@BENcorry BENcorry commented Dec 17, 2023

Checklist
  • npm test passes
  • benchmarks are included
  • commit message follows commit guidelines
  • documents are updated
Description of change
解决问题

图例定位左侧后maxRows失效,maxCol显示有问题 #5724

解决办法

导致问题产生的原因有两个:

  1. Legend ellipsis 是因为计算宽度的时候没有加上对应的padding值。这个修改计算逻辑加上padding即可。
  2. Legend由于量太多导致计算出来的高度大于innerHeight。计算的bbox位置和大小基本是没问题的,所以只要统一一下flex布局即可
Case
/**
 * A recreation of this demo: https://observablehq.com/@d3/bar-chart
 */
import { Chart } from '@antv/g2';

const chart = new Chart({
  container: 'container',
});

chart.title({
  title: 'Population by age and state',
  subtitle: 'It shows the population of U.S. by age and state.',
});

chart
  .interval()
  .data({
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/bmw-prod/f129b517-158d-41a9-83a3-3294d639b39e.csv',
    format: 'csv',
  })
  .transform({ type: 'dodgeX' })
  .encode('x', 'age')
  .encode('y', 'population')
  .encode('color', 'state')
  .scale('y', { nice: true })
  .axis('y', { labelFormatter: '~s' })
  .legend('color',{
    position:'left',
    maxCols: 3,
  })

chart
  .interaction('tooltip', { shared: true })
  .interaction('elementHighlightByColor', { background: true });

chart.render();
修复前
image
修复后
image

Copy link
Member

@pearmini pearmini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非常优秀!🚀🚀🚀

src/component/utils.ts Show resolved Hide resolved
@pearmini pearmini merged commit e4ac450 into antvis:v5 Dec 18, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants