@antv/g6 5.0.0-beta.7 → 5.0.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/g6.min.js +1 -1
  2. package/esm/index.d.ts +1 -1
  3. package/esm/index.js +1 -1
  4. package/esm/item/edge.d.ts +1 -5
  5. package/esm/item/edge.js +15 -12
  6. package/esm/item/edge.js.map +1 -1
  7. package/esm/item/node.js +7 -3
  8. package/esm/item/node.js.map +1 -1
  9. package/esm/runtime/controller/data.js +2 -0
  10. package/esm/runtime/controller/data.js.map +1 -1
  11. package/esm/runtime/graph.d.ts +2 -2
  12. package/esm/runtime/graph.js +0 -1
  13. package/esm/runtime/graph.js.map +1 -1
  14. package/esm/stdlib/item/node/base3d.d.ts +1 -0
  15. package/esm/stdlib/item/node/base3d.js +1 -0
  16. package/esm/stdlib/item/node/base3d.js.map +1 -1
  17. package/esm/stdlib/plugin/history/item-data-command.js +21 -12
  18. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  19. package/esm/util/point.js +4 -1
  20. package/esm/util/point.js.map +1 -1
  21. package/lib/index.d.ts +1 -1
  22. package/lib/index.js +1 -1
  23. package/lib/item/edge.d.ts +1 -5
  24. package/lib/item/edge.js +15 -12
  25. package/lib/item/edge.js.map +1 -1
  26. package/lib/item/node.js +7 -3
  27. package/lib/item/node.js.map +1 -1
  28. package/lib/runtime/controller/data.js +2 -0
  29. package/lib/runtime/controller/data.js.map +1 -1
  30. package/lib/runtime/graph.d.ts +2 -2
  31. package/lib/runtime/graph.js +0 -1
  32. package/lib/runtime/graph.js.map +1 -1
  33. package/lib/stdlib/item/node/base3d.d.ts +1 -0
  34. package/lib/stdlib/item/node/base3d.js +1 -0
  35. package/lib/stdlib/item/node/base3d.js.map +1 -1
  36. package/lib/stdlib/plugin/history/item-data-command.js +21 -12
  37. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  38. package/lib/util/point.js +4 -1
  39. package/lib/util/point.js.map +1 -1
  40. package/package.json +1 -1
  41. package/src/index.ts +1 -1
  42. package/src/item/edge.ts +24 -19
  43. package/src/item/node.ts +6 -4
  44. package/src/runtime/controller/data.ts +1 -0
  45. package/src/runtime/graph.ts +0 -1
  46. package/src/stdlib/item/node/base3d.ts +1 -0
  47. package/src/stdlib/plugin/history/item-data-command.ts +31 -13
  48. package/src/util/point.ts +4 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g6",
3
- "version": "5.0.0-beta.7",
3
+ "version": "5.0.0-beta.9",
4
4
  "description": "A Graph Visualization Framework in JavaScript",
