Skip to content

Conversation

@moayuisuda
Copy link
Collaborator

@moayuisuda moayuisuda commented Dec 23, 2025

Checklist
  • npm test passes
Description of change
  1. 之前 legend 布局没考虑 itemValueText,加上
  2. legend render 下,自适应布局
  3. 去除之前偏 hack 的 html 自定义文档
  4. 增加一些 deepwiki 问不出来的说明文档,给人 & ai 检索

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @moayuisuda, 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 significantly improves the legend rendering capabilities by introducing an adaptive layout system that automatically calculates legend sizes, especially for custom HTML-rendered legends. It also streamlines the documentation by removing a previously described 'hacky' approach for custom HTML legends and adding a detailed explanation of the legend layout mechanism, addressing common issues related to legend height when manual padding is applied. These changes aim to provide a more robust and user-friendly experience for configuring and displaying legends.

Highlights

  • Adaptive Legend Layout: Implemented a new mechanism for legends to automatically adjust their size, particularly when custom HTML rendering is used, ensuring proper fit and avoiding unexpected height changes.
  • Documentation Update: Removed outdated and 'hacky' documentation related to custom HTML legends and introduced a new, comprehensive guide explaining the legend layout calculation logic and how to manage legend sizing effectively, especially when manual padding is applied.
  • Improved Legend Sizing Calculations: Enhanced the computeCategoryLegendSize function to accurately account for itemValueText when calculating legend item dimensions, leading to more precise layout.
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 为图例引入了新的 render 选项,允许使用 HTML 自定义渲染,这是一个非常棒的功能。它替代了过去那种较为“hacky”的自定义图例方式。实现上还通过支持 itemValue 增强了默认图例的功能。文档也相应地进行了更新,包括新增的 legendLayout.md 文件,解释了布局引擎的一个重要方面。

我有一个建议:在 src/runtime/component.ts 中,用于测量 HTML 图例大小的 DOM 操作应包裹在 try...finally 块中,以确保即使发生错误,临时元素也总能从 document.body 中移除,从而使代码更健壮。

Comment on lines +920 to +923
document.body.appendChild(container);
const bbox = container.getBoundingClientRect();
document.body.removeChild(container);
component.size = isVertical ? bbox.width : bbox.height;
Copy link
Contributor

Choose a reason for hiding this comment

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

high

这段代码通过将临时元素附加到 document.body 来测量其大小。这是一种常用技术,但可能不够健壮。如果在 appendChild 之后、removeChild 之前发生错误(例如在 getBoundingClientRect 期间),临时元素可能会残留在 DOM 中,导致内存泄漏并可能影响页面。为了使其更健壮,最好将 DOM 操作包装在 try...finally 块中,以确保清理操作总能执行。

    try {
      document.body.appendChild(container);
      const bbox = container.getBoundingClientRect();
      component.size = isVertical ? bbox.width : bbox.height;
    } finally {
      if (container.parentNode) {
        container.parentNode.removeChild(container);
      }
    }

Copy link
Member

@lxfu1 lxfu1 Dec 23, 2025

Choose a reason for hiding this comment

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

legend layout 应该是 legend 的一部分,不用单独的路由。

document.body.appendChild(container);
const bbox = container.getBoundingClientRect();
document.body.removeChild(container);
component.size = isVertical ? bbox.width : bbox.height;
Copy link
Member

Choose a reason for hiding this comment

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

可以考虑抽一个 calculateRenderedSize.

# Legend Layout Mechanism with Manual Padding

## Problem Description
When `paddingTop` is manually set (e.g., `paddingTop: 72`), the height of `legendCategory` changes unexpectedly (e.g., from 60px to 40px).
Copy link
Member

Choose a reason for hiding this comment

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

我理解这部分内容是不是可以放到 FAQ 里面,也能被检索到

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.

4 participants