@antv/g6 5.0.0-beta.4 → 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/index.d.ts +3 -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 +3 -1
- 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 +2 -0
- package/esm/stdlib/index.js +10 -8
- 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 +11 -12
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/image.d.ts +1 -1
- package/esm/stdlib/item/node/image.js +1 -1
- package/esm/stdlib/item/node/image.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/types/graph.d.ts +14 -14
- package/esm/types/hook.d.ts +6 -0
- 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/index.d.ts +3 -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 +3 -1
- 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 +2 -0
- package/lib/stdlib/index.js +10 -8
- 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 +11 -12
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/image.d.ts +1 -1
- package/lib/stdlib/item/node/image.js +1 -1
- package/lib/stdlib/item/node/image.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/types/graph.d.ts +14 -14
- package/lib/types/hook.d.ts +6 -0
- 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 +10 -7
- 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 +10 -7
- package/src/stdlib/item/edge/base.ts +13 -5
- package/src/stdlib/item/node/base.ts +15 -14
- package/src/stdlib/item/node/image.ts +1 -1
- 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/types/graph.ts +22 -17
- package/src/types/hook.ts +6 -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
|
@@ -73,6 +73,7 @@ const {
|
|
|
73
73
|
Legend,
|
|
74
74
|
Toolbar,
|
|
75
75
|
Timebar,
|
|
76
|
+
Snapline,
|
|
76
77
|
} = Plugins;
|
|
77
78
|
|
|
78
79
|
const {
|
|
@@ -206,13 +207,13 @@ const Extensions = {
|
|
|
206
207
|
ValidateData,
|
|
207
208
|
TransformV4Data,
|
|
208
209
|
MapNodeSize,
|
|
209
|
-
//themes
|
|
210
|
+
// themes
|
|
210
211
|
LightTheme,
|
|
211
212
|
DarkTheme,
|
|
212
|
-
//themeSolvers
|
|
213
|
+
// themeSolvers
|
|
213
214
|
SpecThemeSolver,
|
|
214
215
|
SubjectThemeSolver,
|
|
215
|
-
//layout
|
|
216
|
+
// layout
|
|
216
217
|
ForceLayout,
|
|
217
218
|
GridLayout,
|
|
218
219
|
CircularLayout,
|
|
@@ -225,12 +226,12 @@ const Extensions = {
|
|
|
225
226
|
ForceAtlas2Layout,
|
|
226
227
|
DagreLayout,
|
|
227
228
|
ComboCombinedLayout,
|
|
228
|
-
//Hierarchy
|
|
229
|
+
// Hierarchy
|
|
229
230
|
compactBox,
|
|
230
231
|
dendrogram,
|
|
231
232
|
indented,
|
|
232
233
|
mindmap,
|
|
233
|
-
//nodes
|
|
234
|
+
// nodes
|
|
234
235
|
CircleNode,
|
|
235
236
|
RectNode,
|
|
236
237
|
DiamondNode,
|
|
@@ -252,7 +253,7 @@ const Extensions = {
|
|
|
252
253
|
// combos
|
|
253
254
|
CircleCombo,
|
|
254
255
|
RectCombo,
|
|
255
|
-
//behaviors
|
|
256
|
+
// behaviors
|
|
256
257
|
BaseBehavior,
|
|
257
258
|
ActivateRelations,
|
|
258
259
|
BrushSelect,
|
|
@@ -268,7 +269,8 @@ const Extensions = {
|
|
|
268
269
|
CollapseExpandCombo,
|
|
269
270
|
DragNode,
|
|
270
271
|
DragCombo,
|
|
271
|
-
|
|
272
|
+
ShortcutsCall,
|
|
273
|
+
// plugins
|
|
272
274
|
BasePlugin,
|
|
273
275
|
History,
|
|
274
276
|
Toolbar,
|
|
@@ -280,6 +282,7 @@ const Extensions = {
|
|
|
280
282
|
Legend,
|
|
281
283
|
Timebar,
|
|
282
284
|
Hull,
|
|
285
|
+
Snapline,
|
|
283
286
|
};
|
|
284
287
|
|
|
285
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
|
|
|
@@ -804,7 +804,11 @@ export abstract class BaseNode {
|
|
|
804
804
|
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
805
805
|
* @param zoom The zoom level of the graph.
|
|
806
806
|
*/
|
|
807
|
-
public onZoom = (
|
|
807
|
+
public onZoom = (
|
|
808
|
+
shapeMap: NodeShapeMap | ComboShapeMap,
|
|
809
|
+
zoom: number,
|
|
810
|
+
cacheHiddenShape = {},
|
|
811
|
+
) => {
|
|
808
812
|
// zoomLevel changed
|
|
809
813
|
if (this.lodStrategy) {
|
|
810
814
|
const { levels } = this.lodStrategy;
|
|
@@ -825,7 +829,7 @@ export abstract class BaseNode {
|
|
|
825
829
|
// zoomLevel changed, from higher to lower, hide something
|
|
826
830
|
for (let i = currentLevel + 1; i <= maxLevel; i++) {
|
|
827
831
|
levelShapes[String(i)]?.forEach((id) => {
|
|
828
|
-
if (!shapeMap[id]) return;
|
|
832
|
+
if (!shapeMap[id] || cacheHiddenShape[id]) return;
|
|
829
833
|
shapeMap[id].hide();
|
|
830
834
|
hiddenShape[id] = true;
|
|
831
835
|
});
|
|
@@ -874,8 +878,7 @@ export abstract class BaseNode {
|
|
|
874
878
|
const balanceRatio = 1 / zoom || 1;
|
|
875
879
|
this.zoomCache.balanceRatio = balanceRatio;
|
|
876
880
|
if (!labelShape || !labelShape.isVisible()) return;
|
|
877
|
-
const {
|
|
878
|
-
const { position = 'bottom' } = labelStyle;
|
|
881
|
+
const { position = 'bottom' } = this.mergedStyles.labelShape;
|
|
879
882
|
|
|
880
883
|
const keyShapeLocal = keyShape.getLocalBounds();
|
|
881
884
|
if (zoom < 1) {
|
|
@@ -917,21 +920,20 @@ export abstract class BaseNode {
|
|
|
917
920
|
const scaleTransform = `scale(${balanceRatio}, ${balanceRatio})`;
|
|
918
921
|
labelShape.style.transform = `${oriTransform} ${scaleTransform}`;
|
|
919
922
|
this.scaleTransformCache = scaleTransform;
|
|
920
|
-
|
|
921
|
-
labelShape.style.wordWrapWidth = wordWrapWidth;
|
|
923
|
+
labelShape.style.wordWrapWidth = this.zoomCache.wordWrapWidth * zoom;
|
|
922
924
|
|
|
923
925
|
if (!labelBackgroundShape || !labelBackgroundShape.isVisible()) return;
|
|
924
926
|
|
|
925
|
-
const
|
|
927
|
+
const [paddingTop, paddingRight, paddingBottom, paddingLeft] = this
|
|
928
|
+
.mergedStyles.labelBackgroundShape.padding as number[];
|
|
929
|
+
const sidePadding = paddingRight + paddingLeft;
|
|
926
930
|
const { width, height, x, y } = labelBackgroundShape.attributes;
|
|
927
|
-
const [paddingTop, paddingRight, paddingBottom, paddingLeft] =
|
|
928
|
-
padding as number[];
|
|
929
931
|
|
|
930
932
|
switch (position) {
|
|
931
933
|
case 'top':
|
|
932
934
|
// if it is zoom-out, do not scale the gap between keyShape and labelShape, differentiate from zoom-in by adjusting transformOrigin
|
|
933
935
|
labelBackgroundShape.style.transformOrigin = `${
|
|
934
|
-
paddingLeft + (width -
|
|
936
|
+
paddingLeft + (width - sidePadding) / 2
|
|
935
937
|
} ${zoom < 1 ? height - paddingBottom : keyShapeLocal.min[1] - y}`;
|
|
936
938
|
break;
|
|
937
939
|
case 'left':
|
|
@@ -946,7 +948,7 @@ export abstract class BaseNode {
|
|
|
946
948
|
break;
|
|
947
949
|
case 'bottom':
|
|
948
950
|
labelBackgroundShape.style.transformOrigin = `${
|
|
949
|
-
paddingLeft + (width -
|
|
951
|
+
paddingLeft + (width - sidePadding) / 2
|
|
950
952
|
} ${
|
|
951
953
|
zoom < 1
|
|
952
954
|
? paddingTop + (height - paddingTop - paddingBottom) / 2
|
|
@@ -956,14 +958,13 @@ export abstract class BaseNode {
|
|
|
956
958
|
default:
|
|
957
959
|
// center
|
|
958
960
|
labelBackgroundShape.style.transformOrigin = `${
|
|
959
|
-
paddingLeft + (width -
|
|
961
|
+
paddingLeft + (width - sidePadding) / 2
|
|
960
962
|
} ${paddingTop + (height - paddingTop - paddingBottom) / 2}`;
|
|
961
963
|
}
|
|
962
964
|
|
|
963
965
|
const { labelShapeGeometry: labelBBox } = this.boundsCache;
|
|
964
966
|
const labelWidth = labelBBox.max[0] - labelBBox.min[0];
|
|
965
|
-
const xAxistRatio =
|
|
966
|
-
(labelWidth * balanceRatio + paddingLeft + paddingRight) / width;
|
|
967
|
+
const xAxistRatio = (labelWidth * balanceRatio + sidePadding) / width;
|
|
967
968
|
|
|
968
969
|
labelBackgroundShape.style.transform = `scale(${xAxistRatio}, ${balanceRatio})`;
|
|
969
970
|
}
|
|
@@ -7,9 +7,9 @@ import {
|
|
|
7
7
|
NodeShapeStyles,
|
|
8
8
|
} from '../../../types/node';
|
|
9
9
|
import { convertToNumber } from '../../../util/type';
|
|
10
|
-
import { BaseNode } from './base';
|
|
11
10
|
import { ComboModelData, ComboShapeMap } from '../../../types/combo';
|
|
12
11
|
import { ShapeTagMap } from '../../../util/shape';
|
|
12
|
+
import { BaseNode } from './base';
|
|
13
13
|
|
|
14
14
|
export class ImageNode extends BaseNode {
|
|
15
15
|
override defaultStyles = {
|
|
@@ -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);
|
|
@@ -200,7 +200,7 @@ export class History extends Base {
|
|
|
200
200
|
/**
|
|
201
201
|
* Pause stacking operations.
|
|
202
202
|
*/
|
|
203
|
-
|
|
203
|
+
pauseStack(): void {
|
|
204
204
|
this.withoutStackingCounter++;
|
|
205
205
|
|
|
206
206
|
if (this.withoutStackingCounter === 1) {
|
|
@@ -212,7 +212,7 @@ export class History extends Base {
|
|
|
212
212
|
/**
|
|
213
213
|
* Resume stacking operations.
|
|
214
214
|
*/
|
|
215
|
-
|
|
215
|
+
resumeStack(): void {
|
|
216
216
|
if (this.withoutStackingCounter > 0) {
|
|
217
217
|
this.withoutStackingCounter--;
|
|
218
218
|
}
|
|
@@ -260,14 +260,14 @@ export class History extends Base {
|
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
/**
|
|
263
|
-
* Begin a
|
|
264
|
-
* Any operations performed between `
|
|
263
|
+
* Begin a historyBatch operation.
|
|
264
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
265
265
|
* treated as a single operation when undoing or redoing.
|
|
266
266
|
*/
|
|
267
|
-
public
|
|
267
|
+
public startHistoryBatch() {
|
|
268
268
|
if (this.isBatching) {
|
|
269
269
|
throw new Error(
|
|
270
|
-
'Ensure that
|
|
270
|
+
'Ensure that historyBatch processing is stopped before starting.',
|
|
271
271
|
);
|
|
272
272
|
}
|
|
273
273
|
this.initBatchCommands();
|
|
@@ -275,14 +275,14 @@ export class History extends Base {
|
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
/**
|
|
278
|
-
* End a
|
|
279
|
-
* Any operations performed between `
|
|
278
|
+
* End a historyBatch operation.
|
|
279
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
280
280
|
* treated as a single operation when undoing or redoing.
|
|
281
281
|
*/
|
|
282
|
-
public
|
|
282
|
+
public stopHistoryBatch() {
|
|
283
283
|
if (!this.isBatching) {
|
|
284
284
|
throw new Error(
|
|
285
|
-
'Ensure that
|
|
285
|
+
'Ensure that historyBatch processing is started before stopping.',
|
|
286
286
|
);
|
|
287
287
|
}
|
|
288
288
|
this.push(this.batchCommands);
|
|
@@ -290,13 +290,13 @@ export class History extends Base {
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
/**
|
|
293
|
-
* Execute the provided function in a
|
|
293
|
+
* Execute the provided function in a historyBatch mode
|
|
294
294
|
* @param callback
|
|
295
295
|
*/
|
|
296
|
-
public
|
|
297
|
-
this.
|
|
296
|
+
public historyBatch(callback) {
|
|
297
|
+
this.startHistoryBatch();
|
|
298
298
|
callback();
|
|
299
|
-
this.
|
|
299
|
+
this.stopHistoryBatch();
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
public getEvents() {
|
|
@@ -26,14 +26,14 @@ export class ItemDataCommand implements Command {
|
|
|
26
26
|
|
|
27
27
|
private removeChangedData(graph) {
|
|
28
28
|
const ids = this.changes.map((data) => data.value?.id).filter(Boolean);
|
|
29
|
-
graph.
|
|
29
|
+
graph.executeWithNoStack(() => {
|
|
30
30
|
graph.removeData(this.type, ids);
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
private addChangedData(graph) {
|
|
35
35
|
const models = this.changes.map((data) => data.value).filter(Boolean);
|
|
36
|
-
graph.
|
|
36
|
+
graph.executeWithNoStack(() => {
|
|
37
37
|
graph.addData(this.type, models);
|
|
38
38
|
});
|
|
39
39
|
}
|
|
@@ -61,13 +61,13 @@ export class ItemDataCommand implements Command {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
graph.
|
|
64
|
+
graph.pauseStack();
|
|
65
65
|
if (onlyMove) {
|
|
66
66
|
graph.updatePosition(this.type, models, this.upsertAncestors);
|
|
67
67
|
} else {
|
|
68
68
|
graph.updateData(this.type, models);
|
|
69
69
|
}
|
|
70
|
-
graph.
|
|
70
|
+
graph.resumeStack();
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
undo(graph: IGraph) {
|
|
@@ -11,7 +11,7 @@ export class LayerUpdatedCommand implements Command {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
undo(graph: IGraph) {
|
|
14
|
-
graph.
|
|
14
|
+
graph.executeWithNoStack(() => {
|
|
15
15
|
this.action === 'front'
|
|
16
16
|
? graph.backItem(this.ids)
|
|
17
17
|
: graph.frontItem(this.ids);
|
|
@@ -19,7 +19,7 @@ export class LayerUpdatedCommand implements Command {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
redo(graph: IGraph) {
|
|
22
|
-
graph.
|
|
22
|
+
graph.executeWithNoStack(() => {
|
|
23
23
|
this.action === 'front'
|
|
24
24
|
? graph.frontItem(this.ids)
|
|
25
25
|
: graph.backItem(this.ids);
|
|
@@ -20,7 +20,7 @@ export class StateUpdatedCommand implements Command {
|
|
|
20
20
|
private updateItemsStates(graph, stateOptions) {
|
|
21
21
|
stateOptions?.map((option) => {
|
|
22
22
|
const { ids, states, value } = option;
|
|
23
|
-
graph.
|
|
23
|
+
graph.executeWithNoStack(() => {
|
|
24
24
|
graph.setItemState(ids, states, value);
|
|
25
25
|
});
|
|
26
26
|
});
|
|
@@ -20,13 +20,13 @@ export class VisibilityUpdatedCommand implements Command {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
private toggleItemsVisible(graph: IGraph, values) {
|
|
23
|
-
graph.
|
|
23
|
+
graph.pauseStack();
|
|
24
24
|
each(values, (value) =>
|
|
25
25
|
value.visible
|
|
26
26
|
? graph.showItem(value.ids, this.disableAnimate)
|
|
27
27
|
: graph.hideItem(value.ids, this.disableAnimate),
|
|
28
28
|
);
|
|
29
|
-
graph.
|
|
29
|
+
graph.resumeStack();
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
undo(graph: IGraph) {
|