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(tooltip): on and emit #4980

Merged
merged 1 commit into from
May 10, 2023
Merged

feat(tooltip): on and emit #4980

merged 1 commit into from
May 10, 2023

Conversation

pearmini
Copy link
Member

@pearmini pearmini commented May 10, 2023

Tooltip

手动触发 Tooltip 和抛出数据。

获得提示数据

chart.on('tooltip:show', (event) => {
  console.log(event.data.data);
});

chart.on('tooltip:hide', () => {
  console.log('hide');
});

手动控制展示/隐藏

对于 Interval、Point 等非系列 Mark,控制展示的方式如下:

// 条形图、点图等
chart
  .interval()
  .data([
    { genre: 'Sports', sold: 275 },
    { genre: 'Strategy', sold: 115 },
    { genre: 'Action', sold: 120 },
    { genre: 'Shooter', sold: 350 },
    { genre: 'Other', sold: 150 },
  ])
  .encode('x', 'genre')
  .encode('y', 'sold')
  .encode('color', 'genre');

chart.render().then((chart) =>
  chart.emit('tooltip:show', {
    data: {
      data: { genre: 'Sports' },
    },
  }),
);

对于 Line、Area 等系列 Mark,控制展示的方式如下:

chart
  .line()
  .data({ type: 'fetch', value: 'data/aapl.csv' })
  .encode('x', 'date')
  .encode('y', 'close');

chart.render().then((chart) =>
  chart.emit('tooltip:show', {
    data: {
      data: { x: new Date('2010-11-16') },
    },
  }),
);

隐藏的方式如下:

chart.emit('tooltip:hide');

@pearmini pearmini changed the title feat(tooltip): on and emit [WIP] feat(tooltip): on and emit May 10, 2023
@pearmini
Copy link
Member Author

pearmini commented May 10, 2023

饼图或者使用了 transform 的还需要处理一下。

@pearmini pearmini changed the title [WIP] feat(tooltip): on and emit feat(tooltip): on and emit May 10, 2023
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.

【V5】showTooltip 不生效,如何通过事件控制 Tooltip 的显隐
2 participants