5
5
  "keywords": [
6
6
  "antv",
package/src/index.ts CHANGED
@@ -14,7 +14,7 @@ runtime.enableCSSParsing = false;
14
14
  * Extend the graph class with std lib
15
15
  */
16
16
 
17
- const version = '5.0.0-beta.7';
17
+ const version = '5.0.0-beta.9';
18
18
 
19
19
  const Graph = extend(EmptyGraph, stdLib);
20
20
 
package/src/item/edge.ts CHANGED
@@ -44,11 +44,13 @@ export default class Edge extends Item {
44
44
  public targetItem: Node | Combo;
45
45
 
46
46
  /** Caches to avoid unnecessary calculations. */
47
- private sourcePositionCache: Point;
48
- private targetPositionCache: Point;
49
- private controlPointsCache: Point;
50
- private sourcePointCache: Point;
51
- private targetPointCache: Point;
47
+ private cache: {
48
+ sourcePositionCache?: Point;
49
+ targetPositionCache?: Point;
50
+ controlPointsCache?: Point;
51
+ sourcePointCache?: Point;
52
+ targetPointCache?: Point;
53
+ } = {};
52
54
 
53
55
  constructor(props: IProps) {
54
56
  super(props);
@@ -187,8 +189,8 @@ export default class Edge extends Item {
187
189
  )
188
190
  ) {
189
191
  return {
190
- sourcePoint: this.sourcePointCache,
191
- targetPoint: this.targetPointCache,
192
+ sourcePoint: this.cache.sourcePointCache,
193
+ targetPoint: this.cache.targetPointCache,
192
194
  changed: false,
193
195
  };
194
196
  }
@@ -214,17 +216,17 @@ export default class Edge extends Item {
214
216
  targetPosition,
215
217
  ).nearestPoint;
216
218
  }
217
- this.sourcePointCache = this.sourceItem.getAnchorPoint(
219
+ this.cache.sourcePointCache = this.sourceItem.getAnchorPoint(
218
220
  sourcePrevious,
219
221
  sourceAnchor,
220
222
  );
221
- this.targetPointCache = this.targetItem.getAnchorPoint(
223
+ this.cache.targetPointCache = this.targetItem.getAnchorPoint(
222
224
  targetPrevious,
223
225
  targetAnchor,
224
226
  );
225
227
  return {
226
- sourcePoint: this.sourcePointCache,
227
- targetPoint: this.targetPointCache,
228
+ sourcePoint: this.cache.sourcePointCache,
229
+ targetPoint: this.cache.targetPointCache,
228
230
  changed: true,
229
231
  };
230
232
  }
@@ -237,15 +239,18 @@ export default class Edge extends Item {
237
239
  * @returns
238
240
  */
239
241
  private shouldUpdatePoints(sourcePosition, targetPosition, controlPoints) {
240
- const changed = !(
241
- isSamePoint(sourcePosition, this.sourcePositionCache) &&
242
- isSamePoint(targetPosition, this.targetPositionCache) &&
243
- controlPoints === this.controlPointsCache
244
- );
242
+ const isComboEnd =
243
+ this.sourceItem.type === 'combo' || this.targetItem.type === 'combo';
244
+ const changed =
245
+ !(
246
+ isSamePoint(sourcePosition, this.cache.sourcePositionCache) &&
247
+ isSamePoint(targetPosition, this.cache.targetPositionCache) &&
248
+ controlPoints === this.cache.controlPointsCache
249
+ ) || isComboEnd;
245
250
  if (changed) {
246
- this.sourcePositionCache = sourcePosition;
247
- this.targetPositionCache = targetPosition;
248
- this.controlPointsCache = controlPoints;
251
+ this.cache.sourcePositionCache = sourcePosition;
252
+ this.cache.targetPositionCache = targetPosition;
253
+ this.cache.controlPointsCache = controlPoints;
249
254
  }
250
255
  return changed;
251
256
  }
package/src/item/node.ts CHANGED
@@ -14,7 +14,6 @@ import {
14
14
  getRectIntersectByPoint,
15
15
  } from '../util/point';
16
16
  import { ComboModelData } from '../types/combo';
17
- import { isArraySame } from '../util/array';
18
17
  import Item from './item';
19
18
 
20
19
  interface IProps {
@@ -270,14 +269,16 @@ export default class Node extends Item {
270
269
  const keyShapeWidth = keyShapeRenderBBox.max[0] - keyShapeRenderBBox.min[0];
271
270
  const keyShapeHeight =
272
271
  keyShapeRenderBBox.max[1] - keyShapeRenderBBox.min[1];
272
+ const keyShapeDepth = keyShapeRenderBBox.max[2] - keyShapeRenderBBox.min[2];
273
273
  const anchorPositions = anchorPoints.map((pointRatio) => {
274
- const [xRatio, yRatio] = pointRatio;
274
+ const [xRatio, yRatio, zRatio] = pointRatio;
275
275
  return {
276
276
  x: keyShapeWidth * xRatio + keyShapeRenderBBox.min[0],
277
277
  y: keyShapeHeight * yRatio + keyShapeRenderBBox.min[1],
278
278
  };
279
279
  });
280
280
 
281
+ console.log('anchorIdx', anchorIdx, anchorPositions, shapeType, innerPoint);
281
282
  if (anchorIdx !== undefined && anchorPositions[anchorIdx]) {
282
283
  return anchorPositions[anchorIdx];
283
284
  }
@@ -323,6 +324,7 @@ export default class Node extends Item {
323
324
  }
324
325
 
325
326
  let linkPoint = intersectPoint;
327
+ if (!isNaN(z)) linkPoint.z = z;
326
328
 
327
329
  // If the node has anchorPoints in the data, find the nearest anchor point.
328
330
  if (anchorPoints.length) {
@@ -334,7 +336,7 @@ export default class Node extends Item {
334
336
  }
335
337
  if (!linkPoint) {
336
338
  // If the calculations above are all failed, return the data's position
337
- return { x, y };
339
+ return { x, y, z };
338
340
  }
339
341
  return linkPoint;
340
342
  }
@@ -342,7 +344,7 @@ export default class Node extends Item {
342
344
  public getPosition(): Point {
343
345
  const initiated =
344
346
  this.shapeMap.keyShape && this.group.attributes.x !== undefined;
345
- if (initiated) {
347
+ if (initiated && this.renderExt.dimensions !== 3) {
346
348
  const { center } = this.shapeMap.keyShape.getRenderBounds();
347
349
  return { x: center[0], y: center[1], z: center[2] };
348
350
  }
@@ -527,6 +527,7 @@ export class DataController {
527
527
  const modelsToMove = [];
528
528
  combos.forEach((newModel) => {
529
529
  const { id, data } = newModel;
530
+ if (!data) return;
530
531
  const { x: comboNewX, y: comboNewY, ...others } = data;
531
532
  if (comboNewX !== undefined || comboNewY !== undefined) {
532
533
  if (this.graphCore.getChildren(id, 'combo').length) {
@@ -1114,7 +1114,6 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1114
1114
 
1115
1115
  const { graphCore } = this.dataController;
1116
1116
  const { specification } = this.themeController;
1117
- // debugger;
1118
1117
  graphCore.once('changed', (event) => {
1119
1118
  if (!event.changes.length) return;
1120
1119
  const changes = event.changes;
@@ -21,6 +21,7 @@ export abstract class BaseNode3D extends BaseNode {
21
21
  themeStyles: NodeShapeStyles;
22
22
  mergedStyles: NodeShapeStyles;
23
23
  device: any; // for 3d renderer
24
+ dimensions: number = 3;
24
25
  constructor(props) {
25
26
  super(props);
26
27
  this.device = props.device;
@@ -43,27 +43,45 @@ export class ItemDataCommand implements Command {
43
43
  operationType: StackType,
44
44
  onlyMove = false,
45
45
  ) {
46
- let models;
46
+ const modelMap = new Map();
47
47
  if (this.type === 'combo' && !onlyMove) {
48
- models = this.changes.map((data) => ({
49
- id: data.nodeId,
50
- data: {
51
- parentId: STACK_TYPE.undo ? data.oldParentId : data.newParentId,
52
- },
53
- }));
48
+ this.changes.forEach((data) => {
49
+ const model = modelMap.get(data.nodeId) || {};
50
+ modelMap.set(data.nodeId, {
51
+ id: data.nodeId,
52
+ data: {
53
+ ...model.data,
54
+ parentId: STACK_TYPE.undo ? data.oldParentId : data.newParentId,
55
+ },
56
+ });
57
+ });
54
58
  } else {
55
- models = this.changes.map((data) => {
56
- return {
59
+ this.changes.forEach((data) => {
60
+ const value =
61
+ operationType === STACK_TYPE.undo ? data.oldValue : data.newValue;
62
+ if (
63
+ (typeof value === 'number' && isNaN(value)) ||
64
+ (['x', 'y'].includes(data.propertyName) && value === undefined)
65
+ ) {
66
+ return;
67
+ }
68
+
69
+ const model = modelMap.get(data.nodeId) || {};
70
+ modelMap.set(data.id, {
57
71
  id: data.id,
58
- data:
59
- operationType === STACK_TYPE.undo ? data.oldValue : data.newValue,
60
- };
72
+ data: {
73
+ ...model.data,
74
+ [data.propertyName]: value,
75
+ },
76
+ });
61
77
  });
62
78
  }
63
79
 
64
80
  graph.pauseStack();
81
+ const models = Array.from(modelMap.values());
65
82
  if (onlyMove) {
66
- graph.updatePosition(this.type, models, this.upsertAncestors);
83
+ // No matter it is node or combo, update the nodes' positions
84
+ graph.updateNodePosition(models, this.upsertAncestors);
67
85
  } else {
68
86
  graph.updateData(this.type, models);
69
87
  }
package/src/util/point.ts CHANGED
@@ -52,7 +52,10 @@ export const distanceVec = (p1: vec2, p2: vec2): number => {
52
52
  export const distance = (p1: Point, p2: Point): number => {
53
53
  const vx = p1.x - p2.x;
54
54
  const vy = p1.y - p2.y;
55
- return Math.sqrt(vx * vx + vy * vy);
55
+ const vz = p1.z - p2.z;
56
+ return isNaN(vz)
57
+ ? Math.sqrt(vx * vx + vy * vy)
58
+ : Math.sqrt(vx * vx + vy * vy + vz * vz);
56
59
  };
57
60
 
58
61
  /**