@antv/g6 5.0.0-beta.11 → 5.0.0-beta.12
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/esm/api-doc/graph.d.ts +3 -3
- package/esm/api-doc/graph.js +3 -3
- package/esm/api-doc/graph.js.map +1 -1
- package/esm/constant/shape.d.ts +1 -1
- package/esm/index.d.ts +12 -62
- package/esm/index.js +4 -5
- package/esm/index.js.map +1 -1
- package/esm/runtime/controller/item.js +15 -6
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/controller/layout.js +1 -3
- package/esm/runtime/controller/layout.js.map +1 -1
- package/esm/runtime/graph.d.ts +1 -1
- package/esm/runtime/graph.js +11 -5
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/drag-canvas.d.ts +1 -1
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/behavior/shortcuts-call.d.ts +2 -2
- package/esm/stdlib/behavior/shortcuts-call.js +12 -5
- package/esm/stdlib/behavior/shortcuts-call.js.map +1 -1
- package/esm/stdlib/behavior/zoom-canvas-3d.js +4 -1
- package/esm/stdlib/behavior/zoom-canvas-3d.js.map +1 -1
- package/esm/stdlib/index.d.ts +6 -1
- package/esm/stdlib/index.js +8 -3
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/edge/base.js +5 -1
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/edge/cubic-horizontal.js.map +1 -1
- package/esm/stdlib/item/edge/cubic-vertical.js.map +1 -1
- package/esm/stdlib/item/edge/cubic.js +1 -1
- package/esm/stdlib/item/edge/cubic.js.map +1 -1
- package/esm/stdlib/item/edge/loop.js +1 -1
- package/esm/stdlib/item/edge/loop.js.map +1 -1
- package/esm/stdlib/item/node/cube.d.ts +35 -0
- package/esm/stdlib/item/node/cube.js +54 -0
- package/esm/stdlib/item/node/cube.js.map +1 -0
- package/esm/stdlib/item/node/index.d.ts +3 -0
- package/esm/stdlib/item/node/index.js +3 -0
- package/esm/stdlib/item/node/index.js.map +1 -1
- package/esm/stdlib/plugin/edgeFilterLens/index.d.ts +66 -0
- package/esm/stdlib/plugin/edgeFilterLens/index.js +309 -0
- package/esm/stdlib/plugin/edgeFilterLens/index.js.map +1 -0
- package/esm/stdlib/plugin/grid/index.d.ts +1 -1
- package/esm/stdlib/plugin/grid/index.js +3 -4
- package/esm/stdlib/plugin/grid/index.js.map +1 -1
- package/esm/stdlib/plugin/hull/convexHull.d.ts +1 -1
- package/esm/stdlib/plugin/hull/hullComponent.js +2 -3
- package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
- package/esm/stdlib/plugin/hull/util.d.ts +2 -2
- package/esm/stdlib/plugin/hull/util.js +6 -2
- package/esm/stdlib/plugin/hull/util.js.map +1 -1
- package/esm/stdlib/plugin/index.d.ts +1 -0
- package/esm/stdlib/plugin/index.js +1 -0
- package/esm/stdlib/plugin/index.js.map +1 -1
- package/esm/stdlib/plugin/legend/index.d.ts +2 -2
- package/esm/stdlib/plugin/legend/index.js +3 -3
- package/esm/stdlib/plugin/legend/index.js.map +1 -1
- package/esm/stdlib/plugin/map/index.d.ts +1 -1
- package/esm/stdlib/plugin/map/index.js +4 -4
- package/esm/stdlib/plugin/map/index.js.map +1 -1
- package/esm/stdlib/plugin/menu/index.d.ts +4 -4
- package/esm/stdlib/plugin/menu/index.js +3 -3
- package/esm/stdlib/plugin/menu/index.js.map +1 -1
- package/esm/stdlib/plugin/minimap/index.d.ts +1 -1
- package/esm/stdlib/plugin/minimap/index.js +3 -3
- package/esm/stdlib/plugin/minimap/index.js.map +1 -1
- package/esm/stdlib/plugin/timebar/index.js +2 -2
- package/esm/stdlib/plugin/timebar/index.js.map +1 -1
- package/esm/stdlib/plugin/toolbar/index.d.ts +3 -3
- package/esm/stdlib/plugin/toolbar/index.js +4 -4
- package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
- package/esm/stdlib/plugin/tooltip/index.d.ts +4 -4
- package/esm/stdlib/plugin/tooltip/index.js +3 -4
- package/esm/stdlib/plugin/tooltip/index.js.map +1 -1
- package/esm/stdlib/plugin/types.d.ts +1 -0
- package/esm/stdlib/plugin/watermaker/index.d.ts +78 -0
- package/esm/stdlib/plugin/watermaker/index.js +243 -0
- package/esm/stdlib/plugin/watermaker/index.js.map +1 -0
- package/esm/types/plugin.d.ts +1 -1
- package/esm/util/bbox.js +4 -5
- package/esm/util/bbox.js.map +1 -1
- package/esm/util/behavior.d.ts +2 -2
- package/esm/util/behavior.js +2 -2
- package/esm/util/behavior.js.map +1 -1
- package/esm/util/data.d.ts +2 -2
- package/esm/util/data.js.map +1 -1
- package/esm/util/dom.d.ts +15 -0
- package/esm/util/dom.js +29 -0
- package/esm/util/dom.js.map +1 -0
- package/esm/util/extend.d.ts +1 -1
- package/esm/util/extend.js +0 -1
- package/esm/util/extend.js.map +1 -1
- package/esm/util/index.d.ts +7 -52
- package/esm/util/index.js +7 -23
- package/esm/util/index.js.map +1 -1
- package/esm/util/layout.d.ts +1 -1
- package/esm/util/layout.js.map +1 -1
- package/esm/util/loop.d.ts +1 -1
- package/esm/util/math.d.ts +1 -1
- package/esm/util/matrix.d.ts +6 -0
- package/esm/util/matrix.js +48 -0
- package/esm/util/matrix.js.map +1 -0
- package/esm/util/path.js +1 -1
- package/esm/util/path.js.map +1 -1
- package/esm/util/point.d.ts +1 -1
- package/esm/util/polyline.d.ts +2 -1
- package/esm/util/polyline.js +2 -1
- package/esm/util/polyline.js.map +1 -1
- package/esm/util/router.d.ts +1 -1
- package/esm/util/shape.js.map +1 -1
- package/esm/util/shape3d.js +1 -1
- package/esm/util/shape3d.js.map +1 -1
- package/lib/api-doc/graph.d.ts +3 -3
- package/lib/api-doc/graph.js +27 -7
- package/lib/api-doc/graph.js.map +1 -1
- package/lib/constant/shape.d.ts +1 -1
- package/lib/index.d.ts +12 -62
- package/lib/index.js +18 -10
- package/lib/index.js.map +1 -1
- package/lib/runtime/controller/item.js +15 -6
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/controller/layout.js +1 -3
- package/lib/runtime/controller/layout.js.map +1 -1
- package/lib/runtime/graph.d.ts +1 -1
- package/lib/runtime/graph.js +12 -5
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/drag-canvas.d.ts +1 -1
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/behavior/shortcuts-call.d.ts +2 -2
- package/lib/stdlib/behavior/shortcuts-call.js +12 -5
- package/lib/stdlib/behavior/shortcuts-call.js.map +1 -1
- package/lib/stdlib/behavior/zoom-canvas-3d.js +4 -1
- package/lib/stdlib/behavior/zoom-canvas-3d.js.map +1 -1
- package/lib/stdlib/index.d.ts +6 -1
- package/lib/stdlib/index.js +8 -3
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/edge/base.js +5 -1
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/edge/cubic-horizontal.js.map +1 -1
- package/lib/stdlib/item/edge/cubic-vertical.js.map +1 -1
- package/lib/stdlib/item/edge/cubic.js +2 -2
- package/lib/stdlib/item/edge/cubic.js.map +1 -1
- package/lib/stdlib/item/edge/loop.js +3 -3
- package/lib/stdlib/item/edge/loop.js.map +1 -1
- package/lib/stdlib/item/node/cube.d.ts +35 -0
- package/lib/stdlib/item/node/cube.js +58 -0
- package/lib/stdlib/item/node/cube.js.map +1 -0
- package/lib/stdlib/item/node/index.d.ts +3 -0
- package/lib/stdlib/item/node/index.js +3 -0
- package/lib/stdlib/item/node/index.js.map +1 -1
- package/lib/stdlib/plugin/edgeFilterLens/index.d.ts +66 -0
- package/lib/stdlib/plugin/edgeFilterLens/index.js +313 -0
- package/lib/stdlib/plugin/edgeFilterLens/index.js.map +1 -0
- package/lib/stdlib/plugin/grid/index.d.ts +1 -1
- package/lib/stdlib/plugin/grid/index.js +6 -7
- package/lib/stdlib/plugin/grid/index.js.map +1 -1
- package/lib/stdlib/plugin/hull/convexHull.d.ts +1 -1
- package/lib/stdlib/plugin/hull/hullComponent.js +2 -3
- package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
- package/lib/stdlib/plugin/hull/util.d.ts +2 -2
- package/lib/stdlib/plugin/hull/util.js +26 -22
- package/lib/stdlib/plugin/hull/util.js.map +1 -1
- package/lib/stdlib/plugin/index.d.ts +1 -0
- package/lib/stdlib/plugin/index.js +1 -0
- package/lib/stdlib/plugin/index.js.map +1 -1
- package/lib/stdlib/plugin/legend/index.d.ts +2 -2
- package/lib/stdlib/plugin/legend/index.js +3 -3
- package/lib/stdlib/plugin/legend/index.js.map +1 -1
- package/lib/stdlib/plugin/map/index.d.ts +1 -1
- package/lib/stdlib/plugin/map/index.js +6 -6
- package/lib/stdlib/plugin/map/index.js.map +1 -1
- package/lib/stdlib/plugin/menu/index.d.ts +4 -4
- package/lib/stdlib/plugin/menu/index.js +6 -6
- package/lib/stdlib/plugin/menu/index.js.map +1 -1
- package/lib/stdlib/plugin/minimap/index.d.ts +1 -1
- package/lib/stdlib/plugin/minimap/index.js +6 -6
- package/lib/stdlib/plugin/minimap/index.js.map +1 -1
- package/lib/stdlib/plugin/timebar/index.js +2 -2
- package/lib/stdlib/plugin/timebar/index.js.map +1 -1
- package/lib/stdlib/plugin/toolbar/index.d.ts +3 -3
- package/lib/stdlib/plugin/toolbar/index.js +5 -5
- package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
- package/lib/stdlib/plugin/tooltip/index.d.ts +4 -4
- package/lib/stdlib/plugin/tooltip/index.js +10 -11
- package/lib/stdlib/plugin/tooltip/index.js.map +1 -1
- package/lib/stdlib/plugin/types.d.ts +1 -0
- package/lib/stdlib/plugin/watermaker/index.d.ts +78 -0
- package/lib/stdlib/plugin/watermaker/index.js +247 -0
- package/lib/stdlib/plugin/watermaker/index.js.map +1 -0
- package/lib/types/plugin.d.ts +1 -1
- package/lib/util/bbox.js +4 -5
- package/lib/util/bbox.js.map +1 -1
- package/lib/util/behavior.d.ts +2 -2
- package/lib/util/behavior.js +2 -2
- package/lib/util/behavior.js.map +1 -1
- package/lib/util/data.d.ts +2 -2
- package/lib/util/data.js.map +1 -1
- package/lib/util/dom.d.ts +15 -0
- package/lib/util/dom.js +34 -0
- package/lib/util/dom.js.map +1 -0
- package/lib/util/extend.d.ts +1 -1
- package/lib/util/extend.js +0 -1
- package/lib/util/extend.js.map +1 -1
- package/lib/util/index.d.ts +7 -52
- package/lib/util/index.js +23 -23
- package/lib/util/index.js.map +1 -1
- package/lib/util/layout.d.ts +1 -1
- package/lib/util/layout.js.map +1 -1
- package/lib/util/loop.d.ts +1 -1
- package/lib/util/math.d.ts +1 -1
- package/lib/util/matrix.d.ts +6 -0
- package/lib/util/matrix.js +52 -0
- package/lib/util/matrix.js.map +1 -0
- package/lib/util/path.js +2 -2
- package/lib/util/path.js.map +1 -1
- package/lib/util/point.d.ts +1 -1
- package/lib/util/polyline.d.ts +2 -1
- package/lib/util/polyline.js +2 -1
- package/lib/util/polyline.js.map +1 -1
- package/lib/util/router.d.ts +1 -1
- package/lib/util/shape.js.map +1 -1
- package/lib/util/shape3d.js +1 -1
- package/lib/util/shape3d.js.map +1 -1
- package/package.json +32 -40
- package/src/api-doc/graph.ts +4 -3
- package/src/constant/shape.ts +1 -1
- package/src/index.ts +5 -6
- package/src/runtime/controller/item.ts +15 -6
- package/src/runtime/controller/layout.ts +1 -5
- package/src/runtime/graph.ts +12 -6
- package/src/stdlib/behavior/drag-canvas.ts +1 -1
- package/src/stdlib/behavior/shortcuts-call.ts +13 -4
- package/src/stdlib/behavior/zoom-canvas-3d.ts +4 -1
- package/src/stdlib/index.ts +10 -1
- package/src/stdlib/item/edge/base.ts +5 -2
- package/src/stdlib/item/edge/cubic-horizontal.ts +0 -1
- package/src/stdlib/item/edge/cubic-vertical.ts +0 -1
- package/src/stdlib/item/edge/cubic.ts +1 -1
- package/src/stdlib/item/edge/loop.ts +1 -1
- package/src/stdlib/item/node/cube.ts +102 -0
- package/src/stdlib/item/node/index.ts +3 -0
- package/src/stdlib/plugin/edgeFilterLens/index.ts +387 -0
- package/src/stdlib/plugin/grid/index.ts +6 -6
- package/src/stdlib/plugin/hull/convexHull.ts +1 -1
- package/src/stdlib/plugin/hull/hullComponent.ts +2 -3
- package/src/stdlib/plugin/hull/util.ts +6 -2
- package/src/stdlib/plugin/index.ts +1 -0
- package/src/stdlib/plugin/legend/index.ts +6 -6
- package/src/stdlib/plugin/map/index.ts +7 -7
- package/src/stdlib/plugin/menu/index.ts +13 -13
- package/src/stdlib/plugin/minimap/index.ts +6 -6
- package/src/stdlib/plugin/timebar/index.ts +4 -4
- package/src/stdlib/plugin/toolbar/index.ts +8 -8
- package/src/stdlib/plugin/tooltip/index.ts +10 -10
- package/src/stdlib/plugin/types.ts +1 -0
- package/src/stdlib/plugin/watermaker/index.ts +302 -0
- package/src/types/plugin.ts +1 -1
- package/src/util/bbox.ts +4 -5
- package/src/util/behavior.ts +4 -4
- package/src/util/data.ts +2 -3
- package/src/util/dom.ts +33 -0
- package/src/util/extend.ts +2 -3
- package/src/util/index.ts +7 -24
- package/src/util/layout.ts +3 -2
- package/src/util/loop.ts +1 -1
- package/src/util/math.ts +1 -1
- package/src/util/matrix.ts +66 -0
- package/src/util/path.ts +1 -1
- package/src/util/point.ts +1 -1
- package/src/util/polyline.ts +2 -1
- package/src/util/router.ts +1 -1
- package/src/util/shape.ts +0 -1
- package/src/util/shape3d.ts +1 -1
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { clone } from '@antv/util';
|
|
3
|
+
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
4
|
+
import { IGraph } from '../../../types';
|
|
5
|
+
import { IG6GraphEvent } from '../../../types/event';
|
|
6
|
+
import { ShapeStyle } from '../../../types/item';
|
|
7
|
+
import { distance } from '../../../util/point';
|
|
8
|
+
|
|
9
|
+
const DELTA = 0.01;
|
|
10
|
+
interface EdgeFilterLensConfig extends IPluginBaseConfig {
|
|
11
|
+
trigger?: 'mousemove' | 'click' | 'drag';
|
|
12
|
+
r?: number;
|
|
13
|
+
delegateStyle?: ShapeStyle;
|
|
14
|
+
showLabel?: 'node' | 'edge' | 'both' | undefined;
|
|
15
|
+
scaleRBy?: 'wheel' | undefined;
|
|
16
|
+
maxR?: number;
|
|
17
|
+
minR?: number;
|
|
18
|
+
showType?: 'one' | 'both' | 'only-source' | 'only-target'; // 更名,原名与plugin的type冲突
|
|
19
|
+
shouldShow?: (d?: unknown) => boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const lensDelegateStyle = {
|
|
23
|
+
stroke: '#000',
|
|
24
|
+
strokeOpacity: 0.8,
|
|
25
|
+
lineWidth: 2,
|
|
26
|
+
fillOpacity: 1,
|
|
27
|
+
fill: '#fff',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export class EdgeFilterLens extends Base {
|
|
31
|
+
private showNodeLabel: boolean;
|
|
32
|
+
private showEdgeLabel: boolean;
|
|
33
|
+
private delegate: DisplayObject;
|
|
34
|
+
private cachedTransientNodes: Set<string | number>;
|
|
35
|
+
private cachedTransientEdges: Set<string | number>;
|
|
36
|
+
private dragging: boolean;
|
|
37
|
+
private delegateCenterDiff: { x: number; y: number };
|
|
38
|
+
|
|
39
|
+
constructor(config?: EdgeFilterLensConfig) {
|
|
40
|
+
super(config);
|
|
41
|
+
this.cachedTransientNodes = new Set();
|
|
42
|
+
this.cachedTransientEdges = new Set();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public getDefaultCfgs(): EdgeFilterLensConfig {
|
|
46
|
+
return {
|
|
47
|
+
showType: 'both',
|
|
48
|
+
trigger: 'mousemove',
|
|
49
|
+
r: 60,
|
|
50
|
+
delegateStyle: clone(lensDelegateStyle),
|
|
51
|
+
showLabel: 'edge',
|
|
52
|
+
scaleRBy: 'wheel',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public getEvents() {
|
|
57
|
+
let events = {
|
|
58
|
+
pointerdown: this.onPointerDown,
|
|
59
|
+
pointerup: this.onPointerUp,
|
|
60
|
+
wheel: this.onWheel,
|
|
61
|
+
} as {
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
};
|
|
64
|
+
switch (this.options.trigger) {
|
|
65
|
+
case 'click':
|
|
66
|
+
events = {
|
|
67
|
+
...events,
|
|
68
|
+
click: this.filter,
|
|
69
|
+
};
|
|
70
|
+
break;
|
|
71
|
+
case 'drag':
|
|
72
|
+
events = {
|
|
73
|
+
...events,
|
|
74
|
+
pointermove: this.onPointerMove,
|
|
75
|
+
};
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
events = {
|
|
79
|
+
...events,
|
|
80
|
+
pointermove: this.filter,
|
|
81
|
+
};
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
return events;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public init(graph: IGraph) {
|
|
88
|
+
super.init(graph);
|
|
89
|
+
const showLabel = this.options.showLabel;
|
|
90
|
+
const showNodeLabel = showLabel === 'node' || showLabel === 'both';
|
|
91
|
+
const showEdgeLabel = showLabel === 'edge' || showLabel === 'both';
|
|
92
|
+
this.showNodeLabel = showNodeLabel;
|
|
93
|
+
this.showEdgeLabel = showEdgeLabel;
|
|
94
|
+
const shouldShow = this.options.shouldShow;
|
|
95
|
+
if (!shouldShow) this.options.shouldShow = () => true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
protected onPointerUp(e: IG6GraphEvent) {
|
|
99
|
+
this.dragging = false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
protected onPointerMove(e: IG6GraphEvent) {
|
|
103
|
+
if (!this.dragging) return;
|
|
104
|
+
this.moveDelegate(e);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
protected onPointerDown(e: IG6GraphEvent) {
|
|
108
|
+
const { delegate: lensDelegate } = this;
|
|
109
|
+
let cacheCenter;
|
|
110
|
+
if (!lensDelegate || lensDelegate.destroyed) {
|
|
111
|
+
cacheCenter = { x: e.canvas.x, y: e.canvas.y };
|
|
112
|
+
this.filter(e);
|
|
113
|
+
} else {
|
|
114
|
+
cacheCenter = {
|
|
115
|
+
x: lensDelegate.style.cx,
|
|
116
|
+
y: lensDelegate.style.cy,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
this.delegateCenterDiff = {
|
|
120
|
+
x: e.canvas.x - cacheCenter.x,
|
|
121
|
+
y: e.canvas.y - cacheCenter.y,
|
|
122
|
+
};
|
|
123
|
+
this.dragging = true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Determine whether it is dragged in the delegate
|
|
127
|
+
protected isInLensDelegate(lensDelegate, pointer): boolean {
|
|
128
|
+
const { cx: lensX, cy: lensY, r: lensR } = lensDelegate.style;
|
|
129
|
+
if (
|
|
130
|
+
pointer.x >= lensX - lensR &&
|
|
131
|
+
pointer.x <= lensX + lensR &&
|
|
132
|
+
pointer.y >= lensY - lensR &&
|
|
133
|
+
pointer.y <= lensY + lensR
|
|
134
|
+
) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
protected moveDelegate(e) {
|
|
141
|
+
if (
|
|
142
|
+
this.isInLensDelegate(this.delegate, { x: e.canvas.x, y: e.canvas.y })
|
|
143
|
+
) {
|
|
144
|
+
const center = {
|
|
145
|
+
x: e.canvas.x - this.delegateCenterDiff.x,
|
|
146
|
+
y: e.canvas.y - this.delegateCenterDiff.y,
|
|
147
|
+
};
|
|
148
|
+
this.filter(e, center);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
protected onWheel(e: IG6GraphEvent) {
|
|
153
|
+
const { delegate: lensDelegate, options } = this;
|
|
154
|
+
const { scaleRBy } = options;
|
|
155
|
+
if (!lensDelegate || lensDelegate.destroyed) return;
|
|
156
|
+
if (scaleRBy !== 'wheel') return;
|
|
157
|
+
if (this.isInLensDelegate(lensDelegate, { x: e.canvas.x, y: e.canvas.y })) {
|
|
158
|
+
if (scaleRBy === 'wheel') {
|
|
159
|
+
this.scaleRByWheel(e);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Scale the range by wheel
|
|
166
|
+
* @param e mouse wheel event
|
|
167
|
+
*/
|
|
168
|
+
protected scaleRByWheel(e: IG6GraphEvent) {
|
|
169
|
+
if (!e || !e.originalEvent) return;
|
|
170
|
+
if (e.preventDefault) e.preventDefault();
|
|
171
|
+
const { graph, options } = this;
|
|
172
|
+
const graphCanvasEl = graph.canvas.context.config.canvas;
|
|
173
|
+
const graphHeight = graphCanvasEl?.height || 500;
|
|
174
|
+
const maxR = options.maxR
|
|
175
|
+
? Math.min(options.maxR, graphHeight)
|
|
176
|
+
: graphHeight;
|
|
177
|
+
const minR = options.minR
|
|
178
|
+
? Math.max(options.minR, graphHeight * DELTA)
|
|
179
|
+
: graphHeight * DELTA;
|
|
180
|
+
|
|
181
|
+
const scale = 1 + (e.originalEvent as any).deltaY * -1 * DELTA;
|
|
182
|
+
let r = options.r * scale;
|
|
183
|
+
r = Math.min(r, maxR);
|
|
184
|
+
r = Math.max(r, minR);
|
|
185
|
+
options.r = r;
|
|
186
|
+
this.delegate.style.r = r;
|
|
187
|
+
this.filter(e);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Response function for mousemove, click, or drag to filter out the edges
|
|
192
|
+
* @param e mouse event
|
|
193
|
+
*/
|
|
194
|
+
protected filter(e: IG6GraphEvent, mousePos?) {
|
|
195
|
+
const {
|
|
196
|
+
graph,
|
|
197
|
+
options,
|
|
198
|
+
showNodeLabel,
|
|
199
|
+
showEdgeLabel,
|
|
200
|
+
cachedTransientNodes,
|
|
201
|
+
cachedTransientEdges,
|
|
202
|
+
} = this;
|
|
203
|
+
const r = options.r;
|
|
204
|
+
const showType = options.showType;
|
|
205
|
+
const shouldShow = options.shouldShow;
|
|
206
|
+
const fCenter = mousePos || { x: e.canvas.x, y: e.canvas.y };
|
|
207
|
+
this.updateDelegate(fCenter, r);
|
|
208
|
+
|
|
209
|
+
const nodes = graph.getAllNodesData();
|
|
210
|
+
const hitNodesMap = new Map();
|
|
211
|
+
nodes.forEach((node) => {
|
|
212
|
+
const { data, id } = node;
|
|
213
|
+
if (distance({ x: data.x, y: data.y }, fCenter) < r) {
|
|
214
|
+
hitNodesMap.set(id, node);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const edges = graph.getAllEdgesData();
|
|
219
|
+
const hitEdges = [];
|
|
220
|
+
edges.forEach((edge) => {
|
|
221
|
+
const sourceId = edge.source;
|
|
222
|
+
const targetId = edge.target;
|
|
223
|
+
if (shouldShow(edge)) {
|
|
224
|
+
if (showType === 'only-source' || showType === 'one') {
|
|
225
|
+
if (hitNodesMap.get(sourceId) && !hitNodesMap.get(targetId))
|
|
226
|
+
hitEdges.push(edge);
|
|
227
|
+
} else if (showType === 'only-target' || showType === 'one') {
|
|
228
|
+
if (hitNodesMap.get(targetId) && !hitNodesMap.get(sourceId))
|
|
229
|
+
hitEdges.push(edge);
|
|
230
|
+
} else if (
|
|
231
|
+
showType === 'both' &&
|
|
232
|
+
hitNodesMap.get(sourceId) &&
|
|
233
|
+
hitNodesMap.get(targetId)
|
|
234
|
+
) {
|
|
235
|
+
hitEdges.push(edge);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const currentTransientNodes = new Set<string | number>();
|
|
241
|
+
const currentTransientEdges = new Set<string | number>();
|
|
242
|
+
|
|
243
|
+
hitNodesMap.forEach((node) => {
|
|
244
|
+
currentTransientNodes.add(node.id);
|
|
245
|
+
|
|
246
|
+
if (cachedTransientNodes.has(node.id)) {
|
|
247
|
+
cachedTransientNodes.delete(node.id);
|
|
248
|
+
} else {
|
|
249
|
+
graph.drawTransient('node', node.id, {
|
|
250
|
+
shapeIds: showNodeLabel
|
|
251
|
+
? ['labelShape', 'labelBackgroundShape', 'keyShape']
|
|
252
|
+
: ['keyShape'],
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
cachedTransientNodes.forEach((id) => {
|
|
258
|
+
graph.drawTransient('node', id, { action: 'remove' });
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
if (showEdgeLabel) {
|
|
262
|
+
hitEdges.forEach((edge) => {
|
|
263
|
+
currentTransientEdges.add(edge.id);
|
|
264
|
+
|
|
265
|
+
if (cachedTransientEdges.has(edge.id)) {
|
|
266
|
+
cachedTransientEdges.delete(edge.id);
|
|
267
|
+
} else {
|
|
268
|
+
graph.drawTransient('edge', edge.id, {
|
|
269
|
+
shapeIds: ['labelShape', 'labelBackgroundShape', 'keyShape'],
|
|
270
|
+
drawSource: false,
|
|
271
|
+
drawTarget: false,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
cachedTransientEdges.forEach((id) => {
|
|
277
|
+
graph.drawTransient('edge', id, { action: 'remove' });
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
this.cachedTransientNodes = currentTransientNodes;
|
|
282
|
+
this.cachedTransientEdges = currentTransientEdges;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Adjust part of the parameters, including trigger, showType, r, maxR, minR, shouldShow, showLabel, and scaleRBy
|
|
287
|
+
* @param {EdgeFilterLensConfig} cfg
|
|
288
|
+
*/
|
|
289
|
+
public updateParams(cfg: EdgeFilterLensConfig) {
|
|
290
|
+
const self = this;
|
|
291
|
+
const { r, trigger, minR, maxR, scaleRBy, showLabel, shouldShow } = cfg;
|
|
292
|
+
if (!isNaN(cfg.r)) {
|
|
293
|
+
self.options.r = r;
|
|
294
|
+
}
|
|
295
|
+
if (!isNaN(maxR)) {
|
|
296
|
+
self.options.maxR = maxR;
|
|
297
|
+
}
|
|
298
|
+
if (!isNaN(minR)) {
|
|
299
|
+
self.options.minR = minR;
|
|
300
|
+
}
|
|
301
|
+
if (trigger === 'mousemove' || trigger === 'click' || trigger === 'drag') {
|
|
302
|
+
self.options.trigger = trigger;
|
|
303
|
+
}
|
|
304
|
+
if (scaleRBy === 'wheel' || scaleRBy === 'unset') {
|
|
305
|
+
self.options.scaleRBy = scaleRBy;
|
|
306
|
+
self.delegate.remove();
|
|
307
|
+
self.delegate.destroy();
|
|
308
|
+
}
|
|
309
|
+
if (showLabel === 'node' || showLabel === 'both') {
|
|
310
|
+
self.showNodeLabel = true;
|
|
311
|
+
}
|
|
312
|
+
if (showLabel === 'edge' || showLabel === 'both') {
|
|
313
|
+
self.showEdgeLabel = true;
|
|
314
|
+
}
|
|
315
|
+
if (shouldShow) {
|
|
316
|
+
self.options.shouldShow = shouldShow;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Update the delegate shape of the lens
|
|
322
|
+
* @param {Point} mCenter the center of the shape
|
|
323
|
+
* @param {number} r the radius of the shape
|
|
324
|
+
*/
|
|
325
|
+
private updateDelegate(mCenter, r) {
|
|
326
|
+
const { graph, options, delegate } = this;
|
|
327
|
+
let lensDelegate = delegate;
|
|
328
|
+
if (!lensDelegate || lensDelegate.destroyed) {
|
|
329
|
+
// 拖动多个
|
|
330
|
+
const attrs = options.delegateStyle || lensDelegateStyle;
|
|
331
|
+
|
|
332
|
+
// model上的x, y是相对于图形中心的,delegateShape是g实例,x,y是绝对坐标
|
|
333
|
+
lensDelegate = graph.drawTransient('circle', 'lens-shape', {
|
|
334
|
+
style: {
|
|
335
|
+
r,
|
|
336
|
+
cx: mCenter.x,
|
|
337
|
+
cy: mCenter.y,
|
|
338
|
+
zIndex: -1,
|
|
339
|
+
...attrs,
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
lensDelegate.toBack();
|
|
343
|
+
} else {
|
|
344
|
+
lensDelegate = graph.drawTransient('circle', 'lens-shape', {
|
|
345
|
+
style: {
|
|
346
|
+
r,
|
|
347
|
+
cx: mCenter.x,
|
|
348
|
+
cy: mCenter.y,
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
this.delegate = lensDelegate;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Clear the filtering
|
|
358
|
+
*/
|
|
359
|
+
public clear() {
|
|
360
|
+
const {
|
|
361
|
+
graph,
|
|
362
|
+
delegate: lensDelegate,
|
|
363
|
+
cachedTransientNodes,
|
|
364
|
+
cachedTransientEdges,
|
|
365
|
+
} = this;
|
|
366
|
+
|
|
367
|
+
if (lensDelegate && !lensDelegate.destroyed) {
|
|
368
|
+
graph.drawTransient('circle', 'lens-shape', { action: 'remove' });
|
|
369
|
+
}
|
|
370
|
+
cachedTransientNodes.forEach((id) => {
|
|
371
|
+
graph.drawTransient('node', id, { action: 'remove' });
|
|
372
|
+
});
|
|
373
|
+
cachedTransientEdges.forEach((id) => {
|
|
374
|
+
graph.drawTransient('edge', id, { action: 'remove' });
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
cachedTransientNodes.clear();
|
|
378
|
+
cachedTransientEdges.clear();
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Destroy the component
|
|
383
|
+
*/
|
|
384
|
+
public destroy() {
|
|
385
|
+
this.clear();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// TODO: update type define.
|
|
2
|
-
import { createDom, modifyCSS } from '@antv/dom-util';
|
|
3
2
|
import { Canvas } from '@antv/g';
|
|
4
3
|
import { uniqueId } from '@antv/util';
|
|
4
|
+
import { createDOM, modifyCSS } from '../../../util/dom';
|
|
5
5
|
import { IGraph } from '../../../types';
|
|
6
6
|
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
7
7
|
|
|
@@ -28,7 +28,7 @@ interface ViewPortEventParam {
|
|
|
28
28
|
export class Grid extends Base {
|
|
29
29
|
private canvas: Canvas;
|
|
30
30
|
private viewport: HTMLElement | undefined;
|
|
31
|
-
private container:
|
|
31
|
+
private container: HTMLElement;
|
|
32
32
|
constructor(options?: GridConfig) {
|
|
33
33
|
super(options);
|
|
34
34
|
}
|
|
@@ -49,11 +49,11 @@ export class Grid extends Base {
|
|
|
49
49
|
const [width, height] = graph.getSize();
|
|
50
50
|
const img = this.options.img || GRID_PNG;
|
|
51
51
|
|
|
52
|
-
const container:
|
|
52
|
+
const container: HTMLElement = createDOM(
|
|
53
53
|
`<div class='g6-grid-container' style="position: absolute; left:0;top:0;right:0;bottom:0;overflow: hidden;"></div>`,
|
|
54
54
|
);
|
|
55
55
|
|
|
56
|
-
const gridContainer:
|
|
56
|
+
const gridContainer: HTMLElement = createDOM(
|
|
57
57
|
`<div
|
|
58
58
|
class='g6-grid'
|
|
59
59
|
style='position:absolute;
|
|
@@ -96,7 +96,7 @@ export class Grid extends Base {
|
|
|
96
96
|
* @param param
|
|
97
97
|
*/
|
|
98
98
|
protected updateGrid(param: ViewPortEventParam) {
|
|
99
|
-
const gridContainer:
|
|
99
|
+
const gridContainer: HTMLElement = this.container;
|
|
100
100
|
let { matrix } = param;
|
|
101
101
|
if (!matrix) matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1];
|
|
102
102
|
|
|
@@ -110,7 +110,7 @@ export class Grid extends Base {
|
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
public getContainer():
|
|
113
|
+
public getContainer(): HTMLElement {
|
|
114
114
|
return this.container;
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { parsePathString } from '@antv/path-util';
|
|
2
1
|
import { DisplayObject } from '@antv/g';
|
|
3
2
|
import { isArray } from '@antv/util';
|
|
4
3
|
import { ComboModel, ID, IGraph, NodeModel } from '../../../types';
|
|
@@ -141,7 +140,7 @@ export default class Hull {
|
|
|
141
140
|
contour.map((p) => [p.x, p.y]),
|
|
142
141
|
this.padding,
|
|
143
142
|
);
|
|
144
|
-
path =
|
|
143
|
+
path = hull;
|
|
145
144
|
break;
|
|
146
145
|
case 'smooth-convex':
|
|
147
146
|
contour = genConvexHull(members);
|
|
@@ -150,7 +149,7 @@ export default class Hull {
|
|
|
150
149
|
contour.map((p) => [p.x, p.y]),
|
|
151
150
|
this.padding,
|
|
152
151
|
);
|
|
153
|
-
path =
|
|
152
|
+
path = hull;
|
|
154
153
|
} else if (contour.length > 2) {
|
|
155
154
|
hull = paddedHull(
|
|
156
155
|
contour.map((p) => [p.x, p.y]),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { vec2 } from '
|
|
1
|
+
import { vec2 } from 'gl-matrix';
|
|
2
2
|
import { ID, IGraph } from 'types';
|
|
3
3
|
import { AABB } from '@antv/g';
|
|
4
4
|
import { Bounds, Point } from '../../../types/common';
|
|
@@ -56,7 +56,11 @@ export function roundedHull(polyPoints: vec2[], padding: number) {
|
|
|
56
56
|
const p1 = [points[0][0], points[0][1] - padding];
|
|
57
57
|
const p2 = [points[0][0], points[0][1] + padding];
|
|
58
58
|
|
|
59
|
-
return
|
|
59
|
+
return [
|
|
60
|
+
['M', p1],
|
|
61
|
+
['A', padding, padding, 0, 0, 0, p2],
|
|
62
|
+
['A', padding, padding, 0, 0, 0, p1],
|
|
63
|
+
];
|
|
60
64
|
};
|
|
61
65
|
|
|
62
66
|
// The rounded hull path around two points
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Category } from '@antv/gui';
|
|
2
2
|
import { Canvas, DisplayObject, Circle, Line } from '@antv/g';
|
|
3
3
|
import { isFunction, isString, upperFirst, uniqueId } from '@antv/util';
|
|
4
|
-
import { createDom } from '@antv/dom-util';
|
|
5
4
|
import { ID } from '@antv/graphlib';
|
|
6
5
|
import { IGraph } from '../../../types';
|
|
7
6
|
import { RendererName } from '../../../types/render';
|
|
8
7
|
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
9
8
|
import { createCanvas } from '../../../util/canvas';
|
|
10
9
|
import { ShapeTagMap, formatPadding } from '../../../util/shape';
|
|
10
|
+
import { createDOM } from '../../../util/dom';
|
|
11
11
|
|
|
12
12
|
const LEGEND_CATEGORY_ITEM_MARKER = '.legend-category-item-marker';
|
|
13
13
|
|
|
@@ -51,7 +51,7 @@ export interface LegendConfig extends IPluginBaseConfig {
|
|
|
51
51
|
/**
|
|
52
52
|
* Container for the legend, using graph's container by default
|
|
53
53
|
*/
|
|
54
|
-
container?:
|
|
54
|
+
container?: HTMLElement | string;
|
|
55
55
|
/**
|
|
56
56
|
* Renderer for the legend canvas, 'canvas' by default
|
|
57
57
|
*/
|
|
@@ -102,7 +102,7 @@ export class Legend extends Base {
|
|
|
102
102
|
*/
|
|
103
103
|
private edgeLegend: Category;
|
|
104
104
|
|
|
105
|
-
private wrapper:
|
|
105
|
+
private wrapper: HTMLElement;
|
|
106
106
|
private canvas: Canvas;
|
|
107
107
|
|
|
108
108
|
private size: ('fit-content' | number)[];
|
|
@@ -303,7 +303,7 @@ export class Legend extends Base {
|
|
|
303
303
|
|
|
304
304
|
/**
|
|
305
305
|
* Creates a wrapper div element for the graph and appends it to the container.
|
|
306
|
-
* @returns {
|
|
306
|
+
* @returns {HTMLElement} - The created wrapper div element.
|
|
307
307
|
*/
|
|
308
308
|
private createWrapper() {
|
|
309
309
|
const { options, graph, size } = this;
|
|
@@ -322,9 +322,9 @@ export class Legend extends Base {
|
|
|
322
322
|
size[0] === 'fit-content' ? 0 : size[0],
|
|
323
323
|
size[1] === 'fit-content' ? 0 : size[1],
|
|
324
324
|
];
|
|
325
|
-
const wrapper = (
|
|
325
|
+
const wrapper = createDOM(
|
|
326
326
|
`<div class='${className}' style='width: ${wrapperSize[0]}px; height: ${wrapperSize[1]}px; overflow: hidden;'></div>`,
|
|
327
|
-
)
|
|
327
|
+
);
|
|
328
328
|
$container.appendChild(wrapper);
|
|
329
329
|
return wrapper;
|
|
330
330
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// TODO: update type define.
|
|
2
2
|
// @ts-nocheck
|
|
3
|
-
import { createDom, modifyCSS } from '@antv/dom-util';
|
|
4
3
|
import { Canvas, DisplayObject, Group, Rect } from '@antv/g';
|
|
5
4
|
import { debounce, each, isNil, isString, uniqueId } from '@antv/util';
|
|
6
5
|
import { IGraph } from '../../../types';
|
|
@@ -8,6 +7,7 @@ import { IG6GraphEvent } from '../../../types/event';
|
|
|
8
7
|
import { ShapeStyle } from '../../../types/item';
|
|
9
8
|
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
10
9
|
import { createCanvas } from '../../../util/canvas';
|
|
10
|
+
import { createDOM, modifyCSS } from '../../../util/dom';
|
|
11
11
|
|
|
12
12
|
const DEFAULT_MODE = 'default';
|
|
13
13
|
const KEYSHAPE_MODE = 'keyShape';
|
|
@@ -32,7 +32,7 @@ export interface MiniMapConfig extends IPluginBaseConfig {
|
|
|
32
32
|
/** Whether to hide edges on minimap to enhance performance */
|
|
33
33
|
hideEdge?: boolean;
|
|
34
34
|
/** Container for minimap */
|
|
35
|
-
container?:
|
|
35
|
+
container?: HTMLElement | null;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export class Minimap extends Base {
|
|
@@ -47,7 +47,7 @@ export class Minimap extends Base {
|
|
|
47
47
|
graphItem: DisplayObject;
|
|
48
48
|
}
|
|
49
49
|
> = new Map();
|
|
50
|
-
private container:
|
|
50
|
+
private container: HTMLElement;
|
|
51
51
|
/** Ratio of (minimap graph size / main graph size). */
|
|
52
52
|
private ratio: number;
|
|
53
53
|
/** Distance from top of minimap graph to the top of minimap container. */
|
|
@@ -111,7 +111,7 @@ export class Minimap extends Base {
|
|
|
111
111
|
const containerDOM = canvas.context.config.container as HTMLElement;
|
|
112
112
|
const isFireFox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
|
113
113
|
const isSafari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
|
|
114
|
-
const viewport =
|
|
114
|
+
const viewport = createDOM(`
|
|
115
115
|
<div
|
|
116
116
|
class=${viewportClassName}
|
|
117
117
|
style='position:absolute;
|
|
@@ -631,12 +631,12 @@ export class Minimap extends Base {
|
|
|
631
631
|
const { graph, options } = this;
|
|
632
632
|
const { size, className } = options;
|
|
633
633
|
let parentNode = options.container;
|
|
634
|
-
const container:
|
|
634
|
+
const container: HTMLElement = createDOM(
|
|
635
635
|
`<div class='${className}' style='width: ${size[0]}px; height: ${size[1]}px; overflow: hidden;'></div>`,
|
|
636
636
|
);
|
|
637
637
|
|
|
638
638
|
if (isString(parentNode)) {
|
|
639
|
-
parentNode = document.getElementById(parentNode) as
|
|
639
|
+
parentNode = document.getElementById(parentNode) as HTMLElement;
|
|
640
640
|
}
|
|
641
641
|
|
|
642
642
|
if (parentNode) {
|
|
@@ -653,7 +653,7 @@ export class Minimap extends Base {
|
|
|
653
653
|
}
|
|
654
654
|
this.container = container;
|
|
655
655
|
|
|
656
|
-
const containerDOM =
|
|
656
|
+
const containerDOM = createDOM(
|
|
657
657
|
'<div class="g6-minimap-container" style="position: relative;"></div>',
|
|
658
658
|
);
|
|
659
659
|
container.appendChild(containerDOM);
|