@antv/g6 5.0.0-beta.0 → 5.0.0-beta.2

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.
Files changed (153) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/api-doc/item.d.ts +2 -0
  3. package/esm/api-doc/item.js +2 -0
  4. package/esm/api-doc/item.js.map +1 -1
  5. package/esm/constant/shape.d.ts +2 -1
  6. package/esm/constant/shape.js.map +1 -1
  7. package/esm/index.d.ts +5 -1
  8. package/esm/index.js +3 -2
  9. package/esm/index.js.map +1 -1
  10. package/esm/item/edge.d.ts +1 -1
  11. package/esm/item/edge.js.map +1 -1
  12. package/esm/runtime/controller/data.js +3 -3
  13. package/esm/runtime/controller/data.js.map +1 -1
  14. package/esm/runtime/controller/plugin.js +3 -3
  15. package/esm/runtime/controller/plugin.js.map +1 -1
  16. package/esm/stdlib/behavior/activate-relations.d.ts +9 -9
  17. package/esm/stdlib/behavior/activate-relations.js +6 -6
  18. package/esm/stdlib/behavior/activate-relations.js.map +1 -1
  19. package/esm/stdlib/behavior/drag-canvas.js +12 -12
  20. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  21. package/esm/stdlib/data/validateData.js +7 -2
  22. package/esm/stdlib/data/validateData.js.map +1 -1
  23. package/esm/stdlib/index.d.ts +3 -0
  24. package/esm/stdlib/index.js +4 -1
  25. package/esm/stdlib/index.js.map +1 -1
  26. package/esm/stdlib/item/edge/base.d.ts +95 -5
  27. package/esm/stdlib/item/edge/base.js +75 -6
  28. package/esm/stdlib/item/edge/base.js.map +1 -1
  29. package/esm/stdlib/item/edge/line.js +5 -2
  30. package/esm/stdlib/item/edge/line.js.map +1 -1
  31. package/esm/stdlib/item/edge/polyline.d.ts +3 -2
  32. package/esm/stdlib/item/edge/polyline.js +3 -3
  33. package/esm/stdlib/item/edge/polyline.js.map +1 -1
  34. package/esm/stdlib/item/node/base.d.ts +89 -15
  35. package/esm/stdlib/item/node/base.js +73 -15
  36. package/esm/stdlib/item/node/base.js.map +1 -1
  37. package/esm/stdlib/item/node/base3d.d.ts +23 -0
  38. package/esm/stdlib/item/node/base3d.js +23 -8
  39. package/esm/stdlib/item/node/base3d.js.map +1 -1
  40. package/esm/stdlib/item/node/hexagon.js +6 -3
  41. package/esm/stdlib/item/node/hexagon.js.map +1 -1
  42. package/esm/stdlib/plugin/index.d.ts +1 -0
  43. package/esm/stdlib/plugin/index.js +1 -0
  44. package/esm/stdlib/plugin/index.js.map +1 -1
  45. package/esm/stdlib/plugin/legend/index.js +5 -3
  46. package/esm/stdlib/plugin/legend/index.js.map +1 -1
  47. package/esm/stdlib/plugin/timebar/index.d.ts +98 -0
  48. package/esm/stdlib/plugin/timebar/index.js +303 -0
  49. package/esm/stdlib/plugin/timebar/index.js.map +1 -0
  50. package/esm/stdlib/plugin/toolbar/index.js +1 -1
  51. package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
  52. package/esm/stdlib/plugin/types.d.ts +1 -0
  53. package/esm/types/common.d.ts +1 -0
  54. package/esm/types/spec.d.ts +1 -1
  55. package/esm/util/canvas.d.ts +2 -2
  56. package/esm/util/canvas.js +5 -11
  57. package/esm/util/canvas.js.map +1 -1
  58. package/esm/util/router.d.ts +4 -3
  59. package/esm/util/router.js +8 -5
  60. package/esm/util/router.js.map +1 -1
  61. package/esm/util/shape.d.ts +2 -2
  62. package/esm/util/shape.js +3 -3
  63. package/esm/util/shape.js.map +1 -1
  64. package/lib/api-doc/item.d.ts +2 -0
  65. package/lib/api-doc/item.js +5 -1
  66. package/lib/api-doc/item.js.map +1 -1
  67. package/lib/constant/shape.d.ts +2 -1
  68. package/lib/constant/shape.js.map +1 -1
  69. package/lib/index.d.ts +5 -1
  70. package/lib/index.js +4 -2
  71. package/lib/index.js.map +1 -1
  72. package/lib/item/edge.d.ts +1 -1
  73. package/lib/item/edge.js.map +1 -1
  74. package/lib/runtime/controller/data.js +3 -3
  75. package/lib/runtime/controller/data.js.map +1 -1
  76. package/lib/runtime/controller/plugin.js +3 -3
  77. package/lib/runtime/controller/plugin.js.map +1 -1
  78. package/lib/stdlib/behavior/activate-relations.d.ts +9 -9
  79. package/lib/stdlib/behavior/activate-relations.js +6 -6
  80. package/lib/stdlib/behavior/activate-relations.js.map +1 -1
  81. package/lib/stdlib/behavior/drag-canvas.js +12 -12
  82. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  83. package/lib/stdlib/data/validateData.js +7 -2
  84. package/lib/stdlib/data/validateData.js.map +1 -1
  85. package/lib/stdlib/index.d.ts +3 -0
  86. package/lib/stdlib/index.js +4 -1
  87. package/lib/stdlib/index.js.map +1 -1
  88. package/lib/stdlib/item/edge/base.d.ts +95 -5
  89. package/lib/stdlib/item/edge/base.js +75 -6
  90. package/lib/stdlib/item/edge/base.js.map +1 -1
  91. package/lib/stdlib/item/edge/line.js +5 -2
  92. package/lib/stdlib/item/edge/line.js.map +1 -1
  93. package/lib/stdlib/item/edge/polyline.d.ts +3 -2
  94. package/lib/stdlib/item/edge/polyline.js +3 -3
  95. package/lib/stdlib/item/edge/polyline.js.map +1 -1
  96. package/lib/stdlib/item/node/base.d.ts +89 -15
  97. package/lib/stdlib/item/node/base.js +73 -15
  98. package/lib/stdlib/item/node/base.js.map +1 -1
  99. package/lib/stdlib/item/node/base3d.d.ts +23 -0
  100. package/lib/stdlib/item/node/base3d.js +23 -8
  101. package/lib/stdlib/item/node/base3d.js.map +1 -1
  102. package/lib/stdlib/item/node/hexagon.js +6 -3
  103. package/lib/stdlib/item/node/hexagon.js.map +1 -1
  104. package/lib/stdlib/plugin/index.d.ts +1 -0
  105. package/lib/stdlib/plugin/index.js +1 -0
  106. package/lib/stdlib/plugin/index.js.map +1 -1
  107. package/lib/stdlib/plugin/legend/index.js +5 -3
  108. package/lib/stdlib/plugin/legend/index.js.map +1 -1
  109. package/lib/stdlib/plugin/timebar/index.d.ts +98 -0
  110. package/lib/stdlib/plugin/timebar/index.js +307 -0
  111. package/lib/stdlib/plugin/timebar/index.js.map +1 -0
  112. package/lib/stdlib/plugin/toolbar/index.js +1 -1
  113. package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
  114. package/lib/stdlib/plugin/types.d.ts +1 -0
  115. package/lib/types/common.d.ts +1 -0
  116. package/lib/types/spec.d.ts +1 -1
  117. package/lib/util/canvas.d.ts +2 -2
  118. package/lib/util/canvas.js +5 -11
  119. package/lib/util/canvas.js.map +1 -1
  120. package/lib/util/router.d.ts +4 -3
  121. package/lib/util/router.js +8 -5
  122. package/lib/util/router.js.map +1 -1
  123. package/lib/util/shape.d.ts +2 -2
  124. package/lib/util/shape.js +3 -3
  125. package/lib/util/shape.js.map +1 -1
  126. package/package.json +9 -7
  127. package/src/api-doc/item.ts +2 -0
  128. package/src/constant/shape.ts +2 -1
  129. package/src/index.ts +4 -2
  130. package/src/item/edge.ts +1 -1
  131. package/src/runtime/controller/data.ts +3 -3
  132. package/src/runtime/controller/plugin.ts +15 -3
  133. package/src/stdlib/behavior/activate-relations.ts +6 -6
  134. package/src/stdlib/behavior/drag-canvas.ts +12 -12
  135. package/src/stdlib/data/validateData.ts +7 -2
  136. package/src/stdlib/index.ts +14 -2
  137. package/src/stdlib/item/edge/base.ts +101 -6
  138. package/src/stdlib/item/edge/line.ts +8 -2
  139. package/src/stdlib/item/edge/polyline.ts +7 -5
  140. package/src/stdlib/item/node/base.ts +93 -17
  141. package/src/stdlib/item/node/base3d.ts +23 -9
  142. package/src/stdlib/item/node/hexagon.ts +8 -4
  143. package/src/stdlib/plugin/index.ts +1 -0
  144. package/src/stdlib/plugin/legend/index.ts +5 -4
  145. package/src/stdlib/plugin/timebar/index.ts +473 -0
  146. package/src/stdlib/plugin/toolbar/index.ts +1 -1
  147. package/src/stdlib/plugin/types.ts +1 -0
  148. package/src/types/common.ts +1 -0
  149. package/src/types/spec.ts +1 -1
  150. package/src/util/canvas.ts +5 -5
  151. package/src/util/router.ts +15 -6
  152. package/src/util/shape.ts +8 -5
  153. package/src/api-doc/readme.md +0 -59
