@antv/g6 5.0.0-beta.5 → 5.0.0-beta.7
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 -7
- 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 +22 -2
- package/esm/item/edge.js +93 -42
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.js +9 -5
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +1 -1
- package/esm/item/node.js +22 -15
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/data.d.ts +7 -10
- package/esm/runtime/controller/data.js +123 -281
- package/esm/runtime/controller/data.js.map +1 -1
- package/esm/runtime/controller/item.d.ts +1 -0
- package/esm/runtime/controller/item.js +21 -9
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.d.ts +85 -7
- package/esm/runtime/graph.js +396 -61
- package/esm/runtime/graph.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/create-edge.d.ts +57 -0
- package/esm/stdlib/behavior/create-edge.js +207 -0
- package/esm/stdlib/behavior/create-edge.js.map +1 -0
- package/esm/stdlib/behavior/drag-canvas.d.ts +2 -1
- package/esm/stdlib/behavior/drag-canvas.js +26 -18
- 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 +35 -24
- 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 +70 -57
- 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 +2 -1
- package/esm/stdlib/behavior/zoom-canvas.js +30 -22
- package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
- package/esm/stdlib/data/mapNodeSize.js +2 -2
- package/esm/stdlib/data/mapNodeSize.js.map +1 -1
- package/esm/stdlib/data/transformV4Data.d.ts +2 -2
- package/esm/stdlib/data/transformV4Data.js +2 -2
- package/esm/stdlib/data/transformV4Data.js.map +1 -1
- package/esm/stdlib/data/validateData.d.ts +2 -2
- package/esm/stdlib/data/validateData.js +9 -9
- package/esm/stdlib/data/validateData.js.map +1 -1
- package/esm/stdlib/index.d.ts +10 -6
- package/esm/stdlib/index.js +5 -1
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/edge/base.js +4 -9
- package/esm/stdlib/item/edge/base.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/minimap/index.d.ts +5 -1
- package/esm/stdlib/plugin/minimap/index.js +116 -9
- package/esm/stdlib/plugin/minimap/index.js.map +1 -1
- package/esm/stdlib/plugin/snapline/index.d.ts +5 -1
- package/esm/stdlib/plugin/snapline/index.js +23 -12
- package/esm/stdlib/plugin/snapline/index.js.map +1 -1
- package/esm/types/graph.d.ts +34 -8
- package/esm/types/hook.d.ts +16 -2
- package/esm/types/spec.d.ts +6 -3
- package/esm/types/view.d.ts +5 -0
- package/esm/util/event.d.ts +3 -1
- package/esm/util/event.js +8 -1
- package/esm/util/event.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/layout.d.ts +11 -0
- package/esm/util/layout.js +45 -0
- package/esm/util/layout.js.map +1 -1
- package/esm/util/point.js +5 -1
- package/esm/util/point.js.map +1 -1
- package/esm/util/shape.d.ts +1 -1
- package/esm/util/shape.js +3 -7
- 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 -7
- 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 +22 -2
- package/lib/item/edge.js +92 -41
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.js +9 -5
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +1 -1
- package/lib/item/node.js +22 -15
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/data.d.ts +7 -10
- package/lib/runtime/controller/data.js +123 -281
- package/lib/runtime/controller/data.js.map +1 -1
- package/lib/runtime/controller/item.d.ts +1 -0
- package/lib/runtime/controller/item.js +21 -9
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.d.ts +85 -7
- package/lib/runtime/graph.js +396 -61
- package/lib/runtime/graph.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/create-edge.d.ts +57 -0
- package/lib/stdlib/behavior/create-edge.js +211 -0
- package/lib/stdlib/behavior/create-edge.js.map +1 -0
- package/lib/stdlib/behavior/drag-canvas.d.ts +2 -1
- package/lib/stdlib/behavior/drag-canvas.js +26 -18
- 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 +35 -24
- 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 +70 -57
- 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 +2 -1
- package/lib/stdlib/behavior/zoom-canvas.js +30 -22
- package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
- package/lib/stdlib/data/mapNodeSize.js +2 -2
- package/lib/stdlib/data/mapNodeSize.js.map +1 -1
- package/lib/stdlib/data/transformV4Data.d.ts +2 -2
- package/lib/stdlib/data/transformV4Data.js +2 -2
- package/lib/stdlib/data/transformV4Data.js.map +1 -1
- package/lib/stdlib/data/validateData.d.ts +2 -2
- package/lib/stdlib/data/validateData.js +9 -9
- package/lib/stdlib/data/validateData.js.map +1 -1
- package/lib/stdlib/index.d.ts +10 -6
- package/lib/stdlib/index.js +5 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/edge/base.js +4 -9
- package/lib/stdlib/item/edge/base.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/minimap/index.d.ts +5 -1
- package/lib/stdlib/plugin/minimap/index.js +116 -9
- package/lib/stdlib/plugin/minimap/index.js.map +1 -1
- package/lib/stdlib/plugin/snapline/index.d.ts +5 -1
- package/lib/stdlib/plugin/snapline/index.js +23 -12
- package/lib/stdlib/plugin/snapline/index.js.map +1 -1
- package/lib/types/graph.d.ts +34 -8
- package/lib/types/hook.d.ts +16 -2
- package/lib/types/spec.d.ts +6 -3
- package/lib/types/view.d.ts +5 -0
- package/lib/util/event.d.ts +3 -1
- package/lib/util/event.js +8 -1
- package/lib/util/event.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/layout.d.ts +11 -0
- package/lib/util/layout.js +47 -1
- package/lib/util/layout.js.map +1 -1
- package/lib/util/point.js +5 -1
- package/lib/util/point.js.map +1 -1
- package/lib/util/shape.d.ts +1 -1
- package/lib/util/shape.js +3 -7
- 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 +1 -1
- package/src/index.ts +1 -1
- package/src/item/combo.ts +14 -9
- package/src/item/edge.ts +121 -55
- package/src/item/item.ts +13 -9
- package/src/item/node.ts +20 -15
- package/src/runtime/controller/data.ts +139 -339
- package/src/runtime/controller/item.ts +30 -12
- package/src/runtime/graph.ts +502 -67
- package/src/stdlib/behavior/brush-select.ts +4 -2
- package/src/stdlib/behavior/create-edge.ts +296 -0
- package/src/stdlib/behavior/drag-canvas.ts +30 -19
- package/src/stdlib/behavior/drag-combo.ts +2 -2
- package/src/stdlib/behavior/drag-node.ts +8 -8
- 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 +34 -23
- package/src/stdlib/data/mapNodeSize.ts +2 -2
- package/src/stdlib/data/transformV4Data.ts +2 -2
- package/src/stdlib/data/validateData.ts +9 -9
- package/src/stdlib/index.ts +6 -0
- package/src/stdlib/item/edge/base.ts +4 -8
- package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
- package/src/stdlib/plugin/minimap/index.ts +120 -10
- package/src/stdlib/plugin/snapline/index.ts +36 -16
- package/src/types/graph.ts +37 -8
- package/src/types/hook.ts +16 -2
- package/src/types/spec.ts +9 -3
- package/src/types/view.ts +8 -3
- package/src/util/event.ts +14 -1
- package/src/util/item.ts +65 -28
- package/src/util/layout.ts +45 -0
- package/src/util/point.ts +4 -2
- package/src/util/shape.ts +6 -7
- package/src/util/warn.ts +20 -0
package/lib/runtime/graph.js
CHANGED
|
@@ -24,9 +24,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const event_emitter_1 = __importDefault(require("@antv/event-emitter"));
|
|
27
|
+
const g_1 = require("@antv/g");
|
|
27
28
|
const util_1 = require("@antv/util");
|
|
29
|
+
const dom_util_1 = require("@antv/dom-util");
|
|
28
30
|
const canvas_1 = require("../util/canvas");
|
|
29
31
|
const shape_1 = require("../util/shape");
|
|
32
|
+
const layout_1 = require("../util/layout");
|
|
30
33
|
const controller_1 = require("./controller");
|
|
31
34
|
const plugin_1 = require("./controller/plugin");
|
|
32
35
|
const hooks_1 = __importDefault(require("./hooks"));
|
|
@@ -198,13 +201,15 @@ class Graph extends event_emitter_1.default {
|
|
|
198
201
|
}),
|
|
199
202
|
transientupdate: new hooks_1.default({ name: 'transientupdate' }),
|
|
200
203
|
pluginchange: new hooks_1.default({ name: 'pluginchange' }),
|
|
201
|
-
themechange: new hooks_1.default({ name: '
|
|
204
|
+
themechange: new hooks_1.default({ name: 'themechange' }),
|
|
205
|
+
mapperchange: new hooks_1.default({ name: 'mapperchange' }),
|
|
202
206
|
treecollapseexpand: new hooks_1.default({ name: 'treecollapseexpand' }),
|
|
203
207
|
destroy: new hooks_1.default({ name: 'destroy' }),
|
|
204
208
|
};
|
|
205
209
|
}
|
|
206
210
|
formatSpecification(spec) {
|
|
207
|
-
|
|
211
|
+
var _a;
|
|
212
|
+
return Object.assign(Object.assign(Object.assign({}, this.specification), spec), { optimize: Object.assign(Object.assign({ tileBehavior: 2000, tileBehaviorSize: 1000, tileFirstRender: 10000, tileFirstRenderSize: 1000 }, (_a = this.specification) === null || _a === void 0 ? void 0 : _a.optimize), spec.optimize) });
|
|
208
213
|
}
|
|
209
214
|
/**
|
|
210
215
|
* Update the specs(configurations).
|
|
@@ -233,6 +238,28 @@ class Graph extends event_emitter_1.default {
|
|
|
233
238
|
theme: this.themeController.specification,
|
|
234
239
|
});
|
|
235
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Update the item display mapper for a specific item type.
|
|
243
|
+
* @param {ITEM_TYPE} type - The type of item (node, edge, or combo).
|
|
244
|
+
* @param {NodeMapper | EdgeMapper | ComboMapper} mapper - The mapper to be updated.
|
|
245
|
+
* */
|
|
246
|
+
updateMapper(type, mapper) {
|
|
247
|
+
switch (type) {
|
|
248
|
+
case 'node':
|
|
249
|
+
this.specification.node = mapper;
|
|
250
|
+
break;
|
|
251
|
+
case 'edge':
|
|
252
|
+
this.specification.edge = mapper;
|
|
253
|
+
break;
|
|
254
|
+
case 'combo':
|
|
255
|
+
this.specification.combo = mapper;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
this.hooks.mapperchange.emit({
|
|
259
|
+
type,
|
|
260
|
+
mapper,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
236
263
|
/**
|
|
237
264
|
* Get the copy of specs(configurations).
|
|
238
265
|
* @returns graph specs
|
|
@@ -266,18 +293,22 @@ class Graph extends event_emitter_1.default {
|
|
|
266
293
|
const { autoFit } = this.specification;
|
|
267
294
|
if (autoFit) {
|
|
268
295
|
if (autoFit === 'view') {
|
|
269
|
-
yield this.fitView();
|
|
296
|
+
yield this.fitView({ rules: { boundsType: 'layout' } });
|
|
270
297
|
}
|
|
271
298
|
else if (autoFit === 'center') {
|
|
272
|
-
yield this.fitCenter();
|
|
299
|
+
yield this.fitCenter('layout');
|
|
273
300
|
}
|
|
274
301
|
else {
|
|
275
302
|
const { type, effectTiming } = autoFit, others = __rest(autoFit, ["type", "effectTiming"]);
|
|
276
303
|
if (type === 'view') {
|
|
277
|
-
|
|
304
|
+
const { padding, rules } = others;
|
|
305
|
+
yield this.fitView({
|
|
306
|
+
padding,
|
|
307
|
+
rules: Object.assign(Object.assign({}, rules), { boundsType: 'layout' }),
|
|
308
|
+
}, effectTiming);
|
|
278
309
|
}
|
|
279
310
|
else if (type === 'center') {
|
|
280
|
-
yield this.fitCenter(effectTiming);
|
|
311
|
+
yield this.fitCenter('layout', effectTiming);
|
|
281
312
|
}
|
|
282
313
|
else if (type === 'position') {
|
|
283
314
|
// TODO: align
|
|
@@ -450,9 +481,12 @@ class Graph extends event_emitter_1.default {
|
|
|
450
481
|
const [top, right, bottom, left] = padding
|
|
451
482
|
? (0, shape_1.formatPadding)(padding)
|
|
452
483
|
: [0, 0, 0, 0];
|
|
453
|
-
const { direction = 'both', ratioRule = 'min' } = rules || {};
|
|
454
|
-
|
|
455
|
-
|
|
484
|
+
const { direction = 'both', ratioRule = 'min', boundsType = 'render', } = rules || {};
|
|
485
|
+
const { center: [graphCenterX, graphCenterY], halfExtents, } = boundsType === 'render'
|
|
486
|
+
? // Get the bounds of the whole graph content.
|
|
487
|
+
this.canvas.document.documentElement.getBounds()
|
|
488
|
+
: // Get the bounds of the nodes positions while the graph content is not ready.
|
|
489
|
+
(0, layout_1.getLayoutBounds)(this);
|
|
456
490
|
const origin = this.canvas.canvas2Viewport({
|
|
457
491
|
x: graphCenterX,
|
|
458
492
|
y: graphCenterY,
|
|
@@ -497,10 +531,13 @@ class Graph extends event_emitter_1.default {
|
|
|
497
531
|
* Fit the graph center to the view center.
|
|
498
532
|
* @param effectTiming animation configurations
|
|
499
533
|
*/
|
|
500
|
-
fitCenter(effectTiming) {
|
|
534
|
+
fitCenter(boundsType = 'render', effectTiming) {
|
|
501
535
|
return __awaiter(this, void 0, void 0, function* () {
|
|
502
|
-
|
|
503
|
-
|
|
536
|
+
const { center: [graphCenterX, graphCenterY], } = boundsType === 'render'
|
|
537
|
+
? // Get the bounds of the whole graph content.
|
|
538
|
+
this.canvas.document.documentElement.getBounds()
|
|
539
|
+
: // Get the bounds of the nodes positions while the graph content is not ready.
|
|
540
|
+
(0, layout_1.getLayoutBounds)(this);
|
|
504
541
|
yield this.translateTo(this.canvas.canvas2Viewport({ x: graphCenterX, y: graphCenterY }), effectTiming);
|
|
505
542
|
});
|
|
506
543
|
}
|
|
@@ -754,23 +791,26 @@ class Graph extends event_emitter_1.default {
|
|
|
754
791
|
// data controller and item controller subscribe additem in order
|
|
755
792
|
const { graphCore } = this.dataController;
|
|
756
793
|
const { specification } = this.themeController;
|
|
794
|
+
// debugger;
|
|
757
795
|
graphCore.once('changed', (event) => {
|
|
758
796
|
if (!event.changes.length)
|
|
759
797
|
return;
|
|
760
798
|
const changes = event.changes;
|
|
761
|
-
|
|
762
|
-
type: itemType,
|
|
763
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
764
|
-
graphCore,
|
|
765
|
-
theme: specification,
|
|
766
|
-
});
|
|
767
|
-
this.emit('afteritemchange', {
|
|
799
|
+
const timingParameters = {
|
|
768
800
|
type: itemType,
|
|
769
801
|
action: 'add',
|
|
770
802
|
models,
|
|
771
803
|
apiName: 'addData',
|
|
772
804
|
changes,
|
|
805
|
+
};
|
|
806
|
+
this.emit('beforeitemchange', timingParameters);
|
|
807
|
+
this.hooks.itemchange.emit({
|
|
808
|
+
type: itemType,
|
|
809
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
810
|
+
graphCore,
|
|
811
|
+
theme: specification,
|
|
773
812
|
});
|
|
813
|
+
this.emit('afteritemchange', timingParameters);
|
|
774
814
|
});
|
|
775
815
|
const modelArr = (0, util_1.isArray)(models) ? models : [models];
|
|
776
816
|
const data = { nodes: [], edges: [], combos: [] };
|
|
@@ -791,27 +831,38 @@ class Graph extends event_emitter_1.default {
|
|
|
791
831
|
removeData(itemType, ids) {
|
|
792
832
|
const idArr = (0, util_1.isArray)(ids) ? ids : [ids];
|
|
793
833
|
const data = { nodes: [], edges: [], combos: [] };
|
|
794
|
-
const {
|
|
834
|
+
const { graphCore } = this.dataController;
|
|
795
835
|
const { specification } = this.themeController;
|
|
796
|
-
const getItem = itemType === 'edge' ?
|
|
797
|
-
|
|
836
|
+
const getItem = itemType === 'edge' ? graphCore.getEdge : graphCore.getNode;
|
|
837
|
+
const hasItem = itemType === 'edge' ? graphCore.hasEdge : graphCore.hasNode;
|
|
838
|
+
data[`${itemType}s`] = idArr
|
|
839
|
+
.map((id) => {
|
|
840
|
+
if (!hasItem.bind(graphCore)(id)) {
|
|
841
|
+
console.warn(`The ${itemType} data with id ${id} does not exist. It will be ignored`);
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
return getItem.bind(graphCore)(id);
|
|
845
|
+
})
|
|
846
|
+
.filter(Boolean);
|
|
798
847
|
graphCore.once('changed', (event) => {
|
|
799
848
|
if (!event.changes.length)
|
|
800
849
|
return;
|
|
801
850
|
const changes = event.changes;
|
|
802
|
-
|
|
803
|
-
type: itemType,
|
|
804
|
-
changes: event.changes,
|
|
805
|
-
graphCore,
|
|
806
|
-
theme: specification,
|
|
807
|
-
});
|
|
808
|
-
this.emit('afteritemchange', {
|
|
851
|
+
const timingParameters = {
|
|
809
852
|
type: itemType,
|
|
810
853
|
action: 'remove',
|
|
811
854
|
ids: idArr,
|
|
812
855
|
apiName: 'removeData',
|
|
813
856
|
changes,
|
|
857
|
+
};
|
|
858
|
+
this.emit('beforeitemchange', timingParameters);
|
|
859
|
+
this.hooks.itemchange.emit({
|
|
860
|
+
type: itemType,
|
|
861
|
+
changes: event.changes,
|
|
862
|
+
graphCore,
|
|
863
|
+
theme: specification,
|
|
814
864
|
});
|
|
865
|
+
this.emit('afteritemchange', timingParameters);
|
|
815
866
|
});
|
|
816
867
|
this.hooks.datachange.emit({
|
|
817
868
|
data,
|
|
@@ -879,19 +930,21 @@ class Graph extends event_emitter_1.default {
|
|
|
879
930
|
const { specification } = this.themeController;
|
|
880
931
|
graphCore.once('changed', (event) => {
|
|
881
932
|
const changes = this.extendChanges((0, util_1.clone)(event.changes));
|
|
882
|
-
|
|
883
|
-
type: itemType,
|
|
884
|
-
changes: event.changes,
|
|
885
|
-
graphCore,
|
|
886
|
-
theme: specification,
|
|
887
|
-
});
|
|
888
|
-
this.emit('afteritemchange', {
|
|
933
|
+
const timingParameters = {
|
|
889
934
|
type: itemType,
|
|
890
935
|
action: 'update',
|
|
891
936
|
models,
|
|
892
937
|
apiName: 'updateData',
|
|
893
938
|
changes,
|
|
939
|
+
};
|
|
940
|
+
this.emit('beforeitemchange', timingParameters);
|
|
941
|
+
this.hooks.itemchange.emit({
|
|
942
|
+
type: itemType,
|
|
943
|
+
changes: event.changes,
|
|
944
|
+
graphCore,
|
|
945
|
+
theme: specification,
|
|
894
946
|
});
|
|
947
|
+
this.emit('afteritemchange', timingParameters);
|
|
895
948
|
});
|
|
896
949
|
this.hooks.datachange.emit({
|
|
897
950
|
data,
|
|
@@ -938,6 +991,15 @@ class Graph extends event_emitter_1.default {
|
|
|
938
991
|
if (!event.changes.length)
|
|
939
992
|
return;
|
|
940
993
|
const changes = event.changes.filter((change) => !(0, util_1.isEqual)(change.newValue, change.oldValue));
|
|
994
|
+
const timingParameters = {
|
|
995
|
+
type,
|
|
996
|
+
action: 'updatePosition',
|
|
997
|
+
upsertAncestors,
|
|
998
|
+
models,
|
|
999
|
+
apiName: 'updatePosition',
|
|
1000
|
+
changes,
|
|
1001
|
+
};
|
|
1002
|
+
this.emit('beforeitemchange', timingParameters);
|
|
941
1003
|
this.hooks.itemchange.emit({
|
|
942
1004
|
type,
|
|
943
1005
|
changes: event.changes,
|
|
@@ -948,14 +1010,7 @@ class Graph extends event_emitter_1.default {
|
|
|
948
1010
|
animate: !disableAnimate,
|
|
949
1011
|
callback,
|
|
950
1012
|
});
|
|
951
|
-
this.emit('afteritemchange',
|
|
952
|
-
type,
|
|
953
|
-
action: 'updatePosition',
|
|
954
|
-
upsertAncestors,
|
|
955
|
-
models,
|
|
956
|
-
apiName: 'updatePosition',
|
|
957
|
-
changes,
|
|
958
|
-
});
|
|
1013
|
+
this.emit('afteritemchange', timingParameters);
|
|
959
1014
|
});
|
|
960
1015
|
this.hooks.datachange.emit({
|
|
961
1016
|
data: {
|
|
@@ -1204,19 +1259,21 @@ class Graph extends event_emitter_1.default {
|
|
|
1204
1259
|
if (!event.changes.length)
|
|
1205
1260
|
return;
|
|
1206
1261
|
const changes = event.changes;
|
|
1207
|
-
|
|
1208
|
-
type: 'combo',
|
|
1209
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
1210
|
-
graphCore,
|
|
1211
|
-
theme: specification,
|
|
1212
|
-
});
|
|
1213
|
-
this.emit('afteritemchange', {
|
|
1262
|
+
const timingParameters = {
|
|
1214
1263
|
type: 'combo',
|
|
1215
1264
|
action: 'add',
|
|
1216
1265
|
models: [model],
|
|
1217
1266
|
apiName: 'addCombo',
|
|
1218
1267
|
changes,
|
|
1268
|
+
};
|
|
1269
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1270
|
+
this.hooks.itemchange.emit({
|
|
1271
|
+
type: 'combo',
|
|
1272
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
1273
|
+
graphCore,
|
|
1274
|
+
theme: specification,
|
|
1219
1275
|
});
|
|
1276
|
+
this.emit('afteritemchange', timingParameters);
|
|
1220
1277
|
});
|
|
1221
1278
|
const data = {
|
|
1222
1279
|
nodes: [],
|
|
@@ -1280,16 +1337,7 @@ class Graph extends event_emitter_1.default {
|
|
|
1280
1337
|
if (!event.changes.length)
|
|
1281
1338
|
return;
|
|
1282
1339
|
const changes = this.extendChanges((0, util_1.clone)(event.changes));
|
|
1283
|
-
|
|
1284
|
-
type: 'combo',
|
|
1285
|
-
changes: event.changes,
|
|
1286
|
-
graphCore,
|
|
1287
|
-
theme: specification,
|
|
1288
|
-
upsertAncestors,
|
|
1289
|
-
action: 'updatePosition',
|
|
1290
|
-
callback,
|
|
1291
|
-
});
|
|
1292
|
-
this.emit('afteritemchange', {
|
|
1340
|
+
const timingParameters = {
|
|
1293
1341
|
type: 'combo',
|
|
1294
1342
|
ids: idArr,
|
|
1295
1343
|
dx,
|
|
@@ -1298,7 +1346,18 @@ class Graph extends event_emitter_1.default {
|
|
|
1298
1346
|
upsertAncestors,
|
|
1299
1347
|
apiName: 'moveCombo',
|
|
1300
1348
|
changes,
|
|
1349
|
+
};
|
|
1350
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1351
|
+
this.hooks.itemchange.emit({
|
|
1352
|
+
type: 'combo',
|
|
1353
|
+
changes: event.changes,
|
|
1354
|
+
graphCore,
|
|
1355
|
+
theme: specification,
|
|
1356
|
+
upsertAncestors,
|
|
1357
|
+
action: 'updatePosition',
|
|
1358
|
+
callback,
|
|
1301
1359
|
});
|
|
1360
|
+
this.emit('afteritemchange', timingParameters);
|
|
1302
1361
|
});
|
|
1303
1362
|
this.hooks.datachange.emit({
|
|
1304
1363
|
data: {
|
|
@@ -1383,6 +1442,14 @@ class Graph extends event_emitter_1.default {
|
|
|
1383
1442
|
getMode() {
|
|
1384
1443
|
return this.interactionController.getMode();
|
|
1385
1444
|
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Set the cursor. But the cursor in item's style has higher priority.
|
|
1447
|
+
* @param cursor
|
|
1448
|
+
*/
|
|
1449
|
+
setCursor(cursor) {
|
|
1450
|
+
this.canvas.setCursor(cursor);
|
|
1451
|
+
this.transientCanvas.setCursor(cursor);
|
|
1452
|
+
}
|
|
1386
1453
|
/**
|
|
1387
1454
|
* Add behavior(s) to mode(s).
|
|
1388
1455
|
* @param behaviors behavior names or configs
|
|
@@ -1553,6 +1620,274 @@ class Graph extends event_emitter_1.default {
|
|
|
1553
1620
|
});
|
|
1554
1621
|
return this.itemController.getTransient(String(id));
|
|
1555
1622
|
}
|
|
1623
|
+
// ===== download operations =====
|
|
1624
|
+
/**
|
|
1625
|
+
* Asynchronously generates a Data URL representation of the canvas content, including
|
|
1626
|
+
* background, main content, and transient canvas.
|
|
1627
|
+
* @param The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
1628
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
1629
|
+
*/
|
|
1630
|
+
toDataURL(type) {
|
|
1631
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1632
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
1633
|
+
const canvas = this.canvas;
|
|
1634
|
+
const transientCanvas = this.transientCanvas;
|
|
1635
|
+
const rendererType = this.rendererType;
|
|
1636
|
+
const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
1637
|
+
const width = this.getSize()[0];
|
|
1638
|
+
const height = this.getSize()[1];
|
|
1639
|
+
const vContainerDOM = (0, dom_util_1.createDom)('<div id="virtual-image"></div>');
|
|
1640
|
+
const vCanvas = (0, canvas_1.createCanvas)(rendererType, vContainerDOM, width, height, pixelRatio);
|
|
1641
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
1642
|
+
let bgRect;
|
|
1643
|
+
if (rendererType !== 'svg') {
|
|
1644
|
+
bgRect = new g_1.Rect({
|
|
1645
|
+
style: {
|
|
1646
|
+
x: 0,
|
|
1647
|
+
y: 0,
|
|
1648
|
+
z: -1,
|
|
1649
|
+
width: vCanvasContextService.getDomElement().width,
|
|
1650
|
+
height: vCanvasContextService.getDomElement().height,
|
|
1651
|
+
//@ts-ignore
|
|
1652
|
+
fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
|
|
1653
|
+
},
|
|
1654
|
+
});
|
|
1655
|
+
vCanvas.appendChild(bgRect);
|
|
1656
|
+
}
|
|
1657
|
+
const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
|
|
1658
|
+
const clonedGroup = canvas.getRoot().cloneNode(true);
|
|
1659
|
+
const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
|
|
1660
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
1661
|
+
vCanvas.appendChild(clonedGroup);
|
|
1662
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
1663
|
+
vCanvas.render();
|
|
1664
|
+
if (!type)
|
|
1665
|
+
type = 'image/png';
|
|
1666
|
+
let dataURL = '';
|
|
1667
|
+
yield vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
1668
|
+
dataURL = url;
|
|
1669
|
+
});
|
|
1670
|
+
return dataURL;
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Asynchronously generates a Data URL representation of the full canvas content,
|
|
1675
|
+
* including background, main content, and transient canvas, with optional padding.
|
|
1676
|
+
* @param type The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
1677
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
1678
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
1679
|
+
*/
|
|
1680
|
+
toFullDataURL(type, imageConfig) {
|
|
1681
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1682
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
1683
|
+
const canvas = this.canvas;
|
|
1684
|
+
const transientCanvas = this.transientCanvas;
|
|
1685
|
+
const backgroundRoot = canvas.getRoot();
|
|
1686
|
+
const root = canvas.getRoot();
|
|
1687
|
+
const transientRoot = transientCanvas.getRoot();
|
|
1688
|
+
const rendererType = this.rendererType;
|
|
1689
|
+
const backgroundBBox = backgroundRoot.getBBox();
|
|
1690
|
+
const BBox = root.getBBox();
|
|
1691
|
+
const transientBBox = transientRoot.getBBox();
|
|
1692
|
+
let padding = imageConfig ? imageConfig.padding : undefined;
|
|
1693
|
+
if (!padding) {
|
|
1694
|
+
padding = [0, 0, 0, 0];
|
|
1695
|
+
}
|
|
1696
|
+
else if ((0, util_1.isNumber)(padding)) {
|
|
1697
|
+
padding = [padding, padding, padding, padding];
|
|
1698
|
+
}
|
|
1699
|
+
const left = (transientBBox.left
|
|
1700
|
+
? backgroundBBox.left
|
|
1701
|
+
? Math.min(backgroundBBox.left, BBox.left, transientBBox.left)
|
|
1702
|
+
: Math.min(BBox.left, transientBBox.left)
|
|
1703
|
+
: BBox.left) - padding[3];
|
|
1704
|
+
const right = (transientBBox.right
|
|
1705
|
+
? backgroundBBox.right
|
|
1706
|
+
? Math.max(backgroundBBox.right, BBox.right, transientBBox.right)
|
|
1707
|
+
: Math.max(BBox.right, transientBBox.right)
|
|
1708
|
+
: BBox.right) + padding[1];
|
|
1709
|
+
const top = (transientBBox.top
|
|
1710
|
+
? backgroundBBox.top
|
|
1711
|
+
? Math.min(backgroundBBox.top, BBox.top, transientBBox.top)
|
|
1712
|
+
: Math.min(BBox.top, transientBBox.top)
|
|
1713
|
+
: BBox.top) - padding[0];
|
|
1714
|
+
const bottom = (transientBBox.bottom
|
|
1715
|
+
? backgroundBBox.bottom
|
|
1716
|
+
? Math.max(backgroundBBox.bottom, BBox.bottom, transientBBox.bottom)
|
|
1717
|
+
: Math.max(BBox.bottom, transientBBox.bottom)
|
|
1718
|
+
: BBox.bottom) + padding[2];
|
|
1719
|
+
const graphCenterX = (left + right) / 2;
|
|
1720
|
+
const graphCenterY = (top + bottom) / 2;
|
|
1721
|
+
const halfX = (right - left) / 2;
|
|
1722
|
+
const halfY = (bottom - top) / 2;
|
|
1723
|
+
const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
1724
|
+
const vWidth = halfX * 2;
|
|
1725
|
+
const vHeight = halfY * 2;
|
|
1726
|
+
const vContainerDOM = (0, dom_util_1.createDom)('<div id="virtual-image"></div>');
|
|
1727
|
+
const vCanvas = (0, canvas_1.createCanvas)(rendererType, vContainerDOM, vWidth, vHeight, pixelRatio);
|
|
1728
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
1729
|
+
if (rendererType !== 'svg') {
|
|
1730
|
+
const bgRect = new g_1.Rect({
|
|
1731
|
+
style: {
|
|
1732
|
+
x: 0,
|
|
1733
|
+
y: 0,
|
|
1734
|
+
z: -1,
|
|
1735
|
+
width: vCanvasContextService.getDomElement().width,
|
|
1736
|
+
height: vCanvasContextService.getDomElement().height,
|
|
1737
|
+
//@ts-ignore
|
|
1738
|
+
fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
|
|
1739
|
+
},
|
|
1740
|
+
});
|
|
1741
|
+
vCanvas.appendChild(bgRect);
|
|
1742
|
+
}
|
|
1743
|
+
const backgroundClonedGroup = backgroundRoot.cloneNode(true);
|
|
1744
|
+
const clonedGroup = root.cloneNode(true);
|
|
1745
|
+
const transientClonedGroup = transientRoot.cloneNode(true);
|
|
1746
|
+
const transPosition = [
|
|
1747
|
+
-graphCenterX + halfX,
|
|
1748
|
+
-graphCenterY + halfY,
|
|
1749
|
+
];
|
|
1750
|
+
backgroundClonedGroup.setPosition(transPosition);
|
|
1751
|
+
clonedGroup.setPosition(transPosition);
|
|
1752
|
+
transientClonedGroup.setPosition(transPosition);
|
|
1753
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
1754
|
+
vCanvas.appendChild(clonedGroup);
|
|
1755
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
1756
|
+
vCanvas.render();
|
|
1757
|
+
if (!type)
|
|
1758
|
+
type = 'image/png';
|
|
1759
|
+
let dataURL = '';
|
|
1760
|
+
yield vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
1761
|
+
dataURL = url;
|
|
1762
|
+
});
|
|
1763
|
+
return dataURL;
|
|
1764
|
+
});
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Converts a Data URL to an image file and handles the download of the image.
|
|
1768
|
+
* @param dataURL The Data URL of the image to be converted and downloaded.
|
|
1769
|
+
* @param renderer The renderer type ('svg' or other) used for the canvas.
|
|
1770
|
+
* @param link The HTML link element used for image download.
|
|
1771
|
+
* @param fileName The desired name for the downloaded image file.
|
|
1772
|
+
*/
|
|
1773
|
+
dataURLToImage(dataURL, renderer, link, fileName) {
|
|
1774
|
+
if (!dataURL || dataURL === 'data:') {
|
|
1775
|
+
console.error('Download image failed. The graph is too large or there is invalid attribute values in graph items');
|
|
1776
|
+
return;
|
|
1777
|
+
}
|
|
1778
|
+
if (typeof window !== 'undefined') {
|
|
1779
|
+
if (window.Blob && window.URL && renderer !== 'svg') {
|
|
1780
|
+
const arr = dataURL.split(',');
|
|
1781
|
+
let mime = '';
|
|
1782
|
+
if (arr && arr.length > 0) {
|
|
1783
|
+
const match = arr[0].match(/:(.*?);/);
|
|
1784
|
+
// eslint-disable-next-line prefer-destructuring
|
|
1785
|
+
if (match && match.length >= 2)
|
|
1786
|
+
mime = match[1];
|
|
1787
|
+
}
|
|
1788
|
+
const bstr = atob(arr[1]);
|
|
1789
|
+
let n = bstr.length;
|
|
1790
|
+
const u8arr = new Uint8Array(n);
|
|
1791
|
+
while (n--) {
|
|
1792
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
1793
|
+
}
|
|
1794
|
+
const blobObj = new Blob([u8arr], { type: mime });
|
|
1795
|
+
if (window.navigator.msSaveBlob) {
|
|
1796
|
+
window.navigator.msSaveBlob(blobObj, fileName);
|
|
1797
|
+
}
|
|
1798
|
+
else {
|
|
1799
|
+
link.addEventListener('click', () => {
|
|
1800
|
+
link.download = fileName;
|
|
1801
|
+
link.href = window.URL.createObjectURL(blobObj);
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
else {
|
|
1806
|
+
link.addEventListener('click', () => {
|
|
1807
|
+
link.download = fileName;
|
|
1808
|
+
link.href = dataURL;
|
|
1809
|
+
});
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* Initiates the download of the graph as an image with an optional name and type.
|
|
1815
|
+
* @param name The desired name for the downloaded image file (optional).
|
|
1816
|
+
* @param type The type of the image to download (optional, defaults to 'image/png').
|
|
1817
|
+
*/
|
|
1818
|
+
downloadImage(name, type) {
|
|
1819
|
+
const self = this;
|
|
1820
|
+
// self.stopAnimate();
|
|
1821
|
+
const rendererType = this.rendererType;
|
|
1822
|
+
if (!type)
|
|
1823
|
+
type = 'image/png';
|
|
1824
|
+
const fileName = (name || 'graph') +
|
|
1825
|
+
(rendererType === 'svg' ? '.svg' : type.split('/')[1]);
|
|
1826
|
+
const link = document.createElement('a');
|
|
1827
|
+
self.asyncToDataUrl(type, (dataURL) => {
|
|
1828
|
+
this.dataURLToImage(dataURL, rendererType, link, fileName);
|
|
1829
|
+
const e = document.createEvent('MouseEvents');
|
|
1830
|
+
e.initEvent('click', false, false);
|
|
1831
|
+
link.dispatchEvent(e);
|
|
1832
|
+
});
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Initiates the download of the entire graph as an image with optional name, type, and padding configuration.
|
|
1836
|
+
* @param name The desired name for the downloaded image file (optional).
|
|
1837
|
+
* @param type The type of the image to download (optional, defaults to 'image/png').
|
|
1838
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
1839
|
+
*/
|
|
1840
|
+
downloadFullImage(name, type, imageConfig) {
|
|
1841
|
+
const self = this;
|
|
1842
|
+
const rendererType = this.rendererType;
|
|
1843
|
+
if (!type)
|
|
1844
|
+
type = 'image/png';
|
|
1845
|
+
const fileName = (name || 'graph') +
|
|
1846
|
+
(rendererType === 'svg' ? '.svg' : type.split('/')[1]);
|
|
1847
|
+
const link = document.createElement('a');
|
|
1848
|
+
self.asyncToFullDataUrl(type, imageConfig, (dataURL) => {
|
|
1849
|
+
this.dataURLToImage(dataURL, rendererType, link, fileName);
|
|
1850
|
+
const e = document.createEvent('MouseEvents');
|
|
1851
|
+
e.initEvent('click', false, false);
|
|
1852
|
+
link.dispatchEvent(e);
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Asynchronously converts the canvas content to a Data URL of the specified type and invokes the provided callback.
|
|
1857
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
1858
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
1859
|
+
*/
|
|
1860
|
+
asyncToDataUrl(type, callback) {
|
|
1861
|
+
let dataURL = '';
|
|
1862
|
+
if (!type)
|
|
1863
|
+
type = 'image/png';
|
|
1864
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
1865
|
+
yield this.toDataURL(type).then((url) => {
|
|
1866
|
+
dataURL = url;
|
|
1867
|
+
});
|
|
1868
|
+
if (callback)
|
|
1869
|
+
callback(dataURL);
|
|
1870
|
+
}), 16);
|
|
1871
|
+
}
|
|
1872
|
+
/**
|
|
1873
|
+
* Asynchronously converts the entire canvas content to a Data URL of the specified type
|
|
1874
|
+
* with optional padding, and invokes the provided callback.
|
|
1875
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
1876
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
1877
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
1878
|
+
*/
|
|
1879
|
+
asyncToFullDataUrl(type, imageConfig, callback) {
|
|
1880
|
+
let dataURL = '';
|
|
1881
|
+
if (!type)
|
|
1882
|
+
type = 'image/png';
|
|
1883
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
1884
|
+
yield this.toFullDataURL(type, imageConfig).then((url) => {
|
|
1885
|
+
dataURL = url;
|
|
1886
|
+
});
|
|
1887
|
+
if (callback)
|
|
1888
|
+
callback(dataURL);
|
|
1889
|
+
}), 16);
|
|
1890
|
+
}
|
|
1556
1891
|
// ===== history operations =====
|
|
1557
1892
|
/**
|
|
1558
1893
|
* Determine if history (redo/undo) is enabled.
|