@logicflow/extension 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/README.md +16 -0
- package/dist/index.css +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/NodeResize/node/RectResize.d.ts +0 -6
- package/es/NodeResize/node/RectResize.js +2 -11
- package/es/bpmn-elements-adapter/json2xml.d.ts +2 -1
- package/es/bpmn-elements-adapter/json2xml.js +18 -4
- package/es/bpmn-elements-adapter/xml2json.js +2 -7
- package/es/components/control/index.d.ts +1 -0
- package/es/components/control/index.js +24 -11
- package/es/components/mini-map/index.js +1 -1
- package/es/dynamic-group/model.d.ts +2 -1
- package/es/dynamic-group/model.js +28 -11
- package/es/dynamic-group/node.js +1 -0
- package/es/index.css +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -0
- package/es/insert-node-in-polyline/index.js +11 -35
- package/es/materials/curved-edge/index.js +49 -21
- package/es/materials/group/GroupNode.d.ts +0 -6
- package/es/materials/group/GroupNode.js +1 -6
- package/es/pool/LaneModel.d.ts +90 -0
- package/es/pool/LaneModel.js +252 -0
- package/es/pool/LaneView.d.ts +40 -0
- package/es/pool/LaneView.js +202 -0
- package/es/pool/PoolModel.d.ts +120 -0
- package/es/pool/PoolModel.js +586 -0
- package/es/pool/PoolView.d.ts +17 -0
- package/es/pool/PoolView.js +76 -0
- package/es/pool/constant.d.ts +15 -0
- package/es/pool/constant.js +17 -0
- package/es/pool/index.d.ts +89 -0
- package/es/pool/index.js +524 -0
- package/es/pool/utils.d.ts +19 -0
- package/es/pool/utils.js +33 -0
- package/es/style/index.css +1 -1
- package/es/style/raw.d.ts +1 -1
- package/es/style/raw.js +1 -1
- package/es/tools/label/LabelOverlay.js +3 -3
- package/es/tools/label/mediumEditor.d.ts +1 -1
- package/es/tools/label/mediumEditor.js +89 -52
- package/es/tools/snapshot/index.d.ts +7 -3
- package/es/tools/snapshot/index.js +72 -77
- package/lib/NodeResize/node/RectResize.d.ts +0 -6
- package/lib/NodeResize/node/RectResize.js +1 -10
- package/lib/bpmn-elements-adapter/json2xml.d.ts +2 -1
- package/lib/bpmn-elements-adapter/json2xml.js +19 -4
- package/lib/bpmn-elements-adapter/xml2json.js +2 -7
- package/lib/components/control/index.d.ts +1 -0
- package/lib/components/control/index.js +24 -11
- package/lib/components/mini-map/index.js +1 -1
- package/lib/dynamic-group/model.d.ts +2 -1
- package/lib/dynamic-group/model.js +28 -11
- package/lib/dynamic-group/node.js +1 -0
- package/lib/index.css +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/insert-node-in-polyline/index.js +10 -34
- package/lib/materials/curved-edge/index.js +49 -21
- package/lib/materials/group/GroupNode.d.ts +0 -6
- package/lib/materials/group/GroupNode.js +1 -6
- package/lib/pool/LaneModel.d.ts +90 -0
- package/lib/pool/LaneModel.js +255 -0
- package/lib/pool/LaneView.d.ts +40 -0
- package/lib/pool/LaneView.js +205 -0
- package/lib/pool/PoolModel.d.ts +120 -0
- package/lib/pool/PoolModel.js +589 -0
- package/lib/pool/PoolView.d.ts +17 -0
- package/lib/pool/PoolView.js +79 -0
- package/lib/pool/constant.d.ts +15 -0
- package/lib/pool/constant.js +20 -0
- package/lib/pool/index.d.ts +89 -0
- package/lib/pool/index.js +527 -0
- package/lib/pool/utils.d.ts +19 -0
- package/lib/pool/utils.js +38 -0
- package/lib/style/index.css +1 -1
- package/lib/style/raw.d.ts +1 -1
- package/lib/style/raw.js +1 -1
- package/lib/tools/label/LabelOverlay.js +2 -2
- package/lib/tools/label/mediumEditor.d.ts +1 -1
- package/lib/tools/label/mediumEditor.js +91 -53
- package/lib/tools/snapshot/index.d.ts +7 -3
- package/lib/tools/snapshot/index.js +72 -77
- package/package.json +10 -7
- package/.turbo/turbo-build.log +0 -38
- package/CHANGELOG.md +0 -1766
- package/__test__/bpmn-adapter.test.js +0 -227
- package/es/materials/curved-edge/__test__/curved-edge.test.d.ts +0 -1
- package/es/materials/curved-edge/__test__/curved-edge.test.js +0 -18
- package/jest.config.js +0 -198
- package/lib/materials/curved-edge/__test__/curved-edge.test.d.ts +0 -1
- package/lib/materials/curved-edge/__test__/curved-edge.test.js +0 -20
- package/rollup.config.js +0 -52
- package/src/NodeResize/BasicShape/Ellipse.tsx +0 -22
- package/src/NodeResize/BasicShape/Polygon.tsx +0 -24
- package/src/NodeResize/BasicShape/Rect.tsx +0 -44
- package/src/NodeResize/control/Control.tsx +0 -537
- package/src/NodeResize/control/ControlGroup.tsx +0 -76
- package/src/NodeResize/control/Util.ts +0 -206
- package/src/NodeResize/index.ts +0 -26
- package/src/NodeResize/node/DiamondResize.tsx +0 -149
- package/src/NodeResize/node/EllipseResize.tsx +0 -140
- package/src/NodeResize/node/HtmlResize.tsx +0 -125
- package/src/NodeResize/node/RectResize.tsx +0 -146
- package/src/NodeResize/node/index.ts +0 -4
- package/src/bpmn/constant.ts +0 -56
- package/src/bpmn/events/EndEvent.ts +0 -73
- package/src/bpmn/events/StartEvent.ts +0 -52
- package/src/bpmn/events/index.ts +0 -2
- package/src/bpmn/flow/SequenceFlow.ts +0 -25
- package/src/bpmn/flow/index.ts +0 -1
- package/src/bpmn/gateways/ExclusiveGateway.ts +0 -71
- package/src/bpmn/gateways/index.ts +0 -1
- package/src/bpmn/getBpmnId.ts +0 -31
- package/src/bpmn/index.ts +0 -60
- package/src/bpmn/tasks/ServiceTask.ts +0 -63
- package/src/bpmn/tasks/UserTask.ts +0 -64
- package/src/bpmn/tasks/index.ts +0 -2
- package/src/bpmn-adapter/bpmnIds.ts +0 -31
- package/src/bpmn-adapter/index.ts +0 -835
- package/src/bpmn-adapter/json2xml.ts +0 -127
- package/src/bpmn-adapter/xml2json.ts +0 -544
- package/src/bpmn-elements/README.md +0 -223
- package/src/bpmn-elements/__tests__/definition.test.js +0 -72
- package/src/bpmn-elements/index.d.ts +0 -26
- package/src/bpmn-elements/index.ts +0 -107
- package/src/bpmn-elements/presets/Event/EndEventFactory.ts +0 -114
- package/src/bpmn-elements/presets/Event/IntermediateCatchEvent.ts +0 -108
- package/src/bpmn-elements/presets/Event/IntermediateThrowEvent.ts +0 -109
- package/src/bpmn-elements/presets/Event/StartEventFactory.ts +0 -114
- package/src/bpmn-elements/presets/Event/boundaryEventFactory.ts +0 -117
- package/src/bpmn-elements/presets/Event/index.ts +0 -14
- package/src/bpmn-elements/presets/Flow/flow.d.ts +0 -6
- package/src/bpmn-elements/presets/Flow/index.ts +0 -8
- package/src/bpmn-elements/presets/Flow/manhattan.ts +0 -691
- package/src/bpmn-elements/presets/Flow/sequenceFlow.ts +0 -65
- package/src/bpmn-elements/presets/Gateway/gateway.ts +0 -107
- package/src/bpmn-elements/presets/Gateway/index.ts +0 -23
- package/src/bpmn-elements/presets/Pool/Lane.ts +0 -211
- package/src/bpmn-elements/presets/Pool/Pool.ts +0 -284
- package/src/bpmn-elements/presets/Pool/index.ts +0 -89
- package/src/bpmn-elements/presets/Task/index.ts +0 -122
- package/src/bpmn-elements/presets/Task/subProcess.ts +0 -189
- package/src/bpmn-elements/presets/Task/task.ts +0 -193
- package/src/bpmn-elements/presets/icons.ts +0 -155
- package/src/bpmn-elements/utils.ts +0 -52
- package/src/bpmn-elements-adapter/README.md +0 -293
- package/src/bpmn-elements-adapter/__tests__/adapter_in.test.js +0 -528
- package/src/bpmn-elements-adapter/__tests__/adapter_out.test.js +0 -569
- package/src/bpmn-elements-adapter/constant.ts +0 -76
- package/src/bpmn-elements-adapter/index.ts +0 -1134
- package/src/bpmn-elements-adapter/json2xml.ts +0 -91
- package/src/bpmn-elements-adapter/xml2json.ts +0 -548
- package/src/components/context-menu/index.ts +0 -253
- package/src/components/control/index.ts +0 -141
- package/src/components/dnd-panel/index.ts +0 -137
- package/src/components/highlight/index.ts +0 -227
- package/src/components/menu/index.ts +0 -748
- package/src/components/mini-map/index.ts +0 -686
- package/src/components/selection-select/index.ts +0 -387
- package/src/dynamic-group/index.ts +0 -775
- package/src/dynamic-group/model.ts +0 -562
- package/src/dynamic-group/node.ts +0 -288
- package/src/dynamic-group/utils.ts +0 -46
- package/src/index.less +0 -1
- package/src/index.ts +0 -45
- package/src/insert-node-in-polyline/edge.ts +0 -175
- package/src/insert-node-in-polyline/index.ts +0 -187
- package/src/materials/curved-edge/__test__/curved-edge.test.ts +0 -46
- package/src/materials/curved-edge/index.ts +0 -185
- package/src/materials/group/GroupNode.ts +0 -442
- package/src/materials/group/index.ts +0 -542
- package/src/materials/node-selection/index.ts +0 -380
- package/src/mindmap/fakerRoot.ts +0 -19
- package/src/mindmap/index.ts +0 -328
- package/src/mindmap/markContent.ts +0 -81
- package/src/mindmap/markContentOption.ts +0 -81
- package/src/mindmap/markEntity.ts +0 -82
- package/src/mindmap/markRoot.ts +0 -83
- package/src/mindmap/theme.ts +0 -11
- package/src/rect-label-node/RectLabelNodeView.ts +0 -33
- package/src/rect-label-node/index.ts +0 -15
- package/src/style/index.less +0 -342
- package/src/style/raw.ts +0 -295
- package/src/tools/auto-layout/index.ts +0 -282
- package/src/tools/flow-path/index.ts +0 -233
- package/src/tools/label/Label.tsx +0 -357
- package/src/tools/label/LabelModel.ts +0 -83
- package/src/tools/label/LabelOverlay.tsx +0 -158
- package/src/tools/label/algorithm.ts +0 -42
- package/src/tools/label/index.ts +0 -479
- package/src/tools/label/mediumEditor.ts +0 -94
- package/src/tools/label/utils.ts +0 -395
- package/src/tools/proximity-connect/index.ts +0 -435
- package/src/tools/snapshot/README.md +0 -145
- package/src/tools/snapshot/index.ts +0 -718
- package/src/tools/snapshot/utils.ts +0 -163
- package/src/turbo-adapter/index.ts +0 -212
- package/stats.html +0 -4842
- package/tsconfig.json +0 -18
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import MediumEditor from 'medium-editor'
|
|
2
|
-
import Picker from 'vanilla-picker'
|
|
3
|
-
import rangy from 'rangy'
|
|
4
|
-
import 'rangy/lib/rangy-classapplier'
|
|
5
|
-
|
|
6
|
-
export const defaultOptions = {
|
|
7
|
-
toolbar: {
|
|
8
|
-
allowMultiParagraphSelection: true,
|
|
9
|
-
buttons: [
|
|
10
|
-
'bold',
|
|
11
|
-
'colorpicker',
|
|
12
|
-
'italic',
|
|
13
|
-
'underline',
|
|
14
|
-
'strikethrough',
|
|
15
|
-
'quote',
|
|
16
|
-
'justifyLeft',
|
|
17
|
-
'justifyCenter',
|
|
18
|
-
'justifyRight',
|
|
19
|
-
'justifyFull',
|
|
20
|
-
'superscript',
|
|
21
|
-
'subscript',
|
|
22
|
-
'orderedlist',
|
|
23
|
-
'unorderedlist',
|
|
24
|
-
'pre',
|
|
25
|
-
'removeFormat',
|
|
26
|
-
'outdent',
|
|
27
|
-
'indent',
|
|
28
|
-
'h2',
|
|
29
|
-
'h3',
|
|
30
|
-
],
|
|
31
|
-
standardizeSelectionStart: false,
|
|
32
|
-
updateOnEmptySelection: false,
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
placeholder: {
|
|
36
|
-
text: '请输入内容',
|
|
37
|
-
hideOnClick: true,
|
|
38
|
-
},
|
|
39
|
-
disableEditing: true,
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const ColorPickerButton = MediumEditor.extensions.button.extend({
|
|
43
|
-
name: 'colorpicker',
|
|
44
|
-
tagNames: ['mark'],
|
|
45
|
-
contentDefault: '<b>Color</b>',
|
|
46
|
-
aria: 'Color Picker',
|
|
47
|
-
action: 'colorPicker',
|
|
48
|
-
init: function () {
|
|
49
|
-
rangy.init()
|
|
50
|
-
MediumEditor.extensions.button.prototype.init.call(this)
|
|
51
|
-
this.colorPicker = new Picker({
|
|
52
|
-
parent: this.button,
|
|
53
|
-
color: '#000',
|
|
54
|
-
onDone: (res) => {
|
|
55
|
-
if (this.coloredText && this.coloredText.isAppliedToSelection()) {
|
|
56
|
-
this.coloredText.undoToSelection()
|
|
57
|
-
}
|
|
58
|
-
this.coloredText = rangy.createClassApplier('colored', {
|
|
59
|
-
elementTagName: 'span',
|
|
60
|
-
elementProperties: {
|
|
61
|
-
style: {
|
|
62
|
-
color: res.hex,
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
normalize: true,
|
|
66
|
-
})
|
|
67
|
-
this.coloredText.toggleSelection()
|
|
68
|
-
this.base.checkContentChanged()
|
|
69
|
-
this.setInactive()
|
|
70
|
-
},
|
|
71
|
-
})
|
|
72
|
-
},
|
|
73
|
-
getButton: function () {
|
|
74
|
-
return this.button
|
|
75
|
-
},
|
|
76
|
-
handleClick: function () {
|
|
77
|
-
this.setActive()
|
|
78
|
-
this.colorPicker.show()
|
|
79
|
-
},
|
|
80
|
-
isAlreadyApplied: function (node) {
|
|
81
|
-
return node.nodeName.toLowerCase() === 'mark'
|
|
82
|
-
},
|
|
83
|
-
isActive: function () {
|
|
84
|
-
return this.button.classList.contains('medium-editor-button-active')
|
|
85
|
-
},
|
|
86
|
-
setInactive: function () {
|
|
87
|
-
this.button.classList.remove('medium-editor-button-active')
|
|
88
|
-
},
|
|
89
|
-
setActive: function () {
|
|
90
|
-
this.button.classList.add('medium-editor-button-active')
|
|
91
|
-
},
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
export { MediumEditor }
|
package/src/tools/label/utils.ts
DELETED
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
import LogicFlow, {
|
|
2
|
-
BaseEdgeModel,
|
|
3
|
-
BaseNodeModel,
|
|
4
|
-
getNodeOutline,
|
|
5
|
-
getEdgeOutline,
|
|
6
|
-
Model,
|
|
7
|
-
ModelType,
|
|
8
|
-
BezierEdgeModel,
|
|
9
|
-
isInSegment,
|
|
10
|
-
getBezierPoints,
|
|
11
|
-
points2PointsList,
|
|
12
|
-
getBBoxOfPoints,
|
|
13
|
-
} from '@logicflow/core'
|
|
14
|
-
import { head, isEmpty, last, min } from 'lodash-es'
|
|
15
|
-
import { calcTwoPointsDistance, getPointOnBezier } from './algorithm'
|
|
16
|
-
|
|
17
|
-
import Point = LogicFlow.Point
|
|
18
|
-
import LabelConfig = LogicFlow.LabelConfig
|
|
19
|
-
import OutlineInfo = Model.OutlineInfo
|
|
20
|
-
|
|
21
|
-
export type BBoxInfo = {
|
|
22
|
-
x: number
|
|
23
|
-
y: number
|
|
24
|
-
width: number
|
|
25
|
-
height: number
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// 工具函数:计算「缩放」后 某坐标点 相对中心位置比例不变的 新坐标点
|
|
29
|
-
// 前提条件: 当缩放一个矩形时,如果你希望矩形中的某个点的位置相对于矩形保持不变
|
|
30
|
-
//
|
|
31
|
-
// 1. 原始矩形的左上角坐标为 (x1, y1),宽度为 w1,高度为 h1。
|
|
32
|
-
// 2. 缩放后的矩形的左上角坐标为 (x2, y2),宽度为 w2,高度为 h2。
|
|
33
|
-
// 3. 矩形中的某个点在原始矩形中的坐标为 (px1, py1)。
|
|
34
|
-
//
|
|
35
|
-
// 目标
|
|
36
|
-
// 计算该点在缩放后矩形中的新坐标 (px2, py2)。
|
|
37
|
-
//
|
|
38
|
-
// 步骤
|
|
39
|
-
// 1. 计算相对位置:首先计算点 (px1, py1) 在原始矩形中的相对位置。
|
|
40
|
-
// relativeX = (px1 - x1) / w1
|
|
41
|
-
// relativeY = (py1 - y1) / h1
|
|
42
|
-
//
|
|
43
|
-
// 2. 计算新坐标:然后,使用相对位置计算该点在缩放后矩形中的新坐标。
|
|
44
|
-
// px2 = x2 + relativeX * w2
|
|
45
|
-
// py2 = y2 + relativeY * h2
|
|
46
|
-
export function calcPointAfterResize(
|
|
47
|
-
origin: BBoxInfo,
|
|
48
|
-
scaled: BBoxInfo,
|
|
49
|
-
point: Point,
|
|
50
|
-
): Point {
|
|
51
|
-
const { x: x1, y: y1, width: w1, height: h1 } = origin
|
|
52
|
-
const { x: x2, y: y2, width: w2, height: h2 } = scaled
|
|
53
|
-
const { x: px1, y: py1 } = point
|
|
54
|
-
|
|
55
|
-
// 计算点在原始矩形中的相对位置
|
|
56
|
-
const relativeX = (px1 - x1) / w1
|
|
57
|
-
const relativeY = (py1 - y1) / h1
|
|
58
|
-
|
|
59
|
-
// 计算点在缩放后矩形中的新坐标
|
|
60
|
-
const px2 = x2 + relativeX * w2
|
|
61
|
-
const py2 = y2 + relativeY * h2
|
|
62
|
-
|
|
63
|
-
return { x: px2, y: py2 }
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// 工具函数:计算「旋转」后 某坐标点 相对中心位置比例不变的 新坐标点
|
|
67
|
-
// 要计算以点 x1 = (x1, y1) 为中心,点 x2 = (x2, y2) 旋转 θ 度后的坐标位置,可以使用旋转矩阵进行计算。
|
|
68
|
-
//
|
|
69
|
-
// 旋转公式如下:
|
|
70
|
-
// 1. 首先将点 x2 平移到以 x1 为原点的坐标系:
|
|
71
|
-
// x' = x2 - x1
|
|
72
|
-
// y' = y2 - y1
|
|
73
|
-
// 2. 然后应用旋转矩阵进行旋转:
|
|
74
|
-
// x'' = x' * cos(θ) - y' * sin(θ)
|
|
75
|
-
// y'' = x' * sin(θ) + y' * cos(θ)
|
|
76
|
-
// 3. 最后将结果平移回原来的坐标系:
|
|
77
|
-
// x_new = x'' + x1
|
|
78
|
-
// y_new = y'' + y1
|
|
79
|
-
//
|
|
80
|
-
// 综合起来,旋转后的新坐标 (x_new, y_new) 计算公式如下:
|
|
81
|
-
//
|
|
82
|
-
// x_new = (x2 - x1) * cos(θ) - (y2 - y1) * sin(θ) + x1
|
|
83
|
-
// y_new = (x2 - x1) * sin(θ) + (y2 - y1) * cos(θ) + y1
|
|
84
|
-
//
|
|
85
|
-
// 其中,θ 需要用弧度表示,如果你有的是角度,可以用以下公式转换为弧度:
|
|
86
|
-
//
|
|
87
|
-
// rad = deg * π / 180
|
|
88
|
-
export function rotatePointAroundCenter(
|
|
89
|
-
target: Point,
|
|
90
|
-
center: Point,
|
|
91
|
-
radian: number,
|
|
92
|
-
): Point {
|
|
93
|
-
// Rotate point (x2, y2) around point (x1, y1) by theta degrees.
|
|
94
|
-
//
|
|
95
|
-
// Parameters:
|
|
96
|
-
// x1, y1: Coordinates of the center point.
|
|
97
|
-
// x2, y2: Coordinates of the point to rotate.
|
|
98
|
-
// theta_degrees: Angle in degrees to rotate the point.
|
|
99
|
-
//
|
|
100
|
-
// Returns:
|
|
101
|
-
// Tuple of new coordinates (x_new, y_new) after rotation.
|
|
102
|
-
|
|
103
|
-
const { x: x1, y: y1 } = center
|
|
104
|
-
const { x: x2, y: y2 } = target
|
|
105
|
-
|
|
106
|
-
// Translate point to origin
|
|
107
|
-
const xPrime = x2 - x1
|
|
108
|
-
const yPrime = y2 - y1
|
|
109
|
-
|
|
110
|
-
// Rotate point
|
|
111
|
-
const xDoublePrime = xPrime * Math.cos(radian) - yPrime * Math.sin(radian)
|
|
112
|
-
const yDoublePrime = xPrime * Math.sin(radian) + yPrime * Math.cos(radian)
|
|
113
|
-
|
|
114
|
-
// Translate point back
|
|
115
|
-
const xNew = xDoublePrime + x1
|
|
116
|
-
const yNew = yDoublePrime + y1
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
x: xNew,
|
|
120
|
-
y: yNew,
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** Edge 相关工具方法 */
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* 获取某点在一个矩形图形(节点 or 边的 outline)内的偏移量
|
|
128
|
-
* @param point 目标点(此处即 Label 的坐标信息)
|
|
129
|
-
* @param element 目标元素
|
|
130
|
-
*/
|
|
131
|
-
export const getPointOffsetOfElementOutline = (
|
|
132
|
-
point: Point,
|
|
133
|
-
element: BaseNodeModel | BaseEdgeModel,
|
|
134
|
-
) => {
|
|
135
|
-
const baseType = element.BaseType
|
|
136
|
-
const bboxInfo: OutlineInfo | undefined =
|
|
137
|
-
baseType === 'node' ? getNodeOutline(element) : getEdgeOutline(element)
|
|
138
|
-
|
|
139
|
-
if (bboxInfo) {
|
|
140
|
-
const { x, y } = point
|
|
141
|
-
const { x: minX, y: minY, x1: maxX, y1: maxY } = bboxInfo
|
|
142
|
-
let xDeltaPercent: number = 0.5
|
|
143
|
-
let yDeltaPercent: number = 0.5
|
|
144
|
-
let xDeltaDistance: number = x - maxX
|
|
145
|
-
let yDeltaDistance: number = y - maxY
|
|
146
|
-
/**
|
|
147
|
-
* 文本在由路径点组成的凸包内,就记录偏移比例
|
|
148
|
-
* 文本在凸包外,记录绝对距离
|
|
149
|
-
* 用于边路径变化时计算文本新位置
|
|
150
|
-
*/
|
|
151
|
-
if (minX && maxX && minX < x && x < maxX) {
|
|
152
|
-
xDeltaPercent = min([(x - minX) / (maxX - minX), 1]) as number
|
|
153
|
-
} else if (x <= minX) {
|
|
154
|
-
xDeltaDistance = x - minX
|
|
155
|
-
} else {
|
|
156
|
-
xDeltaDistance = x - maxX
|
|
157
|
-
}
|
|
158
|
-
if (minY && maxY && minY < y && y < maxY) {
|
|
159
|
-
yDeltaPercent = min([(y - minY) / (maxY - minY), 1]) as number
|
|
160
|
-
} else if (y <= minY) {
|
|
161
|
-
yDeltaDistance = y - minY
|
|
162
|
-
} else {
|
|
163
|
-
yDeltaDistance = y - maxY
|
|
164
|
-
}
|
|
165
|
-
return {
|
|
166
|
-
xDeltaPercent,
|
|
167
|
-
yDeltaPercent,
|
|
168
|
-
xDeltaDistance,
|
|
169
|
-
yDeltaDistance,
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* 判断节点是否在折线上
|
|
176
|
-
* @param point 目标点坐标
|
|
177
|
-
* @param points 折线上的点坐标
|
|
178
|
-
*/
|
|
179
|
-
const isPointOnPolyline = (point: Point, points: Point[]): boolean => {
|
|
180
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
181
|
-
const start = points[i]
|
|
182
|
-
const end = points[i + 1]
|
|
183
|
-
if (isInSegment(point, start, end)) {
|
|
184
|
-
return true
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return false
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* 给定一个点 P = (x_0, y_0) 和线段的两个端点 A = (x_1, y_1) 和 B = (x_2, y_2) ,可以使用以下步骤计算点到线段的距离:
|
|
193
|
-
* 1. 计算向量 AB 和 AP 。
|
|
194
|
-
* 2. 计算 AB 的平方长度。
|
|
195
|
-
* 3. 计算点 P 在直线 AB 上的投影点 Q 。
|
|
196
|
-
* 4. 判断 Q 是否在线段 AB 上。
|
|
197
|
-
* 5. 根据 Q 是否在线段上,计算点到线段的距离。
|
|
198
|
-
*
|
|
199
|
-
* 计算点到线段质检的距离
|
|
200
|
-
* @param point
|
|
201
|
-
* @param start
|
|
202
|
-
* @param end
|
|
203
|
-
*/
|
|
204
|
-
export const pointToSegmentDistance = (
|
|
205
|
-
point: Point,
|
|
206
|
-
start: Point,
|
|
207
|
-
end: Point,
|
|
208
|
-
): number => {
|
|
209
|
-
const { x: px, y: py } = point
|
|
210
|
-
const { x: sx, y: sy } = start
|
|
211
|
-
const { x: ex, y: ey } = end
|
|
212
|
-
|
|
213
|
-
const SEx = ex - sx
|
|
214
|
-
const SEy = ey - sy
|
|
215
|
-
const SPx = px - sx
|
|
216
|
-
const SPy = py - sy
|
|
217
|
-
|
|
218
|
-
const SE_SE = SEx ** 2 + SEy ** 2
|
|
219
|
-
const SP_SE = SPx * SEx + SPy * SEy
|
|
220
|
-
let t = SP_SE / SE_SE
|
|
221
|
-
if (t < 0) t = 0
|
|
222
|
-
if (t > 1) t = 1
|
|
223
|
-
|
|
224
|
-
const qx = sx + t * SEx
|
|
225
|
-
const qy = sy + t * SEy
|
|
226
|
-
return Math.sqrt((px - qx) ** 2 + (py - qy) ** 2)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export const calcPolylineTotalLength = (points: Point[]) => {
|
|
230
|
-
let length = 0
|
|
231
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
232
|
-
const start = points[i]
|
|
233
|
-
const end = points[i + 1]
|
|
234
|
-
length += calcTwoPointsDistance(start, end)
|
|
235
|
-
}
|
|
236
|
-
return length
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* TODO: 确认该函数的意义,写完还是没看懂什么意思
|
|
241
|
-
* @param point
|
|
242
|
-
* @param points
|
|
243
|
-
*/
|
|
244
|
-
export const pointPositionRatio = (point: Point, points: Point[]): number => {
|
|
245
|
-
let length = 0
|
|
246
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
247
|
-
const start = points[i]
|
|
248
|
-
const end = points[i + 1]
|
|
249
|
-
const segmentLength = calcTwoPointsDistance(start, end)
|
|
250
|
-
|
|
251
|
-
if (pointToSegmentDistance(point, start, end) <= 20) {
|
|
252
|
-
const d1 = calcTwoPointsDistance(point, start)
|
|
253
|
-
length += d1
|
|
254
|
-
const totalLength = calcPolylineTotalLength(points)
|
|
255
|
-
// 小数点后保留一位(四舍五入)
|
|
256
|
-
return Math.round((length / totalLength) * 10) / 10
|
|
257
|
-
} else {
|
|
258
|
-
length += segmentLength
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return 0
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* 计算一个坐标在贝塞尔曲线上最近的一个点
|
|
266
|
-
* @param point
|
|
267
|
-
* @param edge
|
|
268
|
-
* @param step
|
|
269
|
-
*/
|
|
270
|
-
export const calcClosestPointOnBezierEdge = (
|
|
271
|
-
point: Point,
|
|
272
|
-
edge: BezierEdgeModel,
|
|
273
|
-
step: number = 5,
|
|
274
|
-
): Point => {
|
|
275
|
-
let minDistance = Infinity
|
|
276
|
-
let closestPoint: Point = point
|
|
277
|
-
|
|
278
|
-
const pointsList = getBezierPoints(edge.path)
|
|
279
|
-
if (isEmpty(pointsList)) return closestPoint
|
|
280
|
-
|
|
281
|
-
const [start, sNext, ePre, end] = pointsList
|
|
282
|
-
for (let i = 0; i <= step; i++) {
|
|
283
|
-
const t = i / step
|
|
284
|
-
const bezierPoint = getPointOnBezier(t, start, sNext, ePre, end)
|
|
285
|
-
const distance = calcTwoPointsDistance(point, bezierPoint)
|
|
286
|
-
if (distance < minDistance) {
|
|
287
|
-
minDistance = distance
|
|
288
|
-
closestPoint = bezierPoint
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return closestPoint
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
export const getNewPointAtDistance = (
|
|
296
|
-
points: Point[],
|
|
297
|
-
ratio: number,
|
|
298
|
-
): Point | undefined => {
|
|
299
|
-
const totalLength = calcPolylineTotalLength(points)
|
|
300
|
-
const targetLength = totalLength * ratio
|
|
301
|
-
|
|
302
|
-
let length = 0
|
|
303
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
304
|
-
const start = points[i]
|
|
305
|
-
const end = points[i + 1]
|
|
306
|
-
const segmentLength = calcTwoPointsDistance(start, end)
|
|
307
|
-
if (length + segmentLength >= targetLength) {
|
|
308
|
-
const ratio = (targetLength - length) / segmentLength
|
|
309
|
-
return {
|
|
310
|
-
x: start.x + (end.x - start.x) * ratio,
|
|
311
|
-
y: start.y + (end.y - start.y) * ratio,
|
|
312
|
-
}
|
|
313
|
-
} else {
|
|
314
|
-
length += segmentLength
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return last(points)
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* 计算一个坐标离折线(包括 PolylineEdge 和 LineEdge 直线)最近的一个点
|
|
322
|
-
* @param point
|
|
323
|
-
* @param edge
|
|
324
|
-
*/
|
|
325
|
-
export const calcLabelPositionOnPolyline = (
|
|
326
|
-
point: Point,
|
|
327
|
-
edge: BaseEdgeModel,
|
|
328
|
-
): Point => {
|
|
329
|
-
let points = points2PointsList(edge.points)
|
|
330
|
-
if (points.length === 0) {
|
|
331
|
-
points = [edge.startPoint, edge.endPoint]
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const { xDeltaPercent, yDeltaPercent, yDeltaDistance, xDeltaDistance } =
|
|
335
|
-
getPointOffsetOfElementOutline(point, edge) ?? {}
|
|
336
|
-
const isPointOnEdge = isPointOnPolyline(point, points)
|
|
337
|
-
const ratio = pointPositionRatio(point, points)
|
|
338
|
-
|
|
339
|
-
const start = head(points)
|
|
340
|
-
const end = last(points)
|
|
341
|
-
|
|
342
|
-
// 分别取路径中,x轴 和 y轴上的最大最小坐标值组合成一个矩形
|
|
343
|
-
const { minX, minY, maxX, maxY } = getBBoxOfPoints(points, 10)
|
|
344
|
-
|
|
345
|
-
if (!start || !end) return point
|
|
346
|
-
|
|
347
|
-
if (xDeltaPercent && yDeltaPercent) {
|
|
348
|
-
const positByPercent = {
|
|
349
|
-
x: minX + (maxX - minX) * xDeltaPercent,
|
|
350
|
-
y: minY + (maxY - minY) * yDeltaPercent,
|
|
351
|
-
}
|
|
352
|
-
return isPointOnEdge
|
|
353
|
-
? (getNewPointAtDistance(points, ratio) ?? point) // 函数什么意思
|
|
354
|
-
: positByPercent
|
|
355
|
-
}
|
|
356
|
-
// 如果文本在凸包的上方或者下方
|
|
357
|
-
if (xDeltaPercent && yDeltaDistance) {
|
|
358
|
-
return {
|
|
359
|
-
x: minX + (maxX - minX) * xDeltaPercent,
|
|
360
|
-
y: yDeltaDistance < 0 ? minY + yDeltaDistance : maxY + yDeltaDistance,
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
// 如果文本在凸包的左边或者右边
|
|
364
|
-
if (yDeltaPercent && xDeltaDistance) {
|
|
365
|
-
return {
|
|
366
|
-
x: xDeltaDistance < 0 ? minX + xDeltaDistance : maxX + xDeltaDistance,
|
|
367
|
-
y: minY + (maxY - minY) * yDeltaPercent,
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
// 如果文本在凸包左上/左下/右上/右下
|
|
371
|
-
if (xDeltaDistance && yDeltaDistance) {
|
|
372
|
-
return {
|
|
373
|
-
x: xDeltaDistance < 0 ? minX + xDeltaDistance : maxX + xDeltaDistance,
|
|
374
|
-
y: yDeltaDistance < 0 ? minY + yDeltaDistance : maxY + yDeltaDistance,
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
// 兜底
|
|
378
|
-
return point
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* 计算 Label 离边最近的点的坐标,用于更新为 Label 的坐标
|
|
383
|
-
* @param label LabelConfig -> 当前 Label 的配置项
|
|
384
|
-
* @param edge
|
|
385
|
-
*/
|
|
386
|
-
export const getLabelPositionOfLine = (
|
|
387
|
-
label: LabelConfig,
|
|
388
|
-
edge: BaseEdgeModel,
|
|
389
|
-
): Point => {
|
|
390
|
-
const { x, y } = label
|
|
391
|
-
if (edge.modelType === ModelType.BEZIER_EDGE) {
|
|
392
|
-
return calcClosestPointOnBezierEdge({ x, y }, edge as BezierEdgeModel)
|
|
393
|
-
}
|
|
394
|
-
return calcLabelPositionOnPolyline({ x, y }, edge)
|
|
395
|
-
}
|