Conversation
* fix(ellipsis-test) tooltip show must need update region tooltip 中根据 region 和 curLoc 来处理最终显示位置,目前 region 只在首次 renderTooltip 时才会设置,导致后续 height 发生变更,tooltip 显示位置有误 * test(5409-spec) 增加单测
fix chart.zh.md
Co-authored-by: liwenbo <liwenbo@kanzhun.com>
* chore: v4.2.11 * chore: uddate version
There was a problem hiding this comment.
Summary of Changes
Hello @sersishen, 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!
This pull request delivers several critical bug fixes and minor enhancements to improve the stability and responsiveness of the G2 charting library. Key improvements include resolving issues with label rendering lifecycle, ensuring accurate pie chart animations regardless of angle changes, and dynamically adjusting tooltip positions after chart resizing. These changes contribute to a more robust charting experience, particularly in interactive and dynamic web applications.
Highlights
- Label Rendering Stability: Fixed an issue where charts with label configurations would error after multiple renders and unmounting, improving the robustness of label lifecycle management.
- Pie Chart Animation Accuracy: Ensured that all attributes of a pie chart segment are updated during animation, even if its angle remains unchanged, leading to more complete visual transitions.
- Dynamic Tooltip Positioning: Improved tooltip positioning to correctly adapt and re-evaluate its display region after chart canvas resizing, preventing misaligned tooltips.
- Enhanced Element State Retrieval: Extended the utility for retrieving elements by state to recursively include those within nested sub-views, providing a more comprehensive search.
- Development Environment Updates: Updated Jest configuration with module name mappings for D3 libraries to ensure proper resolution during testing and incremented the project version to 4.2.11.
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
-
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. ↩
There was a problem hiding this comment.
Code Review
这个 PR 包含了一系列的 Bug 修复,提升了图表的稳定性和交互体验。主要改动包括:
- 修复了饼图在角度不变时颜色等属性不更新的动画问题。
- 修正了图表缩放后,组件上省略文本的 Tooltip 位置不正确的问题。
- 增强了
getElementsByState方法,使其能够正确获取子视图中的元素。 - 通过增加防御性检查,修复了多次渲染后销表可能导致的崩溃问题。
- 更新了 Jest 配置以兼容 d3 模块。
代码改动整体质量不错,并为修复的问题添加了相应的单元测试。我发现了一些可以改进的地方,主要是在 CHANGELOG.md 中存在重复内容,以及在 ellipsis-text.ts 中有代码重复,具体请看我的评论。
| - 部分动画覆盖 callback 配置导致外部的 callback 配置失效 ([#4678](https://github.com/antvis/g2/pull/4678)) ([9d1a25f1](https://github.com/antvis/g2/commit/9d1a25f15ba2cca594ee57d817a8f05ce5a80e60)) | ||
| - **interval:** 设置 backgroundShape capture 为 true, 避免交互时被捕捉(如 element-selected) ([#4714](https://github.com/antvis/g2/pull/4714)) ([c717014d](https://github.com/antvis/g2/commit/c717014dfa8220635ded10c966f5bd577212ce96)) | ||
| - 修复 sibling-x-filter,sibling-y-filter 过滤全部数据的问题 ([#4617](https://github.com/antvis/g2/pull/4617)) ([bc57583f](https://github.com/antvis/g2/commit/bc57583f8c2ac9e36d2fb0c8e444a192f8ce3267)) |
| } else { | ||
| // 更新时需要重新获取 region 赋值,避免画布缩放后 tooltip 位置不对 | ||
| const view = context.view; | ||
| const canvas = view.canvas; | ||
| const region = { | ||
| start: { x: 0, y: 0 }, | ||
| end: { x: canvas.get('width'), y: canvas.get('height') }, | ||
| } | ||
| this.tooltip.set('region', region) | ||
| } |
There was a problem hiding this comment.
这部分计算 region 的逻辑与 renderTooltip 方法中的逻辑(第 87-90 行)重复了。为了提高代码的可维护性并减少重复,建议将这部分逻辑提取到一个私有的辅助方法中,然后在两处调用它。
例如,可以创建一个 getCanvasRegion() 方法:
private getCanvasRegion() {
const canvas = this.context.view.canvas;
return {
start: { x: 0, y: 0 },
end: { x: canvas.get('width'), y: canvas.get('height') },
};
}然后在 showTooltip 和 renderTooltip 中调用 this.getCanvasRegion()。
Checklist
npm testpassesDescription of change