Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(extension): trigger updateEdgePointByAnchors() after moveTo(#1384) #1552

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

wbccb
Copy link
Contributor

@wbccb wbccb commented Apr 6, 2024

related: transform相关问题汇总
fix: #1384
fix: #1417

前言

这次pr不是重构缩放、旋转等transform操作相关逻辑,只是一个简单的bug修复,因为这个bug的产生是因为我之前pr#1205疏忽大意导致的问题

问题发生的原因

在上次pr#1205中,我在onDragEnd()中增加了一行代码this.updateEdgePointByAnchors(),代表的意思是:更新目前node节点所有连接的edge的所有连接点,如下面所示

// packages/extension/src/NodeResize/Control/Control.tsx
onDragEnd = () => {
       // 先触发onDragging()->更新边->再触发用户自定义的getDefaultAnchor(),所以onDragging()拿到的anchors是滞后的
       // 为了正确设置最终的位置,应该在拖拽结束的时候,再设置一次边的Point位置,此时拿到的anchors是最新的
+++   this.updateEdgePointByAnchors();

  
        const { gridSize = 1 } = this.graphModel;
        const x = gridSize * Math.round(this.nodeModel.x / gridSize);
        const y = gridSize * Math.round(this.nodeModel.y / gridSize);
        this.nodeModel.moveTo(x, y);
};

但是我加错位置了,我直接忽视了根据gridSize去修正node节点的相关xy的代码,直接无视了this.nodeModel.moveTo(x, y)这么明显的代码

上面方法翻译过来就是

// packages/extension/src/NodeResize/Control/Control.tsx
onDragEnd = () => {
    // 根据目前最新的anchor(依赖于最新的x和y坐标),然后去修正目前node和edge的连接点坐标

    // 根据gridSize去修正x和y坐标,然后moveTo()触发坐标更新->同时也会自动触发anchors的坐标更新
};

在触发this.nodeModel.moveTo(x, y),应该再次触发一次this.updateEdgePointByAnchors()才对(如下面代码所示)

// packages/extension/src/NodeResize/Control/Control.tsx
onDragEnd = () => {
  this.updateEdgePointByAnchors();

  const { gridSize = 1 } = this.graphModel;
  const x = gridSize * Math.round(this.nodeModel.x / gridSize);
  const y = gridSize * Math.round(this.nodeModel.y / gridSize);
  this.nodeModel.moveTo(x, y);
  this.updateEdgePointByAnchors();
};

简化后,就是this.updateEdgePointByAnchors()应该放在this.nodeModel.moveTo(x, y)之后,而不是之前

解决方法

// packages/extension/src/NodeResize/Control/Control.tsx
onDragEnd = () => {
  this.updateEdgePointByAnchors();

  const { gridSize = 1 } = this.graphModel;
  const x = gridSize * Math.round(this.nodeModel.x / gridSize);
  const y = gridSize * Math.round(this.nodeModel.y / gridSize);
  this.nodeModel.moveTo(x, y);
};

改为

// packages/extension/src/NodeResize/Control/Control.tsx
onDragEnd = () => {
  const { gridSize = 1 } = this.graphModel;
  const x = gridSize * Math.round(this.nodeModel.x / gridSize);
  const y = gridSize * Math.round(this.nodeModel.y / gridSize);
  this.nodeModel.moveTo(x, y);

  this.updateEdgePointByAnchors();
};

@DymoneLewis DymoneLewis merged commit a971296 into didi:master Apr 9, 2024
@wbccb wbccb deleted the fix/1384 branch April 9, 2024 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

group分组,缩放后坐标发生偏差 [Bug report] 缩放节点时,图形和连接线发生偏移。
2 participants