@antv/g6 5.0.0-beta.6 → 5.0.0-beta.8

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 (151) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/index.d.ts +8 -12
  3. package/esm/index.js +1 -1
  4. package/esm/item/edge.d.ts +21 -1
  5. package/esm/item/edge.js +78 -35
  6. package/esm/item/edge.js.map +1 -1
  7. package/esm/item/item.js +9 -5
  8. package/esm/item/item.js.map +1 -1
  9. package/esm/item/node.js +6 -6
  10. package/esm/item/node.js.map +1 -1
  11. package/esm/runtime/controller/data.d.ts +7 -10
  12. package/esm/runtime/controller/data.js +125 -281
  13. package/esm/runtime/controller/data.js.map +1 -1
  14. package/esm/runtime/controller/item.js +2 -6
  15. package/esm/runtime/controller/item.js.map +1 -1
  16. package/esm/runtime/graph.d.ts +5 -5
  17. package/esm/runtime/graph.js +35 -15
  18. package/esm/runtime/graph.js.map +1 -1
  19. package/esm/stdlib/behavior/create-edge.d.ts +2 -2
  20. package/esm/stdlib/behavior/create-edge.js +17 -16
  21. package/esm/stdlib/behavior/create-edge.js.map +1 -1
  22. package/esm/stdlib/behavior/drag-canvas.d.ts +1 -0
  23. package/esm/stdlib/behavior/drag-canvas.js +20 -12
  24. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  25. package/esm/stdlib/behavior/zoom-canvas.d.ts +1 -0
  26. package/esm/stdlib/behavior/zoom-canvas.js +24 -16
  27. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  28. package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
  29. package/esm/stdlib/data/mapNodeSize.js +2 -2
  30. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  31. package/esm/stdlib/data/transformV4Data.d.ts +2 -2
  32. package/esm/stdlib/data/transformV4Data.js +2 -2
  33. package/esm/stdlib/data/transformV4Data.js.map +1 -1
  34. package/esm/stdlib/data/validateData.d.ts +2 -2
  35. package/esm/stdlib/data/validateData.js +9 -9
  36. package/esm/stdlib/data/validateData.js.map +1 -1
  37. package/esm/stdlib/index.d.ts +7 -7
  38. package/esm/stdlib/index.js +1 -1
  39. package/esm/stdlib/index.js.map +1 -1
  40. package/esm/stdlib/item/edge/base.js +4 -9
  41. package/esm/stdlib/item/edge/base.js.map +1 -1
  42. package/esm/stdlib/plugin/history/item-data-command.js +21 -12
  43. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  44. package/esm/stdlib/plugin/minimap/index.js +8 -2
  45. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  46. package/esm/stdlib/plugin/snapline/index.d.ts +5 -1
  47. package/esm/stdlib/plugin/snapline/index.js +23 -12
  48. package/esm/stdlib/plugin/snapline/index.js.map +1 -1
  49. package/esm/types/graph.d.ts +3 -3
  50. package/esm/types/view.d.ts +5 -0
  51. package/esm/util/event.d.ts +3 -1
  52. package/esm/util/event.js +8 -1
  53. package/esm/util/event.js.map +1 -1
  54. package/esm/util/item.js +1 -1
  55. package/esm/util/item.js.map +1 -1
  56. package/esm/util/layout.d.ts +11 -0
  57. package/esm/util/layout.js +45 -0
  58. package/esm/util/layout.js.map +1 -1
  59. package/esm/util/point.js +5 -1
  60. package/esm/util/point.js.map +1 -1
  61. package/esm/util/shape.d.ts +1 -1
  62. package/esm/util/shape.js +3 -7
  63. package/esm/util/shape.js.map +1 -1
  64. package/lib/index.d.ts +8 -12
  65. package/lib/index.js +1 -1
  66. package/lib/item/edge.d.ts +21 -1
  67. package/lib/item/edge.js +77 -34
  68. package/lib/item/edge.js.map +1 -1
  69. package/lib/item/item.js +9 -5
  70. package/lib/item/item.js.map +1 -1
  71. package/lib/item/node.js +6 -6
  72. package/lib/item/node.js.map +1 -1
  73. package/lib/runtime/controller/data.d.ts +7 -10
  74. package/lib/runtime/controller/data.js +125 -281
  75. package/lib/runtime/controller/data.js.map +1 -1
  76. package/lib/runtime/controller/item.js +2 -6
  77. package/lib/runtime/controller/item.js.map +1 -1
  78. package/lib/runtime/graph.d.ts +5 -5
  79. package/lib/runtime/graph.js +35 -15
  80. package/lib/runtime/graph.js.map +1 -1
  81. package/lib/stdlib/behavior/create-edge.d.ts +2 -2
  82. package/lib/stdlib/behavior/create-edge.js +17 -16
  83. package/lib/stdlib/behavior/create-edge.js.map +1 -1
  84. package/lib/stdlib/behavior/drag-canvas.d.ts +1 -0
  85. package/lib/stdlib/behavior/drag-canvas.js +20 -12
  86. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  87. package/lib/stdlib/behavior/zoom-canvas.d.ts +1 -0
  88. package/lib/stdlib/behavior/zoom-canvas.js +24 -16
  89. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  90. package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
  91. package/lib/stdlib/data/mapNodeSize.js +2 -2
  92. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  93. package/lib/stdlib/data/transformV4Data.d.ts +2 -2
  94. package/lib/stdlib/data/transformV4Data.js +2 -2
  95. package/lib/stdlib/data/transformV4Data.js.map +1 -1
  96. package/lib/stdlib/data/validateData.d.ts +2 -2
  97. package/lib/stdlib/data/validateData.js +9 -9
  98. package/lib/stdlib/data/validateData.js.map +1 -1
  99. package/lib/stdlib/index.d.ts +7 -7
  100. package/lib/stdlib/index.js +1 -1
  101. package/lib/stdlib/index.js.map +1 -1
  102. package/lib/stdlib/item/edge/base.js +4 -9
  103. package/lib/stdlib/item/edge/base.js.map +1 -1
  104. package/lib/stdlib/plugin/history/item-data-command.js +21 -12
  105. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  106. package/lib/stdlib/plugin/minimap/index.js +8 -2
  107. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  108. package/lib/stdlib/plugin/snapline/index.d.ts +5 -1
  109. package/lib/stdlib/plugin/snapline/index.js +23 -12
  110. package/lib/stdlib/plugin/snapline/index.js.map +1 -1
  111. package/lib/types/graph.d.ts +3 -3
  112. package/lib/types/view.d.ts +5 -0
  113. package/lib/util/event.d.ts +3 -1
  114. package/lib/util/event.js +8 -1
  115. package/lib/util/event.js.map +1 -1
  116. package/lib/util/item.js +1 -1
  117. package/lib/util/item.js.map +1 -1
  118. package/lib/util/layout.d.ts +11 -0
  119. package/lib/util/layout.js +47 -1
  120. package/lib/util/layout.js.map +1 -1
  121. package/lib/util/point.js +5 -1
  122. package/lib/util/point.js.map +1 -1
  123. package/lib/util/shape.d.ts +1 -1
  124. package/lib/util/shape.js +3 -7
  125. package/lib/util/shape.js.map +1 -1
  126. package/package.json +1 -1
  127. package/src/index.ts +1 -1
  128. package/src/item/edge.ts +108 -48
  129. package/src/item/item.ts +13 -9
  130. package/src/item/node.ts +6 -6
  131. package/src/runtime/controller/data.ts +140 -339
  132. package/src/runtime/controller/item.ts +2 -6
  133. package/src/runtime/graph.ts +57 -17
  134. package/src/stdlib/behavior/create-edge.ts +21 -20
  135. package/src/stdlib/behavior/drag-canvas.ts +23 -12
  136. package/src/stdlib/behavior/zoom-canvas.ts +27 -16
  137. package/src/stdlib/data/mapNodeSize.ts +2 -2
  138. package/src/stdlib/data/transformV4Data.ts +2 -2
  139. package/src/stdlib/data/validateData.ts +9 -9
  140. package/src/stdlib/index.ts +1 -1
  141. package/src/stdlib/item/edge/base.ts +4 -8
  142. package/src/stdlib/plugin/history/item-data-command.ts +31 -13
  143. package/src/stdlib/plugin/minimap/index.ts +16 -10
  144. package/src/stdlib/plugin/snapline/index.ts +36 -16
  145. package/src/types/graph.ts +6 -3
  146. package/src/types/view.ts +8 -3
  147. package/src/util/event.ts +14 -1
  148. package/src/util/item.ts +1 -1
  149. package/src/util/layout.ts +45 -0
  150. package/src/util/point.ts +4 -2
  151. package/src/util/shape.ts +6 -7
