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

feat: allow calculate distance by bbox when snap to node #4126

Merged
merged 2 commits into from
Jan 10, 2024

Conversation

xiawenqi
Copy link
Contributor

@xiawenqi xiawenqi commented Dec 28, 2023

Description

完成 https://github.com/antvis/X6/issues/3963,支持吸附到节点时基于bbox计算距离

Close #3963

Motivation and Context

当吸附到边时,默认为基于最近距离计算,但是吸附到节点时默认为基于节点中心点计算距离且不支持配置。针对连接到母线这种情况吸附到中心点的体验比较差,因此新增了配置项 snapNode , 默认为 center, 可配置为 bbox, 默认值保留原来的行为,配置为 bbox 时基于包围框距离判断是否吸附。

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [ x] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Enhancement (changes that improvement of current feature or performance)
  • Refactoring (changes that neither fixes a bug nor adds a feature)
  • Test Case (changes that add missing tests or correct existing tests)
  • Code style optimization (changes that do not affect the meaning of the code)
  • Docs (changes that only update documentation)
  • Chore (changes that don't modify src or test files)

Self Check before Merge

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@x6-bot x6-bot bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. PR: unreviewed PR does not have any reviews. pkg:x6 labels Dec 28, 2023
Copy link

codecov bot commented Dec 28, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (12ca0e1) 10.37% compared to head (486aa4e) 10.38%.
Report is 23 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4126   +/-   ##
=======================================
  Coverage   10.37%   10.38%           
=======================================
  Files         180      180           
  Lines       10542    10548    +6     
  Branches     2566     2567    +1     
=======================================
+ Hits         1094     1095    +1     
- Misses       9359     9364    +5     
  Partials       89       89           
Flag Coverage Δ
x6 10.38% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
packages/x6/src/graph/options.ts 17.64% <ø> (ø)
packages/x6/src/view/edge.ts 1.12% <0.00%> (ø)

... and 2 files with indirect coverage changes

@@ -109,7 +109,7 @@ export namespace Options {
/**
* Snap edge to the closest node/port in the given radius on dragging.
*/
snap: boolean | { radius: number }
snap: boolean | { radius: number; snapNode: 'center' | 'bbox' }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

很棒的配置!👍 有一个小的建议,将 snapNode 名称修改为 anchor 会更好。

@x6-bot x6-bot bot added PR: reviewed-changes-requested PR has reviewed and got Change request event. and removed PR: unreviewed PR does not have any reviews. labels Jan 9, 2024
@@ -48,6 +48,8 @@ const graph = new Graph({
})
```

当开启了 `allowNode` 时,判断是否吸附到节点计算distance时默认为基于节点的中心,可以通过配置 `snapNode` 为 `bbox` 改为基于节点的包围盒子计算距离。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另外,这个文档文本可以优化一下。当开启了 allowNode 时,这个前提可以去掉。

@x6-bot x6-bot bot added PR: unreviewed PR does not have any reviews. and removed PR: reviewed-changes-requested PR has reviewed and got Change request event. labels Jan 9, 2024
@xiawenqi
Copy link
Contributor Author

xiawenqi commented Jan 9, 2024

👍 感谢建议,已修改。

@NewByVector NewByVector merged commit 8169d42 into antvis:master Jan 10, 2024
11 checks passed
@x6-bot x6-bot bot added PR: merged PR has merged. and removed PR: unreviewed PR does not have any reviews. labels Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:x6 PR: merged PR has merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
2 participants