Skip to content

Conversation

@yvonneyx
Copy link
Collaborator

@yvonneyx yvonneyx commented Jan 9, 2026

  • 当传入的参数是回调形式时,启动 worker 会有问题,回调无法序列化,这里引用 @antv/expr

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @yvonneyx, 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!

本次拉取请求的核心目标是增强布局配置的灵活性和兼容性。通过引入表达式解析能力,解决了 Web Worker 环境下回调函数序列化受限的问题,并统一了节点尺寸和间距的处理逻辑,使得布局算法能够更强大、更易用。这些改进为用户提供了更精细的控制,并确保了不同运行环境下的稳定性。

Highlights

  • 引入表达式支持: 引入了 @antv/expr 库,使得布局配置项(如节点大小、间距、排序依据等)现在可以接受字符串表达式。这解决了在 Web Worker 环境下回调函数无法序列化的问题,并提供了更灵活的动态配置能力。
  • 统一节点尺寸和间距处理: 将 nodeSizenodeSpacing 属性从各个具体布局算法的配置中移除,并统一到 BaseLayoutOptions 中。同时,formatNodeSizeFn 现在返回 STDSize 数组,并能正确处理节点尺寸和间距的宽度和高度分量。
  • 更新布局算法以支持表达式: 多个布局算法(包括 dagre, d3-force, fruchterman, concentric, combo-combined, radial, grid)的实现和类型定义已更新,以充分利用新的表达式功能,允许用户通过字符串定义复杂的行为。
  • 新增和更新测试快照: 新增了多个 d3-force 布局相关的 SVG 快照文件,并更新了 fruchterman 示例,以验证和展示新功能带来的视觉效果和正确性。
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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
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 引入了 @antv/expr 来支持将字符串表达式作为布局参数,解决了回调函数无法序列化导致 worker 失效的问题,这是一个很棒的改进。同时,将 nodeSizenodeSpacing 等通用配置提升到 BaseLayoutOptions 中,使得 API 更加统一和清晰。整体代码风格良好,改动清晰。

@codecov-commenter
Copy link

codecov-commenter commented Jan 12, 2026

Codecov Report

❌ Patch coverage is 96.15385% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.12%. Comparing base (59c85b8) to head (8aa1ad2).

Files with missing lines Patch % Lines
src/algorithm/force/index.ts 90.90% 3 Missing ⚠️
src/algorithm/fruchterman/index.ts 75.00% 1 Missing ⚠️
src/algorithm/grid/index.ts 93.75% 1 Missing ⚠️
src/util/format.ts 97.43% 1 Missing ⚠️
src/util/size.ts 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               v5     #285      +/-   ##
==========================================
+ Coverage   85.44%   86.12%   +0.68%     
==========================================
  Files          76       77       +1     
  Lines        5887     5938      +51     
  Branches     1411     1440      +29     
==========================================
+ Hits         5030     5114      +84     
+ Misses        856      823      -33     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

nodeStrength: 'node.data.ns',
edgeStrength: 'edge.data.es',
linkDistance: 'edge.data.len',
clusterNodeStrength: 'node.data.cs',
Copy link
Contributor

Choose a reason for hiding this comment

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

这个是 @antv/expr 支持的还是 layout 自己实现的

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

antv/expr 支持

test('should return node size plus spacing', () => {
const result = formatNodeSizeFn(20, 5, 10);
expect(result()).toBe(25);
expect(result()).toEqual([25, 25, 25]);
Copy link
Contributor

Choose a reason for hiding this comment

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

这三个值分别是啥意思

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

【长、宽、高】

* @param d - <zh/> 节点实例 | <en/> Node instance
*/
nodesepFunc?: (d?: NodeData) => number;
nodesepFunc?: Expr | ((node: NodeData) => number);
Copy link
Contributor

Choose a reason for hiding this comment

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

直接写出 string | ((node: NodeData) => number ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

这里区分一下是 string 或者 type Expr=string

* <en/> Minimum spacing between rings, used to adjust the radius
* @defaultValue 10
*/
nodeSpacing?: number | ((d?: NodeData) => number);
Copy link
Contributor

Choose a reason for hiding this comment

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

这个参数删掉有影响吗

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

提到通用配置里了

Copy link
Contributor

@Aarebecca Aarebecca left a comment

Choose a reason for hiding this comment

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

文档里面可以要补充一下,一个是 Expr 的写法,还有就是可以访问的局部变量

@yvonneyx yvonneyx merged commit 6cec35f into v5 Jan 13, 2026
2 checks passed
@yvonneyx yvonneyx deleted the structured-clone branch January 13, 2026 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants