@antv/g6 5.0.0-beta.4 → 5.0.0-beta.6
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 +15 -1
- package/esm/index.js +1 -1
- package/esm/item/combo.d.ts +1 -1
- package/esm/item/combo.js +16 -9
- package/esm/item/combo.js.map +1 -1
- package/esm/item/edge.d.ts +2 -1
- package/esm/item/edge.js +18 -8
- 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 +2 -1
- package/esm/item/node.js +19 -10
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/item.d.ts +1 -0
- package/esm/runtime/controller/item.js +271 -151
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.d.ts +98 -18
- package/esm/runtime/graph.js +427 -75
- 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/brush-select.js +1 -2
- package/esm/stdlib/behavior/brush-select.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/create-edge.d.ts +57 -0
- package/esm/stdlib/behavior/create-edge.js +206 -0
- package/esm/stdlib/behavior/create-edge.js.map +1 -0
- package/esm/stdlib/behavior/drag-canvas.d.ts +1 -1
- package/esm/stdlib/behavior/drag-canvas.js +51 -28
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
- package/esm/stdlib/behavior/drag-combo.js +43 -32
- package/esm/stdlib/behavior/drag-combo.js.map +1 -1
- package/esm/stdlib/behavior/drag-node.d.ts +3 -3
- package/esm/stdlib/behavior/drag-node.js +76 -63
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/index.d.ts +2 -0
- package/esm/stdlib/behavior/index.js +2 -0
- package/esm/stdlib/behavior/index.js.map +1 -1
- package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
- package/esm/stdlib/behavior/lasso-select.js +1 -2
- package/esm/stdlib/behavior/lasso-select.js.map +1 -1
- package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
- package/esm/stdlib/behavior/scroll-canvas.js +266 -0
- package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
- package/esm/stdlib/behavior/zoom-canvas.d.ts +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 +6 -0
- package/esm/stdlib/index.js +15 -9
- 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/hull/hullComponent.d.ts +1 -1
- package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
- package/esm/stdlib/plugin/hull/hullComponent.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/minimap/index.d.ts +5 -1
- package/esm/stdlib/plugin/minimap/index.js +109 -8
- package/esm/stdlib/plugin/minimap/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 +45 -19
- package/esm/types/hook.d.ts +22 -2
- package/esm/types/spec.d.ts +19 -3
- 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/item.d.ts +16 -1
- package/esm/util/item.js +31 -8
- package/esm/util/item.js.map +1 -1
- package/esm/util/shape.js +2 -2
- package/esm/util/shape.js.map +1 -1
- package/esm/util/warn.d.ts +14 -0
- package/esm/util/warn.js +4 -0
- package/esm/util/warn.js.map +1 -0
- package/lib/index.d.ts +15 -1
- package/lib/index.js +1 -1
- package/lib/item/combo.d.ts +1 -1
- package/lib/item/combo.js +16 -9
- package/lib/item/combo.js.map +1 -1
- package/lib/item/edge.d.ts +2 -1
- package/lib/item/edge.js +18 -8
- 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 +2 -1
- package/lib/item/node.js +19 -10
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/item.d.ts +1 -0
- package/lib/runtime/controller/item.js +270 -150
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.d.ts +98 -18
- package/lib/runtime/graph.js +427 -75
- 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/brush-select.js +1 -2
- package/lib/stdlib/behavior/brush-select.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/create-edge.d.ts +57 -0
- package/lib/stdlib/behavior/create-edge.js +210 -0
- package/lib/stdlib/behavior/create-edge.js.map +1 -0
- package/lib/stdlib/behavior/drag-canvas.d.ts +1 -1
- package/lib/stdlib/behavior/drag-canvas.js +51 -28
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
- package/lib/stdlib/behavior/drag-combo.js +43 -32
- package/lib/stdlib/behavior/drag-combo.js.map +1 -1
- package/lib/stdlib/behavior/drag-node.d.ts +3 -3
- package/lib/stdlib/behavior/drag-node.js +76 -63
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/index.d.ts +2 -0
- package/lib/stdlib/behavior/index.js +2 -0
- package/lib/stdlib/behavior/index.js.map +1 -1
- package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
- package/lib/stdlib/behavior/lasso-select.js +1 -2
- package/lib/stdlib/behavior/lasso-select.js.map +1 -1
- package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
- package/lib/stdlib/behavior/scroll-canvas.js +270 -0
- package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
- package/lib/stdlib/behavior/zoom-canvas.d.ts +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 +6 -0
- package/lib/stdlib/index.js +15 -9
- 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/hull/hullComponent.d.ts +1 -1
- package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
- package/lib/stdlib/plugin/hull/hullComponent.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/minimap/index.d.ts +5 -1
- package/lib/stdlib/plugin/minimap/index.js +109 -8
- package/lib/stdlib/plugin/minimap/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 +45 -19
- package/lib/types/hook.d.ts +22 -2
- package/lib/types/spec.d.ts +19 -3
- 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/item.d.ts +16 -1
- package/lib/util/item.js +33 -9
- package/lib/util/item.js.map +1 -1
- package/lib/util/shape.js +2 -2
- package/lib/util/shape.js.map +1 -1
- package/lib/util/warn.d.ts +14 -0
- package/lib/util/warn.js +8 -0
- package/lib/util/warn.js.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/item/combo.ts +14 -9
- package/src/item/edge.ts +17 -8
- package/src/item/item.ts +11 -6
- package/src/item/node.ts +24 -16
- package/src/runtime/controller/item.ts +240 -72
- package/src/runtime/graph.ts +536 -80
- package/src/stdlib/behavior/activate-relations.ts +2 -2
- package/src/stdlib/behavior/brush-select.ts +4 -2
- package/src/stdlib/behavior/click-select.ts +1 -1
- package/src/stdlib/behavior/create-edge.ts +295 -0
- package/src/stdlib/behavior/drag-canvas.ts +67 -29
- package/src/stdlib/behavior/drag-combo.ts +10 -10
- package/src/stdlib/behavior/drag-node.ts +18 -18
- package/src/stdlib/behavior/index.ts +2 -0
- package/src/stdlib/behavior/lasso-select.ts +5 -3
- package/src/stdlib/behavior/scroll-canvas.ts +348 -0
- package/src/stdlib/behavior/zoom-canvas.ts +61 -25
- package/src/stdlib/index.ts +16 -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/hull/hullComponent.ts +8 -5
- package/src/stdlib/plugin/index.ts +1 -0
- package/src/stdlib/plugin/minimap/index.ts +113 -9
- package/src/stdlib/plugin/snapline/index.ts +1277 -0
- package/src/stdlib/plugin/types.ts +1 -0
- package/src/types/graph.ts +53 -22
- package/src/types/hook.ts +22 -2
- package/src/types/spec.ts +22 -3
- package/src/util/bbox.ts +38 -1
- package/src/util/item.ts +65 -28
- package/src/util/shape.ts +2 -2
- package/src/util/warn.ts +20 -0
package/src/runtime/graph.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import EventEmitter from '@antv/event-emitter';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AABB,
|
|
4
|
+
Canvas,
|
|
5
|
+
DataURLType,
|
|
6
|
+
DisplayObject,
|
|
7
|
+
PointLike,
|
|
8
|
+
Rect,
|
|
9
|
+
Cursor,
|
|
10
|
+
} from '@antv/g';
|
|
3
11
|
import { GraphChange, ID } from '@antv/graphlib';
|
|
4
12
|
import {
|
|
5
13
|
clone,
|
|
@@ -13,6 +21,7 @@ import {
|
|
|
13
21
|
isString,
|
|
14
22
|
map,
|
|
15
23
|
} from '@antv/util';
|
|
24
|
+
import { createDom } from '@antv/dom-util';
|
|
16
25
|
import { History } from '../stdlib/plugin/history';
|
|
17
26
|
import { Command } from '../stdlib/plugin/history/command';
|
|
18
27
|
import type {
|
|
@@ -26,7 +35,7 @@ import type {
|
|
|
26
35
|
import type { CameraAnimationOptions } from '../types/animate';
|
|
27
36
|
import type { BehaviorOptionsOf, BehaviorRegistry } from '../types/behavior';
|
|
28
37
|
import type { ComboDisplayModel, ComboModel } from '../types/combo';
|
|
29
|
-
import type { Padding, Point } from '../types/common';
|
|
38
|
+
import type { Bounds, Padding, Point } from '../types/common';
|
|
30
39
|
import type { DataChangeType, DataConfig, GraphCore } from '../types/data';
|
|
31
40
|
import type { EdgeDisplayModel, EdgeModel, EdgeModelData } from '../types/edge';
|
|
32
41
|
import type { StackType } from '../types/history';
|
|
@@ -48,6 +57,7 @@ import { FitViewRules, GraphTransformOptions } from '../types/view';
|
|
|
48
57
|
import { changeRenderer, createCanvas } from '../util/canvas';
|
|
49
58
|
import { formatPadding } from '../util/shape';
|
|
50
59
|
import { Plugin as PluginBase } from '../types/plugin';
|
|
60
|
+
import { ComboMapper, EdgeMapper, NodeMapper } from '../types/spec';
|
|
51
61
|
import {
|
|
52
62
|
DataController,
|
|
53
63
|
ExtensionController,
|
|
@@ -101,7 +111,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
101
111
|
constructor(spec: Specification<B, T>) {
|
|
102
112
|
super();
|
|
103
113
|
|
|
104
|
-
this.specification = Object.assign(
|
|
114
|
+
this.specification = Object.assign(
|
|
115
|
+
{},
|
|
116
|
+
this.defaultSpecification,
|
|
117
|
+
this.formatSpecification(spec),
|
|
118
|
+
);
|
|
105
119
|
this.initHooks();
|
|
106
120
|
this.initCanvas();
|
|
107
121
|
this.initControllers();
|
|
@@ -345,7 +359,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
345
359
|
main: Canvas;
|
|
346
360
|
transient: Canvas;
|
|
347
361
|
};
|
|
348
|
-
}>({ name: '
|
|
362
|
+
}>({ name: 'themechange' }),
|
|
363
|
+
mapperchange: new Hook<{
|
|
364
|
+
type: ITEM_TYPE;
|
|
365
|
+
mapper: NodeMapper | EdgeMapper | ComboMapper;
|
|
366
|
+
}>({ name: 'mapperchange' }),
|
|
349
367
|
treecollapseexpand: new Hook<{
|
|
350
368
|
ids: ID[];
|
|
351
369
|
animate: boolean;
|
|
@@ -356,11 +374,29 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
356
374
|
};
|
|
357
375
|
}
|
|
358
376
|
|
|
377
|
+
private formatSpecification(spec: Specification<B, T>) {
|
|
378
|
+
return {
|
|
379
|
+
...spec,
|
|
380
|
+
optimize: {
|
|
381
|
+
tileBehavior: 2000,
|
|
382
|
+
tileBehaviorSize: 1000,
|
|
383
|
+
tileFirstRender: 10000,
|
|
384
|
+
tileFirstRenderSize: 1000,
|
|
385
|
+
...spec.optimize,
|
|
386
|
+
},
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
|
|
359
390
|
/**
|
|
360
391
|
* Update the specs(configurations).
|
|
361
392
|
*/
|
|
362
393
|
public updateSpecification(spec: Specification<B, T>): Specification<B, T> {
|
|
363
|
-
|
|
394
|
+
const newSpec = Object.assign(
|
|
395
|
+
this.specification,
|
|
396
|
+
this.formatSpecification(spec),
|
|
397
|
+
);
|
|
398
|
+
// TODO: update something
|
|
399
|
+
return newSpec;
|
|
364
400
|
}
|
|
365
401
|
/**
|
|
366
402
|
* Update the theme specs (configurations).
|
|
@@ -382,6 +418,32 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
382
418
|
});
|
|
383
419
|
}
|
|
384
420
|
|
|
421
|
+
/**
|
|
422
|
+
* Update the item display mapper for a specific item type.
|
|
423
|
+
* @param {ITEM_TYPE} type - The type of item (node, edge, or combo).
|
|
424
|
+
* @param {NodeMapper | EdgeMapper | ComboMapper} mapper - The mapper to be updated.
|
|
425
|
+
* */
|
|
426
|
+
public updateMapper(
|
|
427
|
+
type: ITEM_TYPE,
|
|
428
|
+
mapper: NodeMapper | EdgeMapper | ComboMapper,
|
|
429
|
+
) {
|
|
430
|
+
switch (type) {
|
|
431
|
+
case 'node':
|
|
432
|
+
this.specification.node = mapper as NodeMapper;
|
|
433
|
+
break;
|
|
434
|
+
case 'edge':
|
|
435
|
+
this.specification.edge = mapper as EdgeMapper;
|
|
436
|
+
break;
|
|
437
|
+
case 'combo':
|
|
438
|
+
this.specification.combo = mapper as ComboMapper;
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
this.hooks.mapperchange.emit({
|
|
442
|
+
type,
|
|
443
|
+
mapper,
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
|
|
385
447
|
/**
|
|
386
448
|
* Get the copy of specs(configurations).
|
|
387
449
|
* @returns graph specs
|
|
@@ -398,12 +460,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
398
460
|
* @group Data
|
|
399
461
|
*/
|
|
400
462
|
public async read(data: DataConfig) {
|
|
463
|
+
const { tileFirstRender, tileFirstRenderSize } =
|
|
464
|
+
this.specification.optimize || {};
|
|
401
465
|
this.hooks.datachange.emit({ data, type: 'replace' });
|
|
402
466
|
const emitRender = async () => {
|
|
403
|
-
this.hooks.render.
|
|
467
|
+
await this.hooks.render.emitLinearAsync({
|
|
404
468
|
graphCore: this.dataController.graphCore,
|
|
405
469
|
theme: this.themeController.specification,
|
|
406
470
|
transientCanvas: this.transientCanvas,
|
|
471
|
+
tileOptimize: {
|
|
472
|
+
tileFirstRender,
|
|
473
|
+
tileFirstRenderSize,
|
|
474
|
+
},
|
|
407
475
|
});
|
|
408
476
|
this.emit('afterrender');
|
|
409
477
|
|
|
@@ -452,11 +520,17 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
452
520
|
data: DataConfig,
|
|
453
521
|
type: 'replace' | 'mergeReplace' = 'mergeReplace',
|
|
454
522
|
) {
|
|
523
|
+
const { tileFirstRender, tileFirstRenderSize } =
|
|
524
|
+
this.specification.optimize || {};
|
|
455
525
|
this.hooks.datachange.emit({ data, type });
|
|
456
526
|
this.hooks.render.emit({
|
|
457
527
|
graphCore: this.dataController.graphCore,
|
|
458
528
|
theme: this.themeController.specification,
|
|
459
529
|
transientCanvas: this.transientCanvas,
|
|
530
|
+
tileOptimize: {
|
|
531
|
+
tileFirstRender,
|
|
532
|
+
tileFirstRenderSize,
|
|
533
|
+
},
|
|
460
534
|
});
|
|
461
535
|
this.emit('afterrender');
|
|
462
536
|
|
|
@@ -468,7 +542,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
468
542
|
* @returns
|
|
469
543
|
*/
|
|
470
544
|
public clear() {
|
|
471
|
-
this.
|
|
545
|
+
this.startHistoryBatch();
|
|
472
546
|
this.removeData(
|
|
473
547
|
'edge',
|
|
474
548
|
this.getAllEdgesData().map((edge) => edge.id),
|
|
@@ -481,7 +555,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
481
555
|
'combo',
|
|
482
556
|
this.getAllCombosData().map((combo) => combo.id),
|
|
483
557
|
);
|
|
484
|
-
this.
|
|
558
|
+
this.stopHistoryBatch();
|
|
485
559
|
}
|
|
486
560
|
|
|
487
561
|
public getViewportCenter(): PointLike {
|
|
@@ -492,9 +566,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
492
566
|
options: GraphTransformOptions,
|
|
493
567
|
effectTiming?: CameraAnimationOptions,
|
|
494
568
|
): Promise<void> {
|
|
569
|
+
const { tileLodSize } = this.specification.optimize || {};
|
|
495
570
|
await this.hooks.viewportchange.emitLinearAsync({
|
|
496
571
|
transform: options,
|
|
497
572
|
effectTiming,
|
|
573
|
+
tileLodSize,
|
|
498
574
|
});
|
|
499
575
|
this.emit('viewportchange', options);
|
|
500
576
|
}
|
|
@@ -779,6 +855,26 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
779
855
|
this.canvas.resize(size[0], size[1]);
|
|
780
856
|
}
|
|
781
857
|
|
|
858
|
+
public getCanvasRange(): Bounds {
|
|
859
|
+
const [width, height] = this.getSize();
|
|
860
|
+
const leftTop = this.getCanvasByViewport({ x: 0, y: 0 });
|
|
861
|
+
const rightBottom = this.getCanvasByViewport({ x: width, y: height });
|
|
862
|
+
return {
|
|
863
|
+
min: [leftTop.x, leftTop.y, leftTop.z],
|
|
864
|
+
max: [rightBottom.x, rightBottom.y, rightBottom.z],
|
|
865
|
+
center: [
|
|
866
|
+
(leftTop.x + rightBottom.x) / 2,
|
|
867
|
+
(leftTop.y + rightBottom.y) / 2,
|
|
868
|
+
(leftTop.z + rightBottom.z) / 2,
|
|
869
|
+
],
|
|
870
|
+
halfExtents: [
|
|
871
|
+
(rightBottom.x - leftTop.x) / 2,
|
|
872
|
+
(rightBottom.y - leftTop.y) / 2,
|
|
873
|
+
(rightBottom.z - leftTop.z) / 2,
|
|
874
|
+
],
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
|
|
782
878
|
/**
|
|
783
879
|
* Get the rendering coordinate according to the canvas dom (viewport) coordinate.
|
|
784
880
|
* @param Point rendering coordinate
|
|
@@ -987,22 +1083,25 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
987
1083
|
|
|
988
1084
|
const { graphCore } = this.dataController;
|
|
989
1085
|
const { specification } = this.themeController;
|
|
1086
|
+
// debugger;
|
|
990
1087
|
graphCore.once('changed', (event) => {
|
|
991
1088
|
if (!event.changes.length) return;
|
|
992
1089
|
const changes = event.changes;
|
|
993
|
-
|
|
994
|
-
type: itemType,
|
|
995
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
996
|
-
graphCore,
|
|
997
|
-
theme: specification,
|
|
998
|
-
});
|
|
999
|
-
this.emit('afteritemchange', {
|
|
1090
|
+
const timingParameters = {
|
|
1000
1091
|
type: itemType,
|
|
1001
1092
|
action: 'add',
|
|
1002
1093
|
models,
|
|
1003
1094
|
apiName: 'addData',
|
|
1004
1095
|
changes,
|
|
1096
|
+
};
|
|
1097
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1098
|
+
this.hooks.itemchange.emit({
|
|
1099
|
+
type: itemType,
|
|
1100
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
1101
|
+
graphCore,
|
|
1102
|
+
theme: specification,
|
|
1005
1103
|
});
|
|
1104
|
+
this.emit('afteritemchange', timingParameters);
|
|
1006
1105
|
});
|
|
1007
1106
|
|
|
1008
1107
|
const modelArr = isArray(models) ? models : [models];
|
|
@@ -1035,19 +1134,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1035
1134
|
graphCore.once('changed', (event) => {
|
|
1036
1135
|
if (!event.changes.length) return;
|
|
1037
1136
|
const changes = event.changes;
|
|
1038
|
-
|
|
1039
|
-
type: itemType,
|
|
1040
|
-
changes: event.changes,
|
|
1041
|
-
graphCore,
|
|
1042
|
-
theme: specification,
|
|
1043
|
-
});
|
|
1044
|
-
this.emit('afteritemchange', {
|
|
1137
|
+
const timingParameters = {
|
|
1045
1138
|
type: itemType,
|
|
1046
1139
|
action: 'remove',
|
|
1047
1140
|
ids: idArr,
|
|
1048
1141
|
apiName: 'removeData',
|
|
1049
1142
|
changes,
|
|
1143
|
+
};
|
|
1144
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1145
|
+
this.hooks.itemchange.emit({
|
|
1146
|
+
type: itemType,
|
|
1147
|
+
changes: event.changes,
|
|
1148
|
+
graphCore,
|
|
1149
|
+
theme: specification,
|
|
1050
1150
|
});
|
|
1151
|
+
this.emit('afteritemchange', timingParameters);
|
|
1051
1152
|
});
|
|
1052
1153
|
this.hooks.datachange.emit({
|
|
1053
1154
|
data,
|
|
@@ -1140,19 +1241,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1140
1241
|
const { specification } = this.themeController;
|
|
1141
1242
|
graphCore.once('changed', (event) => {
|
|
1142
1243
|
const changes = this.extendChanges(clone(event.changes));
|
|
1143
|
-
|
|
1144
|
-
type: itemType,
|
|
1145
|
-
changes: event.changes,
|
|
1146
|
-
graphCore,
|
|
1147
|
-
theme: specification,
|
|
1148
|
-
});
|
|
1149
|
-
this.emit('afteritemchange', {
|
|
1244
|
+
const timingParameters = {
|
|
1150
1245
|
type: itemType,
|
|
1151
1246
|
action: 'update',
|
|
1152
1247
|
models,
|
|
1153
1248
|
apiName: 'updateData',
|
|
1154
1249
|
changes,
|
|
1250
|
+
};
|
|
1251
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1252
|
+
this.hooks.itemchange.emit({
|
|
1253
|
+
type: itemType,
|
|
1254
|
+
changes: event.changes,
|
|
1255
|
+
graphCore,
|
|
1256
|
+
theme: specification,
|
|
1155
1257
|
});
|
|
1258
|
+
this.emit('afteritemchange', timingParameters);
|
|
1156
1259
|
});
|
|
1157
1260
|
|
|
1158
1261
|
this.hooks.datachange.emit({
|
|
@@ -1261,6 +1364,15 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1261
1364
|
const changes = event.changes.filter(
|
|
1262
1365
|
(change) => !isEqual(change.newValue, change.oldValue),
|
|
1263
1366
|
);
|
|
1367
|
+
const timingParameters = {
|
|
1368
|
+
type,
|
|
1369
|
+
action: 'updatePosition',
|
|
1370
|
+
upsertAncestors,
|
|
1371
|
+
models,
|
|
1372
|
+
apiName: 'updatePosition',
|
|
1373
|
+
changes,
|
|
1374
|
+
};
|
|
1375
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1264
1376
|
this.hooks.itemchange.emit({
|
|
1265
1377
|
type,
|
|
1266
1378
|
changes: event.changes,
|
|
@@ -1271,14 +1383,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1271
1383
|
animate: !disableAnimate,
|
|
1272
1384
|
callback,
|
|
1273
1385
|
});
|
|
1274
|
-
this.emit('afteritemchange',
|
|
1275
|
-
type,
|
|
1276
|
-
action: 'updatePosition',
|
|
1277
|
-
upsertAncestors,
|
|
1278
|
-
models,
|
|
1279
|
-
apiName: 'updatePosition',
|
|
1280
|
-
changes,
|
|
1281
|
-
});
|
|
1386
|
+
this.emit('afteritemchange', timingParameters);
|
|
1282
1387
|
});
|
|
1283
1388
|
|
|
1284
1389
|
this.hooks.datachange.emit({
|
|
@@ -1344,7 +1449,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1344
1449
|
* @returns
|
|
1345
1450
|
* @group Item
|
|
1346
1451
|
*/
|
|
1347
|
-
public hideItem(
|
|
1452
|
+
public hideItem(
|
|
1453
|
+
ids: ID | ID[],
|
|
1454
|
+
disableAnimate = false,
|
|
1455
|
+
keepKeyShape = false,
|
|
1456
|
+
) {
|
|
1348
1457
|
const idArr = isArray(ids) ? ids : [ids];
|
|
1349
1458
|
if (isEmpty(idArr)) return;
|
|
1350
1459
|
const changes = {
|
|
@@ -1356,6 +1465,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1356
1465
|
value: false,
|
|
1357
1466
|
graphCore: this.dataController.graphCore,
|
|
1358
1467
|
animate: !disableAnimate,
|
|
1468
|
+
keepKeyShape,
|
|
1359
1469
|
});
|
|
1360
1470
|
this.emit('afteritemvisibilitychange', {
|
|
1361
1471
|
ids,
|
|
@@ -1363,6 +1473,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1363
1473
|
animate: !disableAnimate,
|
|
1364
1474
|
action: 'updateVisibility',
|
|
1365
1475
|
apiName: 'hideItem',
|
|
1476
|
+
keepKeyShape,
|
|
1366
1477
|
changes,
|
|
1367
1478
|
});
|
|
1368
1479
|
}
|
|
@@ -1547,19 +1658,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1547
1658
|
graphCore.once('changed', (event) => {
|
|
1548
1659
|
if (!event.changes.length) return;
|
|
1549
1660
|
const changes = event.changes;
|
|
1550
|
-
|
|
1551
|
-
type: 'combo',
|
|
1552
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
1553
|
-
graphCore,
|
|
1554
|
-
theme: specification,
|
|
1555
|
-
});
|
|
1556
|
-
this.emit('afteritemchange', {
|
|
1661
|
+
const timingParameters = {
|
|
1557
1662
|
type: 'combo',
|
|
1558
1663
|
action: 'add',
|
|
1559
1664
|
models: [model],
|
|
1560
1665
|
apiName: 'addCombo',
|
|
1561
1666
|
changes,
|
|
1667
|
+
};
|
|
1668
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1669
|
+
this.hooks.itemchange.emit({
|
|
1670
|
+
type: 'combo',
|
|
1671
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
1672
|
+
graphCore,
|
|
1673
|
+
theme: specification,
|
|
1562
1674
|
});
|
|
1675
|
+
this.emit('afteritemchange', timingParameters);
|
|
1563
1676
|
});
|
|
1564
1677
|
|
|
1565
1678
|
const data = {
|
|
@@ -1588,7 +1701,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1588
1701
|
*/
|
|
1589
1702
|
public collapseCombo(comboIds: ID | ID[]) {
|
|
1590
1703
|
const ids = isArray(comboIds) ? comboIds : [comboIds];
|
|
1591
|
-
this.
|
|
1704
|
+
this.executeWithNoStack(() => {
|
|
1592
1705
|
this.updateData(
|
|
1593
1706
|
'combo',
|
|
1594
1707
|
ids.map((id) => ({ id, data: { collapsed: true } })),
|
|
@@ -1608,7 +1721,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1608
1721
|
*/
|
|
1609
1722
|
public expandCombo(comboIds: ID | ID[]) {
|
|
1610
1723
|
const ids = isArray(comboIds) ? comboIds : [comboIds];
|
|
1611
|
-
this.
|
|
1724
|
+
this.executeWithNoStack(() => {
|
|
1612
1725
|
this.updateData(
|
|
1613
1726
|
'combo',
|
|
1614
1727
|
ids.map((id) => ({ id, data: { collapsed: false } })),
|
|
@@ -1645,16 +1758,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1645
1758
|
graphCore.once('changed', (event) => {
|
|
1646
1759
|
if (!event.changes.length) return;
|
|
1647
1760
|
const changes = this.extendChanges(clone(event.changes));
|
|
1648
|
-
|
|
1649
|
-
type: 'combo',
|
|
1650
|
-
changes: event.changes,
|
|
1651
|
-
graphCore,
|
|
1652
|
-
theme: specification,
|
|
1653
|
-
upsertAncestors,
|
|
1654
|
-
action: 'updatePosition',
|
|
1655
|
-
callback,
|
|
1656
|
-
});
|
|
1657
|
-
this.emit('afteritemchange', {
|
|
1761
|
+
const timingParameters = {
|
|
1658
1762
|
type: 'combo',
|
|
1659
1763
|
ids: idArr,
|
|
1660
1764
|
dx,
|
|
@@ -1663,7 +1767,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1663
1767
|
upsertAncestors,
|
|
1664
1768
|
apiName: 'moveCombo',
|
|
1665
1769
|
changes,
|
|
1770
|
+
};
|
|
1771
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1772
|
+
this.hooks.itemchange.emit({
|
|
1773
|
+
type: 'combo',
|
|
1774
|
+
changes: event.changes,
|
|
1775
|
+
graphCore,
|
|
1776
|
+
theme: specification,
|
|
1777
|
+
upsertAncestors,
|
|
1778
|
+
action: 'updatePosition',
|
|
1779
|
+
callback,
|
|
1666
1780
|
});
|
|
1781
|
+
this.emit('afteritemchange', timingParameters);
|
|
1667
1782
|
});
|
|
1668
1783
|
|
|
1669
1784
|
this.hooks.datachange.emit({
|
|
@@ -1762,6 +1877,15 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1762
1877
|
return this.interactionController.getMode();
|
|
1763
1878
|
}
|
|
1764
1879
|
|
|
1880
|
+
/**
|
|
1881
|
+
* Set the cursor. But the cursor in item's style has higher priority.
|
|
1882
|
+
* @param cursor
|
|
1883
|
+
*/
|
|
1884
|
+
public setCursor(cursor: Cursor) {
|
|
1885
|
+
this.canvas.setCursor(cursor);
|
|
1886
|
+
this.transientCanvas.setCursor(cursor);
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1765
1889
|
/**
|
|
1766
1890
|
* Add behavior(s) to mode(s).
|
|
1767
1891
|
* @param behaviors behavior names or configs
|
|
@@ -1979,9 +2103,19 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1979
2103
|
type: ITEM_TYPE | SHAPE_TYPE,
|
|
1980
2104
|
id: ID,
|
|
1981
2105
|
config: {
|
|
1982
|
-
action
|
|
1983
|
-
|
|
1984
|
-
|
|
2106
|
+
action?: 'remove' | 'add' | 'update' | undefined;
|
|
2107
|
+
/** Data to be merged into the transient item. */
|
|
2108
|
+
data?: Record<string, any>;
|
|
2109
|
+
/** Style to be merged into the transient shape. */
|
|
2110
|
+
style?: ShapeStyle;
|
|
2111
|
+
/** For type: 'edge' */
|
|
2112
|
+
drawSource?: boolean;
|
|
2113
|
+
/** For type: 'edge' */
|
|
2114
|
+
drawTarget?: boolean;
|
|
2115
|
+
/** Only shape with id in shapeIds will be cloned while type is ITEM_TYPE. If shapeIds is not assigned, the whole item will be cloned. */
|
|
2116
|
+
shapeIds?: string[];
|
|
2117
|
+
/** Whether show the shapes in shapeIds. True by default. */
|
|
2118
|
+
visible?: boolean;
|
|
1985
2119
|
upsertAncestors?: boolean;
|
|
1986
2120
|
},
|
|
1987
2121
|
canvas?: Canvas,
|
|
@@ -1996,6 +2130,328 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1996
2130
|
return this.itemController.getTransient(String(id));
|
|
1997
2131
|
}
|
|
1998
2132
|
|
|
2133
|
+
// ===== download operations =====
|
|
2134
|
+
/**
|
|
2135
|
+
* Asynchronously generates a Data URL representation of the canvas content, including
|
|
2136
|
+
* background, main content, and transient canvas.
|
|
2137
|
+
* @param The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
2138
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
2139
|
+
*/
|
|
2140
|
+
public async toDataURL(type?: DataURLType): Promise<string> {
|
|
2141
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
2142
|
+
const canvas = this.canvas;
|
|
2143
|
+
const transientCanvas = this.transientCanvas;
|
|
2144
|
+
const rendererType = this.rendererType;
|
|
2145
|
+
|
|
2146
|
+
const pixelRatio =
|
|
2147
|
+
typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
2148
|
+
const width = this.getSize()[0];
|
|
2149
|
+
const height = this.getSize()[1];
|
|
2150
|
+
|
|
2151
|
+
const vContainerDOM: HTMLDivElement = createDom(
|
|
2152
|
+
'<div id="virtual-image"></div>',
|
|
2153
|
+
);
|
|
2154
|
+
const vCanvas = createCanvas(
|
|
2155
|
+
rendererType,
|
|
2156
|
+
vContainerDOM,
|
|
2157
|
+
width,
|
|
2158
|
+
height,
|
|
2159
|
+
pixelRatio,
|
|
2160
|
+
);
|
|
2161
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
2162
|
+
let bgRect;
|
|
2163
|
+
if (rendererType !== 'svg') {
|
|
2164
|
+
bgRect = new Rect({
|
|
2165
|
+
style: {
|
|
2166
|
+
x: 0,
|
|
2167
|
+
y: 0,
|
|
2168
|
+
z: -1,
|
|
2169
|
+
width: vCanvasContextService.getDomElement().width,
|
|
2170
|
+
height: vCanvasContextService.getDomElement().height,
|
|
2171
|
+
//@ts-ignore
|
|
2172
|
+
fill: backgroundCanvas.getContextService().getDomElement().style[
|
|
2173
|
+
'background-color'
|
|
2174
|
+
],
|
|
2175
|
+
},
|
|
2176
|
+
});
|
|
2177
|
+
vCanvas.appendChild(bgRect);
|
|
2178
|
+
}
|
|
2179
|
+
const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
|
|
2180
|
+
const clonedGroup = canvas.getRoot().cloneNode(true);
|
|
2181
|
+
const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
|
|
2182
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
2183
|
+
vCanvas.appendChild(clonedGroup);
|
|
2184
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
2185
|
+
vCanvas.render();
|
|
2186
|
+
|
|
2187
|
+
if (!type) type = 'image/png';
|
|
2188
|
+
let dataURL = '';
|
|
2189
|
+
await vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
2190
|
+
dataURL = url;
|
|
2191
|
+
});
|
|
2192
|
+
return dataURL;
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
/**
|
|
2196
|
+
* Asynchronously generates a Data URL representation of the full canvas content,
|
|
2197
|
+
* including background, main content, and transient canvas, with optional padding.
|
|
2198
|
+
* @param type The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
2199
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
2200
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
2201
|
+
*/
|
|
2202
|
+
public async toFullDataURL(
|
|
2203
|
+
type?: DataURLType,
|
|
2204
|
+
imageConfig?: { padding?: number | number[] },
|
|
2205
|
+
) {
|
|
2206
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
2207
|
+
const canvas = this.canvas;
|
|
2208
|
+
const transientCanvas = this.transientCanvas;
|
|
2209
|
+
const backgroundRoot = canvas.getRoot();
|
|
2210
|
+
const root = canvas.getRoot();
|
|
2211
|
+
const transientRoot = transientCanvas.getRoot();
|
|
2212
|
+
const rendererType = this.rendererType;
|
|
2213
|
+
|
|
2214
|
+
const backgroundBBox = backgroundRoot.getBBox();
|
|
2215
|
+
const BBox = root.getBBox();
|
|
2216
|
+
const transientBBox = transientRoot.getBBox();
|
|
2217
|
+
|
|
2218
|
+
let padding = imageConfig ? imageConfig.padding : undefined;
|
|
2219
|
+
if (!padding) {
|
|
2220
|
+
padding = [0, 0, 0, 0];
|
|
2221
|
+
} else if (isNumber(padding)) {
|
|
2222
|
+
padding = [padding, padding, padding, padding];
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
const left =
|
|
2226
|
+
(transientBBox.left
|
|
2227
|
+
? backgroundBBox.left
|
|
2228
|
+
? Math.min(backgroundBBox.left, BBox.left, transientBBox.left)
|
|
2229
|
+
: Math.min(BBox.left, transientBBox.left)
|
|
2230
|
+
: BBox.left) - padding[3];
|
|
2231
|
+
const right =
|
|
2232
|
+
(transientBBox.right
|
|
2233
|
+
? backgroundBBox.right
|
|
2234
|
+
? Math.max(backgroundBBox.right, BBox.right, transientBBox.right)
|
|
2235
|
+
: Math.max(BBox.right, transientBBox.right)
|
|
2236
|
+
: BBox.right) + padding[1];
|
|
2237
|
+
const top =
|
|
2238
|
+
(transientBBox.top
|
|
2239
|
+
? backgroundBBox.top
|
|
2240
|
+
? Math.min(backgroundBBox.top, BBox.top, transientBBox.top)
|
|
2241
|
+
: Math.min(BBox.top, transientBBox.top)
|
|
2242
|
+
: BBox.top) - padding[0];
|
|
2243
|
+
const bottom =
|
|
2244
|
+
(transientBBox.bottom
|
|
2245
|
+
? backgroundBBox.bottom
|
|
2246
|
+
? Math.max(backgroundBBox.bottom, BBox.bottom, transientBBox.bottom)
|
|
2247
|
+
: Math.max(BBox.bottom, transientBBox.bottom)
|
|
2248
|
+
: BBox.bottom) + padding[2];
|
|
2249
|
+
|
|
2250
|
+
const graphCenterX = (left + right) / 2;
|
|
2251
|
+
const graphCenterY = (top + bottom) / 2;
|
|
2252
|
+
const halfX = (right - left) / 2;
|
|
2253
|
+
const halfY = (bottom - top) / 2;
|
|
2254
|
+
|
|
2255
|
+
const pixelRatio =
|
|
2256
|
+
typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
2257
|
+
const vWidth = halfX * 2;
|
|
2258
|
+
const vHeight = halfY * 2;
|
|
2259
|
+
const vContainerDOM: HTMLDivElement = createDom(
|
|
2260
|
+
'<div id="virtual-image"></div>',
|
|
2261
|
+
);
|
|
2262
|
+
const vCanvas = createCanvas(
|
|
2263
|
+
rendererType,
|
|
2264
|
+
vContainerDOM,
|
|
2265
|
+
vWidth,
|
|
2266
|
+
vHeight,
|
|
2267
|
+
pixelRatio,
|
|
2268
|
+
);
|
|
2269
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
2270
|
+
if (rendererType !== 'svg') {
|
|
2271
|
+
const bgRect = new Rect({
|
|
2272
|
+
style: {
|
|
2273
|
+
x: 0,
|
|
2274
|
+
y: 0,
|
|
2275
|
+
z: -1,
|
|
2276
|
+
width: vCanvasContextService.getDomElement().width,
|
|
2277
|
+
height: vCanvasContextService.getDomElement().height,
|
|
2278
|
+
//@ts-ignore
|
|
2279
|
+
fill: backgroundCanvas.getContextService().getDomElement().style[
|
|
2280
|
+
'background-color'
|
|
2281
|
+
],
|
|
2282
|
+
},
|
|
2283
|
+
});
|
|
2284
|
+
vCanvas.appendChild(bgRect);
|
|
2285
|
+
}
|
|
2286
|
+
const backgroundClonedGroup = backgroundRoot.cloneNode(true);
|
|
2287
|
+
const clonedGroup = root.cloneNode(true);
|
|
2288
|
+
const transientClonedGroup = transientRoot.cloneNode(true);
|
|
2289
|
+
const transPosition: [number, number] = [
|
|
2290
|
+
-graphCenterX + halfX,
|
|
2291
|
+
-graphCenterY + halfY,
|
|
2292
|
+
];
|
|
2293
|
+
backgroundClonedGroup.setPosition(transPosition);
|
|
2294
|
+
clonedGroup.setPosition(transPosition);
|
|
2295
|
+
transientClonedGroup.setPosition(transPosition);
|
|
2296
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
2297
|
+
vCanvas.appendChild(clonedGroup);
|
|
2298
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
2299
|
+
vCanvas.render();
|
|
2300
|
+
|
|
2301
|
+
if (!type) type = 'image/png';
|
|
2302
|
+
let dataURL = '';
|
|
2303
|
+
await vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
2304
|
+
dataURL = url;
|
|
2305
|
+
});
|
|
2306
|
+
return dataURL;
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
/**
|
|
2310
|
+
* Converts a Data URL to an image file and handles the download of the image.
|
|
2311
|
+
* @param dataURL The Data URL of the image to be converted and downloaded.
|
|
2312
|
+
* @param renderer The renderer type ('svg' or other) used for the canvas.
|
|
2313
|
+
* @param link The HTML link element used for image download.
|
|
2314
|
+
* @param fileName The desired name for the downloaded image file.
|
|
2315
|
+
*/
|
|
2316
|
+
private dataURLToImage(dataURL: string, renderer: string, link, fileName) {
|
|
2317
|
+
if (!dataURL || dataURL === 'data:') {
|
|
2318
|
+
console.error(
|
|
2319
|
+
'Download image failed. The graph is too large or there is invalid attribute values in graph items',
|
|
2320
|
+
);
|
|
2321
|
+
return;
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
if (typeof window !== 'undefined') {
|
|
2325
|
+
if (window.Blob && window.URL && renderer !== 'svg') {
|
|
2326
|
+
const arr = dataURL.split(',');
|
|
2327
|
+
let mime = '';
|
|
2328
|
+
if (arr && arr.length > 0) {
|
|
2329
|
+
const match = arr[0].match(/:(.*?);/);
|
|
2330
|
+
// eslint-disable-next-line prefer-destructuring
|
|
2331
|
+
if (match && match.length >= 2) mime = match[1];
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2334
|
+
const bstr = atob(arr[1]);
|
|
2335
|
+
let n = bstr.length;
|
|
2336
|
+
const u8arr = new Uint8Array(n);
|
|
2337
|
+
|
|
2338
|
+
while (n--) {
|
|
2339
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2342
|
+
const blobObj = new Blob([u8arr], { type: mime });
|
|
2343
|
+
|
|
2344
|
+
if ((window.navigator as any).msSaveBlob) {
|
|
2345
|
+
(window.navigator as any).msSaveBlob(blobObj, fileName);
|
|
2346
|
+
} else {
|
|
2347
|
+
link.addEventListener('click', () => {
|
|
2348
|
+
link.download = fileName;
|
|
2349
|
+
link.href = window.URL.createObjectURL(blobObj);
|
|
2350
|
+
});
|
|
2351
|
+
}
|
|
2352
|
+
} else {
|
|
2353
|
+
link.addEventListener('click', () => {
|
|
2354
|
+
link.download = fileName;
|
|
2355
|
+
link.href = dataURL;
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2361
|
+
/**
|
|
2362
|
+
* Initiates the download of the graph as an image with an optional name and type.
|
|
2363
|
+
* @param name The desired name for the downloaded image file (optional).
|
|
2364
|
+
* @param type The type of the image to download (optional, defaults to 'image/png').
|
|
2365
|
+
*/
|
|
2366
|
+
public downloadImage(name?: string, type?: DataURLType): void {
|
|
2367
|
+
const self = this;
|
|
2368
|
+
// self.stopAnimate();
|
|
2369
|
+
|
|
2370
|
+
const rendererType = this.rendererType;
|
|
2371
|
+
if (!type) type = 'image/png';
|
|
2372
|
+
|
|
2373
|
+
const fileName: string =
|
|
2374
|
+
(name || 'graph') +
|
|
2375
|
+
(rendererType === 'svg' ? '.svg' : type.split('/')[1]);
|
|
2376
|
+
|
|
2377
|
+
const link: HTMLAnchorElement = document.createElement('a');
|
|
2378
|
+
|
|
2379
|
+
self.asyncToDataUrl(type, (dataURL) => {
|
|
2380
|
+
this.dataURLToImage(dataURL, rendererType, link, fileName);
|
|
2381
|
+
const e = document.createEvent('MouseEvents');
|
|
2382
|
+
e.initEvent('click', false, false);
|
|
2383
|
+
link.dispatchEvent(e);
|
|
2384
|
+
});
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
/**
|
|
2388
|
+
* Initiates the download of the entire graph as an image with optional name, type, and padding configuration.
|
|
2389
|
+
* @param name The desired name for the downloaded image file (optional).
|
|
2390
|
+
* @param type The type of the image to download (optional, defaults to 'image/png').
|
|
2391
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
2392
|
+
*/
|
|
2393
|
+
public downloadFullImage(
|
|
2394
|
+
name?: string,
|
|
2395
|
+
type?: DataURLType,
|
|
2396
|
+
imageConfig?: { padding?: number | number[] },
|
|
2397
|
+
): void {
|
|
2398
|
+
const self = this;
|
|
2399
|
+
|
|
2400
|
+
const rendererType = this.rendererType;
|
|
2401
|
+
if (!type) type = 'image/png';
|
|
2402
|
+
const fileName: string =
|
|
2403
|
+
(name || 'graph') +
|
|
2404
|
+
(rendererType === 'svg' ? '.svg' : type.split('/')[1]);
|
|
2405
|
+
const link: HTMLAnchorElement = document.createElement('a');
|
|
2406
|
+
|
|
2407
|
+
self.asyncToFullDataUrl(type, imageConfig, (dataURL) => {
|
|
2408
|
+
this.dataURLToImage(dataURL, rendererType, link, fileName);
|
|
2409
|
+
const e = document.createEvent('MouseEvents');
|
|
2410
|
+
e.initEvent('click', false, false);
|
|
2411
|
+
link.dispatchEvent(e);
|
|
2412
|
+
});
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
/**
|
|
2416
|
+
* Asynchronously converts the canvas content to a Data URL of the specified type and invokes the provided callback.
|
|
2417
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
2418
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
2419
|
+
*/
|
|
2420
|
+
protected asyncToDataUrl(type?: DataURLType, callback?: Function): void {
|
|
2421
|
+
let dataURL = '';
|
|
2422
|
+
if (!type) type = 'image/png';
|
|
2423
|
+
|
|
2424
|
+
setTimeout(async () => {
|
|
2425
|
+
await this.toDataURL(type).then((url) => {
|
|
2426
|
+
dataURL = url;
|
|
2427
|
+
});
|
|
2428
|
+
if (callback) callback(dataURL);
|
|
2429
|
+
}, 16);
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
/**
|
|
2433
|
+
* Asynchronously converts the entire canvas content to a Data URL of the specified type
|
|
2434
|
+
* with optional padding, and invokes the provided callback.
|
|
2435
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
2436
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
2437
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
2438
|
+
*/
|
|
2439
|
+
protected asyncToFullDataUrl(
|
|
2440
|
+
type?: DataURLType,
|
|
2441
|
+
imageConfig?: { padding?: number | number[] },
|
|
2442
|
+
callback?: (dataUrl: string) => void,
|
|
2443
|
+
): void {
|
|
2444
|
+
let dataURL = '';
|
|
2445
|
+
if (!type) type = 'image/png';
|
|
2446
|
+
|
|
2447
|
+
setTimeout(async () => {
|
|
2448
|
+
await this.toFullDataURL(type, imageConfig).then((url) => {
|
|
2449
|
+
dataURL = url;
|
|
2450
|
+
});
|
|
2451
|
+
if (callback) callback(dataURL);
|
|
2452
|
+
}, 16);
|
|
2453
|
+
}
|
|
2454
|
+
|
|
1999
2455
|
// ===== history operations =====
|
|
2000
2456
|
|
|
2001
2457
|
/**
|
|
@@ -2020,30 +2476,30 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
2020
2476
|
/**
|
|
2021
2477
|
* Pause stacking operation.
|
|
2022
2478
|
*/
|
|
2023
|
-
public
|
|
2479
|
+
public pauseStack(): void {
|
|
2024
2480
|
const history = this.getHistoryPlugin();
|
|
2025
|
-
return history?.
|
|
2481
|
+
return history?.pauseStack();
|
|
2026
2482
|
}
|
|
2027
2483
|
|
|
2028
2484
|
/**
|
|
2029
2485
|
* Resume stacking operation.
|
|
2030
2486
|
*/
|
|
2031
|
-
public
|
|
2487
|
+
public resumeStack(): void {
|
|
2032
2488
|
const history = this.getHistoryPlugin();
|
|
2033
|
-
return history?.
|
|
2489
|
+
return history?.resumeStack();
|
|
2034
2490
|
}
|
|
2035
2491
|
|
|
2036
2492
|
/**
|
|
2037
2493
|
* Execute a callback without allowing any stacking operations.
|
|
2038
2494
|
* @param callback
|
|
2039
2495
|
*/
|
|
2040
|
-
public
|
|
2496
|
+
public executeWithNoStack = (callback: () => void): void => {
|
|
2041
2497
|
const history = this.getHistoryPlugin();
|
|
2042
|
-
history?.
|
|
2498
|
+
history?.pauseStack();
|
|
2043
2499
|
try {
|
|
2044
2500
|
callback();
|
|
2045
2501
|
} finally {
|
|
2046
|
-
history?.
|
|
2502
|
+
history?.resumeStack();
|
|
2047
2503
|
}
|
|
2048
2504
|
};
|
|
2049
2505
|
|
|
@@ -2109,41 +2565,41 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
2109
2565
|
}
|
|
2110
2566
|
|
|
2111
2567
|
/**
|
|
2112
|
-
* Begin a
|
|
2113
|
-
* Any operations performed between `
|
|
2568
|
+
* Begin a historyBatch operation.
|
|
2569
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
2114
2570
|
* treated as a single operation when undoing or redoing.
|
|
2115
2571
|
*/
|
|
2116
|
-
public
|
|
2572
|
+
public startHistoryBatch() {
|
|
2117
2573
|
const history = this.getHistoryPlugin();
|
|
2118
|
-
history?.
|
|
2574
|
+
history?.startHistoryBatch();
|
|
2119
2575
|
}
|
|
2120
2576
|
|
|
2121
2577
|
/**
|
|
2122
|
-
* End a
|
|
2123
|
-
* Any operations performed between `
|
|
2578
|
+
* End a historyBatch operation.
|
|
2579
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
2124
2580
|
* treated as a single operation when undoing or redoing.
|
|
2125
2581
|
*/
|
|
2126
|
-
public
|
|
2582
|
+
public stopHistoryBatch() {
|
|
2127
2583
|
const history = this.getHistoryPlugin();
|
|
2128
|
-
history?.
|
|
2584
|
+
history?.stopHistoryBatch();
|
|
2129
2585
|
}
|
|
2130
2586
|
|
|
2131
2587
|
/**
|
|
2132
2588
|
* Execute a provided function within a batched context
|
|
2133
2589
|
* All operations performed inside callback will be treated as a composite operation
|
|
2134
|
-
* more convenient way without manually invoking `
|
|
2590
|
+
* more convenient way without manually invoking `startHistoryBatch` and `stopHistoryBatch`.
|
|
2135
2591
|
* @param callback The func containing operations to be batched together.
|
|
2136
2592
|
*/
|
|
2137
|
-
public
|
|
2593
|
+
public historyBatch(callback: () => void) {
|
|
2138
2594
|
const history = this.getHistoryPlugin();
|
|
2139
|
-
history?.
|
|
2595
|
+
history?.historyBatch(callback);
|
|
2140
2596
|
}
|
|
2141
2597
|
|
|
2142
2598
|
/**
|
|
2143
2599
|
* Clear history stack
|
|
2144
2600
|
* @param {StackType} stackType undo/redo stack
|
|
2145
2601
|
*/
|
|
2146
|
-
public
|
|
2602
|
+
public cleanHistory(stackType?: StackType) {
|
|
2147
2603
|
const history = this.getHistoryPlugin();
|
|
2148
2604
|
if (!stackType) return history?.clear();
|
|
2149
2605
|
return stackType === 'undo'
|
|
@@ -2197,7 +2653,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
2197
2653
|
this.transientCanvas.destroy();
|
|
2198
2654
|
|
|
2199
2655
|
// clear history stack
|
|
2200
|
-
this.
|
|
2656
|
+
this.cleanHistory();
|
|
2201
2657
|
|
|
2202
2658
|
callback?.();
|
|
2203
2659
|
// }, 500);
|