@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/lib/runtime/graph.js
CHANGED
|
@@ -24,7 +24,9 @@ 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");
|
|
30
32
|
const controller_1 = require("./controller");
|
|
@@ -44,17 +46,17 @@ class Graph extends event_emitter_1.default {
|
|
|
44
46
|
* Execute a callback without allowing any stacking operations.
|
|
45
47
|
* @param callback
|
|
46
48
|
*/
|
|
47
|
-
this.
|
|
49
|
+
this.executeWithNoStack = (callback) => {
|
|
48
50
|
const history = this.getHistoryPlugin();
|
|
49
|
-
history === null || history === void 0 ? void 0 : history.
|
|
51
|
+
history === null || history === void 0 ? void 0 : history.pauseStack();
|
|
50
52
|
try {
|
|
51
53
|
callback();
|
|
52
54
|
}
|
|
53
55
|
finally {
|
|
54
|
-
history === null || history === void 0 ? void 0 : history.
|
|
56
|
+
history === null || history === void 0 ? void 0 : history.resumeStack();
|
|
55
57
|
}
|
|
56
58
|
};
|
|
57
|
-
this.specification = Object.assign({}, this.defaultSpecification, spec);
|
|
59
|
+
this.specification = Object.assign({}, this.defaultSpecification, this.formatSpecification(spec));
|
|
58
60
|
this.initHooks();
|
|
59
61
|
this.initCanvas();
|
|
60
62
|
this.initControllers();
|
|
@@ -198,16 +200,22 @@ class Graph extends event_emitter_1.default {
|
|
|
198
200
|
}),
|
|
199
201
|
transientupdate: new hooks_1.default({ name: 'transientupdate' }),
|
|
200
202
|
pluginchange: new hooks_1.default({ name: 'pluginchange' }),
|
|
201
|
-
themechange: new hooks_1.default({ name: '
|
|
203
|
+
themechange: new hooks_1.default({ name: 'themechange' }),
|
|
204
|
+
mapperchange: new hooks_1.default({ name: 'mapperchange' }),
|
|
202
205
|
treecollapseexpand: new hooks_1.default({ name: 'treecollapseexpand' }),
|
|
203
206
|
destroy: new hooks_1.default({ name: 'destroy' }),
|
|
204
207
|
};
|
|
205
208
|
}
|
|
209
|
+
formatSpecification(spec) {
|
|
210
|
+
return Object.assign(Object.assign({}, spec), { optimize: Object.assign({ tileBehavior: 2000, tileBehaviorSize: 1000, tileFirstRender: 10000, tileFirstRenderSize: 1000 }, spec.optimize) });
|
|
211
|
+
}
|
|
206
212
|
/**
|
|
207
213
|
* Update the specs(configurations).
|
|
208
214
|
*/
|
|
209
215
|
updateSpecification(spec) {
|
|
210
|
-
|
|
216
|
+
const newSpec = Object.assign(this.specification, this.formatSpecification(spec));
|
|
217
|
+
// TODO: update something
|
|
218
|
+
return newSpec;
|
|
211
219
|
}
|
|
212
220
|
/**
|
|
213
221
|
* Update the theme specs (configurations).
|
|
@@ -228,6 +236,28 @@ class Graph extends event_emitter_1.default {
|
|
|
228
236
|
theme: this.themeController.specification,
|
|
229
237
|
});
|
|
230
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Update the item display mapper for a specific item type.
|
|
241
|
+
* @param {ITEM_TYPE} type - The type of item (node, edge, or combo).
|
|
242
|
+
* @param {NodeMapper | EdgeMapper | ComboMapper} mapper - The mapper to be updated.
|
|
243
|
+
* */
|
|
244
|
+
updateMapper(type, mapper) {
|
|
245
|
+
switch (type) {
|
|
246
|
+
case 'node':
|
|
247
|
+
this.specification.node = mapper;
|
|
248
|
+
break;
|
|
249
|
+
case 'edge':
|
|
250
|
+
this.specification.edge = mapper;
|
|
251
|
+
break;
|
|
252
|
+
case 'combo':
|
|
253
|
+
this.specification.combo = mapper;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
this.hooks.mapperchange.emit({
|
|
257
|
+
type,
|
|
258
|
+
mapper,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
231
261
|
/**
|
|
232
262
|
* Get the copy of specs(configurations).
|
|
233
263
|
* @returns graph specs
|
|
@@ -244,12 +274,17 @@ class Graph extends event_emitter_1.default {
|
|
|
244
274
|
*/
|
|
245
275
|
read(data) {
|
|
246
276
|
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
const { tileFirstRender, tileFirstRenderSize } = this.specification.optimize || {};
|
|
247
278
|
this.hooks.datachange.emit({ data, type: 'replace' });
|
|
248
279
|
const emitRender = () => __awaiter(this, void 0, void 0, function* () {
|
|
249
|
-
this.hooks.render.
|
|
280
|
+
yield this.hooks.render.emitLinearAsync({
|
|
250
281
|
graphCore: this.dataController.graphCore,
|
|
251
282
|
theme: this.themeController.specification,
|
|
252
283
|
transientCanvas: this.transientCanvas,
|
|
284
|
+
tileOptimize: {
|
|
285
|
+
tileFirstRender,
|
|
286
|
+
tileFirstRenderSize,
|
|
287
|
+
},
|
|
253
288
|
});
|
|
254
289
|
this.emit('afterrender');
|
|
255
290
|
this.once('afterlayout', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -296,11 +331,16 @@ class Graph extends event_emitter_1.default {
|
|
|
296
331
|
*/
|
|
297
332
|
changeData(data, type = 'mergeReplace') {
|
|
298
333
|
return __awaiter(this, void 0, void 0, function* () {
|
|
334
|
+
const { tileFirstRender, tileFirstRenderSize } = this.specification.optimize || {};
|
|
299
335
|
this.hooks.datachange.emit({ data, type });
|
|
300
336
|
this.hooks.render.emit({
|
|
301
337
|
graphCore: this.dataController.graphCore,
|
|
302
338
|
theme: this.themeController.specification,
|
|
303
339
|
transientCanvas: this.transientCanvas,
|
|
340
|
+
tileOptimize: {
|
|
341
|
+
tileFirstRender,
|
|
342
|
+
tileFirstRenderSize,
|
|
343
|
+
},
|
|
304
344
|
});
|
|
305
345
|
this.emit('afterrender');
|
|
306
346
|
yield this.layout();
|
|
@@ -311,11 +351,11 @@ class Graph extends event_emitter_1.default {
|
|
|
311
351
|
* @returns
|
|
312
352
|
*/
|
|
313
353
|
clear() {
|
|
314
|
-
this.
|
|
354
|
+
this.startHistoryBatch();
|
|
315
355
|
this.removeData('edge', this.getAllEdgesData().map((edge) => edge.id));
|
|
316
356
|
this.removeData('node', this.getAllNodesData().map((node) => node.id));
|
|
317
357
|
this.removeData('combo', this.getAllCombosData().map((combo) => combo.id));
|
|
318
|
-
this.
|
|
358
|
+
this.stopHistoryBatch();
|
|
319
359
|
}
|
|
320
360
|
getViewportCenter() {
|
|
321
361
|
const { width, height } = this.canvas.getConfig();
|
|
@@ -323,9 +363,11 @@ class Graph extends event_emitter_1.default {
|
|
|
323
363
|
}
|
|
324
364
|
transform(options, effectTiming) {
|
|
325
365
|
return __awaiter(this, void 0, void 0, function* () {
|
|
366
|
+
const { tileLodSize } = this.specification.optimize || {};
|
|
326
367
|
yield this.hooks.viewportchange.emitLinearAsync({
|
|
327
368
|
transform: options,
|
|
328
369
|
effectTiming,
|
|
370
|
+
tileLodSize,
|
|
329
371
|
});
|
|
330
372
|
this.emit('viewportchange', options);
|
|
331
373
|
});
|
|
@@ -544,6 +586,25 @@ class Graph extends event_emitter_1.default {
|
|
|
544
586
|
this.specification.height = size[1];
|
|
545
587
|
this.canvas.resize(size[0], size[1]);
|
|
546
588
|
}
|
|
589
|
+
getCanvasRange() {
|
|
590
|
+
const [width, height] = this.getSize();
|
|
591
|
+
const leftTop = this.getCanvasByViewport({ x: 0, y: 0 });
|
|
592
|
+
const rightBottom = this.getCanvasByViewport({ x: width, y: height });
|
|
593
|
+
return {
|
|
594
|
+
min: [leftTop.x, leftTop.y, leftTop.z],
|
|
595
|
+
max: [rightBottom.x, rightBottom.y, rightBottom.z],
|
|
596
|
+
center: [
|
|
597
|
+
(leftTop.x + rightBottom.x) / 2,
|
|
598
|
+
(leftTop.y + rightBottom.y) / 2,
|
|
599
|
+
(leftTop.z + rightBottom.z) / 2,
|
|
600
|
+
],
|
|
601
|
+
halfExtents: [
|
|
602
|
+
(rightBottom.x - leftTop.x) / 2,
|
|
603
|
+
(rightBottom.y - leftTop.y) / 2,
|
|
604
|
+
(rightBottom.z - leftTop.z) / 2,
|
|
605
|
+
],
|
|
606
|
+
};
|
|
607
|
+
}
|
|
547
608
|
/**
|
|
548
609
|
* Get the rendering coordinate according to the canvas dom (viewport) coordinate.
|
|
549
610
|
* @param Point rendering coordinate
|
|
@@ -718,23 +779,26 @@ class Graph extends event_emitter_1.default {
|
|
|
718
779
|
// data controller and item controller subscribe additem in order
|
|
719
780
|
const { graphCore } = this.dataController;
|
|
720
781
|
const { specification } = this.themeController;
|
|
782
|
+
// debugger;
|
|
721
783
|
graphCore.once('changed', (event) => {
|
|
722
784
|
if (!event.changes.length)
|
|
723
785
|
return;
|
|
724
786
|
const changes = event.changes;
|
|
725
|
-
|
|
726
|
-
type: itemType,
|
|
727
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
728
|
-
graphCore,
|
|
729
|
-
theme: specification,
|
|
730
|
-
});
|
|
731
|
-
this.emit('afteritemchange', {
|
|
787
|
+
const timingParameters = {
|
|
732
788
|
type: itemType,
|
|
733
789
|
action: 'add',
|
|
734
790
|
models,
|
|
735
791
|
apiName: 'addData',
|
|
736
792
|
changes,
|
|
793
|
+
};
|
|
794
|
+
this.emit('beforeitemchange', timingParameters);
|
|
795
|
+
this.hooks.itemchange.emit({
|
|
796
|
+
type: itemType,
|
|
797
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
798
|
+
graphCore,
|
|
799
|
+
theme: specification,
|
|
737
800
|
});
|
|
801
|
+
this.emit('afteritemchange', timingParameters);
|
|
738
802
|
});
|
|
739
803
|
const modelArr = (0, util_1.isArray)(models) ? models : [models];
|
|
740
804
|
const data = { nodes: [], edges: [], combos: [] };
|
|
@@ -763,19 +827,21 @@ class Graph extends event_emitter_1.default {
|
|
|
763
827
|
if (!event.changes.length)
|
|
764
828
|
return;
|
|
765
829
|
const changes = event.changes;
|
|
766
|
-
|
|
767
|
-
type: itemType,
|
|
768
|
-
changes: event.changes,
|
|
769
|
-
graphCore,
|
|
770
|
-
theme: specification,
|
|
771
|
-
});
|
|
772
|
-
this.emit('afteritemchange', {
|
|
830
|
+
const timingParameters = {
|
|
773
831
|
type: itemType,
|
|
774
832
|
action: 'remove',
|
|
775
833
|
ids: idArr,
|
|
776
834
|
apiName: 'removeData',
|
|
777
835
|
changes,
|
|
836
|
+
};
|
|
837
|
+
this.emit('beforeitemchange', timingParameters);
|
|
838
|
+
this.hooks.itemchange.emit({
|
|
839
|
+
type: itemType,
|
|
840
|
+
changes: event.changes,
|
|
841
|
+
graphCore,
|
|
842
|
+
theme: specification,
|
|
778
843
|
});
|
|
844
|
+
this.emit('afteritemchange', timingParameters);
|
|
779
845
|
});
|
|
780
846
|
this.hooks.datachange.emit({
|
|
781
847
|
data,
|
|
@@ -843,19 +909,21 @@ class Graph extends event_emitter_1.default {
|
|
|
843
909
|
const { specification } = this.themeController;
|
|
844
910
|
graphCore.once('changed', (event) => {
|
|
845
911
|
const changes = this.extendChanges((0, util_1.clone)(event.changes));
|
|
846
|
-
|
|
847
|
-
type: itemType,
|
|
848
|
-
changes: event.changes,
|
|
849
|
-
graphCore,
|
|
850
|
-
theme: specification,
|
|
851
|
-
});
|
|
852
|
-
this.emit('afteritemchange', {
|
|
912
|
+
const timingParameters = {
|
|
853
913
|
type: itemType,
|
|
854
914
|
action: 'update',
|
|
855
915
|
models,
|
|
856
916
|
apiName: 'updateData',
|
|
857
917
|
changes,
|
|
918
|
+
};
|
|
919
|
+
this.emit('beforeitemchange', timingParameters);
|
|
920
|
+
this.hooks.itemchange.emit({
|
|
921
|
+
type: itemType,
|
|
922
|
+
changes: event.changes,
|
|
923
|
+
graphCore,
|
|
924
|
+
theme: specification,
|
|
858
925
|
});
|
|
926
|
+
this.emit('afteritemchange', timingParameters);
|
|
859
927
|
});
|
|
860
928
|
this.hooks.datachange.emit({
|
|
861
929
|
data,
|
|
@@ -902,6 +970,15 @@ class Graph extends event_emitter_1.default {
|
|
|
902
970
|
if (!event.changes.length)
|
|
903
971
|
return;
|
|
904
972
|
const changes = event.changes.filter((change) => !(0, util_1.isEqual)(change.newValue, change.oldValue));
|
|
973
|
+
const timingParameters = {
|
|
974
|
+
type,
|
|
975
|
+
action: 'updatePosition',
|
|
976
|
+
upsertAncestors,
|
|
977
|
+
models,
|
|
978
|
+
apiName: 'updatePosition',
|
|
979
|
+
changes,
|
|
980
|
+
};
|
|
981
|
+
this.emit('beforeitemchange', timingParameters);
|
|
905
982
|
this.hooks.itemchange.emit({
|
|
906
983
|
type,
|
|
907
984
|
changes: event.changes,
|
|
@@ -912,14 +989,7 @@ class Graph extends event_emitter_1.default {
|
|
|
912
989
|
animate: !disableAnimate,
|
|
913
990
|
callback,
|
|
914
991
|
});
|
|
915
|
-
this.emit('afteritemchange',
|
|
916
|
-
type,
|
|
917
|
-
action: 'updatePosition',
|
|
918
|
-
upsertAncestors,
|
|
919
|
-
models,
|
|
920
|
-
apiName: 'updatePosition',
|
|
921
|
-
changes,
|
|
922
|
-
});
|
|
992
|
+
this.emit('afteritemchange', timingParameters);
|
|
923
993
|
});
|
|
924
994
|
this.hooks.datachange.emit({
|
|
925
995
|
data: {
|
|
@@ -979,7 +1049,7 @@ class Graph extends event_emitter_1.default {
|
|
|
979
1049
|
* @returns
|
|
980
1050
|
* @group Item
|
|
981
1051
|
*/
|
|
982
|
-
hideItem(ids, disableAnimate = false) {
|
|
1052
|
+
hideItem(ids, disableAnimate = false, keepKeyShape = false) {
|
|
983
1053
|
const idArr = (0, util_1.isArray)(ids) ? ids : [ids];
|
|
984
1054
|
if ((0, util_1.isEmpty)(idArr))
|
|
985
1055
|
return;
|
|
@@ -992,6 +1062,7 @@ class Graph extends event_emitter_1.default {
|
|
|
992
1062
|
value: false,
|
|
993
1063
|
graphCore: this.dataController.graphCore,
|
|
994
1064
|
animate: !disableAnimate,
|
|
1065
|
+
keepKeyShape,
|
|
995
1066
|
});
|
|
996
1067
|
this.emit('afteritemvisibilitychange', {
|
|
997
1068
|
ids,
|
|
@@ -999,6 +1070,7 @@ class Graph extends event_emitter_1.default {
|
|
|
999
1070
|
animate: !disableAnimate,
|
|
1000
1071
|
action: 'updateVisibility',
|
|
1001
1072
|
apiName: 'hideItem',
|
|
1073
|
+
keepKeyShape,
|
|
1002
1074
|
changes,
|
|
1003
1075
|
});
|
|
1004
1076
|
}
|
|
@@ -1166,19 +1238,21 @@ class Graph extends event_emitter_1.default {
|
|
|
1166
1238
|
if (!event.changes.length)
|
|
1167
1239
|
return;
|
|
1168
1240
|
const changes = event.changes;
|
|
1169
|
-
|
|
1170
|
-
type: 'combo',
|
|
1171
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
1172
|
-
graphCore,
|
|
1173
|
-
theme: specification,
|
|
1174
|
-
});
|
|
1175
|
-
this.emit('afteritemchange', {
|
|
1241
|
+
const timingParameters = {
|
|
1176
1242
|
type: 'combo',
|
|
1177
1243
|
action: 'add',
|
|
1178
1244
|
models: [model],
|
|
1179
1245
|
apiName: 'addCombo',
|
|
1180
1246
|
changes,
|
|
1247
|
+
};
|
|
1248
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1249
|
+
this.hooks.itemchange.emit({
|
|
1250
|
+
type: 'combo',
|
|
1251
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
1252
|
+
graphCore,
|
|
1253
|
+
theme: specification,
|
|
1181
1254
|
});
|
|
1255
|
+
this.emit('afteritemchange', timingParameters);
|
|
1182
1256
|
});
|
|
1183
1257
|
const data = {
|
|
1184
1258
|
nodes: [],
|
|
@@ -1200,7 +1274,7 @@ class Graph extends event_emitter_1.default {
|
|
|
1200
1274
|
*/
|
|
1201
1275
|
collapseCombo(comboIds) {
|
|
1202
1276
|
const ids = (0, util_1.isArray)(comboIds) ? comboIds : [comboIds];
|
|
1203
|
-
this.
|
|
1277
|
+
this.executeWithNoStack(() => {
|
|
1204
1278
|
this.updateData('combo', ids.map((id) => ({ id, data: { collapsed: true } })));
|
|
1205
1279
|
});
|
|
1206
1280
|
this.emit('aftercollapsecombo', {
|
|
@@ -1217,7 +1291,7 @@ class Graph extends event_emitter_1.default {
|
|
|
1217
1291
|
*/
|
|
1218
1292
|
expandCombo(comboIds) {
|
|
1219
1293
|
const ids = (0, util_1.isArray)(comboIds) ? comboIds : [comboIds];
|
|
1220
|
-
this.
|
|
1294
|
+
this.executeWithNoStack(() => {
|
|
1221
1295
|
this.updateData('combo', ids.map((id) => ({ id, data: { collapsed: false } })));
|
|
1222
1296
|
});
|
|
1223
1297
|
this.emit('afterexpandcombo', {
|
|
@@ -1242,16 +1316,7 @@ class Graph extends event_emitter_1.default {
|
|
|
1242
1316
|
if (!event.changes.length)
|
|
1243
1317
|
return;
|
|
1244
1318
|
const changes = this.extendChanges((0, util_1.clone)(event.changes));
|
|
1245
|
-
|
|
1246
|
-
type: 'combo',
|
|
1247
|
-
changes: event.changes,
|
|
1248
|
-
graphCore,
|
|
1249
|
-
theme: specification,
|
|
1250
|
-
upsertAncestors,
|
|
1251
|
-
action: 'updatePosition',
|
|
1252
|
-
callback,
|
|
1253
|
-
});
|
|
1254
|
-
this.emit('afteritemchange', {
|
|
1319
|
+
const timingParameters = {
|
|
1255
1320
|
type: 'combo',
|
|
1256
1321
|
ids: idArr,
|
|
1257
1322
|
dx,
|
|
@@ -1260,7 +1325,18 @@ class Graph extends event_emitter_1.default {
|
|
|
1260
1325
|
upsertAncestors,
|
|
1261
1326
|
apiName: 'moveCombo',
|
|
1262
1327
|
changes,
|
|
1328
|
+
};
|
|
1329
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1330
|
+
this.hooks.itemchange.emit({
|
|
1331
|
+
type: 'combo',
|
|
1332
|
+
changes: event.changes,
|
|
1333
|
+
graphCore,
|
|
1334
|
+
theme: specification,
|
|
1335
|
+
upsertAncestors,
|
|
1336
|
+
action: 'updatePosition',
|
|
1337
|
+
callback,
|
|
1263
1338
|
});
|
|
1339
|
+
this.emit('afteritemchange', timingParameters);
|
|
1264
1340
|
});
|
|
1265
1341
|
this.hooks.datachange.emit({
|
|
1266
1342
|
data: {
|
|
@@ -1345,6 +1421,14 @@ class Graph extends event_emitter_1.default {
|
|
|
1345
1421
|
getMode() {
|
|
1346
1422
|
return this.interactionController.getMode();
|
|
1347
1423
|
}
|
|
1424
|
+
/**
|
|
1425
|
+
* Set the cursor. But the cursor in item's style has higher priority.
|
|
1426
|
+
* @param cursor
|
|
1427
|
+
*/
|
|
1428
|
+
setCursor(cursor) {
|
|
1429
|
+
this.canvas.setCursor(cursor);
|
|
1430
|
+
this.transientCanvas.setCursor(cursor);
|
|
1431
|
+
}
|
|
1348
1432
|
/**
|
|
1349
1433
|
* Add behavior(s) to mode(s).
|
|
1350
1434
|
* @param behaviors behavior names or configs
|
|
@@ -1515,6 +1599,274 @@ class Graph extends event_emitter_1.default {
|
|
|
1515
1599
|
});
|
|
1516
1600
|
return this.itemController.getTransient(String(id));
|
|
1517
1601
|
}
|
|
1602
|
+
// ===== download operations =====
|
|
1603
|
+
/**
|
|
1604
|
+
* Asynchronously generates a Data URL representation of the canvas content, including
|
|
1605
|
+
* background, main content, and transient canvas.
|
|
1606
|
+
* @param The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
1607
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
1608
|
+
*/
|
|
1609
|
+
toDataURL(type) {
|
|
1610
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1611
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
1612
|
+
const canvas = this.canvas;
|
|
1613
|
+
const transientCanvas = this.transientCanvas;
|
|
1614
|
+
const rendererType = this.rendererType;
|
|
1615
|
+
const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
1616
|
+
const width = this.getSize()[0];
|
|
1617
|
+
const height = this.getSize()[1];
|
|
1618
|
+
const vContainerDOM = (0, dom_util_1.createDom)('<div id="virtual-image"></div>');
|
|
1619
|
+
const vCanvas = (0, canvas_1.createCanvas)(rendererType, vContainerDOM, width, height, pixelRatio);
|
|
1620
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
1621
|
+
let bgRect;
|
|
1622
|
+
if (rendererType !== 'svg') {
|
|
1623
|
+
bgRect = new g_1.Rect({
|
|
1624
|
+
style: {
|
|
1625
|
+
x: 0,
|
|
1626
|
+
y: 0,
|
|
1627
|
+
z: -1,
|
|
1628
|
+
width: vCanvasContextService.getDomElement().width,
|
|
1629
|
+
height: vCanvasContextService.getDomElement().height,
|
|
1630
|
+
//@ts-ignore
|
|
1631
|
+
fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
|
|
1632
|
+
},
|
|
1633
|
+
});
|
|
1634
|
+
vCanvas.appendChild(bgRect);
|
|
1635
|
+
}
|
|
1636
|
+
const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
|
|
1637
|
+
const clonedGroup = canvas.getRoot().cloneNode(true);
|
|
1638
|
+
const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
|
|
1639
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
1640
|
+
vCanvas.appendChild(clonedGroup);
|
|
1641
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
1642
|
+
vCanvas.render();
|
|
1643
|
+
if (!type)
|
|
1644
|
+
type = 'image/png';
|
|
1645
|
+
let dataURL = '';
|
|
1646
|
+
yield vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
1647
|
+
dataURL = url;
|
|
1648
|
+
});
|
|
1649
|
+
return dataURL;
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Asynchronously generates a Data URL representation of the full canvas content,
|
|
1654
|
+
* including background, main content, and transient canvas, with optional padding.
|
|
1655
|
+
* @param type The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
1656
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
1657
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
1658
|
+
*/
|
|
1659
|
+
toFullDataURL(type, imageConfig) {
|
|
1660
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1661
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
1662
|
+
const canvas = this.canvas;
|
|
1663
|
+
const transientCanvas = this.transientCanvas;
|
|
1664
|
+
const backgroundRoot = canvas.getRoot();
|
|
1665
|
+
const root = canvas.getRoot();
|
|
1666
|
+
const transientRoot = transientCanvas.getRoot();
|
|
1667
|
+
const rendererType = this.rendererType;
|
|
1668
|
+
const backgroundBBox = backgroundRoot.getBBox();
|
|
1669
|
+
const BBox = root.getBBox();
|
|
1670
|
+
const transientBBox = transientRoot.getBBox();
|
|
1671
|
+
let padding = imageConfig ? imageConfig.padding : undefined;
|
|
1672
|
+
if (!padding) {
|
|
1673
|
+
padding = [0, 0, 0, 0];
|
|
1674
|
+
}
|
|
1675
|
+
else if ((0, util_1.isNumber)(padding)) {
|
|
1676
|
+
padding = [padding, padding, padding, padding];
|
|
1677
|
+
}
|
|
1678
|
+
const left = (transientBBox.left
|
|
1679
|
+
? backgroundBBox.left
|
|
1680
|
+
? Math.min(backgroundBBox.left, BBox.left, transientBBox.left)
|
|
1681
|
+
: Math.min(BBox.left, transientBBox.left)
|
|
1682
|
+
: BBox.left) - padding[3];
|
|
1683
|
+
const right = (transientBBox.right
|
|
1684
|
+
? backgroundBBox.right
|
|
1685
|
+
? Math.max(backgroundBBox.right, BBox.right, transientBBox.right)
|
|
1686
|
+
: Math.max(BBox.right, transientBBox.right)
|
|
1687
|
+
: BBox.right) + padding[1];
|
|
1688
|
+
const top = (transientBBox.top
|
|
1689
|
+
? backgroundBBox.top
|
|
1690
|
+
? Math.min(backgroundBBox.top, BBox.top, transientBBox.top)
|
|
1691
|
+
: Math.min(BBox.top, transientBBox.top)
|
|
1692
|
+
: BBox.top) - padding[0];
|
|
1693
|
+
const bottom = (transientBBox.bottom
|
|
1694
|
+
? backgroundBBox.bottom
|
|
1695
|
+
? Math.max(backgroundBBox.bottom, BBox.bottom, transientBBox.bottom)
|
|
1696
|
+
: Math.max(BBox.bottom, transientBBox.bottom)
|
|
1697
|
+
: BBox.bottom) + padding[2];
|
|
1698
|
+
const graphCenterX = (left + right) / 2;
|
|
1699
|
+
const graphCenterY = (top + bottom) / 2;
|
|
1700
|
+
const halfX = (right - left) / 2;
|
|
1701
|
+
const halfY = (bottom - top) / 2;
|
|
1702
|
+
const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
1703
|
+
const vWidth = halfX * 2;
|
|
1704
|
+
const vHeight = halfY * 2;
|
|
1705
|
+
const vContainerDOM = (0, dom_util_1.createDom)('<div id="virtual-image"></div>');
|
|
1706
|
+
const vCanvas = (0, canvas_1.createCanvas)(rendererType, vContainerDOM, vWidth, vHeight, pixelRatio);
|
|
1707
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
1708
|
+
if (rendererType !== 'svg') {
|
|
1709
|
+
const bgRect = new g_1.Rect({
|
|
1710
|
+
style: {
|
|
1711
|
+
x: 0,
|
|
1712
|
+
y: 0,
|
|
1713
|
+
z: -1,
|
|
1714
|
+
width: vCanvasContextService.getDomElement().width,
|
|
1715
|
+
height: vCanvasContextService.getDomElement().height,
|
|
1716
|
+
//@ts-ignore
|
|
1717
|
+
fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
|
|
1718
|
+
},
|
|
1719
|
+
});
|
|
1720
|
+
vCanvas.appendChild(bgRect);
|
|
1721
|
+
}
|
|
1722
|
+
const backgroundClonedGroup = backgroundRoot.cloneNode(true);
|
|
1723
|
+
const clonedGroup = root.cloneNode(true);
|
|
1724
|
+
const transientClonedGroup = transientRoot.cloneNode(true);
|
|
1725
|
+
const transPosition = [
|
|
1726
|
+
-graphCenterX + halfX,
|
|
1727
|
+
-graphCenterY + halfY,
|
|
1728
|
+
];
|
|
1729
|
+
backgroundClonedGroup.setPosition(transPosition);
|
|
1730
|
+
clonedGroup.setPosition(transPosition);
|
|
1731
|
+
transientClonedGroup.setPosition(transPosition);
|
|
1732
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
1733
|
+
vCanvas.appendChild(clonedGroup);
|
|
1734
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
1735
|
+
vCanvas.render();
|
|
1736
|
+
if (!type)
|
|
1737
|
+
type = 'image/png';
|
|
1738
|
+
let dataURL = '';
|
|
1739
|
+
yield vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
1740
|
+
dataURL = url;
|
|
1741
|
+
});
|
|
1742
|
+
return dataURL;
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
/**
|
|
1746
|
+
* Converts a Data URL to an image file and handles the download of the image.
|
|
1747
|
+
* @param dataURL The Data URL of the image to be converted and downloaded.
|
|
1748
|
+
* @param renderer The renderer type ('svg' or other) used for the canvas.
|
|
1749
|
+
* @param link The HTML link element used for image download.
|
|
1750
|
+
* @param fileName The desired name for the downloaded image file.
|
|
1751
|
+
*/
|
|
1752
|
+
dataURLToImage(dataURL, renderer, link, fileName) {
|
|
1753
|
+
if (!dataURL || dataURL === 'data:') {
|
|
1754
|
+
console.error('Download image failed. The graph is too large or there is invalid attribute values in graph items');
|
|
1755
|
+
return;
|
|
1756
|
+
}
|
|
1757
|
+
if (typeof window !== 'undefined') {
|
|
1758
|
+
if (window.Blob && window.URL && renderer !== 'svg') {
|
|
1759
|
+
const arr = dataURL.split(',');
|
|
1760
|
+
let mime = '';
|
|
1761
|
+
if (arr && arr.length > 0) {
|
|
1762
|
+
const match = arr[0].match(/:(.*?);/);
|
|
1763
|
+
// eslint-disable-next-line prefer-destructuring
|
|
1764
|
+
if (match && match.length >= 2)
|
|
1765
|
+
mime = match[1];
|
|
1766
|
+
}
|
|
1767
|
+
const bstr = atob(arr[1]);
|
|
1768
|
+
let n = bstr.length;
|
|
1769
|
+
const u8arr = new Uint8Array(n);
|
|
1770
|
+
while (n--) {
|
|
1771
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
1772
|
+
}
|
|
1773
|
+
const blobObj = new Blob([u8arr], { type: mime });
|
|
1774
|
+
if (window.navigator.msSaveBlob) {
|
|
1775
|
+
window.navigator.msSaveBlob(blobObj, fileName);
|
|
1776
|
+
}
|
|
1777
|
+
else {
|
|
1778
|
+
link.addEventListener('click', () => {
|
|
1779
|
+
link.download = fileName;
|
|
1780
|
+
link.href = window.URL.createObjectURL(blobObj);
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
else {
|
|
1785
|
+
link.addEventListener('click', () => {
|
|
1786
|
+
link.download = fileName;
|
|
1787
|
+
link.href = dataURL;
|
|
1788
|
+
});
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
/**
|
|
1793
|
+
* Initiates the download of the graph as an image with an optional name and type.
|
|
1794
|
+
* @param name The desired name for the downloaded image file (optional).
|
|
1795
|
+
* @param type The type of the image to download (optional, defaults to 'image/png').
|
|
1796
|
+
*/
|
|
1797
|
+
downloadImage(name, type) {
|
|
1798
|
+
const self = this;
|
|
1799
|
+
// self.stopAnimate();
|
|
1800
|
+
const rendererType = this.rendererType;
|
|
1801
|
+
if (!type)
|
|
1802
|
+
type = 'image/png';
|
|
1803
|
+
const fileName = (name || 'graph') +
|
|
1804
|
+
(rendererType === 'svg' ? '.svg' : type.split('/')[1]);
|
|
1805
|
+
const link = document.createElement('a');
|
|
1806
|
+
self.asyncToDataUrl(type, (dataURL) => {
|
|
1807
|
+
this.dataURLToImage(dataURL, rendererType, link, fileName);
|
|
1808
|
+
const e = document.createEvent('MouseEvents');
|
|
1809
|
+
e.initEvent('click', false, false);
|
|
1810
|
+
link.dispatchEvent(e);
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* Initiates the download of the entire graph as an image with optional name, type, and padding configuration.
|
|
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
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
1818
|
+
*/
|
|
1819
|
+
downloadFullImage(name, type, imageConfig) {
|
|
1820
|
+
const self = this;
|
|
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.asyncToFullDataUrl(type, imageConfig, (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
|
+
* Asynchronously converts the canvas content to a Data URL of the specified type and invokes the provided callback.
|
|
1836
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
1837
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
1838
|
+
*/
|
|
1839
|
+
asyncToDataUrl(type, callback) {
|
|
1840
|
+
let dataURL = '';
|
|
1841
|
+
if (!type)
|
|
1842
|
+
type = 'image/png';
|
|
1843
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
1844
|
+
yield this.toDataURL(type).then((url) => {
|
|
1845
|
+
dataURL = url;
|
|
1846
|
+
});
|
|
1847
|
+
if (callback)
|
|
1848
|
+
callback(dataURL);
|
|
1849
|
+
}), 16);
|
|
1850
|
+
}
|
|
1851
|
+
/**
|
|
1852
|
+
* Asynchronously converts the entire canvas content to a Data URL of the specified type
|
|
1853
|
+
* with optional padding, and invokes the provided callback.
|
|
1854
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
1855
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
1856
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
1857
|
+
*/
|
|
1858
|
+
asyncToFullDataUrl(type, imageConfig, callback) {
|
|
1859
|
+
let dataURL = '';
|
|
1860
|
+
if (!type)
|
|
1861
|
+
type = 'image/png';
|
|
1862
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
1863
|
+
yield this.toFullDataURL(type, imageConfig).then((url) => {
|
|
1864
|
+
dataURL = url;
|
|
1865
|
+
});
|
|
1866
|
+
if (callback)
|
|
1867
|
+
callback(dataURL);
|
|
1868
|
+
}), 16);
|
|
1869
|
+
}
|
|
1518
1870
|
// ===== history operations =====
|
|
1519
1871
|
/**
|
|
1520
1872
|
* Determine if history (redo/undo) is enabled.
|
|
@@ -1536,16 +1888,16 @@ class Graph extends event_emitter_1.default {
|
|
|
1536
1888
|
/**
|
|
1537
1889
|
* Pause stacking operation.
|
|
1538
1890
|
*/
|
|
1539
|
-
|
|
1891
|
+
pauseStack() {
|
|
1540
1892
|
const history = this.getHistoryPlugin();
|
|
1541
|
-
return history === null || history === void 0 ? void 0 : history.
|
|
1893
|
+
return history === null || history === void 0 ? void 0 : history.pauseStack();
|
|
1542
1894
|
}
|
|
1543
1895
|
/**
|
|
1544
1896
|
* Resume stacking operation.
|
|
1545
1897
|
*/
|
|
1546
|
-
|
|
1898
|
+
resumeStack() {
|
|
1547
1899
|
const history = this.getHistoryPlugin();
|
|
1548
|
-
return history === null || history === void 0 ? void 0 : history.
|
|
1900
|
+
return history === null || history === void 0 ? void 0 : history.resumeStack();
|
|
1549
1901
|
}
|
|
1550
1902
|
/**
|
|
1551
1903
|
* Retrieve the current redo stack which consists of operations that could be undone
|
|
@@ -1602,38 +1954,38 @@ class Graph extends event_emitter_1.default {
|
|
|
1602
1954
|
return history === null || history === void 0 ? void 0 : history.canRedo();
|
|
1603
1955
|
}
|
|
1604
1956
|
/**
|
|
1605
|
-
* Begin a
|
|
1606
|
-
* Any operations performed between `
|
|
1957
|
+
* Begin a historyBatch operation.
|
|
1958
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
1607
1959
|
* treated as a single operation when undoing or redoing.
|
|
1608
1960
|
*/
|
|
1609
|
-
|
|
1961
|
+
startHistoryBatch() {
|
|
1610
1962
|
const history = this.getHistoryPlugin();
|
|
1611
|
-
history === null || history === void 0 ? void 0 : history.
|
|
1963
|
+
history === null || history === void 0 ? void 0 : history.startHistoryBatch();
|
|
1612
1964
|
}
|
|
1613
1965
|
/**
|
|
1614
|
-
* End a
|
|
1615
|
-
* Any operations performed between `
|
|
1966
|
+
* End a historyBatch operation.
|
|
1967
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
1616
1968
|
* treated as a single operation when undoing or redoing.
|
|
1617
1969
|
*/
|
|
1618
|
-
|
|
1970
|
+
stopHistoryBatch() {
|
|
1619
1971
|
const history = this.getHistoryPlugin();
|
|
1620
|
-
history === null || history === void 0 ? void 0 : history.
|
|
1972
|
+
history === null || history === void 0 ? void 0 : history.stopHistoryBatch();
|
|
1621
1973
|
}
|
|
1622
1974
|
/**
|
|
1623
1975
|
* Execute a provided function within a batched context
|
|
1624
1976
|
* All operations performed inside callback will be treated as a composite operation
|
|
1625
|
-
* more convenient way without manually invoking `
|
|
1977
|
+
* more convenient way without manually invoking `startHistoryBatch` and `stopHistoryBatch`.
|
|
1626
1978
|
* @param callback The func containing operations to be batched together.
|
|
1627
1979
|
*/
|
|
1628
|
-
|
|
1980
|
+
historyBatch(callback) {
|
|
1629
1981
|
const history = this.getHistoryPlugin();
|
|
1630
|
-
history === null || history === void 0 ? void 0 : history.
|
|
1982
|
+
history === null || history === void 0 ? void 0 : history.historyBatch(callback);
|
|
1631
1983
|
}
|
|
1632
1984
|
/**
|
|
1633
1985
|
* Clear history stack
|
|
1634
1986
|
* @param {StackType} stackType undo/redo stack
|
|
1635
1987
|
*/
|
|
1636
|
-
|
|
1988
|
+
cleanHistory(stackType) {
|
|
1637
1989
|
const history = this.getHistoryPlugin();
|
|
1638
1990
|
if (!stackType)
|
|
1639
1991
|
return history === null || history === void 0 ? void 0 : history.clear();
|
|
@@ -1685,7 +2037,7 @@ class Graph extends event_emitter_1.default {
|
|
|
1685
2037
|
this.backgroundCanvas.destroy();
|
|
1686
2038
|
this.transientCanvas.destroy();
|
|
1687
2039
|
// clear history stack
|
|
1688
|
-
this.
|
|
2040
|
+
this.cleanHistory();
|
|
1689
2041
|
callback === null || callback === void 0 ? void 0 : callback();
|
|
1690
2042
|
// }, 500);
|
|
1691
2043
|
this.hooks.destroy.emit({});
|