fix(charts): pie/donut 图例给扇区标上分类名,并真正读 showLegend (#3135) - #3138
Open
baozhoutao wants to merge 1 commit into
Open
fix(charts): pie/donut 图例给扇区标上分类名,并真正读 showLegend (#3135)#3138baozhoutao wants to merge 1 commit into
baozhoutao wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
… a `type` dimension (#3135) A dashboard pie whose category dimension is named `type` ("按类型分布" — a staple) rendered a legend of anonymous colour dots: swatches, no text. The label came from the shadcn config helper, which read the LEGEND ITEM's own same-named prop before the data row — and recharts legend items carry a `type` of their own (the icon shape, "rect"). So `nameKey="type"` resolved to "rect", missed the config, and rendered nothing. `color` collided the same way. Read the data row first: that is what `nameKey` was pointing at all along. Two adjacent gaps, same report: - the pie/donut branch drew its legend unconditionally, so `showLegend: false` did nothing; - `DatasetWidget` never forwarded the widget's `chartConfig` at all, so the declared `showLegend` was inert metadata either way — `true` only "worked" because on is the renderer's default. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3135
根因:
type这个维度名把图例文字吃掉了图例标签由 shadcn 的
getPayloadConfigFromPayload解析:它拿nameKey(= 维度字段名)先在 recharts 的 legend item 上找,找不到才看数据行。而 recharts 的 legend item 自带一个type字段 —— 图例图标形状,值是"rect"。于是
dimensions: ['type']("按类型分布",看板里极常见)→nameKey="type"→ 解析成"rect"→config["rect"]查不到 → 回退config["type"]也没有 → label 为 undefined,只剩 2px 色块,一个字不渲染。维度叫color同样受害。单类别数据下最致命:整圆一色 + 一个无字色点。改法:数据行优先于 legend item 自身的同名属性 ——
nameKey本来指的就是数据行的字段。同一份报告里的另外两个缺口
legendVisible只用在 radar/combo 上。写showLegend: false关不掉;写true也不是"生效",只是撞上了默认值。DatasetWidget根本不读widget.chartConfig(只读options),声明的showLegend从元数据层到渲染器之间断链,是死配置。现在把这一个渲染器已支持的标志下沉进 chart schema;未声明就不带这个键,存量看板行为不变。验证
单测:新增
AdvancedChartImpl.pieLegend.test.tsx(type/color/urgency三种维度名 + 单类别 +showLegend:false)与DatasetWidget.showLegend.test.tsx。回滚源码改动后新测试 4 失败 1 通过(通过的正是urgency对照组),修复后全绿。plugin-charts 129/129、plugin-dashboard 156/156。真机 UI(app-showcase 真后端 + console dev,真实 seed 数据):按 issue 原样造 dataset 维度名
type+ pie/donut widget,同一页面只切源码做 A/B:text: ""/swatches: 5(两个 widget 都是裸色点)text: "BacklogDoneIn ProgressIn ReviewTo Do"showLegend:false/true并排对照:原生 Chart Gallery 里
status/priority维度的饼/环图两态都正常 —— 触发条件确实是维度名与 recharts legend item 自带属性撞名,所以 showcase 一直没盖住这个 bug。未动
packages/components/src/ui/chart.tsx有同一 helper 的副本、同样的 bug,但它没从 index 导出、无人引用,属于死代码,未顺手改以免扩大 diff。🤖 Generated with Claude Code