@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/esm/runtime/graph.js
CHANGED
|
@@ -19,7 +19,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
21
|
import EventEmitter from '@antv/event-emitter';
|
|
22
|
+
import { Rect, } from '@antv/g';
|
|
22
23
|
import { clone, groupBy, isArray, isEmpty, isEqual, isNil, isNumber, isObject, isString, map, } from '@antv/util';
|
|
24
|
+
import { createDom } from '@antv/dom-util';
|
|
23
25
|
import { changeRenderer, createCanvas } from '../util/canvas';
|
|
24
26
|
import { formatPadding } from '../util/shape';
|
|
25
27
|
import { DataController, ExtensionController, InteractionController, ItemController, LayoutController, ThemeController, ViewportController, } from './controller';
|
|
@@ -39,17 +41,17 @@ export default class Graph extends EventEmitter {
|
|
|
39
41
|
* Execute a callback without allowing any stacking operations.
|
|
40
42
|
* @param callback
|
|
41
43
|
*/
|
|
42
|
-
this.
|
|
44
|
+
this.executeWithNoStack = (callback) => {
|
|
43
45
|
const history = this.getHistoryPlugin();
|
|
44
|
-
history === null || history === void 0 ? void 0 : history.
|
|
46
|
+
history === null || history === void 0 ? void 0 : history.pauseStack();
|
|
45
47
|
try {
|
|
46
48
|
callback();
|
|
47
49
|
}
|
|
48
50
|
finally {
|
|
49
|
-
history === null || history === void 0 ? void 0 : history.
|
|
51
|
+
history === null || history === void 0 ? void 0 : history.resumeStack();
|
|
50
52
|
}
|
|
51
53
|
};
|
|
52
|
-
this.specification = Object.assign({}, this.defaultSpecification, spec);
|
|
54
|
+
this.specification = Object.assign({}, this.defaultSpecification, this.formatSpecification(spec));
|
|
53
55
|
this.initHooks();
|
|
54
56
|
this.initCanvas();
|
|
55
57
|
this.initControllers();
|
|
@@ -193,16 +195,22 @@ export default class Graph extends EventEmitter {
|
|
|
193
195
|
}),
|
|
194
196
|
transientupdate: new Hook({ name: 'transientupdate' }),
|
|
195
197
|
pluginchange: new Hook({ name: 'pluginchange' }),
|
|
196
|
-
themechange: new Hook({ name: '
|
|
198
|
+
themechange: new Hook({ name: 'themechange' }),
|
|
199
|
+
mapperchange: new Hook({ name: 'mapperchange' }),
|
|
197
200
|
treecollapseexpand: new Hook({ name: 'treecollapseexpand' }),
|
|
198
201
|
destroy: new Hook({ name: 'destroy' }),
|
|
199
202
|
};
|
|
200
203
|
}
|
|
204
|
+
formatSpecification(spec) {
|
|
205
|
+
return Object.assign(Object.assign({}, spec), { optimize: Object.assign({ tileBehavior: 2000, tileBehaviorSize: 1000, tileFirstRender: 10000, tileFirstRenderSize: 1000 }, spec.optimize) });
|
|
206
|
+
}
|
|
201
207
|
/**
|
|
202
208
|
* Update the specs(configurations).
|
|
203
209
|
*/
|
|
204
210
|
updateSpecification(spec) {
|
|
205
|
-
|
|
211
|
+
const newSpec = Object.assign(this.specification, this.formatSpecification(spec));
|
|
212
|
+
// TODO: update something
|
|
213
|
+
return newSpec;
|
|
206
214
|
}
|
|
207
215
|
/**
|
|
208
216
|
* Update the theme specs (configurations).
|
|
@@ -223,6 +231,28 @@ export default class Graph extends EventEmitter {
|
|
|
223
231
|
theme: this.themeController.specification,
|
|
224
232
|
});
|
|
225
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Update the item display mapper for a specific item type.
|
|
236
|
+
* @param {ITEM_TYPE} type - The type of item (node, edge, or combo).
|
|
237
|
+
* @param {NodeMapper | EdgeMapper | ComboMapper} mapper - The mapper to be updated.
|
|
238
|
+
* */
|
|
239
|
+
updateMapper(type, mapper) {
|
|
240
|
+
switch (type) {
|
|
241
|
+
case 'node':
|
|
242
|
+
this.specification.node = mapper;
|
|
243
|
+
break;
|
|
244
|
+
case 'edge':
|
|
245
|
+
this.specification.edge = mapper;
|
|
246
|
+
break;
|
|
247
|
+
case 'combo':
|
|
248
|
+
this.specification.combo = mapper;
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
this.hooks.mapperchange.emit({
|
|
252
|
+
type,
|
|
253
|
+
mapper,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
226
256
|
/**
|
|
227
257
|
* Get the copy of specs(configurations).
|
|
228
258
|
* @returns graph specs
|
|
@@ -239,12 +269,17 @@ export default class Graph extends EventEmitter {
|
|
|
239
269
|
*/
|
|
240
270
|
read(data) {
|
|
241
271
|
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
const { tileFirstRender, tileFirstRenderSize } = this.specification.optimize || {};
|
|
242
273
|
this.hooks.datachange.emit({ data, type: 'replace' });
|
|
243
274
|
const emitRender = () => __awaiter(this, void 0, void 0, function* () {
|
|
244
|
-
this.hooks.render.
|
|
275
|
+
yield this.hooks.render.emitLinearAsync({
|
|
245
276
|
graphCore: this.dataController.graphCore,
|
|
246
277
|
theme: this.themeController.specification,
|
|
247
278
|
transientCanvas: this.transientCanvas,
|
|
279
|
+
tileOptimize: {
|
|
280
|
+
tileFirstRender,
|
|
281
|
+
tileFirstRenderSize,
|
|
282
|
+
},
|
|
248
283
|
});
|
|
249
284
|
this.emit('afterrender');
|
|
250
285
|
this.once('afterlayout', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -291,11 +326,16 @@ export default class Graph extends EventEmitter {
|
|
|
291
326
|
*/
|
|
292
327
|
changeData(data, type = 'mergeReplace') {
|
|
293
328
|
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
+
const { tileFirstRender, tileFirstRenderSize } = this.specification.optimize || {};
|
|
294
330
|
this.hooks.datachange.emit({ data, type });
|
|
295
331
|
this.hooks.render.emit({
|
|
296
332
|
graphCore: this.dataController.graphCore,
|
|
297
333
|
theme: this.themeController.specification,
|
|
298
334
|
transientCanvas: this.transientCanvas,
|
|
335
|
+
tileOptimize: {
|
|
336
|
+
tileFirstRender,
|
|
337
|
+
tileFirstRenderSize,
|
|
338
|
+
},
|
|
299
339
|
});
|
|
300
340
|
this.emit('afterrender');
|
|
301
341
|
yield this.layout();
|
|
@@ -306,11 +346,11 @@ export default class Graph extends EventEmitter {
|
|
|
306
346
|
* @returns
|
|
307
347
|
*/
|
|
308
348
|
clear() {
|
|
309
|
-
this.
|
|
349
|
+
this.startHistoryBatch();
|
|
310
350
|
this.removeData('edge', this.getAllEdgesData().map((edge) => edge.id));
|
|
311
351
|
this.removeData('node', this.getAllNodesData().map((node) => node.id));
|
|
312
352
|
this.removeData('combo', this.getAllCombosData().map((combo) => combo.id));
|
|
313
|
-
this.
|
|
353
|
+
this.stopHistoryBatch();
|
|
314
354
|
}
|
|
315
355
|
getViewportCenter() {
|
|
316
356
|
const { width, height } = this.canvas.getConfig();
|
|
@@ -318,9 +358,11 @@ export default class Graph extends EventEmitter {
|
|
|
318
358
|
}
|
|
319
359
|
transform(options, effectTiming) {
|
|
320
360
|
return __awaiter(this, void 0, void 0, function* () {
|
|
361
|
+
const { tileLodSize } = this.specification.optimize || {};
|
|
321
362
|
yield this.hooks.viewportchange.emitLinearAsync({
|
|
322
363
|
transform: options,
|
|
323
364
|
effectTiming,
|
|
365
|
+
tileLodSize,
|
|
324
366
|
});
|
|
325
367
|
this.emit('viewportchange', options);
|
|
326
368
|
});
|
|
@@ -539,6 +581,25 @@ export default class Graph extends EventEmitter {
|
|
|
539
581
|
this.specification.height = size[1];
|
|
540
582
|
this.canvas.resize(size[0], size[1]);
|
|
541
583
|
}
|
|
584
|
+
getCanvasRange() {
|
|
585
|
+
const [width, height] = this.getSize();
|
|
586
|
+
const leftTop = this.getCanvasByViewport({ x: 0, y: 0 });
|
|
587
|
+
const rightBottom = this.getCanvasByViewport({ x: width, y: height });
|
|
588
|
+
return {
|
|
589
|
+
min: [leftTop.x, leftTop.y, leftTop.z],
|
|
590
|
+
max: [rightBottom.x, rightBottom.y, rightBottom.z],
|
|
591
|
+
center: [
|
|
592
|
+
(leftTop.x + rightBottom.x) / 2,
|
|
593
|
+
(leftTop.y + rightBottom.y) / 2,
|
|
594
|
+
(leftTop.z + rightBottom.z) / 2,
|
|
595
|
+
],
|
|
596
|
+
halfExtents: [
|
|
597
|
+
(rightBottom.x - leftTop.x) / 2,
|
|
598
|
+
(rightBottom.y - leftTop.y) / 2,
|
|
599
|
+
(rightBottom.z - leftTop.z) / 2,
|
|
600
|
+
],
|
|
601
|
+
};
|
|
602
|
+
}
|
|
542
603
|
/**
|
|
543
604
|
* Get the rendering coordinate according to the canvas dom (viewport) coordinate.
|
|
544
605
|
* @param Point rendering coordinate
|
|
@@ -713,23 +774,26 @@ export default class Graph extends EventEmitter {
|
|
|
713
774
|
// data controller and item controller subscribe additem in order
|
|
714
775
|
const { graphCore } = this.dataController;
|
|
715
776
|
const { specification } = this.themeController;
|
|
777
|
+
// debugger;
|
|
716
778
|
graphCore.once('changed', (event) => {
|
|
717
779
|
if (!event.changes.length)
|
|
718
780
|
return;
|
|
719
781
|
const changes = event.changes;
|
|
720
|
-
|
|
721
|
-
type: itemType,
|
|
722
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
723
|
-
graphCore,
|
|
724
|
-
theme: specification,
|
|
725
|
-
});
|
|
726
|
-
this.emit('afteritemchange', {
|
|
782
|
+
const timingParameters = {
|
|
727
783
|
type: itemType,
|
|
728
784
|
action: 'add',
|
|
729
785
|
models,
|
|
730
786
|
apiName: 'addData',
|
|
731
787
|
changes,
|
|
788
|
+
};
|
|
789
|
+
this.emit('beforeitemchange', timingParameters);
|
|
790
|
+
this.hooks.itemchange.emit({
|
|
791
|
+
type: itemType,
|
|
792
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
793
|
+
graphCore,
|
|
794
|
+
theme: specification,
|
|
732
795
|
});
|
|
796
|
+
this.emit('afteritemchange', timingParameters);
|
|
733
797
|
});
|
|
734
798
|
const modelArr = isArray(models) ? models : [models];
|
|
735
799
|
const data = { nodes: [], edges: [], combos: [] };
|
|
@@ -758,19 +822,21 @@ export default class Graph extends EventEmitter {
|
|
|
758
822
|
if (!event.changes.length)
|
|
759
823
|
return;
|
|
760
824
|
const changes = event.changes;
|
|
761
|
-
|
|
762
|
-
type: itemType,
|
|
763
|
-
changes: event.changes,
|
|
764
|
-
graphCore,
|
|
765
|
-
theme: specification,
|
|
766
|
-
});
|
|
767
|
-
this.emit('afteritemchange', {
|
|
825
|
+
const timingParameters = {
|
|
768
826
|
type: itemType,
|
|
769
827
|
action: 'remove',
|
|
770
828
|
ids: idArr,
|
|
771
829
|
apiName: 'removeData',
|
|
772
830
|
changes,
|
|
831
|
+
};
|
|
832
|
+
this.emit('beforeitemchange', timingParameters);
|
|
833
|
+
this.hooks.itemchange.emit({
|
|
834
|
+
type: itemType,
|
|
835
|
+
changes: event.changes,
|
|
836
|
+
graphCore,
|
|
837
|
+
theme: specification,
|
|
773
838
|
});
|
|
839
|
+
this.emit('afteritemchange', timingParameters);
|
|
774
840
|
});
|
|
775
841
|
this.hooks.datachange.emit({
|
|
776
842
|
data,
|
|
@@ -838,19 +904,21 @@ export default class Graph extends EventEmitter {
|
|
|
838
904
|
const { specification } = this.themeController;
|
|
839
905
|
graphCore.once('changed', (event) => {
|
|
840
906
|
const changes = this.extendChanges(clone(event.changes));
|
|
841
|
-
|
|
842
|
-
type: itemType,
|
|
843
|
-
changes: event.changes,
|
|
844
|
-
graphCore,
|
|
845
|
-
theme: specification,
|
|
846
|
-
});
|
|
847
|
-
this.emit('afteritemchange', {
|
|
907
|
+
const timingParameters = {
|
|
848
908
|
type: itemType,
|
|
849
909
|
action: 'update',
|
|
850
910
|
models,
|
|
851
911
|
apiName: 'updateData',
|
|
852
912
|
changes,
|
|
913
|
+
};
|
|
914
|
+
this.emit('beforeitemchange', timingParameters);
|
|
915
|
+
this.hooks.itemchange.emit({
|
|
916
|
+
type: itemType,
|
|
917
|
+
changes: event.changes,
|
|
918
|
+
graphCore,
|
|
919
|
+
theme: specification,
|
|
853
920
|
});
|
|
921
|
+
this.emit('afteritemchange', timingParameters);
|
|
854
922
|
});
|
|
855
923
|
this.hooks.datachange.emit({
|
|
856
924
|
data,
|
|
@@ -897,6 +965,15 @@ export default class Graph extends EventEmitter {
|
|
|
897
965
|
if (!event.changes.length)
|
|
898
966
|
return;
|
|
899
967
|
const changes = event.changes.filter((change) => !isEqual(change.newValue, change.oldValue));
|
|
968
|
+
const timingParameters = {
|
|
969
|
+
type,
|
|
970
|
+
action: 'updatePosition',
|
|
971
|
+
upsertAncestors,
|
|
972
|
+
models,
|
|
973
|
+
apiName: 'updatePosition',
|
|
974
|
+
changes,
|
|
975
|
+
};
|
|
976
|
+
this.emit('beforeitemchange', timingParameters);
|
|
900
977
|
this.hooks.itemchange.emit({
|
|
901
978
|
type,
|
|
902
979
|
changes: event.changes,
|
|
@@ -907,14 +984,7 @@ export default class Graph extends EventEmitter {
|
|
|
907
984
|
animate: !disableAnimate,
|
|
908
985
|
callback,
|
|
909
986
|
});
|
|
910
|
-
this.emit('afteritemchange',
|
|
911
|
-
type,
|
|
912
|
-
action: 'updatePosition',
|
|
913
|
-
upsertAncestors,
|
|
914
|
-
models,
|
|
915
|
-
apiName: 'updatePosition',
|
|
916
|
-
changes,
|
|
917
|
-
});
|
|
987
|
+
this.emit('afteritemchange', timingParameters);
|
|
918
988
|
});
|
|
919
989
|
this.hooks.datachange.emit({
|
|
920
990
|
data: {
|
|
@@ -974,7 +1044,7 @@ export default class Graph extends EventEmitter {
|
|
|
974
1044
|
* @returns
|
|
975
1045
|
* @group Item
|
|
976
1046
|
*/
|
|
977
|
-
hideItem(ids, disableAnimate = false) {
|
|
1047
|
+
hideItem(ids, disableAnimate = false, keepKeyShape = false) {
|
|
978
1048
|
const idArr = isArray(ids) ? ids : [ids];
|
|
979
1049
|
if (isEmpty(idArr))
|
|
980
1050
|
return;
|
|
@@ -987,6 +1057,7 @@ export default class Graph extends EventEmitter {
|
|
|
987
1057
|
value: false,
|
|
988
1058
|
graphCore: this.dataController.graphCore,
|
|
989
1059
|
animate: !disableAnimate,
|
|
1060
|
+
keepKeyShape,
|
|
990
1061
|
});
|
|
991
1062
|
this.emit('afteritemvisibilitychange', {
|
|
992
1063
|
ids,
|
|
@@ -994,6 +1065,7 @@ export default class Graph extends EventEmitter {
|
|
|
994
1065
|
animate: !disableAnimate,
|
|
995
1066
|
action: 'updateVisibility',
|
|
996
1067
|
apiName: 'hideItem',
|
|
1068
|
+
keepKeyShape,
|
|
997
1069
|
changes,
|
|
998
1070
|
});
|
|
999
1071
|
}
|
|
@@ -1161,19 +1233,21 @@ export default class Graph extends EventEmitter {
|
|
|
1161
1233
|
if (!event.changes.length)
|
|
1162
1234
|
return;
|
|
1163
1235
|
const changes = event.changes;
|
|
1164
|
-
|
|
1165
|
-
type: 'combo',
|
|
1166
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
1167
|
-
graphCore,
|
|
1168
|
-
theme: specification,
|
|
1169
|
-
});
|
|
1170
|
-
this.emit('afteritemchange', {
|
|
1236
|
+
const timingParameters = {
|
|
1171
1237
|
type: 'combo',
|
|
1172
1238
|
action: 'add',
|
|
1173
1239
|
models: [model],
|
|
1174
1240
|
apiName: 'addCombo',
|
|
1175
1241
|
changes,
|
|
1242
|
+
};
|
|
1243
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1244
|
+
this.hooks.itemchange.emit({
|
|
1245
|
+
type: 'combo',
|
|
1246
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
1247
|
+
graphCore,
|
|
1248
|
+
theme: specification,
|
|
1176
1249
|
});
|
|
1250
|
+
this.emit('afteritemchange', timingParameters);
|
|
1177
1251
|
});
|
|
1178
1252
|
const data = {
|
|
1179
1253
|
nodes: [],
|
|
@@ -1195,7 +1269,7 @@ export default class Graph extends EventEmitter {
|
|
|
1195
1269
|
*/
|
|
1196
1270
|
collapseCombo(comboIds) {
|
|
1197
1271
|
const ids = isArray(comboIds) ? comboIds : [comboIds];
|
|
1198
|
-
this.
|
|
1272
|
+
this.executeWithNoStack(() => {
|
|
1199
1273
|
this.updateData('combo', ids.map((id) => ({ id, data: { collapsed: true } })));
|
|
1200
1274
|
});
|
|
1201
1275
|
this.emit('aftercollapsecombo', {
|
|
@@ -1212,7 +1286,7 @@ export default class Graph extends EventEmitter {
|
|
|
1212
1286
|
*/
|
|
1213
1287
|
expandCombo(comboIds) {
|
|
1214
1288
|
const ids = isArray(comboIds) ? comboIds : [comboIds];
|
|
1215
|
-
this.
|
|
1289
|
+
this.executeWithNoStack(() => {
|
|
1216
1290
|
this.updateData('combo', ids.map((id) => ({ id, data: { collapsed: false } })));
|
|
1217
1291
|
});
|
|
1218
1292
|
this.emit('afterexpandcombo', {
|
|
@@ -1237,16 +1311,7 @@ export default class Graph extends EventEmitter {
|
|
|
1237
1311
|
if (!event.changes.length)
|
|
1238
1312
|
return;
|
|
1239
1313
|
const changes = this.extendChanges(clone(event.changes));
|
|
1240
|
-
|
|
1241
|
-
type: 'combo',
|
|
1242
|
-
changes: event.changes,
|
|
1243
|
-
graphCore,
|
|
1244
|
-
theme: specification,
|
|
1245
|
-
upsertAncestors,
|
|
1246
|
-
action: 'updatePosition',
|
|
1247
|
-
callback,
|
|
1248
|
-
});
|
|
1249
|
-
this.emit('afteritemchange', {
|
|
1314
|
+
const timingParameters = {
|
|
1250
1315
|
type: 'combo',
|
|
1251
1316
|
ids: idArr,
|
|
1252
1317
|
dx,
|
|
@@ -1255,7 +1320,18 @@ export default class Graph extends EventEmitter {
|
|
|
1255
1320
|
upsertAncestors,
|
|
1256
1321
|
apiName: 'moveCombo',
|
|
1257
1322
|
changes,
|
|
1323
|
+
};
|
|
1324
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1325
|
+
this.hooks.itemchange.emit({
|
|
1326
|
+
type: 'combo',
|
|
1327
|
+
changes: event.changes,
|
|
1328
|
+
graphCore,
|
|
1329
|
+
theme: specification,
|
|
1330
|
+
upsertAncestors,
|
|
1331
|
+
action: 'updatePosition',
|
|
1332
|
+
callback,
|
|
1258
1333
|
});
|
|
1334
|
+
this.emit('afteritemchange', timingParameters);
|
|
1259
1335
|
});
|
|
1260
1336
|
this.hooks.datachange.emit({
|
|
1261
1337
|
data: {
|
|
@@ -1340,6 +1416,14 @@ export default class Graph extends EventEmitter {
|
|
|
1340
1416
|
getMode() {
|
|
1341
1417
|
return this.interactionController.getMode();
|
|
1342
1418
|
}
|
|
1419
|
+
/**
|
|
1420
|
+
* Set the cursor. But the cursor in item's style has higher priority.
|
|
1421
|
+
* @param cursor
|
|
1422
|
+
*/
|
|
1423
|
+
setCursor(cursor) {
|
|
1424
|
+
this.canvas.setCursor(cursor);
|
|
1425
|
+
this.transientCanvas.setCursor(cursor);
|
|
1426
|
+
}
|
|
1343
1427
|
/**
|
|
1344
1428
|
* Add behavior(s) to mode(s).
|
|
1345
1429
|
* @param behaviors behavior names or configs
|
|
@@ -1510,6 +1594,274 @@ export default class Graph extends EventEmitter {
|
|
|
1510
1594
|
});
|
|
1511
1595
|
return this.itemController.getTransient(String(id));
|
|
1512
1596
|
}
|
|
1597
|
+
// ===== download operations =====
|
|
1598
|
+
/**
|
|
1599
|
+
* Asynchronously generates a Data URL representation of the canvas content, including
|
|
1600
|
+
* background, main content, and transient canvas.
|
|
1601
|
+
* @param The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
1602
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
1603
|
+
*/
|
|
1604
|
+
toDataURL(type) {
|
|
1605
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1606
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
1607
|
+
const canvas = this.canvas;
|
|
1608
|
+
const transientCanvas = this.transientCanvas;
|
|
1609
|
+
const rendererType = this.rendererType;
|
|
1610
|
+
const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
1611
|
+
const width = this.getSize()[0];
|
|
1612
|
+
const height = this.getSize()[1];
|
|
1613
|
+
const vContainerDOM = createDom('<div id="virtual-image"></div>');
|
|
1614
|
+
const vCanvas = createCanvas(rendererType, vContainerDOM, width, height, pixelRatio);
|
|
1615
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
1616
|
+
let bgRect;
|
|
1617
|
+
if (rendererType !== 'svg') {
|
|
1618
|
+
bgRect = new Rect({
|
|
1619
|
+
style: {
|
|
1620
|
+
x: 0,
|
|
1621
|
+
y: 0,
|
|
1622
|
+
z: -1,
|
|
1623
|
+
width: vCanvasContextService.getDomElement().width,
|
|
1624
|
+
height: vCanvasContextService.getDomElement().height,
|
|
1625
|
+
//@ts-ignore
|
|
1626
|
+
fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
|
|
1627
|
+
},
|
|
1628
|
+
});
|
|
1629
|
+
vCanvas.appendChild(bgRect);
|
|
1630
|
+
}
|
|
1631
|
+
const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
|
|
1632
|
+
const clonedGroup = canvas.getRoot().cloneNode(true);
|
|
1633
|
+
const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
|
|
1634
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
1635
|
+
vCanvas.appendChild(clonedGroup);
|
|
1636
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
1637
|
+
vCanvas.render();
|
|
1638
|
+
if (!type)
|
|
1639
|
+
type = 'image/png';
|
|
1640
|
+
let dataURL = '';
|
|
1641
|
+
yield vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
1642
|
+
dataURL = url;
|
|
1643
|
+
});
|
|
1644
|
+
return dataURL;
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
/**
|
|
1648
|
+
* Asynchronously generates a Data URL representation of the full canvas content,
|
|
1649
|
+
* including background, main content, and transient canvas, with optional padding.
|
|
1650
|
+
* @param type The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
1651
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
1652
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
1653
|
+
*/
|
|
1654
|
+
toFullDataURL(type, imageConfig) {
|
|
1655
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1656
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
1657
|
+
const canvas = this.canvas;
|
|
1658
|
+
const transientCanvas = this.transientCanvas;
|
|
1659
|
+
const backgroundRoot = canvas.getRoot();
|
|
1660
|
+
const root = canvas.getRoot();
|
|
1661
|
+
const transientRoot = transientCanvas.getRoot();
|
|
1662
|
+
const rendererType = this.rendererType;
|
|
1663
|
+
const backgroundBBox = backgroundRoot.getBBox();
|
|
1664
|
+
const BBox = root.getBBox();
|
|
1665
|
+
const transientBBox = transientRoot.getBBox();
|
|
1666
|
+
let padding = imageConfig ? imageConfig.padding : undefined;
|
|
1667
|
+
if (!padding) {
|
|
1668
|
+
padding = [0, 0, 0, 0];
|
|
1669
|
+
}
|
|
1670
|
+
else if (isNumber(padding)) {
|
|
1671
|
+
padding = [padding, padding, padding, padding];
|
|
1672
|
+
}
|
|
1673
|
+
const left = (transientBBox.left
|
|
1674
|
+
? backgroundBBox.left
|
|
1675
|
+
? Math.min(backgroundBBox.left, BBox.left, transientBBox.left)
|
|
1676
|
+
: Math.min(BBox.left, transientBBox.left)
|
|
1677
|
+
: BBox.left) - padding[3];
|
|
1678
|
+
const right = (transientBBox.right
|
|
1679
|
+
? backgroundBBox.right
|
|
1680
|
+
? Math.max(backgroundBBox.right, BBox.right, transientBBox.right)
|
|
1681
|
+
: Math.max(BBox.right, transientBBox.right)
|
|
1682
|
+
: BBox.right) + padding[1];
|
|
1683
|
+
const top = (transientBBox.top
|
|
1684
|
+
? backgroundBBox.top
|
|
1685
|
+
? Math.min(backgroundBBox.top, BBox.top, transientBBox.top)
|
|
1686
|
+
: Math.min(BBox.top, transientBBox.top)
|
|
1687
|
+
: BBox.top) - padding[0];
|
|
1688
|
+
const bottom = (transientBBox.bottom
|
|
1689
|
+
? backgroundBBox.bottom
|
|
1690
|
+
? Math.max(backgroundBBox.bottom, BBox.bottom, transientBBox.bottom)
|
|
1691
|
+
: Math.max(BBox.bottom, transientBBox.bottom)
|
|
1692
|
+
: BBox.bottom) + padding[2];
|
|
1693
|
+
const graphCenterX = (left + right) / 2;
|
|
1694
|
+
const graphCenterY = (top + bottom) / 2;
|
|
1695
|
+
const halfX = (right - left) / 2;
|
|
1696
|
+
const halfY = (bottom - top) / 2;
|
|
1697
|
+
const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
1698
|
+
const vWidth = halfX * 2;
|
|
1699
|
+
const vHeight = halfY * 2;
|
|
1700
|
+
const vContainerDOM = createDom('<div id="virtual-image"></div>');
|
|
1701
|
+
const vCanvas = createCanvas(rendererType, vContainerDOM, vWidth, vHeight, pixelRatio);
|
|
1702
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
1703
|
+
if (rendererType !== 'svg') {
|
|
1704
|
+
const bgRect = new Rect({
|
|
1705
|
+
style: {
|
|
1706
|
+
x: 0,
|
|
1707
|
+
y: 0,
|
|
1708
|
+
z: -1,
|
|
1709
|
+
width: vCanvasContextService.getDomElement().width,
|
|
1710
|
+
height: vCanvasContextService.getDomElement().height,
|
|
1711
|
+
//@ts-ignore
|
|
1712
|
+
fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
|
|
1713
|
+
},
|
|
1714
|
+
});
|
|
1715
|
+
vCanvas.appendChild(bgRect);
|
|
1716
|
+
}
|
|
1717
|
+
const backgroundClonedGroup = backgroundRoot.cloneNode(true);
|
|
1718
|
+
const clonedGroup = root.cloneNode(true);
|
|
1719
|
+
const transientClonedGroup = transientRoot.cloneNode(true);
|
|
1720
|
+
const transPosition = [
|
|
1721
|
+
-graphCenterX + halfX,
|
|
1722
|
+
-graphCenterY + halfY,
|
|
1723
|
+
];
|
|
1724
|
+
backgroundClonedGroup.setPosition(transPosition);
|
|
1725
|
+
clonedGroup.setPosition(transPosition);
|
|
1726
|
+
transientClonedGroup.setPosition(transPosition);
|
|
1727
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
1728
|
+
vCanvas.appendChild(clonedGroup);
|
|
1729
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
1730
|
+
vCanvas.render();
|
|
1731
|
+
if (!type)
|
|
1732
|
+
type = 'image/png';
|
|
1733
|
+
let dataURL = '';
|
|
1734
|
+
yield vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
1735
|
+
dataURL = url;
|
|
1736
|
+
});
|
|
1737
|
+
return dataURL;
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Converts a Data URL to an image file and handles the download of the image.
|
|
1742
|
+
* @param dataURL The Data URL of the image to be converted and downloaded.
|
|
1743
|
+
* @param renderer The renderer type ('svg' or other) used for the canvas.
|
|
1744
|
+
* @param link The HTML link element used for image download.
|
|
1745
|
+
* @param fileName The desired name for the downloaded image file.
|
|
1746
|
+
*/
|
|
1747
|
+
dataURLToImage(dataURL, renderer, link, fileName) {
|
|
1748
|
+
if (!dataURL || dataURL === 'data:') {
|
|
1749
|
+
console.error('Download image failed. The graph is too large or there is invalid attribute values in graph items');
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1752
|
+
if (typeof window !== 'undefined') {
|
|
1753
|
+
if (window.Blob && window.URL && renderer !== 'svg') {
|
|
1754
|
+
const arr = dataURL.split(',');
|
|
1755
|
+
let mime = '';
|
|
1756
|
+
if (arr && arr.length > 0) {
|
|
1757
|
+
const match = arr[0].match(/:(.*?);/);
|
|
1758
|
+
// eslint-disable-next-line prefer-destructuring
|
|
1759
|
+
if (match && match.length >= 2)
|
|
1760
|
+
mime = match[1];
|
|
1761
|
+
}
|
|
1762
|
+
const bstr = atob(arr[1]);
|
|
1763
|
+
let n = bstr.length;
|
|
1764
|
+
const u8arr = new Uint8Array(n);
|
|
1765
|
+
while (n--) {
|
|
1766
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
1767
|
+
}
|
|
1768
|
+
const blobObj = new Blob([u8arr], { type: mime });
|
|
1769
|
+
if (window.navigator.msSaveBlob) {
|
|
1770
|
+
window.navigator.msSaveBlob(blobObj, fileName);
|
|
1771
|
+
}
|
|
1772
|
+
else {
|
|
1773
|
+
link.addEventListener('click', () => {
|
|
1774
|
+
link.download = fileName;
|
|
1775
|
+
link.href = window.URL.createObjectURL(blobObj);
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
else {
|
|
1780
|
+
link.addEventListener('click', () => {
|
|
1781
|
+
link.download = fileName;
|
|
1782
|
+
link.href = dataURL;
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* Initiates the download of the graph as an image with an optional name and type.
|
|
1789
|
+
* @param name The desired name for the downloaded image file (optional).
|
|
1790
|
+
* @param type The type of the image to download (optional, defaults to 'image/png').
|
|
1791
|
+
*/
|
|
1792
|
+
downloadImage(name, type) {
|
|
1793
|
+
const self = this;
|
|
1794
|
+
// self.stopAnimate();
|
|
1795
|
+
const rendererType = this.rendererType;
|
|
1796
|
+
if (!type)
|
|
1797
|
+
type = 'image/png';
|
|
1798
|
+
const fileName = (name || 'graph') +
|
|
1799
|
+
(rendererType === 'svg' ? '.svg' : type.split('/')[1]);
|
|
1800
|
+
const link = document.createElement('a');
|
|
1801
|
+
self.asyncToDataUrl(type, (dataURL) => {
|
|
1802
|
+
this.dataURLToImage(dataURL, rendererType, link, fileName);
|
|
1803
|
+
const e = document.createEvent('MouseEvents');
|
|
1804
|
+
e.initEvent('click', false, false);
|
|
1805
|
+
link.dispatchEvent(e);
|
|
1806
|
+
});
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Initiates the download of the entire graph as an image with optional name, type, and padding configuration.
|
|
1810
|
+
* @param name The desired name for the downloaded image file (optional).
|
|
1811
|
+
* @param type The type of the image to download (optional, defaults to 'image/png').
|
|
1812
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
1813
|
+
*/
|
|
1814
|
+
downloadFullImage(name, type, imageConfig) {
|
|
1815
|
+
const self = this;
|
|
1816
|
+
const rendererType = this.rendererType;
|
|
1817
|
+
if (!type)
|
|
1818
|
+
type = 'image/png';
|
|
1819
|
+
const fileName = (name || 'graph') +
|
|
1820
|
+
(rendererType === 'svg' ? '.svg' : type.split('/')[1]);
|
|
1821
|
+
const link = document.createElement('a');
|
|
1822
|
+
self.asyncToFullDataUrl(type, imageConfig, (dataURL) => {
|
|
1823
|
+
this.dataURLToImage(dataURL, rendererType, link, fileName);
|
|
1824
|
+
const e = document.createEvent('MouseEvents');
|
|
1825
|
+
e.initEvent('click', false, false);
|
|
1826
|
+
link.dispatchEvent(e);
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
/**
|
|
1830
|
+
* Asynchronously converts the canvas content to a Data URL of the specified type and invokes the provided callback.
|
|
1831
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
1832
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
1833
|
+
*/
|
|
1834
|
+
asyncToDataUrl(type, callback) {
|
|
1835
|
+
let dataURL = '';
|
|
1836
|
+
if (!type)
|
|
1837
|
+
type = 'image/png';
|
|
1838
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
1839
|
+
yield this.toDataURL(type).then((url) => {
|
|
1840
|
+
dataURL = url;
|
|
1841
|
+
});
|
|
1842
|
+
if (callback)
|
|
1843
|
+
callback(dataURL);
|
|
1844
|
+
}), 16);
|
|
1845
|
+
}
|
|
1846
|
+
/**
|
|
1847
|
+
* Asynchronously converts the entire canvas content to a Data URL of the specified type
|
|
1848
|
+
* with optional padding, and invokes the provided callback.
|
|
1849
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
1850
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
1851
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
1852
|
+
*/
|
|
1853
|
+
asyncToFullDataUrl(type, imageConfig, callback) {
|
|
1854
|
+
let dataURL = '';
|
|
1855
|
+
if (!type)
|
|
1856
|
+
type = 'image/png';
|
|
1857
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
1858
|
+
yield this.toFullDataURL(type, imageConfig).then((url) => {
|
|
1859
|
+
dataURL = url;
|
|
1860
|
+
});
|
|
1861
|
+
if (callback)
|
|
1862
|
+
callback(dataURL);
|
|
1863
|
+
}), 16);
|
|
1864
|
+
}
|
|
1513
1865
|
// ===== history operations =====
|
|
1514
1866
|
/**
|
|
1515
1867
|
* Determine if history (redo/undo) is enabled.
|
|
@@ -1531,16 +1883,16 @@ export default class Graph extends EventEmitter {
|
|
|
1531
1883
|
/**
|
|
1532
1884
|
* Pause stacking operation.
|
|
1533
1885
|
*/
|
|
1534
|
-
|
|
1886
|
+
pauseStack() {
|
|
1535
1887
|
const history = this.getHistoryPlugin();
|
|
1536
|
-
return history === null || history === void 0 ? void 0 : history.
|
|
1888
|
+
return history === null || history === void 0 ? void 0 : history.pauseStack();
|
|
1537
1889
|
}
|
|
1538
1890
|
/**
|
|
1539
1891
|
* Resume stacking operation.
|
|
1540
1892
|
*/
|
|
1541
|
-
|
|
1893
|
+
resumeStack() {
|
|
1542
1894
|
const history = this.getHistoryPlugin();
|
|
1543
|
-
return history === null || history === void 0 ? void 0 : history.
|
|
1895
|
+
return history === null || history === void 0 ? void 0 : history.resumeStack();
|
|
1544
1896
|
}
|
|
1545
1897
|
/**
|
|
1546
1898
|
* Retrieve the current redo stack which consists of operations that could be undone
|
|
@@ -1597,38 +1949,38 @@ export default class Graph extends EventEmitter {
|
|
|
1597
1949
|
return history === null || history === void 0 ? void 0 : history.canRedo();
|
|
1598
1950
|
}
|
|
1599
1951
|
/**
|
|
1600
|
-
* Begin a
|
|
1601
|
-
* Any operations performed between `
|
|
1952
|
+
* Begin a historyBatch operation.
|
|
1953
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
1602
1954
|
* treated as a single operation when undoing or redoing.
|
|
1603
1955
|
*/
|
|
1604
|
-
|
|
1956
|
+
startHistoryBatch() {
|
|
1605
1957
|
const history = this.getHistoryPlugin();
|
|
1606
|
-
history === null || history === void 0 ? void 0 : history.
|
|
1958
|
+
history === null || history === void 0 ? void 0 : history.startHistoryBatch();
|
|
1607
1959
|
}
|
|
1608
1960
|
/**
|
|
1609
|
-
* End a
|
|
1610
|
-
* Any operations performed between `
|
|
1961
|
+
* End a historyBatch operation.
|
|
1962
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
1611
1963
|
* treated as a single operation when undoing or redoing.
|
|
1612
1964
|
*/
|
|
1613
|
-
|
|
1965
|
+
stopHistoryBatch() {
|
|
1614
1966
|
const history = this.getHistoryPlugin();
|
|
1615
|
-
history === null || history === void 0 ? void 0 : history.
|
|
1967
|
+
history === null || history === void 0 ? void 0 : history.stopHistoryBatch();
|
|
1616
1968
|
}
|
|
1617
1969
|
/**
|
|
1618
1970
|
* Execute a provided function within a batched context
|
|
1619
1971
|
* All operations performed inside callback will be treated as a composite operation
|
|
1620
|
-
* more convenient way without manually invoking `
|
|
1972
|
+
* more convenient way without manually invoking `startHistoryBatch` and `stopHistoryBatch`.
|
|
1621
1973
|
* @param callback The func containing operations to be batched together.
|
|
1622
1974
|
*/
|
|
1623
|
-
|
|
1975
|
+
historyBatch(callback) {
|
|
1624
1976
|
const history = this.getHistoryPlugin();
|
|
1625
|
-
history === null || history === void 0 ? void 0 : history.
|
|
1977
|
+
history === null || history === void 0 ? void 0 : history.historyBatch(callback);
|
|
1626
1978
|
}
|
|
1627
1979
|
/**
|
|
1628
1980
|
* Clear history stack
|
|
1629
1981
|
* @param {StackType} stackType undo/redo stack
|
|
1630
1982
|
*/
|
|
1631
|
-
|
|
1983
|
+
cleanHistory(stackType) {
|
|
1632
1984
|
const history = this.getHistoryPlugin();
|
|
1633
1985
|
if (!stackType)
|
|
1634
1986
|
return history === null || history === void 0 ? void 0 : history.clear();
|
|
@@ -1680,7 +2032,7 @@ export default class Graph extends EventEmitter {
|
|
|
1680
2032
|
this.backgroundCanvas.destroy();
|
|
1681
2033
|
this.transientCanvas.destroy();
|
|
1682
2034
|
// clear history stack
|
|
1683
|
-
this.
|
|
2035
|
+
this.cleanHistory();
|
|
1684
2036
|
callback === null || callback === void 0 ? void 0 : callback();
|
|
1685
2037
|
// }, 500);
|
|
1686
2038
|
this.hooks.destroy.emit({});
|