Skip to content

fix(core): one rule for text on coloured chart areas - #947

Merged
eizedev merged 22 commits into
mainfrom
fix/labels-on-coloured-fills
Nov 25, 2026
Merged

eizedev merged 22 commits into
mainfrom
fix/labels-on-coloured-fills

Conversation

@eizedev

@eizedev eizedev commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Summary

One rule for text on coloured chart areas, readable in light and dark themes and after a theme switch.

Fixes #913
Fixes #914

Mechanism Wish Issue
Treemap: every label sits on a plate in --pk-surface with --pk-text, the same on every tile and centred in it. A name that does not fit ends in "…" after at least 4 characters. A value line that does not fit is dropped, never cut. A tile with less room, or lower than one line, shows no text and no empty plate. A tap or pointer shows its name and value. Treemap labels read the same in both themes and after a theme switch #914
Heatmap: each number takes whichever of --pk-text / --pk-surface has the higher contrast on its cell if that reaches 4.5:1, else black or white Heatmap numbers readable on every cell #914
High and low points: ▲/▼ and the value in the muted text colour (--pk-muted) with a --pk-surface outline, beside the dot or above the group. In dense grouped bars, the chart's highest and lowest are placed first; labels that do not fit are dropped, and the tooltip still has them. Readable labels for high and low points, not hidden behind bars #913
Reference lines: the label in --pk-muted, after a dash sample in the line's colour. Below 480 px the kind word ("Average 25") stays when every label fits in 30 % of the width, else the value alone. Readable average and target labels, also on phones #913

Sizes, measured with Node 24 as in CI:

  • First load: 179.0 KiB gzip (budget 182.5).
  • Chart load group: 261.8 KiB (+1.6 KiB). I raised its budget to 262.0 KiB.

The growth baseline accepts 9 more lines on the two chart docs pages. They hold:

  • the treemap rule;
  • reference lines on phones;
  • the bar gap limits;
  • two bullets an earlier edit had lost.

Known limit, documented in docs/concepts/charts.md: label placement beside grouped bars assumes ECharts' default barGap and barCategoryGap.

Neutral review

I ran four rounds of independent review on the local branch before pushing. Fixed because of them:

  • one treemap look on every tile instead of a mix of plated and bare text;
  • shortened names instead of lost ones, with no empty plates;
  • the 66 × 31 px tile at 390 px keeps its label;
  • at least 4 characters before "…";
  • reference-line names under 480 px decided all or none;
  • drawn treemap tiles matched by position and name, tested against real ECharts with nested data;
  • highest and lowest first only in grouped bars;
  • the label-colour docs match the code;
  • tests for the tap tooltip and for the size gate, derived from the source constants.

The last round found nothing blocking.

Checklist (PRODUCT.md)

  • Linked issue
  • New or changed tests fail without this change; no test weakened. This was shown by mutation for the treemap fit, the label floor, the tile matching, the ordering and the reference-line words. The tap-tooltip test has no cheap mutation.
  • Docs and CHANGELOG.md (core, react, report, element) describe the new state
  • Reviewed before opening by a separate AI session

Test plan

🤖 Generated with Claude Code

eizedev and others added 22 commits November 25, 2026 18:44
…ouped bars

One rule for text on a coloured fill, in both themes (#914):
- treemap: every label in --pk-text on a plate in --pk-surface, so all
  tiles look alike whatever their colour
- heatmap: each number in --pk-text or --pk-surface, else black or white,
  whichever reaches 4.5:1 on the cell (labelColorOn)
- high and low points, reference lines: glyph, value and words in the
  text colour; the dot keeps the series colour

High and low points and reference lines (#913):
- a point's label sits over its own bar in grouped bars and never
  crosses another bar; without room it is left out
- narrow charts write a line's value, a trend its name
- an average's sample takes colorMap and chart.colors

tests/fill-contrast.js measures a label's contrast on its fill in both
themes, for tests of any package.

Closes #913
Closes #914

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…f react and report

The theme-switch test also compares each label's ink and the plate under
it with a fresh render, so a plate left in the old theme fails it.
pivotkit-react and pivotkit-report name the changed chart text.

Refs #913
Refs #914

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d-fills

# Conflicts:
#	packages/pivotkit-core/CHANGELOG.md
#	packages/pivotkit-element/CHANGELOG.md
#	packages/pivotkit-report/CHANGELOG.md
…aving it out

A high or low point's label that has no room over its bar or beside its dot now stands
over the highest bar of its category's group, inside the plot. Labels that still have no
room are left out, and the tooltip has the value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hout words

decorateOption takes tileOf, a treemap's tiles after a first draw, and drawnTiles reads
them from an ECharts instance. pivotkit-react and pivotkit-report draw a treemap twice,
as they do for pixelOf. Each label's padding then puts its lines in the tile's middle.
A label too wide for its tile has no plate and takes the ink that reads on the tile, so
no plate stands empty or cuts a name early.

Docs and changelogs name labelColorOn's black and white results, the tokens of point
and reference-line labels, and what happens without a --pk-surface the chart can draw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rged branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A tile with no room for one line on a plate lost its label: the padding that centres
the lines pushed the text out of the box. Such a label now has no plate, as one too
wide for its tile, and a centred label is never moved below one line.

The browser test counts the tiles without words and measures the contrast of labels
with and without a plate; the SVG test checks that the report centres them too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d-fills

# Conflicts:
#	scripts/growth-baseline.json
…rowth baseline

After the merge of main the chart group measures 261.5 KiB gzip on an
official Node 24 build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…re they fit

- Treemap: every label sits on a plate in the tile's middle. A name wider
  than its tile is cut with an ellipsis, a value line that does not fit is
  left out, and a tile with room for fewer than 3 characters has no label.
  The bare per-tile ink stays only for a theme without a readable surface.
- drawnTiles matches an item by name as well as by place, so in a tree
  with children no tile is taken for another item's (checked against
  ECharts 6.1.0, with a server-side rendered test).
- Reference lines below 480 px keep their names when every label fits in
  30 % of the width, else write the values as before.
- In dense grouped bars, the chart's highest and lowest point labels are
  placed first.
- barSlots documents that it assumes ECharts' default bar gaps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…p limits

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dense grouped bars

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… bars only

On lines, placing them first left a close low without its label; the
series' order moves the labels apart instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ites the values

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lines of a tile kept 5 px above and below, so a tile of 66 x 31 px at
14 px text lost its label. Now a pixel above and below is enough; the
sides keep their padding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The chart pages gain the treemap label rule, reference lines on phones,
the bar gap limits and two restored bullets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A cut name now keeps at least 4 characters before the ellipsis; a tile
with less room shows no label, and its tooltip gives name and value.
The treemap label constants live in chart-measure.js, so the browser
spec derives its size gate from them instead of repeating numbers.

Docs and changelogs name the muted text colour (--pk-muted) for point
and reference-line labels and use one wording (30 % of the width) for
narrow reference lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l below the smallest tile

On a touch screen at 390 px, a tap on a tile without words and on one
with a cut name shows the tooltip with the whole name and the value.
A tile too narrow even for the narrowest cut name, or lower than a
line, shows neither words nor a plate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cters

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eizedev
eizedev merged commit a3ff41d into main Nov 25, 2026
26 checks passed
@eizedev
eizedev deleted the fix/labels-on-coloured-fills branch November 25, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

charts: label colours on treemap tiles and heatmap cells mix after a theme switch charts: readable labels for high and low points and average lines

1 participant