Skip to content

Conversation

@binxie33
Copy link

@binxie33 binxie33 commented Feb 1, 2026

现在 collapseNode 函数没有正确的更新style,导致如果使用badges来跟踪展开 / 收起的子节点数时,收起之后无法正确显示。

修复代码是直接复制expandNode函数里的对应代码。

修复后效果如下:
collapsenode

在测试代码里:behaviorExpandCollapseNode 添加badges如下可复现:

badges:(n) => {
            console.log(n, n.style, n.style.collapsed);

            if (!n.style.collapsed) {
                console.log("return early for non collapsed node");
                return [];
            }

            return [{
                text: n.childrenCount?.toString() || '',
                placement: 'right',
                fill: 'white',
                backgroundFill: '#F4C13C',
                fontSize: 12,
                backgroundRadius: 8,
                padding: [4, 8],
            }];
        }
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @binxie33, 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 库中 collapseNode 函数的一个关键缺陷,即在节点折叠时未能正确更新其样式。这一修复确保了当节点状态改变时,其视觉表现(尤其是自定义徽章)能够准确反映当前状态,从而提升了用户界面的准确性和一致性。

Highlights

  • 修复折叠节点样式更新问题: 解决了 collapseNode 函数未能正确更新节点样式的问题,特别是在使用徽章(badges)跟踪子节点数量时,折叠后徽章显示不正确。
  • 引入样式重新计算逻辑: 在 collapseNode 函数中加入了清除动画和重新计算样式的逻辑,确保节点折叠后样式能正确更新,修复代码是直接复制 expandNode 函数里的对应代码。
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

你好,感谢你对 G6 的贡献。

这次的 Pull Request 修复了 collapseNode 函数中节点样式没有被正确重新计算的问题,确保了在使用 badges 等依赖于节点状态的样式时能够正确显示。

我在代码中发现了一个可以优化的地方:computeStylecomputeChangesAndDrawData 的调用顺序。目前的顺序虽然可以工作,但存在一定的效率问题。将 computeStyle 提前,可以使逻辑更清晰,并可能提高性能。我在具体的代码行上留下了详细的评论。

总体来说,这是一个有价值的修复。合并后将改善节点收起功能的用户体验。

Comment on lines +715 to +716
this.context.animation!.clear();
this.computeStyle('collapse');
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

你好,感谢你的修复。这个改动通过调用 computeStyle 解决了样式更新不及时的问题。

不过,当前的执行顺序似乎可以优化。computeChangesAndDrawData (在第 713 行) 在 computeStyle 之前被调用,这意味着 data 的计算是基于旧的样式。虽然 animation.clear() 清除了可能基于旧样式创建的动画,但整个流程是:计算 -> 清除 -> 重新计算,效率较低。

更理想的顺序是先调用 computeStyle('collapse'),再调用 computeChangesAndDrawData。这样可以确保数据变更的计算总是基于最新的样式状态,逻辑更清晰,也可能让 this.context.animation!.clear() 不再需要。

由于评论范围的限制,我无法提供一个直接修改顺序的代码建议,但这在未来的重构中是值��考虑的一个点。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant