@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,578 @@
|
|
|
1
|
+
import { clone, throttle } from '@antv/util';
|
|
2
|
+
import { DisplayObject } from '@antv/g';
|
|
3
|
+
import { Point } from '../../../types/common';
|
|
4
|
+
import { IGraph } from '../../../types';
|
|
5
|
+
import { ShapeStyle } from '../../../types/item';
|
|
6
|
+
import { IG6GraphEvent } from '../../../types/event';
|
|
7
|
+
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
8
|
+
|
|
9
|
+
const DELTA = 0.05;
|
|
10
|
+
|
|
11
|
+
interface FisheyeConfig extends IPluginBaseConfig {
|
|
12
|
+
trigger?: 'mousemove' | 'click' | 'drag';
|
|
13
|
+
d?: number;
|
|
14
|
+
r?: number;
|
|
15
|
+
delegateStyle?: ShapeStyle;
|
|
16
|
+
showLabel?: boolean;
|
|
17
|
+
scaleRBy?: 'wheel' | 'drag' | 'unset' | undefined;
|
|
18
|
+
scaleDBy?: 'wheel' | 'drag' | 'unset' | undefined;
|
|
19
|
+
maxR?: number;
|
|
20
|
+
minR?: number;
|
|
21
|
+
maxD?: number;
|
|
22
|
+
minD?: number;
|
|
23
|
+
throttle?: number;
|
|
24
|
+
showDPercent?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const lensDelegateStyle = {
|
|
28
|
+
stroke: '#000',
|
|
29
|
+
strokeOpacity: 0.8,
|
|
30
|
+
lineWidth: 2,
|
|
31
|
+
fillOpacity: 0.1,
|
|
32
|
+
fill: '#ccc',
|
|
33
|
+
};
|
|
34
|
+
export default class Fisheye extends Base {
|
|
35
|
+
private pointerDown: Point | undefined = undefined;
|
|
36
|
+
private cacheCenter: Point | undefined = undefined;
|
|
37
|
+
private dragPrePos: Point | undefined = undefined;
|
|
38
|
+
private dragging = false;
|
|
39
|
+
private molecularParam: number;
|
|
40
|
+
private dPercentText: DisplayObject;
|
|
41
|
+
private delegate: DisplayObject;
|
|
42
|
+
private r2: number;
|
|
43
|
+
|
|
44
|
+
private cachedOriginPositions: {
|
|
45
|
+
[id: string]: {
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
texts: DisplayObject[];
|
|
49
|
+
};
|
|
50
|
+
} = {};
|
|
51
|
+
|
|
52
|
+
private cachedTransientTexts: {
|
|
53
|
+
[id: string]: DisplayObject;
|
|
54
|
+
} = {};
|
|
55
|
+
|
|
56
|
+
private delegateCenterDiff: { x: number; y: number };
|
|
57
|
+
|
|
58
|
+
constructor(options?: FisheyeConfig) {
|
|
59
|
+
super(options);
|
|
60
|
+
}
|
|
61
|
+
public getDefaultCfgs(): FisheyeConfig {
|
|
62
|
+
return {
|
|
63
|
+
trigger: 'mousemove',
|
|
64
|
+
d: 1.5,
|
|
65
|
+
r: 300,
|
|
66
|
+
delegateStyle: clone(lensDelegateStyle),
|
|
67
|
+
showLabel: true,
|
|
68
|
+
maxD: 5,
|
|
69
|
+
minD: 0,
|
|
70
|
+
throttle: 16,
|
|
71
|
+
scaleRBy: 'drag',
|
|
72
|
+
scaleDBy: 'drag',
|
|
73
|
+
showDPercent: true,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// class-methods-use-this
|
|
78
|
+
public getEvents() {
|
|
79
|
+
const events = {
|
|
80
|
+
pointerdown: this.onPointerDown,
|
|
81
|
+
pointerup: this.onPointerUp,
|
|
82
|
+
wheel: this.onWheel,
|
|
83
|
+
afterlayout: this.initOriginPositions,
|
|
84
|
+
} as {
|
|
85
|
+
[key: string]: any;
|
|
86
|
+
};
|
|
87
|
+
switch ((this as any).options.trigger) {
|
|
88
|
+
case 'click':
|
|
89
|
+
return {
|
|
90
|
+
...events,
|
|
91
|
+
click: this.magnify,
|
|
92
|
+
};
|
|
93
|
+
case 'drag':
|
|
94
|
+
return {
|
|
95
|
+
...events,
|
|
96
|
+
pointermove: this.onPointerMove,
|
|
97
|
+
};
|
|
98
|
+
default:
|
|
99
|
+
return {
|
|
100
|
+
...events,
|
|
101
|
+
pointermove: this.magnify,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public init(graph: IGraph) {
|
|
107
|
+
super.init(graph);
|
|
108
|
+
const { r, d } = this.options;
|
|
109
|
+
this.cachedTransientTexts = {};
|
|
110
|
+
this.initOriginPositions();
|
|
111
|
+
this.r2 = r * r;
|
|
112
|
+
this.molecularParam = (d + 1) * r;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private initOriginPositions = () => {
|
|
116
|
+
const { graph } = this;
|
|
117
|
+
const positions = {};
|
|
118
|
+
graph.getAllNodesData().forEach((node) => {
|
|
119
|
+
positions[node.id] = { x: node.data.x, y: node.data.y, texts: [] };
|
|
120
|
+
});
|
|
121
|
+
this.cachedOriginPositions = positions;
|
|
122
|
+
return positions;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Determine whether it is dragged in the delegate
|
|
126
|
+
protected isInLensDelegate(lensDelegate, pointer): boolean {
|
|
127
|
+
const { cx: lensX, cy: lensY, r: lensR } = lensDelegate.style;
|
|
128
|
+
if (
|
|
129
|
+
pointer.x >= lensX - lensR &&
|
|
130
|
+
pointer.x <= lensX + lensR &&
|
|
131
|
+
pointer.y >= lensY - lensR &&
|
|
132
|
+
pointer.y <= lensY + lensR
|
|
133
|
+
) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
protected onPointerUp(e: IG6GraphEvent) {
|
|
140
|
+
this.pointerDown = undefined;
|
|
141
|
+
this.cacheCenter = undefined;
|
|
142
|
+
this.dragging = false;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
protected onPointerMove(e: IG6GraphEvent) {
|
|
146
|
+
if (!this.dragging && this.pointerDown) {
|
|
147
|
+
this.dragging = true;
|
|
148
|
+
}
|
|
149
|
+
if (!this.pointerDown) return;
|
|
150
|
+
this.moveDelegate(this.delegate, e);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
protected onPointerDown(e: IG6GraphEvent) {
|
|
154
|
+
const { delegate: lensDelegate } = this;
|
|
155
|
+
if (!lensDelegate || lensDelegate.destroyed) {
|
|
156
|
+
this.cacheCenter = { x: e.canvas.x, y: e.canvas.y };
|
|
157
|
+
this.magnify(e);
|
|
158
|
+
} else {
|
|
159
|
+
this.cacheCenter = {
|
|
160
|
+
x: lensDelegate.attr('cx'),
|
|
161
|
+
y: lensDelegate.attr('cy'),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
this.pointerDown = { x: e.canvas.x, y: e.canvas.y };
|
|
165
|
+
this.dragging = false;
|
|
166
|
+
this.dragPrePos = { x: e.canvas.x, y: e.canvas.y };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
protected moveDelegate(lensDelegate, e) {
|
|
170
|
+
if (this.isInLensDelegate(lensDelegate, { x: e.canvas.x, y: e.canvas.y })) {
|
|
171
|
+
this.delegateCenterDiff = {
|
|
172
|
+
x: e.canvas.x - this.pointerDown.x,
|
|
173
|
+
y: e.canvas.y - this.pointerDown.y,
|
|
174
|
+
};
|
|
175
|
+
this.magnify(e, this.cacheCenter);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
protected onWheel(e: IG6GraphEvent) {
|
|
180
|
+
const { delegate: lensDelegate, options } = this;
|
|
181
|
+
const { scaleDBy, scaleRBy } = options;
|
|
182
|
+
if (!lensDelegate || lensDelegate.destroyed) return;
|
|
183
|
+
if (scaleDBy !== 'wheel' && scaleRBy !== 'wheel') return;
|
|
184
|
+
if (this.isInLensDelegate(lensDelegate, { x: e.canvas.x, y: e.canvas.y })) {
|
|
185
|
+
if (scaleRBy === 'wheel') {
|
|
186
|
+
this.scaleRByWheel(e);
|
|
187
|
+
}
|
|
188
|
+
if (scaleDBy === 'wheel') {
|
|
189
|
+
this.scaleDByWheel(e);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Scale the range by wheel
|
|
196
|
+
* @param e mouse wheel event
|
|
197
|
+
*/
|
|
198
|
+
protected scaleRByWheel(e: IG6GraphEvent) {
|
|
199
|
+
if (!e || !e.originalEvent) return;
|
|
200
|
+
if (e.preventDefault) e.preventDefault();
|
|
201
|
+
const { graph, options } = this;
|
|
202
|
+
let ratio;
|
|
203
|
+
const { delegate: lensDelegate, maxR, minR, d } = options;
|
|
204
|
+
let { r } = options;
|
|
205
|
+
const lensCenter = lensDelegate
|
|
206
|
+
? {
|
|
207
|
+
x: lensDelegate.attr('cx'),
|
|
208
|
+
y: lensDelegate.attr('cy'),
|
|
209
|
+
}
|
|
210
|
+
: undefined;
|
|
211
|
+
const mousePos = lensCenter || { x: e.canvas.x, y: e.canvas.y };
|
|
212
|
+
if ((e.originalEvent as any).deltaY < 0) {
|
|
213
|
+
ratio = 1 - DELTA;
|
|
214
|
+
} else {
|
|
215
|
+
ratio = 1 / (1 - DELTA);
|
|
216
|
+
}
|
|
217
|
+
const graphHeight = graph.canvas.context.config.canvas.height;
|
|
218
|
+
if (
|
|
219
|
+
(r > (maxR || graphHeight) && ratio > 1) ||
|
|
220
|
+
(r < (minR || graphHeight * 0.05) && ratio < 1)
|
|
221
|
+
) {
|
|
222
|
+
ratio = 1;
|
|
223
|
+
}
|
|
224
|
+
r *= ratio;
|
|
225
|
+
this.options.r = r;
|
|
226
|
+
this.r2 = r * r;
|
|
227
|
+
this.molecularParam = (d + 1) * r;
|
|
228
|
+
this.delegateCenterDiff = undefined;
|
|
229
|
+
this.magnify(e, mousePos);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Scale the range by dragging
|
|
234
|
+
* @param e mouse event
|
|
235
|
+
*/
|
|
236
|
+
protected scaleRByDrag = throttle(
|
|
237
|
+
this.scaleRByDragMethod.bind(this),
|
|
238
|
+
this.options.throttle,
|
|
239
|
+
{ leading: true, trailing: true },
|
|
240
|
+
);
|
|
241
|
+
protected scaleRByDragMethod(e: IG6GraphEvent) {
|
|
242
|
+
if (!e) return;
|
|
243
|
+
const { dragPrePos, graph, options } = this;
|
|
244
|
+
const { maxR, minR, d } = options;
|
|
245
|
+
let { r } = options;
|
|
246
|
+
let ratio;
|
|
247
|
+
if (e.canvas.x - dragPrePos.x < 0) {
|
|
248
|
+
ratio = 1 - DELTA;
|
|
249
|
+
} else {
|
|
250
|
+
ratio = 1 / (1 - DELTA);
|
|
251
|
+
}
|
|
252
|
+
const graphCanvasEl = graph.canvas.context.config.canvas;
|
|
253
|
+
const [
|
|
254
|
+
graphWidth = graphCanvasEl?.width || 500,
|
|
255
|
+
graphHeight = graphCanvasEl?.height || 500,
|
|
256
|
+
] = graph.getSize();
|
|
257
|
+
if (
|
|
258
|
+
(r > (maxR || graphHeight) && ratio > 1) ||
|
|
259
|
+
(r < (minR || graphHeight * 0.05) && ratio < 1)
|
|
260
|
+
) {
|
|
261
|
+
ratio = 1;
|
|
262
|
+
}
|
|
263
|
+
r *= ratio;
|
|
264
|
+
this.options.r = r;
|
|
265
|
+
this.r2 = r * r;
|
|
266
|
+
this.molecularParam = (d + 1) * r;
|
|
267
|
+
this.magnify(e);
|
|
268
|
+
this.dragPrePos = { x: e.canvas.x, y: e.canvas.y };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Scale the magnifying factor by wheel
|
|
273
|
+
* @param e mouse wheel event
|
|
274
|
+
*/
|
|
275
|
+
protected scaleDByWheel(evt: IG6GraphEvent) {
|
|
276
|
+
if (!evt && !evt.originalEvent) return;
|
|
277
|
+
if (evt.preventDefault) evt.preventDefault();
|
|
278
|
+
let delta = 0;
|
|
279
|
+
if ((evt.originalEvent as any).deltaY < 0) {
|
|
280
|
+
delta = -0.1;
|
|
281
|
+
} else {
|
|
282
|
+
delta = 0.1;
|
|
283
|
+
}
|
|
284
|
+
const { d, maxD, minD, r } = this.options;
|
|
285
|
+
const newD = d + delta;
|
|
286
|
+
if (newD < maxD && newD > minD) {
|
|
287
|
+
this.options.d = newD;
|
|
288
|
+
this.molecularParam = (newD + 1) * r;
|
|
289
|
+
const { delegate: lensDelegate } = this;
|
|
290
|
+
const lensCenter = lensDelegate
|
|
291
|
+
? {
|
|
292
|
+
x: lensDelegate.attr('cx'),
|
|
293
|
+
y: lensDelegate.attr('cy'),
|
|
294
|
+
}
|
|
295
|
+
: undefined;
|
|
296
|
+
this.delegateCenterDiff = undefined;
|
|
297
|
+
this.magnify(evt, lensCenter);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Scale the magnifying factor by dragging
|
|
303
|
+
* @param e mouse event
|
|
304
|
+
*/
|
|
305
|
+
protected scaleDByDrag = throttle(
|
|
306
|
+
this.scaleDByDragMethod.bind(this),
|
|
307
|
+
this.options.throttle,
|
|
308
|
+
{ leading: true, trailing: true },
|
|
309
|
+
);
|
|
310
|
+
protected scaleDByDragMethod(e: IG6GraphEvent) {
|
|
311
|
+
const { d, maxD, minD, r } = this.options;
|
|
312
|
+
const delta = e.canvas.x - this.dragPrePos.x > 0 ? 0.1 : -0.1;
|
|
313
|
+
const newD = d + delta;
|
|
314
|
+
if (newD < maxD && newD > minD) {
|
|
315
|
+
this.options.d = newD;
|
|
316
|
+
this.molecularParam = (newD + 1) * r;
|
|
317
|
+
this.magnify(e);
|
|
318
|
+
}
|
|
319
|
+
this.dragPrePos = { x: e.canvas.x, y: e.canvas.y };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Response function for mousemove, click, or drag to magnify
|
|
324
|
+
* @param e mouse event
|
|
325
|
+
*/
|
|
326
|
+
protected magnify(e: IG6GraphEvent, mousePos?) {
|
|
327
|
+
this.restoreCache();
|
|
328
|
+
const {
|
|
329
|
+
r2,
|
|
330
|
+
graph,
|
|
331
|
+
cachedOriginPositions,
|
|
332
|
+
cachedTransientTexts,
|
|
333
|
+
molecularParam,
|
|
334
|
+
delegateCenterDiff,
|
|
335
|
+
options,
|
|
336
|
+
} = this;
|
|
337
|
+
const positions = Object.keys(cachedOriginPositions).map((id) => ({
|
|
338
|
+
id,
|
|
339
|
+
data: {
|
|
340
|
+
x: cachedOriginPositions[id].x,
|
|
341
|
+
y: cachedOriginPositions[id].y,
|
|
342
|
+
},
|
|
343
|
+
}));
|
|
344
|
+
const { r, d, showLabel, trigger } = options;
|
|
345
|
+
const nodes = graph.getAllNodesData();
|
|
346
|
+
const nodeLength = nodes.length;
|
|
347
|
+
const point = graph.getCanvasByClient(e.client);
|
|
348
|
+
let mCenter = mousePos
|
|
349
|
+
? { x: mousePos.x, y: mousePos.y }
|
|
350
|
+
: { x: point.x, y: point.y };
|
|
351
|
+
if (this.dragging && (trigger === 'mousemove' || trigger === 'click')) {
|
|
352
|
+
mCenter = this.cacheCenter;
|
|
353
|
+
}
|
|
354
|
+
if (delegateCenterDiff) {
|
|
355
|
+
mCenter.x += delegateCenterDiff.x;
|
|
356
|
+
mCenter.y += delegateCenterDiff.y;
|
|
357
|
+
}
|
|
358
|
+
this.updateDelegate(mCenter, r, e);
|
|
359
|
+
for (let i = 0; i < nodeLength; i++) {
|
|
360
|
+
const model = nodes[i];
|
|
361
|
+
const { x, y } = cachedOriginPositions[model.id]; // calculate based on the origin positions
|
|
362
|
+
if (isNaN(x) || isNaN(y)) continue;
|
|
363
|
+
// the square of the distance between the node and the magnified center
|
|
364
|
+
const dist2 =
|
|
365
|
+
(x - mCenter.x) * (x - mCenter.x) + (y - mCenter.y) * (y - mCenter.y);
|
|
366
|
+
if (!isNaN(dist2) && dist2 < r2 && dist2 !== 0) {
|
|
367
|
+
const dist = Math.sqrt(dist2);
|
|
368
|
+
// // (r * (d + 1) * (dist / r)) / (d * (dist / r) + 1);
|
|
369
|
+
const magnifiedDist = (molecularParam * dist) / (d * dist + r);
|
|
370
|
+
const vecX = (x - mCenter.x) / dist;
|
|
371
|
+
const vecY = (y - mCenter.y) / dist;
|
|
372
|
+
const magnifiedX = vecX * magnifiedDist + mCenter.x;
|
|
373
|
+
const magnifiedY = vecY * magnifiedDist + mCenter.y;
|
|
374
|
+
const magnifiedNode = {
|
|
375
|
+
id: model.id,
|
|
376
|
+
data: { x: magnifiedX, y: magnifiedY },
|
|
377
|
+
};
|
|
378
|
+
const textContent =
|
|
379
|
+
model.data.label || (model.data.labelShape as any)?.text;
|
|
380
|
+
if (showLabel && 2 * dist < r) {
|
|
381
|
+
const transientTextID = `node-text-${model.id}`;
|
|
382
|
+
const cachedTransientText = cachedTransientTexts[transientTextID];
|
|
383
|
+
if (cachedTransientText) {
|
|
384
|
+
cachedTransientText.attr({
|
|
385
|
+
x: magnifiedNode.data.x,
|
|
386
|
+
y: magnifiedNode.data.y,
|
|
387
|
+
});
|
|
388
|
+
cachedTransientText.show();
|
|
389
|
+
cachedOriginPositions[model.id].texts.push(cachedTransientText);
|
|
390
|
+
} else if (textContent) {
|
|
391
|
+
const text = graph.drawTransient('text', transientTextID, {
|
|
392
|
+
style: {
|
|
393
|
+
text: textContent,
|
|
394
|
+
x: magnifiedNode.data.x,
|
|
395
|
+
y: magnifiedNode.data.y,
|
|
396
|
+
textAlign: 'center',
|
|
397
|
+
textBaseline: 'middle',
|
|
398
|
+
fill: '#000',
|
|
399
|
+
lineWidth: 1,
|
|
400
|
+
fontSize: 12,
|
|
401
|
+
isBillboard: true,
|
|
402
|
+
lod: -1,
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
cachedTransientTexts[transientTextID] = text;
|
|
406
|
+
cachedOriginPositions[model.id].texts.push(text);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
positions[model.id] = magnifiedNode;
|
|
410
|
+
} else {
|
|
411
|
+
// update the origin positions outside of the lens
|
|
412
|
+
if (!cachedOriginPositions[model.id]) {
|
|
413
|
+
cachedOriginPositions[model.id] = { x, y, texts: [] };
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
graph.updateNodePosition(Object.values(positions));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
protected restoreCache() {
|
|
421
|
+
const cachePositions = { ...this.cachedOriginPositions };
|
|
422
|
+
Object.values(this.cachedOriginPositions).forEach((position) => {
|
|
423
|
+
position.texts?.forEach((text) => text.hide());
|
|
424
|
+
});
|
|
425
|
+
return cachePositions;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Adjust part of the parameters, including trigger, d, r, maxR, minR, maxD, minD, scaleRBy, and scaleDBy
|
|
430
|
+
* @param {FisheyeConfig} cfg
|
|
431
|
+
*/
|
|
432
|
+
public updateParams(cfg: FisheyeConfig) {
|
|
433
|
+
const { r, d, trigger, minD, maxD, minR, maxR, scaleDBy, scaleRBy } = cfg;
|
|
434
|
+
if (!isNaN(cfg.r)) {
|
|
435
|
+
this.options.r = r;
|
|
436
|
+
this.r2 = r * r;
|
|
437
|
+
}
|
|
438
|
+
if (!isNaN(d)) {
|
|
439
|
+
this.options.d = d;
|
|
440
|
+
}
|
|
441
|
+
if (!isNaN(maxD)) {
|
|
442
|
+
this.options.maxD = maxD;
|
|
443
|
+
}
|
|
444
|
+
if (!isNaN(minD)) {
|
|
445
|
+
this.options.minD = minD;
|
|
446
|
+
}
|
|
447
|
+
if (!isNaN(maxR)) {
|
|
448
|
+
this.options.maxR = maxR;
|
|
449
|
+
}
|
|
450
|
+
if (!isNaN(minR)) {
|
|
451
|
+
this.options.minR = minR;
|
|
452
|
+
}
|
|
453
|
+
const { graph, dPercentText, options } = this;
|
|
454
|
+
const { d: nd, r: nr } = options;
|
|
455
|
+
this.molecularParam = (nd + 1) * nr;
|
|
456
|
+
if (trigger === 'mousemove' || trigger === 'click' || trigger === 'drag') {
|
|
457
|
+
this.options.trigger = trigger;
|
|
458
|
+
}
|
|
459
|
+
if (scaleDBy === 'drag' || scaleDBy === 'wheel' || scaleDBy === 'unset') {
|
|
460
|
+
this.options.scaleDBy = scaleDBy;
|
|
461
|
+
graph.drawTransient('circle', 'lens-shape', { action: 'remove' });
|
|
462
|
+
if (dPercentText) {
|
|
463
|
+
graph.drawTransient('text', 'lens-text-shape', { action: 'remove' });
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
if (scaleRBy === 'drag' || scaleRBy === 'wheel' || scaleRBy === 'unset') {
|
|
467
|
+
this.options.scaleRBy = scaleRBy;
|
|
468
|
+
graph.drawTransient('circle', 'lens-shape', { action: 'remove' });
|
|
469
|
+
if (dPercentText) {
|
|
470
|
+
graph.drawTransient('text', 'lens-text-shape', { action: 'remove' });
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Update the delegate shape of the lens
|
|
477
|
+
* @param {Point} mCenter the center of the shape
|
|
478
|
+
* @param {number} r the radius of the shape
|
|
479
|
+
*/
|
|
480
|
+
private updateDelegate(mCenter, r, e) {
|
|
481
|
+
const { graph, dPercentText } = this;
|
|
482
|
+
let lensDelegate = this.delegate;
|
|
483
|
+
if (!lensDelegate || lensDelegate.destroyed) {
|
|
484
|
+
const attrs = this.options.delegateStyle || lensDelegateStyle;
|
|
485
|
+
lensDelegate = graph.drawTransient('circle', 'lens-shape', {
|
|
486
|
+
style: {
|
|
487
|
+
r: r / 1.5,
|
|
488
|
+
cx: mCenter.x,
|
|
489
|
+
cy: mCenter.y,
|
|
490
|
+
...attrs,
|
|
491
|
+
},
|
|
492
|
+
});
|
|
493
|
+
} else {
|
|
494
|
+
lensDelegate.attr({
|
|
495
|
+
cx: mCenter.x,
|
|
496
|
+
cy: mCenter.y,
|
|
497
|
+
r: r / 1.5,
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
const { d, minD, maxD, showDPercent } = this.options;
|
|
502
|
+
|
|
503
|
+
// draw the zoom factor percentage text
|
|
504
|
+
if (showDPercent) {
|
|
505
|
+
const percent = Math.round(((d - minD) / (maxD - minD)) * 100);
|
|
506
|
+
const textY = mCenter.y + r / 1.5 + 16;
|
|
507
|
+
if (!dPercentText || dPercentText.destroyed) {
|
|
508
|
+
const text = graph.drawTransient('text', 'lens-text-shape', {
|
|
509
|
+
style: {
|
|
510
|
+
text: `${percent}%`,
|
|
511
|
+
x: mCenter.x,
|
|
512
|
+
y: textY,
|
|
513
|
+
fill: '#aaa',
|
|
514
|
+
stroke: '#fff',
|
|
515
|
+
lineWidth: 1,
|
|
516
|
+
fontSize: 12,
|
|
517
|
+
},
|
|
518
|
+
});
|
|
519
|
+
this.dPercentText = text;
|
|
520
|
+
} else {
|
|
521
|
+
dPercentText.attr({
|
|
522
|
+
text: `${percent}%`,
|
|
523
|
+
x: mCenter.x,
|
|
524
|
+
y: textY,
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
this.delegate = lensDelegate;
|
|
529
|
+
|
|
530
|
+
// Adjust the range of r and d
|
|
531
|
+
if (this.options.trigger !== 'drag') {
|
|
532
|
+
if (this.options.scaleRBy === 'drag') {
|
|
533
|
+
if (!this.pointerDown) return;
|
|
534
|
+
this.scaleRByDrag(e);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
if (this.options.scaleDBy === 'drag') {
|
|
538
|
+
if (!this.pointerDown) return;
|
|
539
|
+
this.scaleDByDrag(e);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Clear the fisheye lens
|
|
546
|
+
*/
|
|
547
|
+
public clear() {
|
|
548
|
+
const {
|
|
549
|
+
graph,
|
|
550
|
+
delegate: lensDelegate,
|
|
551
|
+
cachedOriginPositions,
|
|
552
|
+
dPercentText,
|
|
553
|
+
} = this;
|
|
554
|
+
this.restoreCache();
|
|
555
|
+
graph.updateNodePosition(
|
|
556
|
+
Object.keys(cachedOriginPositions).map((id) => ({
|
|
557
|
+
id,
|
|
558
|
+
data: {
|
|
559
|
+
x: cachedOriginPositions[id].x,
|
|
560
|
+
y: cachedOriginPositions[id].y,
|
|
561
|
+
},
|
|
562
|
+
})),
|
|
563
|
+
);
|
|
564
|
+
if (lensDelegate && !lensDelegate.destroyed) {
|
|
565
|
+
graph.drawTransient('circle', 'lens-shape', { action: 'remove' });
|
|
566
|
+
}
|
|
567
|
+
if (dPercentText && !dPercentText.destroyed) {
|
|
568
|
+
graph.drawTransient('text', 'lens-text-shape', { action: 'remove' });
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Destroy the component
|
|
574
|
+
*/
|
|
575
|
+
public destroy() {
|
|
576
|
+
this.clear();
|
|
577
|
+
}
|
|
578
|
+
}
|