@antv/g6 5.0.0-beta.1 → 5.0.0-beta.10
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/constant/shape.d.ts +4 -1
- package/esm/constant/shape.js.map +1 -1
- package/esm/index.d.ts +22 -7
- package/esm/index.js +3 -2
- package/esm/index.js.map +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 +20 -3
- package/esm/item/edge.js +99 -43
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.d.ts +3 -2
- package/esm/item/item.js +21 -11
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +2 -1
- package/esm/item/node.js +33 -16
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/data.d.ts +7 -10
- package/esm/runtime/controller/data.js +125 -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 +267 -151
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.d.ts +103 -23
- package/esm/runtime/graph.js +460 -88
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/activate-relations.d.ts +9 -9
- package/esm/stdlib/behavior/activate-relations.js +8 -8
- 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 +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 +59 -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 +3 -0
- package/esm/stdlib/behavior/index.js +3 -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/shortcuts-call.d.ts +38 -0
- package/esm/stdlib/behavior/shortcuts-call.js +80 -0
- package/esm/stdlib/behavior/shortcuts-call.js.map +1 -0
- package/esm/stdlib/behavior/zoom-canvas.d.ts +2 -1
- package/esm/stdlib/behavior/zoom-canvas.js +55 -24
- 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 +16 -6
- package/esm/stdlib/index.js +20 -10
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/edge/base.d.ts +10 -1
- package/esm/stdlib/item/edge/base.js +20 -13
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/edge/line.js +5 -2
- package/esm/stdlib/item/edge/line.js.map +1 -1
- package/esm/stdlib/item/edge/polyline.d.ts +3 -2
- package/esm/stdlib/item/edge/polyline.js +3 -3
- package/esm/stdlib/item/edge/polyline.js.map +1 -1
- package/esm/stdlib/item/node/base.d.ts +1 -1
- package/esm/stdlib/item/node/base.js +18 -26
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/base3d.d.ts +1 -0
- package/esm/stdlib/item/node/base3d.js +1 -0
- package/esm/stdlib/item/node/base3d.js.map +1 -1
- package/esm/stdlib/item/node/diamond.js +1 -1
- package/esm/stdlib/item/node/ellipse.js +2 -2
- package/esm/stdlib/item/node/hexagon.js +12 -5
- package/esm/stdlib/item/node/hexagon.js.map +1 -1
- package/esm/stdlib/item/node/image.d.ts +40 -0
- package/esm/stdlib/item/node/image.js +110 -0
- package/esm/stdlib/item/node/image.js.map +1 -0
- package/esm/stdlib/item/node/index.d.ts +1 -0
- package/esm/stdlib/item/node/index.js +1 -0
- package/esm/stdlib/item/node/index.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 +25 -16
- 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 +2 -0
- package/esm/stdlib/plugin/index.js +2 -0
- package/esm/stdlib/plugin/index.js.map +1 -1
- package/esm/stdlib/plugin/legend/index.js +1 -1
- package/esm/stdlib/plugin/legend/index.js.map +1 -1
- package/esm/stdlib/plugin/map/index.d.ts +118 -0
- package/esm/stdlib/plugin/map/index.js +683 -0
- package/esm/stdlib/plugin/map/index.js.map +1 -0
- 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 +167 -0
- package/esm/stdlib/plugin/snapline/index.js +1063 -0
- package/esm/stdlib/plugin/snapline/index.js.map +1 -0
- package/esm/stdlib/plugin/timebar/index.d.ts +98 -0
- package/esm/stdlib/plugin/timebar/index.js +303 -0
- package/esm/stdlib/plugin/timebar/index.js.map +1 -0
- package/esm/stdlib/plugin/toolbar/index.js +1 -1
- package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
- package/esm/stdlib/plugin/types.d.ts +2 -0
- package/esm/stdlib/theme/dark.js +42 -2
- package/esm/stdlib/theme/dark.js.map +1 -1
- package/esm/stdlib/theme/light.js +4 -4
- package/esm/types/common.d.ts +1 -0
- package/esm/types/event.d.ts +1 -0
- package/esm/types/graph.d.ts +48 -22
- package/esm/types/hook.d.ts +22 -2
- package/esm/types/item.d.ts +6 -0
- package/esm/types/item.js.map +1 -1
- package/esm/types/spec.d.ts +19 -3
- package/esm/types/view.d.ts +5 -0
- 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/canvas.d.ts +2 -2
- package/esm/util/canvas.js +5 -11
- package/esm/util/canvas.js.map +1 -1
- 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 +9 -2
- package/esm/util/point.js.map +1 -1
- package/esm/util/router.d.ts +4 -3
- package/esm/util/router.js +8 -5
- package/esm/util/router.js.map +1 -1
- package/esm/util/shape.d.ts +3 -3
- package/esm/util/shape.js +8 -12
- 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/constant/shape.d.ts +4 -1
- package/lib/constant/shape.js.map +1 -1
- package/lib/index.d.ts +22 -7
- package/lib/index.js +4 -2
- package/lib/index.js.map +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 +20 -3
- package/lib/item/edge.js +98 -42
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.d.ts +3 -2
- package/lib/item/item.js +21 -11
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +2 -1
- package/lib/item/node.js +33 -16
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/data.d.ts +7 -10
- package/lib/runtime/controller/data.js +125 -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 +266 -150
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.d.ts +103 -23
- package/lib/runtime/graph.js +460 -88
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/activate-relations.d.ts +9 -9
- package/lib/stdlib/behavior/activate-relations.js +8 -8
- 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 +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 +59 -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 +3 -0
- package/lib/stdlib/behavior/index.js +3 -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/shortcuts-call.d.ts +38 -0
- package/lib/stdlib/behavior/shortcuts-call.js +84 -0
- package/lib/stdlib/behavior/shortcuts-call.js.map +1 -0
- package/lib/stdlib/behavior/zoom-canvas.d.ts +2 -1
- package/lib/stdlib/behavior/zoom-canvas.js +55 -24
- 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 +16 -6
- package/lib/stdlib/index.js +20 -10
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/edge/base.d.ts +10 -1
- package/lib/stdlib/item/edge/base.js +20 -13
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/edge/line.js +5 -2
- package/lib/stdlib/item/edge/line.js.map +1 -1
- package/lib/stdlib/item/edge/polyline.d.ts +3 -2
- package/lib/stdlib/item/edge/polyline.js +3 -3
- package/lib/stdlib/item/edge/polyline.js.map +1 -1
- package/lib/stdlib/item/node/base.d.ts +1 -1
- package/lib/stdlib/item/node/base.js +18 -26
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/base3d.d.ts +1 -0
- package/lib/stdlib/item/node/base3d.js +1 -0
- package/lib/stdlib/item/node/base3d.js.map +1 -1
- package/lib/stdlib/item/node/diamond.js +1 -1
- package/lib/stdlib/item/node/ellipse.js +2 -2
- package/lib/stdlib/item/node/hexagon.js +12 -5
- package/lib/stdlib/item/node/hexagon.js.map +1 -1
- package/lib/stdlib/item/node/image.d.ts +40 -0
- package/lib/stdlib/item/node/image.js +114 -0
- package/lib/stdlib/item/node/image.js.map +1 -0
- package/lib/stdlib/item/node/index.d.ts +1 -0
- package/lib/stdlib/item/node/index.js +1 -0
- package/lib/stdlib/item/node/index.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 +25 -16
- 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 +2 -0
- package/lib/stdlib/plugin/index.js +2 -0
- package/lib/stdlib/plugin/index.js.map +1 -1
- package/lib/stdlib/plugin/legend/index.js +1 -1
- package/lib/stdlib/plugin/legend/index.js.map +1 -1
- package/lib/stdlib/plugin/map/index.d.ts +118 -0
- package/lib/stdlib/plugin/map/index.js +687 -0
- package/lib/stdlib/plugin/map/index.js.map +1 -0
- 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 +167 -0
- package/lib/stdlib/plugin/snapline/index.js +1067 -0
- package/lib/stdlib/plugin/snapline/index.js.map +1 -0
- package/lib/stdlib/plugin/timebar/index.d.ts +98 -0
- package/lib/stdlib/plugin/timebar/index.js +307 -0
- package/lib/stdlib/plugin/timebar/index.js.map +1 -0
- package/lib/stdlib/plugin/toolbar/index.js +1 -1
- package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
- package/lib/stdlib/plugin/types.d.ts +2 -0
- package/lib/stdlib/theme/dark.js +42 -2
- package/lib/stdlib/theme/dark.js.map +1 -1
- package/lib/stdlib/theme/light.js +4 -4
- package/lib/types/common.d.ts +1 -0
- package/lib/types/event.d.ts +1 -0
- package/lib/types/graph.d.ts +48 -22
- package/lib/types/hook.d.ts +22 -2
- package/lib/types/item.d.ts +6 -0
- package/lib/types/item.js.map +1 -1
- package/lib/types/spec.d.ts +19 -3
- package/lib/types/view.d.ts +5 -0
- 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/canvas.d.ts +2 -2
- package/lib/util/canvas.js +5 -11
- package/lib/util/canvas.js.map +1 -1
- 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 +9 -2
- package/lib/util/point.js.map +1 -1
- package/lib/util/router.d.ts +4 -3
- package/lib/util/router.js +8 -5
- package/lib/util/router.js.map +1 -1
- package/lib/util/shape.d.ts +3 -3
- package/lib/util/shape.js +8 -12
- 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 +10 -10
- package/src/constant/shape.ts +2 -1
- package/src/index.ts +4 -2
- package/src/item/combo.ts +14 -9
- package/src/item/edge.ts +131 -57
- package/src/item/item.ts +24 -15
- package/src/item/node.ts +38 -24
- package/src/runtime/controller/data.ts +140 -339
- package/src/runtime/controller/item.ts +236 -72
- package/src/runtime/graph.ts +592 -96
- package/src/stdlib/behavior/activate-relations.ts +8 -8
- 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 +296 -0
- package/src/stdlib/behavior/drag-canvas.ts +78 -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 +3 -0
- package/src/stdlib/behavior/lasso-select.ts +5 -3
- package/src/stdlib/behavior/scroll-canvas.ts +348 -0
- package/src/stdlib/behavior/shortcuts-call.ts +120 -0
- package/src/stdlib/behavior/zoom-canvas.ts +72 -25
- 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 +33 -9
- package/src/stdlib/item/edge/base.ts +26 -13
- package/src/stdlib/item/edge/line.ts +8 -2
- package/src/stdlib/item/edge/polyline.ts +7 -5
- package/src/stdlib/item/node/base.ts +24 -29
- package/src/stdlib/item/node/base3d.ts +1 -0
- package/src/stdlib/item/node/diamond.ts +1 -1
- package/src/stdlib/item/node/ellipse.ts +2 -2
- package/src/stdlib/item/node/hexagon.ts +14 -6
- package/src/stdlib/item/node/image.ts +190 -0
- package/src/stdlib/item/node/index.ts +1 -0
- 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 +35 -17
- 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 +2 -0
- package/src/stdlib/plugin/legend/index.ts +1 -1
- package/src/stdlib/plugin/map/index.ts +808 -0
- package/src/stdlib/plugin/minimap/index.ts +120 -10
- package/src/stdlib/plugin/snapline/index.ts +1297 -0
- package/src/stdlib/plugin/timebar/index.ts +473 -0
- package/src/stdlib/plugin/toolbar/index.ts +1 -1
- package/src/stdlib/plugin/types.ts +2 -0
- package/src/stdlib/theme/dark.ts +66 -2
- package/src/stdlib/theme/light.ts +4 -4
- package/src/types/common.ts +1 -0
- package/src/types/event.ts +1 -0
- package/src/types/graph.ts +59 -25
- package/src/types/hook.ts +22 -2
- package/src/types/item.ts +10 -0
- package/src/types/spec.ts +22 -3
- package/src/types/view.ts +8 -3
- package/src/util/bbox.ts +38 -1
- package/src/util/canvas.ts +5 -5
- 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 +8 -3
- package/src/util/router.ts +15 -6
- package/src/util/shape.ts +16 -14
- package/src/util/warn.ts +20 -0
- package/src/api-doc/readme.md +0 -59
package/src/runtime/graph.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import EventEmitter from '@antv/event-emitter';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AABB,
|
|
4
|
+
Canvas,
|
|
5
|
+
DataURLType,
|
|
6
|
+
DisplayObject,
|
|
7
|
+
PointLike,
|
|
8
|
+
Rect,
|
|
9
|
+
Cursor,
|
|
10
|
+
} from '@antv/g';
|
|
3
11
|
import { GraphChange, ID } from '@antv/graphlib';
|
|
4
12
|
import {
|
|
5
13
|
clone,
|
|
@@ -13,6 +21,7 @@ import {
|
|
|
13
21
|
isString,
|
|
14
22
|
map,
|
|
15
23
|
} from '@antv/util';
|
|
24
|
+
import { createDom } from '@antv/dom-util';
|
|
16
25
|
import { History } from '../stdlib/plugin/history';
|
|
17
26
|
import { Command } from '../stdlib/plugin/history/command';
|
|
18
27
|
import type {
|
|
@@ -26,7 +35,7 @@ import type {
|
|
|
26
35
|
import type { CameraAnimationOptions } from '../types/animate';
|
|
27
36
|
import type { BehaviorOptionsOf, BehaviorRegistry } from '../types/behavior';
|
|
28
37
|
import type { ComboDisplayModel, ComboModel } from '../types/combo';
|
|
29
|
-
import type { Padding, Point } from '../types/common';
|
|
38
|
+
import type { Bounds, Padding, Point } from '../types/common';
|
|
30
39
|
import type { DataChangeType, DataConfig, GraphCore } from '../types/data';
|
|
31
40
|
import type { EdgeDisplayModel, EdgeModel, EdgeModelData } from '../types/edge';
|
|
32
41
|
import type { StackType } from '../types/history';
|
|
@@ -47,7 +56,9 @@ import type {
|
|
|
47
56
|
import { FitViewRules, GraphTransformOptions } from '../types/view';
|
|
48
57
|
import { changeRenderer, createCanvas } from '../util/canvas';
|
|
49
58
|
import { formatPadding } from '../util/shape';
|
|
59
|
+
import { getLayoutBounds } from '../util/layout';
|
|
50
60
|
import { Plugin as PluginBase } from '../types/plugin';
|
|
61
|
+
import { ComboMapper, EdgeMapper, NodeMapper } from '../types/spec';
|
|
51
62
|
import {
|
|
52
63
|
DataController,
|
|
53
64
|
ExtensionController,
|
|
@@ -101,7 +112,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
101
112
|
constructor(spec: Specification<B, T>) {
|
|
102
113
|
super();
|
|
103
114
|
|
|
104
|
-
this.specification = Object.assign(
|
|
115
|
+
this.specification = Object.assign(
|
|
116
|
+
{},
|
|
117
|
+
this.defaultSpecification,
|
|
118
|
+
this.formatSpecification(spec),
|
|
119
|
+
);
|
|
105
120
|
this.initHooks();
|
|
106
121
|
this.initCanvas();
|
|
107
122
|
this.initControllers();
|
|
@@ -345,7 +360,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
345
360
|
main: Canvas;
|
|
346
361
|
transient: Canvas;
|
|
347
362
|
};
|
|
348
|
-
}>({ name: '
|
|
363
|
+
}>({ name: 'themechange' }),
|
|
364
|
+
mapperchange: new Hook<{
|
|
365
|
+
type: ITEM_TYPE;
|
|
366
|
+
mapper: NodeMapper | EdgeMapper | ComboMapper;
|
|
367
|
+
}>({ name: 'mapperchange' }),
|
|
349
368
|
treecollapseexpand: new Hook<{
|
|
350
369
|
ids: ID[];
|
|
351
370
|
animate: boolean;
|
|
@@ -356,11 +375,31 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
356
375
|
};
|
|
357
376
|
}
|
|
358
377
|
|
|
378
|
+
private formatSpecification(spec: Specification<B, T>) {
|
|
379
|
+
return {
|
|
380
|
+
...this.specification,
|
|
381
|
+
...spec,
|
|
382
|
+
optimize: {
|
|
383
|
+
tileBehavior: 2000,
|
|
384
|
+
tileBehaviorSize: 1000,
|
|
385
|
+
tileFirstRender: 10000,
|
|
386
|
+
tileFirstRenderSize: 1000,
|
|
387
|
+
...this.specification?.optimize,
|
|
388
|
+
...spec.optimize,
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
359
393
|
/**
|
|
360
394
|
* Update the specs(configurations).
|
|
361
395
|
*/
|
|
362
396
|
public updateSpecification(spec: Specification<B, T>): Specification<B, T> {
|
|
363
|
-
|
|
397
|
+
const newSpec = Object.assign(
|
|
398
|
+
this.specification,
|
|
399
|
+
this.formatSpecification(spec),
|
|
400
|
+
);
|
|
401
|
+
// TODO: update something
|
|
402
|
+
return newSpec;
|
|
364
403
|
}
|
|
365
404
|
/**
|
|
366
405
|
* Update the theme specs (configurations).
|
|
@@ -382,6 +421,32 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
382
421
|
});
|
|
383
422
|
}
|
|
384
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Update the item display mapper for a specific item type.
|
|
426
|
+
* @param {ITEM_TYPE} type - The type of item (node, edge, or combo).
|
|
427
|
+
* @param {NodeMapper | EdgeMapper | ComboMapper} mapper - The mapper to be updated.
|
|
428
|
+
* */
|
|
429
|
+
public updateMapper(
|
|
430
|
+
type: ITEM_TYPE,
|
|
431
|
+
mapper: NodeMapper | EdgeMapper | ComboMapper,
|
|
432
|
+
) {
|
|
433
|
+
switch (type) {
|
|
434
|
+
case 'node':
|
|
435
|
+
this.specification.node = mapper as NodeMapper;
|
|
436
|
+
break;
|
|
437
|
+
case 'edge':
|
|
438
|
+
this.specification.edge = mapper as EdgeMapper;
|
|
439
|
+
break;
|
|
440
|
+
case 'combo':
|
|
441
|
+
this.specification.combo = mapper as ComboMapper;
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
this.hooks.mapperchange.emit({
|
|
445
|
+
type,
|
|
446
|
+
mapper,
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
|
|
385
450
|
/**
|
|
386
451
|
* Get the copy of specs(configurations).
|
|
387
452
|
* @returns graph specs
|
|
@@ -398,12 +463,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
398
463
|
* @group Data
|
|
399
464
|
*/
|
|
400
465
|
public async read(data: DataConfig) {
|
|
466
|
+
const { tileFirstRender, tileFirstRenderSize } =
|
|
467
|
+
this.specification.optimize || {};
|
|
401
468
|
this.hooks.datachange.emit({ data, type: 'replace' });
|
|
402
469
|
const emitRender = async () => {
|
|
403
|
-
this.hooks.render.
|
|
470
|
+
await this.hooks.render.emitLinearAsync({
|
|
404
471
|
graphCore: this.dataController.graphCore,
|
|
405
472
|
theme: this.themeController.specification,
|
|
406
473
|
transientCanvas: this.transientCanvas,
|
|
474
|
+
tileOptimize: {
|
|
475
|
+
tileFirstRender,
|
|
476
|
+
tileFirstRenderSize,
|
|
477
|
+
},
|
|
407
478
|
});
|
|
408
479
|
this.emit('afterrender');
|
|
409
480
|
|
|
@@ -411,15 +482,28 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
411
482
|
const { autoFit } = this.specification;
|
|
412
483
|
if (autoFit) {
|
|
413
484
|
if (autoFit === 'view') {
|
|
414
|
-
await this.fitView();
|
|
485
|
+
await this.fitView({ rules: { boundsType: 'layout' } });
|
|
415
486
|
} else if (autoFit === 'center') {
|
|
416
|
-
await this.fitCenter();
|
|
487
|
+
await this.fitCenter('layout');
|
|
417
488
|
} else {
|
|
418
489
|
const { type, effectTiming, ...others } = autoFit;
|
|
419
490
|
if (type === 'view') {
|
|
420
|
-
|
|
491
|
+
const { padding, rules } = others as {
|
|
492
|
+
padding: Padding;
|
|
493
|
+
rules: FitViewRules;
|
|
494
|
+
};
|
|
495
|
+
await this.fitView(
|
|
496
|
+
{
|
|
497
|
+
padding,
|
|
498
|
+
rules: {
|
|
499
|
+
...rules,
|
|
500
|
+
boundsType: 'layout',
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
effectTiming,
|
|
504
|
+
);
|
|
421
505
|
} else if (type === 'center') {
|
|
422
|
-
await this.fitCenter(effectTiming);
|
|
506
|
+
await this.fitCenter('layout', effectTiming);
|
|
423
507
|
} else if (type === 'position') {
|
|
424
508
|
// TODO: align
|
|
425
509
|
await this.translateTo((others as any).position, effectTiming);
|
|
@@ -452,11 +536,17 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
452
536
|
data: DataConfig,
|
|
453
537
|
type: 'replace' | 'mergeReplace' = 'mergeReplace',
|
|
454
538
|
) {
|
|
539
|
+
const { tileFirstRender, tileFirstRenderSize } =
|
|
540
|
+
this.specification.optimize || {};
|
|
455
541
|
this.hooks.datachange.emit({ data, type });
|
|
456
542
|
this.hooks.render.emit({
|
|
457
543
|
graphCore: this.dataController.graphCore,
|
|
458
544
|
theme: this.themeController.specification,
|
|
459
545
|
transientCanvas: this.transientCanvas,
|
|
546
|
+
tileOptimize: {
|
|
547
|
+
tileFirstRender,
|
|
548
|
+
tileFirstRenderSize,
|
|
549
|
+
},
|
|
460
550
|
});
|
|
461
551
|
this.emit('afterrender');
|
|
462
552
|
|
|
@@ -468,7 +558,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
468
558
|
* @returns
|
|
469
559
|
*/
|
|
470
560
|
public clear() {
|
|
471
|
-
this.
|
|
561
|
+
this.startHistoryBatch();
|
|
472
562
|
this.removeData(
|
|
473
563
|
'edge',
|
|
474
564
|
this.getAllEdgesData().map((edge) => edge.id),
|
|
@@ -481,7 +571,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
481
571
|
'combo',
|
|
482
572
|
this.getAllCombosData().map((combo) => combo.id),
|
|
483
573
|
);
|
|
484
|
-
this.
|
|
574
|
+
this.stopHistoryBatch();
|
|
485
575
|
}
|
|
486
576
|
|
|
487
577
|
public getViewportCenter(): PointLike {
|
|
@@ -492,9 +582,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
492
582
|
options: GraphTransformOptions,
|
|
493
583
|
effectTiming?: CameraAnimationOptions,
|
|
494
584
|
): Promise<void> {
|
|
585
|
+
const { tileLodSize } = this.specification.optimize || {};
|
|
495
586
|
await this.hooks.viewportchange.emitLinearAsync({
|
|
496
587
|
transform: options,
|
|
497
588
|
effectTiming,
|
|
589
|
+
tileLodSize,
|
|
498
590
|
});
|
|
499
591
|
this.emit('viewportchange', options);
|
|
500
592
|
}
|
|
@@ -637,8 +729,8 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
637
729
|
*/
|
|
638
730
|
public async fitView(
|
|
639
731
|
options?: {
|
|
640
|
-
padding
|
|
641
|
-
rules
|
|
732
|
+
padding?: Padding;
|
|
733
|
+
rules?: FitViewRules;
|
|
642
734
|
},
|
|
643
735
|
effectTiming?: CameraAnimationOptions,
|
|
644
736
|
) {
|
|
@@ -646,13 +738,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
646
738
|
const [top, right, bottom, left] = padding
|
|
647
739
|
? formatPadding(padding)
|
|
648
740
|
: [0, 0, 0, 0];
|
|
649
|
-
const {
|
|
741
|
+
const {
|
|
742
|
+
direction = 'both',
|
|
743
|
+
ratioRule = 'min',
|
|
744
|
+
boundsType = 'render',
|
|
745
|
+
} = rules || {};
|
|
650
746
|
|
|
651
|
-
// Get the bounds of the whole graph.
|
|
652
747
|
const {
|
|
653
748
|
center: [graphCenterX, graphCenterY],
|
|
654
749
|
halfExtents,
|
|
655
|
-
} =
|
|
750
|
+
} =
|
|
751
|
+
boundsType === 'render'
|
|
752
|
+
? // Get the bounds of the whole graph content.
|
|
753
|
+
this.canvas.document.documentElement.getBounds()
|
|
754
|
+
: // Get the bounds of the nodes positions while the graph content is not ready.
|
|
755
|
+
getLayoutBounds(this);
|
|
656
756
|
const origin = this.canvas.canvas2Viewport({
|
|
657
757
|
x: graphCenterX,
|
|
658
758
|
y: graphCenterY,
|
|
@@ -703,11 +803,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
703
803
|
* Fit the graph center to the view center.
|
|
704
804
|
* @param effectTiming animation configurations
|
|
705
805
|
*/
|
|
706
|
-
public async fitCenter(
|
|
707
|
-
|
|
806
|
+
public async fitCenter(
|
|
807
|
+
boundsType: 'render' | 'layout' = 'render',
|
|
808
|
+
effectTiming?: CameraAnimationOptions,
|
|
809
|
+
) {
|
|
708
810
|
const {
|
|
709
811
|
center: [graphCenterX, graphCenterY],
|
|
710
|
-
} =
|
|
812
|
+
} =
|
|
813
|
+
boundsType === 'render'
|
|
814
|
+
? // Get the bounds of the whole graph content.
|
|
815
|
+
this.canvas.document.documentElement.getBounds()
|
|
816
|
+
: // Get the bounds of the nodes positions while the graph content is not ready.
|
|
817
|
+
getLayoutBounds(this);
|
|
711
818
|
await this.translateTo(
|
|
712
819
|
this.canvas.canvas2Viewport({ x: graphCenterX, y: graphCenterY }),
|
|
713
820
|
effectTiming,
|
|
@@ -779,6 +886,26 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
779
886
|
this.canvas.resize(size[0], size[1]);
|
|
780
887
|
}
|
|
781
888
|
|
|
889
|
+
public getCanvasRange(): Bounds {
|
|
890
|
+
const [width, height] = this.getSize();
|
|
891
|
+
const leftTop = this.getCanvasByViewport({ x: 0, y: 0 });
|
|
892
|
+
const rightBottom = this.getCanvasByViewport({ x: width, y: height });
|
|
893
|
+
return {
|
|
894
|
+
min: [leftTop.x, leftTop.y, leftTop.z],
|
|
895
|
+
max: [rightBottom.x, rightBottom.y, rightBottom.z],
|
|
896
|
+
center: [
|
|
897
|
+
(leftTop.x + rightBottom.x) / 2,
|
|
898
|
+
(leftTop.y + rightBottom.y) / 2,
|
|
899
|
+
(leftTop.z + rightBottom.z) / 2,
|
|
900
|
+
],
|
|
901
|
+
halfExtents: [
|
|
902
|
+
(rightBottom.x - leftTop.x) / 2,
|
|
903
|
+
(rightBottom.y - leftTop.y) / 2,
|
|
904
|
+
(rightBottom.z - leftTop.z) / 2,
|
|
905
|
+
],
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
|
|
782
909
|
/**
|
|
783
910
|
* Get the rendering coordinate according to the canvas dom (viewport) coordinate.
|
|
784
911
|
* @param Point rendering coordinate
|
|
@@ -990,19 +1117,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
990
1117
|
graphCore.once('changed', (event) => {
|
|
991
1118
|
if (!event.changes.length) return;
|
|
992
1119
|
const changes = event.changes;
|
|
993
|
-
|
|
994
|
-
type: itemType,
|
|
995
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
996
|
-
graphCore,
|
|
997
|
-
theme: specification,
|
|
998
|
-
});
|
|
999
|
-
this.emit('afteritemchange', {
|
|
1120
|
+
const timingParameters = {
|
|
1000
1121
|
type: itemType,
|
|
1001
1122
|
action: 'add',
|
|
1002
1123
|
models,
|
|
1003
1124
|
apiName: 'addData',
|
|
1004
1125
|
changes,
|
|
1126
|
+
};
|
|
1127
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1128
|
+
this.hooks.itemchange.emit({
|
|
1129
|
+
type: itemType,
|
|
1130
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
1131
|
+
graphCore,
|
|
1132
|
+
theme: specification,
|
|
1005
1133
|
});
|
|
1134
|
+
this.emit('afteritemchange', timingParameters);
|
|
1006
1135
|
});
|
|
1007
1136
|
|
|
1008
1137
|
const modelArr = isArray(models) ? models : [models];
|
|
@@ -1027,27 +1156,39 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1027
1156
|
public removeData(itemType: ITEM_TYPE, ids: ID | ID[]) {
|
|
1028
1157
|
const idArr = isArray(ids) ? ids : [ids];
|
|
1029
1158
|
const data = { nodes: [], edges: [], combos: [] };
|
|
1030
|
-
const {
|
|
1159
|
+
const { graphCore } = this.dataController;
|
|
1031
1160
|
const { specification } = this.themeController;
|
|
1032
|
-
const getItem =
|
|
1033
|
-
|
|
1034
|
-
data[`${itemType}s`] = idArr
|
|
1161
|
+
const getItem = itemType === 'edge' ? graphCore.getEdge : graphCore.getNode;
|
|
1162
|
+
const hasItem = itemType === 'edge' ? graphCore.hasEdge : graphCore.hasNode;
|
|
1163
|
+
data[`${itemType}s`] = idArr
|
|
1164
|
+
.map((id) => {
|
|
1165
|
+
if (!hasItem.bind(graphCore)(id)) {
|
|
1166
|
+
console.warn(
|
|
1167
|
+
`The ${itemType} data with id ${id} does not exist. It will be ignored`,
|
|
1168
|
+
);
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
return getItem.bind(graphCore)(id);
|
|
1172
|
+
})
|
|
1173
|
+
.filter(Boolean);
|
|
1035
1174
|
graphCore.once('changed', (event) => {
|
|
1036
1175
|
if (!event.changes.length) return;
|
|
1037
1176
|
const changes = event.changes;
|
|
1038
|
-
|
|
1039
|
-
type: itemType,
|
|
1040
|
-
changes: event.changes,
|
|
1041
|
-
graphCore,
|
|
1042
|
-
theme: specification,
|
|
1043
|
-
});
|
|
1044
|
-
this.emit('afteritemchange', {
|
|
1177
|
+
const timingParameters = {
|
|
1045
1178
|
type: itemType,
|
|
1046
1179
|
action: 'remove',
|
|
1047
1180
|
ids: idArr,
|
|
1048
1181
|
apiName: 'removeData',
|
|
1049
1182
|
changes,
|
|
1183
|
+
};
|
|
1184
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1185
|
+
this.hooks.itemchange.emit({
|
|
1186
|
+
type: itemType,
|
|
1187
|
+
changes: event.changes,
|
|
1188
|
+
graphCore,
|
|
1189
|
+
theme: specification,
|
|
1050
1190
|
});
|
|
1191
|
+
this.emit('afteritemchange', timingParameters);
|
|
1051
1192
|
});
|
|
1052
1193
|
this.hooks.datachange.emit({
|
|
1053
1194
|
data,
|
|
@@ -1140,19 +1281,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1140
1281
|
const { specification } = this.themeController;
|
|
1141
1282
|
graphCore.once('changed', (event) => {
|
|
1142
1283
|
const changes = this.extendChanges(clone(event.changes));
|
|
1143
|
-
|
|
1144
|
-
type: itemType,
|
|
1145
|
-
changes: event.changes,
|
|
1146
|
-
graphCore,
|
|
1147
|
-
theme: specification,
|
|
1148
|
-
});
|
|
1149
|
-
this.emit('afteritemchange', {
|
|
1284
|
+
const timingParameters = {
|
|
1150
1285
|
type: itemType,
|
|
1151
1286
|
action: 'update',
|
|
1152
1287
|
models,
|
|
1153
1288
|
apiName: 'updateData',
|
|
1154
1289
|
changes,
|
|
1290
|
+
};
|
|
1291
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1292
|
+
this.hooks.itemchange.emit({
|
|
1293
|
+
type: itemType,
|
|
1294
|
+
changes: event.changes,
|
|
1295
|
+
graphCore,
|
|
1296
|
+
theme: specification,
|
|
1155
1297
|
});
|
|
1298
|
+
this.emit('afteritemchange', timingParameters);
|
|
1156
1299
|
});
|
|
1157
1300
|
|
|
1158
1301
|
this.hooks.datachange.emit({
|
|
@@ -1261,6 +1404,15 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1261
1404
|
const changes = event.changes.filter(
|
|
1262
1405
|
(change) => !isEqual(change.newValue, change.oldValue),
|
|
1263
1406
|
);
|
|
1407
|
+
const timingParameters = {
|
|
1408
|
+
type,
|
|
1409
|
+
action: 'updatePosition',
|
|
1410
|
+
upsertAncestors,
|
|
1411
|
+
models,
|
|
1412
|
+
apiName: 'updatePosition',
|
|
1413
|
+
changes,
|
|
1414
|
+
};
|
|
1415
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1264
1416
|
this.hooks.itemchange.emit({
|
|
1265
1417
|
type,
|
|
1266
1418
|
changes: event.changes,
|
|
@@ -1271,14 +1423,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1271
1423
|
animate: !disableAnimate,
|
|
1272
1424
|
callback,
|
|
1273
1425
|
});
|
|
1274
|
-
this.emit('afteritemchange',
|
|
1275
|
-
type,
|
|
1276
|
-
action: 'updatePosition',
|
|
1277
|
-
upsertAncestors,
|
|
1278
|
-
models,
|
|
1279
|
-
apiName: 'updatePosition',
|
|
1280
|
-
changes,
|
|
1281
|
-
});
|
|
1426
|
+
this.emit('afteritemchange', timingParameters);
|
|
1282
1427
|
});
|
|
1283
1428
|
|
|
1284
1429
|
this.hooks.datachange.emit({
|
|
@@ -1344,7 +1489,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1344
1489
|
* @returns
|
|
1345
1490
|
* @group Item
|
|
1346
1491
|
*/
|
|
1347
|
-
public hideItem(
|
|
1492
|
+
public hideItem(
|
|
1493
|
+
ids: ID | ID[],
|
|
1494
|
+
disableAnimate = false,
|
|
1495
|
+
keepKeyShape = false,
|
|
1496
|
+
) {
|
|
1348
1497
|
const idArr = isArray(ids) ? ids : [ids];
|
|
1349
1498
|
if (isEmpty(idArr)) return;
|
|
1350
1499
|
const changes = {
|
|
@@ -1356,6 +1505,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1356
1505
|
value: false,
|
|
1357
1506
|
graphCore: this.dataController.graphCore,
|
|
1358
1507
|
animate: !disableAnimate,
|
|
1508
|
+
keepKeyShape,
|
|
1359
1509
|
});
|
|
1360
1510
|
this.emit('afteritemvisibilitychange', {
|
|
1361
1511
|
ids,
|
|
@@ -1363,6 +1513,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1363
1513
|
animate: !disableAnimate,
|
|
1364
1514
|
action: 'updateVisibility',
|
|
1365
1515
|
apiName: 'hideItem',
|
|
1516
|
+
keepKeyShape,
|
|
1366
1517
|
changes,
|
|
1367
1518
|
});
|
|
1368
1519
|
}
|
|
@@ -1547,19 +1698,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1547
1698
|
graphCore.once('changed', (event) => {
|
|
1548
1699
|
if (!event.changes.length) return;
|
|
1549
1700
|
const changes = event.changes;
|
|
1550
|
-
|
|
1551
|
-
type: 'combo',
|
|
1552
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
1553
|
-
graphCore,
|
|
1554
|
-
theme: specification,
|
|
1555
|
-
});
|
|
1556
|
-
this.emit('afteritemchange', {
|
|
1701
|
+
const timingParameters = {
|
|
1557
1702
|
type: 'combo',
|
|
1558
1703
|
action: 'add',
|
|
1559
1704
|
models: [model],
|
|
1560
1705
|
apiName: 'addCombo',
|
|
1561
1706
|
changes,
|
|
1707
|
+
};
|
|
1708
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1709
|
+
this.hooks.itemchange.emit({
|
|
1710
|
+
type: 'combo',
|
|
1711
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
1712
|
+
graphCore,
|
|
1713
|
+
theme: specification,
|
|
1562
1714
|
});
|
|
1715
|
+
this.emit('afteritemchange', timingParameters);
|
|
1563
1716
|
});
|
|
1564
1717
|
|
|
1565
1718
|
const data = {
|
|
@@ -1588,7 +1741,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1588
1741
|
*/
|
|
1589
1742
|
public collapseCombo(comboIds: ID | ID[]) {
|
|
1590
1743
|
const ids = isArray(comboIds) ? comboIds : [comboIds];
|
|
1591
|
-
this.
|
|
1744
|
+
this.executeWithNoStack(() => {
|
|
1592
1745
|
this.updateData(
|
|
1593
1746
|
'combo',
|
|
1594
1747
|
ids.map((id) => ({ id, data: { collapsed: true } })),
|
|
@@ -1608,7 +1761,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1608
1761
|
*/
|
|
1609
1762
|
public expandCombo(comboIds: ID | ID[]) {
|
|
1610
1763
|
const ids = isArray(comboIds) ? comboIds : [comboIds];
|
|
1611
|
-
this.
|
|
1764
|
+
this.executeWithNoStack(() => {
|
|
1612
1765
|
this.updateData(
|
|
1613
1766
|
'combo',
|
|
1614
1767
|
ids.map((id) => ({ id, data: { collapsed: false } })),
|
|
@@ -1645,16 +1798,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1645
1798
|
graphCore.once('changed', (event) => {
|
|
1646
1799
|
if (!event.changes.length) return;
|
|
1647
1800
|
const changes = this.extendChanges(clone(event.changes));
|
|
1648
|
-
|
|
1649
|
-
type: 'combo',
|
|
1650
|
-
changes: event.changes,
|
|
1651
|
-
graphCore,
|
|
1652
|
-
theme: specification,
|
|
1653
|
-
upsertAncestors,
|
|
1654
|
-
action: 'updatePosition',
|
|
1655
|
-
callback,
|
|
1656
|
-
});
|
|
1657
|
-
this.emit('afteritemchange', {
|
|
1801
|
+
const timingParameters = {
|
|
1658
1802
|
type: 'combo',
|
|
1659
1803
|
ids: idArr,
|
|
1660
1804
|
dx,
|
|
@@ -1663,7 +1807,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1663
1807
|
upsertAncestors,
|
|
1664
1808
|
apiName: 'moveCombo',
|
|
1665
1809
|
changes,
|
|
1810
|
+
};
|
|
1811
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1812
|
+
this.hooks.itemchange.emit({
|
|
1813
|
+
type: 'combo',
|
|
1814
|
+
changes: event.changes,
|
|
1815
|
+
graphCore,
|
|
1816
|
+
theme: specification,
|
|
1817
|
+
upsertAncestors,
|
|
1818
|
+
action: 'updatePosition',
|
|
1819
|
+
callback,
|
|
1666
1820
|
});
|
|
1821
|
+
this.emit('afteritemchange', timingParameters);
|
|
1667
1822
|
});
|
|
1668
1823
|
|
|
1669
1824
|
this.hooks.datachange.emit({
|
|
@@ -1762,6 +1917,15 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1762
1917
|
return this.interactionController.getMode();
|
|
1763
1918
|
}
|
|
1764
1919
|
|
|
1920
|
+
/**
|
|
1921
|
+
* Set the cursor. But the cursor in item's style has higher priority.
|
|
1922
|
+
* @param cursor
|
|
1923
|
+
*/
|
|
1924
|
+
public setCursor(cursor: Cursor) {
|
|
1925
|
+
this.canvas.setCursor(cursor);
|
|
1926
|
+
this.transientCanvas.setCursor(cursor);
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1765
1929
|
/**
|
|
1766
1930
|
* Add behavior(s) to mode(s).
|
|
1767
1931
|
* @param behaviors behavior names or configs
|
|
@@ -1979,9 +2143,19 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1979
2143
|
type: ITEM_TYPE | SHAPE_TYPE,
|
|
1980
2144
|
id: ID,
|
|
1981
2145
|
config: {
|
|
1982
|
-
action
|
|
1983
|
-
|
|
1984
|
-
|
|
2146
|
+
action?: 'remove' | 'add' | 'update' | undefined;
|
|
2147
|
+
/** Data to be merged into the transient item. */
|
|
2148
|
+
data?: Record<string, any>;
|
|
2149
|
+
/** Style to be merged into the transient shape. */
|
|
2150
|
+
style?: ShapeStyle;
|
|
2151
|
+
/** For type: 'edge' */
|
|
2152
|
+
drawSource?: boolean;
|
|
2153
|
+
/** For type: 'edge' */
|
|
2154
|
+
drawTarget?: boolean;
|
|
2155
|
+
/** Only shape with id in shapeIds will be cloned while type is ITEM_TYPE. If shapeIds is not assigned, the whole item will be cloned. */
|
|
2156
|
+
shapeIds?: string[];
|
|
2157
|
+
/** Whether show the shapes in shapeIds. True by default. */
|
|
2158
|
+
visible?: boolean;
|
|
1985
2159
|
upsertAncestors?: boolean;
|
|
1986
2160
|
},
|
|
1987
2161
|
canvas?: Canvas,
|
|
@@ -1996,6 +2170,328 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1996
2170
|
return this.itemController.getTransient(String(id));
|
|
1997
2171
|
}
|
|
1998
2172
|
|
|
2173
|
+
// ===== download operations =====
|
|
2174
|
+
/**
|
|
2175
|
+
* Asynchronously generates a Data URL representation of the canvas content, including
|
|
2176
|
+
* background, main content, and transient canvas.
|
|
2177
|
+
* @param The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
2178
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
2179
|
+
*/
|
|
2180
|
+
public async toDataURL(type?: DataURLType): Promise<string> {
|
|
2181
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
2182
|
+
const canvas = this.canvas;
|
|
2183
|
+
const transientCanvas = this.transientCanvas;
|
|
2184
|
+
const rendererType = this.rendererType;
|
|
2185
|
+
|
|
2186
|
+
const pixelRatio =
|
|
2187
|
+
typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
2188
|
+
const width = this.getSize()[0];
|
|
2189
|
+
const height = this.getSize()[1];
|
|
2190
|
+
|
|
2191
|
+
const vContainerDOM: HTMLDivElement = createDom(
|
|
2192
|
+
'<div id="virtual-image"></div>',
|
|
2193
|
+
);
|
|
2194
|
+
const vCanvas = createCanvas(
|
|
2195
|
+
rendererType,
|
|
2196
|
+
vContainerDOM,
|
|
2197
|
+
width,
|
|
2198
|
+
height,
|
|
2199
|
+
pixelRatio,
|
|
2200
|
+
);
|
|
2201
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
2202
|
+
let bgRect;
|
|
2203
|
+
if (rendererType !== 'svg') {
|
|
2204
|
+
bgRect = new Rect({
|
|
2205
|
+
style: {
|
|
2206
|
+
x: 0,
|
|
2207
|
+
y: 0,
|
|
2208
|
+
z: -1,
|
|
2209
|
+
width: vCanvasContextService.getDomElement().width,
|
|
2210
|
+
height: vCanvasContextService.getDomElement().height,
|
|
2211
|
+
//@ts-ignore
|
|
2212
|
+
fill: backgroundCanvas.getContextService().getDomElement().style[
|
|
2213
|
+
'background-color'
|
|
2214
|
+
],
|
|
2215
|
+
},
|
|
2216
|
+
});
|
|
2217
|
+
vCanvas.appendChild(bgRect);
|
|
2218
|
+
}
|
|
2219
|
+
const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
|
|
2220
|
+
const clonedGroup = canvas.getRoot().cloneNode(true);
|
|
2221
|
+
const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
|
|
2222
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
2223
|
+
vCanvas.appendChild(clonedGroup);
|
|
2224
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
2225
|
+
vCanvas.render();
|
|
2226
|
+
|
|
2227
|
+
if (!type) type = 'image/png';
|
|
2228
|
+
let dataURL = '';
|
|
2229
|
+
await vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
2230
|
+
dataURL = url;
|
|
2231
|
+
});
|
|
2232
|
+
return dataURL;
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
/**
|
|
2236
|
+
* Asynchronously generates a Data URL representation of the full canvas content,
|
|
2237
|
+
* including background, main content, and transient canvas, with optional padding.
|
|
2238
|
+
* @param type The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
2239
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
2240
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
2241
|
+
*/
|
|
2242
|
+
public async toFullDataURL(
|
|
2243
|
+
type?: DataURLType,
|
|
2244
|
+
imageConfig?: { padding?: number | number[] },
|
|
2245
|
+
) {
|
|
2246
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
2247
|
+
const canvas = this.canvas;
|
|
2248
|
+
const transientCanvas = this.transientCanvas;
|
|
2249
|
+
const backgroundRoot = canvas.getRoot();
|
|
2250
|
+
const root = canvas.getRoot();
|
|
2251
|
+
const transientRoot = transientCanvas.getRoot();
|
|
2252
|
+
const rendererType = this.rendererType;
|
|
2253
|
+
|
|
2254
|
+
const backgroundBBox = backgroundRoot.getBBox();
|
|
2255
|
+
const BBox = root.getBBox();
|
|
2256
|
+
const transientBBox = transientRoot.getBBox();
|
|
2257
|
+
|
|
2258
|
+
let padding = imageConfig ? imageConfig.padding : undefined;
|
|
2259
|
+
if (!padding) {
|
|
2260
|
+
padding = [0, 0, 0, 0];
|
|
2261
|
+
} else if (isNumber(padding)) {
|
|
2262
|
+
padding = [padding, padding, padding, padding];
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
const left =
|
|
2266
|
+
(transientBBox.left
|
|
2267
|
+
? backgroundBBox.left
|
|
2268
|
+
? Math.min(backgroundBBox.left, BBox.left, transientBBox.left)
|
|
2269
|
+
: Math.min(BBox.left, transientBBox.left)
|
|
2270
|
+
: BBox.left) - padding[3];
|
|
2271
|
+
const right =
|
|
2272
|
+
(transientBBox.right
|
|
2273
|
+
? backgroundBBox.right
|
|
2274
|
+
? Math.max(backgroundBBox.right, BBox.right, transientBBox.right)
|
|
2275
|
+
: Math.max(BBox.right, transientBBox.right)
|
|
2276
|
+
: BBox.right) + padding[1];
|
|
2277
|
+
const top =
|
|
2278
|
+
(transientBBox.top
|
|
2279
|
+
? backgroundBBox.top
|
|
2280
|
+
? Math.min(backgroundBBox.top, BBox.top, transientBBox.top)
|
|
2281
|
+
: Math.min(BBox.top, transientBBox.top)
|
|
2282
|
+
: BBox.top) - padding[0];
|
|
2283
|
+
const bottom =
|
|
2284
|
+
(transientBBox.bottom
|
|
2285
|
+
? backgroundBBox.bottom
|
|
2286
|
+
? Math.max(backgroundBBox.bottom, BBox.bottom, transientBBox.bottom)
|
|
2287
|
+
: Math.max(BBox.bottom, transientBBox.bottom)
|
|
2288
|
+
: BBox.bottom) + padding[2];
|
|
2289
|
+
|
|
2290
|
+
const graphCenterX = (left + right) / 2;
|
|
2291
|
+
const graphCenterY = (top + bottom) / 2;
|
|
2292
|
+
const halfX = (right - left) / 2;
|
|
2293
|
+
const halfY = (bottom - top) / 2;
|
|
2294
|
+
|
|
2295
|
+
const pixelRatio =
|
|
2296
|
+
typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
2297
|
+
const vWidth = halfX * 2;
|
|
2298
|
+
const vHeight = halfY * 2;
|
|
2299
|
+
const vContainerDOM: HTMLDivElement = createDom(
|
|
2300
|
+
'<div id="virtual-image"></div>',
|
|
2301
|
+
);
|
|
2302
|
+
const vCanvas = createCanvas(
|
|
2303
|
+
rendererType,
|
|
2304
|
+
vContainerDOM,
|
|
2305
|
+
vWidth,
|
|
2306
|
+
vHeight,
|
|
2307
|
+
pixelRatio,
|
|
2308
|
+
);
|
|
2309
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
2310
|
+
if (rendererType !== 'svg') {
|
|
2311
|
+
const bgRect = new Rect({
|
|
2312
|
+
style: {
|
|
2313
|
+
x: 0,
|
|
2314
|
+
y: 0,
|
|
2315
|
+
z: -1,
|
|
2316
|
+
width: vCanvasContextService.getDomElement().width,
|
|
2317
|
+
height: vCanvasContextService.getDomElement().height,
|
|
2318
|
+
//@ts-ignore
|
|
2319
|
+
fill: backgroundCanvas.getContextService().getDomElement().style[
|
|
2320
|
+
'background-color'
|
|
2321
|
+
],
|
|
2322
|
+
},
|
|
2323
|
+
});
|
|
2324
|
+
vCanvas.appendChild(bgRect);
|
|
2325
|
+
}
|
|
2326
|
+
const backgroundClonedGroup = backgroundRoot.cloneNode(true);
|
|
2327
|
+
const clonedGroup = root.cloneNode(true);
|
|
2328
|
+
const transientClonedGroup = transientRoot.cloneNode(true);
|
|
2329
|
+
const transPosition: [number, number] = [
|
|
2330
|
+
-graphCenterX + halfX,
|
|
2331
|
+
-graphCenterY + halfY,
|
|
2332
|
+
];
|
|
2333
|
+
backgroundClonedGroup.setPosition(transPosition);
|
|
2334
|
+
clonedGroup.setPosition(transPosition);
|
|
2335
|
+
transientClonedGroup.setPosition(transPosition);
|
|
2336
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
2337
|
+
vCanvas.appendChild(clonedGroup);
|
|
2338
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
2339
|
+
vCanvas.render();
|
|
2340
|
+
|
|
2341
|
+
if (!type) type = 'image/png';
|
|
2342
|
+
let dataURL = '';
|
|
2343
|
+
await vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
2344
|
+
dataURL = url;
|
|
2345
|
+
});
|
|
2346
|
+
return dataURL;
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
/**
|
|
2350
|
+
* Converts a Data URL to an image file and handles the download of the image.
|
|
2351
|
+
* @param dataURL The Data URL of the image to be converted and downloaded.
|
|
2352
|
+
* @param renderer The renderer type ('svg' or other) used for the canvas.
|
|
2353
|
+
* @param link The HTML link element used for image download.
|
|
2354
|
+
* @param fileName The desired name for the downloaded image file.
|
|
2355
|
+
*/
|
|
2356
|
+
private dataURLToImage(dataURL: string, renderer: string, link, fileName) {
|
|
2357
|
+
if (!dataURL || dataURL === 'data:') {
|
|
2358
|
+
console.error(
|
|
2359
|
+
'Download image failed. The graph is too large or there is invalid attribute values in graph items',
|
|
2360
|
+
);
|
|
2361
|
+
return;
|
|
2362
|
+
}
|
|
2363
|
+
|
|
2364
|
+
if (typeof window !== 'undefined') {
|
|
2365
|
+
if (window.Blob && window.URL && renderer !== 'svg') {
|
|
2366
|
+
const arr = dataURL.split(',');
|
|
2367
|
+
let mime = '';
|
|
2368
|
+
if (arr && arr.length > 0) {
|
|
2369
|
+
const match = arr[0].match(/:(.*?);/);
|
|
2370
|
+
// eslint-disable-next-line prefer-destructuring
|
|
2371
|
+
if (match && match.length >= 2) mime = match[1];
|
|
2372
|
+
}
|
|
2373
|
+
|
|
2374
|
+
const bstr = atob(arr[1]);
|
|
2375
|
+
let n = bstr.length;
|
|
2376
|
+
const u8arr = new Uint8Array(n);
|
|
2377
|
+
|
|
2378
|
+
while (n--) {
|
|
2379
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
const blobObj = new Blob([u8arr], { type: mime });
|
|
2383
|
+
|
|
2384
|
+
if ((window.navigator as any).msSaveBlob) {
|
|
2385
|
+
(window.navigator as any).msSaveBlob(blobObj, fileName);
|
|
2386
|
+
} else {
|
|
2387
|
+
link.addEventListener('click', () => {
|
|
2388
|
+
link.download = fileName;
|
|
2389
|
+
link.href = window.URL.createObjectURL(blobObj);
|
|
2390
|
+
});
|
|
2391
|
+
}
|
|
2392
|
+
} else {
|
|
2393
|
+
link.addEventListener('click', () => {
|
|
2394
|
+
link.download = fileName;
|
|
2395
|
+
link.href = dataURL;
|
|
2396
|
+
});
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
/**
|
|
2402
|
+
* Initiates the download of the graph as an image with an optional name and type.
|
|
2403
|
+
* @param name The desired name for the downloaded image file (optional).
|
|
2404
|
+
* @param type The type of the image to download (optional, defaults to 'image/png').
|
|
2405
|
+
*/
|
|
2406
|
+
public downloadImage(name?: string, type?: DataURLType): void {
|
|
2407
|
+
const self = this;
|
|
2408
|
+
// self.stopAnimate();
|
|
2409
|
+
|
|
2410
|
+
const rendererType = this.rendererType;
|
|
2411
|
+
if (!type) type = 'image/png';
|
|
2412
|
+
|
|
2413
|
+
const fileName: string =
|
|
2414
|
+
(name || 'graph') +
|
|
2415
|
+
(rendererType === 'svg' ? '.svg' : type.split('/')[1]);
|
|
2416
|
+
|
|
2417
|
+
const link: HTMLAnchorElement = document.createElement('a');
|
|
2418
|
+
|
|
2419
|
+
self.asyncToDataUrl(type, (dataURL) => {
|
|
2420
|
+
this.dataURLToImage(dataURL, rendererType, link, fileName);
|
|
2421
|
+
const e = document.createEvent('MouseEvents');
|
|
2422
|
+
e.initEvent('click', false, false);
|
|
2423
|
+
link.dispatchEvent(e);
|
|
2424
|
+
});
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
/**
|
|
2428
|
+
* Initiates the download of the entire graph as an image with optional name, type, and padding configuration.
|
|
2429
|
+
* @param name The desired name for the downloaded image file (optional).
|
|
2430
|
+
* @param type The type of the image to download (optional, defaults to 'image/png').
|
|
2431
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
2432
|
+
*/
|
|
2433
|
+
public downloadFullImage(
|
|
2434
|
+
name?: string,
|
|
2435
|
+
type?: DataURLType,
|
|
2436
|
+
imageConfig?: { padding?: number | number[] },
|
|
2437
|
+
): void {
|
|
2438
|
+
const self = this;
|
|
2439
|
+
|
|
2440
|
+
const rendererType = this.rendererType;
|
|
2441
|
+
if (!type) type = 'image/png';
|
|
2442
|
+
const fileName: string =
|
|
2443
|
+
(name || 'graph') +
|
|
2444
|
+
(rendererType === 'svg' ? '.svg' : type.split('/')[1]);
|
|
2445
|
+
const link: HTMLAnchorElement = document.createElement('a');
|
|
2446
|
+
|
|
2447
|
+
self.asyncToFullDataUrl(type, imageConfig, (dataURL) => {
|
|
2448
|
+
this.dataURLToImage(dataURL, rendererType, link, fileName);
|
|
2449
|
+
const e = document.createEvent('MouseEvents');
|
|
2450
|
+
e.initEvent('click', false, false);
|
|
2451
|
+
link.dispatchEvent(e);
|
|
2452
|
+
});
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
/**
|
|
2456
|
+
* Asynchronously converts the canvas content to a Data URL of the specified type and invokes the provided callback.
|
|
2457
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
2458
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
2459
|
+
*/
|
|
2460
|
+
protected asyncToDataUrl(type?: DataURLType, callback?: Function): void {
|
|
2461
|
+
let dataURL = '';
|
|
2462
|
+
if (!type) type = 'image/png';
|
|
2463
|
+
|
|
2464
|
+
setTimeout(async () => {
|
|
2465
|
+
await this.toDataURL(type).then((url) => {
|
|
2466
|
+
dataURL = url;
|
|
2467
|
+
});
|
|
2468
|
+
if (callback) callback(dataURL);
|
|
2469
|
+
}, 16);
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
/**
|
|
2473
|
+
* Asynchronously converts the entire canvas content to a Data URL of the specified type
|
|
2474
|
+
* with optional padding, and invokes the provided callback.
|
|
2475
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
2476
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
2477
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
2478
|
+
*/
|
|
2479
|
+
protected asyncToFullDataUrl(
|
|
2480
|
+
type?: DataURLType,
|
|
2481
|
+
imageConfig?: { padding?: number | number[] },
|
|
2482
|
+
callback?: (dataUrl: string) => void,
|
|
2483
|
+
): void {
|
|
2484
|
+
let dataURL = '';
|
|
2485
|
+
if (!type) type = 'image/png';
|
|
2486
|
+
|
|
2487
|
+
setTimeout(async () => {
|
|
2488
|
+
await this.toFullDataURL(type, imageConfig).then((url) => {
|
|
2489
|
+
dataURL = url;
|
|
2490
|
+
});
|
|
2491
|
+
if (callback) callback(dataURL);
|
|
2492
|
+
}, 16);
|
|
2493
|
+
}
|
|
2494
|
+
|
|
1999
2495
|
// ===== history operations =====
|
|
2000
2496
|
|
|
2001
2497
|
/**
|
|
@@ -2020,30 +2516,30 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
2020
2516
|
/**
|
|
2021
2517
|
* Pause stacking operation.
|
|
2022
2518
|
*/
|
|
2023
|
-
public
|
|
2519
|
+
public pauseStack(): void {
|
|
2024
2520
|
const history = this.getHistoryPlugin();
|
|
2025
|
-
return history?.
|
|
2521
|
+
return history?.pauseStack();
|
|
2026
2522
|
}
|
|
2027
2523
|
|
|
2028
2524
|
/**
|
|
2029
2525
|
* Resume stacking operation.
|
|
2030
2526
|
*/
|
|
2031
|
-
public
|
|
2527
|
+
public resumeStack(): void {
|
|
2032
2528
|
const history = this.getHistoryPlugin();
|
|
2033
|
-
return history?.
|
|
2529
|
+
return history?.resumeStack();
|
|
2034
2530
|
}
|
|
2035
2531
|
|
|
2036
2532
|
/**
|
|
2037
2533
|
* Execute a callback without allowing any stacking operations.
|
|
2038
2534
|
* @param callback
|
|
2039
2535
|
*/
|
|
2040
|
-
public
|
|
2536
|
+
public executeWithNoStack = (callback: () => void): void => {
|
|
2041
2537
|
const history = this.getHistoryPlugin();
|
|
2042
|
-
history?.
|
|
2538
|
+
history?.pauseStack();
|
|
2043
2539
|
try {
|
|
2044
2540
|
callback();
|
|
2045
2541
|
} finally {
|
|
2046
|
-
history?.
|
|
2542
|
+
history?.resumeStack();
|
|
2047
2543
|
}
|
|
2048
2544
|
};
|
|
2049
2545
|
|
|
@@ -2109,41 +2605,41 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
2109
2605
|
}
|
|
2110
2606
|
|
|
2111
2607
|
/**
|
|
2112
|
-
* Begin a
|
|
2113
|
-
* Any operations performed between `
|
|
2608
|
+
* Begin a historyBatch operation.
|
|
2609
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
2114
2610
|
* treated as a single operation when undoing or redoing.
|
|
2115
2611
|
*/
|
|
2116
|
-
public
|
|
2612
|
+
public startHistoryBatch() {
|
|
2117
2613
|
const history = this.getHistoryPlugin();
|
|
2118
|
-
history?.
|
|
2614
|
+
history?.startHistoryBatch();
|
|
2119
2615
|
}
|
|
2120
2616
|
|
|
2121
2617
|
/**
|
|
2122
|
-
* End a
|
|
2123
|
-
* Any operations performed between `
|
|
2618
|
+
* End a historyBatch operation.
|
|
2619
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
2124
2620
|
* treated as a single operation when undoing or redoing.
|
|
2125
2621
|
*/
|
|
2126
|
-
public
|
|
2622
|
+
public stopHistoryBatch() {
|
|
2127
2623
|
const history = this.getHistoryPlugin();
|
|
2128
|
-
history?.
|
|
2624
|
+
history?.stopHistoryBatch();
|
|
2129
2625
|
}
|
|
2130
2626
|
|
|
2131
2627
|
/**
|
|
2132
2628
|
* Execute a provided function within a batched context
|
|
2133
2629
|
* All operations performed inside callback will be treated as a composite operation
|
|
2134
|
-
* more convenient way without manually invoking `
|
|
2630
|
+
* more convenient way without manually invoking `startHistoryBatch` and `stopHistoryBatch`.
|
|
2135
2631
|
* @param callback The func containing operations to be batched together.
|
|
2136
2632
|
*/
|
|
2137
|
-
public
|
|
2633
|
+
public historyBatch(callback: () => void) {
|
|
2138
2634
|
const history = this.getHistoryPlugin();
|
|
2139
|
-
history?.
|
|
2635
|
+
history?.historyBatch(callback);
|
|
2140
2636
|
}
|
|
2141
2637
|
|
|
2142
2638
|
/**
|
|
2143
2639
|
* Clear history stack
|
|
2144
2640
|
* @param {StackType} stackType undo/redo stack
|
|
2145
2641
|
*/
|
|
2146
|
-
public
|
|
2642
|
+
public cleanHistory(stackType?: StackType) {
|
|
2147
2643
|
const history = this.getHistoryPlugin();
|
|
2148
2644
|
if (!stackType) return history?.clear();
|
|
2149
2645
|
return stackType === 'undo'
|
|
@@ -2197,7 +2693,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
2197
2693
|
this.transientCanvas.destroy();
|
|
2198
2694
|
|
|
2199
2695
|
// clear history stack
|
|
2200
|
-
this.
|
|
2696
|
+
this.cleanHistory();
|
|
2201
2697
|
|
|
2202
2698
|
callback?.();
|
|
2203
2699
|
// }, 500);
|