@logicflow/extension 2.2.0-alpha.7 → 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/package.json +10 -7
- package/.turbo/turbo-build.log +0 -38
- package/CHANGELOG.md +0 -1829
- 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 -126
- 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 -105
- package/src/bpmn-elements-adapter/xml2json.ts +0 -542
- package/src/components/context-menu/index.ts +0 -253
- package/src/components/control/index.ts +0 -155
- 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 -774
- package/src/dynamic-group/model.ts +0 -580
- 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 -47
- package/src/insert-node-in-polyline/edge.ts +0 -175
- package/src/insert-node-in-polyline/index.ts +0 -193
- package/src/materials/curved-edge/__test__/curved-edge.test.ts +0 -46
- package/src/materials/curved-edge/index.ts +0 -217
- package/src/materials/group/GroupNode.ts +0 -437
- 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/pool/LaneModel.ts +0 -226
- package/src/pool/LaneView.ts +0 -220
- package/src/pool/PoolModel.ts +0 -631
- package/src/pool/PoolView.ts +0 -75
- package/src/pool/constant.ts +0 -19
- package/src/pool/index.ts +0 -621
- package/src/pool/utils.ts +0 -46
- package/src/rect-label-node/RectLabelNodeView.ts +0 -33
- package/src/rect-label-node/index.ts +0 -15
- package/src/style/index.less +0 -381
- package/src/style/raw.ts +0 -328
- 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 -162
- package/src/tools/label/algorithm.ts +0 -42
- package/src/tools/label/index.ts +0 -479
- package/src/tools/label/mediumEditor.ts +0 -121
- 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 -701
- 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,686 +0,0 @@
|
|
|
1
|
-
import LogicFlow from '@logicflow/core'
|
|
2
|
-
|
|
3
|
-
import Position = LogicFlow.Position
|
|
4
|
-
import MiniMapOption = MiniMap.MiniMapOption
|
|
5
|
-
import MiniMapPosition = MiniMap.MiniMapPosition
|
|
6
|
-
|
|
7
|
-
export namespace MiniMap {
|
|
8
|
-
export type MiniMapOption = Partial<{
|
|
9
|
-
/**
|
|
10
|
-
* 小地图中画布的宽度
|
|
11
|
-
*/
|
|
12
|
-
width: number
|
|
13
|
-
/**
|
|
14
|
-
* 小地图中画布的高度
|
|
15
|
-
*/
|
|
16
|
-
height: number
|
|
17
|
-
/**
|
|
18
|
-
* 在小地图的画布中是否渲染边
|
|
19
|
-
*/
|
|
20
|
-
showEdge: boolean
|
|
21
|
-
/**
|
|
22
|
-
* 是否显示小地图的标题栏
|
|
23
|
-
*/
|
|
24
|
-
isShowHeader: boolean
|
|
25
|
-
/**
|
|
26
|
-
* 是否显示关闭按钮
|
|
27
|
-
*/
|
|
28
|
-
isShowCloseIcon: boolean
|
|
29
|
-
/**
|
|
30
|
-
* 小地图标题栏的文本内容
|
|
31
|
-
*/
|
|
32
|
-
headerTitle: string
|
|
33
|
-
/**
|
|
34
|
-
* 小地图与画布左边界的左边距,优先级高于`rightPosition`
|
|
35
|
-
*/
|
|
36
|
-
leftPosition: number
|
|
37
|
-
/**
|
|
38
|
-
* 小地图与画布右边界的右边距,优先级低于`leftPosition`
|
|
39
|
-
*/
|
|
40
|
-
rightPosition: number
|
|
41
|
-
/**
|
|
42
|
-
* 小地图与画布上边界的上边距,优先级高于`bottomPosition`
|
|
43
|
-
*/
|
|
44
|
-
topPosition: number
|
|
45
|
-
/**
|
|
46
|
-
* 小地图与画布下边界的下边距,优先级低于`topPosition`
|
|
47
|
-
*/
|
|
48
|
-
bottomPosition: number
|
|
49
|
-
}>
|
|
50
|
-
|
|
51
|
-
export type AbsolutePosition = Partial<
|
|
52
|
-
Record<'left' | 'right' | 'top' | 'bottom', number>
|
|
53
|
-
>
|
|
54
|
-
|
|
55
|
-
export type MiniMapPosition =
|
|
56
|
-
| 'left-top' // 表示迷你地图位于容器的左上角
|
|
57
|
-
| 'right-top' // 表示迷你地图位于容器的右上角
|
|
58
|
-
| 'left-bottom' // 表示迷你地图位于容器的右上角
|
|
59
|
-
| 'right-bottom' // 表示迷你地图位于容器的右下角。
|
|
60
|
-
| AbsolutePosition // 自定义小地图在画布上的位置
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
type Bounds = Record<'left' | 'top' | 'bottom' | 'right', number>
|
|
64
|
-
|
|
65
|
-
export class MiniMap {
|
|
66
|
-
static pluginName = 'miniMap'
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 主画布的LogicFlow实例
|
|
70
|
-
*/
|
|
71
|
-
private lf: LogicFlow
|
|
72
|
-
/**
|
|
73
|
-
* LogicFlow构造函数
|
|
74
|
-
*/
|
|
75
|
-
private LFCtor: LogicFlow.LogicFlowConstructor
|
|
76
|
-
/**
|
|
77
|
-
* 小地图中画布的LogicFlow实例
|
|
78
|
-
*/
|
|
79
|
-
private lfMap!: LogicFlow
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* lf的工具层容器,用于挂载小地图
|
|
83
|
-
*/
|
|
84
|
-
private container?: HTMLElement
|
|
85
|
-
/**
|
|
86
|
-
* 小地图的容器
|
|
87
|
-
*/
|
|
88
|
-
private miniMapContainer?: HTMLDivElement
|
|
89
|
-
/**
|
|
90
|
-
* 小地图的画布容器
|
|
91
|
-
*/
|
|
92
|
-
private miniMapWrap!: HTMLDivElement
|
|
93
|
-
/**
|
|
94
|
-
* 小地图的预览视窗
|
|
95
|
-
*/
|
|
96
|
-
private viewport!: HTMLDivElement
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* 小地图中画布容器的宽度
|
|
100
|
-
*/
|
|
101
|
-
private width = 200
|
|
102
|
-
/**
|
|
103
|
-
* 小地图中画布容器的高度
|
|
104
|
-
*/
|
|
105
|
-
private height = 150
|
|
106
|
-
/**
|
|
107
|
-
* 小地图中画布的缩放比例
|
|
108
|
-
*/
|
|
109
|
-
private scale = 1
|
|
110
|
-
/**
|
|
111
|
-
* 小地图中画布的水平位移
|
|
112
|
-
*/
|
|
113
|
-
private translateX = 0
|
|
114
|
-
/**
|
|
115
|
-
* 小地图中画布的垂直位移
|
|
116
|
-
*/
|
|
117
|
-
private translateY = 0
|
|
118
|
-
/**
|
|
119
|
-
* 在小地图的画布中是否渲染边
|
|
120
|
-
*/
|
|
121
|
-
private showEdge = false
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 小地图中画布的区域范围
|
|
125
|
-
*/
|
|
126
|
-
private bounds: Bounds
|
|
127
|
-
/**
|
|
128
|
-
* 所有元素占领的区域范围
|
|
129
|
-
*/
|
|
130
|
-
private elementAreaBounds: Bounds
|
|
131
|
-
/**
|
|
132
|
-
* 主画布视口的区域范围
|
|
133
|
-
*/
|
|
134
|
-
private viewPortBounds: Bounds
|
|
135
|
-
|
|
136
|
-
// 小地图相对画布的绝对定位
|
|
137
|
-
private leftPosition?: number
|
|
138
|
-
private topPosition?: number
|
|
139
|
-
private rightPosition?: number
|
|
140
|
-
private bottomPosition?: number
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* 预览视窗左上角在主画布的y坐标
|
|
144
|
-
*/
|
|
145
|
-
private viewPortTop = 0
|
|
146
|
-
/**
|
|
147
|
-
* 预览视窗左上角在主画布的x坐标
|
|
148
|
-
*/
|
|
149
|
-
private viewPortLeft = 0
|
|
150
|
-
// 预览视窗的宽高
|
|
151
|
-
private viewPortWidth = 150
|
|
152
|
-
private viewPortHeight = 75
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* 拖拽预览视窗时,记录起始点的位置
|
|
156
|
-
*/
|
|
157
|
-
private startPosition!: Position
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* 是否显示小地图
|
|
161
|
-
*/
|
|
162
|
-
private isShow = false
|
|
163
|
-
/**
|
|
164
|
-
* 是否显示小地图的标题栏
|
|
165
|
-
*/
|
|
166
|
-
private isShowHeader = false
|
|
167
|
-
/**
|
|
168
|
-
* 是否显示关闭按钮
|
|
169
|
-
*/
|
|
170
|
-
private isShowCloseIcon = false
|
|
171
|
-
/**
|
|
172
|
-
* 小地图标题栏的文本内容
|
|
173
|
-
*/
|
|
174
|
-
private headerTitle = '导航'
|
|
175
|
-
/**
|
|
176
|
-
* 小地图的logicFlow实例需要禁用的插件
|
|
177
|
-
*/
|
|
178
|
-
private disabledPlugins = ['miniMap', 'control', 'selectionSelect']
|
|
179
|
-
|
|
180
|
-
constructor({ lf, LogicFlow, options }: LogicFlow.IExtensionProps) {
|
|
181
|
-
this.lf = lf
|
|
182
|
-
this.LFCtor = LogicFlow
|
|
183
|
-
if (options) {
|
|
184
|
-
this.setOption(options as MiniMapOption)
|
|
185
|
-
}
|
|
186
|
-
this.viewPortWidth = lf.graphModel.width
|
|
187
|
-
this.viewPortHeight = lf.graphModel.height
|
|
188
|
-
const boundsInit: Bounds = {
|
|
189
|
-
left: 0,
|
|
190
|
-
right: this.viewPortWidth,
|
|
191
|
-
top: 0,
|
|
192
|
-
bottom: this.viewPortHeight,
|
|
193
|
-
}
|
|
194
|
-
this.bounds = boundsInit
|
|
195
|
-
this.elementAreaBounds = boundsInit
|
|
196
|
-
this.viewPortBounds = boundsInit
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
onGraphResize = () => {
|
|
200
|
-
this.updateViewPortBounds()
|
|
201
|
-
if (this.isShow) {
|
|
202
|
-
this.updateViewPort()
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
render = (_: LogicFlow, container: HTMLElement) => {
|
|
207
|
-
this.container = container
|
|
208
|
-
this.lf.on('history:change', () => {
|
|
209
|
-
if (this.isShow) {
|
|
210
|
-
this.setView()
|
|
211
|
-
}
|
|
212
|
-
})
|
|
213
|
-
this.lf.on('graph:transform', () => {
|
|
214
|
-
if (this.isShow) {
|
|
215
|
-
this.setView(false)
|
|
216
|
-
}
|
|
217
|
-
})
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* 显示小地图
|
|
222
|
-
* @param left 相对画布的左边距
|
|
223
|
-
* @param top 相对画布的上边距
|
|
224
|
-
*/
|
|
225
|
-
public show = (left?: number, top?: number) => {
|
|
226
|
-
if (!this.isShow) {
|
|
227
|
-
this.initMiniMap()
|
|
228
|
-
this.lf.on('graph:resize', this.onGraphResize)
|
|
229
|
-
this.createMiniMap(left, top)
|
|
230
|
-
this.setView(true)
|
|
231
|
-
}
|
|
232
|
-
this.isShow = true
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* 隐藏小地图
|
|
236
|
-
*/
|
|
237
|
-
public hide = () => {
|
|
238
|
-
if (this.isShow) {
|
|
239
|
-
this.lf.off('graph:resize', this.onGraphResize)
|
|
240
|
-
this.lfMap.destroy()
|
|
241
|
-
// 保证重新创建实例时,小地图中内容偏移正确
|
|
242
|
-
this.translateX = 0
|
|
243
|
-
this.translateY = 0
|
|
244
|
-
|
|
245
|
-
this.removeMiniMap()
|
|
246
|
-
this.lf.emit('miniMap:close', {})
|
|
247
|
-
}
|
|
248
|
-
this.isShow = false
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* 更新小地图在画布中的位置
|
|
252
|
-
* @param {MiniMapPosition} position
|
|
253
|
-
*/
|
|
254
|
-
public updatePosition = (position: MiniMapPosition) => {
|
|
255
|
-
if (typeof position === 'object') {
|
|
256
|
-
if (position.left !== undefined || position.right !== undefined) {
|
|
257
|
-
this.leftPosition = position.left
|
|
258
|
-
this.rightPosition = position.right
|
|
259
|
-
}
|
|
260
|
-
if (position.top !== undefined || position.bottom !== undefined) {
|
|
261
|
-
this.topPosition = position.top
|
|
262
|
-
this.bottomPosition = position.bottom
|
|
263
|
-
}
|
|
264
|
-
} else {
|
|
265
|
-
switch (position) {
|
|
266
|
-
case 'left-top':
|
|
267
|
-
this.leftPosition = 0
|
|
268
|
-
this.rightPosition = undefined
|
|
269
|
-
this.topPosition = 0
|
|
270
|
-
this.bottomPosition = undefined
|
|
271
|
-
break
|
|
272
|
-
case 'right-top':
|
|
273
|
-
this.leftPosition = undefined
|
|
274
|
-
this.rightPosition = 0
|
|
275
|
-
this.topPosition = 0
|
|
276
|
-
this.bottomPosition = undefined
|
|
277
|
-
break
|
|
278
|
-
case 'left-bottom':
|
|
279
|
-
this.leftPosition = 0
|
|
280
|
-
this.rightPosition = undefined
|
|
281
|
-
this.topPosition = undefined
|
|
282
|
-
this.bottomPosition = 0
|
|
283
|
-
break
|
|
284
|
-
case 'right-bottom':
|
|
285
|
-
this.leftPosition = undefined
|
|
286
|
-
this.rightPosition = 0
|
|
287
|
-
this.topPosition = undefined
|
|
288
|
-
this.bottomPosition = 0
|
|
289
|
-
break
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
this.updateMiniMapPosition()
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* 重置主画布的缩放和平移
|
|
296
|
-
*/
|
|
297
|
-
public reset = () => {
|
|
298
|
-
this.lf.resetTranslate()
|
|
299
|
-
this.lf.resetZoom()
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* 设置小地图的画布中是否显示边
|
|
303
|
-
* @param {boolean} showEdge
|
|
304
|
-
*/
|
|
305
|
-
public setShowEdge = (showEdge: boolean) => {
|
|
306
|
-
if (this.showEdge !== showEdge) {
|
|
307
|
-
this.showEdge = showEdge
|
|
308
|
-
this.setView()
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* 初始化小地图的配置
|
|
314
|
-
* @param options
|
|
315
|
-
*/
|
|
316
|
-
private setOption(options: MiniMapOption) {
|
|
317
|
-
const {
|
|
318
|
-
width = 200,
|
|
319
|
-
height = 150,
|
|
320
|
-
showEdge = false,
|
|
321
|
-
isShowHeader = false,
|
|
322
|
-
isShowCloseIcon = false,
|
|
323
|
-
leftPosition,
|
|
324
|
-
topPosition,
|
|
325
|
-
rightPosition = 0,
|
|
326
|
-
bottomPosition = 0,
|
|
327
|
-
headerTitle = '导航',
|
|
328
|
-
} = options
|
|
329
|
-
this.width = width
|
|
330
|
-
this.height = height
|
|
331
|
-
this.showEdge = showEdge
|
|
332
|
-
this.isShowHeader = isShowHeader
|
|
333
|
-
this.isShowCloseIcon = isShowCloseIcon
|
|
334
|
-
this.leftPosition = leftPosition
|
|
335
|
-
this.rightPosition = leftPosition !== undefined ? undefined : rightPosition
|
|
336
|
-
this.topPosition = topPosition
|
|
337
|
-
this.bottomPosition = topPosition !== undefined ? undefined : bottomPosition
|
|
338
|
-
this.headerTitle = headerTitle
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* 初始化小地图的 LogicFlow 实例
|
|
343
|
-
*/
|
|
344
|
-
private initMiniMap() {
|
|
345
|
-
const miniMapWrap = document.createElement('div')
|
|
346
|
-
miniMapWrap.className = 'lf-mini-map-graph'
|
|
347
|
-
miniMapWrap.style.width = `${this.width}px`
|
|
348
|
-
miniMapWrap.style.height = `${this.height}px`
|
|
349
|
-
this.lfMap = new this.LFCtor({
|
|
350
|
-
container: miniMapWrap,
|
|
351
|
-
grid: false,
|
|
352
|
-
isSilentMode: true,
|
|
353
|
-
stopZoomGraph: true,
|
|
354
|
-
stopScrollGraph: true,
|
|
355
|
-
// 禁用画布移动会导致 transformModel.translate 无效,所以这里不禁用
|
|
356
|
-
stopMoveGraph: false,
|
|
357
|
-
history: false,
|
|
358
|
-
snapline: false,
|
|
359
|
-
disabledPlugins: this.disabledPlugins,
|
|
360
|
-
isMiniMap: true,
|
|
361
|
-
})
|
|
362
|
-
// minimap中禁用adapter。
|
|
363
|
-
// this.lfMap.adapterIn = (a) => a
|
|
364
|
-
// this.lfMap.adapterOut = (a) => a
|
|
365
|
-
|
|
366
|
-
this.miniMapWrap = miniMapWrap
|
|
367
|
-
this.createViewPort()
|
|
368
|
-
miniMapWrap.addEventListener('click', this.mapClick)
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
private createMiniMap(left?: number, top?: number) {
|
|
372
|
-
const miniMapContainer = document.createElement('div')
|
|
373
|
-
this.miniMapContainer = miniMapContainer
|
|
374
|
-
miniMapContainer.appendChild(this.miniMapWrap)
|
|
375
|
-
|
|
376
|
-
miniMapContainer.style.position = 'absolute'
|
|
377
|
-
if (left !== undefined || top !== undefined) {
|
|
378
|
-
this.leftPosition = left || 0
|
|
379
|
-
this.topPosition = top || 0
|
|
380
|
-
this.rightPosition = undefined
|
|
381
|
-
this.bottomPosition = undefined
|
|
382
|
-
}
|
|
383
|
-
this.updateMiniMapPosition()
|
|
384
|
-
|
|
385
|
-
miniMapContainer.className = 'lf-mini-map'
|
|
386
|
-
if (!this.isShowCloseIcon) {
|
|
387
|
-
miniMapContainer.classList.add('lf-mini-map-no-close-icon')
|
|
388
|
-
}
|
|
389
|
-
if (!this.isShowHeader) {
|
|
390
|
-
miniMapContainer.classList.add('lf-mini-map-no-header')
|
|
391
|
-
}
|
|
392
|
-
this.container?.appendChild(miniMapContainer)
|
|
393
|
-
this.miniMapWrap.appendChild(this.viewport)
|
|
394
|
-
|
|
395
|
-
const header = document.createElement('div')
|
|
396
|
-
header.className = 'lf-mini-map-header'
|
|
397
|
-
header.innerText = this.headerTitle
|
|
398
|
-
miniMapContainer.appendChild(header)
|
|
399
|
-
|
|
400
|
-
const close = document.createElement('span')
|
|
401
|
-
close.className = 'lf-mini-map-close'
|
|
402
|
-
close.addEventListener('click', this.hide)
|
|
403
|
-
miniMapContainer.appendChild(close)
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
private updateMiniMapPosition() {
|
|
407
|
-
if (this.miniMapContainer) {
|
|
408
|
-
const { style } = this.miniMapContainer
|
|
409
|
-
|
|
410
|
-
if (this.rightPosition !== undefined) {
|
|
411
|
-
style.right = `${this.rightPosition}px`
|
|
412
|
-
style.left = ''
|
|
413
|
-
} else {
|
|
414
|
-
style.left = `${this.leftPosition}px`
|
|
415
|
-
style.right = ''
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
if (this.bottomPosition !== undefined) {
|
|
419
|
-
style.bottom = `${this.bottomPosition}px`
|
|
420
|
-
style.top = ''
|
|
421
|
-
} else {
|
|
422
|
-
style.top = `${this.topPosition}px`
|
|
423
|
-
style.bottom = ''
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
private removeMiniMap() {
|
|
429
|
-
if (this.miniMapContainer) {
|
|
430
|
-
this.container?.removeChild(this.miniMapContainer)
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* 更新小地图的区域范围
|
|
436
|
-
* @param data
|
|
437
|
-
*/
|
|
438
|
-
private updateBounds(data?: LogicFlow.GraphData) {
|
|
439
|
-
if (data) {
|
|
440
|
-
this.updateElementAreaBounds(data)
|
|
441
|
-
}
|
|
442
|
-
this.updateViewPortBounds()
|
|
443
|
-
this.bounds = {
|
|
444
|
-
left: Math.min(this.elementAreaBounds.left, this.viewPortBounds.left),
|
|
445
|
-
right: Math.max(this.elementAreaBounds.right, this.viewPortBounds.right),
|
|
446
|
-
top: Math.min(this.elementAreaBounds.top, this.viewPortBounds.top),
|
|
447
|
-
bottom: Math.max(
|
|
448
|
-
this.elementAreaBounds.bottom,
|
|
449
|
-
this.viewPortBounds.bottom,
|
|
450
|
-
),
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* 计算所有图形一起,占领的区域范围。
|
|
456
|
-
* @param data
|
|
457
|
-
*/
|
|
458
|
-
private updateElementAreaBounds(data: LogicFlow.GraphData) {
|
|
459
|
-
const elementAreaBounds: Bounds = {
|
|
460
|
-
left: 0,
|
|
461
|
-
right: 0,
|
|
462
|
-
top: 0,
|
|
463
|
-
bottom: 0,
|
|
464
|
-
}
|
|
465
|
-
const { nodes } = data
|
|
466
|
-
if (nodes && nodes.length > 0) {
|
|
467
|
-
// TODO: 后续能获取节点高宽信息后,需要更新这里的计算方式
|
|
468
|
-
nodes.forEach((node) => {
|
|
469
|
-
const { x, y } = node
|
|
470
|
-
const width = (node.width as number) ?? 200
|
|
471
|
-
const height = (node.height as number) ?? 200
|
|
472
|
-
|
|
473
|
-
const nodeLeft = x - width / 2
|
|
474
|
-
const nodeRight = x + width / 2
|
|
475
|
-
const nodeTop = y - height / 2
|
|
476
|
-
const nodeBottom = y + height / 2
|
|
477
|
-
|
|
478
|
-
elementAreaBounds.left = Math.min(nodeLeft, elementAreaBounds.left)
|
|
479
|
-
elementAreaBounds.right = Math.max(nodeRight, elementAreaBounds.right)
|
|
480
|
-
elementAreaBounds.top = Math.min(nodeTop, elementAreaBounds.top)
|
|
481
|
-
elementAreaBounds.bottom = Math.max(
|
|
482
|
-
nodeBottom,
|
|
483
|
-
elementAreaBounds.bottom,
|
|
484
|
-
)
|
|
485
|
-
})
|
|
486
|
-
}
|
|
487
|
-
this.elementAreaBounds = elementAreaBounds
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* 获取视口范围
|
|
492
|
-
*/
|
|
493
|
-
private updateViewPortBounds() {
|
|
494
|
-
const { TRANSLATE_X, TRANSLATE_Y, SCALE_X, SCALE_Y } =
|
|
495
|
-
this.lf.getTransform()
|
|
496
|
-
const { width, height } = this.lf.graphModel
|
|
497
|
-
|
|
498
|
-
this.viewPortBounds = {
|
|
499
|
-
left: -TRANSLATE_X / SCALE_X,
|
|
500
|
-
right: (-TRANSLATE_X + width) / SCALE_X,
|
|
501
|
-
top: -TRANSLATE_Y / SCALE_Y,
|
|
502
|
-
bottom: (-TRANSLATE_Y + height) / SCALE_Y,
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* 删除部分内容以简化渲染,包括边与节点文本
|
|
508
|
-
*/
|
|
509
|
-
private resetData(data: LogicFlow.GraphData): LogicFlow.GraphData {
|
|
510
|
-
const { nodes, edges } = data
|
|
511
|
-
nodes.forEach((node) => {
|
|
512
|
-
// 删除节点文本
|
|
513
|
-
node.text = undefined
|
|
514
|
-
})
|
|
515
|
-
if (this.showEdge) {
|
|
516
|
-
edges.forEach((edge) => {
|
|
517
|
-
// 删除边上的文本
|
|
518
|
-
edge.text = undefined
|
|
519
|
-
})
|
|
520
|
-
}
|
|
521
|
-
return {
|
|
522
|
-
nodes,
|
|
523
|
-
// 是否渲染边
|
|
524
|
-
edges: this.showEdge ? edges : [],
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* MiniMap视图重绘
|
|
530
|
-
* @param reRender 是否重新渲染画布元素
|
|
531
|
-
*/
|
|
532
|
-
// TODO: 确定 render 函数是否为增量渲染,如果是则不需要 reRender 参数做限制
|
|
533
|
-
private setView(reRender: boolean = true) {
|
|
534
|
-
if (reRender) {
|
|
535
|
-
// 1. 获取到图中所有的节点中的位置
|
|
536
|
-
const graphData = this.lf.getGraphRawData()
|
|
537
|
-
const data = this.resetData(graphData)
|
|
538
|
-
// 由于随时都会有新节点注册进来,需要同步将注册的
|
|
539
|
-
const { viewMap } = this.lf
|
|
540
|
-
const { modelMap } = this.lf.graphModel
|
|
541
|
-
const { viewMap: minimapViewMap } = this.lfMap
|
|
542
|
-
|
|
543
|
-
for (const key of viewMap.keys()) {
|
|
544
|
-
if (!minimapViewMap.has(key)) {
|
|
545
|
-
this.lfMap.register({
|
|
546
|
-
type: key,
|
|
547
|
-
view: viewMap.get(key)!,
|
|
548
|
-
model: modelMap.get(key)!,
|
|
549
|
-
})
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
// 2. 将数据渲染到小地图的画布上
|
|
554
|
-
this.lfMap.render(data)
|
|
555
|
-
|
|
556
|
-
// 3. 更新所有节点与当前视口构成的区域范围
|
|
557
|
-
this.updateBounds(data)
|
|
558
|
-
} else {
|
|
559
|
-
this.updateBounds()
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
// 4. 计算小地图画布相对小地图容器的缩放比例,并移动小地图的视图保证元素全部可见且整体居中。
|
|
563
|
-
const { left, top, right, bottom } = this.bounds
|
|
564
|
-
const realWidth = right - left
|
|
565
|
-
const realHeight = bottom - top
|
|
566
|
-
const realWidthScale = this.width / realWidth
|
|
567
|
-
const realHeightScale = this.height / realHeight
|
|
568
|
-
const scale = Math.min(realWidthScale, realHeightScale)
|
|
569
|
-
this.scale = scale
|
|
570
|
-
|
|
571
|
-
const translateX = left - (this.width / scale - realWidth) / 2
|
|
572
|
-
const translateY = top - (this.height / scale - realHeight) / 2
|
|
573
|
-
this.lfMap.graphModel.transformModel.translate(
|
|
574
|
-
-translateX + this.translateX,
|
|
575
|
-
-translateY + this.translateY,
|
|
576
|
-
)
|
|
577
|
-
this.translateX = translateX
|
|
578
|
-
this.translateY = translateY
|
|
579
|
-
|
|
580
|
-
// 5. 将小地图的画布缩放对应的比例。
|
|
581
|
-
if (this.miniMapWrap.firstChild) {
|
|
582
|
-
const innerStyle = (this.miniMapWrap.firstChild as HTMLElement).style
|
|
583
|
-
innerStyle.pointerEvents = 'none'
|
|
584
|
-
innerStyle.transform = `matrix(${scale}, 0, 0, ${scale}, 0, 0)`
|
|
585
|
-
innerStyle.transformOrigin = 'left top'
|
|
586
|
-
innerStyle.height = `${this.height / scale}px`
|
|
587
|
-
innerStyle.width = `${this.width / scale}px`
|
|
588
|
-
this.updateViewPort()
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
/**
|
|
593
|
-
* 更新预览视窗的位置
|
|
594
|
-
*/
|
|
595
|
-
private updateViewPort() {
|
|
596
|
-
const viewStyle = this.viewport.style
|
|
597
|
-
const { TRANSLATE_X, TRANSLATE_Y, SCALE_X, SCALE_Y } =
|
|
598
|
-
this.lf.getTransform()
|
|
599
|
-
const { width, height } = this.lf.graphModel
|
|
600
|
-
|
|
601
|
-
this.viewPortLeft = -TRANSLATE_X / SCALE_X
|
|
602
|
-
this.viewPortTop = -TRANSLATE_Y / SCALE_Y
|
|
603
|
-
this.viewPortWidth = (width / SCALE_X) * this.scale
|
|
604
|
-
this.viewPortHeight = (height / SCALE_Y) * this.scale
|
|
605
|
-
|
|
606
|
-
viewStyle.width = `${this.viewPortWidth}px`
|
|
607
|
-
viewStyle.height = `${this.viewPortHeight}px`
|
|
608
|
-
viewStyle.left = `${(this.viewPortLeft - this.translateX) * this.scale}px`
|
|
609
|
-
viewStyle.top = `${(this.viewPortTop - this.translateY) * this.scale}px`
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
/**
|
|
613
|
-
* 创建预览视窗元素
|
|
614
|
-
*/
|
|
615
|
-
private createViewPort() {
|
|
616
|
-
const div = document.createElement('div')
|
|
617
|
-
div.className = 'lf-minimap-viewport'
|
|
618
|
-
|
|
619
|
-
div.style.touchAction = 'none'
|
|
620
|
-
div.addEventListener('pointerdown', this.startDrag)
|
|
621
|
-
|
|
622
|
-
// 禁止预览视窗的点击事件冒泡
|
|
623
|
-
div.addEventListener('click', (e: MouseEvent) => {
|
|
624
|
-
e.stopPropagation()
|
|
625
|
-
})
|
|
626
|
-
this.viewport = div
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
private startDrag = (e: PointerEvent) => {
|
|
630
|
-
document.addEventListener('pointermove', this.drag)
|
|
631
|
-
document.addEventListener('pointerup', this.drop)
|
|
632
|
-
const { x, y } = e
|
|
633
|
-
this.startPosition = { x, y }
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
/**
|
|
637
|
-
* 拖拽预览视窗过程中,更新主画布视口
|
|
638
|
-
*/
|
|
639
|
-
private drag = (e: PointerEvent) => {
|
|
640
|
-
const { x, y } = e
|
|
641
|
-
const translateX = (x - this.startPosition.x) / this.scale
|
|
642
|
-
const translateY = (y - this.startPosition.y) / this.scale
|
|
643
|
-
const centerX =
|
|
644
|
-
this.viewPortLeft + translateX + this.viewPortWidth / this.scale / 2
|
|
645
|
-
const centerY =
|
|
646
|
-
this.viewPortTop + translateY + this.viewPortHeight / this.scale / 2
|
|
647
|
-
|
|
648
|
-
// 每移动一次预览视窗都需要更新拖拽的起始点
|
|
649
|
-
this.startPosition = { x, y }
|
|
650
|
-
this.lf.focusOn({
|
|
651
|
-
coordinate: {
|
|
652
|
-
x: centerX,
|
|
653
|
-
y: centerY,
|
|
654
|
-
},
|
|
655
|
-
})
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* 拖拽预览视窗结束,移除拖拽事件
|
|
660
|
-
*/
|
|
661
|
-
private drop = () => {
|
|
662
|
-
document.removeEventListener('pointermove', this.drag)
|
|
663
|
-
document.removeEventListener('pointerup', this.drop)
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
/**
|
|
667
|
-
* 点击小地图中非预览视窗的区域时,移动主画布视口聚焦于点击位置
|
|
668
|
-
*/
|
|
669
|
-
private mapClick = (e: MouseEvent) => {
|
|
670
|
-
const { offsetX, offsetY } = e
|
|
671
|
-
const centerX = this.translateX + offsetX / this.scale
|
|
672
|
-
const centerY = this.translateY + offsetY / this.scale
|
|
673
|
-
this.lf.focusOn({
|
|
674
|
-
coordinate: {
|
|
675
|
-
x: centerX,
|
|
676
|
-
y: centerY,
|
|
677
|
-
},
|
|
678
|
-
})
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
destroy() {
|
|
682
|
-
this.lf.off('graph:resize', this.onGraphResize)
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
export default MiniMap
|