Repository navigation
Commit 2c3dc72
fix(plugin-charts): a sankey names its nodes and colours its flows, a funnel labels every stage, the sankey footnote is translated (objectui#13404) (#13425)
Closes #13404
Clause-②: no
## What changed
All three defects are in
`packages/plugin-charts/src/AdvancedChartImpl.tsx`.
1. **Sankey: node names and link colours.** `node` and `link` were plain
objects, so Recharts drew bare rectangles with no text and every link
was the same `muted-foreground` grey. There are now two module-scope
renderers:
- `SankeyNodeShape` draws the rect plus the node's name. The name goes
to the right of the node, or to the left for a node with no outgoing
link. Under `align: 'justify'` those are exactly the last-column nodes,
which sit against the right edge.
- `SankeyLinkShape` draws the same curve Recharts' default draws,
stroked at opacity 0.4 in the colour of the node the link flows into.
Each category node takes `palette[idx % palette.length]` through
`resolveColor`, the same positional palette the funnel and treemap arms
use, and it honours a caller's `colors`. The root keeps
`muted-foreground` because it is the total, not a category. The
renderers are at module scope because Recharts lists `node` and `link`
in the dependencies of its layout memo. The `as any` on `node` is gone.
2. **Funnel: labels clipped.** `LabelList position="right"` put every
label past its trapezoid's right edge. The widest stage's edge is the
plot edge, so those labels drew off the surface. Labels are now
`position="center"` with foreground text inside a background halo
(`HALO_LABEL_PROPS`).
3. **Sankey footnote is English-only.** "Showing N of M rows ..." now
comes from a new count family, `chart.sankeyOmittedRows` (base, `_one`,
`_other`, plus each language's extra CLDR slots), translated in all ten
packs. The English text is unchanged. The measure key is still drawn as
a `code` chip: the sentence is interpolated with a private-use mark in
`{{field}}` and split on it, the same construction as `withChips` in
`metadata-viewer`, so each language decides where the chip goes.
## Judgment calls
- **Links take the TARGET's colour, not the source's.** The card asks
for "the source node's palette colour", but in this arm every link
leaves the same root node: `links = rows.map((r, i) => ({ source: 0,
target: i + 1, ... }))`. Colouring by source would paint every link one
colour again, which is the defect. The target is the category the link
carries, so each link matches the node it ends in. For the same reason
the test cannot build "two links with different sources", so it pins two
flows into two categories carrying two different strokes, each equal to
its node's fill.
- **Funnel labels inside the segments rather than a reserved right
margin.** A centred label is anchored on the funnel's axis, the vertical
line through the middle of the chart, so no stage name can be pushed off
the surface. Reserving room on the right would shrink every funnel by
its longest name and still clip a name longer than the reserve. A single
contrasting fill fails on the narrowest stage: a white label disappears
once it is wider than the segment and spills onto the background. The
foreground-on-background halo reads on both the segment and the
background, in light and dark themes (both colours are theme tokens).
Recharts' centre position also wraps a multi-word name to the segment's
mid-height width in a real browser.
- **`createSafeTranslation`, not the file's `useSafeTranslate`.** The
sentence agrees with a count ("1 row has" / "2 rows have"), so it is an
i18next count family and the call has to pass `count`, which
`useSafeTranslate` cannot. Its defaults map is what a host without a
provider renders, and it picks `_one` / `_other` the way i18next does.
`check:i18n-keys` confirms each defaults row repeats the `en` pack
value.
## Tests
New: `AdvancedChartImpl.sankeyFunnelLabels-13404.test.tsx` (13 tests,
jsdom, asserting on rendered SVG text and attributes):
- Sankey: every node name is a `text` (root series label plus each
category). The root's name is right of its node with `text-anchor`
start. Each last-column name is left of its node with `text-anchor` end,
inside the 480px surface. The three links carry three distinct strokes,
equal to their target nodes' fills and to `--chart-1..3`. The root fill
is not used by any link. A caller `colors` palette reaches the links.
- Funnel: one label per stage. Every label is anchored between 25% and
75% of the width, all on one x (the narrowest stage on the same axis as
the widest), with `text-anchor` middle. The narrowest stage's label
carries the foreground fill, background stroke and `paint-order` stroke.
- Footnote: en with no provider reads exactly the old text in the plural
and the singular, with the key still in `code`. en under `I18nProvider`
reads the same, which pins the defaults map to the en pack. zh renders
the zh `_other` row with the counts filled in and the chip kept. Every
pack carries the family with all four placeholders, translated.
- Control: a bar chart's data labels are unchanged and carry no halo.
Treemap leaf names are still white and no sankey labels appear. A pie
draws no halo labels.
Results on head f0a3687126 (after merging origin/main and re-running
`pnpm run setup` for the moved pin):
- `pnpm exec vitest run packages/plugin-charts/ packages/i18n/
--maxWorkers=2`: Test Files 183 passed (183), Tests 2609 passed, 22
skipped (2631).
- `turbo run type-check --filter=@object-ui/plugin-charts
--filter=@object-ui/i18n` (no dependents): Tasks 11 successful, 11
total.
- eslint on the touched files: 0 errors. The only warnings in new code
are 7 `no-explicit-any` in the new test file, from the same `vi.mock`
and `series as any` shape its sibling tests use.
- `check:i18n-keys`, `check:i18n-drift`, `check:i18n-dead-keys`,
`check:new-line-citations` and `check-changeset-presence`: all exit 0.
Ablation, one leg per fix. Each mutation went through the
anchor-must-hit replace tool and was restored to the HEAD blob with an
empty `git diff HEAD`:
- `node={SankeyNodeShape}` changed back to the old `{ fill: ... }`
object: 3 failed, 10 passed (no node text, and the node-fill comparison
fails).
- `link={SankeyLinkShape}` changed back to the old grey object: 2
failed, 11 passed (link strokes and caller palette).
- Funnel `LabelList` changed back to `position="right"`: 2 failed, 11
passed. "Qualification is anchored inside the plot: expected 433 to be
less than 360", and the halo assertion also fails.
- `SankeyOmittedRowsNote` changed back to the old English JSX: 1 failed,
24 passed with `AdvancedChartImpl.sankeyOmittedRows.test.tsx` included.
Only the zh test fails, so the en output is byte-identical to the old
JSX.
## Acceptance notes
- The other footnotes and refusals in this file are still English-only
JSX: `unsizedRowsNote`, `MagnitudeRefusal`, the sankey
`no-positive-flow` refusal, and the axis-position and unplotted-points
notes. They have the same defect but this card does not name them, so
they are not changed here.
- The `en` pack is in the eager closure. This adds one three-row family
to it, so the `Bundle Analysis` performance-budget check in CI is the
reading for its size.
- The line/area `XAxis` that PR #13420 changed is not touched.
- [x] Adds no product-specific widget, dialog, hook or string (see
AGENTS.md › Product-neutral renderer)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WJozybDmRH8z2c5SD7vJkj
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 7f60e9d commit 2c3dc72
13 files changed
Lines changed: 494 additions & 15 deletions
File tree
- .changeset
- packages
- i18n/src/locales
- plugin-charts/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1464 | 1464 | | |
1465 | 1465 | | |
1466 | 1466 | | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
1467 | 1474 | | |
1468 | 1475 | | |
1469 | 1476 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1305 | 1305 | | |
1306 | 1306 | | |
1307 | 1307 | | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
1308 | 1311 | | |
1309 | 1312 | | |
1310 | 1313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1618 | 1618 | | |
1619 | 1619 | | |
1620 | 1620 | | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
1621 | 1628 | | |
1622 | 1629 | | |
1623 | 1630 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1347 | 1347 | | |
1348 | 1348 | | |
1349 | 1349 | | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
1350 | 1354 | | |
1351 | 1355 | | |
1352 | 1356 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1343 | 1343 | | |
1344 | 1344 | | |
1345 | 1345 | | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
1346 | 1350 | | |
1347 | 1351 | | |
1348 | 1352 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1305 | 1305 | | |
1306 | 1306 | | |
1307 | 1307 | | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
1308 | 1311 | | |
1309 | 1312 | | |
1310 | 1313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1305 | 1305 | | |
1306 | 1306 | | |
1307 | 1307 | | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
1308 | 1311 | | |
1309 | 1312 | | |
1310 | 1313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1342 | 1342 | | |
1343 | 1343 | | |
1344 | 1344 | | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
1345 | 1349 | | |
1346 | 1350 | | |
1347 | 1351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1389 | 1389 | | |
1390 | 1390 | | |
1391 | 1391 | | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
1392 | 1397 | | |
1393 | 1398 | | |
1394 | 1399 | | |
| |||
0 commit comments