Skip to content

Conversation

@XinyueDu
Copy link
Contributor

PR includes

视口变化时图表 resize

  • G2 在 onReady 中调用 chart.fitView 方法实现图表适应窗口

  • G6 由于没有实现 onReady,使用 DOM 重新挂载的方法暂时实现

  • fixed #0

  • add / modify test cases

  • documents, demos

Screenshot

image image
Before After

Copilot AI review requested due to automatic review settings December 25, 2025 12:44
@changeset-bot
Copy link

changeset-bot bot commented Dec 25, 2025

⚠️ No Changeset found

Latest commit: e01f62e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gemini-code-assist
Copy link

Summary of Changes

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

此拉取请求旨在解决图表在外部容器尺寸变化时无法正确响应和调整大小的问题。通过引入 ResizeObserver 机制,本PR为 G2 和 G6 图表提供了健壮的响应式布局能力。G2 图表现在可以在容器尺寸变化时自动调用其内置的尺寸调整方法,而G6图表则通过巧妙地强制组件重新渲染来适应新的尺寸,从而显著提升了用户体验和图表展示的灵活性。

Highlights

  • 响应式图表尺寸调整: 实现了图表容器尺寸变化的响应式处理,确保图表在视口或容器大小改变时能正确调整。
  • G2 图表优化: 针对 G2 图表,在 onReady 后调用 chart.fitView 并通过 ResizeObserver 监听容器变化进行节流式尺寸调整。
  • G6 图表兼容性: 针对 G6 图表,由于其没有直接的 resize 方法,通过 ResizeObserver 监听容器变化并强制组件重新挂载来触发尺寸更新。
  • 新增演示: 新增了一个演示文件 dom-render-resize.tsx,用于展示图表在容器延迟渲染和动态尺寸变化下的响应能力。
  • 文档更新: 更新了相关文档,增加了“resize 渲染”章节并链接到新的演示。
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.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 25, 2025

🎊 PR Preview e01f62e has been successfully built and deployed to https://antvis-GPT-Vis-preview-pr-254.surge.sh

🕐 Build time: 16.866s

🤖 By surge-preview

Copy link

@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 很好地解决了视口变化时图表重绘的问题。对于 G2 图表,通过 fitView 等方法实现自适应;对于 G6 图表,通过重新挂载 DOM 的方式来解决。代码实现了解耦,并增加了相应的演示案例。

我发现 VisChart.tsx 中处理图表 resize 的部分可以进行一些优化。具体来说,有两个 useEffect hook 存在代码重复,并且使用方式上有一些可以改进的地方,比如存在陈旧闭包(stale closure)和不推荐的依赖项。我提供了一个具体的代码建议来合并这两个 useEffect,以提高代码的可读性和健壮性。

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements chart resizing functionality to automatically adapt chart dimensions when the viewport or container size changes. The implementation uses different strategies for G2 and G6 charts: G2 charts leverage the fitView method called in onReady, while G6 charts use a DOM remounting approach with a reset key mechanism. The PR also includes a new demo showcasing the resize behavior and renames the error demo file to follow kebab-case naming conventions.

Key Changes:

  • Added ResizeObserver-based logic to detect and respond to container size changes
  • Implemented chart resize methods for G2 charts and full re-render strategy for G6 charts
  • Created new demo (dom-render-resize.tsx) to demonstrate resize functionality

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
src/GPTVis/index.md Added new section for resize rendering demo and fixed demo file reference to kebab-case
src/GPTVis/index.en.md Added English documentation for resize rendering demo and fixed demo file reference
src/GPTVis/demos/error-render.tsx New error demo file with kebab-case naming showing flow diagram with invalid data
src/GPTVis/demos/dom-render-resize.tsx New demo illustrating chart resize behavior with expandable/collapsible container
src/ChartCodeRender/VisChart.tsx Core implementation of resize logic with dual ResizeObserver approach and chart adaptation methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +142 to +166
// Helper: Resize chart to match container (handles G2/G6)
const resizeChartToContainer = () => {
const chart = chartRef.current;
const container = chartContainerRef.current;
if (!chart || !container) return;
const rect = container.getBoundingClientRect();
const width = Math.round(rect.width);
const height = Math.round(rect.height);
if (width <= 0 || height <= 0) return;
try {
if (typeof chart.forceFit === 'function') {
chart.forceFit();
} else if (typeof chart.changeSize === 'function') {
chart.changeSize(width, height);
} else if (typeof chart.fitView === 'function') {
chart.fitView();
} else if (typeof chart.layout === 'function') {
chart.layout();
} else if (typeof chart.render === 'function') {
chart.render();
}
} catch (error) {
console.error('GPT-Vis resize chart error:', error);
}
};
Copy link

Copilot AI Dec 25, 2025

Choose a reason for hiding this comment

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

The resizeChartToContainer function is defined inside the component body but is not memoized with useCallback. Since it's used in multiple useEffect hooks and called from onReady callbacks, this function will be recreated on every render. This could cause the effects to re-run unnecessarily or reference stale closures. Wrap this function in useCallback with appropriate dependencies to ensure stable references.

Copilot uses AI. Check for mistakes.
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.

2 participants