/
plugin-tooltip.ts
50 lines (46 loc) · 1.18 KB
/
plugin-tooltip.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Graph } from '@/src';
import data from '@@/dataset/cluster.json';
import { isObject } from '@antv/util';
import type { STDTestCase } from '../types';
export const pluginTooltip: STDTestCase = async (context) => {
const graph = new Graph({
...context,
autoResize: true,
data,
layout: { type: 'd3force' },
behaviors: ['drag-canvas', 'drag-element'],
node: {
style: {
labelText: (d) => d.id,
},
},
plugins: [
{
type: 'tooltip',
getContent: (evt: any, { items }: { items: any[] }) => {
return `<div>${items[0].id}</div>`;
},
},
],
});
await graph.render();
pluginTooltip.form = (panel) => {
const config = {
trigger: 'pointerenter',
};
return [
panel
.add(config, 'trigger', ['pointerenter', 'click'])
.name('Change Trigger Method')
.onChange((trigger: string) => {
graph.setPlugins((plugins) =>
plugins.map((plugin) => {
if (isObject(plugin) && plugin.type === 'tooltip') return { ...plugin, trigger };
return plugin;
}),
);
}),
];
};
return graph;
};