Skip to content

Conversation

@huaxiabuluo
Copy link
Contributor

  • 修正 itemFormatter 回调参数描述:从 (value, name) 改为 (value, tickValue)
  • 更新 API 表格中的参数说明
  • 新增使用 itemFormatter 格式化自动生成图例的示例
Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Description of change

- 修正 itemFormatter 回调参数描述:从 (value, name) 改为 (value, tickValue)
- 更新 API 表格中的参数说明
- 新增使用 itemFormatter 格式化自动生成图例的示例
@gemini-code-assist
Copy link

Summary of Changes

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

此拉取请求旨在提升 F2 图例 itemFormatter 功能的文档清晰度和准确性。通过修正回调参数描述、更新 API 表格说明并提供新的使用示例,它帮助开发者更好地理解和利用 itemFormatter 来格式化图例项,尤其是在自动生成图例的场景下,从而提高开发效率和图表的可定制性。

Highlights

  • 文档修正: 修正了 itemFormatter 回调函数的参数描述,从 (value, name) 更新为 (value, tickValue),以更准确地反映其用途。
  • API 表格更新: 更新了 API 表格中 itemFormatter 参数的说明,详细阐述了两个参数的含义。
  • 新增示例: 新增了一个代码示例,演示如何使用 itemFormatter 来格式化自动生成的图例,特别是在处理百分比显示时。
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

@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

这次的 Pull Request 主要是修正了 Legend 组件中 itemFormatter 的文档,包括回调参数、API 表格说明,并增加了一个新的示例。这些改动都很好,让文档更准确、更易于理解。我针对新加的示例代码有一个小建议,可以让它更简洁一些。

Comment on lines +211 to +240
// 数据(环形图示例)
const data = [
{ name: '股票类', percent: 83.59, a: '1' },
{ name: '债券类', percent: 2.17, a: '1' },
{ name: '现金类', percent: 14.24, a: '1' },
];

// 创建分类名到百分比的查找表
const nameToPercentMap = Object.fromEntries(
data.map(({ name, percent }) => [name, percent])
);

<Chart
data={data}
coord={{
type: 'polar',
transposed: true,
}}
>
<Interval x="a" y="percent" adjust="stack" color="name" />
<Legend
position="bottom"
itemFormatter={(value, tickValue) => {
// value: undefined(自动生成的图例没有值)
// tickValue: 分类名称,如 '股票类'、'债券类'
// 格式化为百分比形式
return nameToPercentMap[tickValue] + '%';
}}
/>
</Chart>

Choose a reason for hiding this comment

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

medium

为了让示例代码更简洁,可以省略创建 nameToPercentMap 的步骤,直接在 itemFormatter 函数内部通过 data.find() 来查找对应项。对于示例中的少量数据,这种方式性能上没有问题,而且能让读者更专注于 itemFormatter 本身的使用。这样也使得整个示例的结构更简单。

// 数据(环形图示例)
const data = [
  { name: '股票类', percent: 83.59, a: '1' },
  { name: '债券类', percent: 2.17, a: '1' },
  { name: '现金类', percent: 14.24, a: '1' },
];

<Chart
  data={data}
  coord={{
    type: 'polar',
    transposed: true,
  }}
>
  <Interval x="a" y="percent" adjust="stack" color="name" />
  <Legend
    position="bottom"
    itemFormatter={(value, tickValue) => {
      // value: undefined(自动生成的图例没有值)
      // tickValue: 分类名称,如 '股票类'、'债券类'
      // 格式化为百分比形式
      const item = data.find(d => d.name === tickValue);
      return item ? `${item.percent}%` : '';
    }}
  />
</Chart>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

medium

为了让示例代码更简洁,可以省略创建 nameToPercentMap 的步骤,直接在 itemFormatter 函数内部通过 data.find() 来查找对应项。对于示例中的少量数据,这种方式性能上没有问题,而且能让读者更专注于 itemFormatter 本身的使用。这样也使得整个示例的结构更简单。

// 数据(环形图示例)
const data = [
  { name: '股票类', percent: 83.59, a: '1' },
  { name: '债券类', percent: 2.17, a: '1' },
  { name: '现金类', percent: 14.24, a: '1' },
];

<Chart
  data={data}
  coord={{
    type: 'polar',
    transposed: true,
  }}
>
  <Interval x="a" y="percent" adjust="stack" color="name" />
  <Legend
    position="bottom"
    itemFormatter={(value, tickValue) => {
      // value: undefined(自动生成的图例没有值)
      // tickValue: 分类名称,如 '股票类'、'债券类'
      // 格式化为百分比形式
      const item = data.find(d => d.name === tickValue);
      return item ? `${item.percent}%` : '';
    }}
  />
</Chart>

nameToPercentMap 是否更加语义化?并且时间复杂度上会有略微提升

@github-actions
Copy link

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
f2/dist/index.js = 1,706.38 kB 1,706.38 kB = 323.03 kB 323.03 kB
f2/dist/index.min.js = 532.93 kB 532.93 kB = 160.21 kB 160.21 kB

Significant size changes

Includes any change greater than 0.2%:
(No significant changes)

Generated by 🚫 dangerJS against 5f0fe29

@huaxiabuluo huaxiabuluo merged commit 322efba into master Jan 12, 2026
7 checks passed
@huaxiabuluo huaxiabuluo deleted the docs-legend-itemformatter branch January 12, 2026 11:14
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