@antv/g6 5.0.0-beta.5 → 5.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/g6.min.js +2 -2
- package/esm/index.d.ts +15 -7
- package/esm/index.js +1 -1
- package/esm/item/combo.d.ts +1 -1
- package/esm/item/combo.js +16 -9
- package/esm/item/combo.js.map +1 -1
- package/esm/item/edge.d.ts +22 -2
- package/esm/item/edge.js +93 -42
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.js +9 -5
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +1 -1
- package/esm/item/node.js +22 -15
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/data.d.ts +7 -10
- package/esm/runtime/controller/data.js +123 -281
- package/esm/runtime/controller/data.js.map +1 -1
- package/esm/runtime/controller/item.d.ts +1 -0
- package/esm/runtime/controller/item.js +21 -9
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.d.ts +85 -7
- package/esm/runtime/graph.js +396 -61
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/brush-select.js +1 -2
- package/esm/stdlib/behavior/brush-select.js.map +1 -1
- package/esm/stdlib/behavior/create-edge.d.ts +57 -0
- package/esm/stdlib/behavior/create-edge.js +207 -0
- package/esm/stdlib/behavior/create-edge.js.map +1 -0
- package/esm/stdlib/behavior/drag-canvas.d.ts +2 -1
- package/esm/stdlib/behavior/drag-canvas.js +26 -18
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
- package/esm/stdlib/behavior/drag-combo.js +35 -24
- package/esm/stdlib/behavior/drag-combo.js.map +1 -1
- package/esm/stdlib/behavior/drag-node.d.ts +3 -3
- package/esm/stdlib/behavior/drag-node.js +70 -57
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/index.d.ts +2 -0
- package/esm/stdlib/behavior/index.js +2 -0
- package/esm/stdlib/behavior/index.js.map +1 -1
- package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
- package/esm/stdlib/behavior/lasso-select.js +1 -2
- package/esm/stdlib/behavior/lasso-select.js.map +1 -1
- package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
- package/esm/stdlib/behavior/scroll-canvas.js +266 -0
- package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
- package/esm/stdlib/behavior/zoom-canvas.d.ts +2 -1
- package/esm/stdlib/behavior/zoom-canvas.js +30 -22
- package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
- package/esm/stdlib/data/mapNodeSize.js +2 -2
- package/esm/stdlib/data/mapNodeSize.js.map +1 -1
- package/esm/stdlib/data/transformV4Data.d.ts +2 -2
- package/esm/stdlib/data/transformV4Data.js +2 -2
- package/esm/stdlib/data/transformV4Data.js.map +1 -1
- package/esm/stdlib/data/validateData.d.ts +2 -2
- package/esm/stdlib/data/validateData.js +9 -9
- package/esm/stdlib/data/validateData.js.map +1 -1
- package/esm/stdlib/index.d.ts +10 -6
- package/esm/stdlib/index.js +5 -1
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/edge/base.js +4 -9
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
- package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
- package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
- package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
- package/esm/stdlib/plugin/minimap/index.js +116 -9
- package/esm/stdlib/plugin/minimap/index.js.map +1 -1
- package/esm/stdlib/plugin/snapline/index.d.ts +5 -1
- package/esm/stdlib/plugin/snapline/index.js +23 -12
- package/esm/stdlib/plugin/snapline/index.js.map +1 -1
- package/esm/types/graph.d.ts +34 -8
- package/esm/types/hook.d.ts +16 -2
- package/esm/types/spec.d.ts +6 -3
- package/esm/types/view.d.ts +5 -0
- package/esm/util/event.d.ts +3 -1
- package/esm/util/event.js +8 -1
- package/esm/util/event.js.map +1 -1
- package/esm/util/item.d.ts +16 -1
- package/esm/util/item.js +31 -8
- package/esm/util/item.js.map +1 -1
- package/esm/util/layout.d.ts +11 -0
- package/esm/util/layout.js +45 -0
- package/esm/util/layout.js.map +1 -1
- package/esm/util/point.js +5 -1
- package/esm/util/point.js.map +1 -1
- package/esm/util/shape.d.ts +1 -1
- package/esm/util/shape.js +3 -7
- package/esm/util/shape.js.map +1 -1
- package/esm/util/warn.d.ts +14 -0
- package/esm/util/warn.js +4 -0
- package/esm/util/warn.js.map +1 -0
- package/lib/index.d.ts +15 -7
- package/lib/index.js +1 -1
- package/lib/item/combo.d.ts +1 -1
- package/lib/item/combo.js +16 -9
- package/lib/item/combo.js.map +1 -1
- package/lib/item/edge.d.ts +22 -2
- package/lib/item/edge.js +92 -41
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.js +9 -5
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +1 -1
- package/lib/item/node.js +22 -15
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/data.d.ts +7 -10
- package/lib/runtime/controller/data.js +123 -281
- package/lib/runtime/controller/data.js.map +1 -1
- package/lib/runtime/controller/item.d.ts +1 -0
- package/lib/runtime/controller/item.js +21 -9
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.d.ts +85 -7
- package/lib/runtime/graph.js +396 -61
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/brush-select.js +1 -2
- package/lib/stdlib/behavior/brush-select.js.map +1 -1
- package/lib/stdlib/behavior/create-edge.d.ts +57 -0
- package/lib/stdlib/behavior/create-edge.js +211 -0
- package/lib/stdlib/behavior/create-edge.js.map +1 -0
- package/lib/stdlib/behavior/drag-canvas.d.ts +2 -1
- package/lib/stdlib/behavior/drag-canvas.js +26 -18
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
- package/lib/stdlib/behavior/drag-combo.js +35 -24
- package/lib/stdlib/behavior/drag-combo.js.map +1 -1
- package/lib/stdlib/behavior/drag-node.d.ts +3 -3
- package/lib/stdlib/behavior/drag-node.js +70 -57
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/index.d.ts +2 -0
- package/lib/stdlib/behavior/index.js +2 -0
- package/lib/stdlib/behavior/index.js.map +1 -1
- package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
- package/lib/stdlib/behavior/lasso-select.js +1 -2
- package/lib/stdlib/behavior/lasso-select.js.map +1 -1
- package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
- package/lib/stdlib/behavior/scroll-canvas.js +270 -0
- package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
- package/lib/stdlib/behavior/zoom-canvas.d.ts +2 -1
- package/lib/stdlib/behavior/zoom-canvas.js +30 -22
- package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
- package/lib/stdlib/data/mapNodeSize.js +2 -2
- package/lib/stdlib/data/mapNodeSize.js.map +1 -1
- package/lib/stdlib/data/transformV4Data.d.ts +2 -2
- package/lib/stdlib/data/transformV4Data.js +2 -2
- package/lib/stdlib/data/transformV4Data.js.map +1 -1
- package/lib/stdlib/data/validateData.d.ts +2 -2
- package/lib/stdlib/data/validateData.js +9 -9
- package/lib/stdlib/data/validateData.js.map +1 -1
- package/lib/stdlib/index.d.ts +10 -6
- package/lib/stdlib/index.js +5 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/edge/base.js +4 -9
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
- package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
- package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
- package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
- package/lib/stdlib/plugin/minimap/index.js +116 -9
- package/lib/stdlib/plugin/minimap/index.js.map +1 -1
- package/lib/stdlib/plugin/snapline/index.d.ts +5 -1
- package/lib/stdlib/plugin/snapline/index.js +23 -12
- package/lib/stdlib/plugin/snapline/index.js.map +1 -1
- package/lib/types/graph.d.ts +34 -8
- package/lib/types/hook.d.ts +16 -2
- package/lib/types/spec.d.ts +6 -3
- package/lib/types/view.d.ts +5 -0
- package/lib/util/event.d.ts +3 -1
- package/lib/util/event.js +8 -1
- package/lib/util/event.js.map +1 -1
- package/lib/util/item.d.ts +16 -1
- package/lib/util/item.js +33 -9
- package/lib/util/item.js.map +1 -1
- package/lib/util/layout.d.ts +11 -0
- package/lib/util/layout.js +47 -1
- package/lib/util/layout.js.map +1 -1
- package/lib/util/point.js +5 -1
- package/lib/util/point.js.map +1 -1
- package/lib/util/shape.d.ts +1 -1
- package/lib/util/shape.js +3 -7
- package/lib/util/shape.js.map +1 -1
- package/lib/util/warn.d.ts +14 -0
- package/lib/util/warn.js +8 -0
- package/lib/util/warn.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/item/combo.ts +14 -9
- package/src/item/edge.ts +121 -55
- package/src/item/item.ts +13 -9
- package/src/item/node.ts +20 -15
- package/src/runtime/controller/data.ts +139 -339
- package/src/runtime/controller/item.ts +30 -12
- package/src/runtime/graph.ts +502 -67
- package/src/stdlib/behavior/brush-select.ts +4 -2
- package/src/stdlib/behavior/create-edge.ts +296 -0
- package/src/stdlib/behavior/drag-canvas.ts +30 -19
- package/src/stdlib/behavior/drag-combo.ts +2 -2
- package/src/stdlib/behavior/drag-node.ts +8 -8
- package/src/stdlib/behavior/index.ts +2 -0
- package/src/stdlib/behavior/lasso-select.ts +5 -3
- package/src/stdlib/behavior/scroll-canvas.ts +348 -0
- package/src/stdlib/behavior/zoom-canvas.ts +34 -23
- package/src/stdlib/data/mapNodeSize.ts +2 -2
- package/src/stdlib/data/transformV4Data.ts +2 -2
- package/src/stdlib/data/validateData.ts +9 -9
- package/src/stdlib/index.ts +6 -0
- package/src/stdlib/item/edge/base.ts +4 -8
- package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
- package/src/stdlib/plugin/minimap/index.ts +120 -10
- package/src/stdlib/plugin/snapline/index.ts +36 -16
- package/src/types/graph.ts +37 -8
- package/src/types/hook.ts +16 -2
- package/src/types/spec.ts +9 -3
- package/src/types/view.ts +8 -3
- package/src/util/event.ts +14 -1
- package/src/util/item.ts +65 -28
- package/src/util/layout.ts +45 -0
- package/src/util/point.ts +4 -2
- package/src/util/shape.ts +6 -7
- package/src/util/warn.ts +20 -0
package/esm/runtime/graph.js
CHANGED
|
@@ -19,9 +19,12 @@ 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';
|
|
27
|
+
import { getLayoutBounds } from '../util/layout';
|
|
25
28
|
import { DataController, ExtensionController, InteractionController, ItemController, LayoutController, ThemeController, ViewportController, } from './controller';
|
|
26
29
|
import { PluginController } from './controller/plugin';
|
|
27
30
|
import Hook from './hooks';
|
|
@@ -193,13 +196,15 @@ export default class Graph extends EventEmitter {
|
|
|
193
196
|
}),
|
|
194
197
|
transientupdate: new Hook({ name: 'transientupdate' }),
|
|
195
198
|
pluginchange: new Hook({ name: 'pluginchange' }),
|
|
196
|
-
themechange: new Hook({ name: '
|
|
199
|
+
themechange: new Hook({ name: 'themechange' }),
|
|
200
|
+
mapperchange: new Hook({ name: 'mapperchange' }),
|
|
197
201
|
treecollapseexpand: new Hook({ name: 'treecollapseexpand' }),
|
|
198
202
|
destroy: new Hook({ name: 'destroy' }),
|
|
199
203
|
};
|
|
200
204
|
}
|
|
201
205
|
formatSpecification(spec) {
|
|
202
|
-
|
|
206
|
+
var _a;
|
|
207
|
+
return Object.assign(Object.assign(Object.assign({}, this.specification), spec), { optimize: Object.assign(Object.assign({ tileBehavior: 2000, tileBehaviorSize: 1000, tileFirstRender: 10000, tileFirstRenderSize: 1000 }, (_a = this.specification) === null || _a === void 0 ? void 0 : _a.optimize), spec.optimize) });
|
|
203
208
|
}
|
|
204
209
|
/**
|
|
205
210
|
* Update the specs(configurations).
|
|
@@ -228,6 +233,28 @@ export default class Graph extends EventEmitter {
|
|
|
228
233
|
theme: this.themeController.specification,
|
|
229
234
|
});
|
|
230
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Update the item display mapper for a specific item type.
|
|
238
|
+
* @param {ITEM_TYPE} type - The type of item (node, edge, or combo).
|
|
239
|
+
* @param {NodeMapper | EdgeMapper | ComboMapper} mapper - The mapper to be updated.
|
|
240
|
+
* */
|
|
241
|
+
updateMapper(type, mapper) {
|
|
242
|
+
switch (type) {
|
|
243
|
+
case 'node':
|
|
244
|
+
this.specification.node = mapper;
|
|
245
|
+
break;
|
|
246
|
+
case 'edge':
|
|
247
|
+
this.specification.edge = mapper;
|
|
248
|
+
break;
|
|
249
|
+
case 'combo':
|
|
250
|
+
this.specification.combo = mapper;
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
this.hooks.mapperchange.emit({
|
|
254
|
+
type,
|
|
255
|
+
mapper,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
231
258
|
/**
|
|
232
259
|
* Get the copy of specs(configurations).
|
|
233
260
|
* @returns graph specs
|
|
@@ -261,18 +288,22 @@ export default class Graph extends EventEmitter {
|
|
|
261
288
|
const { autoFit } = this.specification;
|
|
262
289
|
if (autoFit) {
|
|
263
290
|
if (autoFit === 'view') {
|
|
264
|
-
yield this.fitView();
|
|
291
|
+
yield this.fitView({ rules: { boundsType: 'layout' } });
|
|
265
292
|
}
|
|
266
293
|
else if (autoFit === 'center') {
|
|
267
|
-
yield this.fitCenter();
|
|
294
|
+
yield this.fitCenter('layout');
|
|
268
295
|
}
|
|
269
296
|
else {
|
|
270
297
|
const { type, effectTiming } = autoFit, others = __rest(autoFit, ["type", "effectTiming"]);
|
|
271
298
|
if (type === 'view') {
|
|
272
|
-
|
|
299
|
+
const { padding, rules } = others;
|
|
300
|
+
yield this.fitView({
|
|
301
|
+
padding,
|
|
302
|
+
rules: Object.assign(Object.assign({}, rules), { boundsType: 'layout' }),
|
|
303
|
+
}, effectTiming);
|
|
273
304
|
}
|
|
274
305
|
else if (type === 'center') {
|
|
275
|
-
yield this.fitCenter(effectTiming);
|
|
306
|
+
yield this.fitCenter('layout', effectTiming);
|
|
276
307
|
}
|
|
277
308
|
else if (type === 'position') {
|
|
278
309
|
// TODO: align
|
|
@@ -445,9 +476,12 @@ export default class Graph extends EventEmitter {
|
|
|
445
476
|
const [top, right, bottom, left] = padding
|
|
446
477
|
? formatPadding(padding)
|
|
447
478
|
: [0, 0, 0, 0];
|
|
448
|
-
const { direction = 'both', ratioRule = 'min' } = rules || {};
|
|
449
|
-
|
|
450
|
-
|
|
479
|
+
const { direction = 'both', ratioRule = 'min', boundsType = 'render', } = rules || {};
|
|
480
|
+
const { center: [graphCenterX, graphCenterY], halfExtents, } = boundsType === 'render'
|
|
481
|
+
? // Get the bounds of the whole graph content.
|
|
482
|
+
this.canvas.document.documentElement.getBounds()
|
|
483
|
+
: // Get the bounds of the nodes positions while the graph content is not ready.
|
|
484
|
+
getLayoutBounds(this);
|
|
451
485
|
const origin = this.canvas.canvas2Viewport({
|
|
452
486
|
x: graphCenterX,
|
|
453
487
|
y: graphCenterY,
|
|
@@ -492,10 +526,13 @@ export default class Graph extends EventEmitter {
|
|
|
492
526
|
* Fit the graph center to the view center.
|
|
493
527
|
* @param effectTiming animation configurations
|
|
494
528
|
*/
|
|
495
|
-
fitCenter(effectTiming) {
|
|
529
|
+
fitCenter(boundsType = 'render', effectTiming) {
|
|
496
530
|
return __awaiter(this, void 0, void 0, function* () {
|
|
497
|
-
|
|
498
|
-
|
|
531
|
+
const { center: [graphCenterX, graphCenterY], } = boundsType === 'render'
|
|
532
|
+
? // Get the bounds of the whole graph content.
|
|
533
|
+
this.canvas.document.documentElement.getBounds()
|
|
534
|
+
: // Get the bounds of the nodes positions while the graph content is not ready.
|
|
535
|
+
getLayoutBounds(this);
|
|
499
536
|
yield this.translateTo(this.canvas.canvas2Viewport({ x: graphCenterX, y: graphCenterY }), effectTiming);
|
|
500
537
|
});
|
|
501
538
|
}
|
|
@@ -749,23 +786,26 @@ export default class Graph extends EventEmitter {
|
|
|
749
786
|
// data controller and item controller subscribe additem in order
|
|
750
787
|
const { graphCore } = this.dataController;
|
|
751
788
|
const { specification } = this.themeController;
|
|
789
|
+
// debugger;
|
|
752
790
|
graphCore.once('changed', (event) => {
|
|
753
791
|
if (!event.changes.length)
|
|
754
792
|
return;
|
|
755
793
|
const changes = event.changes;
|
|
756
|
-
|
|
757
|
-
type: itemType,
|
|
758
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
759
|
-
graphCore,
|
|
760
|
-
theme: specification,
|
|
761
|
-
});
|
|
762
|
-
this.emit('afteritemchange', {
|
|
794
|
+
const timingParameters = {
|
|
763
795
|
type: itemType,
|
|
764
796
|
action: 'add',
|
|
765
797
|
models,
|
|
766
798
|
apiName: 'addData',
|
|
767
799
|
changes,
|
|
800
|
+
};
|
|
801
|
+
this.emit('beforeitemchange', timingParameters);
|
|
802
|
+
this.hooks.itemchange.emit({
|
|
803
|
+
type: itemType,
|
|
804
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
805
|
+
graphCore,
|
|
806
|
+
theme: specification,
|
|
768
807
|
});
|
|
808
|
+
this.emit('afteritemchange', timingParameters);
|
|
769
809
|
});
|
|
770
810
|
const modelArr = isArray(models) ? models : [models];
|
|
771
811
|
const data = { nodes: [], edges: [], combos: [] };
|
|
@@ -786,27 +826,38 @@ export default class Graph extends EventEmitter {
|
|
|
786
826
|
removeData(itemType, ids) {
|
|
787
827
|
const idArr = isArray(ids) ? ids : [ids];
|
|
788
828
|
const data = { nodes: [], edges: [], combos: [] };
|
|
789
|
-
const {
|
|
829
|
+
const { graphCore } = this.dataController;
|
|
790
830
|
const { specification } = this.themeController;
|
|
791
|
-
const getItem = itemType === 'edge' ?
|
|
792
|
-
|
|
831
|
+
const getItem = itemType === 'edge' ? graphCore.getEdge : graphCore.getNode;
|
|
832
|
+
const hasItem = itemType === 'edge' ? graphCore.hasEdge : graphCore.hasNode;
|
|
833
|
+
data[`${itemType}s`] = idArr
|
|
834
|
+
.map((id) => {
|
|
835
|
+
if (!hasItem.bind(graphCore)(id)) {
|
|
836
|
+
console.warn(`The ${itemType} data with id ${id} does not exist. It will be ignored`);
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
return getItem.bind(graphCore)(id);
|
|
840
|
+
})
|
|
841
|
+
.filter(Boolean);
|
|
793
842
|
graphCore.once('changed', (event) => {
|
|
794
843
|
if (!event.changes.length)
|
|
795
844
|
return;
|
|
796
845
|
const changes = event.changes;
|
|
797
|
-
|
|
798
|
-
type: itemType,
|
|
799
|
-
changes: event.changes,
|
|
800
|
-
graphCore,
|
|
801
|
-
theme: specification,
|
|
802
|
-
});
|
|
803
|
-
this.emit('afteritemchange', {
|
|
846
|
+
const timingParameters = {
|
|
804
847
|
type: itemType,
|
|
805
848
|
action: 'remove',
|
|
806
849
|
ids: idArr,
|
|
807
850
|
apiName: 'removeData',
|
|
808
851
|
changes,
|
|
852
|
+
};
|
|
853
|
+
this.emit('beforeitemchange', timingParameters);
|
|
854
|
+
this.hooks.itemchange.emit({
|
|
855
|
+
type: itemType,
|
|
856
|
+
changes: event.changes,
|
|
857
|
+
graphCore,
|
|
858
|
+
theme: specification,
|
|
809
859
|
});
|
|
860
|
+
this.emit('afteritemchange', timingParameters);
|
|
810
861
|
});
|
|
811
862
|
this.hooks.datachange.emit({
|
|
812
863
|
data,
|
|
@@ -874,19 +925,21 @@ export default class Graph extends EventEmitter {
|
|
|
874
925
|
const { specification } = this.themeController;
|
|
875
926
|
graphCore.once('changed', (event) => {
|
|
876
927
|
const changes = this.extendChanges(clone(event.changes));
|
|
877
|
-
|
|
878
|
-
type: itemType,
|
|
879
|
-
changes: event.changes,
|
|
880
|
-
graphCore,
|
|
881
|
-
theme: specification,
|
|
882
|
-
});
|
|
883
|
-
this.emit('afteritemchange', {
|
|
928
|
+
const timingParameters = {
|
|
884
929
|
type: itemType,
|
|
885
930
|
action: 'update',
|
|
886
931
|
models,
|
|
887
932
|
apiName: 'updateData',
|
|
888
933
|
changes,
|
|
934
|
+
};
|
|
935
|
+
this.emit('beforeitemchange', timingParameters);
|
|
936
|
+
this.hooks.itemchange.emit({
|
|
937
|
+
type: itemType,
|
|
938
|
+
changes: event.changes,
|
|
939
|
+
graphCore,
|
|
940
|
+
theme: specification,
|
|
889
941
|
});
|
|
942
|
+
this.emit('afteritemchange', timingParameters);
|
|
890
943
|
});
|
|
891
944
|
this.hooks.datachange.emit({
|
|
892
945
|
data,
|
|
@@ -933,6 +986,15 @@ export default class Graph extends EventEmitter {
|
|
|
933
986
|
if (!event.changes.length)
|
|
934
987
|
return;
|
|
935
988
|
const changes = event.changes.filter((change) => !isEqual(change.newValue, change.oldValue));
|
|
989
|
+
const timingParameters = {
|
|
990
|
+
type,
|
|
991
|
+
action: 'updatePosition',
|
|
992
|
+
upsertAncestors,
|
|
993
|
+
models,
|
|
994
|
+
apiName: 'updatePosition',
|
|
995
|
+
changes,
|
|
996
|
+
};
|
|
997
|
+
this.emit('beforeitemchange', timingParameters);
|
|
936
998
|
this.hooks.itemchange.emit({
|
|
937
999
|
type,
|
|
938
1000
|
changes: event.changes,
|
|
@@ -943,14 +1005,7 @@ export default class Graph extends EventEmitter {
|
|
|
943
1005
|
animate: !disableAnimate,
|
|
944
1006
|
callback,
|
|
945
1007
|
});
|
|
946
|
-
this.emit('afteritemchange',
|
|
947
|
-
type,
|
|
948
|
-
action: 'updatePosition',
|
|
949
|
-
upsertAncestors,
|
|
950
|
-
models,
|
|
951
|
-
apiName: 'updatePosition',
|
|
952
|
-
changes,
|
|
953
|
-
});
|
|
1008
|
+
this.emit('afteritemchange', timingParameters);
|
|
954
1009
|
});
|
|
955
1010
|
this.hooks.datachange.emit({
|
|
956
1011
|
data: {
|
|
@@ -1199,19 +1254,21 @@ export default class Graph extends EventEmitter {
|
|
|
1199
1254
|
if (!event.changes.length)
|
|
1200
1255
|
return;
|
|
1201
1256
|
const changes = event.changes;
|
|
1202
|
-
|
|
1203
|
-
type: 'combo',
|
|
1204
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
1205
|
-
graphCore,
|
|
1206
|
-
theme: specification,
|
|
1207
|
-
});
|
|
1208
|
-
this.emit('afteritemchange', {
|
|
1257
|
+
const timingParameters = {
|
|
1209
1258
|
type: 'combo',
|
|
1210
1259
|
action: 'add',
|
|
1211
1260
|
models: [model],
|
|
1212
1261
|
apiName: 'addCombo',
|
|
1213
1262
|
changes,
|
|
1263
|
+
};
|
|
1264
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1265
|
+
this.hooks.itemchange.emit({
|
|
1266
|
+
type: 'combo',
|
|
1267
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
1268
|
+
graphCore,
|
|
1269
|
+
theme: specification,
|
|
1214
1270
|
});
|
|
1271
|
+
this.emit('afteritemchange', timingParameters);
|
|
1215
1272
|
});
|
|
1216
1273
|
const data = {
|
|
1217
1274
|
nodes: [],
|
|
@@ -1275,16 +1332,7 @@ export default class Graph extends EventEmitter {
|
|
|
1275
1332
|
if (!event.changes.length)
|
|
1276
1333
|
return;
|
|
1277
1334
|
const changes = this.extendChanges(clone(event.changes));
|
|
1278
|
-
|
|
1279
|
-
type: 'combo',
|
|
1280
|
-
changes: event.changes,
|
|
1281
|
-
graphCore,
|
|
1282
|
-
theme: specification,
|
|
1283
|
-
upsertAncestors,
|
|
1284
|
-
action: 'updatePosition',
|
|
1285
|
-
callback,
|
|
1286
|
-
});
|
|
1287
|
-
this.emit('afteritemchange', {
|
|
1335
|
+
const timingParameters = {
|
|
1288
1336
|
type: 'combo',
|
|
1289
1337
|
ids: idArr,
|
|
1290
1338
|
dx,
|
|
@@ -1293,7 +1341,18 @@ export default class Graph extends EventEmitter {
|
|
|
1293
1341
|
upsertAncestors,
|
|
1294
1342
|
apiName: 'moveCombo',
|
|
1295
1343
|
changes,
|
|
1344
|
+
};
|
|
1345
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1346
|
+
this.hooks.itemchange.emit({
|
|
1347
|
+
type: 'combo',
|
|
1348
|
+
changes: event.changes,
|
|
1349
|
+
graphCore,
|
|
1350
|
+
theme: specification,
|
|
1351
|
+
upsertAncestors,
|
|
1352
|
+
action: 'updatePosition',
|
|
1353
|
+
callback,
|
|
1296
1354
|
});
|
|
1355
|
+
this.emit('afteritemchange', timingParameters);
|
|
1297
1356
|
});
|
|
1298
1357
|
this.hooks.datachange.emit({
|
|
1299
1358
|
data: {
|
|
@@ -1378,6 +1437,14 @@ export default class Graph extends EventEmitter {
|
|
|
1378
1437
|
getMode() {
|
|
1379
1438
|
return this.interactionController.getMode();
|
|
1380
1439
|
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Set the cursor. But the cursor in item's style has higher priority.
|
|
1442
|
+
* @param cursor
|
|
1443
|
+
*/
|
|
1444
|
+
setCursor(cursor) {
|
|
1445
|
+
this.canvas.setCursor(cursor);
|
|
1446
|
+
this.transientCanvas.setCursor(cursor);
|
|
1447
|
+
}
|
|
1381
1448
|
/**
|
|
1382
1449
|
* Add behavior(s) to mode(s).
|
|
1383
1450
|
* @param behaviors behavior names or configs
|
|
@@ -1548,6 +1615,274 @@ export default class Graph extends EventEmitter {
|
|
|
1548
1615
|
});
|
|
1549
1616
|
return this.itemController.getTransient(String(id));
|
|
1550
1617
|
}
|
|
1618
|
+
// ===== download operations =====
|
|
1619
|
+
/**
|
|
1620
|
+
* Asynchronously generates a Data URL representation of the canvas content, including
|
|
1621
|
+
* background, main content, and transient canvas.
|
|
1622
|
+
* @param The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
1623
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
1624
|
+
*/
|
|
1625
|
+
toDataURL(type) {
|
|
1626
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1627
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
1628
|
+
const canvas = this.canvas;
|
|
1629
|
+
const transientCanvas = this.transientCanvas;
|
|
1630
|
+
const rendererType = this.rendererType;
|
|
1631
|
+
const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
1632
|
+
const width = this.getSize()[0];
|
|
1633
|
+
const height = this.getSize()[1];
|
|
1634
|
+
const vContainerDOM = createDom('<div id="virtual-image"></div>');
|
|
1635
|
+
const vCanvas = createCanvas(rendererType, vContainerDOM, width, height, pixelRatio);
|
|
1636
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
1637
|
+
let bgRect;
|
|
1638
|
+
if (rendererType !== 'svg') {
|
|
1639
|
+
bgRect = new Rect({
|
|
1640
|
+
style: {
|
|
1641
|
+
x: 0,
|
|
1642
|
+
y: 0,
|
|
1643
|
+
z: -1,
|
|
1644
|
+
width: vCanvasContextService.getDomElement().width,
|
|
1645
|
+
height: vCanvasContextService.getDomElement().height,
|
|
1646
|
+
//@ts-ignore
|
|
1647
|
+
fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
|
|
1648
|
+
},
|
|
1649
|
+
});
|
|
1650
|
+
vCanvas.appendChild(bgRect);
|
|
1651
|
+
}
|
|
1652
|
+
const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
|
|
1653
|
+
const clonedGroup = canvas.getRoot().cloneNode(true);
|
|
1654
|
+
const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
|
|
1655
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
1656
|
+
vCanvas.appendChild(clonedGroup);
|
|
1657
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
1658
|
+
vCanvas.render();
|
|
1659
|
+
if (!type)
|
|
1660
|
+
type = 'image/png';
|
|
1661
|
+
let dataURL = '';
|
|
1662
|
+
yield vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
1663
|
+
dataURL = url;
|
|
1664
|
+
});
|
|
1665
|
+
return dataURL;
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
/**
|
|
1669
|
+
* Asynchronously generates a Data URL representation of the full canvas content,
|
|
1670
|
+
* including background, main content, and transient canvas, with optional padding.
|
|
1671
|
+
* @param type The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
1672
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
1673
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
1674
|
+
*/
|
|
1675
|
+
toFullDataURL(type, imageConfig) {
|
|
1676
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1677
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
1678
|
+
const canvas = this.canvas;
|
|
1679
|
+
const transientCanvas = this.transientCanvas;
|
|
1680
|
+
const backgroundRoot = canvas.getRoot();
|
|
1681
|
+
const root = canvas.getRoot();
|
|
1682
|
+
const transientRoot = transientCanvas.getRoot();
|
|
1683
|
+
const rendererType = this.rendererType;
|
|
1684
|
+
const backgroundBBox = backgroundRoot.getBBox();
|
|
1685
|
+
const BBox = root.getBBox();
|
|
1686
|
+
const transientBBox = transientRoot.getBBox();
|
|
1687
|
+
let padding = imageConfig ? imageConfig.padding : undefined;
|
|
1688
|
+
if (!padding) {
|
|
1689
|
+
padding = [0, 0, 0, 0];
|
|
1690
|
+
}
|
|
1691
|
+
else if (isNumber(padding)) {
|
|
1692
|
+
padding = [padding, padding, padding, padding];
|
|
1693
|
+
}
|
|
1694
|
+
const left = (transientBBox.left
|
|
1695
|
+
? backgroundBBox.left
|
|
1696
|
+
? Math.min(backgroundBBox.left, BBox.left, transientBBox.left)
|
|
1697
|
+
: Math.min(BBox.left, transientBBox.left)
|
|
1698
|
+
: BBox.left) - padding[3];
|
|
1699
|
+
const right = (transientBBox.right
|
|
1700
|
+
? backgroundBBox.right
|
|
1701
|
+
? Math.max(backgroundBBox.right, BBox.right, transientBBox.right)
|
|
1702
|
+
: Math.max(BBox.right, transientBBox.right)
|
|
1703
|
+
: BBox.right) + padding[1];
|
|
1704
|
+
const top = (transientBBox.top
|
|
1705
|
+
? backgroundBBox.top
|
|
1706
|
+
? Math.min(backgroundBBox.top, BBox.top, transientBBox.top)
|
|
1707
|
+
: Math.min(BBox.top, transientBBox.top)
|
|
1708
|
+
: BBox.top) - padding[0];
|
|
1709
|
+
const bottom = (transientBBox.bottom
|
|
1710
|
+
? backgroundBBox.bottom
|
|
1711
|
+
? Math.max(backgroundBBox.bottom, BBox.bottom, transientBBox.bottom)
|
|
1712
|
+
: Math.max(BBox.bottom, transientBBox.bottom)
|
|
1713
|
+
: BBox.bottom) + padding[2];
|
|
1714
|
+
const graphCenterX = (left + right) / 2;
|
|
1715
|
+
const graphCenterY = (top + bottom) / 2;
|
|
1716
|
+
const halfX = (right - left) / 2;
|
|
1717
|
+
const halfY = (bottom - top) / 2;
|
|
1718
|
+
const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
1719
|
+
const vWidth = halfX * 2;
|
|
1720
|
+
const vHeight = halfY * 2;
|
|
1721
|
+
const vContainerDOM = createDom('<div id="virtual-image"></div>');
|
|
1722
|
+
const vCanvas = createCanvas(rendererType, vContainerDOM, vWidth, vHeight, pixelRatio);
|
|
1723
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
1724
|
+
if (rendererType !== 'svg') {
|
|
1725
|
+
const bgRect = new Rect({
|
|
1726
|
+
style: {
|
|
1727
|
+
x: 0,
|
|
1728
|
+
y: 0,
|
|
1729
|
+
z: -1,
|
|
1730
|
+
width: vCanvasContextService.getDomElement().width,
|
|
1731
|
+
height: vCanvasContextService.getDomElement().height,
|
|
1732
|
+
//@ts-ignore
|
|
1733
|
+
fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
|
|
1734
|
+
},
|
|
1735
|
+
});
|
|
1736
|
+
vCanvas.appendChild(bgRect);
|
|
1737
|
+
}
|
|
1738
|
+
const backgroundClonedGroup = backgroundRoot.cloneNode(true);
|
|
1739
|
+
const clonedGroup = root.cloneNode(true);
|
|
1740
|
+
const transientClonedGroup = transientRoot.cloneNode(true);
|
|
1741
|
+
const transPosition = [
|
|
1742
|
+
-graphCenterX + halfX,
|
|
1743
|
+
-graphCenterY + halfY,
|
|
1744
|
+
];
|
|
1745
|
+
backgroundClonedGroup.setPosition(transPosition);
|
|
1746
|
+
clonedGroup.setPosition(transPosition);
|
|
1747
|
+
transientClonedGroup.setPosition(transPosition);
|
|
1748
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
1749
|
+
vCanvas.appendChild(clonedGroup);
|
|
1750
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
1751
|
+
vCanvas.render();
|
|
1752
|
+
if (!type)
|
|
1753
|
+
type = 'image/png';
|
|
1754
|
+
let dataURL = '';
|
|
1755
|
+
yield vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
1756
|
+
dataURL = url;
|
|
1757
|
+
});
|
|
1758
|
+
return dataURL;
|
|
1759
|
+
});
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Converts a Data URL to an image file and handles the download of the image.
|
|
1763
|
+
* @param dataURL The Data URL of the image to be converted and downloaded.
|
|
1764
|
+
* @param renderer The renderer type ('svg' or other) used for the canvas.
|
|
1765
|
+
* @param link The HTML link element used for image download.
|
|
1766
|
+
* @param fileName The desired name for the downloaded image file.
|
|
1767
|
+
*/
|
|
1768
|
+
dataURLToImage(dataURL, renderer, link, fileName) {
|
|
1769
|
+
if (!dataURL || dataURL === 'data:') {
|
|
1770
|
+
console.error('Download image failed. The graph is too large or there is invalid attribute values in graph items');
|
|
1771
|
+
return;
|
|
1772
|
+
}
|
|
1773
|
+
if (typeof window !== 'undefined') {
|
|
1774
|
+
if (window.Blob && window.URL && renderer !== 'svg') {
|
|
1775
|
+
const arr = dataURL.split(',');
|
|
1776
|
+
let mime = '';
|
|
1777
|
+
if (arr && arr.length > 0) {
|
|
1778
|
+
const match = arr[0].match(/:(.*?);/);
|
|
1779
|
+
// eslint-disable-next-line prefer-destructuring
|
|
1780
|
+
if (match && match.length >= 2)
|
|
1781
|
+
mime = match[1];
|
|
1782
|
+
}
|
|
1783
|
+
const bstr = atob(arr[1]);
|
|
1784
|
+
let n = bstr.length;
|
|
1785
|
+
const u8arr = new Uint8Array(n);
|
|
1786
|
+
while (n--) {
|
|
1787
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
1788
|
+
}
|
|
1789
|
+
const blobObj = new Blob([u8arr], { type: mime });
|
|
1790
|
+
if (window.navigator.msSaveBlob) {
|
|
1791
|
+
window.navigator.msSaveBlob(blobObj, fileName);
|
|
1792
|
+
}
|
|
1793
|
+
else {
|
|
1794
|
+
link.addEventListener('click', () => {
|
|
1795
|
+
link.download = fileName;
|
|
1796
|
+
link.href = window.URL.createObjectURL(blobObj);
|
|
1797
|
+
});
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
else {
|
|
1801
|
+
link.addEventListener('click', () => {
|
|
1802
|
+
link.download = fileName;
|
|
1803
|
+
link.href = dataURL;
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Initiates the download of the graph as an image with an optional name and type.
|
|
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
|
+
*/
|
|
1813
|
+
downloadImage(name, type) {
|
|
1814
|
+
const self = this;
|
|
1815
|
+
// self.stopAnimate();
|
|
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.asyncToDataUrl(type, (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
|
+
* Initiates the download of the entire graph as an image with optional name, type, and padding configuration.
|
|
1831
|
+
* @param name The desired name for the downloaded image file (optional).
|
|
1832
|
+
* @param type The type of the image to download (optional, defaults to 'image/png').
|
|
1833
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
1834
|
+
*/
|
|
1835
|
+
downloadFullImage(name, type, imageConfig) {
|
|
1836
|
+
const self = this;
|
|
1837
|
+
const rendererType = this.rendererType;
|
|
1838
|
+
if (!type)
|
|
1839
|
+
type = 'image/png';
|
|
1840
|
+
const fileName = (name || 'graph') +
|
|
1841
|
+
(rendererType === 'svg' ? '.svg' : type.split('/')[1]);
|
|
1842
|
+
const link = document.createElement('a');
|
|
1843
|
+
self.asyncToFullDataUrl(type, imageConfig, (dataURL) => {
|
|
1844
|
+
this.dataURLToImage(dataURL, rendererType, link, fileName);
|
|
1845
|
+
const e = document.createEvent('MouseEvents');
|
|
1846
|
+
e.initEvent('click', false, false);
|
|
1847
|
+
link.dispatchEvent(e);
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
/**
|
|
1851
|
+
* Asynchronously converts the canvas content to a Data URL of the specified type and invokes the provided callback.
|
|
1852
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
1853
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
1854
|
+
*/
|
|
1855
|
+
asyncToDataUrl(type, callback) {
|
|
1856
|
+
let dataURL = '';
|
|
1857
|
+
if (!type)
|
|
1858
|
+
type = 'image/png';
|
|
1859
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
1860
|
+
yield this.toDataURL(type).then((url) => {
|
|
1861
|
+
dataURL = url;
|
|
1862
|
+
});
|
|
1863
|
+
if (callback)
|
|
1864
|
+
callback(dataURL);
|
|
1865
|
+
}), 16);
|
|
1866
|
+
}
|
|
1867
|
+
/**
|
|
1868
|
+
* Asynchronously converts the entire canvas content to a Data URL of the specified type
|
|
1869
|
+
* with optional padding, and invokes the provided callback.
|
|
1870
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
1871
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
1872
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
1873
|
+
*/
|
|
1874
|
+
asyncToFullDataUrl(type, imageConfig, callback) {
|
|
1875
|
+
let dataURL = '';
|
|
1876
|
+
if (!type)
|
|
1877
|
+
type = 'image/png';
|
|
1878
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
1879
|
+
yield this.toFullDataURL(type, imageConfig).then((url) => {
|
|
1880
|
+
dataURL = url;
|
|
1881
|
+
});
|
|
1882
|
+
if (callback)
|
|
1883
|
+
callback(dataURL);
|
|
1884
|
+
}), 16);
|
|
1885
|
+
}
|
|
1551
1886
|
// ===== history operations =====
|
|
1552
1887
|
/**
|
|
1553
1888
|
* Determine if history (redo/undo) is enabled.
|