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: label formatter callback params #5062

Merged
merged 1 commit into from
May 23, 2023
Merged

Conversation

pepper-nice
Copy link
Contributor

@pepper-nice pepper-nice commented May 19, 2023

ref: #5069

描述

label formatter 函数传入更多参数供业务层识别。

import { Chart } from '@antv/g2';

const chart = new Chart({
  container: 'container',
  theme: 'classic',
  autoFit: true,
});

chart
  .interval()
  .data({
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/bmw-prod/f129b517-158d-41a9-83a3-3294d639b39e.csv',
    format: 'csv',
  })
  .transform({ type: 'stackY' })
  .transform({ type: 'sortX', by: 'y', reverse: true })
  .encode('x', 'state')
  .encode('y', 'population')
  .encode('color', 'age')
  .axis('x', {
    labelSpacing: 4,
    style: {
      labelTransform: 'rotate(90)',
    },
  })
  .axis('y', { labelFormatter: '~s' })
  .label({
    text: 'population',
    formatter: (value, datum, index) => {
      // 1. 根据 index 匹配 formattedData
      // 2. 根据 data 信息得到不同数据的 formatter
    }
  });

chart.render();

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.

加测试和文档。

@hustcc
Copy link
Member

hustcc commented May 22, 2023

axis、legend、slider、scrollbar、tooltip 等组件都改成同样的签名吧。

formatter: (text, datum, idx, data) => string;

可以先检查一下,然后可以分多个 pr 搞吧~

@pepper-nice pepper-nice force-pushed the fix/label-formatter-callback branch from 369f2ec to 4de7a77 Compare May 23, 2023 02:25
@hustcc hustcc merged commit 1ee4b1f into v5 May 23, 2023
3 checks passed
@hustcc hustcc deleted the fix/label-formatter-callback branch May 23, 2023 03:10
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.

None yet

3 participants