@antv/g6 5.0.0-beta.0 → 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/api-doc/item.d.ts +2 -0
- package/esm/api-doc/item.js +2 -0
- package/esm/api-doc/item.js.map +1 -1
- 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 +127 -283
- 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/controller/plugin.js +3 -3
- package/esm/runtime/controller/plugin.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 +57 -26
- 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 +16 -11
- 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 +96 -6
- package/esm/stdlib/item/edge/base.js +92 -19
- 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 +90 -16
- package/esm/stdlib/item/node/base.js +91 -41
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/base3d.d.ts +24 -0
- package/esm/stdlib/item/node/base3d.js +24 -8
- 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 +5 -3
- 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 +20 -4
- 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/api-doc/item.d.ts +2 -0
- package/lib/api-doc/item.js +5 -1
- package/lib/api-doc/item.js.map +1 -1
- 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 +127 -283
- 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/controller/plugin.js +3 -3
- package/lib/runtime/controller/plugin.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 +57 -26
- 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 +16 -11
- 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 +96 -6
- package/lib/stdlib/item/edge/base.js +92 -19
- 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 +90 -16
- package/lib/stdlib/item/node/base.js +91 -41
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/base3d.d.ts +24 -0
- package/lib/stdlib/item/node/base3d.js +24 -8
- 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 +5 -3
- 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 +20 -4
- 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/api-doc/item.ts +2 -0
- 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 +142 -341
- package/src/runtime/controller/item.ts +236 -72
- package/src/runtime/controller/plugin.ts +15 -3
- 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 +76 -27
- 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 +16 -11
- package/src/stdlib/index.ts +33 -9
- package/src/stdlib/item/edge/base.ts +118 -19
- 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 +117 -46
- package/src/stdlib/item/node/base3d.ts +24 -9
- 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 +5 -4
- 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 +23 -4
- 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
|
@@ -0,0 +1,1063 @@
|
|
|
1
|
+
import { throttle } from '@antv/util';
|
|
2
|
+
import { Plugin as Base } from '../../../types/plugin';
|
|
3
|
+
export class Snapline extends Base {
|
|
4
|
+
setTolerance(tolerance) {
|
|
5
|
+
this.tolerance = tolerance;
|
|
6
|
+
}
|
|
7
|
+
getTolerance() {
|
|
8
|
+
return this.tolerance;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* getDrawLineId via DrawLine
|
|
12
|
+
* Principle: the lines on the drawing board is the only load-point
|
|
13
|
+
* @param dl drawLine
|
|
14
|
+
*/
|
|
15
|
+
getDrawLineIdByDrawLine(dl) {
|
|
16
|
+
if (!dl)
|
|
17
|
+
return;
|
|
18
|
+
return `${dl.line[0].x}-${dl.line[0].y}-${dl.line[1].x}-${dl.line[1].y}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param cp based on constractBBox's point
|
|
23
|
+
* @param dp based on draggingBBox point
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
getDrawLineIdByPoints([cp, dp]) {
|
|
27
|
+
return `${cp.x}-${cp.y}-${dp.x}-${dp.y}`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* all AlignLines satisfy conditions: in the tolerance range
|
|
31
|
+
*/
|
|
32
|
+
addAlignLinesForChoose() {
|
|
33
|
+
function isInToleranceRange(xOrY, contrast, tolerance) {
|
|
34
|
+
return xOrY >= contrast - tolerance && xOrY <= contrast + tolerance;
|
|
35
|
+
}
|
|
36
|
+
this.vContrastPoints.forEach((vpoint) => {
|
|
37
|
+
if (isInToleranceRange(this.draggingBBox.min[0], vpoint.x, this.tolerance))
|
|
38
|
+
this.alignLinesForChoose.v.push({
|
|
39
|
+
dl: {
|
|
40
|
+
line: [vpoint, { x: vpoint.x, y: this.draggingBBox.center[1] }],
|
|
41
|
+
lp: 'left',
|
|
42
|
+
},
|
|
43
|
+
offset: { x: vpoint.x - this.draggingBBox.min[0], y: 0 },
|
|
44
|
+
});
|
|
45
|
+
if (isInToleranceRange(this.draggingBBox.center[0], vpoint.x, this.tolerance))
|
|
46
|
+
this.alignLinesForChoose.v.push({
|
|
47
|
+
dl: {
|
|
48
|
+
line: [vpoint, { x: vpoint.x, y: this.draggingBBox.center[1] }],
|
|
49
|
+
lp: 'vcenter',
|
|
50
|
+
},
|
|
51
|
+
offset: { x: vpoint.x - this.draggingBBox.center[0], y: 0 },
|
|
52
|
+
});
|
|
53
|
+
if (isInToleranceRange(this.draggingBBox.max[0], vpoint.x, this.tolerance))
|
|
54
|
+
this.alignLinesForChoose.v.push({
|
|
55
|
+
dl: {
|
|
56
|
+
line: [vpoint, { x: vpoint.x, y: this.draggingBBox.center[1] }],
|
|
57
|
+
lp: 'right',
|
|
58
|
+
},
|
|
59
|
+
offset: { x: vpoint.x - this.draggingBBox.max[0], y: 0 },
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
this.hContrastPoints.forEach((hpoint) => {
|
|
63
|
+
if (isInToleranceRange(this.draggingBBox.min[1], hpoint.y, this.tolerance))
|
|
64
|
+
this.alignLinesForChoose.v.push({
|
|
65
|
+
dl: {
|
|
66
|
+
line: [hpoint, { x: this.draggingBBox.min[0], y: hpoint.y }],
|
|
67
|
+
lp: 'top',
|
|
68
|
+
},
|
|
69
|
+
offset: { x: 0, y: hpoint.y - this.draggingBBox.min[1] },
|
|
70
|
+
});
|
|
71
|
+
if (isInToleranceRange(this.draggingBBox.center[1], hpoint.y, this.tolerance))
|
|
72
|
+
this.alignLinesForChoose.v.push({
|
|
73
|
+
dl: {
|
|
74
|
+
line: [hpoint, { x: this.draggingBBox.center[0], y: hpoint.y }],
|
|
75
|
+
lp: 'hcenter',
|
|
76
|
+
},
|
|
77
|
+
offset: { x: 0, y: hpoint.y - this.draggingBBox.center[1] },
|
|
78
|
+
});
|
|
79
|
+
if (isInToleranceRange(this.draggingBBox.max[1], hpoint.y, this.tolerance))
|
|
80
|
+
this.alignLinesForChoose.v.push({
|
|
81
|
+
dl: {
|
|
82
|
+
line: [hpoint, { x: this.draggingBBox.max[0], y: hpoint.y }],
|
|
83
|
+
lp: 'bottom',
|
|
84
|
+
},
|
|
85
|
+
offset: { x: 0, y: hpoint.y - this.draggingBBox.max[1] },
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
initAlignLinesForChoose() {
|
|
90
|
+
this.alignLinesForChoose.v = [];
|
|
91
|
+
this.alignLinesForChoose.h = [];
|
|
92
|
+
let allIds = [];
|
|
93
|
+
this.graph.getAllCombosData().forEach((item) => {
|
|
94
|
+
allIds.push(item.id);
|
|
95
|
+
});
|
|
96
|
+
this.graph.getAllNodesData().forEach((item) => {
|
|
97
|
+
allIds.push(item.id);
|
|
98
|
+
});
|
|
99
|
+
allIds = allIds.filter((item) => item !== this.dragItemId); // 排除drag item
|
|
100
|
+
allIds.forEach((id) => {
|
|
101
|
+
const cb = this.graph.getRenderBBox(id, true); // contrast bbox
|
|
102
|
+
// 判断2个方向,6条线的对比
|
|
103
|
+
/* draggingBBox left */
|
|
104
|
+
if (Math.abs(this.draggingBBox.min[0] - cb.min[0]) <= this.tolerance) {
|
|
105
|
+
this.alignLinesForChoose.v.push({
|
|
106
|
+
dl: {
|
|
107
|
+
line: [
|
|
108
|
+
{ x: cb.min[0], y: cb.center[1] },
|
|
109
|
+
{ x: cb.min[0], y: this.draggingBBox.center[1] },
|
|
110
|
+
],
|
|
111
|
+
lp: 'left',
|
|
112
|
+
},
|
|
113
|
+
offset: {
|
|
114
|
+
x: this.draggingBBox.min[0] - cb.min[0],
|
|
115
|
+
y: this.draggingBBox.center[1] - cb.center[1],
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (Math.abs(this.draggingBBox.min[0] - cb.center[0]) <= this.tolerance) {
|
|
120
|
+
this.alignLinesForChoose.v.push({
|
|
121
|
+
dl: {
|
|
122
|
+
line: [
|
|
123
|
+
{ x: cb.center[0], y: cb.center[1] },
|
|
124
|
+
{ x: cb.center[0], y: this.draggingBBox.center[1] },
|
|
125
|
+
],
|
|
126
|
+
lp: 'left',
|
|
127
|
+
},
|
|
128
|
+
offset: {
|
|
129
|
+
x: this.draggingBBox.min[0] - cb.center[0],
|
|
130
|
+
y: this.draggingBBox.center[1] - cb.center[1],
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (Math.abs(this.draggingBBox.min[0] - cb.max[0]) <= this.tolerance) {
|
|
135
|
+
this.alignLinesForChoose.v.push({
|
|
136
|
+
dl: {
|
|
137
|
+
line: [
|
|
138
|
+
{ x: cb.max[0], y: cb.center[1] },
|
|
139
|
+
{ x: cb.max[0], y: this.draggingBBox.center[1] },
|
|
140
|
+
],
|
|
141
|
+
lp: 'left',
|
|
142
|
+
},
|
|
143
|
+
offset: {
|
|
144
|
+
x: this.draggingBBox.min[0] - cb.max[0],
|
|
145
|
+
y: this.draggingBBox.center[1] - cb.center[1],
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/* draggingBBox vcenter */
|
|
150
|
+
if (Math.abs(this.draggingBBox.center[0] - cb.min[0]) <= this.tolerance) {
|
|
151
|
+
this.alignLinesForChoose.v.push({
|
|
152
|
+
dl: {
|
|
153
|
+
line: [
|
|
154
|
+
{ x: cb.min[0], y: cb.center[1] },
|
|
155
|
+
{ x: cb.min[0], y: this.draggingBBox.center[1] },
|
|
156
|
+
],
|
|
157
|
+
lp: 'vcenter',
|
|
158
|
+
},
|
|
159
|
+
offset: {
|
|
160
|
+
x: this.draggingBBox.center[0] - cb.min[0],
|
|
161
|
+
y: this.draggingBBox.center[1] - cb.center[1],
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (Math.abs(this.draggingBBox.center[0] - cb.center[0]) <= this.tolerance) {
|
|
166
|
+
this.alignLinesForChoose.v.push({
|
|
167
|
+
dl: {
|
|
168
|
+
line: [
|
|
169
|
+
{ x: cb.center[0], y: cb.center[1] },
|
|
170
|
+
{ x: cb.center[0], y: this.draggingBBox.center[1] },
|
|
171
|
+
],
|
|
172
|
+
lp: 'vcenter',
|
|
173
|
+
},
|
|
174
|
+
offset: {
|
|
175
|
+
x: this.draggingBBox.center[0] - cb.center[0],
|
|
176
|
+
y: this.draggingBBox.center[1] - cb.center[1],
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (Math.abs(this.draggingBBox.center[0] - cb.max[0]) <= this.tolerance) {
|
|
181
|
+
this.alignLinesForChoose.v.push({
|
|
182
|
+
dl: {
|
|
183
|
+
line: [
|
|
184
|
+
{ x: cb.max[0], y: cb.center[1] },
|
|
185
|
+
{ x: cb.max[0], y: this.draggingBBox.center[1] },
|
|
186
|
+
],
|
|
187
|
+
lp: 'vcenter',
|
|
188
|
+
},
|
|
189
|
+
offset: {
|
|
190
|
+
x: this.draggingBBox.center[0] - cb.max[0],
|
|
191
|
+
y: this.draggingBBox.center[1] - cb.center[1],
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/* draggingBBox right */
|
|
196
|
+
if (Math.abs(this.draggingBBox.max[0] - cb.min[0]) <= this.tolerance) {
|
|
197
|
+
this.alignLinesForChoose.v.push({
|
|
198
|
+
dl: {
|
|
199
|
+
line: [
|
|
200
|
+
{ x: cb.min[0], y: cb.center[1] },
|
|
201
|
+
{ x: cb.min[0], y: this.draggingBBox.center[1] },
|
|
202
|
+
],
|
|
203
|
+
lp: 'right',
|
|
204
|
+
},
|
|
205
|
+
offset: {
|
|
206
|
+
x: this.draggingBBox.max[0] - cb.min[0],
|
|
207
|
+
y: this.draggingBBox.center[1] - cb.center[1],
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
if (Math.abs(this.draggingBBox.max[0] - cb.center[0]) <= this.tolerance) {
|
|
212
|
+
this.alignLinesForChoose.v.push({
|
|
213
|
+
dl: {
|
|
214
|
+
line: [
|
|
215
|
+
{ x: cb.center[0], y: cb.center[1] },
|
|
216
|
+
{ x: cb.center[0], y: this.draggingBBox.center[1] },
|
|
217
|
+
],
|
|
218
|
+
lp: 'right',
|
|
219
|
+
},
|
|
220
|
+
offset: {
|
|
221
|
+
x: this.draggingBBox.max[0] - cb.center[0],
|
|
222
|
+
y: this.draggingBBox.center[1] - cb.center[1],
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
if (Math.abs(this.draggingBBox.max[0] - cb.max[0]) <= this.tolerance) {
|
|
227
|
+
this.alignLinesForChoose.v.push({
|
|
228
|
+
dl: {
|
|
229
|
+
line: [
|
|
230
|
+
{ x: cb.max[0], y: cb.center[1] },
|
|
231
|
+
{ x: cb.max[0], y: this.draggingBBox.center[1] },
|
|
232
|
+
],
|
|
233
|
+
lp: 'right',
|
|
234
|
+
},
|
|
235
|
+
offset: {
|
|
236
|
+
x: this.draggingBBox.max[0] - cb.max[0],
|
|
237
|
+
y: this.draggingBBox.center[1] - cb.center[1],
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/* draggingBBox top */
|
|
242
|
+
if (Math.abs(this.draggingBBox.min[1] - cb.max[1]) <= this.tolerance) {
|
|
243
|
+
this.alignLinesForChoose.h.push({
|
|
244
|
+
dl: {
|
|
245
|
+
line: [
|
|
246
|
+
{ x: cb.center[0], y: cb.max[1] },
|
|
247
|
+
{ x: this.draggingBBox.center[0], y: cb.max[1] },
|
|
248
|
+
],
|
|
249
|
+
lp: 'top',
|
|
250
|
+
},
|
|
251
|
+
offset: {
|
|
252
|
+
x: this.draggingBBox.center[0] - cb.center[0],
|
|
253
|
+
y: this.draggingBBox.min[1] - cb.max[1],
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
if (Math.abs(this.draggingBBox.min[1] - cb.center[1]) <= this.tolerance) {
|
|
258
|
+
this.alignLinesForChoose.h.push({
|
|
259
|
+
dl: {
|
|
260
|
+
line: [
|
|
261
|
+
{ x: cb.center[0], y: cb.center[1] },
|
|
262
|
+
{ x: this.draggingBBox.center[0], y: cb.center[1] },
|
|
263
|
+
],
|
|
264
|
+
lp: 'top',
|
|
265
|
+
},
|
|
266
|
+
offset: {
|
|
267
|
+
x: this.draggingBBox.center[0] - cb.center[0],
|
|
268
|
+
y: this.draggingBBox.min[1] - cb.center[1],
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
if (Math.abs(this.draggingBBox.min[1] - cb.min[1]) <= this.tolerance) {
|
|
273
|
+
this.alignLinesForChoose.h.push({
|
|
274
|
+
dl: {
|
|
275
|
+
line: [
|
|
276
|
+
{ x: cb.center[0], y: cb.max[1] },
|
|
277
|
+
{ x: this.draggingBBox.center[0], y: cb.max[1] },
|
|
278
|
+
],
|
|
279
|
+
lp: 'top',
|
|
280
|
+
},
|
|
281
|
+
offset: {
|
|
282
|
+
x: this.draggingBBox.center[0] - cb.center[0],
|
|
283
|
+
y: this.draggingBBox.min[1] - cb.min[1],
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/* draggingBBox hcenter */
|
|
288
|
+
if (Math.abs(this.draggingBBox.center[1] - cb.max[1]) <= this.tolerance) {
|
|
289
|
+
this.alignLinesForChoose.h.push({
|
|
290
|
+
dl: {
|
|
291
|
+
line: [
|
|
292
|
+
{ x: cb.center[0], y: cb.max[1] },
|
|
293
|
+
{ x: this.draggingBBox.center[0], y: cb.max[1] },
|
|
294
|
+
],
|
|
295
|
+
lp: 'hcenter',
|
|
296
|
+
},
|
|
297
|
+
offset: {
|
|
298
|
+
x: this.draggingBBox.center[0] - cb.center[0],
|
|
299
|
+
y: this.draggingBBox.center[1] - cb.max[1],
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
if (Math.abs(this.draggingBBox.center[1] - cb.center[1]) <= this.tolerance) {
|
|
304
|
+
this.alignLinesForChoose.h.push({
|
|
305
|
+
dl: {
|
|
306
|
+
line: [
|
|
307
|
+
{ x: cb.center[0], y: cb.center[1] },
|
|
308
|
+
{ x: this.draggingBBox.center[0], y: cb.center[1] },
|
|
309
|
+
],
|
|
310
|
+
lp: 'hcenter',
|
|
311
|
+
},
|
|
312
|
+
offset: {
|
|
313
|
+
x: this.draggingBBox.center[0] - cb.center[0],
|
|
314
|
+
y: this.draggingBBox.center[1] - cb.center[1],
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
if (Math.abs(this.draggingBBox.center[1] - cb.min[1]) <= this.tolerance) {
|
|
319
|
+
this.alignLinesForChoose.h.push({
|
|
320
|
+
dl: {
|
|
321
|
+
line: [
|
|
322
|
+
{ x: cb.center[0], y: cb.min[1] },
|
|
323
|
+
{ x: this.draggingBBox.center[0], y: cb.min[1] },
|
|
324
|
+
],
|
|
325
|
+
lp: 'hcenter',
|
|
326
|
+
},
|
|
327
|
+
offset: {
|
|
328
|
+
x: this.draggingBBox.center[0] - cb.center[0],
|
|
329
|
+
y: this.draggingBBox.center[1] - cb.min[1],
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
/* draggingBBox bottom */
|
|
334
|
+
if (Math.abs(this.draggingBBox.max[1] - cb.max[1]) <= this.tolerance) {
|
|
335
|
+
this.alignLinesForChoose.h.push({
|
|
336
|
+
dl: {
|
|
337
|
+
line: [
|
|
338
|
+
{ x: cb.center[0], y: cb.max[1] },
|
|
339
|
+
{ x: this.draggingBBox.center[0], y: cb.max[1] },
|
|
340
|
+
],
|
|
341
|
+
lp: 'bottom',
|
|
342
|
+
},
|
|
343
|
+
offset: {
|
|
344
|
+
x: this.draggingBBox.center[0] - cb.center[0],
|
|
345
|
+
y: this.draggingBBox.max[1] - cb.max[1],
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
if (Math.abs(this.draggingBBox.max[1] - cb.center[1]) <= this.tolerance) {
|
|
350
|
+
this.alignLinesForChoose.h.push({
|
|
351
|
+
dl: {
|
|
352
|
+
line: [
|
|
353
|
+
{ x: cb.center[0], y: cb.center[1] },
|
|
354
|
+
{ x: this.draggingBBox.center[0], y: cb.center[1] },
|
|
355
|
+
],
|
|
356
|
+
lp: 'bottom',
|
|
357
|
+
},
|
|
358
|
+
offset: {
|
|
359
|
+
x: this.draggingBBox.center[0] - cb.center[0],
|
|
360
|
+
y: this.draggingBBox.max[1] - cb.center[1],
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
if (Math.abs(this.draggingBBox.max[1] - cb.min[1]) <= this.tolerance) {
|
|
365
|
+
this.alignLinesForChoose.h.push({
|
|
366
|
+
dl: {
|
|
367
|
+
line: [
|
|
368
|
+
{ x: cb.center[0], y: cb.min[1] },
|
|
369
|
+
{ x: this.draggingBBox.center[0], y: cb.min[1] },
|
|
370
|
+
],
|
|
371
|
+
lp: 'bottom',
|
|
372
|
+
},
|
|
373
|
+
offset: {
|
|
374
|
+
x: this.draggingBBox.center[0] - cb.center[0],
|
|
375
|
+
y: this.draggingBBox.max[1] - cb.min[1],
|
|
376
|
+
},
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
chooseAlignLine() {
|
|
382
|
+
// Principles:
|
|
383
|
+
// 1. Smaller difference from tolerance is more important
|
|
384
|
+
// 2. Same tolerance, (if multiple lines in the same direction are within the tolerance range) Importance: hcenter > top > bottom; vcenter > left > right
|
|
385
|
+
// 3. At most: vertical one count; horizon one count
|
|
386
|
+
// 4. Repeat line, will be subject to the longest (note: can't go to heavy, for performance, in the array of selected again)
|
|
387
|
+
// v direction line selection rule: draggingBBox's left/vcenter/right compares to vContrastPoints
|
|
388
|
+
// h direction line selection rule: draggingBBox's top/hcenter/bottom compares to hContrastPoints
|
|
389
|
+
if (this.alignLinesForChoose.v.length + this.alignLinesForChoose.h.length ===
|
|
390
|
+
0) {
|
|
391
|
+
return { v: undefined, h: undefined };
|
|
392
|
+
}
|
|
393
|
+
let vTmpLines = [];
|
|
394
|
+
let hTmpLines = [];
|
|
395
|
+
// 1.v,h direction: select the line with minimum offset
|
|
396
|
+
const vMinOffset = Math.min(...this.alignLinesForChoose.v.map((dlFc) => dlFc.offset.x));
|
|
397
|
+
const hMinOffset = Math.min(...this.alignLinesForChoose.h.map((dlFc) => dlFc.offset.y));
|
|
398
|
+
vTmpLines = this.alignLinesForChoose.v.filter((dlFc) => dlFc.offset.x === vMinOffset);
|
|
399
|
+
hTmpLines = this.alignLinesForChoose.h.filter((dlFc) => dlFc.offset.y === hMinOffset);
|
|
400
|
+
// 2.same tolerance,hcenter > top > bottom; vcenter > left > right. (The principle of selecting only one direction)
|
|
401
|
+
{
|
|
402
|
+
const vcenter_hasdata = vTmpLines.some((dlFc) => dlFc.dl.lp === 'vcenter');
|
|
403
|
+
const left_hasdata = vTmpLines.some((dlFc) => dlFc.dl.lp === 'left');
|
|
404
|
+
vTmpLines = vTmpLines.filter((dlFc) => {
|
|
405
|
+
if (dlFc.dl.lp === 'vcenter') {
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
if (dlFc.dl.lp === 'left') {
|
|
409
|
+
if (!vcenter_hasdata && left_hasdata) {
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
if (dlFc.dl.lp === 'right') {
|
|
415
|
+
if (!vcenter_hasdata && !left_hasdata) {
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
return false;
|
|
421
|
+
});
|
|
422
|
+
const hcenter_hasdata = hTmpLines.some((dlFc) => dlFc.dl.lp === 'hcenter');
|
|
423
|
+
const top_hasdata = hTmpLines.some((dlFc) => dlFc.dl.lp === 'top');
|
|
424
|
+
hTmpLines = hTmpLines.filter((dlFc) => {
|
|
425
|
+
if (dlFc.dl.lp === 'hcenter') {
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
if (dlFc.dl.lp === 'top') {
|
|
429
|
+
if (!hcenter_hasdata && top_hasdata) {
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
if (dlFc.dl.lp === 'bottom') {
|
|
435
|
+
if (!hcenter_hasdata && !top_hasdata) {
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
return false;
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
// 3.remove duplicates
|
|
444
|
+
const uniVTmpLines = Array.from(vTmpLines
|
|
445
|
+
.reduce((map, item) => {
|
|
446
|
+
var _a;
|
|
447
|
+
if (!map.has(item.dl.lp) ||
|
|
448
|
+
Math.abs(item.offset.x) < Math.abs((_a = map.get(item.dl.lp)) === null || _a === void 0 ? void 0 : _a.offset.x)) {
|
|
449
|
+
map.set(item.dl.lp, item);
|
|
450
|
+
}
|
|
451
|
+
return map;
|
|
452
|
+
}, new Map())
|
|
453
|
+
.values());
|
|
454
|
+
const uniHTmpLines = Array.from(hTmpLines
|
|
455
|
+
.reduce((map, item) => {
|
|
456
|
+
var _a;
|
|
457
|
+
if (!map.has(item.dl.lp) ||
|
|
458
|
+
Math.abs(item.offset.y) < Math.abs((_a = map.get(item.dl.lp)) === null || _a === void 0 ? void 0 : _a.offset.y)) {
|
|
459
|
+
map.set(item.dl.lp, item);
|
|
460
|
+
}
|
|
461
|
+
return map;
|
|
462
|
+
}, new Map())
|
|
463
|
+
.values());
|
|
464
|
+
// 4.choose a maximum offset one of DrawLineForChoose
|
|
465
|
+
const vMaxDL = uniVTmpLines.length
|
|
466
|
+
? uniVTmpLines.reduce((maxItem, curItem) => {
|
|
467
|
+
if (curItem.offset.x > maxItem.offset.x) {
|
|
468
|
+
return curItem;
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
return maxItem;
|
|
472
|
+
}
|
|
473
|
+
})
|
|
474
|
+
: undefined;
|
|
475
|
+
const hMaxDL = uniHTmpLines.length
|
|
476
|
+
? uniHTmpLines.reduce((maxItem, curItem) => {
|
|
477
|
+
if (curItem.offset.y > maxItem.offset.y) {
|
|
478
|
+
return curItem;
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
return maxItem;
|
|
482
|
+
}
|
|
483
|
+
})
|
|
484
|
+
: undefined;
|
|
485
|
+
return {
|
|
486
|
+
v: vMaxDL ? vMaxDL.dl : undefined,
|
|
487
|
+
h: hMaxDL ? hMaxDL.dl : undefined,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
constructor(options) {
|
|
491
|
+
super(options);
|
|
492
|
+
//#region state: historyPoints
|
|
493
|
+
this.historyPoints = [
|
|
494
|
+
undefined,
|
|
495
|
+
undefined,
|
|
496
|
+
];
|
|
497
|
+
/**
|
|
498
|
+
* when start drag, offset of cursor and node center (event.canvas - draggingnode.BBox)
|
|
499
|
+
*/
|
|
500
|
+
this.initialOffset = [undefined, undefined];
|
|
501
|
+
/**
|
|
502
|
+
* Cache the nodes' positions to be throttly updated.
|
|
503
|
+
*/
|
|
504
|
+
this.updateCache = new Map();
|
|
505
|
+
/**
|
|
506
|
+
* Gets the current cursor node and center offset and then with initialOffset difference
|
|
507
|
+
*/
|
|
508
|
+
this.getCurOffsetCompareToInitialOffset = (e) => {
|
|
509
|
+
if (this.initialOffset[0] === undefined ||
|
|
510
|
+
this.initialOffset[1] === undefined) {
|
|
511
|
+
return [undefined, undefined];
|
|
512
|
+
}
|
|
513
|
+
const curOffset = [
|
|
514
|
+
e.canvas.x - this.draggingBBox.center[0],
|
|
515
|
+
e.canvas.y - this.draggingBBox.center[1],
|
|
516
|
+
];
|
|
517
|
+
return [
|
|
518
|
+
curOffset[0] - this.initialOffset[0],
|
|
519
|
+
curOffset[1] - this.initialOffset[1],
|
|
520
|
+
];
|
|
521
|
+
};
|
|
522
|
+
this.dragging = false;
|
|
523
|
+
this.draggingBBox = undefined;
|
|
524
|
+
// Gets the offset between the cursor and draggingItem
|
|
525
|
+
this.getPointerOffsetWithItem = (pointer) => {
|
|
526
|
+
return {
|
|
527
|
+
x: Math.abs(pointer.x - this.draggingBBox.center[0]),
|
|
528
|
+
y: Math.abs(pointer.x - this.draggingBBox.center[1]),
|
|
529
|
+
};
|
|
530
|
+
};
|
|
531
|
+
//#region state: tolerance
|
|
532
|
+
this.tolerance = 4;
|
|
533
|
+
this.toleranceFactor = 2;
|
|
534
|
+
//#endregion
|
|
535
|
+
// All the lines in the vertical direction
|
|
536
|
+
this.vContrastPoints = [];
|
|
537
|
+
this.hContrastPoints = [];
|
|
538
|
+
/**
|
|
539
|
+
* alignLinesForChoose container
|
|
540
|
+
*/
|
|
541
|
+
this.alignLinesForChoose = { v: [], h: [] };
|
|
542
|
+
/**
|
|
543
|
+
* v and h direction adsorption state
|
|
544
|
+
*/
|
|
545
|
+
this.isAdsorbed = [false, false]; // whether the adsorption state
|
|
546
|
+
this.dragEvent = undefined; // drag event
|
|
547
|
+
// use dragItemId and dragItemType to avoid object changing when dragging
|
|
548
|
+
this.dragItemId = undefined;
|
|
549
|
+
this.dragItemType = undefined;
|
|
550
|
+
/**
|
|
551
|
+
* Historical adsorption region: v and h directions
|
|
552
|
+
* x0 ~ x1: Represents the starting and ending line in the v direction
|
|
553
|
+
* y0 ~ y1: Represents the starting and ending line in the h direction
|
|
554
|
+
*
|
|
555
|
+
* When the cursor moves out of this region && non-adsorbed state => set to undefined
|
|
556
|
+
*/
|
|
557
|
+
this.historyAbsorbArea = [undefined, undefined];
|
|
558
|
+
/**
|
|
559
|
+
* Unable to adsorb: countdown
|
|
560
|
+
*/
|
|
561
|
+
this.canAdsorbCount = 0;
|
|
562
|
+
/**
|
|
563
|
+
* Countdown method: Countdown
|
|
564
|
+
*/
|
|
565
|
+
this.canAdsorbCountDown = () => {
|
|
566
|
+
if (this.canAdsorbCount > 0) {
|
|
567
|
+
const intervalID = setInterval(() => {
|
|
568
|
+
this.canAdsorbCount--;
|
|
569
|
+
if (this.canAdsorbCount <= 0) {
|
|
570
|
+
clearTimeout(intervalID);
|
|
571
|
+
}
|
|
572
|
+
}, 100);
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
this.onDrag = throttle(((event) => {
|
|
576
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
577
|
+
this.dragEvent = event;
|
|
578
|
+
this.initAlignLinesForChoose();
|
|
579
|
+
// control layer: Check to delete existing line & drawed line & adsorption
|
|
580
|
+
// set historyPoints
|
|
581
|
+
this.historyPoints[0] = this.historyPoints[1];
|
|
582
|
+
this.historyPoints[1] = { x: event.canvas.x, y: event.canvas.y };
|
|
583
|
+
let vlp = undefined;
|
|
584
|
+
let vline = undefined;
|
|
585
|
+
let hlp = undefined;
|
|
586
|
+
let hline = undefined;
|
|
587
|
+
// v direction: whether keep adsorption
|
|
588
|
+
const checkVShouldHoldAbsorb = (vlp, vline) => {
|
|
589
|
+
// v direction: continue to adsorb
|
|
590
|
+
const vShouldAbsorb = Math.abs(this.getCurOffsetCompareToInitialOffset(event)[0]) <=
|
|
591
|
+
this.tolerance * this.toleranceFactor;
|
|
592
|
+
if (vShouldAbsorb) {
|
|
593
|
+
if (vlp === 'left') {
|
|
594
|
+
this.doUpdatePosition({
|
|
595
|
+
x: vline[0].x + this.draggingBBox.halfExtents[0],
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
else if (vlp === 'vcenter') {
|
|
599
|
+
this.doUpdatePosition({
|
|
600
|
+
x: vline[0].x,
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
else if (vlp === 'right') {
|
|
604
|
+
this.doUpdatePosition({
|
|
605
|
+
fx: vline[0].x - this.draggingBBox.halfExtents[0],
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
// updarte align line when absorb
|
|
609
|
+
this.updateAlignLineWhenAbsorb([true, false]);
|
|
610
|
+
}
|
|
611
|
+
else {
|
|
612
|
+
// cancel absorb
|
|
613
|
+
// 1.update positon
|
|
614
|
+
this.doUpdatePosition({ fx: undefined });
|
|
615
|
+
// 2.remove align line && update state
|
|
616
|
+
this.removeAlignLine([true, undefined]);
|
|
617
|
+
// count down to be adsorbable
|
|
618
|
+
this.canAdsorbCount = 10; // 1s
|
|
619
|
+
this.canAdsorbCountDown();
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
// h direction: whether keep adsorption
|
|
623
|
+
const checkHShouldHoldAbsorb = (hlp, hline) => {
|
|
624
|
+
// h direction: continue to adsorb
|
|
625
|
+
const hShouldAbsorb = Math.abs(this.getCurOffsetCompareToInitialOffset(event)[1]) <=
|
|
626
|
+
this.tolerance * this.toleranceFactor;
|
|
627
|
+
if (hShouldAbsorb) {
|
|
628
|
+
if (hlp === 'top') {
|
|
629
|
+
this.doUpdatePosition({
|
|
630
|
+
fy: hline[0].y + this.draggingBBox.halfExtents[1],
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
else if (hlp === 'hcenter') {
|
|
634
|
+
this.doUpdatePosition({
|
|
635
|
+
fy: hline[0].y,
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
else if (hlp === 'bottom') {
|
|
639
|
+
this.doUpdatePosition({
|
|
640
|
+
fy: hline[0].y - this.draggingBBox.halfExtents[1],
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
// update align line
|
|
644
|
+
this.updateAlignLineWhenAbsorb([false, true]);
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
// 1.update position
|
|
648
|
+
this.doUpdatePosition({ fy: undefined });
|
|
649
|
+
// 2.remove align line && update state
|
|
650
|
+
this.removeAlignLine([undefined, true]);
|
|
651
|
+
// count down to be adsorbable
|
|
652
|
+
this.canAdsorbCount = 10; // 1s
|
|
653
|
+
this.canAdsorbCountDown();
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
// v direction: whether adsorbed
|
|
657
|
+
const checkVShouldAbsorb = () => {
|
|
658
|
+
const ret = this.canDrawLine();
|
|
659
|
+
// If in recent from adsorption area, can't immediately draw lines (must be removed from the area to reline this area)
|
|
660
|
+
if (ret) {
|
|
661
|
+
// draw align lines
|
|
662
|
+
this.drawAlignLines({ vdl: ret.vdl, hdl: undefined });
|
|
663
|
+
// absorb dragging box
|
|
664
|
+
this.absorb({ vdl: ret.vdl, hdl: undefined });
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
// h direction: whether adsorbed
|
|
668
|
+
const checkHShouldAbsorb = () => {
|
|
669
|
+
const ret = this.canDrawLine();
|
|
670
|
+
// If in recent from adsorption area, can't immediately draw lines (must be removed from the area to reline this area)
|
|
671
|
+
if (ret) {
|
|
672
|
+
// draw align lines
|
|
673
|
+
this.drawAlignLines({ vdl: undefined, hdl: ret.hdl });
|
|
674
|
+
// absorb dragging box
|
|
675
|
+
this.absorb({ vdl: undefined, hdl: ret.hdl });
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
// 1、the current state of the two directions are adsorption
|
|
679
|
+
if (this.isAdsorbed[0] && this.isAdsorbed[1]) {
|
|
680
|
+
vlp = (_a = this.drawedLines[0].dl) === null || _a === void 0 ? void 0 : _a.lp;
|
|
681
|
+
vline = (_b = this.drawedLines[0].dl) === null || _b === void 0 ? void 0 : _b.line;
|
|
682
|
+
hlp = (_c = this.drawedLines[1].dl) === null || _c === void 0 ? void 0 : _c.lp;
|
|
683
|
+
hline = (_d = this.drawedLines[1].dl) === null || _d === void 0 ? void 0 : _d.line;
|
|
684
|
+
checkVShouldHoldAbsorb(vlp, vline);
|
|
685
|
+
checkHShouldHoldAbsorb(hlp, hline);
|
|
686
|
+
}
|
|
687
|
+
else if (this.isAdsorbed[0] && !this.isAdsorbed[1]) {
|
|
688
|
+
// 2、currently, only the v direction is adsorbed
|
|
689
|
+
vlp = (_e = this.drawedLines[0].dl) === null || _e === void 0 ? void 0 : _e.lp;
|
|
690
|
+
vline = (_f = this.drawedLines[0].dl) === null || _f === void 0 ? void 0 : _f.line;
|
|
691
|
+
checkVShouldHoldAbsorb(vlp, vline);
|
|
692
|
+
checkHShouldAbsorb();
|
|
693
|
+
}
|
|
694
|
+
else if (!this.isAdsorbed[0] && this.isAdsorbed[1]) {
|
|
695
|
+
// 3、currently, only the h direction is adsorbed
|
|
696
|
+
hlp = (_g = this.drawedLines[1].dl) === null || _g === void 0 ? void 0 : _g.lp;
|
|
697
|
+
hline = (_h = this.drawedLines[1].dl) === null || _h === void 0 ? void 0 : _h.line;
|
|
698
|
+
checkHShouldHoldAbsorb(vlp, vline);
|
|
699
|
+
checkVShouldAbsorb();
|
|
700
|
+
}
|
|
701
|
+
else if (!this.isAdsorbed[0] && !this.isAdsorbed[1]) {
|
|
702
|
+
// 4、currently, v and h directions are not adsorbed
|
|
703
|
+
const ret = this.canDrawLine();
|
|
704
|
+
// If you have recently detached from the attachment area, you cannot draw the line immediately (you need to remove the detached area to redraw the area)
|
|
705
|
+
if (ret) {
|
|
706
|
+
// draw align lines
|
|
707
|
+
this.drawAlignLines(ret);
|
|
708
|
+
// absorb dragging box
|
|
709
|
+
this.absorb(ret);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}).bind(this), 16, {
|
|
713
|
+
leading: false,
|
|
714
|
+
trailing: true,
|
|
715
|
+
});
|
|
716
|
+
//#region draw/remove lines
|
|
717
|
+
// first:v direction; second:h direction;
|
|
718
|
+
// ddo: drawed DisplayObject, dl: DrawLine
|
|
719
|
+
this.drawedLines = [undefined, undefined];
|
|
720
|
+
this.throttleUpdate = throttle(() => {
|
|
721
|
+
this.graph.updateNodePosition(Array.from(this.updateCache.values()), false, true);
|
|
722
|
+
this.updateCache.clear();
|
|
723
|
+
}, 16, {
|
|
724
|
+
leading: true,
|
|
725
|
+
trailing: true,
|
|
726
|
+
});
|
|
727
|
+
this.init(options.graph);
|
|
728
|
+
}
|
|
729
|
+
getEvents() {
|
|
730
|
+
return {
|
|
731
|
+
pointerdown: this.onPointerDown,
|
|
732
|
+
pointermove: this.onPointerMove,
|
|
733
|
+
pointerup: this.onPointerUp,
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
onPointerDown(event) {
|
|
737
|
+
this.historyPoints[1] = { x: event.canvas.x, y: event.canvas.y };
|
|
738
|
+
this.dragItemId = event.itemId;
|
|
739
|
+
this.dragItemType = event.itemType;
|
|
740
|
+
}
|
|
741
|
+
onPointerMove(event) {
|
|
742
|
+
if (!this.historyPoints[1])
|
|
743
|
+
return;
|
|
744
|
+
if (this.dragItemType !== 'node') {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
// pointerDown + first move = start drag
|
|
748
|
+
if (!this.dragging) {
|
|
749
|
+
this.onDragStart(event);
|
|
750
|
+
this.dragging = true;
|
|
751
|
+
}
|
|
752
|
+
else {
|
|
753
|
+
this.onDrag(event);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
onPointerUp(event) {
|
|
757
|
+
// pointerUp + dragging = onDragEnd
|
|
758
|
+
if (this.dragging) {
|
|
759
|
+
this.onDragEnd();
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
this.historyPoints = [undefined, undefined];
|
|
763
|
+
this.dragging = false;
|
|
764
|
+
this.dragItemId = undefined;
|
|
765
|
+
this.dragItemType = undefined;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
getGraph(event) {
|
|
769
|
+
return event.currentTarget;
|
|
770
|
+
}
|
|
771
|
+
//#region event handler
|
|
772
|
+
onDragStart(event) {
|
|
773
|
+
this.draggingBBox = this.graph.getRenderBBox(event.itemId, true);
|
|
774
|
+
this.initialOffset = [
|
|
775
|
+
event.canvas.x - this.draggingBBox.center[0],
|
|
776
|
+
event.canvas.y - this.draggingBBox.center[1],
|
|
777
|
+
];
|
|
778
|
+
}
|
|
779
|
+
onDragEnd() {
|
|
780
|
+
this.dragEvent = undefined;
|
|
781
|
+
this.historyPoints = [undefined, undefined];
|
|
782
|
+
this.dragging = false;
|
|
783
|
+
this.dragItemId = undefined;
|
|
784
|
+
this.dragItemType = undefined;
|
|
785
|
+
}
|
|
786
|
+
drawAlignLines({ vdl, hdl, }) {
|
|
787
|
+
// 1.draw align line
|
|
788
|
+
const vLineID = vdl ? this.getDrawLineIdByDrawLine(vdl) : undefined;
|
|
789
|
+
const hLineID = hdl ? this.getDrawLineIdByDrawLine(hdl) : undefined;
|
|
790
|
+
let vLine = undefined;
|
|
791
|
+
if (vdl) {
|
|
792
|
+
vLine = this.graph.drawTransient('line', vLineID, {
|
|
793
|
+
style: {
|
|
794
|
+
stroke: 'red',
|
|
795
|
+
lineWidth: 1,
|
|
796
|
+
x1: vdl.line[0].x,
|
|
797
|
+
y1: vdl.line[0].y,
|
|
798
|
+
x2: vdl.line[1].x,
|
|
799
|
+
y2: vdl.line[1].y,
|
|
800
|
+
},
|
|
801
|
+
});
|
|
802
|
+
// add to alignLines
|
|
803
|
+
this.drawedLines[0] = { do: vLine, dl: vdl };
|
|
804
|
+
}
|
|
805
|
+
let hLine = undefined;
|
|
806
|
+
if (hdl) {
|
|
807
|
+
hLine = this.graph.drawTransient('line', hLineID, {
|
|
808
|
+
style: {
|
|
809
|
+
stroke: 'red',
|
|
810
|
+
lineWidth: 1,
|
|
811
|
+
x1: hdl.line[0].x,
|
|
812
|
+
y1: hdl.line[0].y,
|
|
813
|
+
x2: hdl.line[1].x,
|
|
814
|
+
y2: hdl.line[1].y,
|
|
815
|
+
},
|
|
816
|
+
});
|
|
817
|
+
// add to alignLines
|
|
818
|
+
this.drawedLines[1] = { do: hLine, dl: hdl };
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* remove align line
|
|
823
|
+
* @param rvdl: remove vertical drawed line
|
|
824
|
+
* @param rhdl: remove horizon drawed line
|
|
825
|
+
*/
|
|
826
|
+
removeAlignLine([rvdl, rhdl]) {
|
|
827
|
+
if (rvdl) {
|
|
828
|
+
const vlid = this.getDrawLineIdByDrawLine(this.drawedLines[0].dl);
|
|
829
|
+
this.graph.drawTransient('line', vlid, { action: 'remove' });
|
|
830
|
+
this.drawedLines[0] = undefined;
|
|
831
|
+
this.isAdsorbed[0] = false;
|
|
832
|
+
}
|
|
833
|
+
if (rhdl) {
|
|
834
|
+
const hlid = this.getDrawLineIdByDrawLine(this.drawedLines[1].dl);
|
|
835
|
+
this.graph.drawTransient('line', hlid, { action: 'remove' });
|
|
836
|
+
this.drawedLines[1] = undefined;
|
|
837
|
+
this.isAdsorbed[1] = false;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* via ID: remove align line
|
|
842
|
+
* @param rmLineID
|
|
843
|
+
*/
|
|
844
|
+
removeAlignLineByID(rmLineID) {
|
|
845
|
+
// remove from DisplayObject
|
|
846
|
+
const [vTmpDrawedLine, hTmpDrawedLine] = this.drawedLines;
|
|
847
|
+
this.drawedLines.forEach((line, index) => {
|
|
848
|
+
if (line && line.do) {
|
|
849
|
+
const lineID = this.getDrawLineIdByPoints(line.dl.line);
|
|
850
|
+
if (lineID === rmLineID) {
|
|
851
|
+
if (index === 0 && vTmpDrawedLine) {
|
|
852
|
+
vTmpDrawedLine.dl = undefined;
|
|
853
|
+
vTmpDrawedLine.do = undefined;
|
|
854
|
+
}
|
|
855
|
+
else if (index === 1 && hTmpDrawedLine) {
|
|
856
|
+
hTmpDrawedLine.dl = undefined;
|
|
857
|
+
hTmpDrawedLine.do = undefined;
|
|
858
|
+
}
|
|
859
|
+
this.isAdsorbed[index] = false;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
this.drawedLines[0] = vTmpDrawedLine;
|
|
864
|
+
this.drawedLines[1] = hTmpDrawedLine;
|
|
865
|
+
// remove drawed line
|
|
866
|
+
this.graph.drawTransient('line', rmLineID, { action: 'remove' });
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* get draggingBBox Point based on LinePosition
|
|
870
|
+
*/
|
|
871
|
+
getDraggingBBoxPointByLinePosition(lp) {
|
|
872
|
+
if (!this.draggingBBox) {
|
|
873
|
+
return undefined;
|
|
874
|
+
}
|
|
875
|
+
if (lp === 'left') {
|
|
876
|
+
return { x: this.draggingBBox.min[0], y: this.draggingBBox.center[1] };
|
|
877
|
+
}
|
|
878
|
+
if (lp === 'vcenter' || lp === 'hcenter') {
|
|
879
|
+
return { x: this.draggingBBox.center[0], y: this.draggingBBox.center[1] };
|
|
880
|
+
}
|
|
881
|
+
if (lp === 'right') {
|
|
882
|
+
return { x: this.draggingBBox.max[0], y: this.draggingBBox.center[1] };
|
|
883
|
+
}
|
|
884
|
+
if (lp === 'top') {
|
|
885
|
+
return { x: this.draggingBBox.center[0], y: this.draggingBBox.min[1] };
|
|
886
|
+
}
|
|
887
|
+
if (lp === 'bottom') {
|
|
888
|
+
return { x: this.draggingBBox.center[0], y: this.draggingBBox.max[1] };
|
|
889
|
+
}
|
|
890
|
+
return undefined;
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* update align line under condition of absorbed
|
|
894
|
+
*/
|
|
895
|
+
updateAlignLineWhenAbsorb([v, h]) {
|
|
896
|
+
if (v) {
|
|
897
|
+
if (this.drawedLines[0] && this.drawedLines[0].do) {
|
|
898
|
+
const draggingBBoxDrawEndPoint = this.getDraggingBBoxPointByLinePosition(this.drawedLines[0].dl.lp);
|
|
899
|
+
const vdl = {
|
|
900
|
+
line: [
|
|
901
|
+
this.drawedLines[0].dl.line[0],
|
|
902
|
+
{
|
|
903
|
+
x: this.drawedLines[0].dl.line[0].x,
|
|
904
|
+
y: draggingBBoxDrawEndPoint.y,
|
|
905
|
+
},
|
|
906
|
+
],
|
|
907
|
+
lp: this.drawedLines[0].dl.lp,
|
|
908
|
+
};
|
|
909
|
+
this.removeAlignLineByID(this.drawedLines[0].do.id);
|
|
910
|
+
this.drawAlignLines({ vdl: vdl, hdl: undefined });
|
|
911
|
+
this.isAdsorbed[0] = true;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
if (h) {
|
|
915
|
+
if (this.drawedLines[1] && this.drawedLines[1].do) {
|
|
916
|
+
const draggingBBoxDrawEndPoint = this.getDraggingBBoxPointByLinePosition(this.drawedLines[1].dl.lp);
|
|
917
|
+
const hdl = {
|
|
918
|
+
line: [
|
|
919
|
+
this.drawedLines[1].dl.line[0],
|
|
920
|
+
{
|
|
921
|
+
x: draggingBBoxDrawEndPoint.x,
|
|
922
|
+
y: this.drawedLines[1].dl.line[0].y,
|
|
923
|
+
},
|
|
924
|
+
],
|
|
925
|
+
lp: this.drawedLines[1].dl.lp,
|
|
926
|
+
};
|
|
927
|
+
this.removeAlignLineByID(this.drawedLines[1].do.id);
|
|
928
|
+
this.drawAlignLines({ vdl: undefined, hdl: hdl });
|
|
929
|
+
this.isAdsorbed[1] = true;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* check whether can draw lines
|
|
935
|
+
*/
|
|
936
|
+
canDrawLine() {
|
|
937
|
+
const { v, h } = this.chooseAlignLine();
|
|
938
|
+
if (!v && !h) {
|
|
939
|
+
return false;
|
|
940
|
+
}
|
|
941
|
+
return { vdl: v, hdl: h };
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* detect whether adsorption can be cancelled
|
|
945
|
+
* two directions:v h
|
|
946
|
+
* @return first: v direction ; second:h direction; undefine means no-adsorb
|
|
947
|
+
*/
|
|
948
|
+
canCancelAbsorb() {
|
|
949
|
+
// eslint-disable-next-line prefer-const
|
|
950
|
+
let ret = [
|
|
951
|
+
undefined,
|
|
952
|
+
undefined,
|
|
953
|
+
];
|
|
954
|
+
const vdl = this.drawedLines[0].dl;
|
|
955
|
+
const hdl = this.drawedLines[1].dl;
|
|
956
|
+
const offset = this.getPointerOffsetWithItem({
|
|
957
|
+
x: this.dragEvent.canvas.x,
|
|
958
|
+
y: this.dragEvent.canvas.y,
|
|
959
|
+
});
|
|
960
|
+
if (vdl) {
|
|
961
|
+
if (Math.abs(offset.x) > this.tolerance * this.toleranceFactor) {
|
|
962
|
+
ret[0] = true;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
if (hdl) {
|
|
966
|
+
if (Math.abs(offset.y) > this.tolerance * this.toleranceFactor) {
|
|
967
|
+
ret[1] = true;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
return ret;
|
|
971
|
+
}
|
|
972
|
+
//#endregion
|
|
973
|
+
/**
|
|
974
|
+
* absorb the dragging box
|
|
975
|
+
*/
|
|
976
|
+
absorb(dls) {
|
|
977
|
+
if (dls.vdl) {
|
|
978
|
+
this.isAdsorbed[0] = true;
|
|
979
|
+
this.historyAbsorbArea[0] = [
|
|
980
|
+
dls.vdl.line[0].x - this.tolerance * this.toleranceFactor,
|
|
981
|
+
dls.vdl.line[0].x + this.tolerance * this.toleranceFactor,
|
|
982
|
+
];
|
|
983
|
+
this.updateDraggingItemPosition(this.drawedLines[0].dl);
|
|
984
|
+
}
|
|
985
|
+
if (dls.hdl) {
|
|
986
|
+
this.isAdsorbed[1] = true;
|
|
987
|
+
this.historyAbsorbArea[1] = [
|
|
988
|
+
dls.hdl.line[0].y - this.tolerance * this.toleranceFactor,
|
|
989
|
+
dls.hdl.line[0].y + this.tolerance * this.toleranceFactor,
|
|
990
|
+
];
|
|
991
|
+
this.updateDraggingItemPosition(this.drawedLines[1].dl);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* If there is dl(draw line), then absorb to dl;
|
|
996
|
+
* don't pass dl, means cancel absorb
|
|
997
|
+
* @param dl drawline [point, point]
|
|
998
|
+
*/
|
|
999
|
+
updateDraggingItemPosition(dl, shouldChange) {
|
|
1000
|
+
// Determine if historyPoints do not exist do not continue
|
|
1001
|
+
if (!this.historyPoints[0] && !this.historyPoints[1]) {
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
// absorb effect
|
|
1005
|
+
if (dl) {
|
|
1006
|
+
// calculate the diff and absorb
|
|
1007
|
+
if (dl.lp === 'left') {
|
|
1008
|
+
const tmpX = dl.line[0].x + this.draggingBBox.halfExtents[0];
|
|
1009
|
+
this.doUpdatePosition({ fx: tmpX });
|
|
1010
|
+
}
|
|
1011
|
+
if (dl.lp === 'vcenter') {
|
|
1012
|
+
this.doUpdatePosition({
|
|
1013
|
+
fx: dl.line[0].x,
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
if (dl.lp === 'right') {
|
|
1017
|
+
this.doUpdatePosition({
|
|
1018
|
+
fx: dl.line[0].x - this.draggingBBox.halfExtents[0],
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
if (dl.lp === 'top') {
|
|
1022
|
+
this.doUpdatePosition({
|
|
1023
|
+
fy: dl.line[0].y + this.draggingBBox.halfExtents[1],
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
if (dl.lp === 'hcenter') {
|
|
1027
|
+
this.doUpdatePosition({
|
|
1028
|
+
fy: dl.line[0].y,
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
if (dl.lp === 'bottom') {
|
|
1032
|
+
this.doUpdatePosition({
|
|
1033
|
+
fy: dl.line[0].y - this.draggingBBox.halfExtents[1],
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
if (shouldChange) {
|
|
1038
|
+
if (shouldChange.x) {
|
|
1039
|
+
const changeX = this.draggingBBox.center[0] + shouldChange.x;
|
|
1040
|
+
this.doUpdatePosition({
|
|
1041
|
+
x: changeX,
|
|
1042
|
+
fx: undefined,
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
if (shouldChange.y) {
|
|
1046
|
+
const changeY = this.draggingBBox.center[1] + shouldChange.y;
|
|
1047
|
+
this.doUpdatePosition({
|
|
1048
|
+
y: changeY,
|
|
1049
|
+
fy: undefined,
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
doUpdatePosition(data) {
|
|
1055
|
+
const cache = this.updateCache.get(this.dragItemId);
|
|
1056
|
+
this.updateCache.set(this.dragItemId, {
|
|
1057
|
+
id: this.dragItemId,
|
|
1058
|
+
data: Object.assign(Object.assign({}, cache === null || cache === void 0 ? void 0 : cache.data), data),
|
|
1059
|
+
});
|
|
1060
|
+
this.throttleUpdate();
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
//# sourceMappingURL=index.js.map
|