@logicflow/core 2.2.0 → 2.2.1
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/index.css +3 -2
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/LogicFlow.d.ts +9 -0
- package/es/LogicFlow.js +0 -1
- package/es/constant/index.d.ts +1 -1
- package/es/constant/index.js +1 -1
- package/es/constant/theme.d.ts +136 -0
- package/es/constant/theme.js +680 -0
- package/es/index.css +3 -2
- package/es/model/GraphModel.d.ts +10 -2
- package/es/model/GraphModel.js +48 -14
- package/es/model/TransformModel.js +9 -9
- package/es/model/edge/BaseEdgeModel.js +7 -2
- package/es/model/edge/PolylineEdgeModel.d.ts +7 -0
- package/es/model/edge/PolylineEdgeModel.js +136 -7
- package/es/model/node/BaseNodeModel.d.ts +12 -1
- package/es/model/node/BaseNodeModel.js +9 -2
- package/es/model/node/HtmlNodeModel.d.ts +12 -0
- package/es/model/node/HtmlNodeModel.js +19 -0
- package/es/model/node/PolygonNodeModel.js +3 -3
- package/es/options.d.ts +4 -2
- package/es/style/index.css +3 -2
- package/es/style/index.less +3 -2
- package/es/style/raw.d.ts +1 -1
- package/es/style/raw.js +1 -1
- package/es/tool/MultipleSelectTool.js +10 -5
- package/es/util/drag.js +0 -1
- package/es/util/edge.d.ts +40 -1
- package/es/util/edge.js +43 -9
- package/es/util/geometry.d.ts +8 -0
- package/es/util/geometry.js +79 -0
- package/es/util/theme.d.ts +2 -65
- package/es/util/theme.js +4 -281
- package/es/view/Anchor.d.ts +1 -0
- package/es/view/Anchor.js +24 -21
- package/es/view/Control.d.ts +5 -0
- package/es/view/Control.js +44 -57
- package/es/view/edge/BaseEdge.js +9 -0
- package/es/view/edge/PolylineEdge.js +13 -2
- package/es/view/node/BaseNode.d.ts +1 -0
- package/es/view/node/BaseNode.js +23 -11
- package/es/view/node/HtmlNode.js +2 -4
- package/es/view/overlay/CanvasOverlay.js +5 -2
- package/es/view/overlay/Grid.d.ts +12 -1
- package/es/view/overlay/Grid.js +85 -23
- package/es/view/overlay/OutlineOverlay.d.ts +1 -0
- package/es/view/overlay/OutlineOverlay.js +18 -17
- package/es/view/overlay/gridConfig.d.ts +46 -0
- package/es/view/overlay/gridConfig.js +99 -0
- package/es/view/shape/Polygon.d.ts +0 -7
- package/es/view/shape/Polygon.js +12 -43
- package/lib/LogicFlow.d.ts +9 -0
- package/lib/LogicFlow.js +0 -1
- package/lib/constant/index.d.ts +1 -1
- package/lib/constant/index.js +16 -2
- package/lib/constant/theme.d.ts +136 -0
- package/lib/constant/theme.js +683 -0
- package/lib/index.css +3 -2
- package/lib/model/GraphModel.d.ts +10 -2
- package/lib/model/GraphModel.js +49 -15
- package/lib/model/TransformModel.js +9 -9
- package/lib/model/edge/BaseEdgeModel.js +7 -2
- package/lib/model/edge/PolylineEdgeModel.d.ts +7 -0
- package/lib/model/edge/PolylineEdgeModel.js +136 -7
- package/lib/model/node/BaseNodeModel.d.ts +12 -1
- package/lib/model/node/BaseNodeModel.js +9 -2
- package/lib/model/node/HtmlNodeModel.d.ts +12 -0
- package/lib/model/node/HtmlNodeModel.js +19 -0
- package/lib/model/node/PolygonNodeModel.js +3 -3
- package/lib/options.d.ts +4 -2
- package/lib/style/index.css +3 -2
- package/lib/style/index.less +3 -2
- package/lib/style/raw.d.ts +1 -1
- package/lib/style/raw.js +1 -1
- package/lib/tool/MultipleSelectTool.js +10 -5
- package/lib/util/drag.js +0 -1
- package/lib/util/edge.d.ts +40 -1
- package/lib/util/edge.js +43 -9
- package/lib/util/geometry.d.ts +8 -0
- package/lib/util/geometry.js +81 -1
- package/lib/util/theme.d.ts +2 -65
- package/lib/util/theme.js +15 -292
- package/lib/view/Anchor.d.ts +1 -0
- package/lib/view/Anchor.js +24 -21
- package/lib/view/Control.d.ts +5 -0
- package/lib/view/Control.js +44 -57
- package/lib/view/edge/BaseEdge.js +9 -0
- package/lib/view/edge/PolylineEdge.js +13 -2
- package/lib/view/node/BaseNode.d.ts +1 -0
- package/lib/view/node/BaseNode.js +22 -10
- package/lib/view/node/HtmlNode.js +1 -3
- package/lib/view/overlay/CanvasOverlay.js +5 -2
- package/lib/view/overlay/Grid.d.ts +12 -1
- package/lib/view/overlay/Grid.js +83 -21
- package/lib/view/overlay/OutlineOverlay.d.ts +1 -0
- package/lib/view/overlay/OutlineOverlay.js +18 -17
- package/lib/view/overlay/gridConfig.d.ts +46 -0
- package/lib/view/overlay/gridConfig.js +104 -0
- package/lib/view/shape/Polygon.d.ts +0 -7
- package/lib/view/shape/Polygon.js +13 -45
- package/package.json +6 -1
- package/.turbo/turbo-build$colon$dev.log +0 -10
- package/.turbo/turbo-build.log +0 -33
- package/CHANGELOG.md +0 -1849
- package/__tests__/algorithm/egde.test.ts +0 -131
- package/__tests__/algorithm/index.test.ts +0 -74
- package/__tests__/algorithm/outline.test.ts +0 -43
- package/__tests__/bugs/1545-spec.test.ts +0 -42
- package/__tests__/event/event.test.ts +0 -22
- package/__tests__/history/history.test.ts +0 -28
- package/__tests__/logicflow.test.ts +0 -575
- package/__tests__/model/graphmodel.test.ts +0 -87
- package/__tests__/util/compatible.test.ts +0 -48
- package/__tests__/util/edge.test.ts +0 -224
- package/__tests__/util/geometry.test.ts +0 -14
- package/__tests__/util/graph.test.ts +0 -16
- package/__tests__/util/matrix.test.ts +0 -41
- package/__tests__/util/node.test.ts +0 -68
- package/__tests__/util/sampling.test.ts +0 -12
- package/__tests__/util/vector.test.ts +0 -50
- package/__tests__/util/zIndex.test.ts +0 -10
- package/src/LogicFlow.tsx +0 -2008
- package/src/algorithm/edge.ts +0 -67
- package/src/algorithm/index.ts +0 -70
- package/src/algorithm/outline.ts +0 -77
- package/src/algorithm/rotate.ts +0 -55
- package/src/common/drag.ts +0 -219
- package/src/common/history.ts +0 -108
- package/src/common/index.ts +0 -6
- package/src/common/keyboard.ts +0 -108
- package/src/common/matrix.ts +0 -122
- package/src/common/vector.ts +0 -93
- package/src/constant/index.ts +0 -179
- package/src/event/event.md +0 -66
- package/src/event/eventArgs.ts +0 -643
- package/src/event/eventEmitter.ts +0 -156
- package/src/history/index.ts +0 -119
- package/src/index.less +0 -1
- package/src/index.ts +0 -26
- package/src/keyboard/index.ts +0 -112
- package/src/keyboard/shortcut.ts +0 -200
- package/src/model/BaseModel.ts +0 -250
- package/src/model/EditConfigModel.ts +0 -334
- package/src/model/GraphModel.ts +0 -1788
- package/src/model/NestedTransformModel.ts +0 -121
- package/src/model/SnaplineModel.ts +0 -256
- package/src/model/TransformModel.ts +0 -258
- package/src/model/edge/BaseEdgeModel.ts +0 -777
- package/src/model/edge/BezierEdgeModel.ts +0 -197
- package/src/model/edge/LineEdgeModel.ts +0 -36
- package/src/model/edge/PolylineEdgeModel.ts +0 -672
- package/src/model/edge/index.ts +0 -4
- package/src/model/index.ts +0 -9
- package/src/model/node/BaseNodeModel.ts +0 -949
- package/src/model/node/CircleNodeModel.ts +0 -91
- package/src/model/node/DiamondNodeModel.ts +0 -132
- package/src/model/node/EllipseNodeModel.ts +0 -98
- package/src/model/node/HtmlNodeModel.ts +0 -50
- package/src/model/node/PolygonNodeModel.ts +0 -150
- package/src/model/node/RectNodeModel.ts +0 -69
- package/src/model/node/TextNodeModel.ts +0 -54
- package/src/model/node/index.ts +0 -8
- package/src/options.ts +0 -145
- package/src/style/index.less +0 -261
- package/src/style/raw.ts +0 -220
- package/src/tool/MultipleSelectTool.tsx +0 -132
- package/src/tool/TextEditTool.tsx +0 -193
- package/src/tool/index.ts +0 -101
- package/src/typings.d.ts +0 -5
- package/src/util/animation.ts +0 -29
- package/src/util/browser.ts +0 -4
- package/src/util/compatible.ts +0 -15
- package/src/util/drag.ts +0 -220
- package/src/util/edge.ts +0 -1060
- package/src/util/geometry.ts +0 -55
- package/src/util/graph.ts +0 -46
- package/src/util/index.ts +0 -17
- package/src/util/matrix.ts +0 -129
- package/src/util/mobx.ts +0 -23
- package/src/util/node.ts +0 -543
- package/src/util/raf.ts +0 -28
- package/src/util/resize.ts +0 -606
- package/src/util/sampling.ts +0 -85
- package/src/util/theme.ts +0 -375
- package/src/util/uuid.ts +0 -26
- package/src/util/vector.ts +0 -93
- package/src/util/zIndex.ts +0 -6
- package/src/view/Anchor.tsx +0 -445
- package/src/view/Control.tsx +0 -512
- package/src/view/Graph.tsx +0 -141
- package/src/view/Rotate.tsx +0 -113
- package/src/view/behavior/dnd.ts +0 -162
- package/src/view/behavior/index.ts +0 -2
- package/src/view/behavior/snapline.ts +0 -16
- package/src/view/edge/AdjustPoint.tsx +0 -425
- package/src/view/edge/Arrow.tsx +0 -54
- package/src/view/edge/BaseEdge.tsx +0 -650
- package/src/view/edge/BezierEdge.tsx +0 -101
- package/src/view/edge/LineEdge.tsx +0 -81
- package/src/view/edge/PolylineEdge.tsx +0 -299
- package/src/view/edge/index.ts +0 -6
- package/src/view/index.ts +0 -8
- package/src/view/node/BaseNode.tsx +0 -571
- package/src/view/node/CircleNode.tsx +0 -21
- package/src/view/node/DiamondNode.tsx +0 -24
- package/src/view/node/EllipseNode.tsx +0 -22
- package/src/view/node/HtmlNode.tsx +0 -95
- package/src/view/node/PolygonNode.tsx +0 -28
- package/src/view/node/RectNode.tsx +0 -30
- package/src/view/node/TextNode.tsx +0 -39
- package/src/view/node/index.ts +0 -8
- package/src/view/overlay/BackgroundOverlay.tsx +0 -34
- package/src/view/overlay/BezierAdjustOverlay.tsx +0 -150
- package/src/view/overlay/CanvasOverlay.tsx +0 -288
- package/src/view/overlay/Grid.tsx +0 -162
- package/src/view/overlay/ModificationOverlay.tsx +0 -31
- package/src/view/overlay/OutlineOverlay.tsx +0 -170
- package/src/view/overlay/SnaplineOverlay.tsx +0 -44
- package/src/view/overlay/ToolOverlay.tsx +0 -65
- package/src/view/overlay/getTransformHoc.tsx +0 -50
- package/src/view/overlay/index.ts +0 -8
- package/src/view/shape/Circle.tsx +0 -41
- package/src/view/shape/Ellipse.tsx +0 -42
- package/src/view/shape/Line.tsx +0 -39
- package/src/view/shape/Path.tsx +0 -22
- package/src/view/shape/Polygon.tsx +0 -91
- package/src/view/shape/Polyline.tsx +0 -31
- package/src/view/shape/Rect.tsx +0 -44
- package/src/view/shape/Text.tsx +0 -169
- package/src/view/shape/index.ts +0 -8
- package/src/view/text/BaseText.tsx +0 -134
- package/src/view/text/LineText.tsx +0 -168
- package/src/view/text/index.ts +0 -2
- package/stats.html +0 -4842
- package/tsconfig.json +0 -18
|
@@ -1,672 +0,0 @@
|
|
|
1
|
-
import { get, assign, cloneDeep } from 'lodash-es'
|
|
2
|
-
import { observable, action } from 'mobx'
|
|
3
|
-
import { BaseEdgeModel } from '.'
|
|
4
|
-
import { BaseNodeModel, RectNodeModel, CircleNodeModel, Model } from '..'
|
|
5
|
-
import LogicFlow from '../../LogicFlow'
|
|
6
|
-
import { ModelType, SegmentDirection } from '../../constant'
|
|
7
|
-
import {
|
|
8
|
-
isInNode,
|
|
9
|
-
distance,
|
|
10
|
-
getClosestRadiusCenter,
|
|
11
|
-
inStraightLineOfRect,
|
|
12
|
-
getCrossPointWithCircle,
|
|
13
|
-
getCrossPointWithEllipse,
|
|
14
|
-
getCrossPointWithPolygon,
|
|
15
|
-
getPolylinePoints,
|
|
16
|
-
getLongestEdge,
|
|
17
|
-
getCrossPointInRect,
|
|
18
|
-
isSegmentsInNode,
|
|
19
|
-
isSegmentsCrossNode,
|
|
20
|
-
segmentDirection,
|
|
21
|
-
points2PointsList,
|
|
22
|
-
pointFilter,
|
|
23
|
-
} from '../../util'
|
|
24
|
-
|
|
25
|
-
import Point = LogicFlow.Point
|
|
26
|
-
import Position = LogicFlow.Position
|
|
27
|
-
import AppendConfig = LogicFlow.AppendConfig
|
|
28
|
-
import AnchorConfig = Model.AnchorConfig
|
|
29
|
-
|
|
30
|
-
export class PolylineEdgeModel extends BaseEdgeModel {
|
|
31
|
-
modelType = ModelType.POLYLINE_EDGE
|
|
32
|
-
draggingPointList: Point[] = []
|
|
33
|
-
@observable offset?: number
|
|
34
|
-
@observable dbClickPosition?: Point
|
|
35
|
-
|
|
36
|
-
initEdgeData(data: LogicFlow.EdgeConfig): void {
|
|
37
|
-
this.offset = get(data, 'properties.offset', 30)
|
|
38
|
-
if (data.pointsList) {
|
|
39
|
-
this.pointsList = data.pointsList
|
|
40
|
-
}
|
|
41
|
-
super.initEdgeData(data)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getEdgeStyle() {
|
|
45
|
-
const { polyline } = this.graphModel.theme
|
|
46
|
-
const style = super.getEdgeStyle()
|
|
47
|
-
const { style: customStyle = {} } = this.properties
|
|
48
|
-
return {
|
|
49
|
-
...style,
|
|
50
|
-
...cloneDeep(polyline),
|
|
51
|
-
...cloneDeep(customStyle),
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
getTextPosition() {
|
|
56
|
-
// 在文本为空的情况下,文本位置为双击位置
|
|
57
|
-
const textValue = this.text?.value
|
|
58
|
-
if (this.dbClickPosition && !textValue) {
|
|
59
|
-
const { x, y } = this.dbClickPosition
|
|
60
|
-
return { x, y }
|
|
61
|
-
}
|
|
62
|
-
// 文本不为空或者没有双击位置时,取最长边的中点作为文本位置
|
|
63
|
-
const currentPositionList = points2PointsList(this.points)
|
|
64
|
-
const [p1, p2] = getLongestEdge(currentPositionList)
|
|
65
|
-
return {
|
|
66
|
-
x: (p1.x + p2.x) / 2,
|
|
67
|
-
y: (p1.y + p2.y) / 2,
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 获取下一个锚点
|
|
72
|
-
getAfterAnchor(
|
|
73
|
-
direction: SegmentDirection,
|
|
74
|
-
position: Position,
|
|
75
|
-
anchorList: AnchorConfig[],
|
|
76
|
-
) {
|
|
77
|
-
let anchor: AnchorConfig
|
|
78
|
-
let minDistance: number
|
|
79
|
-
anchorList.forEach((item) => {
|
|
80
|
-
let distanceX: number
|
|
81
|
-
if (direction === SegmentDirection.HORIZONTAL) {
|
|
82
|
-
distanceX = Math.abs(position.y - item.y)
|
|
83
|
-
} else if (direction === SegmentDirection.VERTICAL) {
|
|
84
|
-
distanceX = Math.abs(position.x - item.x)
|
|
85
|
-
}
|
|
86
|
-
if (!minDistance || minDistance > distanceX!) {
|
|
87
|
-
minDistance = distanceX!
|
|
88
|
-
anchor = item
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
|
-
return anchor!
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/* 获取拖拽过程中产生的交点 */
|
|
95
|
-
getCrossPoint(direction: SegmentDirection, start: Position, end: Position) {
|
|
96
|
-
let position: Point
|
|
97
|
-
if (direction === SegmentDirection.HORIZONTAL) {
|
|
98
|
-
position = {
|
|
99
|
-
x: end.x,
|
|
100
|
-
y: start.y,
|
|
101
|
-
}
|
|
102
|
-
} else if (direction === SegmentDirection.VERTICAL) {
|
|
103
|
-
position = {
|
|
104
|
-
x: start.x,
|
|
105
|
-
y: end.y,
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return position!
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// 删除在图形内的过个交点
|
|
112
|
-
removeCrossPoints(startIndex: number, endIndex: number, pointList: Point[]) {
|
|
113
|
-
const list = pointList.map((i) => i)
|
|
114
|
-
if (startIndex === 1) {
|
|
115
|
-
const start = list[startIndex]
|
|
116
|
-
const end = list[endIndex]
|
|
117
|
-
const pre = list[startIndex - 1]
|
|
118
|
-
const isInStartNode = isSegmentsInNode(pre, start, this.sourceNode)
|
|
119
|
-
if (isInStartNode) {
|
|
120
|
-
const isSegmentsCrossStartNode = isSegmentsCrossNode(
|
|
121
|
-
start,
|
|
122
|
-
end,
|
|
123
|
-
this.sourceNode,
|
|
124
|
-
)
|
|
125
|
-
if (isSegmentsCrossStartNode) {
|
|
126
|
-
const point = getCrossPointInRect(start, end, this.sourceNode)
|
|
127
|
-
if (point) {
|
|
128
|
-
list[startIndex] = point
|
|
129
|
-
list.splice(startIndex - 1, 1)
|
|
130
|
-
startIndex--
|
|
131
|
-
endIndex--
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
const anchorList = this.sourceNode.anchors
|
|
136
|
-
anchorList.forEach((item) => {
|
|
137
|
-
if (
|
|
138
|
-
(item.x === pre.x && item.x === start.x) ||
|
|
139
|
-
(item.y === pre.y && item.y === start.y)
|
|
140
|
-
) {
|
|
141
|
-
const distance1 = distance(item.x, item.y, start.x, start.y)
|
|
142
|
-
const distance2 = distance(pre.x, pre.y, start.x, start.y)
|
|
143
|
-
if (distance1 < distance2) {
|
|
144
|
-
list[startIndex - 1] = item
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (endIndex === pointList.length - 2) {
|
|
151
|
-
const start = list[startIndex]
|
|
152
|
-
const end = list[endIndex]
|
|
153
|
-
const next = list[endIndex + 1]
|
|
154
|
-
const isInEndNode = isSegmentsInNode(end, next, this.targetNode)
|
|
155
|
-
if (isInEndNode) {
|
|
156
|
-
const isSegmentsCrossStartNode = isSegmentsCrossNode(
|
|
157
|
-
start,
|
|
158
|
-
end,
|
|
159
|
-
this.targetNode,
|
|
160
|
-
)
|
|
161
|
-
if (isSegmentsCrossStartNode) {
|
|
162
|
-
const point = getCrossPointInRect(start, end, this.targetNode)
|
|
163
|
-
if (point) {
|
|
164
|
-
list[endIndex] = point
|
|
165
|
-
list.splice(endIndex + 1, 1)
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
} else {
|
|
169
|
-
const anchorList = this.targetNode.anchors
|
|
170
|
-
anchorList.forEach((item) => {
|
|
171
|
-
if (
|
|
172
|
-
(item.x === next.x && item.x === end.x) ||
|
|
173
|
-
(item.y === next.y && item.y === end.y)
|
|
174
|
-
) {
|
|
175
|
-
const distance1 = distance(item.x, item.y, end.x, end.y)
|
|
176
|
-
const distance2 = distance(next.x, next.y, end.x, end.y)
|
|
177
|
-
if (distance1 < distance2) {
|
|
178
|
-
list[endIndex + 1] = item
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return list
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// 获取在拖拽过程中可能产生的点
|
|
188
|
-
getDraggingPoints(
|
|
189
|
-
direction: SegmentDirection,
|
|
190
|
-
positionType: string,
|
|
191
|
-
position: Position,
|
|
192
|
-
anchorList: AnchorConfig[],
|
|
193
|
-
draggingPointList: Point[],
|
|
194
|
-
) {
|
|
195
|
-
const pointList = draggingPointList.map((i) => i)
|
|
196
|
-
const anchor = this.getAfterAnchor(direction, position, anchorList)
|
|
197
|
-
const crossPoint = this.getCrossPoint(direction, position, anchor)
|
|
198
|
-
if (positionType === 'start') {
|
|
199
|
-
pointList.unshift(crossPoint)
|
|
200
|
-
pointList.unshift(anchor)
|
|
201
|
-
} else {
|
|
202
|
-
pointList.push(crossPoint)
|
|
203
|
-
pointList.push(anchor)
|
|
204
|
-
}
|
|
205
|
-
return pointList
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// 更新相交点[起点,终点],更加贴近图形, 未修改observable不作为action
|
|
209
|
-
updateCrossPoints(pointList: Point[]) {
|
|
210
|
-
const list = pointList.map((i) => i)
|
|
211
|
-
const start = pointList[0]
|
|
212
|
-
const next = pointList[1]
|
|
213
|
-
const pre = pointList[list.length - 2]
|
|
214
|
-
const end = pointList[list.length - 1]
|
|
215
|
-
const { sourceNode, targetNode } = this
|
|
216
|
-
const sourceModelType = sourceNode.modelType
|
|
217
|
-
const targetModelType = targetNode.modelType
|
|
218
|
-
const startPointDirection = segmentDirection(start, next)!
|
|
219
|
-
let startCrossPoint = list[0]
|
|
220
|
-
switch (sourceModelType) {
|
|
221
|
-
case ModelType.RECT_NODE:
|
|
222
|
-
if ((sourceNode as RectNodeModel).radius !== 0) {
|
|
223
|
-
const inInnerNode = inStraightLineOfRect(start, sourceNode)
|
|
224
|
-
if (!inInnerNode) {
|
|
225
|
-
startCrossPoint = getClosestRadiusCenter(
|
|
226
|
-
start,
|
|
227
|
-
startPointDirection,
|
|
228
|
-
sourceNode,
|
|
229
|
-
)
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
break
|
|
233
|
-
case ModelType.CIRCLE_NODE:
|
|
234
|
-
startCrossPoint = getCrossPointWithCircle(
|
|
235
|
-
start,
|
|
236
|
-
startPointDirection,
|
|
237
|
-
sourceNode as CircleNodeModel,
|
|
238
|
-
)
|
|
239
|
-
break
|
|
240
|
-
case ModelType.ELLIPSE_NODE:
|
|
241
|
-
startCrossPoint = getCrossPointWithEllipse(
|
|
242
|
-
start,
|
|
243
|
-
startPointDirection,
|
|
244
|
-
sourceNode,
|
|
245
|
-
)
|
|
246
|
-
break
|
|
247
|
-
case ModelType.DIAMOND_NODE:
|
|
248
|
-
startCrossPoint = getCrossPointWithPolygon(
|
|
249
|
-
start,
|
|
250
|
-
startPointDirection,
|
|
251
|
-
sourceNode,
|
|
252
|
-
)
|
|
253
|
-
break
|
|
254
|
-
case ModelType.POLYGON_NODE:
|
|
255
|
-
startCrossPoint = getCrossPointWithPolygon(
|
|
256
|
-
start,
|
|
257
|
-
startPointDirection,
|
|
258
|
-
sourceNode,
|
|
259
|
-
)
|
|
260
|
-
break
|
|
261
|
-
default:
|
|
262
|
-
break
|
|
263
|
-
}
|
|
264
|
-
// 如果线段和形状没有交点时startCrossPoint会为undefined导致后续计算报错
|
|
265
|
-
if (startCrossPoint) {
|
|
266
|
-
list[0] = startCrossPoint
|
|
267
|
-
}
|
|
268
|
-
const endPointDirection = segmentDirection(pre, end)!
|
|
269
|
-
let endCrossPoint = list[list.length - 1]
|
|
270
|
-
switch (targetModelType) {
|
|
271
|
-
case ModelType.RECT_NODE:
|
|
272
|
-
if ((targetNode as RectNodeModel).radius !== 0) {
|
|
273
|
-
const inInnerNode = inStraightLineOfRect(end, targetNode)
|
|
274
|
-
if (!inInnerNode) {
|
|
275
|
-
endCrossPoint = getClosestRadiusCenter(
|
|
276
|
-
end,
|
|
277
|
-
endPointDirection,
|
|
278
|
-
targetNode,
|
|
279
|
-
)
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
break
|
|
283
|
-
case ModelType.CIRCLE_NODE:
|
|
284
|
-
endCrossPoint = getCrossPointWithCircle(
|
|
285
|
-
end,
|
|
286
|
-
endPointDirection,
|
|
287
|
-
targetNode as CircleNodeModel,
|
|
288
|
-
)
|
|
289
|
-
break
|
|
290
|
-
case ModelType.ELLIPSE_NODE:
|
|
291
|
-
endCrossPoint = getCrossPointWithEllipse(
|
|
292
|
-
end,
|
|
293
|
-
endPointDirection,
|
|
294
|
-
targetNode,
|
|
295
|
-
)
|
|
296
|
-
break
|
|
297
|
-
case ModelType.DIAMOND_NODE:
|
|
298
|
-
endCrossPoint = getCrossPointWithPolygon(
|
|
299
|
-
end,
|
|
300
|
-
endPointDirection,
|
|
301
|
-
targetNode,
|
|
302
|
-
)
|
|
303
|
-
break
|
|
304
|
-
case ModelType.POLYGON_NODE:
|
|
305
|
-
endCrossPoint = getCrossPointWithPolygon(
|
|
306
|
-
end,
|
|
307
|
-
endPointDirection,
|
|
308
|
-
targetNode,
|
|
309
|
-
)
|
|
310
|
-
break
|
|
311
|
-
default:
|
|
312
|
-
break
|
|
313
|
-
}
|
|
314
|
-
// 如果线段和形状没有交点时startCrossPoint会为undefined导致后续计算报错
|
|
315
|
-
if (endCrossPoint) {
|
|
316
|
-
list[list.length - 1] = endCrossPoint
|
|
317
|
-
}
|
|
318
|
-
return list
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
updatePath(pointList: Point[]) {
|
|
322
|
-
this.pointsList = pointList
|
|
323
|
-
this.points = this.getPath(this.pointsList)
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
getData() {
|
|
327
|
-
const data = super.getData()
|
|
328
|
-
const pointsList = this.pointsList.map(({ x, y }) => ({
|
|
329
|
-
x,
|
|
330
|
-
y,
|
|
331
|
-
}))
|
|
332
|
-
return Object.assign({}, data, {
|
|
333
|
-
pointsList,
|
|
334
|
-
})
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
getPath(points: Point[]): string {
|
|
338
|
-
return points.map((point) => `${point.x},${point.y}`).join(' ')
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
@action
|
|
342
|
-
initPoints() {
|
|
343
|
-
if (this.pointsList.length > 0) {
|
|
344
|
-
this.points = this.getPath(this.pointsList)
|
|
345
|
-
} else {
|
|
346
|
-
this.updatePoints()
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
@action
|
|
351
|
-
updatePoints() {
|
|
352
|
-
const pointsList = getPolylinePoints(
|
|
353
|
-
{
|
|
354
|
-
x: this.startPoint.x,
|
|
355
|
-
y: this.startPoint.y,
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
x: this.endPoint.x,
|
|
359
|
-
y: this.endPoint.y,
|
|
360
|
-
},
|
|
361
|
-
this.sourceNode,
|
|
362
|
-
this.targetNode,
|
|
363
|
-
this.offset || 0,
|
|
364
|
-
)
|
|
365
|
-
this.pointsList = pointsList
|
|
366
|
-
this.points = pointsList.map((point) => `${point.x},${point.y}`).join(' ')
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
@action
|
|
370
|
-
updateStartPoint(anchor: Point) {
|
|
371
|
-
this.startPoint = Object.assign({}, anchor)
|
|
372
|
-
this.updatePoints()
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
@action
|
|
376
|
-
moveStartPoint(deltaX: number, deltaY: number): void {
|
|
377
|
-
this.startPoint.x += deltaX
|
|
378
|
-
this.startPoint.y += deltaY
|
|
379
|
-
this.updatePoints()
|
|
380
|
-
// todo: 尽量保持边的整体轮廓, 通过deltaX和deltaY更新pointsList,而不是重新计算。
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
@action
|
|
384
|
-
updateEndPoint(anchor: Point) {
|
|
385
|
-
this.endPoint = Object.assign({}, anchor)
|
|
386
|
-
this.updatePoints()
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
@action
|
|
390
|
-
moveEndPoint(deltaX: number, deltaY: number): void {
|
|
391
|
-
this.endPoint.x += deltaX
|
|
392
|
-
this.endPoint.y += deltaY
|
|
393
|
-
this.updatePoints()
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
@action
|
|
397
|
-
updatePointsList(deltaX: number, deltaY: number): void {
|
|
398
|
-
this.pointsList.forEach((item) => {
|
|
399
|
-
item.x += deltaX
|
|
400
|
-
item.y += deltaY
|
|
401
|
-
})
|
|
402
|
-
const startPoint = this.pointsList[0]
|
|
403
|
-
this.startPoint = Object.assign({}, startPoint)
|
|
404
|
-
const endPoint = this.pointsList[this.pointsList.length - 1]
|
|
405
|
-
this.endPoint = Object.assign({}, endPoint)
|
|
406
|
-
this.initPoints()
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
@action
|
|
410
|
-
dragAppendStart() {
|
|
411
|
-
// mobx observer 对象被iterator处理会有问题
|
|
412
|
-
this.draggingPointList = this.pointsList.map((i) => i)
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
@action
|
|
416
|
-
dragAppendSimple(
|
|
417
|
-
appendInfo: AppendConfig,
|
|
418
|
-
dragInfo: Record<'x' | 'y', number>,
|
|
419
|
-
) {
|
|
420
|
-
// 因为drag事件是mouseDown事件触发的,因此当真实拖拽之后再设置isDragging
|
|
421
|
-
// 避免因为点击事件造成,在dragStart触发之后,没有触发dragEnd错误设置了isDragging状态,对history计算造成错误
|
|
422
|
-
this.isDragging = true
|
|
423
|
-
const { start, end, startIndex, endIndex, direction } = appendInfo
|
|
424
|
-
const { pointsList } = this
|
|
425
|
-
let draggingPointList = pointsList
|
|
426
|
-
if (direction === SegmentDirection.HORIZONTAL) {
|
|
427
|
-
// 水平,仅调整y坐标,拿到当前线段两个端点移动后的坐标
|
|
428
|
-
pointsList[startIndex] = {
|
|
429
|
-
x: start.x,
|
|
430
|
-
y: start.y + dragInfo.y,
|
|
431
|
-
}
|
|
432
|
-
pointsList[endIndex] = {
|
|
433
|
-
x: end.x,
|
|
434
|
-
y: end.y + dragInfo.y,
|
|
435
|
-
}
|
|
436
|
-
draggingPointList = this.pointsList.map((i) => i)
|
|
437
|
-
} else if (direction === SegmentDirection.VERTICAL) {
|
|
438
|
-
// 垂直,仅调整x坐标, 与水平调整同理
|
|
439
|
-
pointsList[startIndex] = {
|
|
440
|
-
x: start.x + dragInfo.x,
|
|
441
|
-
y: start.y,
|
|
442
|
-
}
|
|
443
|
-
pointsList[endIndex] = {
|
|
444
|
-
x: end.x + dragInfo.x,
|
|
445
|
-
y: end.y,
|
|
446
|
-
}
|
|
447
|
-
draggingPointList = this.pointsList.map((i) => i)
|
|
448
|
-
}
|
|
449
|
-
this.updatePointsAfterDrag(draggingPointList)
|
|
450
|
-
this.draggingPointList = draggingPointList
|
|
451
|
-
// TODO: 判断该逻辑是否需要
|
|
452
|
-
if (this.text?.value) {
|
|
453
|
-
this.setText(assign({}, this.text, this.textPosition))
|
|
454
|
-
}
|
|
455
|
-
return {
|
|
456
|
-
start: assign({}, pointsList[startIndex]),
|
|
457
|
-
end: assign({}, pointsList[endIndex]),
|
|
458
|
-
startIndex,
|
|
459
|
-
endIndex,
|
|
460
|
-
direction,
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
@action
|
|
465
|
-
dragAppend(appendInfo: AppendConfig, dragInfo: Record<'x' | 'y', number>) {
|
|
466
|
-
this.isDragging = true
|
|
467
|
-
const { start, end, startIndex, endIndex, direction } = appendInfo
|
|
468
|
-
const { pointsList } = this
|
|
469
|
-
if (direction === SegmentDirection.HORIZONTAL) {
|
|
470
|
-
// 水平,仅调整y坐标
|
|
471
|
-
// step1: 拿到当前线段两个端点移动后的坐标
|
|
472
|
-
pointsList[startIndex] = {
|
|
473
|
-
x: start.x,
|
|
474
|
-
y: start.y + dragInfo.y,
|
|
475
|
-
}
|
|
476
|
-
pointsList[endIndex] = {
|
|
477
|
-
x: end.x,
|
|
478
|
-
y: end.y + dragInfo.y,
|
|
479
|
-
}
|
|
480
|
-
// step2: 计算拖拽后,两个端点与节点外框的交点
|
|
481
|
-
// 定义一个拖住中节点list
|
|
482
|
-
let draggingPointList = this.pointsList.map((i) => i)
|
|
483
|
-
if (startIndex !== 0 && endIndex !== this.pointsList.length - 1) {
|
|
484
|
-
// 2.1)如果线段没有连接起终点,过滤会穿插在图形内部的线段,取整个图形离线段最近的点
|
|
485
|
-
draggingPointList = this.removeCrossPoints(
|
|
486
|
-
startIndex,
|
|
487
|
-
endIndex,
|
|
488
|
-
draggingPointList,
|
|
489
|
-
)
|
|
490
|
-
}
|
|
491
|
-
if (startIndex === 0) {
|
|
492
|
-
// 2.2)如果线段连接了起点, 判断起点是否在节点内部
|
|
493
|
-
const startPosition = {
|
|
494
|
-
x: start.x,
|
|
495
|
-
y: start.y + dragInfo.y,
|
|
496
|
-
}
|
|
497
|
-
const inNode = isInNode(startPosition, this.sourceNode)
|
|
498
|
-
if (!inNode) {
|
|
499
|
-
// 如果不在节点内部,更换起点为线段与节点的交点
|
|
500
|
-
const anchorList = this.sourceNode.anchors
|
|
501
|
-
draggingPointList = this.getDraggingPoints(
|
|
502
|
-
direction,
|
|
503
|
-
'start',
|
|
504
|
-
startPosition,
|
|
505
|
-
anchorList,
|
|
506
|
-
draggingPointList,
|
|
507
|
-
)
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
if (endIndex === this.pointsList.length - 1) {
|
|
511
|
-
// 2.2)如果线段连接了终点, 判断起点是否在节点内部
|
|
512
|
-
const endPosition = {
|
|
513
|
-
x: end.x,
|
|
514
|
-
y: end.y + dragInfo.y,
|
|
515
|
-
}
|
|
516
|
-
const inNode = isInNode(endPosition, this.targetNode)
|
|
517
|
-
if (!inNode) {
|
|
518
|
-
// 如果不在节点内部,更换终点为线段与节点的交点
|
|
519
|
-
const anchorList = this.targetNode.anchors
|
|
520
|
-
draggingPointList = this.getDraggingPoints(
|
|
521
|
-
direction,
|
|
522
|
-
'end',
|
|
523
|
-
endPosition,
|
|
524
|
-
anchorList,
|
|
525
|
-
draggingPointList,
|
|
526
|
-
)
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
this.updatePointsAfterDrag(draggingPointList)
|
|
530
|
-
// step3: 调整到对应外框的位置后,执行updatePointsAfterDrag,找到当前线段和图形的准确交点
|
|
531
|
-
this.draggingPointList = draggingPointList
|
|
532
|
-
} else if (direction === SegmentDirection.VERTICAL) {
|
|
533
|
-
// 垂直,仅调整x坐标, 与水平调整同理
|
|
534
|
-
pointsList[startIndex] = {
|
|
535
|
-
x: start.x + dragInfo.x,
|
|
536
|
-
y: start.y,
|
|
537
|
-
}
|
|
538
|
-
pointsList[endIndex] = {
|
|
539
|
-
x: end.x + dragInfo.x,
|
|
540
|
-
y: end.y,
|
|
541
|
-
}
|
|
542
|
-
let draggingPointList = this.pointsList.map((i) => i)
|
|
543
|
-
if (startIndex !== 0 && endIndex !== this.pointsList.length - 1) {
|
|
544
|
-
draggingPointList = this.removeCrossPoints(
|
|
545
|
-
startIndex,
|
|
546
|
-
endIndex,
|
|
547
|
-
draggingPointList,
|
|
548
|
-
)
|
|
549
|
-
}
|
|
550
|
-
if (startIndex === 0) {
|
|
551
|
-
const startPosition = {
|
|
552
|
-
x: start.x + dragInfo.x,
|
|
553
|
-
y: start.y,
|
|
554
|
-
}
|
|
555
|
-
const inNode = isInNode(startPosition, this.sourceNode)
|
|
556
|
-
if (!inNode) {
|
|
557
|
-
const anchorList = this.sourceNode.anchors
|
|
558
|
-
draggingPointList = this.getDraggingPoints(
|
|
559
|
-
direction,
|
|
560
|
-
'start',
|
|
561
|
-
startPosition,
|
|
562
|
-
anchorList,
|
|
563
|
-
draggingPointList,
|
|
564
|
-
)
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
if (endIndex === this.pointsList.length - 1) {
|
|
568
|
-
const endPosition = {
|
|
569
|
-
x: end.x + dragInfo.x,
|
|
570
|
-
y: end.y,
|
|
571
|
-
}
|
|
572
|
-
const inNode = isInNode(endPosition, this.targetNode)
|
|
573
|
-
if (!inNode) {
|
|
574
|
-
const anchorList = this.targetNode.anchors
|
|
575
|
-
draggingPointList = this.getDraggingPoints(
|
|
576
|
-
direction,
|
|
577
|
-
'end',
|
|
578
|
-
endPosition,
|
|
579
|
-
anchorList,
|
|
580
|
-
draggingPointList,
|
|
581
|
-
)
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
this.updatePointsAfterDrag(draggingPointList)
|
|
585
|
-
this.draggingPointList = draggingPointList
|
|
586
|
-
}
|
|
587
|
-
// TODO: 确认该判断逻辑是否需要
|
|
588
|
-
if (this.text?.value) {
|
|
589
|
-
this.setText(assign({}, this.text, this.textPosition))
|
|
590
|
-
}
|
|
591
|
-
return {
|
|
592
|
-
start: assign({}, pointsList[startIndex]),
|
|
593
|
-
end: assign({}, pointsList[endIndex]),
|
|
594
|
-
startIndex,
|
|
595
|
-
endIndex,
|
|
596
|
-
direction,
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
@action
|
|
601
|
-
dragAppendEnd() {
|
|
602
|
-
if (this.draggingPointList) {
|
|
603
|
-
const pointsList = pointFilter(points2PointsList(this.points))
|
|
604
|
-
// 更新pointsList,重新渲染appendWidth
|
|
605
|
-
this.pointsList = pointsList.map((i) => i)
|
|
606
|
-
// draggingPointList清空
|
|
607
|
-
this.draggingPointList = []
|
|
608
|
-
// 更新起终点
|
|
609
|
-
const startPoint = pointsList[0]
|
|
610
|
-
this.startPoint = assign({}, startPoint)
|
|
611
|
-
const endPoint = pointsList[pointsList.length - 1]
|
|
612
|
-
this.endPoint = assign({}, endPoint)
|
|
613
|
-
}
|
|
614
|
-
this.isDragging = false
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
/* 拖拽之后个更新points,仅更新边,不更新pointsList,
|
|
618
|
-
appendWidth会依赖pointsList,更新pointsList会重新渲染appendWidth,从而导致不能继续拖拽
|
|
619
|
-
在拖拽结束后再进行pointsList的更新
|
|
620
|
-
*/
|
|
621
|
-
@action
|
|
622
|
-
updatePointsAfterDrag(pointsList: Point[]) {
|
|
623
|
-
// 找到准确的连接点后,更新points, 更新边,同时更新依赖points的箭头
|
|
624
|
-
const list = this.updateCrossPoints(pointsList)
|
|
625
|
-
this.points = list.map((point) => `${point.x},${point.y}`).join(' ')
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
// 获取边调整的起点
|
|
629
|
-
@action
|
|
630
|
-
getAdjustStart() {
|
|
631
|
-
return this.pointsList[0] || this.startPoint
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
// 获取边调整的终点
|
|
635
|
-
@action
|
|
636
|
-
getAdjustEnd() {
|
|
637
|
-
const { pointsList } = this
|
|
638
|
-
return pointsList[pointsList.length - 1] || this.endPoint
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
// 起终点拖拽调整过程中,进行折线路径更新
|
|
642
|
-
@action
|
|
643
|
-
updateAfterAdjustStartAndEnd({
|
|
644
|
-
startPoint,
|
|
645
|
-
endPoint,
|
|
646
|
-
sourceNode,
|
|
647
|
-
targetNode,
|
|
648
|
-
}: {
|
|
649
|
-
startPoint: Point
|
|
650
|
-
endPoint: Point
|
|
651
|
-
sourceNode: BaseNodeModel
|
|
652
|
-
targetNode: BaseNodeModel
|
|
653
|
-
}) {
|
|
654
|
-
this.pointsList = getPolylinePoints(
|
|
655
|
-
{
|
|
656
|
-
x: startPoint.x,
|
|
657
|
-
y: startPoint.y,
|
|
658
|
-
},
|
|
659
|
-
{
|
|
660
|
-
x: endPoint.x,
|
|
661
|
-
y: endPoint.y,
|
|
662
|
-
},
|
|
663
|
-
sourceNode,
|
|
664
|
-
targetNode,
|
|
665
|
-
this.offset || 0,
|
|
666
|
-
)
|
|
667
|
-
|
|
668
|
-
this.initPoints()
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
export default PolylineEdgeModel
|
package/src/model/edge/index.ts
DELETED
package/src/model/index.ts
DELETED