Skip to content

fix: 修复 create-edge 连线位置偏移问题#7622

Closed
lzxue wants to merge 1 commit intov5from
fix/issue-7618-create-edge-offset
Closed

fix: 修复 create-edge 连线位置偏移问题#7622
lzxue wants to merge 1 commit intov5from
fix/issue-7618-create-edge-offset

Conversation

@lzxue
Copy link
Copy Markdown
Contributor

@lzxue lzxue commented Mar 19, 2026

修复 Issue #7618

问题描述

create-edge 时连接线发生偏移,不跟随鼠标,但连接节点后连接线正常。

修复方案

将客户端坐标转换为画布坐标,避免容器偏移导致的连线位置错误。

修改内容

  • 修改 packages/g6/src/behaviors/create-edge.ts 中的 updateAssistEdge 方法
  • 使用 graph.getCanvasByClient() 将浏览器客户端坐标转换为画布坐标

测试

该修复已针对 issue #7618 中描述的场景进行测试,当容器有 margin/padding 或非全屏时,连线能正确跟随鼠标。

Closes #7618

将客户端坐标转换为画布坐标,避免容器偏移导致的连线位置错误

Fixes #7618
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在解决 G6 图形库中 create-edge 功能的一个关键问题,即在创建连线时,辅助线会出现位置偏移,无法准确跟随鼠标。通过在 updateAssistEdge 方法中引入客户端坐标到画布坐标的转换,本修复确保了连线在各种容器布局下都能精确显示,显著提升了用户在绘制连线时的体验和准确性。

Highlights

  • 修复连线偏移问题: 解决了 create-edge 行为中,辅助连线在创建过程中不跟随鼠标移动,导致位置偏移的问题。
  • 坐标转换机制: 在 updateAssistEdge 方法中引入了 graph.getCanvasByClient(),将浏览器客户端坐标精确转换为画布坐标。
  • 提升用户体验: 确保了在容器存在 margin/padding 或非全屏显示时,连线也能正确跟随鼠标,提升了交互的准确性。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 PR 旨在修复 create-edge 行为中辅助线位置不跟随鼠标的问题。您通过使用 graph.getCanvasByClient() 方法转换坐标来解决此问题。该修复方向是正确的,我对此实现有一个关于代码整洁度的建议。

const { model, element } = this.context;
model.translateNodeTo(ASSIST_NODE_ID, [event.client.x, event.client.y]);
const { graph, model, element } = this.context;
// 将客户端坐标转换为画布坐标,避免容器偏移导致的连线位置错误
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

建议移除此注释。graph.getCanvasByClient 这个方法名已经足够清晰地表达了其功能,即“通过客户端坐标获取画布坐标”。根据代码自解释的原则,当代码本身足够清晰时,最好避免添加多余的注释,以保持代码的整洁性。

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.95%. Comparing base (91eb195) to head (62ac6f9).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##               v5    #7622   +/-   ##
=======================================
  Coverage   94.95%   94.95%           
=======================================
  Files         188      188           
  Lines       10014    10015    +1     
  Branches     2171     2171           
=======================================
+ Hits         9509     9510    +1     
+ Misses        505      467   -38     
- Partials        0       38   +38     
Flag Coverage Δ
g6 94.95% <100.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
packages/g6/src/behaviors/create-edge.ts 96.87% <100.00%> (+0.03%) ⬆️

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Aarebecca
Copy link
Copy Markdown
Contributor

Duplicate with #7609

@Aarebecca Aarebecca closed this Mar 30, 2026
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.

[Bug]: create-edge时连接线发生偏移,不跟随鼠标,但连接节点后连接线正常;使用简单html示例也复现

3 participants