@antv/g6 5.0.0-beta.2 → 5.0.0-beta.21
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/api-doc/graph.d.ts +3 -3
- package/esm/api-doc/graph.js +3 -3
- package/esm/api-doc/graph.js.map +1 -1
- package/esm/api-doc/types.d.ts +1 -0
- package/esm/api-doc/types.js +1 -2
- package/esm/api-doc/types.js.map +1 -1
- package/esm/constant/shape.d.ts +3 -1
- package/esm/index.d.ts +33 -65
- package/esm/index.js +4 -5
- package/esm/index.js.map +1 -1
- package/esm/item/combo.d.ts +1 -1
- package/esm/item/combo.js +18 -14
- package/esm/item/combo.js.map +1 -1
- package/esm/item/edge.d.ts +19 -2
- package/esm/item/edge.js +100 -44
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.d.ts +3 -2
- package/esm/item/item.js +27 -13
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +2 -8
- package/esm/item/node.js +31 -19
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/data.d.ts +30 -16
- package/esm/runtime/controller/data.js +290 -422
- package/esm/runtime/controller/data.js.map +1 -1
- package/esm/runtime/controller/interaction.js +9 -4
- package/esm/runtime/controller/interaction.js.map +1 -1
- package/esm/runtime/controller/item.d.ts +1 -0
- package/esm/runtime/controller/item.js +285 -150
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/controller/layout.js +1 -3
- package/esm/runtime/controller/layout.js.map +1 -1
- package/esm/runtime/controller/plugin.js +9 -5
- package/esm/runtime/controller/plugin.js.map +1 -1
- package/esm/runtime/graph.d.ts +104 -24
- package/esm/runtime/graph.js +472 -94
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/activate-relations.js +2 -2
- package/esm/stdlib/behavior/activate-relations.js.map +1 -1
- package/esm/stdlib/behavior/brush-select.d.ts +7 -1
- package/esm/stdlib/behavior/brush-select.js +10 -12
- 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 +215 -0
- package/esm/stdlib/behavior/create-edge.js.map +1 -0
- package/esm/stdlib/behavior/drag-canvas.d.ts +3 -1
- package/esm/stdlib/behavior/drag-canvas.js +78 -33
- 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 +80 -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 +3 -4
- 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 +87 -0
- package/esm/stdlib/behavior/shortcuts-call.js.map +1 -0
- package/esm/stdlib/behavior/zoom-canvas-3d.js +4 -1
- package/esm/stdlib/behavior/zoom-canvas-3d.js.map +1 -1
- package/esm/stdlib/behavior/zoom-canvas.d.ts +3 -1
- package/esm/stdlib/behavior/zoom-canvas.js +70 -26
- package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/esm/stdlib/data/index.d.ts +1 -0
- package/esm/stdlib/data/index.js +1 -0
- package/esm/stdlib/data/index.js.map +1 -1
- package/esm/stdlib/data/mapNodeSize.d.ts +4 -5
- package/esm/stdlib/data/mapNodeSize.js +12 -2
- package/esm/stdlib/data/mapNodeSize.js.map +1 -1
- package/esm/stdlib/data/processParallelEdges.d.ts +21 -0
- package/esm/stdlib/data/processParallelEdges.js +127 -0
- package/esm/stdlib/data/processParallelEdges.js.map +1 -0
- package/esm/stdlib/data/transformV4Data.d.ts +3 -4
- package/esm/stdlib/data/transformV4Data.js +10 -2
- package/esm/stdlib/data/transformV4Data.js.map +1 -1
- package/esm/stdlib/data/validateData.d.ts +4 -5
- package/esm/stdlib/data/validateData.js +22 -13
- package/esm/stdlib/data/validateData.js.map +1 -1
- package/esm/stdlib/index.d.ts +27 -8
- package/esm/stdlib/index.js +24 -11
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/edge/base.d.ts +3 -5
- package/esm/stdlib/item/edge/base.js +32 -31
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/edge/cubic-horizontal.js.map +1 -1
- package/esm/stdlib/item/edge/cubic-vertical.js.map +1 -1
- package/esm/stdlib/item/edge/cubic.js +1 -1
- package/esm/stdlib/item/edge/cubic.js.map +1 -1
- package/esm/stdlib/item/edge/loop.js +1 -1
- package/esm/stdlib/item/edge/loop.js.map +1 -1
- package/esm/stdlib/item/node/base.d.ts +3 -6
- package/esm/stdlib/item/node/base.js +30 -60
- 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/cube.d.ts +35 -0
- package/esm/stdlib/item/node/cube.js +54 -0
- package/esm/stdlib/item/node/cube.js.map +1 -0
- 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 +6 -2
- 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 +4 -0
- package/esm/stdlib/item/node/index.js +4 -0
- package/esm/stdlib/item/node/index.js.map +1 -1
- package/esm/stdlib/plugin/edgeFilterLens/index.d.ts +66 -0
- package/esm/stdlib/plugin/edgeFilterLens/index.js +309 -0
- package/esm/stdlib/plugin/edgeFilterLens/index.js.map +1 -0
- package/esm/stdlib/plugin/grid/index.d.ts +1 -1
- package/esm/stdlib/plugin/grid/index.js +3 -4
- package/esm/stdlib/plugin/grid/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/convexHull.d.ts +1 -1
- package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
- package/esm/stdlib/plugin/hull/hullComponent.js +5 -9
- package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
- package/esm/stdlib/plugin/hull/util.d.ts +2 -2
- package/esm/stdlib/plugin/hull/util.js +6 -2
- package/esm/stdlib/plugin/hull/util.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.d.ts +2 -2
- package/esm/stdlib/plugin/legend/index.js +3 -3
- package/esm/stdlib/plugin/legend/index.js.map +1 -1
- package/esm/stdlib/plugin/menu/index.d.ts +4 -4
- package/esm/stdlib/plugin/menu/index.js +3 -3
- package/esm/stdlib/plugin/menu/index.js.map +1 -1
- package/esm/stdlib/plugin/minimap/index.d.ts +6 -2
- package/esm/stdlib/plugin/minimap/index.js +119 -12
- 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.js +2 -2
- package/esm/stdlib/plugin/timebar/index.js.map +1 -1
- package/esm/stdlib/plugin/toolbar/index.d.ts +3 -3
- package/esm/stdlib/plugin/toolbar/index.js +4 -4
- package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
- package/esm/stdlib/plugin/tooltip/index.d.ts +4 -4
- package/esm/stdlib/plugin/tooltip/index.js +3 -4
- package/esm/stdlib/plugin/tooltip/index.js.map +1 -1
- package/esm/stdlib/plugin/types.d.ts +2 -0
- package/esm/stdlib/plugin/watermaker/index.d.ts +78 -0
- package/esm/stdlib/plugin/watermaker/index.js +243 -0
- package/esm/stdlib/plugin/watermaker/index.js.map +1 -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/data.d.ts +5 -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/index.d.ts +2 -1
- package/esm/types/index.js +1 -0
- package/esm/types/index.js.map +1 -1
- package/esm/types/item.d.ts +7 -1
- package/esm/types/item.js.map +1 -1
- package/esm/types/plugin.d.ts +1 -1
- package/esm/types/spec.d.ts +20 -3
- package/esm/types/view.d.ts +5 -0
- package/esm/util/array.d.ts +1 -0
- package/esm/util/array.js +3 -0
- package/esm/util/array.js.map +1 -1
- package/esm/util/bbox.d.ts +16 -1
- package/esm/util/bbox.js +33 -5
- package/esm/util/bbox.js.map +1 -1
- package/esm/util/behavior.d.ts +2 -2
- package/esm/util/behavior.js +2 -2
- package/esm/util/behavior.js.map +1 -1
- package/esm/util/data.d.ts +5 -2
- package/esm/util/data.js +15 -0
- package/esm/util/data.js.map +1 -1
- package/esm/util/dom.d.ts +15 -0
- package/esm/util/dom.js +29 -0
- package/esm/util/dom.js.map +1 -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/extend.d.ts +1 -1
- package/esm/util/extend.js +0 -1
- package/esm/util/extend.js.map +1 -1
- package/esm/util/index.d.ts +7 -52
- package/esm/util/index.js +7 -23
- package/esm/util/index.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 +12 -1
- package/esm/util/layout.js +45 -0
- package/esm/util/layout.js.map +1 -1
- package/esm/util/loop.d.ts +2 -1
- package/esm/util/loop.js +14 -0
- package/esm/util/loop.js.map +1 -1
- package/esm/util/math.d.ts +1 -1
- package/esm/util/matrix.d.ts +6 -0
- package/esm/util/matrix.js +48 -0
- package/esm/util/matrix.js.map +1 -0
- package/esm/util/path.js +1 -1
- package/esm/util/path.js.map +1 -1
- package/esm/util/point.d.ts +1 -1
- package/esm/util/point.js +9 -2
- package/esm/util/point.js.map +1 -1
- package/esm/util/polyline.d.ts +2 -1
- package/esm/util/polyline.js +2 -1
- package/esm/util/polyline.js.map +1 -1
- package/esm/util/router.d.ts +1 -1
- package/esm/util/shape.d.ts +3 -3
- package/esm/util/shape.js +17 -26
- package/esm/util/shape.js.map +1 -1
- package/esm/util/shape3d.d.ts +1 -1
- package/esm/util/shape3d.js +16 -17
- package/esm/util/shape3d.js.map +1 -1
- package/esm/util/text.d.ts +1 -1
- package/esm/util/text.js +3 -2
- package/esm/util/text.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/api-doc/graph.d.ts +3 -3
- package/lib/api-doc/graph.js +27 -7
- package/lib/api-doc/graph.js.map +1 -1
- package/lib/api-doc/types.d.ts +1 -0
- package/lib/api-doc/types.js +2 -2
- package/lib/api-doc/types.js.map +1 -1
- package/lib/constant/shape.d.ts +3 -1
- package/lib/index.d.ts +33 -65
- package/lib/index.js +18 -10
- package/lib/index.js.map +1 -1
- package/lib/item/combo.d.ts +1 -1
- package/lib/item/combo.js +18 -14
- package/lib/item/combo.js.map +1 -1
- package/lib/item/edge.d.ts +19 -2
- package/lib/item/edge.js +99 -43
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.d.ts +3 -2
- package/lib/item/item.js +27 -13
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +2 -8
- package/lib/item/node.js +31 -19
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/data.d.ts +30 -16
- package/lib/runtime/controller/data.js +288 -420
- package/lib/runtime/controller/data.js.map +1 -1
- package/lib/runtime/controller/interaction.js +9 -4
- package/lib/runtime/controller/interaction.js.map +1 -1
- package/lib/runtime/controller/item.d.ts +1 -0
- package/lib/runtime/controller/item.js +284 -149
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/controller/layout.js +1 -3
- package/lib/runtime/controller/layout.js.map +1 -1
- package/lib/runtime/controller/plugin.js +9 -5
- package/lib/runtime/controller/plugin.js.map +1 -1
- package/lib/runtime/graph.d.ts +104 -24
- package/lib/runtime/graph.js +473 -94
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/activate-relations.js +2 -2
- package/lib/stdlib/behavior/activate-relations.js.map +1 -1
- package/lib/stdlib/behavior/brush-select.d.ts +7 -1
- package/lib/stdlib/behavior/brush-select.js +13 -12
- 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 +219 -0
- package/lib/stdlib/behavior/create-edge.js.map +1 -0
- package/lib/stdlib/behavior/drag-canvas.d.ts +3 -1
- package/lib/stdlib/behavior/drag-canvas.js +78 -33
- 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 +80 -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 +6 -4
- 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 +91 -0
- package/lib/stdlib/behavior/shortcuts-call.js.map +1 -0
- package/lib/stdlib/behavior/zoom-canvas-3d.js +4 -1
- package/lib/stdlib/behavior/zoom-canvas-3d.js.map +1 -1
- package/lib/stdlib/behavior/zoom-canvas.d.ts +3 -1
- package/lib/stdlib/behavior/zoom-canvas.js +70 -26
- package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/lib/stdlib/data/index.d.ts +1 -0
- package/lib/stdlib/data/index.js +1 -0
- package/lib/stdlib/data/index.js.map +1 -1
- package/lib/stdlib/data/mapNodeSize.d.ts +4 -5
- package/lib/stdlib/data/mapNodeSize.js +13 -3
- package/lib/stdlib/data/mapNodeSize.js.map +1 -1
- package/lib/stdlib/data/processParallelEdges.d.ts +21 -0
- package/lib/stdlib/data/processParallelEdges.js +131 -0
- package/lib/stdlib/data/processParallelEdges.js.map +1 -0
- package/lib/stdlib/data/transformV4Data.d.ts +3 -4
- package/lib/stdlib/data/transformV4Data.js +11 -3
- package/lib/stdlib/data/transformV4Data.js.map +1 -1
- package/lib/stdlib/data/validateData.d.ts +4 -5
- package/lib/stdlib/data/validateData.js +23 -14
- package/lib/stdlib/data/validateData.js.map +1 -1
- package/lib/stdlib/index.d.ts +27 -8
- package/lib/stdlib/index.js +24 -11
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/edge/base.d.ts +3 -5
- package/lib/stdlib/item/edge/base.js +30 -29
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/edge/cubic-horizontal.js.map +1 -1
- package/lib/stdlib/item/edge/cubic-vertical.js.map +1 -1
- package/lib/stdlib/item/edge/cubic.js +2 -2
- package/lib/stdlib/item/edge/cubic.js.map +1 -1
- package/lib/stdlib/item/edge/loop.js +3 -3
- package/lib/stdlib/item/edge/loop.js.map +1 -1
- package/lib/stdlib/item/node/base.d.ts +3 -6
- package/lib/stdlib/item/node/base.js +29 -59
- 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/cube.d.ts +35 -0
- package/lib/stdlib/item/node/cube.js +58 -0
- package/lib/stdlib/item/node/cube.js.map +1 -0
- 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 +6 -2
- 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 +4 -0
- package/lib/stdlib/item/node/index.js +4 -0
- package/lib/stdlib/item/node/index.js.map +1 -1
- package/lib/stdlib/plugin/edgeFilterLens/index.d.ts +66 -0
- package/lib/stdlib/plugin/edgeFilterLens/index.js +313 -0
- package/lib/stdlib/plugin/edgeFilterLens/index.js.map +1 -0
- package/lib/stdlib/plugin/grid/index.d.ts +1 -1
- package/lib/stdlib/plugin/grid/index.js +6 -7
- package/lib/stdlib/plugin/grid/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/convexHull.d.ts +1 -1
- package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
- package/lib/stdlib/plugin/hull/hullComponent.js +5 -9
- package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
- package/lib/stdlib/plugin/hull/util.d.ts +2 -2
- package/lib/stdlib/plugin/hull/util.js +26 -22
- package/lib/stdlib/plugin/hull/util.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.d.ts +2 -2
- package/lib/stdlib/plugin/legend/index.js +3 -3
- package/lib/stdlib/plugin/legend/index.js.map +1 -1
- package/lib/stdlib/plugin/menu/index.d.ts +4 -4
- package/lib/stdlib/plugin/menu/index.js +6 -6
- package/lib/stdlib/plugin/menu/index.js.map +1 -1
- package/lib/stdlib/plugin/minimap/index.d.ts +6 -2
- package/lib/stdlib/plugin/minimap/index.js +121 -14
- 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.js +2 -2
- package/lib/stdlib/plugin/timebar/index.js.map +1 -1
- package/lib/stdlib/plugin/toolbar/index.d.ts +3 -3
- package/lib/stdlib/plugin/toolbar/index.js +5 -5
- package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
- package/lib/stdlib/plugin/tooltip/index.d.ts +4 -4
- package/lib/stdlib/plugin/tooltip/index.js +10 -11
- package/lib/stdlib/plugin/tooltip/index.js.map +1 -1
- package/lib/stdlib/plugin/types.d.ts +2 -0
- package/lib/stdlib/plugin/watermaker/index.d.ts +78 -0
- package/lib/stdlib/plugin/watermaker/index.js +247 -0
- package/lib/stdlib/plugin/watermaker/index.js.map +1 -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/data.d.ts +5 -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/index.d.ts +2 -1
- package/lib/types/index.js +3 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/item.d.ts +7 -1
- package/lib/types/item.js.map +1 -1
- package/lib/types/plugin.d.ts +1 -1
- package/lib/types/spec.d.ts +20 -3
- package/lib/types/view.d.ts +5 -0
- package/lib/util/array.d.ts +1 -0
- package/lib/util/array.js +5 -1
- package/lib/util/array.js.map +1 -1
- package/lib/util/bbox.d.ts +16 -1
- package/lib/util/bbox.js +36 -6
- package/lib/util/bbox.js.map +1 -1
- package/lib/util/behavior.d.ts +2 -2
- package/lib/util/behavior.js +2 -2
- package/lib/util/behavior.js.map +1 -1
- package/lib/util/data.d.ts +5 -2
- package/lib/util/data.js +16 -1
- package/lib/util/data.js.map +1 -1
- package/lib/util/dom.d.ts +15 -0
- package/lib/util/dom.js +34 -0
- package/lib/util/dom.js.map +1 -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/extend.d.ts +1 -1
- package/lib/util/extend.js +0 -1
- package/lib/util/extend.js.map +1 -1
- package/lib/util/index.d.ts +7 -52
- package/lib/util/index.js +23 -23
- package/lib/util/index.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 +12 -1
- package/lib/util/layout.js +47 -1
- package/lib/util/layout.js.map +1 -1
- package/lib/util/loop.d.ts +2 -1
- package/lib/util/loop.js +15 -1
- package/lib/util/loop.js.map +1 -1
- package/lib/util/math.d.ts +1 -1
- package/lib/util/matrix.d.ts +6 -0
- package/lib/util/matrix.js +52 -0
- package/lib/util/matrix.js.map +1 -0
- package/lib/util/path.js +2 -2
- package/lib/util/path.js.map +1 -1
- package/lib/util/point.d.ts +1 -1
- package/lib/util/point.js +9 -2
- package/lib/util/point.js.map +1 -1
- package/lib/util/polyline.d.ts +2 -1
- package/lib/util/polyline.js +2 -1
- package/lib/util/polyline.js.map +1 -1
- package/lib/util/router.d.ts +1 -1
- package/lib/util/shape.d.ts +3 -3
- package/lib/util/shape.js +17 -26
- package/lib/util/shape.js.map +1 -1
- package/lib/util/shape3d.d.ts +1 -1
- package/lib/util/shape3d.js +15 -16
- package/lib/util/shape3d.js.map +1 -1
- package/lib/util/text.d.ts +1 -1
- package/lib/util/text.js +3 -2
- package/lib/util/text.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 +42 -51
- package/src/api-doc/graph.ts +4 -3
- package/src/api-doc/types.ts +1 -0
- package/src/constant/shape.ts +1 -1
- package/src/index.ts +5 -6
- package/src/item/combo.ts +16 -15
- package/src/item/edge.ts +135 -57
- package/src/item/item.ts +32 -19
- package/src/item/node.ts +36 -50
- package/src/runtime/controller/data.ts +371 -490
- package/src/runtime/controller/interaction.ts +10 -4
- package/src/runtime/controller/item.ts +261 -78
- package/src/runtime/controller/layout.ts +1 -5
- package/src/runtime/controller/plugin.ts +15 -4
- package/src/runtime/graph.ts +605 -103
- package/src/stdlib/behavior/activate-relations.ts +2 -2
- package/src/stdlib/behavior/brush-select.ts +14 -13
- package/src/stdlib/behavior/click-select.ts +1 -1
- package/src/stdlib/behavior/create-edge.ts +305 -0
- package/src/stdlib/behavior/drag-canvas.ts +107 -35
- package/src/stdlib/behavior/drag-combo.ts +10 -10
- package/src/stdlib/behavior/drag-node.ts +27 -18
- package/src/stdlib/behavior/index.ts +3 -0
- package/src/stdlib/behavior/lasso-select.ts +7 -5
- package/src/stdlib/behavior/scroll-canvas.ts +348 -0
- package/src/stdlib/behavior/shortcuts-call.ts +129 -0
- package/src/stdlib/behavior/zoom-canvas-3d.ts +4 -1
- package/src/stdlib/behavior/zoom-canvas.ts +98 -27
- package/src/stdlib/data/index.ts +1 -0
- package/src/stdlib/data/mapNodeSize.ts +22 -3
- package/src/stdlib/data/processParallelEdges.ts +203 -0
- package/src/stdlib/data/transformV4Data.ts +16 -3
- package/src/stdlib/data/validateData.ts +32 -18
- package/src/stdlib/index.ts +31 -8
- package/src/stdlib/item/edge/base.ts +32 -41
- package/src/stdlib/item/edge/cubic-horizontal.ts +0 -1
- package/src/stdlib/item/edge/cubic-vertical.ts +0 -1
- package/src/stdlib/item/edge/cubic.ts +1 -1
- package/src/stdlib/item/edge/loop.ts +1 -1
- package/src/stdlib/item/node/base.ts +38 -65
- package/src/stdlib/item/node/base3d.ts +1 -0
- package/src/stdlib/item/node/cube.ts +102 -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 +6 -2
- package/src/stdlib/item/node/image.ts +190 -0
- package/src/stdlib/item/node/index.ts +4 -0
- package/src/stdlib/plugin/edgeFilterLens/index.ts +387 -0
- package/src/stdlib/plugin/grid/index.ts +6 -6
- 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/convexHull.ts +1 -1
- package/src/stdlib/plugin/hull/hullComponent.ts +10 -8
- package/src/stdlib/plugin/hull/util.ts +6 -2
- package/src/stdlib/plugin/index.ts +2 -0
- package/src/stdlib/plugin/legend/index.ts +6 -6
- package/src/stdlib/plugin/menu/index.ts +13 -13
- package/src/stdlib/plugin/minimap/index.ts +126 -16
- package/src/stdlib/plugin/snapline/index.ts +1297 -0
- package/src/stdlib/plugin/timebar/index.ts +4 -4
- package/src/stdlib/plugin/toolbar/index.ts +8 -8
- package/src/stdlib/plugin/tooltip/index.ts +10 -10
- package/src/stdlib/plugin/types.ts +2 -0
- package/src/stdlib/plugin/watermaker/index.ts +302 -0
- package/src/stdlib/theme/dark.ts +66 -2
- package/src/stdlib/theme/light.ts +4 -4
- package/src/types/data.ts +6 -0
- package/src/types/event.ts +1 -0
- package/src/types/graph.ts +62 -25
- package/src/types/hook.ts +22 -2
- package/src/types/index.ts +2 -1
- package/src/types/item.ts +12 -1
- package/src/types/plugin.ts +1 -1
- package/src/types/spec.ts +23 -3
- package/src/types/view.ts +8 -3
- package/src/util/array.ts +12 -0
- package/src/util/bbox.ts +42 -6
- package/src/util/behavior.ts +4 -4
- package/src/util/data.ts +26 -4
- package/src/util/dom.ts +33 -0
- package/src/util/event.ts +14 -1
- package/src/util/extend.ts +2 -3
- package/src/util/index.ts +7 -24
- package/src/util/item.ts +65 -28
- package/src/util/layout.ts +48 -2
- package/src/util/loop.ts +16 -1
- package/src/util/math.ts +1 -1
- package/src/util/matrix.ts +66 -0
- package/src/util/path.ts +1 -1
- package/src/util/point.ts +9 -4
- package/src/util/polyline.ts +2 -1
- package/src/util/router.ts +1 -1
- package/src/util/shape.ts +23 -26
- package/src/util/shape3d.ts +20 -20
- package/src/util/text.ts +3 -1
- package/src/util/warn.ts +20 -0
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,
|
|
@@ -26,7 +34,7 @@ import type {
|
|
|
26
34
|
import type { CameraAnimationOptions } from '../types/animate';
|
|
27
35
|
import type { BehaviorOptionsOf, BehaviorRegistry } from '../types/behavior';
|
|
28
36
|
import type { ComboDisplayModel, ComboModel } from '../types/combo';
|
|
29
|
-
import type { Padding, Point } from '../types/common';
|
|
37
|
+
import type { Bounds, Padding, Point } from '../types/common';
|
|
30
38
|
import type { DataChangeType, DataConfig, GraphCore } from '../types/data';
|
|
31
39
|
import type { EdgeDisplayModel, EdgeModel, EdgeModelData } from '../types/edge';
|
|
32
40
|
import type { StackType } from '../types/history';
|
|
@@ -47,7 +55,10 @@ import type {
|
|
|
47
55
|
import { FitViewRules, GraphTransformOptions } from '../types/view';
|
|
48
56
|
import { changeRenderer, createCanvas } from '../util/canvas';
|
|
49
57
|
import { formatPadding } from '../util/shape';
|
|
58
|
+
import { getLayoutBounds } from '../util/layout';
|
|
59
|
+
import { createDOM } from '../util/dom';
|
|
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,
|
|
@@ -60,7 +71,7 @@ import {
|
|
|
60
71
|
import { PluginController } from './controller/plugin';
|
|
61
72
|
import Hook from './hooks';
|
|
62
73
|
|
|
63
|
-
export
|
|
74
|
+
export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
64
75
|
extends EventEmitter
|
|
65
76
|
implements IGraph<B, T>
|
|
66
77
|
{
|
|
@@ -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();
|
|
@@ -165,7 +180,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
165
180
|
this.canvas = canvas;
|
|
166
181
|
this.backgroundCanvas = backgroundCanvas;
|
|
167
182
|
this.transientCanvas = transientCanvas;
|
|
168
|
-
this.container = container as
|
|
183
|
+
this.container = container as HTMLElement;
|
|
169
184
|
} else {
|
|
170
185
|
const containerDOM = isString(container)
|
|
171
186
|
? document.getElementById(container as string)
|
|
@@ -221,11 +236,12 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
221
236
|
.getContextService()
|
|
222
237
|
.getDomElement() as unknown as HTMLElement;
|
|
223
238
|
if ($domElement && $domElement.style) {
|
|
224
|
-
|
|
239
|
+
// Make all these 3 canvas doms overlap each other. The container already has `position: relative` style.
|
|
240
|
+
$domElement.style.position = 'absolute';
|
|
225
241
|
$domElement.style.outline = 'none';
|
|
226
242
|
$domElement.tabIndex = 1; // Enable keyboard events
|
|
227
243
|
// Transient canvas should let interactive events go through.
|
|
228
|
-
if (i
|
|
244
|
+
if (i !== 1) {
|
|
229
245
|
$domElement.style.pointerEvents = 'none';
|
|
230
246
|
}
|
|
231
247
|
}
|
|
@@ -345,7 +361,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
345
361
|
main: Canvas;
|
|
346
362
|
transient: Canvas;
|
|
347
363
|
};
|
|
348
|
-
}>({ name: '
|
|
364
|
+
}>({ name: 'themechange' }),
|
|
365
|
+
mapperchange: new Hook<{
|
|
366
|
+
type: ITEM_TYPE;
|
|
367
|
+
mapper: NodeMapper | EdgeMapper | ComboMapper;
|
|
368
|
+
}>({ name: 'mapperchange' }),
|
|
349
369
|
treecollapseexpand: new Hook<{
|
|
350
370
|
ids: ID[];
|
|
351
371
|
animate: boolean;
|
|
@@ -356,11 +376,31 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
356
376
|
};
|
|
357
377
|
}
|
|
358
378
|
|
|
379
|
+
private formatSpecification(spec: Specification<B, T>) {
|
|
380
|
+
return {
|
|
381
|
+
...this.specification,
|
|
382
|
+
...spec,
|
|
383
|
+
optimize: {
|
|
384
|
+
tileBehavior: 2000,
|
|
385
|
+
tileBehaviorSize: 1000,
|
|
386
|
+
tileFirstRender: 10000,
|
|
387
|
+
tileFirstRenderSize: 1000,
|
|
388
|
+
...this.specification?.optimize,
|
|
389
|
+
...spec.optimize,
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
359
394
|
/**
|
|
360
395
|
* Update the specs(configurations).
|
|
361
396
|
*/
|
|
362
397
|
public updateSpecification(spec: Specification<B, T>): Specification<B, T> {
|
|
363
|
-
|
|
398
|
+
const newSpec = Object.assign(
|
|
399
|
+
this.specification,
|
|
400
|
+
this.formatSpecification(spec),
|
|
401
|
+
);
|
|
402
|
+
// TODO: update something
|
|
403
|
+
return newSpec;
|
|
364
404
|
}
|
|
365
405
|
/**
|
|
366
406
|
* Update the theme specs (configurations).
|
|
@@ -382,6 +422,32 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
382
422
|
});
|
|
383
423
|
}
|
|
384
424
|
|
|
425
|
+
/**
|
|
426
|
+
* Update the item display mapper for a specific item type.
|
|
427
|
+
* @param {ITEM_TYPE} type - The type of item (node, edge, or combo).
|
|
428
|
+
* @param {NodeMapper | EdgeMapper | ComboMapper} mapper - The mapper to be updated.
|
|
429
|
+
* */
|
|
430
|
+
public updateMapper(
|
|
431
|
+
type: ITEM_TYPE,
|
|
432
|
+
mapper: NodeMapper | EdgeMapper | ComboMapper,
|
|
433
|
+
) {
|
|
434
|
+
switch (type) {
|
|
435
|
+
case 'node':
|
|
436
|
+
this.specification.node = mapper as NodeMapper;
|
|
437
|
+
break;
|
|
438
|
+
case 'edge':
|
|
439
|
+
this.specification.edge = mapper as EdgeMapper;
|
|
440
|
+
break;
|
|
441
|
+
case 'combo':
|
|
442
|
+
this.specification.combo = mapper as ComboMapper;
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
this.hooks.mapperchange.emit({
|
|
446
|
+
type,
|
|
447
|
+
mapper,
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
|
|
385
451
|
/**
|
|
386
452
|
* Get the copy of specs(configurations).
|
|
387
453
|
* @returns graph specs
|
|
@@ -398,12 +464,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
398
464
|
* @group Data
|
|
399
465
|
*/
|
|
400
466
|
public async read(data: DataConfig) {
|
|
467
|
+
const { tileFirstRender, tileFirstRenderSize } =
|
|
468
|
+
this.specification.optimize || {};
|
|
401
469
|
this.hooks.datachange.emit({ data, type: 'replace' });
|
|
402
470
|
const emitRender = async () => {
|
|
403
|
-
this.hooks.render.
|
|
471
|
+
await this.hooks.render.emitLinearAsync({
|
|
404
472
|
graphCore: this.dataController.graphCore,
|
|
405
473
|
theme: this.themeController.specification,
|
|
406
474
|
transientCanvas: this.transientCanvas,
|
|
475
|
+
tileOptimize: {
|
|
476
|
+
tileFirstRender,
|
|
477
|
+
tileFirstRenderSize,
|
|
478
|
+
},
|
|
407
479
|
});
|
|
408
480
|
this.emit('afterrender');
|
|
409
481
|
|
|
@@ -411,15 +483,28 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
411
483
|
const { autoFit } = this.specification;
|
|
412
484
|
if (autoFit) {
|
|
413
485
|
if (autoFit === 'view') {
|
|
414
|
-
await this.fitView();
|
|
486
|
+
await this.fitView({ rules: { boundsType: 'layout' } });
|
|
415
487
|
} else if (autoFit === 'center') {
|
|
416
|
-
await this.fitCenter();
|
|
488
|
+
await this.fitCenter('layout');
|
|
417
489
|
} else {
|
|
418
490
|
const { type, effectTiming, ...others } = autoFit;
|
|
419
491
|
if (type === 'view') {
|
|
420
|
-
|
|
492
|
+
const { padding, rules } = others as {
|
|
493
|
+
padding: Padding;
|
|
494
|
+
rules: FitViewRules;
|
|
495
|
+
};
|
|
496
|
+
await this.fitView(
|
|
497
|
+
{
|
|
498
|
+
padding,
|
|
499
|
+
rules: {
|
|
500
|
+
...rules,
|
|
501
|
+
boundsType: 'layout',
|
|
502
|
+
},
|
|
503
|
+
},
|
|
504
|
+
effectTiming,
|
|
505
|
+
);
|
|
421
506
|
} else if (type === 'center') {
|
|
422
|
-
await this.fitCenter(effectTiming);
|
|
507
|
+
await this.fitCenter('layout', effectTiming);
|
|
423
508
|
} else if (type === 'position') {
|
|
424
509
|
// TODO: align
|
|
425
510
|
await this.translateTo((others as any).position, effectTiming);
|
|
@@ -452,11 +537,17 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
452
537
|
data: DataConfig,
|
|
453
538
|
type: 'replace' | 'mergeReplace' = 'mergeReplace',
|
|
454
539
|
) {
|
|
540
|
+
const { tileFirstRender, tileFirstRenderSize } =
|
|
541
|
+
this.specification.optimize || {};
|
|
455
542
|
this.hooks.datachange.emit({ data, type });
|
|
456
543
|
this.hooks.render.emit({
|
|
457
544
|
graphCore: this.dataController.graphCore,
|
|
458
545
|
theme: this.themeController.specification,
|
|
459
546
|
transientCanvas: this.transientCanvas,
|
|
547
|
+
tileOptimize: {
|
|
548
|
+
tileFirstRender,
|
|
549
|
+
tileFirstRenderSize,
|
|
550
|
+
},
|
|
460
551
|
});
|
|
461
552
|
this.emit('afterrender');
|
|
462
553
|
|
|
@@ -468,7 +559,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
468
559
|
* @returns
|
|
469
560
|
*/
|
|
470
561
|
public clear() {
|
|
471
|
-
this.
|
|
562
|
+
this.startHistoryBatch();
|
|
472
563
|
this.removeData(
|
|
473
564
|
'edge',
|
|
474
565
|
this.getAllEdgesData().map((edge) => edge.id),
|
|
@@ -481,7 +572,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
481
572
|
'combo',
|
|
482
573
|
this.getAllCombosData().map((combo) => combo.id),
|
|
483
574
|
);
|
|
484
|
-
this.
|
|
575
|
+
this.stopHistoryBatch();
|
|
485
576
|
}
|
|
486
577
|
|
|
487
578
|
public getViewportCenter(): PointLike {
|
|
@@ -492,9 +583,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
492
583
|
options: GraphTransformOptions,
|
|
493
584
|
effectTiming?: CameraAnimationOptions,
|
|
494
585
|
): Promise<void> {
|
|
586
|
+
const { tileLodSize } = this.specification.optimize || {};
|
|
495
587
|
await this.hooks.viewportchange.emitLinearAsync({
|
|
496
588
|
transform: options,
|
|
497
589
|
effectTiming,
|
|
590
|
+
tileLodSize,
|
|
498
591
|
});
|
|
499
592
|
this.emit('viewportchange', options);
|
|
500
593
|
}
|
|
@@ -637,8 +730,8 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
637
730
|
*/
|
|
638
731
|
public async fitView(
|
|
639
732
|
options?: {
|
|
640
|
-
padding
|
|
641
|
-
rules
|
|
733
|
+
padding?: Padding;
|
|
734
|
+
rules?: FitViewRules;
|
|
642
735
|
},
|
|
643
736
|
effectTiming?: CameraAnimationOptions,
|
|
644
737
|
) {
|
|
@@ -646,13 +739,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
646
739
|
const [top, right, bottom, left] = padding
|
|
647
740
|
? formatPadding(padding)
|
|
648
741
|
: [0, 0, 0, 0];
|
|
649
|
-
const {
|
|
742
|
+
const {
|
|
743
|
+
direction = 'both',
|
|
744
|
+
ratioRule = 'min',
|
|
745
|
+
boundsType = 'render',
|
|
746
|
+
} = rules || {};
|
|
650
747
|
|
|
651
|
-
// Get the bounds of the whole graph.
|
|
652
748
|
const {
|
|
653
749
|
center: [graphCenterX, graphCenterY],
|
|
654
750
|
halfExtents,
|
|
655
|
-
} =
|
|
751
|
+
} =
|
|
752
|
+
boundsType === 'render'
|
|
753
|
+
? // Get the bounds of the whole graph content.
|
|
754
|
+
this.canvas.document.documentElement.getBounds()
|
|
755
|
+
: // Get the bounds of the nodes positions while the graph content is not ready.
|
|
756
|
+
getLayoutBounds(this);
|
|
656
757
|
const origin = this.canvas.canvas2Viewport({
|
|
657
758
|
x: graphCenterX,
|
|
658
759
|
y: graphCenterY,
|
|
@@ -703,11 +804,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
703
804
|
* Fit the graph center to the view center.
|
|
704
805
|
* @param effectTiming animation configurations
|
|
705
806
|
*/
|
|
706
|
-
public async fitCenter(
|
|
707
|
-
|
|
807
|
+
public async fitCenter(
|
|
808
|
+
boundsType: 'render' | 'layout' = 'render',
|
|
809
|
+
effectTiming?: CameraAnimationOptions,
|
|
810
|
+
) {
|
|
708
811
|
const {
|
|
709
812
|
center: [graphCenterX, graphCenterY],
|
|
710
|
-
} =
|
|
813
|
+
} =
|
|
814
|
+
boundsType === 'render'
|
|
815
|
+
? // Get the bounds of the whole graph content.
|
|
816
|
+
this.canvas.document.documentElement.getBounds()
|
|
817
|
+
: // Get the bounds of the nodes positions while the graph content is not ready.
|
|
818
|
+
getLayoutBounds(this);
|
|
711
819
|
await this.translateTo(
|
|
712
820
|
this.canvas.canvas2Viewport({ x: graphCenterX, y: graphCenterY }),
|
|
713
821
|
effectTiming,
|
|
@@ -774,9 +882,34 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
774
882
|
);
|
|
775
883
|
return;
|
|
776
884
|
}
|
|
885
|
+
const oldSize = [this.specification.width, this.specification.height];
|
|
886
|
+
this.emit('beforesetsize', { oldSize, size: size });
|
|
777
887
|
this.specification.width = size[0];
|
|
778
888
|
this.specification.height = size[1];
|
|
779
889
|
this.canvas.resize(size[0], size[1]);
|
|
890
|
+
this.transientCanvas.resize(size[0], size[1]);
|
|
891
|
+
this.backgroundCanvas.resize(size[0], size[1]);
|
|
892
|
+
this.emit('aftersetsize', { oldSize, size: size });
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
public getCanvasRange(): Bounds {
|
|
896
|
+
const [width, height] = this.getSize();
|
|
897
|
+
const leftTop = this.getCanvasByViewport({ x: 0, y: 0 });
|
|
898
|
+
const rightBottom = this.getCanvasByViewport({ x: width, y: height });
|
|
899
|
+
return {
|
|
900
|
+
min: [leftTop.x, leftTop.y, leftTop.z],
|
|
901
|
+
max: [rightBottom.x, rightBottom.y, rightBottom.z],
|
|
902
|
+
center: [
|
|
903
|
+
(leftTop.x + rightBottom.x) / 2,
|
|
904
|
+
(leftTop.y + rightBottom.y) / 2,
|
|
905
|
+
(leftTop.z + rightBottom.z) / 2,
|
|
906
|
+
],
|
|
907
|
+
halfExtents: [
|
|
908
|
+
(rightBottom.x - leftTop.x) / 2,
|
|
909
|
+
(rightBottom.y - leftTop.y) / 2,
|
|
910
|
+
(rightBottom.z - leftTop.z) / 2,
|
|
911
|
+
],
|
|
912
|
+
};
|
|
780
913
|
}
|
|
781
914
|
|
|
782
915
|
/**
|
|
@@ -990,19 +1123,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
990
1123
|
graphCore.once('changed', (event) => {
|
|
991
1124
|
if (!event.changes.length) return;
|
|
992
1125
|
const changes = event.changes;
|
|
993
|
-
|
|
994
|
-
type: itemType,
|
|
995
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
996
|
-
graphCore,
|
|
997
|
-
theme: specification,
|
|
998
|
-
});
|
|
999
|
-
this.emit('afteritemchange', {
|
|
1126
|
+
const timingParameters = {
|
|
1000
1127
|
type: itemType,
|
|
1001
1128
|
action: 'add',
|
|
1002
1129
|
models,
|
|
1003
1130
|
apiName: 'addData',
|
|
1004
1131
|
changes,
|
|
1132
|
+
};
|
|
1133
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1134
|
+
this.hooks.itemchange.emit({
|
|
1135
|
+
type: itemType,
|
|
1136
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
1137
|
+
graphCore,
|
|
1138
|
+
theme: specification,
|
|
1005
1139
|
});
|
|
1140
|
+
this.emit('afteritemchange', timingParameters);
|
|
1006
1141
|
});
|
|
1007
1142
|
|
|
1008
1143
|
const modelArr = isArray(models) ? models : [models];
|
|
@@ -1027,27 +1162,39 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1027
1162
|
public removeData(itemType: ITEM_TYPE, ids: ID | ID[]) {
|
|
1028
1163
|
const idArr = isArray(ids) ? ids : [ids];
|
|
1029
1164
|
const data = { nodes: [], edges: [], combos: [] };
|
|
1030
|
-
const {
|
|
1165
|
+
const { graphCore } = this.dataController;
|
|
1031
1166
|
const { specification } = this.themeController;
|
|
1032
|
-
const getItem =
|
|
1033
|
-
|
|
1034
|
-
data[`${itemType}s`] = idArr
|
|
1167
|
+
const getItem = itemType === 'edge' ? graphCore.getEdge : graphCore.getNode;
|
|
1168
|
+
const hasItem = itemType === 'edge' ? graphCore.hasEdge : graphCore.hasNode;
|
|
1169
|
+
data[`${itemType}s`] = idArr
|
|
1170
|
+
.map((id) => {
|
|
1171
|
+
if (!hasItem.bind(graphCore)(id)) {
|
|
1172
|
+
console.warn(
|
|
1173
|
+
`The ${itemType} data with id ${id} does not exist. It will be ignored`,
|
|
1174
|
+
);
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
return getItem.bind(graphCore)(id);
|
|
1178
|
+
})
|
|
1179
|
+
.filter(Boolean);
|
|
1035
1180
|
graphCore.once('changed', (event) => {
|
|
1036
1181
|
if (!event.changes.length) return;
|
|
1037
1182
|
const changes = event.changes;
|
|
1038
|
-
|
|
1039
|
-
type: itemType,
|
|
1040
|
-
changes: event.changes,
|
|
1041
|
-
graphCore,
|
|
1042
|
-
theme: specification,
|
|
1043
|
-
});
|
|
1044
|
-
this.emit('afteritemchange', {
|
|
1183
|
+
const timingParameters = {
|
|
1045
1184
|
type: itemType,
|
|
1046
1185
|
action: 'remove',
|
|
1047
1186
|
ids: idArr,
|
|
1048
1187
|
apiName: 'removeData',
|
|
1049
1188
|
changes,
|
|
1189
|
+
};
|
|
1190
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1191
|
+
this.hooks.itemchange.emit({
|
|
1192
|
+
type: itemType,
|
|
1193
|
+
changes: event.changes,
|
|
1194
|
+
graphCore,
|
|
1195
|
+
theme: specification,
|
|
1050
1196
|
});
|
|
1197
|
+
this.emit('afteritemchange', timingParameters);
|
|
1051
1198
|
});
|
|
1052
1199
|
this.hooks.datachange.emit({
|
|
1053
1200
|
data,
|
|
@@ -1140,19 +1287,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1140
1287
|
const { specification } = this.themeController;
|
|
1141
1288
|
graphCore.once('changed', (event) => {
|
|
1142
1289
|
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', {
|
|
1290
|
+
const timingParameters = {
|
|
1150
1291
|
type: itemType,
|
|
1151
1292
|
action: 'update',
|
|
1152
1293
|
models,
|
|
1153
1294
|
apiName: 'updateData',
|
|
1154
1295
|
changes,
|
|
1296
|
+
};
|
|
1297
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1298
|
+
this.hooks.itemchange.emit({
|
|
1299
|
+
type: itemType,
|
|
1300
|
+
changes: event.changes,
|
|
1301
|
+
graphCore,
|
|
1302
|
+
theme: specification,
|
|
1155
1303
|
});
|
|
1304
|
+
this.emit('afteritemchange', timingParameters);
|
|
1156
1305
|
});
|
|
1157
1306
|
|
|
1158
1307
|
this.hooks.datachange.emit({
|
|
@@ -1256,11 +1405,20 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1256
1405
|
const modelArr = isArray(models) ? models : [models];
|
|
1257
1406
|
const { graphCore } = this.dataController;
|
|
1258
1407
|
const { specification } = this.themeController;
|
|
1259
|
-
graphCore
|
|
1408
|
+
graphCore?.once('changed', (event) => {
|
|
1260
1409
|
if (!event.changes.length) return;
|
|
1261
1410
|
const changes = event.changes.filter(
|
|
1262
1411
|
(change) => !isEqual(change.newValue, change.oldValue),
|
|
1263
1412
|
);
|
|
1413
|
+
const timingParameters = {
|
|
1414
|
+
type,
|
|
1415
|
+
action: 'updatePosition',
|
|
1416
|
+
upsertAncestors,
|
|
1417
|
+
models,
|
|
1418
|
+
apiName: 'updatePosition',
|
|
1419
|
+
changes,
|
|
1420
|
+
};
|
|
1421
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1264
1422
|
this.hooks.itemchange.emit({
|
|
1265
1423
|
type,
|
|
1266
1424
|
changes: event.changes,
|
|
@@ -1271,14 +1429,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1271
1429
|
animate: !disableAnimate,
|
|
1272
1430
|
callback,
|
|
1273
1431
|
});
|
|
1274
|
-
this.emit('afteritemchange',
|
|
1275
|
-
type,
|
|
1276
|
-
action: 'updatePosition',
|
|
1277
|
-
upsertAncestors,
|
|
1278
|
-
models,
|
|
1279
|
-
apiName: 'updatePosition',
|
|
1280
|
-
changes,
|
|
1281
|
-
});
|
|
1432
|
+
this.emit('afteritemchange', timingParameters);
|
|
1282
1433
|
});
|
|
1283
1434
|
|
|
1284
1435
|
this.hooks.datachange.emit({
|
|
@@ -1344,7 +1495,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1344
1495
|
* @returns
|
|
1345
1496
|
* @group Item
|
|
1346
1497
|
*/
|
|
1347
|
-
public hideItem(
|
|
1498
|
+
public hideItem(
|
|
1499
|
+
ids: ID | ID[],
|
|
1500
|
+
disableAnimate = false,
|
|
1501
|
+
keepKeyShape = false,
|
|
1502
|
+
) {
|
|
1348
1503
|
const idArr = isArray(ids) ? ids : [ids];
|
|
1349
1504
|
if (isEmpty(idArr)) return;
|
|
1350
1505
|
const changes = {
|
|
@@ -1356,6 +1511,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1356
1511
|
value: false,
|
|
1357
1512
|
graphCore: this.dataController.graphCore,
|
|
1358
1513
|
animate: !disableAnimate,
|
|
1514
|
+
keepKeyShape,
|
|
1359
1515
|
});
|
|
1360
1516
|
this.emit('afteritemvisibilitychange', {
|
|
1361
1517
|
ids,
|
|
@@ -1363,6 +1519,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1363
1519
|
animate: !disableAnimate,
|
|
1364
1520
|
action: 'updateVisibility',
|
|
1365
1521
|
apiName: 'hideItem',
|
|
1522
|
+
keepKeyShape,
|
|
1366
1523
|
changes,
|
|
1367
1524
|
});
|
|
1368
1525
|
}
|
|
@@ -1449,7 +1606,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1449
1606
|
value,
|
|
1450
1607
|
});
|
|
1451
1608
|
this.emit('afteritemstatechange', {
|
|
1452
|
-
ids,
|
|
1609
|
+
ids: idArr,
|
|
1453
1610
|
states,
|
|
1454
1611
|
value,
|
|
1455
1612
|
action: 'updateState',
|
|
@@ -1498,7 +1655,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1498
1655
|
value: false,
|
|
1499
1656
|
});
|
|
1500
1657
|
this.emit('afteritemstatechange', {
|
|
1501
|
-
ids,
|
|
1658
|
+
ids: idArr,
|
|
1502
1659
|
states,
|
|
1503
1660
|
value: false,
|
|
1504
1661
|
action: 'updateState',
|
|
@@ -1547,19 +1704,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1547
1704
|
graphCore.once('changed', (event) => {
|
|
1548
1705
|
if (!event.changes.length) return;
|
|
1549
1706
|
const changes = event.changes;
|
|
1550
|
-
|
|
1551
|
-
type: 'combo',
|
|
1552
|
-
changes: graphCore.reduceChanges(event.changes),
|
|
1553
|
-
graphCore,
|
|
1554
|
-
theme: specification,
|
|
1555
|
-
});
|
|
1556
|
-
this.emit('afteritemchange', {
|
|
1707
|
+
const timingParameters = {
|
|
1557
1708
|
type: 'combo',
|
|
1558
1709
|
action: 'add',
|
|
1559
1710
|
models: [model],
|
|
1560
1711
|
apiName: 'addCombo',
|
|
1561
1712
|
changes,
|
|
1713
|
+
};
|
|
1714
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1715
|
+
this.hooks.itemchange.emit({
|
|
1716
|
+
type: 'combo',
|
|
1717
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
1718
|
+
graphCore,
|
|
1719
|
+
theme: specification,
|
|
1562
1720
|
});
|
|
1721
|
+
this.emit('afteritemchange', timingParameters);
|
|
1563
1722
|
});
|
|
1564
1723
|
|
|
1565
1724
|
const data = {
|
|
@@ -1588,7 +1747,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1588
1747
|
*/
|
|
1589
1748
|
public collapseCombo(comboIds: ID | ID[]) {
|
|
1590
1749
|
const ids = isArray(comboIds) ? comboIds : [comboIds];
|
|
1591
|
-
this.
|
|
1750
|
+
this.executeWithNoStack(() => {
|
|
1592
1751
|
this.updateData(
|
|
1593
1752
|
'combo',
|
|
1594
1753
|
ids.map((id) => ({ id, data: { collapsed: true } })),
|
|
@@ -1608,7 +1767,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1608
1767
|
*/
|
|
1609
1768
|
public expandCombo(comboIds: ID | ID[]) {
|
|
1610
1769
|
const ids = isArray(comboIds) ? comboIds : [comboIds];
|
|
1611
|
-
this.
|
|
1770
|
+
this.executeWithNoStack(() => {
|
|
1612
1771
|
this.updateData(
|
|
1613
1772
|
'combo',
|
|
1614
1773
|
ids.map((id) => ({ id, data: { collapsed: false } })),
|
|
@@ -1645,16 +1804,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1645
1804
|
graphCore.once('changed', (event) => {
|
|
1646
1805
|
if (!event.changes.length) return;
|
|
1647
1806
|
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', {
|
|
1807
|
+
const timingParameters = {
|
|
1658
1808
|
type: 'combo',
|
|
1659
1809
|
ids: idArr,
|
|
1660
1810
|
dx,
|
|
@@ -1663,7 +1813,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1663
1813
|
upsertAncestors,
|
|
1664
1814
|
apiName: 'moveCombo',
|
|
1665
1815
|
changes,
|
|
1816
|
+
};
|
|
1817
|
+
this.emit('beforeitemchange', timingParameters);
|
|
1818
|
+
this.hooks.itemchange.emit({
|
|
1819
|
+
type: 'combo',
|
|
1820
|
+
changes: event.changes,
|
|
1821
|
+
graphCore,
|
|
1822
|
+
theme: specification,
|
|
1823
|
+
upsertAncestors,
|
|
1824
|
+
action: 'updatePosition',
|
|
1825
|
+
callback,
|
|
1666
1826
|
});
|
|
1827
|
+
this.emit('afteritemchange', timingParameters);
|
|
1667
1828
|
});
|
|
1668
1829
|
|
|
1669
1830
|
this.hooks.datachange.emit({
|
|
@@ -1762,6 +1923,15 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1762
1923
|
return this.interactionController.getMode();
|
|
1763
1924
|
}
|
|
1764
1925
|
|
|
1926
|
+
/**
|
|
1927
|
+
* Set the cursor. But the cursor in item's style has higher priority.
|
|
1928
|
+
* @param cursor
|
|
1929
|
+
*/
|
|
1930
|
+
public setCursor(cursor: Cursor) {
|
|
1931
|
+
this.canvas.setCursor(cursor);
|
|
1932
|
+
this.transientCanvas.setCursor(cursor);
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1765
1935
|
/**
|
|
1766
1936
|
* Add behavior(s) to mode(s).
|
|
1767
1937
|
* @param behaviors behavior names or configs
|
|
@@ -1979,9 +2149,19 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1979
2149
|
type: ITEM_TYPE | SHAPE_TYPE,
|
|
1980
2150
|
id: ID,
|
|
1981
2151
|
config: {
|
|
1982
|
-
action
|
|
1983
|
-
|
|
1984
|
-
|
|
2152
|
+
action?: 'remove' | 'add' | 'update' | undefined;
|
|
2153
|
+
/** Data to be merged into the transient item. */
|
|
2154
|
+
data?: Record<string, any>;
|
|
2155
|
+
/** Style to be merged into the transient shape. */
|
|
2156
|
+
style?: ShapeStyle;
|
|
2157
|
+
/** For type: 'edge' */
|
|
2158
|
+
drawSource?: boolean;
|
|
2159
|
+
/** For type: 'edge' */
|
|
2160
|
+
drawTarget?: boolean;
|
|
2161
|
+
/** 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. */
|
|
2162
|
+
shapeIds?: string[];
|
|
2163
|
+
/** Whether show the shapes in shapeIds. True by default. */
|
|
2164
|
+
visible?: boolean;
|
|
1985
2165
|
upsertAncestors?: boolean;
|
|
1986
2166
|
},
|
|
1987
2167
|
canvas?: Canvas,
|
|
@@ -1996,6 +2176,328 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1996
2176
|
return this.itemController.getTransient(String(id));
|
|
1997
2177
|
}
|
|
1998
2178
|
|
|
2179
|
+
// ===== download operations =====
|
|
2180
|
+
/**
|
|
2181
|
+
* Asynchronously generates a Data URL representation of the canvas content, including
|
|
2182
|
+
* background, main content, and transient canvas.
|
|
2183
|
+
* @param The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
2184
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
2185
|
+
*/
|
|
2186
|
+
public async toDataURL(type?: DataURLType): Promise<string> {
|
|
2187
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
2188
|
+
const canvas = this.canvas;
|
|
2189
|
+
const transientCanvas = this.transientCanvas;
|
|
2190
|
+
const rendererType = this.rendererType;
|
|
2191
|
+
|
|
2192
|
+
const pixelRatio =
|
|
2193
|
+
typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
2194
|
+
const width = this.getSize()[0];
|
|
2195
|
+
const height = this.getSize()[1];
|
|
2196
|
+
|
|
2197
|
+
const vContainerDOM: HTMLElement = createDOM(
|
|
2198
|
+
'<div id="virtual-image"></div>',
|
|
2199
|
+
);
|
|
2200
|
+
const vCanvas = createCanvas(
|
|
2201
|
+
rendererType,
|
|
2202
|
+
vContainerDOM,
|
|
2203
|
+
width,
|
|
2204
|
+
height,
|
|
2205
|
+
pixelRatio,
|
|
2206
|
+
);
|
|
2207
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
2208
|
+
let bgRect;
|
|
2209
|
+
if (rendererType !== 'svg') {
|
|
2210
|
+
bgRect = new Rect({
|
|
2211
|
+
style: {
|
|
2212
|
+
x: 0,
|
|
2213
|
+
y: 0,
|
|
2214
|
+
z: -1,
|
|
2215
|
+
width: vCanvasContextService.getDomElement().width,
|
|
2216
|
+
height: vCanvasContextService.getDomElement().height,
|
|
2217
|
+
//@ts-ignore
|
|
2218
|
+
fill: backgroundCanvas.getContextService().getDomElement().style[
|
|
2219
|
+
'background-color'
|
|
2220
|
+
],
|
|
2221
|
+
},
|
|
2222
|
+
});
|
|
2223
|
+
vCanvas.appendChild(bgRect);
|
|
2224
|
+
}
|
|
2225
|
+
const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
|
|
2226
|
+
const clonedGroup = canvas.getRoot().cloneNode(true);
|
|
2227
|
+
const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
|
|
2228
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
2229
|
+
vCanvas.appendChild(clonedGroup);
|
|
2230
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
2231
|
+
vCanvas.render();
|
|
2232
|
+
|
|
2233
|
+
if (!type) type = 'image/png';
|
|
2234
|
+
let dataURL = '';
|
|
2235
|
+
await vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
2236
|
+
dataURL = url;
|
|
2237
|
+
});
|
|
2238
|
+
return dataURL;
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
/**
|
|
2242
|
+
* Asynchronously generates a Data URL representation of the full canvas content,
|
|
2243
|
+
* including background, main content, and transient canvas, with optional padding.
|
|
2244
|
+
* @param type The type of the Data URL (e.g., 'image/png', 'image/jpeg').
|
|
2245
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
2246
|
+
* @returns A Promise that resolves to the Data URL string.
|
|
2247
|
+
*/
|
|
2248
|
+
public async toFullDataURL(
|
|
2249
|
+
type?: DataURLType,
|
|
2250
|
+
imageConfig?: { padding?: number | number[] },
|
|
2251
|
+
) {
|
|
2252
|
+
const backgroundCanvas = this.backgroundCanvas;
|
|
2253
|
+
const canvas = this.canvas;
|
|
2254
|
+
const transientCanvas = this.transientCanvas;
|
|
2255
|
+
const backgroundRoot = canvas.getRoot();
|
|
2256
|
+
const root = canvas.getRoot();
|
|
2257
|
+
const transientRoot = transientCanvas.getRoot();
|
|
2258
|
+
const rendererType = this.rendererType;
|
|
2259
|
+
|
|
2260
|
+
const backgroundBBox = backgroundRoot.getBBox();
|
|
2261
|
+
const BBox = root.getBBox();
|
|
2262
|
+
const transientBBox = transientRoot.getBBox();
|
|
2263
|
+
|
|
2264
|
+
let padding = imageConfig ? imageConfig.padding : undefined;
|
|
2265
|
+
if (!padding) {
|
|
2266
|
+
padding = [0, 0, 0, 0];
|
|
2267
|
+
} else if (isNumber(padding)) {
|
|
2268
|
+
padding = [padding, padding, padding, padding];
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
const left =
|
|
2272
|
+
(transientBBox.left
|
|
2273
|
+
? backgroundBBox.left
|
|
2274
|
+
? Math.min(backgroundBBox.left, BBox.left, transientBBox.left)
|
|
2275
|
+
: Math.min(BBox.left, transientBBox.left)
|
|
2276
|
+
: BBox.left) - padding[3];
|
|
2277
|
+
const right =
|
|
2278
|
+
(transientBBox.right
|
|
2279
|
+
? backgroundBBox.right
|
|
2280
|
+
? Math.max(backgroundBBox.right, BBox.right, transientBBox.right)
|
|
2281
|
+
: Math.max(BBox.right, transientBBox.right)
|
|
2282
|
+
: BBox.right) + padding[1];
|
|
2283
|
+
const top =
|
|
2284
|
+
(transientBBox.top
|
|
2285
|
+
? backgroundBBox.top
|
|
2286
|
+
? Math.min(backgroundBBox.top, BBox.top, transientBBox.top)
|
|
2287
|
+
: Math.min(BBox.top, transientBBox.top)
|
|
2288
|
+
: BBox.top) - padding[0];
|
|
2289
|
+
const bottom =
|
|
2290
|
+
(transientBBox.bottom
|
|
2291
|
+
? backgroundBBox.bottom
|
|
2292
|
+
? Math.max(backgroundBBox.bottom, BBox.bottom, transientBBox.bottom)
|
|
2293
|
+
: Math.max(BBox.bottom, transientBBox.bottom)
|
|
2294
|
+
: BBox.bottom) + padding[2];
|
|
2295
|
+
|
|
2296
|
+
const graphCenterX = (left + right) / 2;
|
|
2297
|
+
const graphCenterY = (top + bottom) / 2;
|
|
2298
|
+
const halfX = (right - left) / 2;
|
|
2299
|
+
const halfY = (bottom - top) / 2;
|
|
2300
|
+
|
|
2301
|
+
const pixelRatio =
|
|
2302
|
+
typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
2303
|
+
const vWidth = halfX * 2;
|
|
2304
|
+
const vHeight = halfY * 2;
|
|
2305
|
+
const vContainerDOM: HTMLElement = createDOM(
|
|
2306
|
+
'<div id="virtual-image"></div>',
|
|
2307
|
+
);
|
|
2308
|
+
const vCanvas = createCanvas(
|
|
2309
|
+
rendererType,
|
|
2310
|
+
vContainerDOM,
|
|
2311
|
+
vWidth,
|
|
2312
|
+
vHeight,
|
|
2313
|
+
pixelRatio,
|
|
2314
|
+
);
|
|
2315
|
+
const vCanvasContextService = vCanvas.getContextService();
|
|
2316
|
+
if (rendererType !== 'svg') {
|
|
2317
|
+
const bgRect = new Rect({
|
|
2318
|
+
style: {
|
|
2319
|
+
x: 0,
|
|
2320
|
+
y: 0,
|
|
2321
|
+
z: -1,
|
|
2322
|
+
width: vCanvasContextService.getDomElement().width,
|
|
2323
|
+
height: vCanvasContextService.getDomElement().height,
|
|
2324
|
+
//@ts-ignore
|
|
2325
|
+
fill: backgroundCanvas.getContextService().getDomElement().style[
|
|
2326
|
+
'background-color'
|
|
2327
|
+
],
|
|
2328
|
+
},
|
|
2329
|
+
});
|
|
2330
|
+
vCanvas.appendChild(bgRect);
|
|
2331
|
+
}
|
|
2332
|
+
const backgroundClonedGroup = backgroundRoot.cloneNode(true);
|
|
2333
|
+
const clonedGroup = root.cloneNode(true);
|
|
2334
|
+
const transientClonedGroup = transientRoot.cloneNode(true);
|
|
2335
|
+
const transPosition: [number, number] = [
|
|
2336
|
+
-graphCenterX + halfX,
|
|
2337
|
+
-graphCenterY + halfY,
|
|
2338
|
+
];
|
|
2339
|
+
backgroundClonedGroup.setPosition(transPosition);
|
|
2340
|
+
clonedGroup.setPosition(transPosition);
|
|
2341
|
+
transientClonedGroup.setPosition(transPosition);
|
|
2342
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
2343
|
+
vCanvas.appendChild(clonedGroup);
|
|
2344
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
2345
|
+
vCanvas.render();
|
|
2346
|
+
|
|
2347
|
+
if (!type) type = 'image/png';
|
|
2348
|
+
let dataURL = '';
|
|
2349
|
+
await vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
2350
|
+
dataURL = url;
|
|
2351
|
+
});
|
|
2352
|
+
return dataURL;
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
/**
|
|
2356
|
+
* Converts a Data URL to an image file and handles the download of the image.
|
|
2357
|
+
* @param dataURL The Data URL of the image to be converted and downloaded.
|
|
2358
|
+
* @param renderer The renderer type ('svg' or other) used for the canvas.
|
|
2359
|
+
* @param link The HTML link element used for image download.
|
|
2360
|
+
* @param fileName The desired name for the downloaded image file.
|
|
2361
|
+
*/
|
|
2362
|
+
private dataURLToImage(dataURL: string, renderer: string, link, fileName) {
|
|
2363
|
+
if (!dataURL || dataURL === 'data:') {
|
|
2364
|
+
console.error(
|
|
2365
|
+
'Download image failed. The graph is too large or there is invalid attribute values in graph items',
|
|
2366
|
+
);
|
|
2367
|
+
return;
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
if (typeof window !== 'undefined') {
|
|
2371
|
+
if (window.Blob && window.URL && renderer !== 'svg') {
|
|
2372
|
+
const arr = dataURL.split(',');
|
|
2373
|
+
let mime = '';
|
|
2374
|
+
if (arr && arr.length > 0) {
|
|
2375
|
+
const match = arr[0].match(/:(.*?);/);
|
|
2376
|
+
// eslint-disable-next-line prefer-destructuring
|
|
2377
|
+
if (match && match.length >= 2) mime = match[1];
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
const bstr = atob(arr[1]);
|
|
2381
|
+
let n = bstr.length;
|
|
2382
|
+
const u8arr = new Uint8Array(n);
|
|
2383
|
+
|
|
2384
|
+
while (n--) {
|
|
2385
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
const blobObj = new Blob([u8arr], { type: mime });
|
|
2389
|
+
|
|
2390
|
+
if ((window.navigator as any).msSaveBlob) {
|
|
2391
|
+
(window.navigator as any).msSaveBlob(blobObj, fileName);
|
|
2392
|
+
} else {
|
|
2393
|
+
link.addEventListener('click', () => {
|
|
2394
|
+
link.download = fileName;
|
|
2395
|
+
link.href = window.URL.createObjectURL(blobObj);
|
|
2396
|
+
});
|
|
2397
|
+
}
|
|
2398
|
+
} else {
|
|
2399
|
+
link.addEventListener('click', () => {
|
|
2400
|
+
link.download = fileName;
|
|
2401
|
+
link.href = dataURL;
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
/**
|
|
2408
|
+
* Initiates the download of the graph as an image with an optional name and type.
|
|
2409
|
+
* @param name The desired name for the downloaded image file (optional).
|
|
2410
|
+
* @param type The type of the image to download (optional, defaults to 'image/png').
|
|
2411
|
+
*/
|
|
2412
|
+
public downloadImage(name?: string, type?: DataURLType): void {
|
|
2413
|
+
const self = this;
|
|
2414
|
+
// self.stopAnimate();
|
|
2415
|
+
|
|
2416
|
+
const rendererType = this.rendererType;
|
|
2417
|
+
if (!type) type = 'image/png';
|
|
2418
|
+
|
|
2419
|
+
const fileName: string =
|
|
2420
|
+
(name || 'graph') +
|
|
2421
|
+
(rendererType === 'svg' ? '.svg' : type.split('/')[1]);
|
|
2422
|
+
|
|
2423
|
+
const link: HTMLAnchorElement = document.createElement('a');
|
|
2424
|
+
|
|
2425
|
+
self.asyncToDataUrl(type, (dataURL) => {
|
|
2426
|
+
this.dataURLToImage(dataURL, rendererType, link, fileName);
|
|
2427
|
+
const e = document.createEvent('MouseEvents');
|
|
2428
|
+
e.initEvent('click', false, false);
|
|
2429
|
+
link.dispatchEvent(e);
|
|
2430
|
+
});
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
/**
|
|
2434
|
+
* Initiates the download of the entire graph as an image with optional name, type, and padding configuration.
|
|
2435
|
+
* @param name The desired name for the downloaded image file (optional).
|
|
2436
|
+
* @param type The type of the image to download (optional, defaults to 'image/png').
|
|
2437
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
2438
|
+
*/
|
|
2439
|
+
public downloadFullImage(
|
|
2440
|
+
name?: string,
|
|
2441
|
+
type?: DataURLType,
|
|
2442
|
+
imageConfig?: { padding?: number | number[] },
|
|
2443
|
+
): void {
|
|
2444
|
+
const self = this;
|
|
2445
|
+
|
|
2446
|
+
const rendererType = this.rendererType;
|
|
2447
|
+
if (!type) type = 'image/png';
|
|
2448
|
+
const fileName: string =
|
|
2449
|
+
(name || 'graph') +
|
|
2450
|
+
(rendererType === 'svg' ? '.svg' : type.split('/')[1]);
|
|
2451
|
+
const link: HTMLAnchorElement = document.createElement('a');
|
|
2452
|
+
|
|
2453
|
+
self.asyncToFullDataUrl(type, imageConfig, (dataURL) => {
|
|
2454
|
+
this.dataURLToImage(dataURL, rendererType, link, fileName);
|
|
2455
|
+
const e = document.createEvent('MouseEvents');
|
|
2456
|
+
e.initEvent('click', false, false);
|
|
2457
|
+
link.dispatchEvent(e);
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
/**
|
|
2462
|
+
* Asynchronously converts the canvas content to a Data URL of the specified type and invokes the provided callback.
|
|
2463
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
2464
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
2465
|
+
*/
|
|
2466
|
+
protected asyncToDataUrl(type?: DataURLType, callback?: Function): void {
|
|
2467
|
+
let dataURL = '';
|
|
2468
|
+
if (!type) type = 'image/png';
|
|
2469
|
+
|
|
2470
|
+
setTimeout(async () => {
|
|
2471
|
+
await this.toDataURL(type).then((url) => {
|
|
2472
|
+
dataURL = url;
|
|
2473
|
+
});
|
|
2474
|
+
if (callback) callback(dataURL);
|
|
2475
|
+
}, 16);
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
/**
|
|
2479
|
+
* Asynchronously converts the entire canvas content to a Data URL of the specified type
|
|
2480
|
+
* with optional padding, and invokes the provided callback.
|
|
2481
|
+
* @param type The type of the Data URL (optional, defaults to 'image/png').
|
|
2482
|
+
* @param imageConfig Configuration options for the image (optional).
|
|
2483
|
+
* @param callback A callback function to handle the Data URL (optional).
|
|
2484
|
+
*/
|
|
2485
|
+
protected asyncToFullDataUrl(
|
|
2486
|
+
type?: DataURLType,
|
|
2487
|
+
imageConfig?: { padding?: number | number[] },
|
|
2488
|
+
callback?: (dataUrl: string) => void,
|
|
2489
|
+
): void {
|
|
2490
|
+
let dataURL = '';
|
|
2491
|
+
if (!type) type = 'image/png';
|
|
2492
|
+
|
|
2493
|
+
setTimeout(async () => {
|
|
2494
|
+
await this.toFullDataURL(type, imageConfig).then((url) => {
|
|
2495
|
+
dataURL = url;
|
|
2496
|
+
});
|
|
2497
|
+
if (callback) callback(dataURL);
|
|
2498
|
+
}, 16);
|
|
2499
|
+
}
|
|
2500
|
+
|
|
1999
2501
|
// ===== history operations =====
|
|
2000
2502
|
|
|
2001
2503
|
/**
|
|
@@ -2020,30 +2522,30 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
2020
2522
|
/**
|
|
2021
2523
|
* Pause stacking operation.
|
|
2022
2524
|
*/
|
|
2023
|
-
public
|
|
2525
|
+
public pauseStack(): void {
|
|
2024
2526
|
const history = this.getHistoryPlugin();
|
|
2025
|
-
return history?.
|
|
2527
|
+
return history?.pauseStack();
|
|
2026
2528
|
}
|
|
2027
2529
|
|
|
2028
2530
|
/**
|
|
2029
2531
|
* Resume stacking operation.
|
|
2030
2532
|
*/
|
|
2031
|
-
public
|
|
2533
|
+
public resumeStack(): void {
|
|
2032
2534
|
const history = this.getHistoryPlugin();
|
|
2033
|
-
return history?.
|
|
2535
|
+
return history?.resumeStack();
|
|
2034
2536
|
}
|
|
2035
2537
|
|
|
2036
2538
|
/**
|
|
2037
2539
|
* Execute a callback without allowing any stacking operations.
|
|
2038
2540
|
* @param callback
|
|
2039
2541
|
*/
|
|
2040
|
-
public
|
|
2542
|
+
public executeWithNoStack = (callback: () => void): void => {
|
|
2041
2543
|
const history = this.getHistoryPlugin();
|
|
2042
|
-
history?.
|
|
2544
|
+
history?.pauseStack();
|
|
2043
2545
|
try {
|
|
2044
2546
|
callback();
|
|
2045
2547
|
} finally {
|
|
2046
|
-
history?.
|
|
2548
|
+
history?.resumeStack();
|
|
2047
2549
|
}
|
|
2048
2550
|
};
|
|
2049
2551
|
|
|
@@ -2109,41 +2611,41 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
2109
2611
|
}
|
|
2110
2612
|
|
|
2111
2613
|
/**
|
|
2112
|
-
* Begin a
|
|
2113
|
-
* Any operations performed between `
|
|
2614
|
+
* Begin a historyBatch operation.
|
|
2615
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
2114
2616
|
* treated as a single operation when undoing or redoing.
|
|
2115
2617
|
*/
|
|
2116
|
-
public
|
|
2618
|
+
public startHistoryBatch() {
|
|
2117
2619
|
const history = this.getHistoryPlugin();
|
|
2118
|
-
history?.
|
|
2620
|
+
history?.startHistoryBatch();
|
|
2119
2621
|
}
|
|
2120
2622
|
|
|
2121
2623
|
/**
|
|
2122
|
-
* End a
|
|
2123
|
-
* Any operations performed between `
|
|
2624
|
+
* End a historyBatch operation.
|
|
2625
|
+
* Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
|
|
2124
2626
|
* treated as a single operation when undoing or redoing.
|
|
2125
2627
|
*/
|
|
2126
|
-
public
|
|
2628
|
+
public stopHistoryBatch() {
|
|
2127
2629
|
const history = this.getHistoryPlugin();
|
|
2128
|
-
history?.
|
|
2630
|
+
history?.stopHistoryBatch();
|
|
2129
2631
|
}
|
|
2130
2632
|
|
|
2131
2633
|
/**
|
|
2132
2634
|
* Execute a provided function within a batched context
|
|
2133
2635
|
* All operations performed inside callback will be treated as a composite operation
|
|
2134
|
-
* more convenient way without manually invoking `
|
|
2636
|
+
* more convenient way without manually invoking `startHistoryBatch` and `stopHistoryBatch`.
|
|
2135
2637
|
* @param callback The func containing operations to be batched together.
|
|
2136
2638
|
*/
|
|
2137
|
-
public
|
|
2639
|
+
public historyBatch(callback: () => void) {
|
|
2138
2640
|
const history = this.getHistoryPlugin();
|
|
2139
|
-
history?.
|
|
2641
|
+
history?.historyBatch(callback);
|
|
2140
2642
|
}
|
|
2141
2643
|
|
|
2142
2644
|
/**
|
|
2143
2645
|
* Clear history stack
|
|
2144
2646
|
* @param {StackType} stackType undo/redo stack
|
|
2145
2647
|
*/
|
|
2146
|
-
public
|
|
2648
|
+
public cleanHistory(stackType?: StackType) {
|
|
2147
2649
|
const history = this.getHistoryPlugin();
|
|
2148
2650
|
if (!stackType) return history?.clear();
|
|
2149
2651
|
return stackType === 'undo'
|
|
@@ -2197,7 +2699,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
2197
2699
|
this.transientCanvas.destroy();
|
|
2198
2700
|
|
|
2199
2701
|
// clear history stack
|
|
2200
|
-
this.
|
|
2702
|
+
this.cleanHistory();
|
|
2201
2703
|
|
|
2202
2704
|
callback?.();
|
|
2203
2705
|
// }, 500);
|