@antv/g6 5.0.0-beta.0 → 5.0.0-beta.1
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/item.d.ts +2 -0
- package/esm/api-doc/item.js +2 -0
- package/esm/api-doc/item.js.map +1 -1
- package/esm/runtime/controller/data.js +2 -2
- package/esm/runtime/controller/data.js.map +1 -1
- package/esm/runtime/controller/plugin.js +3 -3
- package/esm/runtime/controller/plugin.js.map +1 -1
- package/esm/stdlib/behavior/drag-canvas.js +12 -12
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/data/validateData.js +7 -2
- package/esm/stdlib/data/validateData.js.map +1 -1
- package/esm/stdlib/item/edge/base.d.ts +86 -5
- package/esm/stdlib/item/edge/base.js +72 -6
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/node/base.d.ts +89 -15
- package/esm/stdlib/item/node/base.js +73 -15
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/base3d.d.ts +23 -0
- package/esm/stdlib/item/node/base3d.js +23 -8
- package/esm/stdlib/item/node/base3d.js.map +1 -1
- package/esm/stdlib/plugin/legend/index.js +4 -2
- package/esm/stdlib/plugin/legend/index.js.map +1 -1
- package/esm/types/spec.d.ts +1 -1
- package/lib/api-doc/item.d.ts +2 -0
- package/lib/api-doc/item.js +5 -1
- package/lib/api-doc/item.js.map +1 -1
- package/lib/runtime/controller/data.js +2 -2
- package/lib/runtime/controller/data.js.map +1 -1
- package/lib/runtime/controller/plugin.js +3 -3
- package/lib/runtime/controller/plugin.js.map +1 -1
- package/lib/stdlib/behavior/drag-canvas.js +12 -12
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/data/validateData.js +7 -2
- package/lib/stdlib/data/validateData.js.map +1 -1
- package/lib/stdlib/item/edge/base.d.ts +86 -5
- package/lib/stdlib/item/edge/base.js +72 -6
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/node/base.d.ts +89 -15
- package/lib/stdlib/item/node/base.js +73 -15
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/base3d.d.ts +23 -0
- package/lib/stdlib/item/node/base3d.js +23 -8
- package/lib/stdlib/item/node/base3d.js.map +1 -1
- package/lib/stdlib/plugin/legend/index.js +4 -2
- package/lib/stdlib/plugin/legend/index.js.map +1 -1
- package/lib/types/spec.d.ts +1 -1
- package/package.json +1 -1
- package/src/api-doc/item.ts +2 -0
- package/src/runtime/controller/data.ts +2 -2
- package/src/runtime/controller/plugin.ts +15 -3
- package/src/stdlib/behavior/drag-canvas.ts +12 -12
- package/src/stdlib/data/validateData.ts +7 -2
- package/src/stdlib/item/edge/base.ts +92 -6
- package/src/stdlib/item/node/base.ts +93 -17
- package/src/stdlib/item/node/base3d.ts +23 -9
- package/src/stdlib/plugin/legend/index.ts +4 -3
- package/src/types/spec.ts +1 -1
|
@@ -97,11 +97,18 @@ export abstract class BaseNode {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
|
-
*
|
|
100
|
+
* Get merged styles from `getMergedStyles` and assigns the merged styles to the 'mergedStyles' property.
|
|
101
|
+
* @param model - The NodeDisplayModel or ComboDisplayModel to merge the styles from.
|
|
101
102
|
*/
|
|
102
103
|
public mergeStyles(model: NodeDisplayModel | ComboDisplayModel) {
|
|
103
104
|
this.mergedStyles = this.getMergedStyles(model);
|
|
104
105
|
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Merge style
|
|
109
|
+
* @param model - The NodeDisplayModel or ComboDisplayModel to retrieve the merged styles from.
|
|
110
|
+
* @returns The merged styles as a NodeShapeStyles object.
|
|
111
|
+
*/
|
|
105
112
|
public getMergedStyles(model: NodeDisplayModel | ComboDisplayModel) {
|
|
106
113
|
const { data } = model;
|
|
107
114
|
const dataStyles = {} as NodeShapeStyles | ComboShapeStyles;
|
|
@@ -151,6 +158,7 @@ export abstract class BaseNode {
|
|
|
151
158
|
}
|
|
152
159
|
/**
|
|
153
160
|
* Call it after calling draw function to update cache about bounds and zoom levels.
|
|
161
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
154
162
|
*/
|
|
155
163
|
public updateCache(shapeMap) {
|
|
156
164
|
['keyShape', 'labelShape']
|
|
@@ -188,8 +196,13 @@ export abstract class BaseNode {
|
|
|
188
196
|
}
|
|
189
197
|
}
|
|
190
198
|
/**
|
|
191
|
-
* Draw all elements related to the
|
|
199
|
+
* Draw all elements related to the node.
|
|
192
200
|
* You should call `drawKeyShape` and `drawAnchorShape`,`drawLabelShape`,`drawIconShape`...as you like.
|
|
201
|
+
* @param model The displayed model of this node, only for drawing and not received by users.
|
|
202
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
203
|
+
* @param diffData An object that contains previous and current data.
|
|
204
|
+
* @param diffState An object that contains previous and current node's state.
|
|
205
|
+
* @returns An object containing the keyShape and optional labelShape, iconShape, and some otherShapes properties
|
|
193
206
|
*/
|
|
194
207
|
abstract draw(
|
|
195
208
|
model: NodeDisplayModel | ComboDisplayModel,
|
|
@@ -206,6 +219,13 @@ export abstract class BaseNode {
|
|
|
206
219
|
[otherShapeId: string]: DisplayObject;
|
|
207
220
|
};
|
|
208
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Perform additional drawing operations or add custom shapes after drawing node.
|
|
224
|
+
* @param model The displayed model of this node, only for drawing and not received by users.
|
|
225
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
226
|
+
* @param shapesChanged An array of shape IDs that have changed and need to be updated.
|
|
227
|
+
* @returns An object that contains some new shapes to be added to the node.
|
|
228
|
+
*/
|
|
209
229
|
public afterDraw(
|
|
210
230
|
model: NodeDisplayModel | ComboDisplayModel,
|
|
211
231
|
shapeMap: { [shapeId: string]: DisplayObject },
|
|
@@ -214,6 +234,13 @@ export abstract class BaseNode {
|
|
|
214
234
|
return {};
|
|
215
235
|
}
|
|
216
236
|
// shouldUpdate: (model: NodeDisplayModel, prevModel: NodeDisplayModel) => boolean = () => true;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Set the state for the node.
|
|
240
|
+
* @param state state name
|
|
241
|
+
* @param value state value
|
|
242
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
243
|
+
*/
|
|
217
244
|
public setState: (
|
|
218
245
|
name: string,
|
|
219
246
|
value: boolean,
|
|
@@ -222,7 +249,12 @@ export abstract class BaseNode {
|
|
|
222
249
|
|
|
223
250
|
/**
|
|
224
251
|
* The key function of drawing shape.
|
|
225
|
-
*
|
|
252
|
+
* Draw the key shape of the node based on the provided model and shape map.
|
|
253
|
+
* @param model The displayed model of this node, only for drawing and not received by users.
|
|
254
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
255
|
+
* @param diffData An object that contains previous and current data.
|
|
256
|
+
* @param diffState An object that contains previous and current node's state.
|
|
257
|
+
* @returns The display object representing the key shape of the node.
|
|
226
258
|
*/
|
|
227
259
|
abstract drawKeyShape(
|
|
228
260
|
model: NodeDisplayModel | ComboDisplayModel,
|
|
@@ -235,7 +267,12 @@ export abstract class BaseNode {
|
|
|
235
267
|
): DisplayObject;
|
|
236
268
|
|
|
237
269
|
/**
|
|
238
|
-
* Draw the label of the node
|
|
270
|
+
* Draw the label shape of the node
|
|
271
|
+
* @param model The displayed model of this node, only for drawing and not received by users.
|
|
272
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
273
|
+
* @param diffData An object that contains previous and current data.
|
|
274
|
+
* @param diffState An object that contains previous and current node's state.
|
|
275
|
+
* @returns The display object representing the label shape of the node.
|
|
239
276
|
*/
|
|
240
277
|
public drawLabelShape(
|
|
241
278
|
model: NodeDisplayModel | ComboDisplayModel,
|
|
@@ -247,7 +284,7 @@ export abstract class BaseNode {
|
|
|
247
284
|
diffState?: { previous: State[]; current: State[] },
|
|
248
285
|
): DisplayObject {
|
|
249
286
|
const { labelShape: shapeStyle } = this.mergedStyles;
|
|
250
|
-
if (!shapeStyle) return;
|
|
287
|
+
if (!shapeStyle || !shapeStyle.text || !model.data.labelShape) return;
|
|
251
288
|
const { keyShape } = shapeMap;
|
|
252
289
|
this.boundsCache.keyShapeLocal =
|
|
253
290
|
this.boundsCache.keyShapeLocal || keyShape.getLocalBounds();
|
|
@@ -338,7 +375,12 @@ export abstract class BaseNode {
|
|
|
338
375
|
}
|
|
339
376
|
|
|
340
377
|
/**
|
|
341
|
-
* Draw the label background of the node
|
|
378
|
+
* Draw the label background shape of the node
|
|
379
|
+
* @param model The displayed model of this node, only for drawing and not received by users.
|
|
380
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
381
|
+
* @param diffData An object that contains previous and current data.
|
|
382
|
+
* @param diffState An object that contains previous and current node's state.
|
|
383
|
+
* @returns The display object representing the label background shape of the node.
|
|
342
384
|
*/
|
|
343
385
|
public drawLabelBackgroundShape(
|
|
344
386
|
model: NodeDisplayModel | ComboDisplayModel,
|
|
@@ -350,7 +392,7 @@ export abstract class BaseNode {
|
|
|
350
392
|
diffState?: { oldState: State[]; newState: State[] },
|
|
351
393
|
): DisplayObject {
|
|
352
394
|
const { labelShape } = shapeMap;
|
|
353
|
-
if (!labelShape || !model.data.labelShape) return;
|
|
395
|
+
if (!labelShape || !labelShape.style.text || !model.data.labelShape) return;
|
|
354
396
|
if (
|
|
355
397
|
!this.boundsCache.labelShapeGeometry ||
|
|
356
398
|
labelShape.getAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY)
|
|
@@ -390,7 +432,12 @@ export abstract class BaseNode {
|
|
|
390
432
|
}
|
|
391
433
|
|
|
392
434
|
/**
|
|
393
|
-
* Draw the icon of the node
|
|
435
|
+
* Draw the icon shape of the node
|
|
436
|
+
* @param model The displayed model of this node, only for drawing and not received by users.
|
|
437
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
438
|
+
* @param diffData An object that contains previous and current data.
|
|
439
|
+
* @param diffState An object that contains previous and current node's state.
|
|
440
|
+
* @returns The display object representing the icon shape of the node.
|
|
394
441
|
*/
|
|
395
442
|
public drawIconShape(
|
|
396
443
|
model: NodeDisplayModel | ComboDisplayModel,
|
|
@@ -436,7 +483,12 @@ export abstract class BaseNode {
|
|
|
436
483
|
}
|
|
437
484
|
|
|
438
485
|
/**
|
|
439
|
-
* Draw the halo of the node
|
|
486
|
+
* Draw the halo shape of the node
|
|
487
|
+
* @param model The displayed model of this node, only for drawing and not received by users.
|
|
488
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
489
|
+
* @param diffData An object that contains previous and current data.
|
|
490
|
+
* @param diffState An object that contains previous and current node's state.
|
|
491
|
+
* @returns The display object representing the halo shape of the node.
|
|
440
492
|
*/
|
|
441
493
|
public drawHaloShape(
|
|
442
494
|
model: NodeDisplayModel | ComboDisplayModel,
|
|
@@ -471,7 +523,12 @@ export abstract class BaseNode {
|
|
|
471
523
|
}
|
|
472
524
|
|
|
473
525
|
/**
|
|
474
|
-
* Draw the anchors of the node
|
|
526
|
+
* Draw the anchors shape of the node
|
|
527
|
+
* @param model The displayed model of this node, only for drawing and not received by users.
|
|
528
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
529
|
+
* @param diffData An object that contains previous and current data.
|
|
530
|
+
* @param diffState An object that contains previous and current node's state.
|
|
531
|
+
* @returns The display object representing the anchors shape of the node.
|
|
475
532
|
*/
|
|
476
533
|
public drawAnchorShapes(
|
|
477
534
|
model: NodeDisplayModel | ComboDisplayModel,
|
|
@@ -546,10 +603,10 @@ export abstract class BaseNode {
|
|
|
546
603
|
}
|
|
547
604
|
|
|
548
605
|
/**
|
|
549
|
-
*
|
|
550
|
-
* e.g CircleNode `
|
|
551
|
-
* @param
|
|
552
|
-
* @
|
|
606
|
+
* Configures the anchor positions based on the provided keyShapeStyle and returns the configuration.
|
|
607
|
+
* e.g for a CircleNode, it returns: `{"right":keyShapeStyle.x+keyShapeStyle.r, keyShapeStyle.y}`
|
|
608
|
+
* @param keyShapeStyle - The keyShapeStyle object that contains the style information of the key shape.
|
|
609
|
+
* @returns The anchor position configuration as an IAnchorPositionMap object.
|
|
553
610
|
*/
|
|
554
611
|
public calculateAnchorPosition(keyShapeStyle: any): IAnchorPositionMap {
|
|
555
612
|
const x = convertToNumber(keyShapeStyle.x);
|
|
@@ -564,7 +621,12 @@ export abstract class BaseNode {
|
|
|
564
621
|
}
|
|
565
622
|
|
|
566
623
|
/**
|
|
567
|
-
* Draw the badges of the node
|
|
624
|
+
* Draw the badges shape of the node
|
|
625
|
+
* @param model The displayed model of this node, only for drawing and not received by users.
|
|
626
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
627
|
+
* @param diffData An object that contains previous and current data.
|
|
628
|
+
* @param diffState An object that contains previous and current node's state.
|
|
629
|
+
* @returns The display object representing the badges shape of the node.
|
|
568
630
|
*/
|
|
569
631
|
public drawBadgeShapes(
|
|
570
632
|
model: NodeDisplayModel | ComboDisplayModel,
|
|
@@ -723,6 +785,11 @@ export abstract class BaseNode {
|
|
|
723
785
|
|
|
724
786
|
/**
|
|
725
787
|
* Draw other shapes(such as preRect,stateIcon) of the node
|
|
788
|
+
* @param model The displayed model of this node, only for drawing and not received by users.
|
|
789
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
790
|
+
* @param diffData An object that contains previous and current data.
|
|
791
|
+
* @param diffState An object that contains previous and current node's state.
|
|
792
|
+
* @returns The display object representing the other shapes of the node.
|
|
726
793
|
*/
|
|
727
794
|
public drawOtherShapes(
|
|
728
795
|
model: NodeDisplayModel | ComboDisplayModel,
|
|
@@ -740,8 +807,8 @@ export abstract class BaseNode {
|
|
|
740
807
|
* The listener for graph zooming.
|
|
741
808
|
* 1. show / hide some shapes while zoom level changed;
|
|
742
809
|
* 2. change the shapes' sizes to make them have same visual size while zooming, e.g. labelShape, labelBackgroundShape.
|
|
743
|
-
* @param shapeMap
|
|
744
|
-
* @param zoom
|
|
810
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
811
|
+
* @param zoom The zoom level of the graph.
|
|
745
812
|
*/
|
|
746
813
|
public onZoom = (shapeMap: NodeShapeMap | ComboShapeMap, zoom: number) => {
|
|
747
814
|
// zoomLevel changed
|
|
@@ -907,6 +974,15 @@ export abstract class BaseNode {
|
|
|
907
974
|
labelBackgroundShape.style.transform = `scale(${xAxistRatio}, ${balanceRatio})`;
|
|
908
975
|
}
|
|
909
976
|
|
|
977
|
+
/**
|
|
978
|
+
* Create (if does not exit in shapeMap) or update the shape according to the configurations.
|
|
979
|
+
* @param type shape's type
|
|
980
|
+
* @param id unique string to indicates the shape
|
|
981
|
+
* @param style style to be updated
|
|
982
|
+
* @param shapeMap the shape map of a node / combo
|
|
983
|
+
* @param model data model of the node / combo
|
|
984
|
+
* @returns The display object representing the shape.
|
|
985
|
+
*/
|
|
910
986
|
public upsertShape(
|
|
911
987
|
type: SHAPE_TYPE | SHAPE_TYPE_3D,
|
|
912
988
|
id: string,
|
|
@@ -26,7 +26,14 @@ export abstract class BaseNode3D extends BaseNode {
|
|
|
26
26
|
this.device = props.device;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Draw the label shape of the 3D node
|
|
31
|
+
* @param model The displayed model of this 3D node, only for drawing and not received by users.
|
|
32
|
+
* @param shapeMap The shape map that contains all of the elements to show on the 3D node.
|
|
33
|
+
* @param diffData An object that contains previous and current data.
|
|
34
|
+
* @param diffState An object that contains previous and current 3D node's state.
|
|
35
|
+
* @returns The display object representing the label shape of the 3D node.
|
|
36
|
+
*/
|
|
30
37
|
public drawLabelShape(
|
|
31
38
|
model: NodeDisplayModel,
|
|
32
39
|
shapeMap: NodeShapeMap,
|
|
@@ -49,13 +56,6 @@ export abstract class BaseNode3D extends BaseNode {
|
|
|
49
56
|
...otherStyle
|
|
50
57
|
} = shapeStyle;
|
|
51
58
|
|
|
52
|
-
// TODO
|
|
53
|
-
// const wordWrapWidth = getWordWrapWidthByBox(
|
|
54
|
-
// keyShapeBox,
|
|
55
|
-
// maxWidth,
|
|
56
|
-
// this.zoomCache.zoom,
|
|
57
|
-
// );
|
|
58
|
-
|
|
59
59
|
const positionPreset = {
|
|
60
60
|
x: keyShapeBox.center[0],
|
|
61
61
|
y: keyShapeBox.max[1],
|
|
@@ -109,7 +109,14 @@ export abstract class BaseNode3D extends BaseNode {
|
|
|
109
109
|
return this.upsertShape('text', 'labelShape', style, shapeMap);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Draw the icon shape of the 3D node
|
|
114
|
+
* @param model The displayed model of this 3D node, only for drawing and not received by users.
|
|
115
|
+
* @param shapeMap The shape map that contains all of the elements to show on the 3D node.
|
|
116
|
+
* @param diffData An object that contains previous and current data.
|
|
117
|
+
* @param diffState An object that contains previous and current 3D node's state.
|
|
118
|
+
* @returns The display object representing the icon shape of the 3D node.
|
|
119
|
+
*/
|
|
113
120
|
public drawIconShape(
|
|
114
121
|
model: NodeDisplayModel,
|
|
115
122
|
shapeMap: NodeShapeMap,
|
|
@@ -192,5 +199,12 @@ export abstract class BaseNode3D extends BaseNode {
|
|
|
192
199
|
return upsertShape3D(type, id, style as GShapeStyle, shapeMap, this.device);
|
|
193
200
|
}
|
|
194
201
|
|
|
202
|
+
/**
|
|
203
|
+
* The listener for graph zooming.
|
|
204
|
+
* 1. show / hide some shapes while zoom level changed;
|
|
205
|
+
* 2. change the shapes' sizes to make them have same visual size while zooming, e.g. labelShape, labelBackgroundShape.
|
|
206
|
+
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
207
|
+
* @param zoom The zoom level of the graph.
|
|
208
|
+
*/
|
|
195
209
|
public onZoom = (shapeMap: NodeShapeMap, zoom: number) => {};
|
|
196
210
|
}
|
|
@@ -574,9 +574,10 @@ export class Legend extends Base {
|
|
|
574
574
|
firstItem.legend.childNodes[1].childNodes[0]
|
|
575
575
|
.childNodes[0] as DisplayObject
|
|
576
576
|
).getRenderBounds();
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
577
|
+
if (firstItemBounds) {
|
|
578
|
+
const firstBottom = firstItemBounds.max[1] + firstItem.padding[2];
|
|
579
|
+
secondItem.legend.translateLocal([0, firstBottom]);
|
|
580
|
+
}
|
|
580
581
|
} else {
|
|
581
582
|
firstItem.legend.translateLocal([
|
|
582
583
|
-bbox.min[0] + firstItem.padding[3],
|