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

【v5】Tooltip 无法展示 falsy 值 #4891

Closed
Deathsteps opened this issue Apr 17, 2023 · 2 comments · Fixed by #4907
Closed

【v5】Tooltip 无法展示 falsy 值 #4891

Deathsteps opened this issue Apr 17, 2023 · 2 comments · Fixed by #4907
Assignees

Comments

@Deathsteps
Copy link
Contributor

问题描述

tooltip 无法展示 falsy 值(null, undefined, 0)都不显示

image

image

期望结果

至少应该显示 0 值,null, undefined 在数据表中也是有意义的,也应该显示。

如何重现

G2 V5 版本,官方示例改了一下数据

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

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


const data = [
  {
    city: '杭州',
    value: 400,
  },
  {
    city: '上海',
    value: 200,
  },
  {
    city: '北京',
    value: 100,
  },
  {
    city: '河北',
    value: 0,
  },
  {
    city: '苏州',
    value: 500,
  },
  {
    city: '海南',
    value: 200,
  },
]

chart
  .line()
  .data(data)
  .encode('x', 'city')
  .encode('y', 'value')
  .axis('y');

chart.render();
chart.interaction('tooltip', true)

额外信息

  • G2 5.0.3
@pearmini pearmini self-assigned this Apr 17, 2023
@pearmini
Copy link
Member

目前确实过滤了 falsy 的值,的确是不合理的,更好的做法是让用户能显示地指定什么是 falsy 的值。

// 只有 d.value 大于 10 的时候才展示
chart.interaction("tooltip", { defined: d => d.value > 10 }); 

@Deathsteps
Copy link
Contributor Author

目前确实过滤了 falsy 的值,的确是不合理的,更好的做法是让用户能显示地指定什么是 falsy 的值。

// 只有 d.value 大于 10 的时候才展示
chart.interaction("tooltip", { defined: d => d.value > 10 }); 

个人观点,从 tooltip 功能的角度讲,如实显示就行了,如果有定制需求,要么用值函数,要么就直接自定义 render。tooltip 本身配置项简单点更好维护。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants