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