@@ -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
  }
@@ -502,8 +502,12 @@ export class Minimap extends Base {
502
502
  if (!graphEdgeGroup) return;
503
503
  let { minimapItem, graphItem } = itemMap.get(edgeModel.id) || {};
504
504
  if (minimapItem && !minimapItem.destroyed) {
505
- const path = graphItem.style.path;
505
+ const { path, x1, x2, y1, y2 } = graphItem.style;
506
506
  minimapItem.style.path = path;
507
+ minimapItem.style.x1 = x1;
508
+ minimapItem.style.x2 = x2;
509
+ minimapItem.style.y1 = y1;
510
+ minimapItem.style.y2 = y2;
507
511
  } else {
508
512
  graphItem = graphEdgeGroup
509
513
  .find((ele) => ele.getAttribute('data-item-id') === edgeModel.id)
@@ -596,16 +600,18 @@ export class Minimap extends Base {
596
600
  () => {
597
601
  const nodeGroup = this.canvas.getRoot().getElementById('node-group');
598
602
  const edgeGroup = this.canvas.getRoot().getElementById('edge-group');
599
- nodeGroup.childNodes.concat(edgeGroup.childNodes).forEach((child) => {
600
- const id = child.getAttribute?.('data-item-id');
601
- if (this.visibleCache.hasOwnProperty(id)) {
602
- if (this.visibleCache[id]) {
603
- child.childNodes.forEach((shape) => shape.show());
604
- } else if (this.visibleCache[id] === false) {
605
- child.childNodes.forEach((shape) => shape.hide());
603
+ (nodeGroup?.childNodes || [])
604
+ .concat(edgeGroup?.childNodes || [])
605
+ .forEach((child) => {
606
+ const id = child.getAttribute?.('data-item-id');
607
+ if (this.visibleCache.hasOwnProperty(id)) {
608
+ if (this.visibleCache[id]) {
609
+ child.childNodes.forEach((shape) => shape.show());
610
+ } else if (this.visibleCache[id] === false) {
611
+ child.childNodes.forEach((shape) => shape.hide());
612
+ }
606
613
  }
607
- }
608
- });
614
+ });
609
615
  this.visibleCache = {};
610
616
  },
611
617
  50,
@@ -2,7 +2,7 @@ import { ID } from '@antv/graphlib';
2
2
  import { AABB, DisplayObject } from '@antv/g';
3
3
  import { throttle } from '@antv/util';
4
4
  import { ITEM_TYPE, ShapeStyle } from '../../../types/item';
5
- import { IG6GraphEvent, IGraph } from '../../../types';
5
+ import { IG6GraphEvent, IGraph, NodeModel } from '../../../types';
6
6
  import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
7
7
  import { Point } from '../../../types/common';
8
8
 
@@ -46,6 +46,11 @@ export class Snapline extends Base {
46
46
  offsetY: number | undefined,
47
47
  ] = [undefined, undefined];
48
48
 
49
+ /**
50
+ * Cache the nodes' positions to be throttly updated.
51
+ */
52
+ private updateCache: Map<ID, NodeModel> = new Map();
53
+
49
54
  /**
50
55
  * Gets the current cursor node and center offset and then with initialOffset difference
51
56
  */
@@ -70,14 +75,9 @@ export class Snapline extends Base {
70
75
  ];
71
76
  };
72
77
 
73
- //#endregion
74
-
75
78
  private dragging = false;
76
79
  private draggingBBox: AABB = undefined;
77
80
 
78
- // the offset(cursor and draggingbox) when start to drag
79
- private nonAbosorbOffset: Point = undefined;
80
-
81
81
  // Gets the offset between the cursor and draggingItem
82
82
  private getPointerOffsetWithItem = (pointer: {
83
83
  x: number;
@@ -118,6 +118,7 @@ export class Snapline extends Base {
118
118
  * @param dl drawLine
119
119
  */
120
120
  getDrawLineIdByDrawLine(dl: DrawLine): ID {
121
+ if (!dl) return;
121
122
  return `${dl.line[0].x}-${dl.line[0].y}-${dl.line[1].x}-${dl.line[1].y}`;
122
123
  }
123
124
  /**
@@ -777,11 +778,6 @@ export class Snapline extends Base {
777
778
  event.canvas.x - this.draggingBBox.center[0],
778
779
  event.canvas.y - this.draggingBBox.center[1],
779
780
  ];
780
-
781
- this.nonAbosorbOffset = this.getPointerOffsetWithItem({
782
- x: event.canvas.x,
783
- y: event.canvas.y,
784
- });
785
781
  }
786
782
 
787
783
  onDrag = throttle(
@@ -790,7 +786,7 @@ export class Snapline extends Base {
790
786
 
791
787
  this.initAlignLinesForChoose();
792
788
 
793
- // control layer:Check to delete existing line & drawed line & adsorption
789
+ // control layer: Check to delete existing line & drawed line & adsorption
794
790
  // set historyPoints
795
791
 
796
792
  this.historyPoints[0] = this.historyPoints[1];
@@ -936,10 +932,10 @@ export class Snapline extends Base {
936
932
  }
937
933
  }
938
934
  }).bind(this),
939
- 10,
935
+ 16,
940
936
  {
941
- leading: true,
942
- trailing: false,
937
+ leading: false,
938
+ trailing: true,
943
939
  },
944
940
  );
945
941
 
@@ -1272,6 +1268,30 @@ export class Snapline extends Base {
1272
1268
  }
1273
1269
 
1274
1270
  doUpdatePosition(data) {
1275
- this.graph.updateNodePosition({ id: this.dragItemId, data }, false, true);
1271
+ const cache = this.updateCache.get(this.dragItemId);
1272
+ this.updateCache.set(this.dragItemId, {
1273
+ id: this.dragItemId,
1274
+ data: {
1275
+ ...cache?.data,
1276
+ ...data,
1277
+ },
1278
+ });
1279
+ this.throttleUpdate();
1276
1280
  }
1281
+
1282
+ throttleUpdate = throttle(
1283
+ () => {
1284
+ this.graph.updateNodePosition(
1285
+ Array.from(this.updateCache.values()),
1286
+ false,
1287
+ true,
1288
+ );
1289
+ this.updateCache.clear();
1290
+ },
1291
+ 16,
1292
+ {
1293
+ leading: true,
1294
+ trailing: true,
1295
+ },
1296
+ );
1277
1297
  }
@@ -395,8 +395,8 @@ export interface IGraph<
395
395
  */
396
396
  fitView: (
397
397
  options?: {
398
- padding: Padding;
399
- rules: FitViewRules;
398
+ padding?: Padding;
399
+ rules?: FitViewRules;
400
400
  },
401
401
  effectTiming?: CameraAnimationOptions,
402
402
  ) => Promise<void>;
@@ -406,7 +406,10 @@ export interface IGraph<
406
406
  * @returns
407
407
  * @group View
408
408
  */
409
- fitCenter: (effectTiming?: CameraAnimationOptions) => Promise<void>;
409
+ fitCenter: (
410
+ boundsType?: 'render' | 'layout',
411
+ effectTiming?: CameraAnimationOptions,
412
+ ) => Promise<void>;
410
413
  /**
411
414
  * Move the graph to make the item align the view center.
412
415
  * @param item node/edge/combo item or its id
package/src/types/view.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  export interface FitViewRules {
2
- onlyOutOfViewPort?: boolean; // Whehter fit it only when the graph is out of the view.
3
- direction?: 'x' | 'y' | 'both'; // Axis to fit.
4
- ratioRule?: 'max' | 'min'; // Ratio rule to fit.
2
+ /** Whehter fit it only when the graph is out of the view. */
3
+ onlyOutOfViewPort?: boolean;
4
+ /** Axis to fit. */
5
+ direction?: 'x' | 'y' | 'both';
6
+ /** Ratio rule to fit. */
7
+ ratioRule?: 'max' | 'min';
8
+ /** Bounds type. 'render' means calculate the bounds by get rendering bounds. 'layout' for the situation that layout algorithm is done but the positions are not animated rendered. */
9
+ boundsType?: 'render' | 'layout';
5
10
  }
6
11
 
7
12
  export type GraphAlignment =
package/src/util/event.ts CHANGED
@@ -9,6 +9,8 @@ import {
9
9
  NodeDataUpdated,
10
10
  NodeRemoved,
11
11
  TreeStructureChanged,
12
+ TreeStructureAttached,
13
+ TreeStructureDetached,
12
14
  } from '@antv/graphlib';
13
15
  import { IG6GraphEvent, IGraph, NodeModelData } from '../types';
14
16
  import { GraphCore } from '../types/data';
@@ -84,6 +86,8 @@ export type GroupedChanges = {
84
86
  EdgeDataUpdated: EdgeDataUpdated<EdgeModelData>[];
85
87
  TreeStructureChanged: TreeStructureChanged[];
86
88
  ComboStructureChanged: TreeStructureChanged[];
89
+ TreeStructureAttached: TreeStructureAttached[];
90
+ TreeStructureDetached: TreeStructureDetached[];
87
91
  };
88
92
 
89
93
  /**
@@ -106,6 +110,8 @@ export const getGroupedChanges = (
106
110
  EdgeDataUpdated: [],
107
111
  TreeStructureChanged: [],
108
112
  ComboStructureChanged: [],
113
+ TreeStructureAttached: [],
114
+ TreeStructureDetached: [],
109
115
  };
110
116
  changes.forEach((change) => {
111
117
  const { type: changeType } = change;
@@ -126,7 +132,14 @@ export const getGroupedChanges = (
126
132
  else if (change.treeKey === 'tree')
127
133
  groupedChanges.TreeStructureChanged.push(change);
128
134
  return;
129
- } else if (['NodeRemoved', 'EdgeRemoved'].includes(changeType)) {
135
+ } else if (
136
+ [
137
+ 'NodeRemoved',
138
+ 'EdgeRemoved',
139
+ 'TreeStructureAttached',
140
+ 'TreeStructureDetached',
141
+ ].includes(changeType)
142
+ ) {
130
143
  groupedChanges[changeType].push(change);
131
144
  } else {
132
145
  const { id: oid } = change.value;
package/src/util/item.ts CHANGED
@@ -169,5 +169,5 @@ export const upsertTransientItem = (
169
169
  * @returns
170
170
  */
171
171
  export function generateEdgeID(source: ID, target: ID) {
172
- return [source, target, uniqueId()].join('->');
172
+ return [source, uniqueId(), target].join('->');
173
173
  }
@@ -163,3 +163,48 @@ export const radialLayout = (
163
163
  });
164
164
  return;
165
165
  };
166
+
167
+ /**
168
+ * Get the layout (nodes' positions) bounds of a graph.
169
+ * @param {Graph} graph - The graph object.
170
+ * @returns {Object} - The layout bounds object containing the minimum, maximum, center, and halfExtents values.
171
+ */
172
+ export const getLayoutBounds = (graph) => {
173
+ const min = [Infinity, Infinity];
174
+ const max = [-Infinity, -Infinity];
175
+ const borderIds = { min: [], max: [] };
176
+ graph.getAllNodesData().forEach((model) => {
177
+ const { x, y } = model.data;
178
+ if (isNaN(x) || isNaN(y)) return;
179
+ if (min[0] > x) {
180
+ min[0] = x;
181
+ borderIds.min[0] = model.id;
182
+ }
183
+ if (min[1] > y) {
184
+ min[1] = y;
185
+ borderIds.min[1] = model.id;
186
+ }
187
+ if (max[0] < x) {
188
+ max[0] = x;
189
+ borderIds.max[0] = model.id;
190
+ }
191
+ if (max[1] < y) {
192
+ max[1] = y;
193
+ borderIds.max[1] = model.id;
194
+ }
195
+ });
196
+ borderIds.min.forEach((id, i) => {
197
+ const { halfExtents: nodeHalfSize } = graph.getRenderBBox(id);
198
+ min[i] -= nodeHalfSize[i];
199
+ });
200
+ borderIds.max.forEach((id, i) => {
201
+ const { halfExtents: nodeHalfSize } = graph.getRenderBBox(id);
202
+ max[i] += nodeHalfSize[i];
203
+ });
204
+ return {
205
+ min,
206
+ max,
207
+ center: min.map((val, i) => (max[i] + val) / 2),
208
+ halfExtents: min.map((val, i) => (max[i] - val) / 2),
209
+ };
210
+ };
package/src/util/point.ts CHANGED
@@ -61,8 +61,10 @@ export const distance = (p1: Point, p2: Point): number => {
61
61
  * @param p2
62
62
  * @returns
63
63
  */
64
- export const isSamePoint = (p1: Point, p2: Point): boolean =>
65
- p1.x === p2.x && p1.y === p2.y && p1.z === p2.z;
64
+ export const isSamePoint = (p1: Point, p2: Point): boolean => {
65
+ if (!p1 || !p2) return false;
66
+ return p1.x === p2.x && p1.y === p2.y && p1.z === p2.z;
67
+ };
66
68
 
67
69
  /**
68
70
  * Get point and circle intersect point.
package/src/util/shape.ts CHANGED
@@ -270,7 +270,7 @@ export const formatPadding = (
270
270
  * @returns
271
271
  */
272
272
  export const mergeStyles = (styleMaps: ItemShapeStyles[]) => {
273
- let currentResult = styleMaps[0];
273
+ let currentResult = clone(styleMaps[0]);
274
274
  styleMaps.forEach((styleMap, i) => {
275
275
  if (i > 0) currentResult = merge2Styles(currentResult, styleMap);
276
276
  });
@@ -289,15 +289,14 @@ const merge2Styles = (
289
289
  ) => {
290
290
  if (!styleMap1) return { ...styleMap2 };
291
291
  else if (!styleMap2) return { ...styleMap1 };
292
- const mergedStyle = clone(styleMap1);
292
+ const mergedStyle = styleMap1;
293
293
  Object.keys(styleMap2).forEach((shapeId) => {
294
294
  const style = styleMap2[shapeId];
295
- mergedStyle[shapeId] = mergedStyle[shapeId] || {};
296
295
  if (!style) return;
297
- Object.keys(style).forEach((styleName) => {
298
- const value = style[styleName];
299
- mergedStyle[shapeId][styleName] = value;
300
- });
296
+ mergedStyle[shapeId] = {
297
+ ...mergedStyle[shapeId],
298
+ ...style,
299
+ };
301
300
  });
302
301
  return mergedStyle;
303
302
  };