@@ -97,9 +97,20 @@ export abstract class BaseEdge {
97
97
  ...lodStrategy?.animateCfg,
98
98
  };
99
99
  }
100
+
101
+ /**
102
+ * Get merged styles from `getMergedStyles` and assigns the merged styles to the 'mergedStyles' property.
103
+ * @param model - The EdgeDisplayModel to merge the styles from.
104
+ */
100
105
  public mergeStyles(model: EdgeDisplayModel) {
101
106
  this.mergedStyles = this.getMergedStyles(model);
102
107
  }
108
+
109
+ /**
110
+ * Merge style
111
+ * @param model - The EdgeDisplayModel to retrieve the merged styles from.
112
+ * @returns The merged styles as a EdgeShapeStyles object.
113
+ */
103
114
  public getMergedStyles(model: EdgeDisplayModel) {
104
115
  const { data } = model;
105
116
  const dataStyles = {} as EdgeShapeStyles;
@@ -131,6 +142,7 @@ export abstract class BaseEdge {
131
142
 
132
143
  /**
133
144
  * Call it after calling draw function to update cache about bounds and zoom levels.
145
+ * @param shapeMap The shape map that contains all of the elements to show on the edge.
134
146
  */
135
147
  public updateCache(shapeMap) {
136
148
  ['labelShape', 'labelBackgroundShape'].forEach((id) => {
@@ -165,6 +177,15 @@ export abstract class BaseEdge {
165
177
  if (zoom !== 1) this.onZoom(shapeMap, zoom);
166
178
  }
167
179
 
180
+ /**
181
+ * Draw all elements related to the edge.
182
+ * You should call `drawKeyShape` and `drawAnchorShape`,`drawLabelShape`,`drawIconShape`...as you like.
183
+ * @param model The displayed model of this edge, only for drawing and not received by users.
184
+ * @param shapeMap The shape map that contains all of the elements to show on the edge.
185
+ * @param diffData An object that contains previous and current data.
186
+ * @param diffState An object that contains previous and current edge's state.
187
+ * @returns An object containing the keyShape and optional labelShape, iconShape, and some otherShapes properties
188
+ */
168
189
  abstract draw(
169
190
  model: EdgeDisplayModel,
170
191
  sourcePoint: Point,
@@ -178,6 +199,14 @@ export abstract class BaseEdge {
178
199
  iconShape?: DisplayObject;
179
200
  [otherShapeId: string]: DisplayObject;
180
201
  };
202
+
203
+ /**
204
+ * Perform additional drawing operations or add custom shapes after drawing edge.
205
+ * @param model The displayed model of this edge, only for drawing and not received by users.
206
+ * @param shapeMap The shape map that contains all of the elements to show on the edge.
207
+ * @param shapesChanged An array of shape IDs that have changed and need to be updated.
208
+ * @returns An object that contains some new shapes to be added to the edge.
209
+ */
181
210
  public afterDraw(
182
211
  model: EdgeDisplayModel,
183
212
  shapeMap: { [shapeId: string]: DisplayObject },
@@ -186,12 +215,27 @@ export abstract class BaseEdge {
186
215
  return {};
187
216
  }
188
217
  // shouldUpdate: (model: EdgeDisplayModel, prevModel: EdgeDisplayModel) => boolean = () => true;
218
+
219
+ /**
220
+ * Set the state for the edge.
221
+ * @param state state name
222
+ * @param value state value
223
+ * @param shapeMap The shape map that contains all of the elements to show on the edge.
224
+ */
189
225
  public setState: (
190
226
  name: string,
191
227
  value: boolean,
192
228
  shapeMap: { [shapeId: string]: DisplayObject },
193
229
  ) => void;
194
230
 
231
+ /**
232
+ * Draw the label shape of the edge
233
+ * @param model The displayed model of this edge, only for drawing and not received by users.
234
+ * @param shapeMap The shape map that contains all of the elements to show on the edge.
235
+ * @param diffData An object that contains previous and current data.
236
+ * @param diffState An object that contains previous and current edge's state.
237
+ * @returns The display object representing the label shape of the edge.
238
+ */
195
239
  public drawLabelShape(
196
240
  model: EdgeDisplayModel,
197
241
  shapeMap: EdgeShapeMap,
@@ -201,7 +245,8 @@ export abstract class BaseEdge {
201
245
  const { keyShape } = shapeMap;
202
246
 
203
247
  const { labelShape: shapeStyle } = this.mergedStyles;
204
- if (!shapeStyle) return;
248
+ if (!shapeStyle || !shapeStyle.text || !model.data.labelShape) return;
249
+
205
250
  const {
206
251
  position,
207
252
  offsetX: propsOffsetX,
@@ -297,6 +342,14 @@ export abstract class BaseEdge {
297
342
  return this.upsertShape('text', 'labelShape', style, shapeMap, model);
298
343
  }
299
344
 
345
+ /**
346
+ * Draw the label background shape of the edge
347
+ * @param model The displayed model of this edge, only for drawing and not received by users.
348
+ * @param shapeMap The shape map that contains all of the elements to show on the edge.
349
+ * @param diffData An object that contains previous and current data.
350
+ * @param diffState An object that contains previous and current edge's state.
351
+ * @returns The display object representing the label background shape of the edge.
352
+ */
300
353
  public drawLabelBackgroundShape(
301
354
  model: EdgeDisplayModel,
302
355
  shapeMap: EdgeShapeMap,
@@ -356,6 +409,14 @@ export abstract class BaseEdge {
356
409
  );
357
410
  }
358
411
 
412
+ /**
413
+ * Draw the icon shape of the edge
414
+ * @param model The displayed model of this edge, only for drawing and not received by users.
415
+ * @param shapeMap The shape map that contains all of the elements to show on the edge.
416
+ * @param diffData An object that contains previous and current data.
417
+ * @param diffState An object that contains previous and current edge's state.
418
+ * @returns The display object representing the icon shape of the edge.
419
+ */
359
420
  public drawIconShape(
360
421
  model: EdgeDisplayModel,
361
422
  shapeMap: EdgeShapeMap,
@@ -442,6 +503,14 @@ export abstract class BaseEdge {
442
503
  );
443
504
  }
444
505
 
506
+ /**
507
+ * Draw the halo shape of the edge
508
+ * @param model The displayed model of this edge, only for drawing and not received by users.
509
+ * @param shapeMap The shape map that contains all of the elements to show on the edge.
510
+ * @param diffData An object that contains previous and current data.
511
+ * @param diffState An object that contains previous and current edge's state.
512
+ * @returns The display object representing the halo shape of the edge.
513
+ */
445
514
  public drawHaloShape(
446
515
  model: EdgeDisplayModel,
447
516
  shapeMap: EdgeShapeMap,
@@ -465,12 +534,21 @@ export abstract class BaseEdge {
465
534
  );
466
535
  }
467
536
 
537
+ public drawOtherShapes(
538
+ model: EdgeDisplayModel,
539
+ shapeMap: EdgeShapeMap,
540
+ diffData?: { previous: EdgeModelData; current: EdgeModelData },
541
+ diffState?: { previous: State[]; current: State[] },
542
+ ): { [id: string]: DisplayObject } {
543
+ return {};
544
+ }
545
+
468
546
  /**
469
547
  * The listener for graph zooming.
470
548
  * 1. show / hide some shapes while zoom level changed;
471
549
  * 2. change the shapes' sizes to make them have same visual size while zooming, e.g. labelShape, labelBackgroundShape.
472
- * @param shapeMap
473
- * @param zoom
550
+ * @param shapeMap The shape map that contains all of the elements to show on the edge.
551
+ * @param zoom The zoom level of the graph.
474
552
  */
475
553
  public onZoom = (shapeMap: EdgeShapeMap, zoom: number) => {
476
554
  // balance the size for label, badges
@@ -557,7 +635,7 @@ export abstract class BaseEdge {
557
635
 
558
636
  /**
559
637
  * Update the source point { x, y } for the edge. Called in item's draw func.
560
- * @param point
638
+ * @param point source point
561
639
  */
562
640
  public setSourcePoint(point: Point) {
563
641
  this.sourcePoint = point;
@@ -565,7 +643,7 @@ export abstract class BaseEdge {
565
643
 
566
644
  /**
567
645
  * Update the target point { x, y } for the edge. Called in item's draw func.
568
- * @param point
646
+ * @param point target point
569
647
  */
570
648
  public setTargetPoint(point: Point) {
571
649
  this.targetPoint = point;
@@ -573,12 +651,20 @@ export abstract class BaseEdge {
573
651
 
574
652
  /**
575
653
  * Update all visible nodes on the canvas to be aware of obstacles. Called in item's draw func.
576
- * @param nodeMap
654
+ * @param nodeMap The Map object representing the node map, where keys are node IDs and values are nodes.
577
655
  */
578
656
  public setNodeMap(nodeMap: Map<ID, Node>) {
579
657
  this.nodeMap = nodeMap;
580
658
  }
581
659
 
660
+ /**
661
+ * Adds or updates an arrow marker on the specified position of an edge.
662
+ * @param position - The position where the arrow marker should be added or updated. Can be either 'start' or 'end'.
663
+ * @param arrowConfig - The configuration for the arrow marker. Can be a boolean indicating whether to use the default arrow configuration, or an ArrowStyle object with custom arrow properties.
664
+ * @param bodyStyle - The style of the edge body.
665
+ * @param model - The EdgeDisplayModel that contains the data and style information for the edge.
666
+ * @param resultStyle - The style object where the arrow marker properties will be added or updated.
667
+ */
582
668
  public upsertArrow(
583
669
  position: 'start' | 'end',
584
670
  arrowConfig: boolean | ArrowStyle,
@@ -624,6 +710,15 @@ export abstract class BaseEdge {
624
710
  resultStyle[`${markerField}Offset`] = width / 2 + offset;
625
711
  }
626
712
 
713
+ /**
714
+ * Create (if does not exit in shapeMap) or update the shape according to the configurations.
715
+ * @param type shape's type
716
+ * @param id unique string to indicates the shape
717
+ * @param style style to be updated
718
+ * @param shapeMap the shape map of a edge
719
+ * @param model data model of the edge
720
+ * @returns The display object representing the shape.
721
+ */
627
722
  public upsertShape(
628
723
  type: SHAPE_TYPE,
629
724
  id: string,
@@ -35,7 +35,7 @@ export class LineEdge extends BaseEdge {
35
35
  ): EdgeShapeMap {
36
36
  const { data = {} } = model;
37
37
 
38
- const shapes: EdgeShapeMap = { keyShape: undefined };
38
+ let shapes: EdgeShapeMap = { keyShape: undefined };
39
39
 
40
40
  shapes.keyShape = this.drawKeyShape(
41
41
  model,
@@ -66,7 +66,13 @@ export class LineEdge extends BaseEdge {
66
66
  shapes.iconShape = this.drawIconShape(model, shapeMap, diffData);
67
67
  }
68
68
 
69
- // TODO: other shapes
69
+ // otherShapes
70
+ if (data.otherShapes) {
71
+ shapes = {
72
+ ...shapes,
73
+ ...this.drawOtherShapes(model, shapeMap, diffData),
74
+ };
75
+ }
70
76
 
71
77
  return shapes;
72
78
  }
@@ -8,7 +8,7 @@ import {
8
8
  } from '../../../types/edge';
9
9
  import { State } from '../../../types/item';
10
10
  import { getPolylinePath } from '../../../util/polyline';
11
- import { pathFinder } from '../../../util/router';
11
+ import { RouterCfg, pathFinder } from '../../../util/router';
12
12
  import Node from '../../../item/node';
13
13
  import { LineEdge } from './line';
14
14
  export class PolylineEdge extends LineEdge {
@@ -74,7 +74,7 @@ export class PolylineEdge extends LineEdge {
74
74
 
75
75
  return shapes;
76
76
  }
77
- private getControlPoints(
77
+ public getControlPoints(
78
78
  model: EdgeDisplayModel,
79
79
  sourcePoint: Point,
80
80
  targetPoint: Point,
@@ -95,16 +95,18 @@ export class PolylineEdge extends LineEdge {
95
95
  model: EdgeDisplayModel,
96
96
  points: Point[],
97
97
  radius: number,
98
- routeCfg?: Record<string, any>,
98
+ routeCfg?: RouterCfg,
99
99
  auto?: boolean,
100
100
  ): string {
101
101
  const { id: edgeId, source: sourceNodeId, target: targetNodeId } = model;
102
102
 
103
103
  // Draw a polyline with control points
104
- if (!auto) return getPolylinePath(edgeId, points, radius);
104
+ if (!auto && routeCfg.name !== 'er')
105
+ return getPolylinePath(edgeId, points, radius);
105
106
 
106
107
  // Find the shortest path computed by A* routing algorithm
107
108
  const polylinePoints = pathFinder(
109
+ points,
108
110
  sourceNodeId,
109
111
  targetNodeId,
110
112
  this.nodeMap as unknown as Map<ID, Node>,
@@ -136,7 +138,7 @@ export class PolylineEdge extends LineEdge {
136
138
 
137
139
  const routeCfg = mix(
138
140
  {},
139
- { offset: keyShapeStyle.offset },
141
+ { offset: keyShapeStyle.offset, name: 'orth' },
140
142
  keyShapeStyle.routeCfg,
141
143
  );
142
144
 
@@ -97,11 +97,18 @@ export abstract class BaseNode {
97
97
  }
98
98
 
99
99
  /**
100
- * Merge default style with the style Customized by users
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 graphic.
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
- * Defined the basic shape of the node.
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
- * Configure anchor position by keyShapeStyle. return the configuration.
550
- * e.g CircleNode `return {"right":keyShapeStyle.x+keyShapeStyle.r, keyShapeStyle.y}`
551
- * @param {*} keyShapeStyle
552
- * @return {IAnchorPositionMap} anchorpositionMap
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
- // TODO: 3d text - billboard 2d shape
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
- // TODO: 3d icon? - billboard image or text for alpha
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
  }
@@ -9,6 +9,11 @@ import {
9
9
  } from '../../../types/node';
10
10
  import { BaseNode } from './base';
11
11
 
12
+ const offsetAngleMap = {
13
+ horizontal: 0,
14
+ vertical: Math.PI / 2,
15
+ };
16
+
12
17
  export class HexagonNode extends BaseNode {
13
18
  override defaultStyles = {
14
19
  keyShape: {
@@ -119,9 +124,9 @@ export class HexagonNode extends BaseNode {
119
124
  private getHexagonPoints(r: number, direction: string): [number, number][] {
120
125
  const angleIncrement = Math.PI / 3; //The angle increment between vertex.
121
126
  const v = [];
122
- const offsetAngle = direction === 'horizontal' ? 0 : Math.PI / 2;
127
+
123
128
  for (let i = 0; i < 6; i++) {
124
- const angle = i * angleIncrement + offsetAngle;
129
+ const angle = i * angleIncrement + offsetAngleMap[direction];
125
130
  const vx = r * Math.cos(angle);
126
131
  const vy = r * Math.sin(angle);
127
132
  v.push([vx, vy]);
@@ -153,8 +158,7 @@ export class HexagonNode extends BaseNode {
153
158
  ? anchorPositionHorizontal
154
159
  : anchorPositionVertical;
155
160
  const angleIncrement = Math.PI / 3; //The angle increment between vertex.
156
- const offsetAngle =
157
- keyShapeStyle.direction === 'horizontal' ? 0 : Math.PI / 2;
161
+ const offsetAngle = offsetAngleMap[keyShapeStyle.direction];
158
162
  const r = keyShapeStyle.r;
159
163
  const anchorPositionMap = {};
160
164
  for (let i = 0; i < 6; i++) {
@@ -6,3 +6,4 @@ export * from './menu';
6
6
  export * from './minimap';
7
7
  export * from './toolbar';
8
8
  export * from './tooltip';
9
+ export * from './timebar';
@@ -235,7 +235,7 @@ export class Legend extends Base {
235
235
  canvasSize[0],
236
236
  canvasSize[1],
237
237
  undefined,
238
- background,
238
+ { background },
239
239
  );
240
240
  }
241
241
 
@@ -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
- const firstBottom = firstItemBounds.max[1] + firstItem.padding[2];
578
-
579
- secondItem.legend.translateLocal([0, firstBottom]);
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],