@logicflow/core 2.0.3 → 2.0.5
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/.turbo/turbo-build$colon$dev.log +2 -2
- package/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +18 -0
- package/package.json +1 -1
- package/src/algorithm/rotate.ts +55 -0
- package/src/model/node/BaseNodeModel.ts +17 -1
- package/src/util/graph.ts +1 -1
- package/src/util/resize.ts +238 -12
- package/src/view/Control.tsx +7 -1
- package/stats.html +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
> @logicflow/core@2.0.
|
|
2
|
+
> @logicflow/core@2.0.3 build:dev /Users/didi/Desktop/github/LogicFlow/packages/core
|
|
3
3
|
> rss
|
|
4
4
|
|
|
5
5
|
> [build:dev] pnpm run --if-present build:less && run-p -s build:cjs build:esm
|
|
6
6
|
|
|
7
|
-
> @logicflow/core@2.0.
|
|
7
|
+
> @logicflow/core@2.0.3 build:less /Users/didi/Desktop/github/LogicFlow/packages/core
|
|
8
8
|
> rss
|
|
9
9
|
|
|
10
10
|
> [build:less] ./scripts/build-less
|
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
|
-
> @logicflow/core@2.0.
|
|
2
|
+
> @logicflow/core@2.0.3 prebuild /Users/didi/Desktop/github/LogicFlow/packages/core
|
|
3
3
|
> rss
|
|
4
4
|
|
|
5
5
|
> [prebuild] run-s -s clean:build
|
|
6
6
|
> [clean:build] rimraf dist es lib
|
|
7
7
|
|
|
8
|
-
> @logicflow/core@2.0.
|
|
8
|
+
> @logicflow/core@2.0.3 build /Users/didi/Desktop/github/LogicFlow/packages/core
|
|
9
9
|
> rss
|
|
10
10
|
|
|
11
11
|
> [build] run-p -s build:dev build:umd
|
|
@@ -30,4 +30,4 @@ src/index.ts -> src/LogicFlow.tsx -> src/index.ts
|
|
|
30
30
|
src/util/index.ts -> src/util/edge.ts -> src/util/index.ts
|
|
31
31
|
src/util/index.ts -> src/util/edge.ts -> src/algorithm/index.ts -> src/algorithm/outline.ts -> src/util/index.ts
|
|
32
32
|
...and 18 more
|
|
33
|
-
[32mcreated [1mdist/index.min.js[22m in [
|
|
33
|
+
[32mcreated [1mdist/index.min.js[22m in [1m16s[22m[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix(core&extension): fix bugs from issues
|
|
8
|
+
- fix(core): update import path to relative path style to remove compile error in angular(修复angular中引用后编译报错问题)
|
|
9
|
+
- fix(core): 修复BaseNodeModel的getData()拿不到width和height的问题(#1826)
|
|
10
|
+
- fix(core): node => rotate+正常模式resize(#1428)
|
|
11
|
+
- fix(core): 外部调用handleResize()没有传入anchor坐标不触发recalcRotatedResizeInfo方法
|
|
12
|
+
- chore(core): rotate+正常模式resize的相关变量名称从anchor改为control
|
|
13
|
+
|
|
14
|
+
## 2.0.4
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- fix: 修复节点文本设置draggable和editable不生效问题
|
|
19
|
+
|
|
3
20
|
## 2.0.3
|
|
4
21
|
|
|
5
22
|
### Patch Changes: Release 2.0.3 Version
|
|
23
|
+
|
|
6
24
|
- chore: 新增 rollup.config 将 extension less 文件打包成 css,并不在 js 中引入 less
|
|
7
25
|
- 解决 BaseEdgeModel 中 setProperty 方法使用 set 时报错的 bug
|
|
8
26
|
- isIe 调整为方法,解决 ssr 项目中 window is not defined 的问题 close #1524
|
package/package.json
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface SimplePoint {
|
|
2
|
+
x: number
|
|
3
|
+
y: number
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 根据两个点获取中心点坐标
|
|
8
|
+
*/
|
|
9
|
+
export function getNewCenter(startPoint: SimplePoint, endPoint: SimplePoint) {
|
|
10
|
+
const { x: x1, y: y1 } = startPoint
|
|
11
|
+
const { x: x2, y: y2 } = endPoint
|
|
12
|
+
const newCenter = {
|
|
13
|
+
x: x1 + (x2 - x1) / 2,
|
|
14
|
+
y: y1 + (y2 - y1) / 2,
|
|
15
|
+
}
|
|
16
|
+
return newCenter
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 旋转矩阵公式,可以获取某一个坐标旋转angle后的坐标
|
|
21
|
+
* @param p 当前坐标
|
|
22
|
+
* @param center 旋转中心
|
|
23
|
+
* @param angle 旋转角度(不是弧度)
|
|
24
|
+
*/
|
|
25
|
+
export function calculatePointAfterRotateAngle(
|
|
26
|
+
p: SimplePoint,
|
|
27
|
+
center: SimplePoint,
|
|
28
|
+
angle: number,
|
|
29
|
+
) {
|
|
30
|
+
const radian = angleToRadian(angle)
|
|
31
|
+
const dx = p.x - center.x
|
|
32
|
+
const dy = p.y - center.y
|
|
33
|
+
const x = dx * Math.cos(radian) - dy * Math.sin(radian) + center.x
|
|
34
|
+
const y = dx * Math.sin(radian) + dy * Math.cos(radian) + center.y
|
|
35
|
+
return {
|
|
36
|
+
x,
|
|
37
|
+
y,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 角度转弧度
|
|
43
|
+
* @param angle 角度
|
|
44
|
+
*/
|
|
45
|
+
export function angleToRadian(angle: number) {
|
|
46
|
+
return (angle * Math.PI) / 180
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 弧度转角度
|
|
51
|
+
* @param radian 弧度
|
|
52
|
+
*/
|
|
53
|
+
export function radianToAngle(radian: number) {
|
|
54
|
+
return (radian / Math.PI) * 180
|
|
55
|
+
}
|
|
@@ -267,7 +267,7 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
|
|
|
267
267
|
textConfig.draggable = text.draggable
|
|
268
268
|
}
|
|
269
269
|
if (!isUndefined(text.editable)) {
|
|
270
|
-
textConfig.
|
|
270
|
+
textConfig.editable = text.editable
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
}
|
|
@@ -306,6 +306,18 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
|
|
|
306
306
|
if (isObservable(properties)) {
|
|
307
307
|
properties = toJS(properties)
|
|
308
308
|
}
|
|
309
|
+
if (isNil(properties.width)) {
|
|
310
|
+
// resize()的时候会触发this.setProperties({width,height})
|
|
311
|
+
// 然后返回getData(),可以从properties拿到width
|
|
312
|
+
// 但是初始化如果没有在properties传入width,那么getData()就一直无法从properties拿到width
|
|
313
|
+
properties.width = this.width
|
|
314
|
+
}
|
|
315
|
+
if (isNil(properties.height)) {
|
|
316
|
+
// resize()的时候会触发this.setProperties({width,height})
|
|
317
|
+
// 然后返回getData(),可以从properties拿到height
|
|
318
|
+
// 但是初始化如果没有在properties传入height,那么getData()就一直无法从properties拿到width
|
|
319
|
+
properties.height = this.height
|
|
320
|
+
}
|
|
309
321
|
const data: NodeData = {
|
|
310
322
|
id: this.id,
|
|
311
323
|
type: this.type,
|
|
@@ -687,6 +699,10 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
|
|
|
687
699
|
this.y = this.y + deltaY
|
|
688
700
|
this.text && this.moveText(0, deltaY)
|
|
689
701
|
}
|
|
702
|
+
if (isAllowMoveX || isAllowMoveY) {
|
|
703
|
+
// 更新x和y的同时也要更新对应的transform旋转矩阵(依赖x、y)
|
|
704
|
+
this.rotate = this._rotate
|
|
705
|
+
}
|
|
690
706
|
return isAllowMoveX || isAllowMoveY
|
|
691
707
|
}
|
|
692
708
|
|
package/src/util/graph.ts
CHANGED
package/src/util/resize.ts
CHANGED
|
@@ -5,6 +5,70 @@ import { EventType } from '../constant'
|
|
|
5
5
|
|
|
6
6
|
import ResizeInfo = ResizeControl.ResizeInfo
|
|
7
7
|
import ResizeNodeData = ResizeControl.ResizeNodeData
|
|
8
|
+
import {
|
|
9
|
+
calculatePointAfterRotateAngle,
|
|
10
|
+
getNewCenter,
|
|
11
|
+
radianToAngle,
|
|
12
|
+
} from '../algorithm/rotate'
|
|
13
|
+
import type { SimplePoint } from '../algorithm/rotate'
|
|
14
|
+
|
|
15
|
+
function recalcRotatedResizeInfo(
|
|
16
|
+
pct: number,
|
|
17
|
+
resizeInfo: ResizeInfo,
|
|
18
|
+
rotate: number,
|
|
19
|
+
controlX: number,
|
|
20
|
+
controlY: number,
|
|
21
|
+
oldCenterX: number,
|
|
22
|
+
oldCenterY: number,
|
|
23
|
+
freezeWidth = false,
|
|
24
|
+
freezeHeight = false,
|
|
25
|
+
) {
|
|
26
|
+
// 假设我们触摸的点是右下角的control
|
|
27
|
+
const { deltaX, deltaY, width: oldWidth, height: oldHeight } = resizeInfo
|
|
28
|
+
const angle = radianToAngle(rotate)
|
|
29
|
+
|
|
30
|
+
// 右下角的control
|
|
31
|
+
const startZeroTouchControlPoint = {
|
|
32
|
+
x: controlX, // control锚点的坐标x
|
|
33
|
+
y: controlY, // control锚点的坐标y
|
|
34
|
+
}
|
|
35
|
+
const oldCenter = { x: oldCenterX, y: oldCenterY }
|
|
36
|
+
// 右下角的control坐标(transform后的-touchStartPoint)
|
|
37
|
+
const startRotatedTouchControlPoint = calculatePointAfterRotateAngle(
|
|
38
|
+
startZeroTouchControlPoint,
|
|
39
|
+
oldCenter,
|
|
40
|
+
angle,
|
|
41
|
+
)
|
|
42
|
+
// 右下角的control坐标(transform后的-touchEndPoint)
|
|
43
|
+
const endRotatedTouchControlPoint = {
|
|
44
|
+
x: startRotatedTouchControlPoint.x + deltaX,
|
|
45
|
+
y: startRotatedTouchControlPoint.y + deltaY,
|
|
46
|
+
}
|
|
47
|
+
// 计算出新的宽度和高度以及新的中心点
|
|
48
|
+
const {
|
|
49
|
+
width: newWidth,
|
|
50
|
+
height: newHeight,
|
|
51
|
+
center: newCenter,
|
|
52
|
+
} = calculateWidthAndHeight(
|
|
53
|
+
startRotatedTouchControlPoint,
|
|
54
|
+
endRotatedTouchControlPoint,
|
|
55
|
+
oldCenter,
|
|
56
|
+
angle,
|
|
57
|
+
freezeWidth,
|
|
58
|
+
freezeHeight,
|
|
59
|
+
oldWidth,
|
|
60
|
+
oldHeight,
|
|
61
|
+
)
|
|
62
|
+
// calculateWidthAndHeight()得到的是整个宽度,比如圆pct=0.5,此时newWidth等于整个圆直径
|
|
63
|
+
resizeInfo.width = newWidth * pct
|
|
64
|
+
resizeInfo.height = newHeight * pct
|
|
65
|
+
|
|
66
|
+
// BaseNodeModel.resize(deltaX/2, deltaY/2),因此这里要*2
|
|
67
|
+
resizeInfo.deltaX = (newCenter.x - oldCenter.x) * 2
|
|
68
|
+
resizeInfo.deltaY = (newCenter.y - oldCenter.y) * 2
|
|
69
|
+
|
|
70
|
+
return resizeInfo
|
|
71
|
+
}
|
|
8
72
|
|
|
9
73
|
/**
|
|
10
74
|
* 计算 Control 拖动后,节点的高度信息
|
|
@@ -20,6 +84,11 @@ export const recalcResizeInfo = (
|
|
|
20
84
|
pct = 1,
|
|
21
85
|
freezeWidth = false,
|
|
22
86
|
freezeHeight = false,
|
|
87
|
+
rotate = 0,
|
|
88
|
+
controlX: number | undefined,
|
|
89
|
+
controlY: number | undefined,
|
|
90
|
+
oldCenterX: number,
|
|
91
|
+
oldCenterY: number,
|
|
23
92
|
): ResizeInfo => {
|
|
24
93
|
const nextResizeInfo = cloneDeep(resizeInfo)
|
|
25
94
|
let { deltaX, deltaY } = nextResizeInfo
|
|
@@ -100,6 +169,26 @@ export const recalcResizeInfo = (
|
|
|
100
169
|
}
|
|
101
170
|
return nextResizeInfo
|
|
102
171
|
}
|
|
172
|
+
if (
|
|
173
|
+
rotate % (2 * Math.PI) !== 0 &&
|
|
174
|
+
controlX !== undefined &&
|
|
175
|
+
controlY !== undefined
|
|
176
|
+
) {
|
|
177
|
+
// 角度rotate不为0,则触发另外的计算修正resize的deltaX和deltaY
|
|
178
|
+
// 因为rotate不为0的时候,左上角的坐标一直在变化
|
|
179
|
+
// 角度rotate不为0得到的resizeInfo.deltaX仅仅代表中心点的变化,而不是宽度的变化
|
|
180
|
+
return recalcRotatedResizeInfo(
|
|
181
|
+
pct,
|
|
182
|
+
nextResizeInfo,
|
|
183
|
+
rotate,
|
|
184
|
+
controlX,
|
|
185
|
+
controlY,
|
|
186
|
+
oldCenterX,
|
|
187
|
+
oldCenterY,
|
|
188
|
+
freezeWidth,
|
|
189
|
+
freezeHeight,
|
|
190
|
+
)
|
|
191
|
+
}
|
|
103
192
|
|
|
104
193
|
// 如果限制了宽/高不变,对应的 width/height 保持一致
|
|
105
194
|
switch (index) {
|
|
@@ -194,17 +283,21 @@ export const triggerResizeEvent = (
|
|
|
194
283
|
}
|
|
195
284
|
|
|
196
285
|
// TODO:确认 handleResize 函数的类型定义
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
286
|
+
export type IHandleResizeParams = {
|
|
287
|
+
x?: number
|
|
288
|
+
y?: number
|
|
289
|
+
deltaX: number
|
|
290
|
+
deltaY: number
|
|
291
|
+
index: ResizeControlIndex
|
|
292
|
+
nodeModel: BaseNodeModel
|
|
293
|
+
graphModel: GraphModel
|
|
294
|
+
cancelCallback?: () => void
|
|
295
|
+
}
|
|
205
296
|
|
|
206
297
|
/**
|
|
207
298
|
* 处理节点的 resize 事件,提出来放到 utils 中,方便在外面(extension)中使用
|
|
299
|
+
* @param x
|
|
300
|
+
* @param y
|
|
208
301
|
* @param deltaX
|
|
209
302
|
* @param deltaY
|
|
210
303
|
* @param index
|
|
@@ -213,13 +306,15 @@ export const triggerResizeEvent = (
|
|
|
213
306
|
* @param cancelCallback
|
|
214
307
|
*/
|
|
215
308
|
export const handleResize = ({
|
|
309
|
+
x,
|
|
310
|
+
y,
|
|
216
311
|
deltaX,
|
|
217
312
|
deltaY,
|
|
218
313
|
index,
|
|
219
314
|
nodeModel,
|
|
220
315
|
graphModel,
|
|
221
316
|
cancelCallback,
|
|
222
|
-
}) => {
|
|
317
|
+
}: IHandleResizeParams) => {
|
|
223
318
|
const {
|
|
224
319
|
r, // circle
|
|
225
320
|
rx, // ellipse/diamond
|
|
@@ -232,6 +327,9 @@ export const handleResize = ({
|
|
|
232
327
|
minHeight,
|
|
233
328
|
maxWidth,
|
|
234
329
|
maxHeight,
|
|
330
|
+
rotate,
|
|
331
|
+
x: oldCenterX,
|
|
332
|
+
y: oldCenterY,
|
|
235
333
|
} = nodeModel
|
|
236
334
|
const isFreezeWidth = minWidth === maxWidth
|
|
237
335
|
const isFreezeHeight = minHeight === maxHeight
|
|
@@ -245,12 +343,19 @@ export const handleResize = ({
|
|
|
245
343
|
}
|
|
246
344
|
|
|
247
345
|
const pct = r || (rx && ry) ? 1 / 2 : 1
|
|
346
|
+
const controlX = x
|
|
347
|
+
const controlY = y
|
|
248
348
|
const nextSize = recalcResizeInfo(
|
|
249
349
|
index,
|
|
250
350
|
resizeInfo,
|
|
251
351
|
pct,
|
|
252
352
|
isFreezeWidth,
|
|
253
353
|
isFreezeHeight,
|
|
354
|
+
rotate,
|
|
355
|
+
controlX,
|
|
356
|
+
controlY,
|
|
357
|
+
oldCenterX,
|
|
358
|
+
oldCenterY,
|
|
254
359
|
)
|
|
255
360
|
|
|
256
361
|
// 限制放大缩小的最大最小范围
|
|
@@ -264,9 +369,19 @@ export const handleResize = ({
|
|
|
264
369
|
cancelCallback?.()
|
|
265
370
|
return
|
|
266
371
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
372
|
+
if (
|
|
373
|
+
rotate % (2 * Math.PI) == 0 ||
|
|
374
|
+
PCTResizeInfo ||
|
|
375
|
+
controlX === undefined ||
|
|
376
|
+
controlY === undefined
|
|
377
|
+
) {
|
|
378
|
+
// rotate!==0并且不是PCTResizeInfo时,即使是isFreezeWidth||isFreezeHeight
|
|
379
|
+
// recalcRotatedResizeInfo()计算出来的中心点会发生变化
|
|
380
|
+
|
|
381
|
+
// 如果限制了宽高不变,对应的 x/y 不产生位移
|
|
382
|
+
nextSize.deltaX = isFreezeWidth ? 0 : nextSize.deltaX
|
|
383
|
+
nextSize.deltaY = isFreezeHeight ? 0 : nextSize.deltaY
|
|
384
|
+
}
|
|
270
385
|
|
|
271
386
|
const preNodeData = nodeModel.getData()
|
|
272
387
|
const curNodeData = nodeModel.resize(nextSize)
|
|
@@ -284,3 +399,114 @@ export const handleResize = ({
|
|
|
284
399
|
graphModel,
|
|
285
400
|
)
|
|
286
401
|
}
|
|
402
|
+
|
|
403
|
+
export function calculateWidthAndHeight(
|
|
404
|
+
startRotatedTouchControlPoint: SimplePoint,
|
|
405
|
+
endRotatedTouchControlPoint: SimplePoint,
|
|
406
|
+
oldCenter: SimplePoint,
|
|
407
|
+
angle: number,
|
|
408
|
+
freezeWidth = false,
|
|
409
|
+
freezeHeight = false,
|
|
410
|
+
oldWidth: number,
|
|
411
|
+
oldHeight: number,
|
|
412
|
+
) {
|
|
413
|
+
// 假设目前触摸的是右下角的control点
|
|
414
|
+
// 计算出来左上角的control坐标,resize过程左上角的control坐标保持不变
|
|
415
|
+
const freezePoint: SimplePoint = {
|
|
416
|
+
x: oldCenter.x - (startRotatedTouchControlPoint.x - oldCenter.x),
|
|
417
|
+
y: oldCenter.y - (startRotatedTouchControlPoint.y - oldCenter.y),
|
|
418
|
+
}
|
|
419
|
+
// 【touchEndPoint】右下角 + freezePoint左上角 计算出新的中心点
|
|
420
|
+
let newCenter = getNewCenter(freezePoint, endRotatedTouchControlPoint)
|
|
421
|
+
|
|
422
|
+
// 得到【touchEndPoint】右下角-没有transform的坐标
|
|
423
|
+
let endZeroTouchControlPoint: SimplePoint = calculatePointAfterRotateAngle(
|
|
424
|
+
endRotatedTouchControlPoint,
|
|
425
|
+
newCenter,
|
|
426
|
+
-angle,
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
// ---------- 使用transform之前的坐标计算出新的width和height ----------
|
|
430
|
+
|
|
431
|
+
// 得到左上角---没有transform的坐标
|
|
432
|
+
let zeroFreezePoint: SimplePoint = calculatePointAfterRotateAngle(
|
|
433
|
+
freezePoint,
|
|
434
|
+
newCenter,
|
|
435
|
+
-angle,
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
if (freezeWidth) {
|
|
439
|
+
// 如果固定width,那么不能单纯使用endZeroTouchControlPoint.x=startZeroTouchControlPoint.x
|
|
440
|
+
// 因为去掉transform的左上角不一定是重合的,我们要保证的是transform后的左上角重合
|
|
441
|
+
const newWidth = Math.abs(endZeroTouchControlPoint.x - zeroFreezePoint.x)
|
|
442
|
+
const widthDx = newWidth - oldWidth
|
|
443
|
+
|
|
444
|
+
// 点击的是左边锚点,是+widthDx/2,点击是右边锚点,是-widthDx/2
|
|
445
|
+
if (newCenter.x > endZeroTouchControlPoint.x) {
|
|
446
|
+
// 当前触摸的是左边锚点
|
|
447
|
+
newCenter.x = newCenter.x + widthDx / 2
|
|
448
|
+
} else {
|
|
449
|
+
// 当前触摸的是右边锚点
|
|
450
|
+
newCenter.x = newCenter.x - widthDx / 2
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
if (freezeHeight) {
|
|
454
|
+
const newHeight = Math.abs(endZeroTouchControlPoint.y - zeroFreezePoint.y)
|
|
455
|
+
const heightDy = newHeight - oldHeight
|
|
456
|
+
if (newCenter.y > endZeroTouchControlPoint.y) {
|
|
457
|
+
// 当前触摸的是上边锚点
|
|
458
|
+
newCenter.y = newCenter.y + heightDy / 2
|
|
459
|
+
} else {
|
|
460
|
+
newCenter.y = newCenter.y - heightDy / 2
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (freezeWidth || freezeHeight) {
|
|
465
|
+
// 如果调整过transform之前的坐标,那么transform后的坐标也会改变,那么算出来的newCenter也得调整
|
|
466
|
+
// 由于无论如何rotate,中心点都是不变的,因此我们可以使用transform之前的坐标算出新的中心点
|
|
467
|
+
const nowFreezePoint = calculatePointAfterRotateAngle(
|
|
468
|
+
zeroFreezePoint,
|
|
469
|
+
newCenter,
|
|
470
|
+
angle,
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
// 得到当前新rect的左上角与实际上transform后的左上角的偏移量
|
|
474
|
+
const dx = nowFreezePoint.x - freezePoint.x
|
|
475
|
+
const dy = nowFreezePoint.y - freezePoint.y
|
|
476
|
+
|
|
477
|
+
// 修正不使用transform的坐标: 左上角、右下角、center
|
|
478
|
+
newCenter.x = newCenter.x - dx
|
|
479
|
+
newCenter.y = newCenter.y - dy
|
|
480
|
+
zeroFreezePoint = calculatePointAfterRotateAngle(
|
|
481
|
+
freezePoint,
|
|
482
|
+
newCenter,
|
|
483
|
+
-angle,
|
|
484
|
+
)
|
|
485
|
+
endZeroTouchControlPoint = {
|
|
486
|
+
x: newCenter.x - (zeroFreezePoint.x - newCenter.x),
|
|
487
|
+
y: newCenter.y - (zeroFreezePoint.y - newCenter.y),
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// transform之前的坐标的左上角+右下角计算出宽度和高度
|
|
492
|
+
let width = Math.abs(endZeroTouchControlPoint.x - zeroFreezePoint.x)
|
|
493
|
+
let height = Math.abs(endZeroTouchControlPoint.y - zeroFreezePoint.y)
|
|
494
|
+
|
|
495
|
+
// ---------- 使用transform之前的坐标计算出新的width和height ----------
|
|
496
|
+
|
|
497
|
+
if (freezeWidth) {
|
|
498
|
+
// 理论计算出来的width应该等于oldWidth
|
|
499
|
+
// 但是有误差,比如oldWidth = 100; newWidth=100.000000000001
|
|
500
|
+
// 会在handleResize()限制放大缩小的最大最小范围中被阻止滑动
|
|
501
|
+
width = oldWidth
|
|
502
|
+
}
|
|
503
|
+
if (freezeHeight) {
|
|
504
|
+
height = oldHeight
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
return {
|
|
508
|
+
width,
|
|
509
|
+
height,
|
|
510
|
+
center: newCenter,
|
|
511
|
+
}
|
|
512
|
+
}
|
package/src/view/Control.tsx
CHANGED
|
@@ -56,6 +56,10 @@ export class ResizeControl extends Component<
|
|
|
56
56
|
})
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
componentWillUnmount() {
|
|
60
|
+
this.dragHandler.cancelDrag()
|
|
61
|
+
}
|
|
62
|
+
|
|
59
63
|
updateEdgePointByAnchors = () => {
|
|
60
64
|
// https://github.com/didi/LogicFlow/issues/807
|
|
61
65
|
// https://github.com/didi/LogicFlow/issues/875
|
|
@@ -241,10 +245,12 @@ export class ResizeControl extends Component<
|
|
|
241
245
|
|
|
242
246
|
resizeNode = ({ deltaX, deltaY }: VectorData) => {
|
|
243
247
|
const { index } = this
|
|
244
|
-
const { model, graphModel } = this.props
|
|
248
|
+
const { model, graphModel, x, y } = this.props
|
|
245
249
|
|
|
246
250
|
// DONE: 调用每个节点中更新缩放时的方法 updateNode 函数,用来各节点缩放的方法
|
|
247
251
|
handleResize({
|
|
252
|
+
x,
|
|
253
|
+
y,
|
|
248
254
|
deltaX,
|
|
249
255
|
deltaY,
|
|
250
256
|
index,
|