@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
package/src/runtime/graph.ts
CHANGED
|
@@ -26,7 +26,7 @@ import type {
|
|
|
26
26
|
import type { CameraAnimationOptions } from '../types/animate';
|
|
27
27
|
import type { BehaviorOptionsOf, BehaviorRegistry } from '../types/behavior';
|
|
28
28
|
import type { ComboDisplayModel, ComboModel } from '../types/combo';
|
|
29
|
-
import type { Padding, Point } from '../types/common';
|
|
29
|
+
import type { Bounds, Padding, Point } from '../types/common';
|
|
30
30
|
import type { DataChangeType, DataConfig, GraphCore } from '../types/data';
|
|
31
31
|
import type { EdgeDisplayModel, EdgeModel, EdgeModelData } from '../types/edge';
|
|
32
32
|
import type { StackType } from '../types/history';
|
|
@@ -101,7 +101,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
101
101
|
constructor(spec: Specification<B, T>) {
|
|
102
102
|
super();
|
|
103
103
|
|
|
104
|
-
this.specification = Object.assign(
|
|
104
|
+
this.specification = Object.assign(
|
|
105
|
+
{},
|
|
106
|
+
this.defaultSpecification,
|
|
107
|
+
this.formatSpecification(spec),
|
|
108
|
+
);
|
|
105
109
|
this.initHooks();
|
|
106
110
|
this.initCanvas();
|
|
107
111
|
this.initControllers();
|
|
@@ -356,11 +360,29 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
356
360
|
};
|
|
357
361
|
}
|
|
358
362
|
|
|
363
|
+
private formatSpecification(spec: Specification<B, T>) {
|
|
364
|
+
return {
|
|
365
|
+
...spec,
|
|
366
|
+
optimize: {
|
|
367
|
+
tileBehavior: 2000,
|
|
368
|
+
tileBehaviorSize: 1000,
|
|
369
|
+
tileFirstRender: 10000,
|
|
370
|
+
tileFirstRenderSize: 1000,
|
|
371
|
+
...spec.optimize,
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
359
376
|
/**
|
|
360
377
|
* Update the specs(configurations).
|
|
361
378
|
*/
|
|
362
379
|
public updateSpecification(spec: Specification<B, T>): Specification<B, T> {
|
|
363
|
-
|
|
380
|
+
const newSpec = Object.assign(
|
|
381
|
+
this.specification,
|
|
382
|
+
this.formatSpecification(spec),
|
|
383
|
+
);
|
|
384
|
+
// TODO: update something
|
|
385
|
+
return newSpec;
|
|
364
386
|
}
|
|
365
387
|
/**
|
|
366
388
|
* Update the theme specs (configurations).
|
|
@@ -398,12 +420,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
398
420
|
* @group Data
|
|
399
421
|
*/
|
|
400
422
|
public async read(data: DataConfig) {
|
|
423
|
+
const { tileFirstRender, tileFirstRenderSize } =
|
|
424
|
+
this.specification.optimize || {};
|
|
401
425
|
this.hooks.datachange.emit({ data, type: 'replace' });
|
|
402
426
|
const emitRender = async () => {
|
|
403
|
-
this.hooks.render.
|
|
427
|
+
await this.hooks.render.emitLinearAsync({
|
|
404
428
|
graphCore: this.dataController.graphCore,
|
|
405
429
|
theme: this.themeController.specification,
|
|
406
430
|
transientCanvas: this.transientCanvas,
|
|
431
|
+
tileOptimize: {
|
|
432
|
+
tileFirstRender,
|
|
433
|
+
tileFirstRenderSize,
|
|
434
|
+
},
|
|
407
435
|
});
|
|
408
436
|
this.emit('afterrender');
|
|
409
437
|
|
|
@@ -452,11 +480,17 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
452
480
|
data: DataConfig,
|
|
453
481
|
type: 'replace' | 'mergeReplace' = 'mergeReplace',
|
|
454
482
|
) {
|
|
483
|
+
const { tileFirstRender, tileFirstRenderSize } =
|
|
484
|
+
this.specification.optimize || {};
|
|
455
485
|
this.hooks.datachange.emit({ data, type });
|
|
456
486
|
this.hooks.render.emit({
|
|
457
487
|
graphCore: this.dataController.graphCore,
|
|
458
488
|
theme: this.themeController.specification,
|
|
459
489
|
transientCanvas: this.transientCanvas,
|
|
490
|
+
tileOptimize: {
|
|
491
|
+
tileFirstRender,
|
|
492
|
+
tileFirstRenderSize,
|
|
493
|
+
},
|
|
460
494
|
});
|
|
461
495
|
this.emit('afterrender');
|
|
462
496
|
|
|
@@ -468,7 +502,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
468
502
|
* @returns
|
|
469
503
|
*/
|
|
470
504
|
public clear() {
|
|
471
|
-
this.
|
|
505
|
+
this.startHistoryBatch();
|
|
472
506
|
this.removeData(
|
|
473
507
|
'edge',
|
|
474
508
|
this.getAllEdgesData().map((edge) => edge.id),
|
|
@@ -481,7 +515,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
481
515
|
'combo',
|
|
482
516
|
this.getAllCombosData().map((combo) => combo.id),
|
|
483
517
|
);
|
|
484
|
-
this.
|
|
518
|
+
this.stopHistoryBatch();
|
|
485
519
|
}
|
|
486
520
|
|
|
487
521
|
public getViewportCenter(): PointLike {
|
|
@@ -492,9 +526,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
492
526
|
options: GraphTransformOptions,
|
|
493
527
|
effectTiming?: CameraAnimationOptions,
|
|
494
528
|
): Promise<void> {
|
|
529
|
+
const { tileLodSize } = this.specification.optimize || {};
|
|
495
530
|
await this.hooks.viewportchange.emitLinearAsync({
|
|
496
531
|
transform: options,
|
|
497
532
|
effectTiming,
|
|
533
|
+
tileLodSize,
|
|
498
534
|
});
|
|
499
535
|
this.emit('viewportchange', options);
|
|
500
536
|
}
|
|
@@ -779,6 +815,26 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
779
815
|
this.canvas.resize(size[0], size[1]);
|
|
780
816
|
}
|
|
781
817
|
|
|
818
|
+
public getCanvasRange(): Bounds {
|
|
819
|
+
const [width, height] = this.getSize();
|
|
820
|
+
const leftTop = this.getCanvasByViewport({ x: 0, y: 0 });
|
|
821
|
+
const rightBottom = this.getCanvasByViewport({ x: width, y: height });
|
|
822
|
+
return {
|
|
823
|
+
min: [leftTop.x, leftTop.y, leftTop.z],
|
|
824
|
+
max: [rightBottom.x, rightBottom.y, rightBottom.z],
|
|
825
|
+
center: [
|
|
826
|
+
(leftTop.x + rightBottom.x) / 2,
|
|
827
|
+
(leftTop.y + rightBottom.y) / 2,
|
|
828
|
+
(leftTop.z + rightBottom.z) / 2,
|
|
829
|
+
],
|
|
830
|
+
halfExtents: [
|
|
831
|
+
(rightBottom.x - leftTop.x) / 2,
|
|
832
|
+
(rightBottom.y - leftTop.y) / 2,
|
|
833
|
+
(rightBottom.z - leftTop.z) / 2,
|
|
834
|
+
],
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
|
|
782
838
|
/**
|
|
783
839
|
* Get the rendering coordinate according to the canvas dom (viewport) coordinate.
|
|
784
840
|
* @param Point rendering coordinate
|
|
@@ -1344,7 +1400,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1344
1400
|
* @returns
|
|
1345
1401
|
* @group Item
|
|
1346
1402
|
*/
|
|
1347
|
-
public hideItem(
|
|
1403
|
+
public hideItem(
|
|
1404
|
+
ids: ID | ID[],
|
|
1405
|
+
disableAnimate = false,
|
|
1406
|
+
keepKeyShape = false,
|
|
1407
|
+
) {
|
|
1348
1408
|
const idArr = isArray(ids) ? ids : [ids];
|
|
1349
1409
|
if (isEmpty(idArr)) return;
|
|
1350
1410
|
const changes = {
|
|
@@ -1356,6 +1416,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1356
1416
|
value: false,
|
|
1357
1417
|
graphCore: this.dataController.graphCore,
|
|
1358
1418
|
animate: !disableAnimate,
|
|
1419
|
+
keepKeyShape,
|
|
1359
1420
|
});
|
|
1360
1421
|
this.emit('afteritemvisibilitychange', {
|
|
1361
1422
|
ids,
|
|
@@ -1363,6 +1424,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1363
1424
|
animate: !disableAnimate,
|
|
1364
1425
|
action: 'updateVisibility',
|
|
1365
1426
|
apiName: 'hideItem',
|
|
1427
|
+
keepKeyShape,
|
|
1366
1428
|
changes,
|
|
1367
1429
|
});
|
|
1368
1430
|
}
|
|
@@ -1588,7 +1650,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1588
1650
|
*/
|
|
1589
1651
|
public collapseCombo(comboIds: ID | ID[]) {
|
|
1590
1652
|
const ids = isArray(comboIds) ? comboIds : [comboIds];
|
|
1591
|
-
this.
|
|
1653
|
+
this.executeWithNoStack(() => {
|
|
1592
1654
|
this.updateData(
|
|
1593
1655
|
'combo',
|
|
1594
1656
|
ids.map((id) => ({ id, data: { collapsed: true } })),
|
|
@@ -1608,7 +1670,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1608
1670
|
*/
|
|
1609
1671
|
public expandCombo(comboIds: ID | ID[]) {
|
|
1610
1672
|
const ids = isArray(comboIds) ? comboIds : [comboIds];
|
|
1611
|
-
this.
|
|
1673
|
+
this.executeWithNoStack(() => {
|
|
1612
1674
|
this.updateData(
|
|
1613
1675
|
'combo',
|
|
1614
1676
|
ids.map((id) => ({ id, data: { collapsed: false } })),
|
|
@@ -2020,30 +2082,30 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
2020
2082
|
/**
|
|
2021
2083
|
* Pause stacking operation.
|
|
2022
2084
|
*/
|
|
2023
|
-
public
|
|
2085
|
+
public pauseStack(): void {
|
|
2024
2086
|
const history = this.getHistoryPlugin();
|
|
2025
|
-
return history?.
|
|
2087
|
+
return history?.pauseStack();
|
|
2026
2088
|
}
|
|
2027
2089
|
|
|
2028
2090
|
/**
|
|
2029
2091
|
* Resume stacking operation.
|
|
2030
2092
|
*/
|
|
2031
|
-
public
|
|
2093
|
+
public resumeStack(): void {
|
|
2032
2094
|
const history = this.getHistoryPlugin();
|
|
2033
|
-
return history?.
|
|
2095
|
+
return history?.resumeStack();
|
|
2034
2096
|
}
|
|
2035
2097
|
|
|
2036
2098
|
/**
|
|
2037
2099
|
* Execute a callback without allowing any stacking operations.
|
|
2038
2100
|
* @param callback
|
|
2039
2101
|
*/
|
|
2040
|
-
public
|
|
2102
|
+
public executeWithNoStack = (callback: () => void): void => {
|
|
2041
2103
|
const history = this.getHistoryPlugin();
|
|
2042
|
-
history?.
|
|
2104
|
+
history?.pauseStack();
|
|
2043
2105
|
try {
|
|
2044
2106
|
callback();
|
|
2045
2107
|
} finally {
|
|
2046
|
-
history?.
|
|
2108
|
+
history?.resumeStack();
|
|
2047
2109
|
}
|
|
2048
2110
|
};
|
|
2049
2111
|
|
|
@@ -2109,41 +2171,41 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
2109
2171
|
}
|
|
2110
2172
|
|
|
2111
2173
|
/**
|
|
2112
|
-
* Begin a
|
|
2113
|
-
* Any operations performed between `
|
|
2174
|
+
* Begin a historyBatch operation.
|
|
2175
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
2114
2176
|
* treated as a single operation when undoing or redoing.
|
|
2115
2177
|
*/
|
|
2116
|
-
public
|
|
2178
|
+
public startHistoryBatch() {
|
|
2117
2179
|
const history = this.getHistoryPlugin();
|
|
2118
|
-
history?.
|
|
2180
|
+
history?.startHistoryBatch();
|
|
2119
2181
|
}
|
|
2120
2182
|
|
|
2121
2183
|
/**
|
|
2122
|
-
* End a
|
|
2123
|
-
* Any operations performed between `
|
|
2184
|
+
* End a historyBatch operation.
|
|
2185
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
2124
2186
|
* treated as a single operation when undoing or redoing.
|
|
2125
2187
|
*/
|
|
2126
|
-
public
|
|
2188
|
+
public stopHistoryBatch() {
|
|
2127
2189
|
const history = this.getHistoryPlugin();
|
|
2128
|
-
history?.
|
|
2190
|
+
history?.stopHistoryBatch();
|
|
2129
2191
|
}
|
|
2130
2192
|
|
|
2131
2193
|
/**
|
|
2132
2194
|
* Execute a provided function within a batched context
|
|
2133
2195
|
* All operations performed inside callback will be treated as a composite operation
|
|
2134
|
-
* more convenient way without manually invoking `
|
|
2196
|
+
* more convenient way without manually invoking `startHistoryBatch` and `stopHistoryBatch`.
|
|
2135
2197
|
* @param callback The func containing operations to be batched together.
|
|
2136
2198
|
*/
|
|
2137
|
-
public
|
|
2199
|
+
public historyBatch(callback: () => void) {
|
|
2138
2200
|
const history = this.getHistoryPlugin();
|
|
2139
|
-
history?.
|
|
2201
|
+
history?.historyBatch(callback);
|
|
2140
2202
|
}
|
|
2141
2203
|
|
|
2142
2204
|
/**
|
|
2143
2205
|
* Clear history stack
|
|
2144
2206
|
* @param {StackType} stackType undo/redo stack
|
|
2145
2207
|
*/
|
|
2146
|
-
public
|
|
2208
|
+
public cleanHistory(stackType?: StackType) {
|
|
2147
2209
|
const history = this.getHistoryPlugin();
|
|
2148
2210
|
if (!stackType) return history?.clear();
|
|
2149
2211
|
return stackType === 'undo'
|
|
@@ -2197,7 +2259,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
2197
2259
|
this.transientCanvas.destroy();
|
|
2198
2260
|
|
|
2199
2261
|
// clear history stack
|
|
2200
|
-
this.
|
|
2262
|
+
this.cleanHistory();
|
|
2201
2263
|
|
|
2202
2264
|
callback?.();
|
|
2203
2265
|
// }, 500);
|
|
@@ -118,7 +118,7 @@ export class ActivateRelations extends Behavior {
|
|
|
118
118
|
edgeIds,
|
|
119
119
|
);
|
|
120
120
|
|
|
121
|
-
graph.
|
|
121
|
+
graph.historyBatch(() => {
|
|
122
122
|
/** 节点 */
|
|
123
123
|
graph.setItemState(activeNodeIds, ACTIVE_STATE, true);
|
|
124
124
|
graph.setItemState(inactiveNodeIds, ACTIVE_STATE, false);
|
|
@@ -132,7 +132,7 @@ export class ActivateRelations extends Behavior {
|
|
|
132
132
|
}
|
|
133
133
|
public clearActiveState(e: any) {
|
|
134
134
|
const { activeState: ACTIVE_STATE } = this.options;
|
|
135
|
-
this.graph.
|
|
135
|
+
this.graph.historyBatch(() => {
|
|
136
136
|
this.graph.setItemState(this.prevNodeIds, ACTIVE_STATE, false);
|
|
137
137
|
this.graph.setItemState(this.prevEdgeIds, ACTIVE_STATE, false);
|
|
138
138
|
});
|
|
@@ -136,7 +136,7 @@ export class ClickSelect extends Behavior {
|
|
|
136
136
|
|
|
137
137
|
// Select/Unselect item.
|
|
138
138
|
if (this.options.shouldUpdate(event)) {
|
|
139
|
-
this.graph.
|
|
139
|
+
this.graph.historyBatch(() => {
|
|
140
140
|
if (!multiple) {
|
|
141
141
|
// Not multiple, clear all currently selected items
|
|
142
142
|
this.graph.setItemState(this.selectedIds, state, false);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ID, IG6GraphEvent } from 'types';
|
|
2
2
|
import { Behavior } from '../../types/behavior';
|
|
3
3
|
import { Point } from '../../types/common';
|
|
4
|
+
import { isNumber } from '@antv/util';
|
|
4
5
|
|
|
5
6
|
const VALID_TRIGGERS = ['drag', 'directionKeys'];
|
|
6
7
|
export interface DragCanvasOptions {
|
|
@@ -53,7 +54,7 @@ export interface DragCanvasOptions {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
const DEFAULT_OPTIONS: Required<DragCanvasOptions> = {
|
|
56
|
-
enableOptimize:
|
|
57
|
+
enableOptimize: undefined,
|
|
57
58
|
dragOnItems: false,
|
|
58
59
|
trigger: 'drag',
|
|
59
60
|
direction: 'both',
|
|
@@ -132,24 +133,43 @@ export class DragCanvas extends Behavior {
|
|
|
132
133
|
|
|
133
134
|
private hideShapes() {
|
|
134
135
|
const { graph } = this;
|
|
135
|
-
|
|
136
|
+
|
|
137
|
+
const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
|
|
138
|
+
graph.getSpecification().optimize || {};
|
|
139
|
+
const optimize = this.options.enableOptimize || graphBehaviorOptimize;
|
|
140
|
+
const shouldOptimize = isNumber(optimize)
|
|
141
|
+
? graph.getAllNodesData().length > optimize
|
|
142
|
+
: optimize;
|
|
143
|
+
|
|
144
|
+
if (shouldOptimize) {
|
|
136
145
|
this.hiddenEdgeIds = graph
|
|
137
146
|
.getAllEdgesData()
|
|
138
147
|
.map((edge) => edge.id)
|
|
139
148
|
.filter((id) => graph.getItemVisible(id) === true);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
149
|
+
this.hiddenNodeIds = graph
|
|
150
|
+
.getAllNodesData()
|
|
151
|
+
.map((node) => node.id)
|
|
152
|
+
.filter((id) => graph.getItemVisible(id) === true);
|
|
153
|
+
let requestId;
|
|
154
|
+
const hiddenIds = [...this.hiddenNodeIds];
|
|
155
|
+
const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
|
|
156
|
+
const sections = Array.from({ length: sectionNum }, (v, i) =>
|
|
157
|
+
hiddenIds.slice(
|
|
158
|
+
i * tileBehaviorSize,
|
|
159
|
+
i * tileBehaviorSize + tileBehaviorSize,
|
|
160
|
+
),
|
|
161
|
+
);
|
|
162
|
+
const update = () => {
|
|
163
|
+
if (!sections.length) {
|
|
164
|
+
cancelAnimationFrame(requestId);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const section = sections.shift();
|
|
168
|
+
graph.hideItem(section, false, true);
|
|
169
|
+
requestId = requestAnimationFrame(update);
|
|
170
|
+
};
|
|
171
|
+
graph.executeWithNoStack(() => {
|
|
172
|
+
requestId = requestAnimationFrame(update);
|
|
153
173
|
});
|
|
154
174
|
}
|
|
155
175
|
}
|
|
@@ -241,19 +261,37 @@ export class DragCanvas extends Behavior {
|
|
|
241
261
|
this.pointerDownAt = undefined;
|
|
242
262
|
this.dragging = false;
|
|
243
263
|
|
|
244
|
-
const { graph } = this;
|
|
245
|
-
|
|
246
|
-
graph.
|
|
247
|
-
|
|
248
|
-
|
|
264
|
+
const { graph, hiddenNodeIds, hiddenEdgeIds = [] } = this;
|
|
265
|
+
const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
|
|
266
|
+
graph.getSpecification().optimize || {};
|
|
267
|
+
const optimize = this.options.enableOptimize || graphBehaviorOptimize;
|
|
268
|
+
const shouldOptimize = isNumber(optimize)
|
|
269
|
+
? graph.getAllNodesData().length > optimize
|
|
270
|
+
: optimize;
|
|
271
|
+
|
|
272
|
+
if (shouldOptimize) {
|
|
273
|
+
if (hiddenNodeIds) {
|
|
274
|
+
let requestId;
|
|
275
|
+
const hiddenIds = [...hiddenNodeIds, ...hiddenEdgeIds];
|
|
276
|
+
const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
|
|
277
|
+
const sections = Array.from({ length: sectionNum }, (v, i) =>
|
|
278
|
+
hiddenIds.slice(
|
|
279
|
+
i * tileBehaviorSize,
|
|
280
|
+
i * tileBehaviorSize + tileBehaviorSize,
|
|
281
|
+
),
|
|
282
|
+
);
|
|
283
|
+
const update = () => {
|
|
284
|
+
if (!sections.length) {
|
|
285
|
+
cancelAnimationFrame(requestId);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
graph.showItem(sections.shift(), false);
|
|
289
|
+
requestId = requestAnimationFrame(update);
|
|
290
|
+
};
|
|
291
|
+
graph.startHistoryBatch();
|
|
292
|
+
requestId = requestAnimationFrame(update);
|
|
293
|
+
graph.stopHistoryBatch();
|
|
249
294
|
}
|
|
250
|
-
// if (this.hiddenNodeIds) {
|
|
251
|
-
// this.hiddenNodeIds.forEach((id) => {
|
|
252
|
-
// this.graph.drawTransient('node', id, { action: 'remove' });
|
|
253
|
-
// });
|
|
254
|
-
// graph.showItem(this.hiddenNodeIds, true);
|
|
255
|
-
// }
|
|
256
|
-
graph.stopBatch();
|
|
257
295
|
}
|
|
258
296
|
}
|
|
259
297
|
|
|
@@ -250,7 +250,7 @@ export class DragCombo extends Behavior {
|
|
|
250
250
|
selectedComboIds,
|
|
251
251
|
this.hiddenComboTreeRoots,
|
|
252
252
|
);
|
|
253
|
-
this.graph.
|
|
253
|
+
this.graph.executeWithNoStack(() => {
|
|
254
254
|
this.graph.hideItem(
|
|
255
255
|
this.hiddenEdges.map((edge) => edge.id),
|
|
256
256
|
true,
|
|
@@ -280,7 +280,7 @@ export class DragCombo extends Behavior {
|
|
|
280
280
|
});
|
|
281
281
|
|
|
282
282
|
// Hide original edges and nodes. They will be restored when pointerup.
|
|
283
|
-
this.graph.
|
|
283
|
+
this.graph.executeWithNoStack(() => {
|
|
284
284
|
this.graph.hideItem(selectedComboIds, true);
|
|
285
285
|
this.graph.hideItem(
|
|
286
286
|
this.hiddenEdges.map((edge) => edge.id),
|
|
@@ -429,7 +429,7 @@ export class DragCombo extends Behavior {
|
|
|
429
429
|
}
|
|
430
430
|
|
|
431
431
|
public restoreHiddenItems(positions?: Position[]) {
|
|
432
|
-
this.graph.
|
|
432
|
+
this.graph.pauseStack();
|
|
433
433
|
if (this.hiddenEdges.length) {
|
|
434
434
|
this.graph.showItem(
|
|
435
435
|
this.hiddenEdges.map((edge) => edge.id),
|
|
@@ -452,7 +452,7 @@ export class DragCombo extends Behavior {
|
|
|
452
452
|
true,
|
|
453
453
|
);
|
|
454
454
|
}
|
|
455
|
-
this.graph.
|
|
455
|
+
this.graph.resumeStack();
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
public onPointerUp(event: IG6GraphEvent) {
|
|
@@ -561,7 +561,7 @@ export class DragCombo extends Behavior {
|
|
|
561
561
|
|
|
562
562
|
public onDropCombo(event: IG6GraphEvent) {
|
|
563
563
|
const newParentId = event.itemId;
|
|
564
|
-
this.graph.
|
|
564
|
+
this.graph.startHistoryBatch();
|
|
565
565
|
this.originPositions.forEach(({ id }) => {
|
|
566
566
|
const model = this.graph.getComboData(id);
|
|
567
567
|
if (!model || model.id === newParentId) return;
|
|
@@ -570,12 +570,12 @@ export class DragCombo extends Behavior {
|
|
|
570
570
|
// event.stopPropagation();
|
|
571
571
|
this.graph.updateData('combo', { id, data: { parentId: newParentId } });
|
|
572
572
|
});
|
|
573
|
-
this.graph.
|
|
573
|
+
this.graph.stopHistoryBatch();
|
|
574
574
|
this.onPointerUp(event);
|
|
575
575
|
}
|
|
576
576
|
|
|
577
577
|
public onDropCanvas(event: IG6GraphEvent) {
|
|
578
|
-
this.graph.
|
|
578
|
+
this.graph.startHistoryBatch();
|
|
579
579
|
this.originPositions.forEach(({ id }) => {
|
|
580
580
|
const model = this.graph.getComboData(id);
|
|
581
581
|
if (!model) return;
|
|
@@ -583,7 +583,7 @@ export class DragCombo extends Behavior {
|
|
|
583
583
|
if (!parentId) return;
|
|
584
584
|
this.graph.updateData('combo', { id, data: { parentId: undefined } });
|
|
585
585
|
});
|
|
586
|
-
this.graph.
|
|
586
|
+
this.graph.stopHistoryBatch();
|
|
587
587
|
this.onPointerUp(event);
|
|
588
588
|
}
|
|
589
589
|
}
|
|
@@ -258,7 +258,7 @@ export class DragNode extends Behavior {
|
|
|
258
258
|
this.selectedNodeIds,
|
|
259
259
|
this.hiddenComboTreeItems,
|
|
260
260
|
);
|
|
261
|
-
this.graph.
|
|
261
|
+
this.graph.executeWithNoStack(() => {
|
|
262
262
|
this.graph.hideItem(
|
|
263
263
|
this.hiddenEdges.map((edge) => edge.id),
|
|
264
264
|
true,
|
|
@@ -292,7 +292,7 @@ export class DragNode extends Behavior {
|
|
|
292
292
|
});
|
|
293
293
|
|
|
294
294
|
// Hide original edges and nodes. They will be restored when pointerup.
|
|
295
|
-
this.graph.
|
|
295
|
+
this.graph.executeWithNoStack(() => {
|
|
296
296
|
this.graph.hideItem(this.selectedNodeIds, true);
|
|
297
297
|
this.graph.hideItem(
|
|
298
298
|
this.hiddenEdges.map((edge) => edge.id),
|
|
@@ -478,7 +478,7 @@ export class DragNode extends Behavior {
|
|
|
478
478
|
}
|
|
479
479
|
|
|
480
480
|
public restoreHiddenItems(positions?: Position[]) {
|
|
481
|
-
this.graph.
|
|
481
|
+
this.graph.pauseStack();
|
|
482
482
|
if (this.hiddenEdges.length) {
|
|
483
483
|
this.graph.showItem(
|
|
484
484
|
this.hiddenEdges.map((edge) => edge.id),
|
|
@@ -508,7 +508,7 @@ export class DragNode extends Behavior {
|
|
|
508
508
|
true,
|
|
509
509
|
);
|
|
510
510
|
}
|
|
511
|
-
this.graph.
|
|
511
|
+
this.graph.resumeStack();
|
|
512
512
|
}
|
|
513
513
|
|
|
514
514
|
public clearState() {
|
|
@@ -608,7 +608,7 @@ export class DragNode extends Behavior {
|
|
|
608
608
|
? this.graph.getNodeData(dropId).data.parentId
|
|
609
609
|
: dropId;
|
|
610
610
|
|
|
611
|
-
this.graph.
|
|
611
|
+
this.graph.startHistoryBatch();
|
|
612
612
|
this.originPositions.forEach(({ id }) => {
|
|
613
613
|
const model = this.graph.getNodeData(id);
|
|
614
614
|
if (!model) return;
|
|
@@ -621,13 +621,13 @@ export class DragNode extends Behavior {
|
|
|
621
621
|
this.graph.updateData('node', { id, data: { parentId: newParentId } });
|
|
622
622
|
});
|
|
623
623
|
this.onPointerUp(event);
|
|
624
|
-
this.graph.
|
|
624
|
+
this.graph.stopHistoryBatch();
|
|
625
625
|
}
|
|
626
626
|
|
|
627
627
|
public onDropCombo(event: IG6GraphEvent) {
|
|
628
628
|
event.stopPropagation();
|
|
629
629
|
const newParentId = event.itemId;
|
|
630
|
-
this.graph.
|
|
630
|
+
this.graph.startHistoryBatch();
|
|
631
631
|
this.onPointerUp(event);
|
|
632
632
|
this.originPositions.forEach(({ id }) => {
|
|
633
633
|
const model = this.graph.getNodeData(id);
|
|
@@ -637,7 +637,7 @@ export class DragNode extends Behavior {
|
|
|
637
637
|
this.graph.updateData('node', { id, data: { parentId: newParentId } });
|
|
638
638
|
});
|
|
639
639
|
this.clearState();
|
|
640
|
-
this.graph.
|
|
640
|
+
this.graph.stopHistoryBatch();
|
|
641
641
|
}
|
|
642
642
|
|
|
643
643
|
public onDropCanvas(event: IG6GraphEvent) {
|
|
@@ -657,7 +657,7 @@ export class DragNode extends Behavior {
|
|
|
657
657
|
const parentId = this.graph.getNodeData(dropId)
|
|
658
658
|
? this.graph.getNodeData(dropId).data.parentId
|
|
659
659
|
: dropId;
|
|
660
|
-
this.graph.
|
|
660
|
+
this.graph.startHistoryBatch();
|
|
661
661
|
this.onPointerUp(event);
|
|
662
662
|
const nodeToUpdate = [];
|
|
663
663
|
this.originPositions.forEach(({ id }) => {
|
|
@@ -671,6 +671,6 @@ export class DragNode extends Behavior {
|
|
|
671
671
|
});
|
|
672
672
|
if (nodeToUpdate.length) this.graph.updateData('node', nodeToUpdate);
|
|
673
673
|
this.clearState();
|
|
674
|
-
this.graph.
|
|
674
|
+
this.graph.stopHistoryBatch();
|
|
675
675
|
}
|
|
676
676
|
}
|