tooltip插件不能在getContent返回null或undefined时不显示 #5969
sinres624318 posted onGitHub
AntV Open Source Contribution Plan(可选/Optional)
- 我同意将这个 Issue 参与 OSCP 计划 / I agree to participate in the OSCP plan
Issue 类型 / Issue Type
中级任务 / Intermediate Task
任务介绍 / Task Description
在getContent返回null或undefined时不显示tooltip enable在判断e.targetType的时候tooltip总是显示,改为鼠标移出隐藏tooltip也可以
参考说明 / Reference Description
const graph = new Graph({
container: chartRef.current,
layout: {
type: 'dagre',
rankdir: 'LR',
align: 'UL',
controlPoints: true,
nodesepFunc: () => 1,
ranksepFunc: () => 1
},
node: {
type: 'rect',
style: {
size: [100, 30],
fill: 'skyblue',
labelPlacement: 'center',
labelText: (d) => d.label,
labelFill: '#fff'
}
},
data,
edge: {
type: 'polyline',
size: 1,
color: '#e2e2e2',
style: {
endArrow: {
path: 'M 0,0 L 8,4 L 8,-4 Z',
fill: '#e2e2e2'
},
radius: 10
}
},
behaviors: ['drag-canvas', 'zoom-canvas'],
plugins: [
{
type: 'tooltip',
getContent: (e, items) => {
if(e.targetType!=='node')return null
const title = <div>${items[0].label}</div>
const content = items.map((item, i) => {
return <div key={i}>
<div>
<span>时间</span>
<span>${item.time}s</span>
</div>
</div>
})
return ${title}${content}
}
}
]
} as any)
graph.render()