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

feat(interaction): add scrollbarFilter #5152

Merged
merged 1 commit into from
Jun 2, 2023
Merged

Conversation

pearmini
Copy link
Member

@pearmini pearmini commented Jun 2, 2023

Scrollbar Filter

添加 Scrollbar 交互,并且抛出数据和支持手动触发。

srollbar-filter

开始使用

const chart = new Chart({
  theme: 'classic',
  paddingBottom: 120,
  width: 400,
});

chart
  .interval()
  .data([
    { date: '2001-01', value: 100 },
    { date: '2001-02', value: 400 },
    { date: '2001-03', value: 500 },
    { date: '2001-04', value: 600 },
    { date: '2001-05', value: 300 },
    { date: '2001-06', value: 600 },
    { date: '2001-07', value: 300 },
    { date: '2001-08', value: 600 },
    { date: '2001-09', value: 109 },
    { date: '2001-10', value: 100 },
    { date: '2001-11', value: 102 },
    { date: '2001-12', value: 103 },
    { date: '2002-01', value: 102 },
    { date: '2002-02', value: 101 },
    { date: '2002-03', value: 200 },
    { date: '2002-04', value: 500 },
    { date: '2002-05', value: 100 },
    { date: '2002-06', value: 100 },
    { date: '2002-07', value: 102 },
    { date: '2002-08', value: 109 },
  ])
  .encode('x', 'date')
  .encode('y', 'value')
  .axis('x', { size: 80, style: { labelTransform: 'rotate(90deg)' } })
  .scrollbar('x', { ratio: 0.25 }) // 通过 ratio 去指定暂时的数据范围,范围 [0,1]
  .scrollbar('y', { ratio: 0.75 }); // 通过 ratio 去指定暂时的数据范围,范围 [0,1]

chart.render();

触发事件

chart.emit('scrollbarX:filter', {
  data: { selection: [['2001-03'], undefined] },
});

chart.emit('scrollbarY:filter', {
  data: { selection: [undefined, [50, 550]] },
});

监听数据

chart.on('scrollbarX:filter', (event) => {
  const { data, nativeEvent } = event;
  if (nativeEvent) console.log('scrollbarX:filter', data.selection);
});

chart.on('scrollbarY:filter', (event) => {
  const { data, nativeEvent } = event;
  if (nativeEvent) console.log('scrollbarY:filter', data.selection);
});

TODO

  • 代码
  • 文档
  • 测试

@pearmini pearmini merged commit 72e0cc4 into v5 Jun 2, 2023
3 checks passed
@pearmini pearmini deleted the feat/scroll-interaction branch June 2, 2023 15:09
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

2 participants