Skip to content

feat(v3): add radial-bar chart component - #3943

Open
lplalbert wants to merge 2 commits into
antvis:oss-camp2026from
lplalbert:feat/radial-bar
Open

lplalbert wants to merge 2 commits into
antvis:oss-camp2026from
lplalbert:feat/radial-bar

Conversation

@lplalbert

Copy link
Copy Markdown

改动

新增 radial-bar(玉珏图)组件,关联 #3893。

  • charts/radial-bar.md:选型、数据要求、常见变体、样式自定义、v4→v5 易错点、完整案例表
  • examples/radial-bar/*.ts:6 个可运行案例(基础、圆角、外圈标签、半圆、品牌配色、暗色主题)
  • evals/cases/radial-bar.jsonl:12 条评测用例
  • skills/g2plot-v3/SKILL.md:决策树新增选型入口
  • README.md / README.zh-CN.md:图表支持表补充 radial-bar

关键实现

type: 'interval' + coordinate: { type: 'polar', innerRadius },不依赖 @antv/g2-extension-plot。

验证

  • npm run validate(tsc --noEmit)通过
  • npm run lint(lint-md)通过
  • 用 headless Chromium 实际渲染 6 个案例,均正常出图、控制台无 JS 错误
  • 实测发现暗色主题需 type: 'view' + style.viewFill 才真正生效,案例与文档已按实测结果修正

说明

本 PR 由 AI 辅助生成,结构对齐 charts/line.md;未运行 eval:generate / eval:judge(需要模型 API),eval 结果以维护者环境为准。

@github-actions github-actions Bot added the feature 特性需求 label Nov 24, 2026
@lplalbert

Copy link
Copy Markdown
Author

本地 eval 自测结果(仅供参考)

按 evals/ 的流程对 radial-bar 的 12 条用例完整跑了 generate + judge:

  • generate:12/12 成功产出代码
  • judge:12/12 通过渲染 → passRate 100%(charts.radial-bar.passRate = 100)

运行环境:

  • 模型:deepseek-chat(DeepSeek 官方 API,非推理模式,实测 reasoning_tokens 为 None)
  • LLM_TEMPERATURE=0
  • 渲染:Chromium 153 headless,按仓库 judge.mjs 的白屏阈值(非白像素 < 0.3%)判定

说明:

  • 该结果只是给本 PR 一个可核对的参考;按 issue 约定,最终以维护者在统一模型/温度下的 summary.json 为准。
  • 跑 eval 时临时给 load-cases.mjs 加了图表过滤、给 judge.mjs 加了 --no-sandbox,这两处改动未包含在本 PR 中,仓库的 eval 框架保持原样。
  • 顺带一个环境提示:默认的 moonshot-v1-8k 上下文不足以支撑这个多步 agent(会累积到 8k 以上),实际需要 32k 以上的模型。

@interstellarmt

Copy link
Copy Markdown
Member

感谢贡献!本次基于 05a5752,已对照 G2 v5.4.8 源码、官方示例和旧版经典案例完成审核。

问题

  1. 6 个案例实际画成了玫瑰图,没有实现玉珏图。

    玉珏图应让类别对应不同半径的同心环带,数值映射角度。G2 v5 已提供内置写法,原有 x/y 编码可以保留:

    coordinate: { type: 'radial', innerRadius: 0.35 }

    radial 源码已确认。请同步修正全部示例、文档的映射及轴说明、易错点和评测预期。innerRadius 只控制中心孔,不能决定图表类型,“省略后变成饼图”的说明也需更正。

  2. 经典场景覆盖不足。
    当前主要是单系列的圆角、标签、半圆、配色和主题变化,缺少旧版已有的背景轨道/多指标进度环、分组、堆叠。这些已用 G2 v5 的 radial、分层 interval、dodgeX 和 stackY 实测可行,请补齐代表性案例及对应文档、评测,允许合并场景。

另外,6 个示例的说明块都在 import 后,应移至文件开头;文档完整代码应与 basic.ts 保持一致。

通过率

  • npm run validate、npm run lint:通过。
  • 原始示例:6/6 可渲染,但 0/6 符合目标玉珏图结构;30 个区块的数值 tooltip 已核查。
  • qwen-plus、温度 0:首轮自动可渲染 12/12,100%。其中 4 条读取本组件后仍生成玫瑰图,自动通过不代表功能正确。

结论:修改后通过

请先修正核心图形与相关上下文,再补齐经典场景。

按审核意见修正:

- 6 个示例原写法 coordinate: { type: 'polar', innerRadius } 实际渲染为玫瑰图
  (polar 下 x 映射角度、y 映射半径),统一改为 { type: 'radial' }:
  x 映射半径(一个分类一条环带)、y 映射角度(弧长即数值),encode 保持不变
- 新增三个经典场景:progress-ring(背景轨道 + 进度弧,view 叠两层 interval)、
  grouped(transform: dodgeX)、stacked(transform: stackY)
- 移除 half-circle 示例:radial 下截取弧段会让图形明显偏向画布一侧,不是稳定写法,
  仅在文档中说明 startAngle / endAngle 的用法与限制
- 文档同步修正坐标系映射、坐标轴说明(axis.y.title 在 radial 下不渲染)、
  样式与易错点表格,完整代码与 basic.ts 保持一致,并补充 scale.y.domainMax 余量、
  axis.x.zIndex 层级等实测结论
- 示例说明块移至文件开头(import 之前),与 AGENTS.md 约定一致
- 评测用例同步改为 radial 映射,新增分组 / 堆叠 / 进度环 / 玫瑰图纠正等用例(12 → 15)
@lplalbert

Copy link
Copy Markdown
Author

Thanks for the review — all three points are addressed in 78ca636.

1. Coordinate system. You're right, and the root cause is in G2 itself: radial is transpose + reflect + polar in G2 5.4, so the mapping is the other way round than I assumed. polar puts x on the angle and y on the radius, which is why polar + innerRadius rendered a rose chart (wedges around a hole) instead of rings. All 6 examples now use coordinate: { type: 'radial' }, i.e. x → radius (one band per category), y → angle (arc length = value); encode is unchanged. I verified each example by actually rendering it in headless Chrome: 8/8 come out as concentric bands, 0 rose charts.

I also dropped the "omit innerRadius and you get a pie" note — it is wrong. innerRadius only controls the centre hole; the chart type comes from the coordinate. A pie is theta + stackY.

2. Classic scenarios. Added progress-ring.ts (background track: a view with two intervals, the lower one using a full-scale constant), grouped.ts (transform: [{ type: 'dodgeX' }]) and stacked.ts (transform: [{ type: 'stackY' }]) — 8 examples in total. I removed half-circle.ts rather than fixing it: under radial, clipping to startAngle / endAngle pushes the band bundle hard to one side of the canvas (verified), so it is not a stable example. The doc now explains the angles and that limitation instead.

3. Comment placement and code consistency. Every example's description block sits above the imports, and the basic code block in charts/radial-bar.md is byte-identical to basic.ts.

Rendering also turned up four pitfalls, now documented: axis.x.zIndex: 2 (otherwise the category labels are painted under the bands), scale.y.domainMax headroom (a max-value band closes on itself and covers its own label), hiding the angle axis 0 tick (it coincides with the max tick), and that axis.y.title is not rendered at all under radial — the unit has to go into title.subtitle.

npm run validate and npm run lint pass, and the eval cases went from 12 to 15 (grouped / stacked / progress ring, plus a rose-chart regression case and the innerRadius misconception).

@interstellarmt

Copy link
Copy Markdown
Member

感谢按照 review 意见耐心修改,并补齐进度环、分组和堆叠。复核后发现还有三点需要修改:

  • 背景轨道显示可以优化。 examples/radial-bar/progress-ring.ts:37 中,带宽实际为 83%,悬停灰色轨道会显示 y: 100。可以给轨道设 tooltip: false、在进度层绑定原始 usage 后,灰轨道不再提示,彩弧显示 83%。
  • 修正文档和评测预期。 charts/radial-bar.md:24 应写成“数值映射为圆心角”:等值在不同半径上是等角,不是等弧长。charts/radial-bar.md:113 和 evals/cases/radial-bar.jsonl:9 也应去掉“标题必须是对象”;已实测字符串标题可用,需要副标题时再用对象。
  • 让选型入口直接区分玉珏图和环形饼图。 skills/g2plot-v3/SKILL.md:28 建议用「每类各占一条环,对比各自数值」和「各类分同一个环,表示整体占比」区分,不把 5~12 类当成选型门槛。

通过率: validate、lint 通过,原例 8/8 出图。qwen-plus、温度 0:15/15(100%)自动通过,但人工核查有 5 条生成了饼图或环形饼图、1 条生成了普通柱状图。自动判分只检查运行错误和白屏。结论:修改后通过。

This branch has not been deployed

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

Labels

feature 特性需求

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants