Commit 92552a2
committed
fix(legend)!: default the legend to top, and drop it on labeled pies
Three related legend changes.
**Default position is 'top' at every breakpoint.** Charts wider than
700px defaulted to a right-hand legend, which surrendered a column of
plotting width and truncated to "+N more" past a couple of series -- the
election-results bar in the visual suite was labelling one of its two
series. Compact and medium already defaulted to 'top', so this only moves
wide charts and makes the position uniform rather than width-dependent.
`legend: { position: 'right' }` restores it per spec.
**Pie/donut charts drop the categorical legend when every slice is
labeled.** The leader-line labels already name each category, so the
legend restated them one-for-one -- the same redundancy rule bar,
lollipop, and beeswarm already apply when color.field matches the
category axis. The legend stays whenever the labels do not cover every
slice: density 'none' or 'endpoints', a slice count past the point where
labels start losing collisions (measured: first drop at 22 slices in the
tightest container that renders a pie, so the limit is 21), or any
explicit legend config. Waffle and parliament are untouched; they attach
no per-mark labels, so their legend is the sole identifier.
Deliberately NOT gated on strategy.labelMode: charts/pie/index.ts passes
only spec.labels.density to computePieLabels and never consults the
strategy, so reading labelMode would make the legend disagree with what
the renderer draws (hiding the legend on compact while every label still
rendered).
**Fix pie slice labels landing on the wrong wedge.** Labels were assigned
to marks by array position, but the label array is both density-filtered
and re-sorted by collision priority. With density 'endpoints' on a
5-slice pie the second wedge (Bravo) was captioned "Echo". Labels now
carry their source index -- a field LabelCandidate already had for
exactly this hazard -- and are assigned by it. Leader-line connectors
were drawn by the same broken zip and are fixed with them. This was
pre-existing, but hiding the legend would have made it the only
identifier, so it ships together.
Snapshot oracle regenerated: the reclaimed gutter widens the plot
625.8 -> 683.0. 12 visual baselines regenerated for the reflow.
4327 tests pass; typecheck and biome clean.1 parent 0ccdaed commit 92552a2
25 files changed
Lines changed: 415 additions & 153 deletions
File tree
- e2e/visual/__screenshots__/stories.spec.ts-snapshots
- packages
- core/src/responsive
- __tests__
- engine/src
- __tests__
- __snapshots__
- charts/pie
- __tests__
- legend
- __tests__
- vanilla/src/__tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| |||
0 commit comments