fix(extension): 【dynamic-group】修复resize和move的冲突问题(#1826) #1858
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
related: #1826
问题出现的原因
目前
dynamic-group
的resize
操作存在两个问题:group
里面的item
没有按照比例进行缩放group
缩放时,会触发this.x
和this.y
的改变,同时也会触发group.item
的this.x
和this.y
改变,然后group
的resize
再次出发group.item
的this.x
和this.y
的改变,从而造成了两倍,也就是this.x=this.x+2*deltaX
问题1分析
由于比较简单,因此这里不再做详细分析,如下图所示,应该根据group.item.width在group.width所占的比例进行deltaX的换算
问题2分析
而上面的this.graphModel.nodeMoveRules就是在
packages/extension/src/dynamic-group/index.ts
中增加的移动规则因此
group
缩放时,会触发this.x
和this.y
的改变,同时也会触发group.item
的this.x
和this.y
改变然后
group
的resize
再次出发group.item
的this.x
和this.y
的改变,如下面代码所示从而造成了两倍,也就是
this.x=this.x+2*deltaX
的现象解决方法
问题1的解决方法
由于比较简单,因此这里直接贴代码展示,困惑点可能在于如果拿到group.width
在
node:resize
触发时,我们从下面代码可以知道,其实已经是调用nodeModel.resize(nextSize)
才触发triggerResizeEvent
,因此我们在node:resize
拿到的nodeModel
是已经缩放完成的width
和height
,我们需要拿没有resize
之前的width
和height
去计算比例值,因此我们只能使用preNodeData
而这里有个奇怪的地方,虽然我们
nodeModel.resize
的时候(如下面代码所示),是进行了setProperties({width,height})
,但是我们如果一开始没有传入properties: {width:xxx, height:xxx}
,那我们上面代码中获取preNodeData
拿到的properties
是没有width
和height
,也无法从preNodeData
拿到width
和height
因此为了避免首次
preNodeData
中拿不到width
和height
问题2的解决方法
问题2的核心问题是,在校验是否允许移动时,就进行了group.item的移动操作,因此我觉得应该移除这个逻辑
然后将
resize
和move
两种操作分开处理,也就是监听测试效果
pr-5_compressed.mp4
如上面视频所示,
resize
和move
都正常了,但是可以看出,分组缩小并没有限制,与下面两个issues反应的问题应该是一样的,这可能需要再另外进行优化处理