@antv/g6 5.0.0-beta.31 → 5.0.0-beta.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/g6.min.js +2 -2
- package/dist/lib/behaviors/collapse-expand.d.ts +4 -5
- package/dist/lib/behaviors/create-edge.d.ts +55 -0
- package/dist/lib/behaviors/drag-canvas.d.ts +6 -6
- package/dist/lib/behaviors/drag-element.d.ts +5 -3
- package/dist/lib/behaviors/focus-element.d.ts +4 -3
- package/dist/lib/behaviors/hover-element.d.ts +4 -5
- package/dist/lib/behaviors/index.d.ts +2 -0
- package/dist/lib/behaviors/zoom-canvas.d.ts +7 -6
- package/dist/lib/constants/events/graph.d.ts +5 -13
- package/dist/lib/constants/index.d.ts +1 -0
- package/dist/lib/constants/registry.d.ts +20 -0
- package/dist/lib/elements/combos/base-combo.d.ts +21 -0
- package/dist/lib/elements/edges/base-edge.d.ts +21 -0
- package/dist/lib/elements/nodes/base-node.d.ts +22 -1
- package/dist/lib/exports.d.ts +16 -14
- package/dist/lib/plugins/camera-setting.d.ts +95 -0
- package/dist/lib/plugins/contextmenu.d.ts +8 -5
- package/dist/lib/plugins/index.d.ts +4 -0
- package/dist/lib/plugins/legend.d.ts +49 -0
- package/dist/lib/plugins/tooltip.d.ts +12 -10
- package/dist/lib/registry/extension/index.d.ts +2 -2
- package/dist/lib/registry/index.d.ts +6 -4
- package/dist/lib/registry/types.d.ts +0 -6
- package/dist/lib/runtime/canvas.d.ts +2 -1
- package/dist/lib/runtime/data.d.ts +1 -1
- package/dist/lib/runtime/element.d.ts +4 -5
- package/dist/lib/runtime/graph.d.ts +31 -4
- package/dist/lib/runtime/plugin.d.ts +1 -0
- package/dist/lib/types/event.d.ts +42 -7
- package/dist/lib/types/index.d.ts +0 -1
- package/dist/lib/utils/bbox.d.ts +1 -1
- package/dist/lib/utils/element.d.ts +19 -11
- package/dist/lib/utils/event/events.d.ts +8 -13
- package/dist/lib/utils/shortcut.d.ts +10 -0
- package/esm/behaviors/collapse-expand.d.ts +4 -5
- package/esm/behaviors/collapse-expand.js +8 -4
- package/esm/behaviors/collapse-expand.js.map +1 -1
- package/esm/behaviors/create-edge.d.ts +55 -0
- package/esm/behaviors/create-edge.js +141 -0
- package/esm/behaviors/create-edge.js.map +1 -0
- package/esm/behaviors/drag-canvas.d.ts +6 -6
- package/esm/behaviors/drag-canvas.js +15 -7
- package/esm/behaviors/drag-canvas.js.map +1 -1
- package/esm/behaviors/drag-element.d.ts +5 -3
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/focus-element.d.ts +4 -3
- package/esm/behaviors/focus-element.js.map +1 -1
- package/esm/behaviors/hover-element.d.ts +4 -5
- package/esm/behaviors/hover-element.js.map +1 -1
- package/esm/behaviors/index.d.ts +2 -0
- package/esm/behaviors/index.js +1 -0
- package/esm/behaviors/index.js.map +1 -1
- package/esm/behaviors/zoom-canvas.d.ts +7 -6
- package/esm/behaviors/zoom-canvas.js +6 -2
- package/esm/behaviors/zoom-canvas.js.map +1 -1
- package/esm/constants/events/graph.d.ts +5 -13
- package/esm/constants/events/graph.js +4 -12
- package/esm/constants/events/graph.js.map +1 -1
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +1 -0
- package/esm/constants/index.js.map +1 -1
- package/esm/constants/registry.d.ts +20 -0
- package/esm/constants/registry.js +22 -0
- package/esm/constants/registry.js.map +1 -0
- package/esm/elements/combos/base-combo.d.ts +21 -0
- package/esm/elements/combos/base-combo.js +21 -0
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/edges/base-edge.d.ts +21 -0
- package/esm/elements/edges/base-edge.js +21 -0
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/nodes/base-node.d.ts +22 -1
- package/esm/elements/nodes/base-node.js +21 -0
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/exports.d.ts +16 -14
- package/esm/exports.js +7 -6
- package/esm/exports.js.map +1 -1
- package/esm/plugins/camera-setting.d.ts +95 -0
- package/esm/plugins/camera-setting.js +65 -0
- package/esm/plugins/camera-setting.js.map +1 -0
- package/esm/plugins/contextmenu.d.ts +8 -5
- package/esm/plugins/contextmenu.js.map +1 -1
- package/esm/plugins/index.d.ts +4 -0
- package/esm/plugins/index.js +2 -0
- package/esm/plugins/index.js.map +1 -1
- package/esm/plugins/legend.d.ts +49 -0
- package/esm/plugins/legend.js +267 -0
- package/esm/plugins/legend.js.map +1 -0
- package/esm/plugins/tooltip.d.ts +12 -10
- package/esm/plugins/tooltip.js +0 -1
- package/esm/plugins/tooltip.js.map +1 -1
- package/esm/preset.js +2 -5
- package/esm/preset.js.map +1 -1
- package/esm/registry/build-in.js +4 -2
- package/esm/registry/build-in.js.map +1 -1
- package/esm/registry/extension/index.d.ts +2 -2
- package/esm/registry/extension/index.js.map +1 -1
- package/esm/registry/index.d.ts +6 -4
- package/esm/registry/index.js.map +1 -1
- package/esm/registry/types.d.ts +0 -6
- package/esm/runtime/behavior.js +3 -2
- package/esm/runtime/behavior.js.map +1 -1
- package/esm/runtime/canvas.d.ts +2 -1
- package/esm/runtime/canvas.js +68 -30
- package/esm/runtime/canvas.js.map +1 -1
- package/esm/runtime/data.d.ts +1 -1
- package/esm/runtime/element.d.ts +4 -5
- package/esm/runtime/element.js +32 -13
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +31 -4
- package/esm/runtime/graph.js +48 -9
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/plugin.d.ts +1 -0
- package/esm/runtime/plugin.js +3 -0
- package/esm/runtime/plugin.js.map +1 -1
- package/esm/types/event.d.ts +42 -7
- package/esm/types/index.d.ts +0 -1
- package/esm/utils/bbox.d.ts +1 -1
- package/esm/utils/element.d.ts +19 -11
- package/esm/utils/element.js +19 -9
- package/esm/utils/element.js.map +1 -1
- package/esm/utils/event/events.d.ts +8 -13
- package/esm/utils/event/events.js +3 -8
- package/esm/utils/event/events.js.map +1 -1
- package/esm/utils/shortcut.d.ts +10 -0
- package/esm/utils/shortcut.js +24 -3
- package/esm/utils/shortcut.js.map +1 -1
- package/lib/behaviors/collapse-expand.d.ts +4 -5
- package/lib/behaviors/collapse-expand.js +8 -4
- package/lib/behaviors/collapse-expand.js.map +1 -1
- package/lib/behaviors/create-edge.d.ts +55 -0
- package/lib/behaviors/create-edge.js +145 -0
- package/lib/behaviors/create-edge.js.map +1 -0
- package/lib/behaviors/drag-canvas.d.ts +6 -6
- package/lib/behaviors/drag-canvas.js +15 -7
- package/lib/behaviors/drag-canvas.js.map +1 -1
- package/lib/behaviors/drag-element.d.ts +5 -3
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/focus-element.d.ts +4 -3
- package/lib/behaviors/focus-element.js.map +1 -1
- package/lib/behaviors/hover-element.d.ts +4 -5
- package/lib/behaviors/hover-element.js.map +1 -1
- package/lib/behaviors/index.d.ts +2 -0
- package/lib/behaviors/index.js +3 -1
- package/lib/behaviors/index.js.map +1 -1
- package/lib/behaviors/zoom-canvas.d.ts +7 -6
- package/lib/behaviors/zoom-canvas.js +6 -2
- package/lib/behaviors/zoom-canvas.js.map +1 -1
- package/lib/constants/events/graph.d.ts +5 -13
- package/lib/constants/events/graph.js +4 -12
- package/lib/constants/events/graph.js.map +1 -1
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +1 -0
- package/lib/constants/index.js.map +1 -1
- package/lib/constants/registry.d.ts +20 -0
- package/lib/constants/registry.js +25 -0
- package/lib/constants/registry.js.map +1 -0
- package/lib/elements/combos/base-combo.d.ts +21 -0
- package/lib/elements/combos/base-combo.js +21 -0
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/edges/base-edge.d.ts +21 -0
- package/lib/elements/edges/base-edge.js +21 -0
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/nodes/base-node.d.ts +22 -1
- package/lib/elements/nodes/base-node.js +21 -0
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/exports.d.ts +16 -14
- package/lib/exports.js +23 -1
- package/lib/exports.js.map +1 -1
- package/lib/plugins/camera-setting.d.ts +95 -0
- package/lib/plugins/camera-setting.js +69 -0
- package/lib/plugins/camera-setting.js.map +1 -0
- package/lib/plugins/contextmenu.d.ts +8 -5
- package/lib/plugins/contextmenu.js.map +1 -1
- package/lib/plugins/index.d.ts +4 -0
- package/lib/plugins/index.js +5 -1
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/legend.d.ts +49 -0
- package/lib/plugins/legend.js +271 -0
- package/lib/plugins/legend.js.map +1 -0
- package/lib/plugins/tooltip.d.ts +12 -10
- package/lib/plugins/tooltip.js +0 -1
- package/lib/plugins/tooltip.js.map +1 -1
- package/lib/preset.js +2 -5
- package/lib/preset.js.map +1 -1
- package/lib/registry/build-in.js +2 -0
- package/lib/registry/build-in.js.map +1 -1
- package/lib/registry/extension/index.d.ts +2 -2
- package/lib/registry/extension/index.js.map +1 -1
- package/lib/registry/index.d.ts +6 -4
- package/lib/registry/index.js.map +1 -1
- package/lib/registry/types.d.ts +0 -6
- package/lib/runtime/behavior.js +3 -2
- package/lib/runtime/behavior.js.map +1 -1
- package/lib/runtime/canvas.d.ts +2 -1
- package/lib/runtime/canvas.js +68 -30
- package/lib/runtime/canvas.js.map +1 -1
- package/lib/runtime/data.d.ts +1 -1
- package/lib/runtime/element.d.ts +4 -5
- package/lib/runtime/element.js +31 -12
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +31 -4
- package/lib/runtime/graph.js +47 -8
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/plugin.d.ts +1 -0
- package/lib/runtime/plugin.js +3 -0
- package/lib/runtime/plugin.js.map +1 -1
- package/lib/types/event.d.ts +42 -7
- package/lib/types/index.d.ts +0 -1
- package/lib/utils/bbox.d.ts +1 -1
- package/lib/utils/element.d.ts +19 -11
- package/lib/utils/element.js +21 -10
- package/lib/utils/element.js.map +1 -1
- package/lib/utils/event/events.d.ts +8 -13
- package/lib/utils/event/events.js +4 -10
- package/lib/utils/event/events.js.map +1 -1
- package/lib/utils/shortcut.d.ts +10 -0
- package/lib/utils/shortcut.js +24 -3
- package/lib/utils/shortcut.js.map +1 -1
- package/package.json +2 -2
- package/src/behaviors/collapse-expand.ts +13 -11
- package/src/behaviors/create-edge.ts +206 -0
- package/src/behaviors/drag-canvas.ts +22 -14
- package/src/behaviors/drag-element.ts +8 -11
- package/src/behaviors/focus-element.ts +7 -6
- package/src/behaviors/hover-element.ts +14 -10
- package/src/behaviors/index.ts +2 -0
- package/src/behaviors/zoom-canvas.ts +14 -9
- package/src/constants/events/graph.ts +4 -12
- package/src/constants/index.ts +1 -0
- package/src/constants/registry.ts +20 -0
- package/src/elements/combos/base-combo.ts +24 -0
- package/src/elements/edges/base-edge.ts +25 -1
- package/src/elements/nodes/base-node.ts +25 -1
- package/src/exports.ts +55 -12
- package/src/plugins/camera-setting.ts +153 -0
- package/src/plugins/contextmenu.ts +10 -7
- package/src/plugins/index.ts +4 -0
- package/src/plugins/legend.ts +321 -0
- package/src/plugins/tooltip.ts +16 -15
- package/src/preset.ts +2 -6
- package/src/registry/build-in.ts +12 -2
- package/src/registry/extension/index.ts +4 -4
- package/src/registry/index.ts +10 -4
- package/src/registry/types.ts +0 -7
- package/src/runtime/behavior.ts +3 -2
- package/src/runtime/canvas.ts +80 -40
- package/src/runtime/element.ts +52 -20
- package/src/runtime/graph.ts +56 -12
- package/src/runtime/plugin.ts +4 -0
- package/src/types/event.ts +62 -7
- package/src/types/index.ts +0 -1
- package/src/utils/bbox.ts +1 -1
- package/src/utils/element.ts +22 -11
- package/src/utils/event/events.ts +15 -17
- package/src/utils/shortcut.ts +28 -3
- package/dist/lib/types/behavior.d.ts +0 -5
- package/esm/types/behavior.d.ts +0 -5
- package/esm/types/behavior.js +0 -2
- package/esm/types/behavior.js.map +0 -1
- package/lib/types/behavior.d.ts +0 -5
- package/lib/types/behavior.js +0 -3
- package/lib/types/behavior.js.map +0 -1
- package/src/types/behavior.ts +0 -6
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { GraphEvent } from '../constants';
|
|
2
|
+
import type { RuntimeContext } from '../runtime/types';
|
|
3
|
+
import type { BasePluginOptions } from './base-plugin';
|
|
4
|
+
import { BasePlugin } from './base-plugin';
|
|
5
|
+
|
|
6
|
+
export interface CameraSettingOptions extends BasePluginOptions {
|
|
7
|
+
/**
|
|
8
|
+
* <zh/> 投影模式,透视投影仅在 3D 场景下有效
|
|
9
|
+
*
|
|
10
|
+
* <en/> Projection mode, perspective projection is only valid in 3D scenes
|
|
11
|
+
*/
|
|
12
|
+
projectionMode?: 'perspective' | 'orthographic';
|
|
13
|
+
/**
|
|
14
|
+
* <zh/> 相机类型
|
|
15
|
+
* - orbiting: 固定视点,改变相机位置
|
|
16
|
+
* - exploring: 类似 orbiting,但允许相机在北极和南极之间旋转
|
|
17
|
+
* - tracking: 固定相机位置,改变视点
|
|
18
|
+
*
|
|
19
|
+
* <en/> Camera type
|
|
20
|
+
* - orbiting: Fixed viewpoint, change camera position
|
|
21
|
+
* - exploring: Similar to orbiting, but allows the camera to rotate between the North Pole and the South Pole
|
|
22
|
+
* - tracking: Fixed camera position, change viewpoint
|
|
23
|
+
*/
|
|
24
|
+
cameraType?: 'orbiting' | 'exploring' | 'tracking';
|
|
25
|
+
/**
|
|
26
|
+
* <zh/> 近平面位置
|
|
27
|
+
*
|
|
28
|
+
* <en/> The position of the near plane
|
|
29
|
+
*/
|
|
30
|
+
near?: number;
|
|
31
|
+
/**
|
|
32
|
+
* <zh/> 远平面位置
|
|
33
|
+
*
|
|
34
|
+
* <en/> The position of the far plane
|
|
35
|
+
*/
|
|
36
|
+
far?: number;
|
|
37
|
+
/**
|
|
38
|
+
* <zh/> 相机视角,仅在透视相机下有效
|
|
39
|
+
*
|
|
40
|
+
* <en/> Camera field of view, only valid in perspective camera
|
|
41
|
+
*/
|
|
42
|
+
fov?: number;
|
|
43
|
+
/**
|
|
44
|
+
* <zh/> 相机视口宽高比,仅在透视相机下有效。设置为 'auto' 时,会自动根据画布宽高比设置
|
|
45
|
+
*
|
|
46
|
+
* <en/> Camera viewport aspect ratio, only valid in perspective camera. When set to 'auto', it will be automatically set according to the canvas aspect ratio
|
|
47
|
+
*/
|
|
48
|
+
aspect?: number | 'auto';
|
|
49
|
+
/**
|
|
50
|
+
* <zh/> 相机距离目标的距离,默认为 500
|
|
51
|
+
*
|
|
52
|
+
* <en/> The distance from the camera to the target, default is 100.
|
|
53
|
+
*/
|
|
54
|
+
distance?: number;
|
|
55
|
+
/**
|
|
56
|
+
* <zh/> 最小视距
|
|
57
|
+
*
|
|
58
|
+
* <en/> Minimum distance
|
|
59
|
+
*/
|
|
60
|
+
minDistance?: number;
|
|
61
|
+
/**
|
|
62
|
+
* <zh/> 最大视距
|
|
63
|
+
*
|
|
64
|
+
* <en/> Maximum distance
|
|
65
|
+
*/
|
|
66
|
+
maxDistance?: number;
|
|
67
|
+
/**
|
|
68
|
+
* <zh/> 滚转角
|
|
69
|
+
*
|
|
70
|
+
* <en/> Roll
|
|
71
|
+
*/
|
|
72
|
+
roll?: number;
|
|
73
|
+
/**
|
|
74
|
+
* <zh/> 仰角
|
|
75
|
+
*
|
|
76
|
+
* <en/> Elevation
|
|
77
|
+
*/
|
|
78
|
+
elevation?: number;
|
|
79
|
+
/**
|
|
80
|
+
* <zh/> 方位角
|
|
81
|
+
*
|
|
82
|
+
* <en/> Azimuth
|
|
83
|
+
*/
|
|
84
|
+
azimuth?: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* <zh/> 配置相机参数
|
|
89
|
+
*
|
|
90
|
+
* <en/> Configure camera parameters
|
|
91
|
+
*/
|
|
92
|
+
export class CameraSetting extends BasePlugin<CameraSettingOptions> {
|
|
93
|
+
constructor(context: RuntimeContext, options: CameraSettingOptions) {
|
|
94
|
+
super(context, options);
|
|
95
|
+
this.bindEvents();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public update(options: Partial<CameraSettingOptions>): void {
|
|
99
|
+
this.setOptions(options);
|
|
100
|
+
super.update(options);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private bindEvents() {
|
|
104
|
+
this.context.graph.once(GraphEvent.BEFORE_DRAW, () => this.setOptions(this.options));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private setOptions = (options: Partial<CameraSettingOptions>) => {
|
|
108
|
+
const caller = {
|
|
109
|
+
cameraType: 'setType',
|
|
110
|
+
near: 'setNear',
|
|
111
|
+
far: 'setFar',
|
|
112
|
+
fov: 'setFov',
|
|
113
|
+
aspect: 'setAspect',
|
|
114
|
+
// 确保 projectionMode 在 near/far/fov/aspect 之后设置
|
|
115
|
+
// Ensure that projectionMode is set after near/far/fov/aspect
|
|
116
|
+
projectionMode: 'setProjectionMode',
|
|
117
|
+
distance: 'setDistance',
|
|
118
|
+
minDistance: 'setMinDistance',
|
|
119
|
+
maxDistance: 'setMaxDistance',
|
|
120
|
+
roll: 'setRoll',
|
|
121
|
+
elevation: 'setElevation',
|
|
122
|
+
azimuth: 'setAzimuth',
|
|
123
|
+
} as const;
|
|
124
|
+
|
|
125
|
+
const valueMapper = <T extends keyof CameraSettingOptions>(key: T, value: CameraSettingOptions[T]) => {
|
|
126
|
+
switch (key) {
|
|
127
|
+
case 'projectionMode':
|
|
128
|
+
return value === 'perspective' ? 1 : 0;
|
|
129
|
+
case 'cameraType':
|
|
130
|
+
return { orbiting: 0, exploring: 1, tracking: 2 }[value];
|
|
131
|
+
case 'aspect':
|
|
132
|
+
if (typeof value === 'number') return value;
|
|
133
|
+
return this.getCanvasAspect();
|
|
134
|
+
default:
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
Object.entries(caller).forEach(([key, method]) => {
|
|
140
|
+
const value = options[key];
|
|
141
|
+
if (value !== undefined) {
|
|
142
|
+
const actualValue = valueMapper(key, value);
|
|
143
|
+
// @ts-expect-error incorrect ts type check
|
|
144
|
+
this.context.canvas.getCamera()[method](actualValue);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
private getCanvasAspect() {
|
|
150
|
+
const [width, height] = this.context.viewport!.getCanvasSize();
|
|
151
|
+
return width / height;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RuntimeContext } from '../runtime/types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Element } from '../types';
|
|
3
|
+
import type { IPointerEvent } from '../types/event';
|
|
3
4
|
import type { Item } from '../utils/contextmenu';
|
|
4
5
|
import { CONTEXTMENU_CSS, getContentFromItems } from '../utils/contextmenu';
|
|
5
6
|
import { createPluginContainer, insertDOM } from '../utils/dom';
|
|
@@ -35,12 +36,12 @@ export type ContextmenuOptions = BasePluginOptions & {
|
|
|
35
36
|
* <zh/> 返回菜单的项目列表,支持 `Promise` 类型的返回值。是 `getContent` 的快捷配置。
|
|
36
37
|
* <en/> Return the list of menu items, support the `Promise` type return value. It is a shortcut configuration of `getContent`.
|
|
37
38
|
*/
|
|
38
|
-
getItems?: (event:
|
|
39
|
+
getItems?: (event: IElementEvent) => Item[] | Promise<Item[]>;
|
|
39
40
|
/**
|
|
40
41
|
* <zh/> 返回菜单的内容,支持 `Promise` 类型的返回值,也可以使用 `getItems` 来快捷配置。
|
|
41
42
|
* <en/> Return the content of menu, support the `Promise` type return value, you can also use `getItems` for shortcut configuration.
|
|
42
43
|
*/
|
|
43
|
-
getContent?: (event:
|
|
44
|
+
getContent?: (event: IElementEvent) => HTMLElement | string | Promise<HTMLElement | string>;
|
|
44
45
|
/**
|
|
45
46
|
* <zh/> Loading 时候的菜单内容,用于 getContent 返回 Promise 的时候。
|
|
46
47
|
* <en/> The menu content when loading is used when getContent returns a Promise.
|
|
@@ -50,7 +51,7 @@ export type ContextmenuOptions = BasePluginOptions & {
|
|
|
50
51
|
* <zh/> 插件是否可用,通过参数来判断是否支持右键菜单,默认全部可用。
|
|
51
52
|
* <en/> Whether the plugin is available, determine whether the right-click menu is supported through parameters, The default is all available.
|
|
52
53
|
*/
|
|
53
|
-
enable?: boolean | ((event:
|
|
54
|
+
enable?: boolean | ((event: IElementEvent) => boolean);
|
|
54
55
|
};
|
|
55
56
|
|
|
56
57
|
/**
|
|
@@ -86,7 +87,7 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
|
|
|
86
87
|
* <en/> Display the right-click menu based on the incoming element.
|
|
87
88
|
* @param e - 事件
|
|
88
89
|
*/
|
|
89
|
-
public async showContextmenu(e:
|
|
90
|
+
public async showContextmenu(e: IElementEvent) {
|
|
90
91
|
const { enable, offset } = this.options;
|
|
91
92
|
|
|
92
93
|
if ((typeof enable === 'function' && !enable(e)) || !enable) {
|
|
@@ -139,7 +140,7 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
|
|
|
139
140
|
this.$element.remove();
|
|
140
141
|
}
|
|
141
142
|
|
|
142
|
-
private async getDOMContent(e:
|
|
143
|
+
private async getDOMContent(e: IElementEvent) {
|
|
143
144
|
const { getContent, getItems } = this.options;
|
|
144
145
|
|
|
145
146
|
if (getItems) {
|
|
@@ -172,7 +173,7 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
|
|
|
172
173
|
document.removeEventListener('click', this.onMenuItemClick);
|
|
173
174
|
}
|
|
174
175
|
|
|
175
|
-
private onTriggerEvent = (e:
|
|
176
|
+
private onTriggerEvent = (e: IElementEvent) => {
|
|
176
177
|
// `contextmenu` 事件默认会触发浏览器的右键菜单,需要阻止默认事件
|
|
177
178
|
// `click` 事件不需要阻止默认事件
|
|
178
179
|
e.preventDefault?.();
|
|
@@ -196,3 +197,5 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
|
|
|
196
197
|
}
|
|
197
198
|
};
|
|
198
199
|
}
|
|
200
|
+
|
|
201
|
+
type IElementEvent = IPointerEvent<Element>;
|
package/src/plugins/index.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
export { BasePlugin } from './base-plugin';
|
|
2
|
+
export { CameraSetting } from './camera-setting';
|
|
2
3
|
export { Contextmenu } from './contextmenu';
|
|
3
4
|
export { GridLine } from './grid-line';
|
|
5
|
+
export { Legend } from './legend';
|
|
4
6
|
export { Toolbar } from './toolbar';
|
|
5
7
|
export { Tooltip } from './tooltip';
|
|
6
8
|
export { Watermark } from './watermark';
|
|
7
9
|
|
|
8
10
|
export type { BasePluginOptions } from './base-plugin';
|
|
11
|
+
export type { CameraSettingOptions } from './camera-setting';
|
|
9
12
|
export type { ContextmenuOptions } from './contextmenu';
|
|
10
13
|
export type { GridLineOptions } from './grid-line';
|
|
14
|
+
export type { LegendOptions } from './legend';
|
|
11
15
|
export type { ToolbarOptions } from './toolbar';
|
|
12
16
|
export type { TooltipOptions } from './tooltip';
|
|
13
17
|
export type { WatermarkOptions } from './watermark';
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import type { CategoryOptions } from '@antv/component';
|
|
2
|
+
import { Category, Layout, Selection } from '@antv/component';
|
|
3
|
+
import type { ID } from '@antv/graphlib';
|
|
4
|
+
import { get, isFunction } from '@antv/util';
|
|
5
|
+
import { GraphEvent } from '../constants';
|
|
6
|
+
import type { RuntimeContext } from '../runtime/types';
|
|
7
|
+
import type { ElementDatum, ElementType, State } from '../types';
|
|
8
|
+
import type { CardinalPlacement } from '../types/placement';
|
|
9
|
+
import type { BasePluginOptions } from './base-plugin';
|
|
10
|
+
import { BasePlugin } from './base-plugin';
|
|
11
|
+
|
|
12
|
+
type Field = string | ((item: ElementDatum) => string);
|
|
13
|
+
type Datum = {
|
|
14
|
+
id?: string;
|
|
15
|
+
label?: string;
|
|
16
|
+
color?: string;
|
|
17
|
+
marker?: string;
|
|
18
|
+
elementType?: ElementType;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export interface LegendOptions extends BasePluginOptions, Omit<CategoryOptions, 'data'> {
|
|
23
|
+
/** <zh/> 触发方式 | <en/> Event type that triggers display of legend */
|
|
24
|
+
trigger?: 'hover' | 'click';
|
|
25
|
+
/** <zh/> 位置 | <en/> Legend position */
|
|
26
|
+
position?: CardinalPlacement;
|
|
27
|
+
/** <zh/> 节点分类标识 | <en/> Node Classification Identifier */
|
|
28
|
+
nodeField?: Field;
|
|
29
|
+
/** <zh/> 边分类标识 | <en/> Edge Classification Identifier */
|
|
30
|
+
edgeField?: Field;
|
|
31
|
+
/** <zh/> Combo分类标识 | <en/> Combo Classification Identifier */
|
|
32
|
+
comboField?: Field;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class Legend extends BasePlugin<LegendOptions> {
|
|
36
|
+
static defaultOptions: Partial<LegendOptions> = {
|
|
37
|
+
position: 'bottom',
|
|
38
|
+
trigger: 'hover',
|
|
39
|
+
orientation: 'horizontal',
|
|
40
|
+
layout: 'flex',
|
|
41
|
+
itemSpacing: 4,
|
|
42
|
+
rowPadding: 10,
|
|
43
|
+
colPadding: 10,
|
|
44
|
+
itemMarkerSize: 16,
|
|
45
|
+
itemLabelFontSize: 16,
|
|
46
|
+
};
|
|
47
|
+
private typePrefix = '__data__';
|
|
48
|
+
private element: Layout | null = null;
|
|
49
|
+
private draw = false;
|
|
50
|
+
private fieldMap = {
|
|
51
|
+
node: new Map<string, ID[]>(),
|
|
52
|
+
edge: new Map<string, ID[]>(),
|
|
53
|
+
combo: new Map<string, ID[]>(),
|
|
54
|
+
};
|
|
55
|
+
private selectedItems: string[] = [];
|
|
56
|
+
|
|
57
|
+
constructor(context: RuntimeContext, options: LegendOptions) {
|
|
58
|
+
super(context, Object.assign({}, Legend.defaultOptions, options));
|
|
59
|
+
this.bindEvents();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public update(options: Partial<LegendOptions>) {
|
|
63
|
+
super.update(options);
|
|
64
|
+
this.clear();
|
|
65
|
+
this.createElement();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private clear() {
|
|
69
|
+
this.element?.destroy();
|
|
70
|
+
this.element = null;
|
|
71
|
+
this.draw = false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private bindEvents = () => {
|
|
75
|
+
const { graph } = this.context;
|
|
76
|
+
graph.on(GraphEvent.AFTER_DRAW, this.createElement);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
private changeState = (el: Selection, state: State | State[]) => {
|
|
80
|
+
const { graph } = this.context;
|
|
81
|
+
const { typePrefix } = this;
|
|
82
|
+
const composeId = get(el, [typePrefix, 'id']);
|
|
83
|
+
const category = get(el, [typePrefix, 'style', 'labelText']);
|
|
84
|
+
const [type] = composeId.split('__');
|
|
85
|
+
const ids = this.fieldMap[type as keyof typeof this.fieldMap].get(category) || [];
|
|
86
|
+
|
|
87
|
+
graph.setElementState(Object.fromEntries(ids?.map((id) => [id, state])));
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
public click = (el: Selection) => {
|
|
91
|
+
if (this.options.trigger === 'hover') return;
|
|
92
|
+
const composeId = get(el, [this.typePrefix, 'id']);
|
|
93
|
+
if (!this.selectedItems.includes(composeId)) {
|
|
94
|
+
this.selectedItems.push(composeId);
|
|
95
|
+
this.changeState(el, 'selected');
|
|
96
|
+
} else {
|
|
97
|
+
this.selectedItems = this.selectedItems.filter((item) => item !== composeId);
|
|
98
|
+
this.changeState(el, []);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
public mouseleave = (el: Selection) => {
|
|
103
|
+
if (this.options.trigger === 'click') return;
|
|
104
|
+
this.selectedItems = [];
|
|
105
|
+
this.changeState(el, []);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
public mouseenter = (el: Selection) => {
|
|
109
|
+
if (this.options.trigger === 'click') return;
|
|
110
|
+
const composeId = get(el, [this.typePrefix, 'id']);
|
|
111
|
+
if (!this.selectedItems.includes(composeId)) {
|
|
112
|
+
this.selectedItems.push(composeId);
|
|
113
|
+
this.changeState(el, 'active');
|
|
114
|
+
} else {
|
|
115
|
+
this.selectedItems = this.selectedItems.filter((item) => item !== composeId);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
public updateElement() {
|
|
120
|
+
if (!this.element) return;
|
|
121
|
+
const category = this.element.getChildByIndex(0) as Category;
|
|
122
|
+
|
|
123
|
+
category.update({
|
|
124
|
+
itemMarkerOpacity: ({ id }) => {
|
|
125
|
+
if (!this.selectedItems.length || this.selectedItems.includes(id)) return 1;
|
|
126
|
+
return 0.5;
|
|
127
|
+
},
|
|
128
|
+
itemLabelOpacity: ({ id }) => {
|
|
129
|
+
if (!this.selectedItems.length || this.selectedItems.includes(id)) return 1;
|
|
130
|
+
return 0.5;
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private setFieldMap = (field: string, id: ID, type: ElementType) => {
|
|
136
|
+
if (!field) return;
|
|
137
|
+
const map = this.fieldMap[type];
|
|
138
|
+
if (!map) return;
|
|
139
|
+
if (!map.has(field)) {
|
|
140
|
+
map.set(field, [id]);
|
|
141
|
+
} else {
|
|
142
|
+
const ids = map.get(field);
|
|
143
|
+
if (ids) {
|
|
144
|
+
ids.push(id);
|
|
145
|
+
map.set(field, ids);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
private getEvents = () => {
|
|
151
|
+
return {
|
|
152
|
+
mouseenter: this.mouseenter,
|
|
153
|
+
mouseleave: this.mouseleave,
|
|
154
|
+
click: this.click,
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
private getMarkerData = (field: Field, elementType: ElementType) => {
|
|
159
|
+
if (!field) return [];
|
|
160
|
+
const { model, element, graph } = this.context;
|
|
161
|
+
const { nodes, edges, combos } = model.getData();
|
|
162
|
+
const items: { [key: string]: Datum } = {};
|
|
163
|
+
|
|
164
|
+
const getField = (item: ElementDatum) => {
|
|
165
|
+
if (isFunction(field)) return field(item);
|
|
166
|
+
return field;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const defaultType = {
|
|
170
|
+
node: 'circle',
|
|
171
|
+
edge: 'line',
|
|
172
|
+
combo: 'rect',
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/** 用于将 G6 element 转换为 componets 支持的类型 */
|
|
176
|
+
const markerMapping: { [key: string]: string } = {
|
|
177
|
+
circle: 'circle',
|
|
178
|
+
ellipse: 'circle', // 待 components 支持 ellipse
|
|
179
|
+
image: 'bowtie',
|
|
180
|
+
rect: 'square',
|
|
181
|
+
star: 'cross',
|
|
182
|
+
triangle: 'triangle',
|
|
183
|
+
diamond: 'diamond',
|
|
184
|
+
cubic: 'dot',
|
|
185
|
+
line: 'hyphen',
|
|
186
|
+
polyline: 'hyphen',
|
|
187
|
+
quadratic: 'hv',
|
|
188
|
+
'cubic-horizontal': 'hyphen',
|
|
189
|
+
'cubic-vertical': 'line',
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const getElementStyle = (type: ElementType, datum: ElementDatum) => {
|
|
193
|
+
const style = element?.getElementComputedStyle(type, datum);
|
|
194
|
+
return style;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const getElementModel = (data: ElementDatum[], type: ElementType) => {
|
|
198
|
+
data.forEach((item) => {
|
|
199
|
+
const { id } = item;
|
|
200
|
+
const value = get(item, ['data', getField(item)]);
|
|
201
|
+
const { color = '#1783ff', type: marker = 'circle' } = getElementStyle(type, item);
|
|
202
|
+
if ((id || id === 0) && value && value.replace(/\s+/g, '')) {
|
|
203
|
+
this.setFieldMap(value, id, type);
|
|
204
|
+
if (!items[value]) {
|
|
205
|
+
items[value] = {
|
|
206
|
+
id: `${type}__${id}`,
|
|
207
|
+
label: value,
|
|
208
|
+
marker: markerMapping[marker] || defaultType[type],
|
|
209
|
+
elementType: type,
|
|
210
|
+
lineWidth: 1,
|
|
211
|
+
stroke: color,
|
|
212
|
+
fill: color,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
switch (elementType) {
|
|
220
|
+
case 'node':
|
|
221
|
+
getElementModel(nodes, 'node');
|
|
222
|
+
break;
|
|
223
|
+
case 'edge':
|
|
224
|
+
getElementModel(edges, 'edge');
|
|
225
|
+
break;
|
|
226
|
+
case 'combo':
|
|
227
|
+
getElementModel(combos, 'combo');
|
|
228
|
+
break;
|
|
229
|
+
default:
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return Object.values(items);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
public layout = (position: CardinalPlacement) => {
|
|
237
|
+
const preset = {
|
|
238
|
+
flexDirection: 'row',
|
|
239
|
+
alignItems: 'flex-end',
|
|
240
|
+
justifyContent: 'center',
|
|
241
|
+
};
|
|
242
|
+
let { flexDirection, alignItems, justifyContent } = preset;
|
|
243
|
+
|
|
244
|
+
const layout = {
|
|
245
|
+
top: ['row', 'flex-start', 'center'],
|
|
246
|
+
bottom: ['row', 'flex-end', 'center'],
|
|
247
|
+
left: ['column', 'flex-start', 'center'],
|
|
248
|
+
right: ['column', 'flex-end', 'center'],
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
if (position in layout) {
|
|
252
|
+
[flexDirection, alignItems, justifyContent] = layout[position];
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
display: 'flex',
|
|
256
|
+
flexDirection,
|
|
257
|
+
justifyContent,
|
|
258
|
+
alignItems,
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
private createElement = () => {
|
|
263
|
+
if (this.draw) {
|
|
264
|
+
this.updateElement();
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const { canvas } = this.context;
|
|
268
|
+
const [canvasWidth, canvasHeiht] = canvas.getSize();
|
|
269
|
+
const {
|
|
270
|
+
width = canvasWidth,
|
|
271
|
+
height = canvasHeiht,
|
|
272
|
+
nodeField,
|
|
273
|
+
edgeField,
|
|
274
|
+
comboField,
|
|
275
|
+
trigger,
|
|
276
|
+
position,
|
|
277
|
+
...rest
|
|
278
|
+
} = this.options;
|
|
279
|
+
const nodeItems = this.getMarkerData(nodeField, 'node');
|
|
280
|
+
const edgeItems = this.getMarkerData(edgeField, 'edge');
|
|
281
|
+
const comboItems = this.getMarkerData(comboField, 'combo');
|
|
282
|
+
const items = [...nodeItems, ...comboItems, ...edgeItems];
|
|
283
|
+
const layout = this.layout(position);
|
|
284
|
+
|
|
285
|
+
const layoutWrapper = new Layout({
|
|
286
|
+
style: {
|
|
287
|
+
width,
|
|
288
|
+
height,
|
|
289
|
+
...layout,
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
const categoryStyle = {
|
|
294
|
+
width,
|
|
295
|
+
height,
|
|
296
|
+
data: items,
|
|
297
|
+
itemMarkerLineWidth: ({ lineWidth }: Datum) => lineWidth,
|
|
298
|
+
itemMarker: ({ marker }: Datum) => marker,
|
|
299
|
+
itemMarkerStroke: ({ stroke }: Datum) => stroke,
|
|
300
|
+
itemMarkerFill: ({ fill }: Datum) => fill,
|
|
301
|
+
gridCol: nodeItems.length,
|
|
302
|
+
...rest,
|
|
303
|
+
...this.getEvents(),
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const category = new Category({
|
|
307
|
+
className: 'legend',
|
|
308
|
+
style: categoryStyle,
|
|
309
|
+
});
|
|
310
|
+
layoutWrapper.appendChild(category);
|
|
311
|
+
canvas.appendChild(layoutWrapper);
|
|
312
|
+
this.element = layoutWrapper;
|
|
313
|
+
this.draw = true;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
public destroy(): void {
|
|
317
|
+
this.clear();
|
|
318
|
+
this.context.graph.off(GraphEvent.AFTER_DRAW, this.createElement);
|
|
319
|
+
super.destroy();
|
|
320
|
+
}
|
|
321
|
+
}
|
package/src/plugins/tooltip.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { TooltipStyleProps } from '@antv/component';
|
|
|
2
2
|
import { Tooltip as TooltipComponent } from '@antv/component';
|
|
3
3
|
import { get } from '@antv/util';
|
|
4
4
|
import type { RuntimeContext } from '../runtime/types';
|
|
5
|
-
import type {
|
|
5
|
+
import type { Element, ElementDatum, ElementType, IPointerEvent } from '../types';
|
|
6
6
|
import type { BasePluginOptions } from './base-plugin';
|
|
7
7
|
import { BasePlugin } from './base-plugin';
|
|
8
8
|
|
|
@@ -12,9 +12,9 @@ export interface TooltipOptions
|
|
|
12
12
|
/** <zh/> 触发方式 | <en/> Event type that triggers display of tooltip */
|
|
13
13
|
trigger?: 'hover' | 'click';
|
|
14
14
|
/** <zh/> 自定义内容 | <en/> Function for getting tooltip content */
|
|
15
|
-
getContent?: (evt:
|
|
15
|
+
getContent?: (evt: IElementEvent, items: ElementDatum[]) => HTMLElement | string;
|
|
16
16
|
/** <zh/> 是否启用 | <en/> Is enable */
|
|
17
|
-
enable?: boolean | ((evt:
|
|
17
|
+
enable?: boolean | ((evt: IElementEvent) => boolean);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
@@ -39,14 +39,13 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
39
39
|
this.bindEvents();
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
public getEvents(): { [key: string]:
|
|
42
|
+
public getEvents(): { [key: string]: (event: IElementEvent) => void } {
|
|
43
43
|
if (this.options.trigger === 'click') {
|
|
44
44
|
return {
|
|
45
45
|
'node:click': this.onClick,
|
|
46
46
|
'edge:click': this.onClick,
|
|
47
47
|
'combo:click': this.onClick,
|
|
48
48
|
'canvas:click': this.onPointerLeave,
|
|
49
|
-
afterremoveitem: this.onPointerLeave,
|
|
50
49
|
contextmenu: this.onPointerLeave,
|
|
51
50
|
drag: this.onPointerLeave,
|
|
52
51
|
};
|
|
@@ -100,7 +99,7 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
100
99
|
});
|
|
101
100
|
}
|
|
102
101
|
|
|
103
|
-
private isEnable = (e:
|
|
102
|
+
private isEnable = (e: IElementEvent) => {
|
|
104
103
|
const { enable } = this.options;
|
|
105
104
|
if (typeof enable === 'function') {
|
|
106
105
|
return enable(e);
|
|
@@ -108,7 +107,7 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
108
107
|
return enable;
|
|
109
108
|
};
|
|
110
109
|
|
|
111
|
-
public onClick = (e:
|
|
110
|
+
public onClick = (e: IElementEvent) => {
|
|
112
111
|
const {
|
|
113
112
|
target: { id },
|
|
114
113
|
} = e;
|
|
@@ -122,7 +121,7 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
122
121
|
}
|
|
123
122
|
};
|
|
124
123
|
|
|
125
|
-
public onPointerMove = (e:
|
|
124
|
+
public onPointerMove = (e: IElementEvent) => {
|
|
126
125
|
const { target } = e;
|
|
127
126
|
if (!this.currentTarget || target.id === this.currentTarget) {
|
|
128
127
|
return;
|
|
@@ -130,17 +129,17 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
130
129
|
this.showTooltip(e);
|
|
131
130
|
};
|
|
132
131
|
|
|
133
|
-
public onPointerLeave = (e:
|
|
132
|
+
public onPointerLeave = (e: IElementEvent) => {
|
|
134
133
|
this.hideTooltip(e);
|
|
135
134
|
this.currentTarget = null;
|
|
136
135
|
};
|
|
137
136
|
|
|
138
|
-
public onCanvasMove = (e:
|
|
137
|
+
public onCanvasMove = (e: IElementEvent) => {
|
|
139
138
|
this.hideTooltip(e);
|
|
140
139
|
this.currentTarget = null;
|
|
141
140
|
};
|
|
142
141
|
|
|
143
|
-
private onPointerEnter = (e:
|
|
142
|
+
private onPointerEnter = (e: IElementEvent) => {
|
|
144
143
|
this.showTooltip(e);
|
|
145
144
|
};
|
|
146
145
|
|
|
@@ -148,7 +147,7 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
148
147
|
const e = {
|
|
149
148
|
targetType: elementType,
|
|
150
149
|
target: { id },
|
|
151
|
-
} as
|
|
150
|
+
} as IElementEvent;
|
|
152
151
|
this.showTooltip(e);
|
|
153
152
|
};
|
|
154
153
|
|
|
@@ -166,7 +165,7 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
166
165
|
}
|
|
167
166
|
};
|
|
168
167
|
|
|
169
|
-
public showTooltip = (e:
|
|
168
|
+
public showTooltip = (e: IElementEvent) => {
|
|
170
169
|
const {
|
|
171
170
|
targetType,
|
|
172
171
|
client,
|
|
@@ -176,7 +175,7 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
176
175
|
const { getContent } = this.options;
|
|
177
176
|
const { color, stroke } = attributes;
|
|
178
177
|
this.currentTarget = id;
|
|
179
|
-
const items: ElementDatum[] = this.getItems(id, targetType);
|
|
178
|
+
const items: ElementDatum[] = this.getItems(id, targetType as ElementType);
|
|
180
179
|
let x;
|
|
181
180
|
let y;
|
|
182
181
|
if (client) {
|
|
@@ -214,7 +213,7 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
214
213
|
});
|
|
215
214
|
};
|
|
216
215
|
|
|
217
|
-
public hideTooltip = (e?:
|
|
216
|
+
public hideTooltip = (e?: IElementEvent) => {
|
|
218
217
|
// if e is undefined, hide the tooltip, external call
|
|
219
218
|
if (!e) {
|
|
220
219
|
this.tooltipElement?.hide();
|
|
@@ -266,3 +265,5 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
266
265
|
super.destroy();
|
|
267
266
|
}
|
|
268
267
|
}
|
|
268
|
+
|
|
269
|
+
type IElementEvent = IPointerEvent<Element>;
|
package/src/preset.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { runtime } from '@antv/g';
|
|
2
2
|
import { registerBuiltInExtensions } from './registry';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
registerBuiltInExtensions();
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
onload();
|
|
4
|
+
runtime.enableCSSParsing = false;
|
|
5
|
+
registerBuiltInExtensions();
|