Repository navigation
fix(charts): 行里没有类别键时明说,而不是画一张空坐标轴 - #3007
Merged
Merged
Conversation
…ng an empty axis
Rows that carry the measures but NOT the key the chart was told to plot
rendered an axis frame with ZERO marks — no throw, no console warning, no
legend. Measured before changing anything: `data: [{count:2},{count:8}]` with
`xAxisKey="issued"` produced an <svg> whose only text was the Y ticks
("02468") and 0 bar rectangles.
That output is indistinguishable from "the query matched nothing", and it is
the wrong conclusion. In framework#4033 an analytics bucket was grouped by but
never projected, so every trend widget silently drew nothing while the numbers
were right the whole time; the backend fix landed there, but nothing on this
side would have caught the next producer that drops a column.
framework#3701 was the same shape one layer over — a fieldless count keyed its
value `undefined` and the chart plotted nothing. Twice is a pattern.
The chart now renders an explanatory placeholder naming the missing key, and
warns once with BOTH halves of the mismatch (the key expected, the keys the
rows actually carry) — that pair is the whole diagnosis, and its absence is
what made #4033 expensive to find.
Deliberate choices:
- Not a throw. A dashboard widget must not take the page down over its own
data, and an honest empty state is more actionable than a stack trace.
- Absence, not nullishness: `key in row` is false only when the producer never
projected the column. A present-but-null value is a legitimate bucket (rows
whose grouped dimension is empty collapse into one), and testing `== null`
would condemn a working chart. Pinned by its own case.
- Category-axis chart types only. scatter plots two measures; treemap/sankey
read hierarchy/link fields — flagging those would be a false alarm.
- The guard lives in a thin wrapper around the renderer. The condition depends
on `data`, which arrives asynchronously, so an early return inside the
renderer would change its hook count between renders.
plugin-charts: 98/98.
Refs objectstack-ai/objectstack#4033
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TPxNwPnjcn599ujXpU3ibJ
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
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.
补上 objectstack-ai/objectstack#4033 的消费侧那一半。
实测的现状(先量再改)
行里带着度量、但没有图表被告知要绘制的类别键时,渲染出的是一张有坐标轴、零标记的图 —— 不抛错、不警告、无图例:
这与「查询没匹配到数据」完全无法区分,而后者是错误结论、代价也更高:framework#4033 里 analytics 的分桶维度被 group 了却没被投影,所有趋势 widget 静默画不出东西,而数值自始至终是对的。后端已修,但这一侧对「下一个丢列的生产者」仍然毫无防御。
framework#3701 是同一形态在另一层:无字段的 count 把值键成
undefined,「图什么都没画出来」。同样的失败出现两次,就不该等第三次。改动
图表现在渲染一个说明性占位(指名缺失的键),并
console.warn一次,带上不匹配的两半 —— 期望的键 + 行实际携带的键。这一对就是全部诊断信息;缺了它,作者只能拿数据集和图表 spec 手工对差异,而这正是 #4033 难找的原因。几个刻意的取舍:
key in row为 false 才说明生产者从没投影这一列;值为 null 是合法的桶(分组维度为空的行会合并成一个),用== null判断会冤枉一张正常工作的图。这条单独写了用例。data,在渲染器内部提前 return 会让它的 hook 数量在两次渲染间变化,违反 hooks 规则。验证
新增 7 个用例,覆盖:占位渲染、警告内容含两半、有键时完全不介入、null 桶不误报、空结果集不误报、scatter/treemap/sankey 不误报、10 种类别轴图型全部覆盖。
plugin-charts全套 98/98,无回归。🤖 Generated with Claude Code
https://claude.ai/code/session_01TPxNwPnjcn599ujXpU3ibJ
Generated by Claude Code