@antv/g6 5.0.0-alpha.8 → 5.0.0-alpha.9
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 +6 -19
- package/esm/index.d.ts +26 -6
- package/esm/item/combo.d.ts +72 -2
- package/esm/item/combo.js +122 -2
- package/esm/item/combo.js.map +1 -1
- package/esm/item/edge.d.ts +3 -3
- package/esm/item/edge.js +4 -5
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.d.ts +4 -4
- package/esm/item/item.js +38 -9
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +20 -16
- package/esm/item/node.js +14 -8
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/data.d.ts +12 -4
- package/esm/runtime/controller/data.js +354 -62
- package/esm/runtime/controller/data.js.map +1 -1
- package/esm/runtime/controller/interaction.js +16 -4
- package/esm/runtime/controller/interaction.js.map +1 -1
- package/esm/runtime/controller/item.d.ts +11 -2
- package/esm/runtime/controller/item.js +344 -52
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/controller/layout.js +19 -5
- package/esm/runtime/controller/layout.js.map +1 -1
- package/esm/runtime/graph.d.ts +54 -17
- package/esm/runtime/graph.js +165 -34
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/click-select.d.ts +3 -0
- package/esm/stdlib/behavior/click-select.js +13 -1
- package/esm/stdlib/behavior/click-select.js.map +1 -1
- package/esm/stdlib/behavior/collapse-expand-combo.d.ts +29 -0
- package/esm/stdlib/behavior/collapse-expand-combo.js +35 -0
- package/esm/stdlib/behavior/collapse-expand-combo.js.map +1 -0
- package/esm/stdlib/behavior/drag-combo.d.ts +99 -0
- package/esm/stdlib/behavior/drag-combo.js +341 -0
- package/esm/stdlib/behavior/drag-combo.js.map +1 -0
- package/esm/stdlib/behavior/drag-node.d.ts +14 -10
- package/esm/stdlib/behavior/drag-node.js +134 -37
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/hover-activate.d.ts +3 -1
- package/esm/stdlib/behavior/hover-activate.js +3 -1
- package/esm/stdlib/behavior/hover-activate.js.map +1 -1
- package/esm/stdlib/behavior/orbit-canvas-3d.js +1 -1
- package/esm/stdlib/behavior/orbit-canvas-3d.js.map +1 -1
- package/esm/stdlib/behavior/track-canvas-3d.js +1 -1
- package/esm/stdlib/behavior/track-canvas-3d.js.map +1 -1
- package/esm/stdlib/index.d.ts +25 -3
- package/esm/stdlib/index.js +25 -3
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/combo/circle.d.ts +29 -0
- package/esm/stdlib/item/combo/circle.js +56 -0
- package/esm/stdlib/item/combo/circle.js.map +1 -0
- package/esm/stdlib/item/edge/base.d.ts +2 -2
- package/esm/stdlib/item/edge/base.js +3 -0
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/edge/cubic-horizon.d.ts +37 -0
- package/esm/stdlib/item/edge/cubic-horizon.js +71 -0
- package/esm/stdlib/item/edge/cubic-horizon.js.map +1 -0
- package/esm/stdlib/item/edge/cubic-vertical.d.ts +37 -0
- package/esm/stdlib/item/edge/cubic-vertical.js +71 -0
- package/esm/stdlib/item/edge/cubic-vertical.js.map +1 -0
- package/esm/stdlib/item/edge/cubic.d.ts +60 -0
- package/esm/stdlib/item/edge/cubic.js +99 -0
- package/esm/stdlib/item/edge/cubic.js.map +1 -0
- package/esm/stdlib/item/edge/index.d.ts +1 -0
- package/esm/stdlib/item/edge/index.js +1 -0
- package/esm/stdlib/item/edge/index.js.map +1 -1
- package/esm/stdlib/item/edge/line.d.ts +1 -1
- package/esm/stdlib/item/edge/quadratic.d.ts +41 -0
- package/esm/stdlib/item/edge/quadratic.js +66 -0
- package/esm/stdlib/item/edge/quadratic.js.map +1 -0
- package/esm/stdlib/item/node/base.d.ts +38 -37
- package/esm/stdlib/item/node/base.js +4 -4
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/index.d.ts +1 -0
- package/esm/stdlib/item/node/index.js +1 -0
- package/esm/stdlib/item/node/index.js.map +1 -1
- package/esm/stdlib/item/node/rect.d.ts +31 -0
- package/esm/stdlib/item/node/rect.js +59 -0
- package/esm/stdlib/item/node/rect.js.map +1 -0
- package/esm/stdlib/plugin/fisheye/index.d.ts +102 -0
- package/esm/stdlib/plugin/fisheye/index.js +487 -0
- package/esm/stdlib/plugin/fisheye/index.js.map +1 -0
- package/esm/stdlib/plugin/menu/index.d.ts +42 -0
- package/esm/stdlib/plugin/menu/index.js +236 -0
- package/esm/stdlib/plugin/menu/index.js.map +1 -0
- package/esm/stdlib/plugin/tooltip/index.d.ts +75 -0
- package/esm/stdlib/plugin/tooltip/index.js +377 -0
- package/esm/stdlib/plugin/tooltip/index.js.map +1 -0
- package/esm/stdlib/theme/dark.js +4 -0
- package/esm/stdlib/theme/dark.js.map +1 -1
- package/esm/stdlib/theme/light.js +54 -9
- package/esm/stdlib/theme/light.js.map +1 -1
- package/esm/types/combo.d.ts +52 -3
- package/esm/types/data.d.ts +4 -4
- package/esm/types/edge.d.ts +2 -3
- package/esm/types/event.d.ts +9 -1
- package/esm/types/event.js +8 -8
- package/esm/types/event.js.map +1 -1
- package/esm/types/graph.d.ts +49 -13
- package/esm/types/hook.d.ts +8 -1
- package/esm/types/item.d.ts +4 -4
- package/esm/types/node.d.ts +4 -5
- package/esm/types/theme.d.ts +1 -1
- package/esm/util/animate.js.map +1 -1
- package/esm/util/canvas.js +8 -0
- package/esm/util/canvas.js.map +1 -1
- package/esm/util/data.d.ts +65 -0
- package/esm/util/data.js +150 -0
- package/esm/util/data.js.map +1 -0
- package/esm/util/event.d.ts +8 -0
- package/esm/util/event.js +16 -0
- package/esm/util/event.js.map +1 -1
- package/esm/util/item.d.ts +2 -1
- package/esm/util/item.js +36 -13
- package/esm/util/item.js.map +1 -1
- package/esm/util/shape.d.ts +39 -4
- package/esm/util/shape.js +101 -1
- package/esm/util/shape.js.map +1 -1
- package/esm/util/zoom.d.ts +2 -2
- package/lib/index.d.ts +26 -6
- package/lib/item/combo.d.ts +72 -2
- package/lib/item/combo.js +122 -2
- package/lib/item/combo.js.map +1 -1
- package/lib/item/edge.d.ts +3 -3
- package/lib/item/edge.js +4 -5
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.d.ts +4 -4
- package/lib/item/item.js +37 -8
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +20 -16
- package/lib/item/node.js +14 -8
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/data.d.ts +12 -4
- package/lib/runtime/controller/data.js +353 -61
- package/lib/runtime/controller/data.js.map +1 -1
- package/lib/runtime/controller/interaction.js +15 -3
- package/lib/runtime/controller/interaction.js.map +1 -1
- package/lib/runtime/controller/item.d.ts +11 -2
- package/lib/runtime/controller/item.js +342 -50
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/controller/layout.js +19 -5
- package/lib/runtime/controller/layout.js.map +1 -1
- package/lib/runtime/graph.d.ts +54 -17
- package/lib/runtime/graph.js +165 -34
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/click-select.d.ts +3 -0
- package/lib/stdlib/behavior/click-select.js +13 -1
- package/lib/stdlib/behavior/click-select.js.map +1 -1
- package/lib/stdlib/behavior/collapse-expand-combo.d.ts +29 -0
- package/lib/stdlib/behavior/collapse-expand-combo.js +38 -0
- package/lib/stdlib/behavior/collapse-expand-combo.js.map +1 -0
- package/lib/stdlib/behavior/drag-combo.d.ts +99 -0
- package/lib/stdlib/behavior/drag-combo.js +344 -0
- package/lib/stdlib/behavior/drag-combo.js.map +1 -0
- package/lib/stdlib/behavior/drag-node.d.ts +14 -10
- package/lib/stdlib/behavior/drag-node.js +134 -37
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/hover-activate.d.ts +3 -1
- package/lib/stdlib/behavior/hover-activate.js +3 -2
- package/lib/stdlib/behavior/hover-activate.js.map +1 -1
- package/lib/stdlib/behavior/orbit-canvas-3d.js +1 -1
- package/lib/stdlib/behavior/orbit-canvas-3d.js.map +1 -1
- package/lib/stdlib/behavior/track-canvas-3d.js +1 -1
- package/lib/stdlib/behavior/track-canvas-3d.js.map +1 -1
- package/lib/stdlib/index.d.ts +25 -3
- package/lib/stdlib/index.js +25 -3
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/combo/circle.d.ts +29 -0
- package/lib/stdlib/item/combo/circle.js +60 -0
- package/lib/stdlib/item/combo/circle.js.map +1 -0
- package/lib/stdlib/item/edge/base.d.ts +2 -2
- package/lib/stdlib/item/edge/base.js +3 -0
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/edge/cubic-horizon.d.ts +37 -0
- package/lib/stdlib/item/edge/cubic-horizon.js +75 -0
- package/lib/stdlib/item/edge/cubic-horizon.js.map +1 -0
- package/lib/stdlib/item/edge/cubic-vertical.d.ts +37 -0
- package/lib/stdlib/item/edge/cubic-vertical.js +75 -0
- package/lib/stdlib/item/edge/cubic-vertical.js.map +1 -0
- package/lib/stdlib/item/edge/cubic.d.ts +60 -0
- package/lib/stdlib/item/edge/cubic.js +103 -0
- package/lib/stdlib/item/edge/cubic.js.map +1 -0
- package/lib/stdlib/item/edge/index.d.ts +1 -0
- package/lib/stdlib/item/edge/index.js +1 -0
- package/lib/stdlib/item/edge/index.js.map +1 -1
- package/lib/stdlib/item/edge/line.d.ts +1 -1
- package/lib/stdlib/item/edge/quadratic.d.ts +41 -0
- package/lib/stdlib/item/edge/quadratic.js +70 -0
- package/lib/stdlib/item/edge/quadratic.js.map +1 -0
- package/lib/stdlib/item/node/base.d.ts +38 -37
- package/lib/stdlib/item/node/base.js +4 -4
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/index.d.ts +1 -0
- package/lib/stdlib/item/node/index.js +1 -0
- package/lib/stdlib/item/node/index.js.map +1 -1
- package/lib/stdlib/item/node/rect.d.ts +31 -0
- package/lib/stdlib/item/node/rect.js +63 -0
- package/lib/stdlib/item/node/rect.js.map +1 -0
- package/lib/stdlib/plugin/fisheye/index.d.ts +102 -0
- package/lib/stdlib/plugin/fisheye/index.js +490 -0
- package/lib/stdlib/plugin/fisheye/index.js.map +1 -0
- package/lib/stdlib/plugin/menu/index.d.ts +42 -0
- package/lib/stdlib/plugin/menu/index.js +242 -0
- package/lib/stdlib/plugin/menu/index.js.map +1 -0
- package/lib/stdlib/plugin/tooltip/index.d.ts +75 -0
- package/lib/stdlib/plugin/tooltip/index.js +383 -0
- package/lib/stdlib/plugin/tooltip/index.js.map +1 -0
- package/lib/stdlib/theme/dark.js +4 -0
- package/lib/stdlib/theme/dark.js.map +1 -1
- package/lib/stdlib/theme/light.js +54 -9
- package/lib/stdlib/theme/light.js.map +1 -1
- package/lib/types/combo.d.ts +52 -3
- package/lib/types/data.d.ts +4 -4
- package/lib/types/edge.d.ts +2 -3
- package/lib/types/event.d.ts +9 -1
- package/lib/types/event.js +10 -10
- package/lib/types/event.js.map +1 -1
- package/lib/types/graph.d.ts +49 -13
- package/lib/types/hook.d.ts +8 -1
- package/lib/types/item.d.ts +4 -4
- package/lib/types/item.js +1 -1
- package/lib/types/item.js.map +1 -1
- package/lib/types/node.d.ts +4 -5
- package/lib/types/theme.d.ts +1 -1
- package/lib/util/animate.js.map +1 -1
- package/lib/util/canvas.js +8 -0
- package/lib/util/canvas.js.map +1 -1
- package/lib/util/data.d.ts +65 -0
- package/lib/util/data.js +161 -0
- package/lib/util/data.js.map +1 -0
- package/lib/util/event.d.ts +8 -0
- package/lib/util/event.js +18 -1
- package/lib/util/event.js.map +1 -1
- package/lib/util/item.d.ts +2 -1
- package/lib/util/item.js +36 -13
- package/lib/util/item.js.map +1 -1
- package/lib/util/shape.d.ts +39 -4
- package/lib/util/shape.js +105 -2
- package/lib/util/shape.js.map +1 -1
- package/lib/util/zoom.d.ts +2 -2
- package/package.json +13 -13
- package/src/item/combo.ts +220 -2
- package/src/item/edge.ts +7 -8
- package/src/item/item.ts +58 -15
- package/src/item/node.ts +47 -24
- package/src/runtime/controller/data.ts +390 -68
- package/src/runtime/controller/interaction.ts +23 -3
- package/src/runtime/controller/item.ts +444 -64
- package/src/runtime/controller/layout.ts +24 -5
- package/src/runtime/graph.ts +225 -38
- package/src/stdlib/behavior/click-select.ts +15 -2
- package/src/stdlib/behavior/collapse-expand-combo.ts +59 -0
- package/src/stdlib/behavior/drag-combo.ts +533 -0
- package/src/stdlib/behavior/drag-node.ts +195 -62
- package/src/stdlib/behavior/hover-activate.ts +4 -5
- package/src/stdlib/behavior/orbit-canvas-3d.ts +1 -1
- package/src/stdlib/behavior/track-canvas-3d.ts +1 -1
- package/src/stdlib/index.ts +25 -3
- package/src/stdlib/item/combo/circle.ts +113 -0
- package/src/stdlib/item/edge/base.ts +5 -2
- package/src/stdlib/item/edge/cubic-horizon.ts +114 -0
- package/src/stdlib/item/edge/cubic-vertical.ts +116 -0
- package/src/stdlib/item/edge/cubic.ts +198 -0
- package/src/stdlib/item/edge/index.ts +1 -0
- package/src/stdlib/item/edge/quadratic.ts +136 -0
- package/src/stdlib/item/node/base.ts +79 -41
- package/src/stdlib/item/node/index.ts +1 -0
- package/src/stdlib/item/node/rect.ts +124 -0
- package/src/stdlib/plugin/fisheye/index.ts +578 -0
- package/src/stdlib/plugin/menu/index.ts +260 -0
- package/src/stdlib/plugin/tooltip/index.ts +424 -0
- package/src/stdlib/theme/dark.ts +4 -0
- package/src/stdlib/theme/light.ts +77 -9
- package/src/types/combo.ts +61 -3
- package/src/types/data.ts +6 -4
- package/src/types/edge.ts +2 -2
- package/src/types/event.ts +8 -8
- package/src/types/graph.ts +73 -16
- package/src/types/hook.ts +8 -1
- package/src/types/item.ts +10 -9
- package/src/types/node.ts +4 -4
- package/src/types/theme.ts +1 -1
- package/src/util/animate.ts +2 -3
- package/src/util/canvas.ts +10 -0
- package/src/util/data.ts +178 -0
- package/src/util/event.ts +29 -0
- package/src/util/item.ts +75 -12
- package/src/util/shape.ts +142 -5
- package/src/util/zoom.ts +2 -2
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { isString } from '@antv/util';
|
|
2
|
+
import { createDom, modifyCSS } from '@antv/dom-util';
|
|
3
|
+
import Item from 'item/item';
|
|
4
|
+
import insertCss from 'insert-css';
|
|
5
|
+
import { IGraph } from '../../../types';
|
|
6
|
+
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
7
|
+
import { IG6GraphEvent } from '../../../types/event';
|
|
8
|
+
typeof document !== 'undefined' &&
|
|
9
|
+
insertCss(`
|
|
10
|
+
.g6-component-contextmenu {
|
|
11
|
+
border: 1px solid #e2e2e2;
|
|
12
|
+
border-radius: 4px;
|
|
13
|
+
font-size: 12px;
|
|
14
|
+
color: #545454;
|
|
15
|
+
background-color: rgba(255, 255, 255, 0.9);
|
|
16
|
+
padding: 10px 8px;
|
|
17
|
+
box-shadow: rgb(174, 174, 174) 0px 0px 10px;
|
|
18
|
+
}
|
|
19
|
+
.g6-contextmenu-ul {
|
|
20
|
+
padding: 0;
|
|
21
|
+
margin: 0;
|
|
22
|
+
list-style: none;
|
|
23
|
+
}
|
|
24
|
+
.g6-loading-dom {
|
|
25
|
+
border: 5px solid #e5e5e5;
|
|
26
|
+
border-top: 5px solid #227EFF;
|
|
27
|
+
border-radius: 50%;
|
|
28
|
+
width: 25px;
|
|
29
|
+
height: 25px;
|
|
30
|
+
animation: turn-around 1.5s linear infinite;
|
|
31
|
+
}
|
|
32
|
+
@keyframes turn-around {
|
|
33
|
+
0% { transform: rotate(0deg); }
|
|
34
|
+
100% { transform: rotate(360deg); }
|
|
35
|
+
}
|
|
36
|
+
`);
|
|
37
|
+
|
|
38
|
+
interface MenuConfig extends IPluginBaseConfig {
|
|
39
|
+
handleMenuClick?: (target: HTMLElement, item: Item) => void;
|
|
40
|
+
// return the content of menu, support the `Promise` type return value.
|
|
41
|
+
getContent?: (
|
|
42
|
+
evt?: IG6GraphEvent,
|
|
43
|
+
) => HTMLDivElement | string | Promise<HTMLDivElement | string>;
|
|
44
|
+
offsetX?: number;
|
|
45
|
+
offsetY?: number;
|
|
46
|
+
shouldBegin?: (evt?: IG6GraphEvent) => boolean;
|
|
47
|
+
itemTypes?: string[];
|
|
48
|
+
trigger?: 'click' | 'contextmenu';
|
|
49
|
+
onHide?: () => boolean;
|
|
50
|
+
//loading Dom
|
|
51
|
+
loadingContent?: HTMLDivElement | string;
|
|
52
|
+
liHoverStyle?: { [key: string]: string };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default class Menu extends Base {
|
|
56
|
+
private menu;
|
|
57
|
+
private handleMenuClickWrapper;
|
|
58
|
+
private handler;
|
|
59
|
+
private currentTarget;
|
|
60
|
+
private asyncMenu;
|
|
61
|
+
constructor(options?: MenuConfig) {
|
|
62
|
+
super(options);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public getDefaultCfgs(): MenuConfig {
|
|
66
|
+
return {
|
|
67
|
+
offsetX: 6,
|
|
68
|
+
offsetY: 6,
|
|
69
|
+
handleMenuClick: undefined,
|
|
70
|
+
getContent: (e) => {
|
|
71
|
+
return `
|
|
72
|
+
<ul class='g6-contextmenu-ul'>
|
|
73
|
+
<li class='g6-contextmenu-li'>菜单项1</li>
|
|
74
|
+
<li class='g6-contextmenu-li'>菜单项2</li>
|
|
75
|
+
</ul>
|
|
76
|
+
`;
|
|
77
|
+
},
|
|
78
|
+
shouldBegin: (e) => {
|
|
79
|
+
return true;
|
|
80
|
+
},
|
|
81
|
+
// hide menu
|
|
82
|
+
onHide: () => {
|
|
83
|
+
return true;
|
|
84
|
+
},
|
|
85
|
+
itemTypes: ['node', 'edge', 'combo'],
|
|
86
|
+
trigger: 'click',
|
|
87
|
+
container: null,
|
|
88
|
+
loadingContent: `<div class='g6-loading-dom'></div>`,
|
|
89
|
+
liHoverStyle: {
|
|
90
|
+
color: 'white',
|
|
91
|
+
'background-color': '#227EFF',
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public getEvents() {
|
|
97
|
+
return this.options.trigger === 'click'
|
|
98
|
+
? { click: this.onMenuShow, touchend: this.onMenuShow }
|
|
99
|
+
: { contextmenu: this.onMenuShow };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public init(graph: IGraph) {
|
|
103
|
+
super.init(graph);
|
|
104
|
+
const className = this.options.className;
|
|
105
|
+
insertCss(`
|
|
106
|
+
.g6-contextmenu-li:hover{
|
|
107
|
+
${Object.keys(this.options.liHoverStyle)
|
|
108
|
+
.map((k) => {
|
|
109
|
+
return `${k}:${this.options.liHoverStyle[k]};`;
|
|
110
|
+
})
|
|
111
|
+
.join('')}
|
|
112
|
+
}
|
|
113
|
+
`);
|
|
114
|
+
const menu = createDom(
|
|
115
|
+
`<div class=${className || 'g6-component-contextmenu'}></div>`,
|
|
116
|
+
);
|
|
117
|
+
modifyCSS(menu, { top: '0px', position: 'absolute', visibility: 'hidden' });
|
|
118
|
+
let container: HTMLDivElement | null | string = this.options.container;
|
|
119
|
+
if (!container) {
|
|
120
|
+
container = this.graph.container as HTMLDivElement;
|
|
121
|
+
}
|
|
122
|
+
if (isString(container)) {
|
|
123
|
+
container = document.getElementById(container) as HTMLDivElement;
|
|
124
|
+
}
|
|
125
|
+
container.appendChild(menu);
|
|
126
|
+
this.menu = menu;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
protected async onMenuShow(e: IG6GraphEvent) {
|
|
130
|
+
const self = this;
|
|
131
|
+
e.preventDefault();
|
|
132
|
+
self.onMenuHide();
|
|
133
|
+
const itemTypes = this.options.itemTypes;
|
|
134
|
+
if (!e.itemId) {
|
|
135
|
+
if (itemTypes.indexOf('canvas') === -1) {
|
|
136
|
+
self.onMenuHide();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
if (e.itemId && e.itemType && itemTypes.indexOf(e.itemType) === -1) {
|
|
141
|
+
self.onMenuHide();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const shouldBegin = this.options.shouldBegin;
|
|
147
|
+
if (!shouldBegin(e)) return;
|
|
148
|
+
const menuDom = this.menu;
|
|
149
|
+
const graph = this.graph;
|
|
150
|
+
const menu = this.options.getContent(e);
|
|
151
|
+
|
|
152
|
+
const width: number = graph.getSize()[0];
|
|
153
|
+
const height: number = graph.getSize()[1];
|
|
154
|
+
const bbox = menuDom.getBoundingClientRect();
|
|
155
|
+
const offsetX = this.options.offsetX || 0;
|
|
156
|
+
const offsetY = this.options.offsetY || 0;
|
|
157
|
+
const graphTop = this.graph.container.offsetTop;
|
|
158
|
+
const graphLeft = this.graph.container.offsetLeft;
|
|
159
|
+
let x = e.viewport.x + graphLeft + offsetX;
|
|
160
|
+
let y = e.viewport.y + graphTop + offsetY;
|
|
161
|
+
|
|
162
|
+
// when the menu is (part of) out of the canvas
|
|
163
|
+
if (x + bbox.width > width) {
|
|
164
|
+
x -= bbox.width + graphLeft + offsetX;
|
|
165
|
+
}
|
|
166
|
+
if (y + bbox.height > height) {
|
|
167
|
+
y -= bbox.height + graphTop + offsetY;
|
|
168
|
+
}
|
|
169
|
+
modifyCSS(menuDom, {
|
|
170
|
+
top: `${y}px`,
|
|
171
|
+
left: `${x}px`,
|
|
172
|
+
visibility: 'visible',
|
|
173
|
+
});
|
|
174
|
+
if (isString(menu)) {
|
|
175
|
+
//the type is string
|
|
176
|
+
menuDom.innerHTML = menu;
|
|
177
|
+
} else if (menu instanceof HTMLDivElement) {
|
|
178
|
+
//the type is htmldom
|
|
179
|
+
menuDom.innerHTML = menu.outerHTML;
|
|
180
|
+
} else {
|
|
181
|
+
//the type is Promise
|
|
182
|
+
if (isString(this.options.loadingContent)) {
|
|
183
|
+
menuDom.innerHTML = this.options.loadingContent;
|
|
184
|
+
} else {
|
|
185
|
+
menuDom.innerHTML = this.options.loadingContent.outerHTML;
|
|
186
|
+
}
|
|
187
|
+
if (e.itemId != this.currentTarget || !this.asyncMenu) {
|
|
188
|
+
this.currentTarget = e.itemId;
|
|
189
|
+
this.asyncMenu = await this.options.getContent(e);
|
|
190
|
+
}
|
|
191
|
+
if (e.itemId != this.currentTarget) {
|
|
192
|
+
//The menu is not displayed, if `itemId` is unmatched.
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (isString(this.asyncMenu)) {
|
|
196
|
+
menuDom.innerHTML = this.asyncMenu;
|
|
197
|
+
} else {
|
|
198
|
+
menuDom.innerHTML = this.asyncMenu.outerHTML;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
this.removeMenuEventListener();
|
|
202
|
+
|
|
203
|
+
const handleMenuClick = this.options.handleMenuClick;
|
|
204
|
+
if (handleMenuClick) {
|
|
205
|
+
this.handleMenuClickWrapper = (event) => {
|
|
206
|
+
handleMenuClick(event.target, e.itemId, graph);
|
|
207
|
+
};
|
|
208
|
+
menuDom.addEventListener('click', this.handleMenuClickWrapper);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
let triggeredByFirstClick = this.options.trigger === 'click';
|
|
212
|
+
const handler = (e) => {
|
|
213
|
+
if (triggeredByFirstClick) {
|
|
214
|
+
triggeredByFirstClick = false;
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
self.onMenuHide();
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
document.body.addEventListener('click', handler);
|
|
221
|
+
this.handler = handler;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private removeMenuEventListener() {
|
|
225
|
+
const handleMenuClickWrapper = this.handleMenuClickWrapper;
|
|
226
|
+
const handler = this.handler;
|
|
227
|
+
|
|
228
|
+
if (handleMenuClickWrapper) {
|
|
229
|
+
const menuDom = this.menu;
|
|
230
|
+
menuDom.removeEventListener('click', handleMenuClickWrapper);
|
|
231
|
+
this.handleMenuClickWrapper = null;
|
|
232
|
+
}
|
|
233
|
+
if (handler) {
|
|
234
|
+
document.body.removeEventListener('click', handler);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private onMenuHide() {
|
|
239
|
+
const menuDom = this.menu;
|
|
240
|
+
if (menuDom) {
|
|
241
|
+
modifyCSS(menuDom, { visibility: 'hidden' });
|
|
242
|
+
this.removeMenuEventListener();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
public destroy() {
|
|
247
|
+
const menu = this.menu;
|
|
248
|
+
this.removeMenuEventListener();
|
|
249
|
+
if (menu) {
|
|
250
|
+
let container = this.options.container;
|
|
251
|
+
if (!container) {
|
|
252
|
+
container = this.graph.container as HTMLDivElement;
|
|
253
|
+
}
|
|
254
|
+
if (isString(container)) {
|
|
255
|
+
container = document.getElementById(container) as HTMLDivElement;
|
|
256
|
+
}
|
|
257
|
+
container.removeChild(menu);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
// TODO: update type define.
|
|
2
|
+
import { isString, isArray } from '@antv/util';
|
|
3
|
+
import { createDom, modifyCSS } from '@antv/dom-util';
|
|
4
|
+
import insertCss from 'insert-css';
|
|
5
|
+
import { AABB } from '@antv/g';
|
|
6
|
+
import { IGraph } from '../../../types';
|
|
7
|
+
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
8
|
+
import { IG6GraphEvent } from '../../../types/event';
|
|
9
|
+
|
|
10
|
+
typeof document !== 'undefined' &&
|
|
11
|
+
insertCss(`
|
|
12
|
+
.g6-component-tooltip {
|
|
13
|
+
border: 1px solid #e2e2e2;
|
|
14
|
+
border-radius: 4px;
|
|
15
|
+
font-size: 12px;
|
|
16
|
+
color: #545454;
|
|
17
|
+
background-color: rgba(255, 255, 255, 0.9);
|
|
18
|
+
padding: 10px 8px;
|
|
19
|
+
box-shadow: rgb(174, 174, 174) 0px 0px 10px;
|
|
20
|
+
}
|
|
21
|
+
.tooltip-type {
|
|
22
|
+
padding: 0;
|
|
23
|
+
margin: 0;
|
|
24
|
+
}
|
|
25
|
+
.tooltip-id {
|
|
26
|
+
color: #531dab;
|
|
27
|
+
}
|
|
28
|
+
.g6-loading-dom {
|
|
29
|
+
border: 5px solid #e5e5e5;
|
|
30
|
+
border-top: 5px solid #227EFF;
|
|
31
|
+
border-radius: 50%;
|
|
32
|
+
width: 25px;
|
|
33
|
+
height: 25px;
|
|
34
|
+
animation: turn-around 1.5s linear infinite;
|
|
35
|
+
}
|
|
36
|
+
@keyframes turn-around {
|
|
37
|
+
0% { transform: rotate(0deg); }
|
|
38
|
+
100% { transform: rotate(360deg); }
|
|
39
|
+
}
|
|
40
|
+
`);
|
|
41
|
+
|
|
42
|
+
type Placement =
|
|
43
|
+
| 'top'
|
|
44
|
+
| 'left'
|
|
45
|
+
| 'right'
|
|
46
|
+
| 'bottom'
|
|
47
|
+
| 'topLeft'
|
|
48
|
+
| 'leftTop'
|
|
49
|
+
| 'topRight'
|
|
50
|
+
| 'rightTop'
|
|
51
|
+
| 'bottomLeft'
|
|
52
|
+
| 'leftBottom'
|
|
53
|
+
| 'bottomRight'
|
|
54
|
+
| 'rightBottom';
|
|
55
|
+
|
|
56
|
+
interface TooltipConfig extends IPluginBaseConfig {
|
|
57
|
+
getContent?: (
|
|
58
|
+
evt?: IG6GraphEvent,
|
|
59
|
+
) => HTMLDivElement | string | Promise<HTMLDivElement | string>;
|
|
60
|
+
offsetX?: number;
|
|
61
|
+
offsetY?: number;
|
|
62
|
+
shouldBegin?: (evt?: IG6GraphEvent) => boolean;
|
|
63
|
+
// more detail type instead of "string[]"
|
|
64
|
+
itemTypes?: ('node' | 'edge' | 'combo' | 'canvas')[];
|
|
65
|
+
trigger?: 'pointerenter' | 'click';
|
|
66
|
+
fixToNode?: [number, number] | Placement | undefined;
|
|
67
|
+
loadingContent?: HTMLDivElement | string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default class Tooltip extends Base {
|
|
71
|
+
private tooltip;
|
|
72
|
+
private container;
|
|
73
|
+
private currentTarget;
|
|
74
|
+
private asyncTooltip;
|
|
75
|
+
private currentAsyncTarget;
|
|
76
|
+
private hidenTimer; //delay hiding tooltip
|
|
77
|
+
|
|
78
|
+
constructor(options?: TooltipConfig) {
|
|
79
|
+
super(options);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public getDefaultCfgs(): TooltipConfig {
|
|
83
|
+
return {
|
|
84
|
+
offsetX: 0,
|
|
85
|
+
offsetY: 0,
|
|
86
|
+
getContent: (e) => {
|
|
87
|
+
return `
|
|
88
|
+
<div>
|
|
89
|
+
<h4 class='tooltip-type'>类型: ${e.itemType}</h4>
|
|
90
|
+
<span class='tooltip-id'>ID: ${e.itemId}</span>
|
|
91
|
+
</div>
|
|
92
|
+
`;
|
|
93
|
+
},
|
|
94
|
+
shouldBegin: (e) => {
|
|
95
|
+
return true;
|
|
96
|
+
},
|
|
97
|
+
itemTypes: ['node', 'edge', 'combo'],
|
|
98
|
+
trigger: 'pointerenter',
|
|
99
|
+
fixToNode: undefined,
|
|
100
|
+
loadingContent: `<div class='g6-loading-dom'></div>`,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public getEvents() {
|
|
105
|
+
if (this.options.trigger === 'click') {
|
|
106
|
+
return {
|
|
107
|
+
'node:click': this.onClick,
|
|
108
|
+
'edge:click': this.onClick,
|
|
109
|
+
'combo:click': this.onClick,
|
|
110
|
+
'canvas:click': this.onPointerLeave,
|
|
111
|
+
afterremoveitem: this.onPointerLeave,
|
|
112
|
+
contextmenu: this.onPointerLeave,
|
|
113
|
+
drag: this.onPointerLeave,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
'node:pointerenter': this.onPointerEnter,
|
|
119
|
+
'node:pointerleave': this.onPointerLeave,
|
|
120
|
+
'node:pointermove': this.onPointerMove,
|
|
121
|
+
'edge:pointerenter': this.onPointerEnter,
|
|
122
|
+
'edge:pointerleave': this.onPointerLeave,
|
|
123
|
+
'edge:pointermove': this.onPointerMove,
|
|
124
|
+
'combo:pointerenter': this.onPointerEnter,
|
|
125
|
+
'combo:pointerleave': this.onPointerLeave,
|
|
126
|
+
'combo:pointermove': this.onPointerMove,
|
|
127
|
+
afterremoveitem: this.onPointerLeave,
|
|
128
|
+
contextmenu: this.onPointerLeave,
|
|
129
|
+
'node:drag': this.onPointerLeave,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public init(graph: IGraph) {
|
|
134
|
+
super.init(graph);
|
|
135
|
+
const className = this.options.className;
|
|
136
|
+
const tooltip = createDom(
|
|
137
|
+
`<div class='${className || 'g6-component-tooltip'}'></div>`,
|
|
138
|
+
);
|
|
139
|
+
modifyCSS(tooltip, {
|
|
140
|
+
position: 'absolute',
|
|
141
|
+
visibility: 'hidden',
|
|
142
|
+
display: 'none',
|
|
143
|
+
});
|
|
144
|
+
if (this.options.trigger !== 'click') {
|
|
145
|
+
tooltip.addEventListener('pointerenter', (e) => {
|
|
146
|
+
modifyCSS(tooltip, {
|
|
147
|
+
visibility: 'visible',
|
|
148
|
+
display: 'unset',
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
tooltip.addEventListener('pointerleave', (e) => {
|
|
152
|
+
this.hideTooltip();
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
//`container` string type in v5
|
|
156
|
+
let container: HTMLDivElement | null | string = this.options.container;
|
|
157
|
+
if (!container) {
|
|
158
|
+
container = this.graph.container as HTMLDivElement;
|
|
159
|
+
}
|
|
160
|
+
if (isString(container)) {
|
|
161
|
+
container = document.getElementById(container) as HTMLDivElement;
|
|
162
|
+
}
|
|
163
|
+
container.appendChild(tooltip);
|
|
164
|
+
this.tooltip = tooltip;
|
|
165
|
+
this.container = container;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public onClick(e: IG6GraphEvent) {
|
|
169
|
+
if (
|
|
170
|
+
e.itemId &&
|
|
171
|
+
e.itemType &&
|
|
172
|
+
this.options.itemTypes.indexOf(e.itemType) === -1
|
|
173
|
+
)
|
|
174
|
+
return;
|
|
175
|
+
const { itemId } = e;
|
|
176
|
+
// click the same item twice, tooltip will be hidden
|
|
177
|
+
if (this.currentTarget === itemId) {
|
|
178
|
+
this.currentTarget = null;
|
|
179
|
+
this.hideTooltip();
|
|
180
|
+
this.graph.emit('tooltipchange', { itemId: itemId, action: 'hide' });
|
|
181
|
+
} else {
|
|
182
|
+
this.currentTarget = itemId;
|
|
183
|
+
this.showTooltip(e);
|
|
184
|
+
// this.graph.emit('tooltipchange', { itemId: itemId, action: 'show' });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public onPointerEnter(e: IG6GraphEvent) {
|
|
189
|
+
if (
|
|
190
|
+
e.itemId &&
|
|
191
|
+
e.itemType &&
|
|
192
|
+
this.options.itemTypes.indexOf(e.itemType) === -1
|
|
193
|
+
)
|
|
194
|
+
return;
|
|
195
|
+
const { itemId } = e;
|
|
196
|
+
this.currentTarget = itemId;
|
|
197
|
+
this.showTooltip(e);
|
|
198
|
+
this.graph.emit('tooltipchange', { itemId: e.itemId, action: 'show' });
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public onPointerMove(e: IG6GraphEvent) {
|
|
202
|
+
if (
|
|
203
|
+
e.itemId &&
|
|
204
|
+
e.itemType &&
|
|
205
|
+
this.options.itemTypes.indexOf(e.itemType) === -1
|
|
206
|
+
)
|
|
207
|
+
return;
|
|
208
|
+
if (!this.currentTarget || e.itemId === this.currentTarget) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
this.showTooltip(e);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public onPointerLeave() {
|
|
215
|
+
this.hideTooltip();
|
|
216
|
+
this.graph.emit('tooltipchange', {
|
|
217
|
+
itemId: this.currentTarget,
|
|
218
|
+
action: 'hide',
|
|
219
|
+
});
|
|
220
|
+
this.currentTarget = null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public clearContainer() {
|
|
224
|
+
this.container.innerHTML = '';
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
public async showTooltip(e: IG6GraphEvent) {
|
|
228
|
+
clearTimeout(this.hidenTimer);
|
|
229
|
+
if (!e.itemId) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (e.itemType && this.options.itemTypes.indexOf(e.itemType) === -1) return;
|
|
233
|
+
const tooltip = this.options.getContent(e);
|
|
234
|
+
const tooltipDom = this.tooltip;
|
|
235
|
+
// modify the position first because of the async function
|
|
236
|
+
modifyCSS(tooltipDom, {
|
|
237
|
+
display: 'unset',
|
|
238
|
+
});
|
|
239
|
+
const res = this.updatePosition(e);
|
|
240
|
+
modifyCSS(tooltipDom, {
|
|
241
|
+
visibility: 'visible',
|
|
242
|
+
left: `${res.x}px`,
|
|
243
|
+
top: `${res.y}px`,
|
|
244
|
+
});
|
|
245
|
+
if (isString(tooltip)) {
|
|
246
|
+
tooltipDom.innerHTML = tooltip;
|
|
247
|
+
} else if (tooltip instanceof HTMLDivElement) {
|
|
248
|
+
this.clearContainer();
|
|
249
|
+
this.container.appendChild(tooltip);
|
|
250
|
+
} else {
|
|
251
|
+
//promise type
|
|
252
|
+
this.asyncTooltip = null; //avoid trigger many time
|
|
253
|
+
if (isString(this.options.loadingContent)) {
|
|
254
|
+
tooltipDom.innerHTML = this.options.loadingContent;
|
|
255
|
+
} else {
|
|
256
|
+
tooltipDom.innerHTML = this.options.loadingContent.outerHTML;
|
|
257
|
+
}
|
|
258
|
+
if (!this.asyncTooltip || e.itemId !== this.currentAsyncTarget) {
|
|
259
|
+
this.currentAsyncTarget = e.itemId;
|
|
260
|
+
this.asyncTooltip = await this.options.getContent(e);
|
|
261
|
+
}
|
|
262
|
+
if (e.itemId != this.currentAsyncTarget) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (isString(this.asyncTooltip)) {
|
|
266
|
+
tooltipDom.innerHTML = this.asyncTooltip;
|
|
267
|
+
} else {
|
|
268
|
+
this.clearContainer();
|
|
269
|
+
this.container.appendChild(this.asyncTooltip);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
public hideTooltip() {
|
|
275
|
+
const tooltip = this.tooltip;
|
|
276
|
+
if (tooltip) {
|
|
277
|
+
this.hidenTimer = setTimeout(() => {
|
|
278
|
+
modifyCSS(tooltip, { visibility: 'hidden', display: 'none' });
|
|
279
|
+
}, 100);
|
|
280
|
+
tooltip.addEventListener('pointerenter', (e) => {
|
|
281
|
+
clearTimeout(this.hidenTimer);
|
|
282
|
+
});
|
|
283
|
+
tooltip.addEventListener('pointerleave', (e) => {
|
|
284
|
+
modifyCSS(tooltip, { visibility: 'hidden', display: 'none' });
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
public updatePosition(e: IG6GraphEvent): { x: number; y: number } {
|
|
290
|
+
const shouldBegin = this.options.shouldBegin;
|
|
291
|
+
const tooltip = this.tooltip;
|
|
292
|
+
if (!shouldBegin(e)) {
|
|
293
|
+
modifyCSS(tooltip, {
|
|
294
|
+
visibility: 'hidden',
|
|
295
|
+
display: 'none',
|
|
296
|
+
});
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const graph: IGraph = this.graph;
|
|
300
|
+
const width: number = graph.getSize()[0];
|
|
301
|
+
const height: number = graph.getSize()[1];
|
|
302
|
+
const offsetX = this.options.offsetX || 0;
|
|
303
|
+
const offsetY = this.options.offsetY || 0;
|
|
304
|
+
let point = {
|
|
305
|
+
x: e.viewport.x,
|
|
306
|
+
y: e.viewport.y,
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const fixToNode = this.options.fixToNode;
|
|
310
|
+
//handle `fixToNode` config
|
|
311
|
+
if (e.itemType && e.itemType === 'node' && fixToNode) {
|
|
312
|
+
const itemBBox = graph.getRenderBBox(e.itemId) as AABB;
|
|
313
|
+
const itemWidth = itemBBox.max[0] - itemBBox.min[0];
|
|
314
|
+
const itemHeight = itemBBox.max[1] - itemBBox.min[1];
|
|
315
|
+
if (isString(fixToNode)) {
|
|
316
|
+
switch (fixToNode) {
|
|
317
|
+
case 'right': {
|
|
318
|
+
point = {
|
|
319
|
+
x: itemBBox.min[0] + itemWidth * 1,
|
|
320
|
+
y: itemBBox.min[1] + itemHeight * 0.5,
|
|
321
|
+
};
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
case 'rightTop':
|
|
325
|
+
case 'topRight': {
|
|
326
|
+
point = {
|
|
327
|
+
x: itemBBox.min[0] + itemWidth * 1,
|
|
328
|
+
y: itemBBox.min[1] + itemHeight * 0,
|
|
329
|
+
};
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
case 'rightBottom':
|
|
333
|
+
case 'bottomRight': {
|
|
334
|
+
point = {
|
|
335
|
+
x: itemBBox.min[0] + itemWidth * 1,
|
|
336
|
+
y: itemBBox.min[1] + itemHeight * 1,
|
|
337
|
+
};
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
case 'bottom': {
|
|
341
|
+
point = {
|
|
342
|
+
x: itemBBox.min[0] + itemWidth * 0,
|
|
343
|
+
y: itemBBox.min[1] + itemHeight * 1,
|
|
344
|
+
};
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
case 'top': {
|
|
348
|
+
const tooltipBBox = tooltip.getBoundingClientRect();
|
|
349
|
+
point = {
|
|
350
|
+
x: itemBBox.min[0] + itemWidth * 0,
|
|
351
|
+
y: itemBBox.min[1] - tooltipBBox.height,
|
|
352
|
+
};
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
case 'left': {
|
|
356
|
+
const tooltipBBox = tooltip.getBoundingClientRect();
|
|
357
|
+
point = {
|
|
358
|
+
x: itemBBox.min[0] - tooltipBBox.width,
|
|
359
|
+
y: itemBBox.min[1] + itemHeight * 0.5,
|
|
360
|
+
};
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
case 'leftTop':
|
|
364
|
+
case 'topLeft': {
|
|
365
|
+
const tooltipBBox = tooltip.getBoundingClientRect();
|
|
366
|
+
point = {
|
|
367
|
+
x: itemBBox.min[0] - tooltipBBox.width,
|
|
368
|
+
y: itemBBox.min[1] + itemHeight * 0,
|
|
369
|
+
};
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
case 'leftBottom':
|
|
373
|
+
case 'bottomLeft': {
|
|
374
|
+
const tooltipBBox = tooltip.getBoundingClientRect();
|
|
375
|
+
point = {
|
|
376
|
+
x: itemBBox.min[0] - tooltipBBox.width,
|
|
377
|
+
y: itemBBox.min[1] + itemHeight * 1,
|
|
378
|
+
};
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
default:
|
|
382
|
+
//right
|
|
383
|
+
point = {
|
|
384
|
+
x: itemBBox.min[0] + itemWidth * 1,
|
|
385
|
+
y: itemBBox.min[1] + itemHeight * 0.5,
|
|
386
|
+
};
|
|
387
|
+
console.warn(
|
|
388
|
+
`The '${this.options.fixToNode}' fixToNode position configuration is not supported, please use 'top'|'left'| 'right'| 'bottom'| 'topLeft'| 'leftTop'| 'topRight'| 'rightTop'| 'bottomLeft'| 'leftBottom'| 'bottomRight'| 'rightBottom', or use array to config, like: [0,5,1]`,
|
|
389
|
+
);
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
} else if (isArray(fixToNode) && fixToNode.length >= 2) {
|
|
393
|
+
point = {
|
|
394
|
+
x: itemBBox.min[0] + itemWidth * fixToNode[0],
|
|
395
|
+
y: itemBBox.min[1] + itemHeight * fixToNode[1],
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const { x, y } = point;
|
|
401
|
+
const graphContainer = this.graph.container;
|
|
402
|
+
const res = {
|
|
403
|
+
x: x + graphContainer.offsetLeft + offsetX,
|
|
404
|
+
y: y + graphContainer.offsetTop + offsetY,
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
//tooltip dom bbox
|
|
408
|
+
const bbox = tooltip.getBoundingClientRect();
|
|
409
|
+
if (x + bbox.width + offsetX > width) {
|
|
410
|
+
res.x -= bbox.width + offsetX;
|
|
411
|
+
}
|
|
412
|
+
if (y + bbox.height + offsetY > height) {
|
|
413
|
+
res.y -= bbox.height + offsetY;
|
|
414
|
+
if (res.y < 0) {
|
|
415
|
+
res.y = 0;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return res;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
public destroy() {
|
|
422
|
+
this.container.removeChild(this.tooltip);
|
|
423
|
+
}
|
|
424
|
+
}
|
package/src/stdlib/theme/dark.ts
CHANGED
|
@@ -106,6 +106,7 @@ export default {
|
|
|
106
106
|
opacity: 0.45,
|
|
107
107
|
lineWidth: 20,
|
|
108
108
|
zIndex: -1,
|
|
109
|
+
pointerEvents: 'none',
|
|
109
110
|
visible: true,
|
|
110
111
|
},
|
|
111
112
|
},
|
|
@@ -117,6 +118,7 @@ export default {
|
|
|
117
118
|
opacity: 0.25,
|
|
118
119
|
lineWidth: 20,
|
|
119
120
|
zIndex: -1,
|
|
121
|
+
pointerEvents: 'none',
|
|
120
122
|
visible: true,
|
|
121
123
|
},
|
|
122
124
|
},
|
|
@@ -235,6 +237,7 @@ export default {
|
|
|
235
237
|
opacity: 0.25,
|
|
236
238
|
lineWidth: 12,
|
|
237
239
|
zIndex: -1,
|
|
240
|
+
pointerEvents: 'none',
|
|
238
241
|
visible: true,
|
|
239
242
|
},
|
|
240
243
|
},
|
|
@@ -246,6 +249,7 @@ export default {
|
|
|
246
249
|
opacity: 0.25,
|
|
247
250
|
lineWidth: 12,
|
|
248
251
|
zIndex: -1,
|
|
252
|
+
pointerEvents: 'none',
|
|
249
253
|
visible: true,
|
|
250
254
|
},
|
|
251
255
|
},
|