@antv/g6 5.0.0-beta.3 → 5.0.0-beta.5
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/constant/shape.d.ts +2 -0
- package/esm/index.d.ts +4 -1
- package/esm/index.js +1 -1
- package/esm/item/edge.d.ts +1 -0
- package/esm/item/edge.js +3 -1
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.d.ts +3 -2
- package/esm/item/item.js +12 -6
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +1 -0
- package/esm/item/node.js +11 -4
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/item.js +252 -148
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.d.ts +16 -14
- package/esm/runtime/graph.js +66 -28
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/activate-relations.js +2 -2
- package/esm/stdlib/behavior/activate-relations.js.map +1 -1
- package/esm/stdlib/behavior/click-select.js +1 -1
- package/esm/stdlib/behavior/click-select.js.map +1 -1
- package/esm/stdlib/behavior/drag-canvas.js +50 -27
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/behavior/drag-combo.js +8 -8
- package/esm/stdlib/behavior/drag-combo.js.map +1 -1
- package/esm/stdlib/behavior/drag-node.js +10 -10
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/zoom-canvas.js +47 -24
- package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/esm/stdlib/index.d.ts +3 -0
- package/esm/stdlib/index.js +12 -9
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/edge/base.d.ts +1 -1
- package/esm/stdlib/item/edge/base.js +13 -4
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/node/base.d.ts +1 -1
- package/esm/stdlib/item/node/base.js +18 -26
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/diamond.js +1 -1
- package/esm/stdlib/item/node/ellipse.js +2 -2
- package/esm/stdlib/item/node/hexagon.js +6 -2
- package/esm/stdlib/item/node/hexagon.js.map +1 -1
- package/esm/stdlib/item/node/image.d.ts +40 -0
- package/esm/stdlib/item/node/image.js +110 -0
- package/esm/stdlib/item/node/image.js.map +1 -0
- 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/plugin/history/combo-command.js +2 -2
- package/esm/stdlib/plugin/history/combo-command.js.map +1 -1
- package/esm/stdlib/plugin/history/index.d.ts +10 -10
- package/esm/stdlib/plugin/history/index.js +14 -14
- package/esm/stdlib/plugin/history/index.js.map +1 -1
- package/esm/stdlib/plugin/history/item-data-command.js +4 -4
- package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
- package/esm/stdlib/plugin/history/layer-updated-command.js +2 -2
- package/esm/stdlib/plugin/history/layer-updated-command.js.map +1 -1
- package/esm/stdlib/plugin/history/state-updated-command.js +1 -1
- package/esm/stdlib/plugin/history/state-updated-command.js.map +1 -1
- package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
- package/esm/stdlib/plugin/history/visibility-updated-command.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/snapline/index.d.ts +163 -0
- package/esm/stdlib/plugin/snapline/index.js +1052 -0
- package/esm/stdlib/plugin/snapline/index.js.map +1 -0
- package/esm/stdlib/plugin/types.d.ts +1 -0
- package/esm/stdlib/theme/dark.js +42 -2
- package/esm/stdlib/theme/dark.js.map +1 -1
- package/esm/stdlib/theme/light.js +4 -4
- package/esm/types/graph.d.ts +14 -14
- package/esm/types/hook.d.ts +6 -0
- package/esm/types/item.d.ts +6 -0
- package/esm/types/item.js.map +1 -1
- package/esm/types/spec.d.ts +13 -0
- package/esm/util/bbox.d.ts +16 -1
- package/esm/util/bbox.js +29 -0
- package/esm/util/bbox.js.map +1 -1
- package/esm/util/shape.js +2 -2
- package/esm/util/shape.js.map +1 -1
- package/lib/constant/shape.d.ts +2 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.js +1 -1
- package/lib/item/edge.d.ts +1 -0
- package/lib/item/edge.js +3 -1
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.d.ts +3 -2
- package/lib/item/item.js +12 -6
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +1 -0
- package/lib/item/node.js +11 -4
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/item.js +251 -147
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.d.ts +16 -14
- package/lib/runtime/graph.js +66 -28
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/activate-relations.js +2 -2
- package/lib/stdlib/behavior/activate-relations.js.map +1 -1
- package/lib/stdlib/behavior/click-select.js +1 -1
- package/lib/stdlib/behavior/click-select.js.map +1 -1
- package/lib/stdlib/behavior/drag-canvas.js +50 -27
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/behavior/drag-combo.js +8 -8
- package/lib/stdlib/behavior/drag-combo.js.map +1 -1
- package/lib/stdlib/behavior/drag-node.js +10 -10
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/zoom-canvas.js +47 -24
- package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/lib/stdlib/index.d.ts +3 -0
- package/lib/stdlib/index.js +12 -9
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/edge/base.d.ts +1 -1
- package/lib/stdlib/item/edge/base.js +13 -4
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/node/base.d.ts +1 -1
- package/lib/stdlib/item/node/base.js +18 -26
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/diamond.js +1 -1
- package/lib/stdlib/item/node/ellipse.js +2 -2
- package/lib/stdlib/item/node/hexagon.js +6 -2
- package/lib/stdlib/item/node/hexagon.js.map +1 -1
- package/lib/stdlib/item/node/image.d.ts +40 -0
- package/lib/stdlib/item/node/image.js +114 -0
- package/lib/stdlib/item/node/image.js.map +1 -0
- 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/plugin/history/combo-command.js +2 -2
- package/lib/stdlib/plugin/history/combo-command.js.map +1 -1
- package/lib/stdlib/plugin/history/index.d.ts +10 -10
- package/lib/stdlib/plugin/history/index.js +14 -14
- package/lib/stdlib/plugin/history/index.js.map +1 -1
- package/lib/stdlib/plugin/history/item-data-command.js +4 -4
- package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
- package/lib/stdlib/plugin/history/layer-updated-command.js +2 -2
- package/lib/stdlib/plugin/history/layer-updated-command.js.map +1 -1
- package/lib/stdlib/plugin/history/state-updated-command.js +1 -1
- package/lib/stdlib/plugin/history/state-updated-command.js.map +1 -1
- package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
- package/lib/stdlib/plugin/history/visibility-updated-command.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/snapline/index.d.ts +163 -0
- package/lib/stdlib/plugin/snapline/index.js +1056 -0
- package/lib/stdlib/plugin/snapline/index.js.map +1 -0
- package/lib/stdlib/plugin/types.d.ts +1 -0
- package/lib/stdlib/theme/dark.js +42 -2
- package/lib/stdlib/theme/dark.js.map +1 -1
- package/lib/stdlib/theme/light.js +4 -4
- package/lib/types/graph.d.ts +14 -14
- package/lib/types/hook.d.ts +6 -0
- package/lib/types/item.d.ts +6 -0
- package/lib/types/item.js.map +1 -1
- package/lib/types/spec.d.ts +13 -0
- package/lib/util/bbox.d.ts +16 -1
- package/lib/util/bbox.js +32 -1
- package/lib/util/bbox.js.map +1 -1
- package/lib/util/shape.js +2 -2
- package/lib/util/shape.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/item/edge.ts +4 -1
- package/src/item/item.ts +11 -6
- package/src/item/node.ts +18 -10
- package/src/runtime/controller/item.ts +212 -66
- package/src/runtime/graph.ts +91 -29
- package/src/stdlib/behavior/activate-relations.ts +2 -2
- package/src/stdlib/behavior/click-select.ts +1 -1
- package/src/stdlib/behavior/drag-canvas.ts +65 -27
- package/src/stdlib/behavior/drag-combo.ts +8 -8
- package/src/stdlib/behavior/drag-node.ts +10 -10
- package/src/stdlib/behavior/zoom-canvas.ts +60 -24
- package/src/stdlib/index.ts +12 -7
- package/src/stdlib/item/edge/base.ts +13 -5
- package/src/stdlib/item/node/base.ts +24 -29
- package/src/stdlib/item/node/diamond.ts +1 -1
- package/src/stdlib/item/node/ellipse.ts +2 -2
- package/src/stdlib/item/node/hexagon.ts +6 -2
- package/src/stdlib/item/node/image.ts +190 -0
- package/src/stdlib/item/node/index.ts +1 -0
- package/src/stdlib/plugin/history/combo-command.ts +2 -2
- package/src/stdlib/plugin/history/index.ts +14 -14
- package/src/stdlib/plugin/history/item-data-command.ts +4 -4
- package/src/stdlib/plugin/history/layer-updated-command.ts +2 -2
- package/src/stdlib/plugin/history/state-updated-command.ts +1 -1
- package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
- package/src/stdlib/plugin/index.ts +1 -0
- package/src/stdlib/plugin/snapline/index.ts +1277 -0
- package/src/stdlib/plugin/types.ts +1 -0
- package/src/stdlib/theme/dark.ts +66 -2
- package/src/stdlib/theme/light.ts +4 -4
- package/src/types/graph.ts +22 -17
- package/src/types/hook.ts +6 -0
- package/src/types/item.ts +10 -0
- package/src/types/spec.ts +13 -0
- package/src/util/bbox.ts +38 -1
- package/src/util/shape.ts +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ID, IG6GraphEvent } from 'types';
|
|
2
2
|
import { Behavior } from '../../types/behavior';
|
|
3
|
+
import { isNumber } from '@antv/util';
|
|
3
4
|
|
|
4
5
|
const VALID_TRIGGERS = ['wheel', 'upDownKeys'];
|
|
5
6
|
export interface ZoomCanvasOptions {
|
|
@@ -56,7 +57,7 @@ export interface ZoomCanvasOptions {
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
const DEFAULT_OPTIONS: Required<ZoomCanvasOptions> = {
|
|
59
|
-
enableOptimize:
|
|
60
|
+
enableOptimize: undefined,
|
|
60
61
|
triggerOnItems: true,
|
|
61
62
|
sensitivity: 2,
|
|
62
63
|
trigger: 'wheel',
|
|
@@ -114,43 +115,78 @@ export class ZoomCanvas extends Behavior {
|
|
|
114
115
|
|
|
115
116
|
private hideShapes() {
|
|
116
117
|
const { graph } = this;
|
|
117
|
-
|
|
118
|
+
const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
|
|
119
|
+
graph.getSpecification().optimize || {};
|
|
120
|
+
const optimize = this.options.enableOptimize || graphBehaviorOptimize;
|
|
121
|
+
const shouldOptimzie = isNumber(optimize)
|
|
122
|
+
? graph.getAllNodesData().length > optimize
|
|
123
|
+
: optimize;
|
|
124
|
+
if (shouldOptimzie) {
|
|
118
125
|
this.hiddenEdgeIds = graph
|
|
119
126
|
.getAllEdgesData()
|
|
120
127
|
.map((edge) => edge.id)
|
|
121
128
|
.filter((id) => graph.getItemVisible(id) === true);
|
|
122
|
-
// TODO
|
|
123
|
-
graph.hideItem(this.hiddenEdgeIds, false);
|
|
124
129
|
this.hiddenNodeIds = graph
|
|
125
130
|
.getAllNodesData()
|
|
126
131
|
.map((node) => node.id)
|
|
127
132
|
.filter((id) => graph.getItemVisible(id) === true);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
|
|
134
|
+
let requestId;
|
|
135
|
+
const hiddenIds = [...this.hiddenNodeIds];
|
|
136
|
+
const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
|
|
137
|
+
const sections = Array.from({ length: sectionNum }, (v, i) =>
|
|
138
|
+
hiddenIds.slice(
|
|
139
|
+
i * tileBehaviorSize,
|
|
140
|
+
i * tileBehaviorSize + tileBehaviorSize,
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
const update = () => {
|
|
144
|
+
if (!sections.length) {
|
|
145
|
+
cancelAnimationFrame(requestId);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const section = sections.shift();
|
|
149
|
+
graph.hideItem(section, false, true);
|
|
150
|
+
requestId = requestAnimationFrame(update);
|
|
151
|
+
};
|
|
152
|
+
graph.startHistoryBatch();
|
|
153
|
+
requestId = requestAnimationFrame(update);
|
|
154
|
+
graph.stopHistoryBatch();
|
|
135
155
|
}
|
|
136
156
|
}
|
|
137
157
|
|
|
138
158
|
private endZoom() {
|
|
139
|
-
const { graph, hiddenEdgeIds, hiddenNodeIds } = this;
|
|
140
|
-
const {
|
|
159
|
+
const { graph, hiddenEdgeIds = [], hiddenNodeIds } = this;
|
|
160
|
+
const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
|
|
161
|
+
graph.getSpecification().optimize || {};
|
|
162
|
+
const optimize = this.options.enableOptimize || graphBehaviorOptimize;
|
|
163
|
+
const shouldOptimzie = isNumber(optimize)
|
|
164
|
+
? graph.getAllNodesData().length > optimize
|
|
165
|
+
: optimize;
|
|
141
166
|
this.zooming = false;
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
167
|
+
if (shouldOptimzie) {
|
|
168
|
+
if (hiddenNodeIds) {
|
|
169
|
+
let requestId;
|
|
170
|
+
const hiddenIds = [...hiddenNodeIds, ...hiddenEdgeIds];
|
|
171
|
+
const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
|
|
172
|
+
const sections = Array.from({ length: sectionNum }, (v, i) =>
|
|
173
|
+
hiddenIds.slice(
|
|
174
|
+
i * tileBehaviorSize,
|
|
175
|
+
i * tileBehaviorSize + tileBehaviorSize,
|
|
176
|
+
),
|
|
177
|
+
);
|
|
178
|
+
const update = () => {
|
|
179
|
+
if (!sections.length) {
|
|
180
|
+
cancelAnimationFrame(requestId);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
graph.showItem(sections.shift(), false);
|
|
184
|
+
requestId = requestAnimationFrame(update);
|
|
185
|
+
};
|
|
186
|
+
graph.executeWithNoStack(() => {
|
|
187
|
+
requestId = requestAnimationFrame(update);
|
|
188
|
+
});
|
|
146
189
|
}
|
|
147
|
-
// TODO
|
|
148
|
-
// if (hiddenNodeIds) {
|
|
149
|
-
// hiddenNodeIds.forEach((id) => {
|
|
150
|
-
// graph.drawTransient('node', id, { action: 'remove' });
|
|
151
|
-
// });
|
|
152
|
-
// graph.showItem(hiddenNodeIds, false);
|
|
153
|
-
// }
|
|
154
190
|
}
|
|
155
191
|
this.hiddenEdgeIds = [];
|
|
156
192
|
this.hiddenNodeIds = [];
|
package/src/stdlib/index.ts
CHANGED
|
@@ -31,6 +31,7 @@ const {
|
|
|
31
31
|
TriangleNode,
|
|
32
32
|
EllipseNode,
|
|
33
33
|
ModelRectNode,
|
|
34
|
+
ImageNode,
|
|
34
35
|
} = Nodes;
|
|
35
36
|
|
|
36
37
|
const {
|
|
@@ -72,6 +73,7 @@ const {
|
|
|
72
73
|
Legend,
|
|
73
74
|
Toolbar,
|
|
74
75
|
Timebar,
|
|
76
|
+
Snapline,
|
|
75
77
|
} = Plugins;
|
|
76
78
|
|
|
77
79
|
const {
|
|
@@ -129,6 +131,7 @@ const stdLib = {
|
|
|
129
131
|
nodes: {
|
|
130
132
|
'circle-node': CircleNode,
|
|
131
133
|
'rect-node': RectNode,
|
|
134
|
+
'image-node': ImageNode,
|
|
132
135
|
},
|
|
133
136
|
edges: {
|
|
134
137
|
'line-edge': LineEdge,
|
|
@@ -204,13 +207,13 @@ const Extensions = {
|
|
|
204
207
|
ValidateData,
|
|
205
208
|
TransformV4Data,
|
|
206
209
|
MapNodeSize,
|
|
207
|
-
//themes
|
|
210
|
+
// themes
|
|
208
211
|
LightTheme,
|
|
209
212
|
DarkTheme,
|
|
210
|
-
//themeSolvers
|
|
213
|
+
// themeSolvers
|
|
211
214
|
SpecThemeSolver,
|
|
212
215
|
SubjectThemeSolver,
|
|
213
|
-
//layout
|
|
216
|
+
// layout
|
|
214
217
|
ForceLayout,
|
|
215
218
|
GridLayout,
|
|
216
219
|
CircularLayout,
|
|
@@ -223,12 +226,12 @@ const Extensions = {
|
|
|
223
226
|
ForceAtlas2Layout,
|
|
224
227
|
DagreLayout,
|
|
225
228
|
ComboCombinedLayout,
|
|
226
|
-
//Hierarchy
|
|
229
|
+
// Hierarchy
|
|
227
230
|
compactBox,
|
|
228
231
|
dendrogram,
|
|
229
232
|
indented,
|
|
230
233
|
mindmap,
|
|
231
|
-
//nodes
|
|
234
|
+
// nodes
|
|
232
235
|
CircleNode,
|
|
233
236
|
RectNode,
|
|
234
237
|
DiamondNode,
|
|
@@ -250,7 +253,7 @@ const Extensions = {
|
|
|
250
253
|
// combos
|
|
251
254
|
CircleCombo,
|
|
252
255
|
RectCombo,
|
|
253
|
-
//behaviors
|
|
256
|
+
// behaviors
|
|
254
257
|
BaseBehavior,
|
|
255
258
|
ActivateRelations,
|
|
256
259
|
BrushSelect,
|
|
@@ -266,7 +269,8 @@ const Extensions = {
|
|
|
266
269
|
CollapseExpandCombo,
|
|
267
270
|
DragNode,
|
|
268
271
|
DragCombo,
|
|
269
|
-
|
|
272
|
+
ShortcutsCall,
|
|
273
|
+
// plugins
|
|
270
274
|
BasePlugin,
|
|
271
275
|
History,
|
|
272
276
|
Toolbar,
|
|
@@ -278,6 +282,7 @@ const Extensions = {
|
|
|
278
282
|
Legend,
|
|
279
283
|
Timebar,
|
|
280
284
|
Hull,
|
|
285
|
+
Snapline,
|
|
281
286
|
};
|
|
282
287
|
|
|
283
288
|
export default registery;
|
|
@@ -550,7 +550,11 @@ export abstract class BaseEdge {
|
|
|
550
550
|
* @param shapeMap The shape map that contains all of the elements to show on the edge.
|
|
551
551
|
* @param zoom The zoom level of the graph.
|
|
552
552
|
*/
|
|
553
|
-
public onZoom = (
|
|
553
|
+
public onZoom = (
|
|
554
|
+
shapeMap: EdgeShapeMap,
|
|
555
|
+
zoom: number,
|
|
556
|
+
cacheHiddenShape = {},
|
|
557
|
+
) => {
|
|
554
558
|
// balance the size for label, badges
|
|
555
559
|
this.balanceShapeSize(shapeMap, zoom);
|
|
556
560
|
|
|
@@ -574,7 +578,10 @@ export abstract class BaseEdge {
|
|
|
574
578
|
// zoomLevel changed, from higher to lower, hide something
|
|
575
579
|
if (firstRender) {
|
|
576
580
|
for (let i = currentLevel + 1; i <= maxLevel; i++) {
|
|
577
|
-
levelShapes[String(i)]?.forEach((id) =>
|
|
581
|
+
levelShapes[String(i)]?.forEach((id) => {
|
|
582
|
+
if (!shapeMap[id] || cacheHiddenShape[id]) return;
|
|
583
|
+
shapeMap[id]?.hide();
|
|
584
|
+
});
|
|
578
585
|
}
|
|
579
586
|
} else {
|
|
580
587
|
for (let i = currentLevel + 1; i <= maxLevel; i++) {
|
|
@@ -586,7 +593,8 @@ export abstract class BaseEdge {
|
|
|
586
593
|
} else if (currentLevel > previousLevel) {
|
|
587
594
|
// zoomLevel changed, from lower to higher, show something
|
|
588
595
|
for (let i = currentLevel; i >= minLevel; i--) {
|
|
589
|
-
levelShapes[String(i)]?.forEach((id) =>
|
|
596
|
+
levelShapes[String(i)]?.forEach((id) => {
|
|
597
|
+
if (hiddenShape[id]) return;
|
|
590
598
|
fadeIn(
|
|
591
599
|
id,
|
|
592
600
|
shapeMap[id],
|
|
@@ -594,8 +602,8 @@ export abstract class BaseEdge {
|
|
|
594
602
|
this.mergedStyles[id.replace('Background', '')],
|
|
595
603
|
hiddenShape,
|
|
596
604
|
animateConfig,
|
|
597
|
-
)
|
|
598
|
-
);
|
|
605
|
+
);
|
|
606
|
+
});
|
|
599
607
|
}
|
|
600
608
|
}
|
|
601
609
|
|
|
@@ -186,10 +186,10 @@ export abstract class BaseNode {
|
|
|
186
186
|
});
|
|
187
187
|
this.zoomCache.levelShapes = levelShapes;
|
|
188
188
|
|
|
189
|
-
if (shapeMap.labelShape
|
|
189
|
+
if (shapeMap.labelShape) {
|
|
190
190
|
const { maxWidth = '200%' } = this.mergedStyles.labelShape || {};
|
|
191
191
|
this.zoomCache.wordWrapWidth = getWordWrapWidthByBox(
|
|
192
|
-
|
|
192
|
+
shapeMap.keyShape.getLocalBounds(),
|
|
193
193
|
maxWidth,
|
|
194
194
|
1,
|
|
195
195
|
);
|
|
@@ -286,12 +286,10 @@ export abstract class BaseNode {
|
|
|
286
286
|
const { labelShape: shapeStyle } = this.mergedStyles;
|
|
287
287
|
if (!shapeStyle || !shapeStyle.text || !model.data.labelShape) return;
|
|
288
288
|
const { keyShape } = shapeMap;
|
|
289
|
-
this.boundsCache.keyShapeLocal =
|
|
290
|
-
this.boundsCache.keyShapeLocal || keyShape.getLocalBounds();
|
|
291
289
|
const keyShapeBox = getShapeLocalBoundsByStyle(
|
|
292
290
|
keyShape,
|
|
293
291
|
this.mergedStyles.keyShape,
|
|
294
|
-
|
|
292
|
+
keyShape.getLocalBounds(),
|
|
295
293
|
);
|
|
296
294
|
const {
|
|
297
295
|
position,
|
|
@@ -577,12 +575,12 @@ export abstract class BaseNode {
|
|
|
577
575
|
position: string | [number, number],
|
|
578
576
|
anchorPositionMap: IAnchorPositionMap,
|
|
579
577
|
): [number, number] {
|
|
580
|
-
const keyShapeBBox = this.boundsCache.keyShapeLocal
|
|
578
|
+
const keyShapeBBox = this.boundsCache.keyShapeLocal!;
|
|
581
579
|
const keyShapeWidth = keyShapeBBox.max[0] - keyShapeBBox.min[0];
|
|
582
580
|
const keyShapeHeight = keyShapeBBox.max[1] - keyShapeBBox.min[1];
|
|
583
581
|
const defaultPosition: [number, number] = [
|
|
584
|
-
keyShapeBBox.max[0],
|
|
585
|
-
keyShapeBBox.min[1],
|
|
582
|
+
keyShapeBBox.max[0] - keyShapeBBox.center[0],
|
|
583
|
+
keyShapeBBox.min[1] - keyShapeBBox.center[1],
|
|
586
584
|
]; //topRight
|
|
587
585
|
if (position instanceof Array) {
|
|
588
586
|
return [
|
|
@@ -645,12 +643,10 @@ export abstract class BaseNode {
|
|
|
645
643
|
(style) => style.tag === 'badgeShape',
|
|
646
644
|
);
|
|
647
645
|
if (!individualConfigs.length) return {};
|
|
648
|
-
this.boundsCache.keyShapeLocal =
|
|
649
|
-
this.boundsCache.keyShapeLocal || shapeMap.keyShape.getLocalBounds();
|
|
650
646
|
const keyShapeBBox = getShapeLocalBoundsByStyle(
|
|
651
647
|
shapeMap.keyShape,
|
|
652
648
|
keyShapeStyle,
|
|
653
|
-
|
|
649
|
+
shapeMap.keyShape.getLocalBounds(),
|
|
654
650
|
);
|
|
655
651
|
const keyShapeSize = Math.min(
|
|
656
652
|
keyShapeBBox.max[0] - keyShapeBBox.min[0],
|
|
@@ -759,8 +755,6 @@ export abstract class BaseNode {
|
|
|
759
755
|
(text as string).length <= 1
|
|
760
756
|
? bgHeight
|
|
761
757
|
: Math.max(bgHeight, bbox.max[0] - bbox.min[0]) + 8;
|
|
762
|
-
let bgX = isLeft ? pos.x - bgWidth : pos.x;
|
|
763
|
-
if (isCenter) bgX = pos.x - bgWidth / 2;
|
|
764
758
|
shapes[bgShapeId] = this.upsertShape(
|
|
765
759
|
'rect',
|
|
766
760
|
bgShapeId,
|
|
@@ -771,8 +765,8 @@ export abstract class BaseNode {
|
|
|
771
765
|
width: bgWidth,
|
|
772
766
|
radius: bgHeight / 2,
|
|
773
767
|
zIndex,
|
|
774
|
-
x:
|
|
775
|
-
y:
|
|
768
|
+
x: bbox.center[0] - bgWidth / 2,
|
|
769
|
+
y: bbox.center[1] - bgHeight / 2,
|
|
776
770
|
...otherStyles,
|
|
777
771
|
} as GShapeStyle,
|
|
778
772
|
shapeMap,
|
|
@@ -810,7 +804,11 @@ export abstract class BaseNode {
|
|
|
810
804
|
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
811
805
|
* @param zoom The zoom level of the graph.
|
|
812
806
|
*/
|
|
813
|
-
public onZoom = (
|
|
807
|
+
public onZoom = (
|
|
808
|
+
shapeMap: NodeShapeMap | ComboShapeMap,
|
|
809
|
+
zoom: number,
|
|
810
|
+
cacheHiddenShape = {},
|
|
811
|
+
) => {
|
|
814
812
|
// zoomLevel changed
|
|
815
813
|
if (this.lodStrategy) {
|
|
816
814
|
const { levels } = this.lodStrategy;
|
|
@@ -831,7 +829,7 @@ export abstract class BaseNode {
|
|
|
831
829
|
// zoomLevel changed, from higher to lower, hide something
|
|
832
830
|
for (let i = currentLevel + 1; i <= maxLevel; i++) {
|
|
833
831
|
levelShapes[String(i)]?.forEach((id) => {
|
|
834
|
-
if (!shapeMap[id]) return;
|
|
832
|
+
if (!shapeMap[id] || cacheHiddenShape[id]) return;
|
|
835
833
|
shapeMap[id].hide();
|
|
836
834
|
hiddenShape[id] = true;
|
|
837
835
|
});
|
|
@@ -880,8 +878,7 @@ export abstract class BaseNode {
|
|
|
880
878
|
const balanceRatio = 1 / zoom || 1;
|
|
881
879
|
this.zoomCache.balanceRatio = balanceRatio;
|
|
882
880
|
if (!labelShape || !labelShape.isVisible()) return;
|
|
883
|
-
const {
|
|
884
|
-
const { position = 'bottom' } = labelStyle;
|
|
881
|
+
const { position = 'bottom' } = this.mergedStyles.labelShape;
|
|
885
882
|
|
|
886
883
|
const keyShapeLocal = keyShape.getLocalBounds();
|
|
887
884
|
if (zoom < 1) {
|
|
@@ -923,21 +920,20 @@ export abstract class BaseNode {
|
|
|
923
920
|
const scaleTransform = `scale(${balanceRatio}, ${balanceRatio})`;
|
|
924
921
|
labelShape.style.transform = `${oriTransform} ${scaleTransform}`;
|
|
925
922
|
this.scaleTransformCache = scaleTransform;
|
|
926
|
-
|
|
927
|
-
labelShape.style.wordWrapWidth = wordWrapWidth;
|
|
923
|
+
labelShape.style.wordWrapWidth = this.zoomCache.wordWrapWidth * zoom;
|
|
928
924
|
|
|
929
925
|
if (!labelBackgroundShape || !labelBackgroundShape.isVisible()) return;
|
|
930
926
|
|
|
931
|
-
const
|
|
927
|
+
const [paddingTop, paddingRight, paddingBottom, paddingLeft] = this
|
|
928
|
+
.mergedStyles.labelBackgroundShape.padding as number[];
|
|
929
|
+
const sidePadding = paddingRight + paddingLeft;
|
|
932
930
|
const { width, height, x, y } = labelBackgroundShape.attributes;
|
|
933
|
-
const [paddingTop, paddingRight, paddingBottom, paddingLeft] =
|
|
934
|
-
padding as number[];
|
|
935
931
|
|
|
936
932
|
switch (position) {
|
|
937
933
|
case 'top':
|
|
938
934
|
// if it is zoom-out, do not scale the gap between keyShape and labelShape, differentiate from zoom-in by adjusting transformOrigin
|
|
939
935
|
labelBackgroundShape.style.transformOrigin = `${
|
|
940
|
-
paddingLeft + (width -
|
|
936
|
+
paddingLeft + (width - sidePadding) / 2
|
|
941
937
|
} ${zoom < 1 ? height - paddingBottom : keyShapeLocal.min[1] - y}`;
|
|
942
938
|
break;
|
|
943
939
|
case 'left':
|
|
@@ -952,7 +948,7 @@ export abstract class BaseNode {
|
|
|
952
948
|
break;
|
|
953
949
|
case 'bottom':
|
|
954
950
|
labelBackgroundShape.style.transformOrigin = `${
|
|
955
|
-
paddingLeft + (width -
|
|
951
|
+
paddingLeft + (width - sidePadding) / 2
|
|
956
952
|
} ${
|
|
957
953
|
zoom < 1
|
|
958
954
|
? paddingTop + (height - paddingTop - paddingBottom) / 2
|
|
@@ -962,14 +958,13 @@ export abstract class BaseNode {
|
|
|
962
958
|
default:
|
|
963
959
|
// center
|
|
964
960
|
labelBackgroundShape.style.transformOrigin = `${
|
|
965
|
-
paddingLeft + (width -
|
|
961
|
+
paddingLeft + (width - sidePadding) / 2
|
|
966
962
|
} ${paddingTop + (height - paddingTop - paddingBottom) / 2}`;
|
|
967
963
|
}
|
|
968
964
|
|
|
969
965
|
const { labelShapeGeometry: labelBBox } = this.boundsCache;
|
|
970
966
|
const labelWidth = labelBBox.max[0] - labelBBox.min[0];
|
|
971
|
-
const xAxistRatio =
|
|
972
|
-
(labelWidth * balanceRatio + paddingLeft + paddingRight) / width;
|
|
967
|
+
const xAxistRatio = (labelWidth * balanceRatio + sidePadding) / width;
|
|
973
968
|
|
|
974
969
|
labelBackgroundShape.style.transform = `scale(${xAxistRatio}, ${balanceRatio})`;
|
|
975
970
|
}
|
|
@@ -17,10 +17,10 @@ const offsetAngleMap = {
|
|
|
17
17
|
export class HexagonNode extends BaseNode {
|
|
18
18
|
override defaultStyles = {
|
|
19
19
|
keyShape: {
|
|
20
|
-
r:
|
|
20
|
+
r: 16,
|
|
21
21
|
x: 0,
|
|
22
22
|
y: 0,
|
|
23
|
-
direction: '
|
|
23
|
+
direction: 'vertical',
|
|
24
24
|
},
|
|
25
25
|
};
|
|
26
26
|
mergedStyles: NodeShapeStyles;
|
|
@@ -167,6 +167,10 @@ export class HexagonNode extends BaseNode {
|
|
|
167
167
|
const vy = r * Math.sin(angle);
|
|
168
168
|
anchorPositionMap[anchorPositionDirection[i]] = [vx, vy];
|
|
169
169
|
}
|
|
170
|
+
if (!anchorPositionMap.hasOwnProperty('default')) {
|
|
171
|
+
anchorPositionMap['default'] =
|
|
172
|
+
anchorPositionMap[anchorPositionDirection[0]];
|
|
173
|
+
}
|
|
170
174
|
return anchorPositionMap;
|
|
171
175
|
}
|
|
172
176
|
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { ComboDisplayModel, NodeDisplayModel } from '../../../types';
|
|
3
|
+
import { State } from '../../../types/item';
|
|
4
|
+
import {
|
|
5
|
+
NodeModelData,
|
|
6
|
+
NodeShapeMap,
|
|
7
|
+
NodeShapeStyles,
|
|
8
|
+
} from '../../../types/node';
|
|
9
|
+
import { convertToNumber } from '../../../util/type';
|
|
10
|
+
import { ComboModelData, ComboShapeMap } from '../../../types/combo';
|
|
11
|
+
import { ShapeTagMap } from '../../../util/shape';
|
|
12
|
+
import { BaseNode } from './base';
|
|
13
|
+
|
|
14
|
+
export class ImageNode extends BaseNode {
|
|
15
|
+
override defaultStyles = {
|
|
16
|
+
keyShape: {
|
|
17
|
+
x: 0,
|
|
18
|
+
y: 0,
|
|
19
|
+
width: 32,
|
|
20
|
+
height: 32,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
mergedStyles: NodeShapeStyles;
|
|
24
|
+
constructor(props) {
|
|
25
|
+
super(props);
|
|
26
|
+
// suggest to merge default styles like this to avoid style value missing
|
|
27
|
+
// this.defaultStyles = mergeStyles([this.baseDefaultStyles, this.defaultStyles]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public override drawKeyShape(
|
|
31
|
+
model: NodeDisplayModel,
|
|
32
|
+
shapeMap: NodeShapeMap,
|
|
33
|
+
diffData?: { previous: NodeModelData; current: NodeModelData },
|
|
34
|
+
diffState?: { previous: State[]; current: State[] },
|
|
35
|
+
): DisplayObject {
|
|
36
|
+
const clipCfg = this.mergedStyles.keyShape?.clipCfg;
|
|
37
|
+
let clipPath: DisplayObject | undefined;
|
|
38
|
+
if (clipCfg) {
|
|
39
|
+
const { type, ...rest } = clipCfg;
|
|
40
|
+
clipPath = new ShapeTagMap[type]();
|
|
41
|
+
clipPath.attr(rest);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const shape = this.upsertShape(
|
|
45
|
+
'image',
|
|
46
|
+
'keyShape',
|
|
47
|
+
{
|
|
48
|
+
...this.mergedStyles.keyShape,
|
|
49
|
+
x: this.mergedStyles.keyShape!.x,
|
|
50
|
+
y: this.mergedStyles.keyShape!.y,
|
|
51
|
+
anchor: '0.5 0.5',
|
|
52
|
+
},
|
|
53
|
+
shapeMap,
|
|
54
|
+
model,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
if (clipPath) {
|
|
58
|
+
shape.appendChild(clipPath);
|
|
59
|
+
shape.attr('clipPath', clipPath);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return shape;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public override calculateAnchorPosition(keyShapeStyle) {
|
|
66
|
+
const x = convertToNumber(keyShapeStyle.x);
|
|
67
|
+
const y = convertToNumber(keyShapeStyle.y);
|
|
68
|
+
const height = keyShapeStyle.height;
|
|
69
|
+
const width = keyShapeStyle.width;
|
|
70
|
+
const anchorPositionMap = {};
|
|
71
|
+
anchorPositionMap['top'] = [x, y - height / 2];
|
|
72
|
+
anchorPositionMap['left'] = [x - width / 2, y];
|
|
73
|
+
anchorPositionMap['right'] = anchorPositionMap['default'] = [
|
|
74
|
+
x + width / 2,
|
|
75
|
+
y,
|
|
76
|
+
];
|
|
77
|
+
anchorPositionMap['bottom'] = [x, y + height / 2];
|
|
78
|
+
return anchorPositionMap;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public draw(
|
|
82
|
+
model: NodeDisplayModel,
|
|
83
|
+
shapeMap: NodeShapeMap,
|
|
84
|
+
diffData?: { previous: NodeModelData; current: NodeModelData },
|
|
85
|
+
diffState?: { previous: State[]; current: State[] },
|
|
86
|
+
): NodeShapeMap {
|
|
87
|
+
const { data = {} } = model;
|
|
88
|
+
let shapes: NodeShapeMap = { keyShape: undefined };
|
|
89
|
+
|
|
90
|
+
// keyShape
|
|
91
|
+
shapes.keyShape = this.drawKeyShape(model, shapeMap, diffData);
|
|
92
|
+
|
|
93
|
+
// labelShape
|
|
94
|
+
if (data.labelShape) {
|
|
95
|
+
shapes.labelShape = this.drawLabelShape(model, shapeMap, diffData);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// haloShape
|
|
99
|
+
if (data.haloShape && this.drawHaloShape) {
|
|
100
|
+
shapes.haloShape = this.drawHaloShape(model, shapeMap, diffData);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// labelBackgroundShape
|
|
104
|
+
if (data.labelBackgroundShape) {
|
|
105
|
+
shapes.labelBackgroundShape = this.drawLabelBackgroundShape(
|
|
106
|
+
model,
|
|
107
|
+
shapeMap,
|
|
108
|
+
diffData,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// anchor shapes
|
|
113
|
+
if (data.anchorShapes) {
|
|
114
|
+
const anchorShapes = this.drawAnchorShapes(
|
|
115
|
+
model,
|
|
116
|
+
shapeMap,
|
|
117
|
+
diffData,
|
|
118
|
+
diffState,
|
|
119
|
+
);
|
|
120
|
+
shapes = {
|
|
121
|
+
...shapes,
|
|
122
|
+
...anchorShapes,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// iconShape
|
|
127
|
+
if (data.iconShape) {
|
|
128
|
+
shapes.iconShape = this.drawIconShape(model, shapeMap, diffData);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// badgeShape
|
|
132
|
+
if (data.badgeShapes) {
|
|
133
|
+
const badgeShapes = this.drawBadgeShapes(
|
|
134
|
+
model,
|
|
135
|
+
shapeMap,
|
|
136
|
+
diffData,
|
|
137
|
+
diffState,
|
|
138
|
+
);
|
|
139
|
+
shapes = {
|
|
140
|
+
...shapes,
|
|
141
|
+
...badgeShapes,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// otherShapes
|
|
146
|
+
if (data.otherShapes && this.drawOtherShapes) {
|
|
147
|
+
shapes = {
|
|
148
|
+
...shapes,
|
|
149
|
+
...this.drawOtherShapes(model, shapeMap, diffData),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return shapes;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public drawHaloShape(
|
|
156
|
+
model: NodeDisplayModel | ComboDisplayModel,
|
|
157
|
+
shapeMap: NodeShapeMap | ComboShapeMap,
|
|
158
|
+
diffData?: {
|
|
159
|
+
previous: NodeModelData | ComboModelData;
|
|
160
|
+
current: NodeModelData | ComboModelData;
|
|
161
|
+
},
|
|
162
|
+
diffState?: { previous: State[]; current: State[] },
|
|
163
|
+
): DisplayObject {
|
|
164
|
+
const { keyShape } = shapeMap;
|
|
165
|
+
const { haloShape: haloShapeStyle, keyShape: keyShapeStyle } =
|
|
166
|
+
this.mergedStyles;
|
|
167
|
+
if (haloShapeStyle?.visible === false) return;
|
|
168
|
+
|
|
169
|
+
const clipShape = haloShapeStyle?.clipCfg?.type || 'rect';
|
|
170
|
+
const { attributes } = keyShape;
|
|
171
|
+
const { x, y, fill } = attributes;
|
|
172
|
+
|
|
173
|
+
return this.upsertShape(
|
|
174
|
+
clipShape,
|
|
175
|
+
'haloShape',
|
|
176
|
+
{
|
|
177
|
+
...attributes,
|
|
178
|
+
...keyShapeStyle,
|
|
179
|
+
x,
|
|
180
|
+
y,
|
|
181
|
+
stroke: fill,
|
|
182
|
+
...haloShapeStyle,
|
|
183
|
+
fill: 'transparent',
|
|
184
|
+
batchKey: 'halo',
|
|
185
|
+
},
|
|
186
|
+
shapeMap,
|
|
187
|
+
model,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -11,7 +11,7 @@ export class ComboCommand implements Command {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
undo(graph: IGraph) {
|
|
14
|
-
graph.
|
|
14
|
+
graph.executeWithNoStack(() => {
|
|
15
15
|
this.action === 'expandCombo'
|
|
16
16
|
? graph.collapseCombo(this.ids)
|
|
17
17
|
: graph.expandCombo(this.ids);
|
|
@@ -19,7 +19,7 @@ export class ComboCommand implements Command {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
redo(graph: IGraph) {
|
|
22
|
-
graph.
|
|
22
|
+
graph.executeWithNoStack(() => {
|
|
23
23
|
this.action === 'collapseCombo'
|
|
24
24
|
? graph.collapseCombo(this.ids)
|
|
25
25
|
: graph.expandCombo(this.ids);
|