Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7962778
fix(core): readable text on coloured fills and point labels beside gr…
eizedev Nov 25, 2026
1c48f33
test(core): compare treemap plates after a theme switch; changelogs o…
eizedev Nov 25, 2026
15d8630
Merge remote-tracking branch 'origin/main' into fix/labels-on-coloure…
eizedev Nov 25, 2026
598ee6a
fix(core): raise a grouped bar's point label over its group before le…
eizedev Nov 25, 2026
de75d01
fix(core): centre treemap labels in their tiles and draw no plate wit…
eizedev Nov 25, 2026
330758c
chore(repo): set the docs line total of the growth baseline to the me…
eizedev Nov 25, 2026
054fd1b
fix(core): keep the label of a treemap tile too short for a plate
eizedev Nov 25, 2026
0b52e66
Merge remote-tracking branch 'origin/main' into fix/labels-on-coloure…
eizedev Nov 25, 2026
7e73f5c
chore(element): raise the chart budget to 262.0 KiB and refresh the g…
eizedev Nov 25, 2026
a1c50d9
fix(core): plate every treemap label, name narrow reference lines whe…
eizedev Nov 25, 2026
bb46bf4
docs: treemap label rule in one place, narrow reference lines, bar ga…
eizedev Nov 25, 2026
31ca971
test(core): the chart's highest and lowest point label come first in …
eizedev Nov 25, 2026
1d9173a
fix(core): place the highest and lowest point labels first in grouped…
eizedev Nov 25, 2026
d7c3450
docs: retake the treemap screenshots with every label on a plate
eizedev Nov 25, 2026
d04f770
test(core): a 470 px chart names its reference lines, a 390 px one wr…
eizedev Nov 25, 2026
c869ea7
fix(core): keep the plate of a treemap tile one line tall
eizedev Nov 25, 2026
afa668c
docs: retake the treemap screenshots
eizedev Nov 25, 2026
3490139
chore: accept the chart docs growth in the growth baseline
eizedev Nov 25, 2026
e06c513
fix(core): keep at least 4 characters of a cut treemap name
eizedev Nov 25, 2026
556ecf6
docs: retake the treemap screenshots
eizedev Nov 25, 2026
92ccb42
test(core): a tap on a treemap tile shows its name and value; no labe…
eizedev Nov 25, 2026
d151697
docs: a tap on a treemap tile shows its tooltip; the floor is 4 chara…
eizedev Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/assets/screenshots/chart-points-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/screenshots/chart-points-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/screenshots/chart-treemap-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/screenshots/chart-treemap-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions docs/concepts/charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ document.querySelector("pivot-report").colorMap = { Failed: "#e3000f", Success:
- A label writes a sample of its line's dash in the line's colour, then the value as the value
axis does. `decorateOption` puts the labels right of the plot and keeps them a line apart. With
`pixelOf`, the real height of a value after a first draw, they sit at their lines. Below 480 px
it writes the names only and leaves out a label far from its line.
the names stay where all fit in 30 % of the width, else the values (a trend its name); a label
far from its line is left out.
- A trend over the categories' order, when a category has no date, is one straight segment.

Two functions decide which chart draws which line. The chart, the menu and the report's SVG use
Expand Down Expand Up @@ -212,13 +213,14 @@ A series' lines take its colour. The lines of no series, a target and a stack's
`referenceLineChecks`): per series, or of a stack's total.
- The first of equal values gets the point. A series whose values are all the same gets none.
- `toEChartsOption` draws them as a silent ECharts `markPoint` on the series: a dot in the series'
colour (a stack's in `--pk-chart-reference`), a label with ▲ or ▼ in that colour and the value in
the text colour. A palette colour such as yellow is too light for text, so the value keeps the
text colour.
colour (a stack's in `--pk-chart-reference`), and a label with ▲ or ▼ and the value in the muted
text colour (`--pk-muted`). A palette colour such as yellow is too light for text, so the dot alone takes it.
- `decorateOption` keeps the labels inside the plot: the value axis reaches past them
(`dataMin`, `dataMax`). A label that would take the axis across zero sits beside its dot.
- Labels that would cover each other move beside their dots, or are left out. With `pixelOf` it
uses the real heights after a first draw.
- Labels that would cover each other or another bar of a group move beside their dots, then above
the group's highest bar, else are left out; the chart's highest and lowest go first there. With
`pixelOf` it uses the real heights. Bar places assume the default `barGap` and `barCategoryGap`;
a host's `barGap`, `barCategoryGap` or `barWidth` can put a label on a bar or leave it out.
- With more than 8 series, only the chart's highest and lowest value keep a label. Every dot stays.
- The labels and dots get an outline in `--pk-surface`, so they read over a line.

Expand Down
16 changes: 8 additions & 8 deletions docs/reference/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ area with `stackPercent`.
| `tooltipFormatter` | Builds the tooltip's formatter. Leave it out for a chart without a tooltip, such as an SVG. |
| `readColor` | `(color) => color \| null`: a heatmap colour as ECharts can mix it. ECharts reads hex, `rgb()`, `hsl()` and some names only, and another form, such as `oklch()`, turns the cells black. An end with `null` takes `DEFAULT_THEME.colorScale`'s colour. |
| `zoom`, `zoomAt`, `timeline`, `touch` | The zoom slider of a chart on a screen. See below. |
| `pixelOf` | `(value) => px`: a value's height in the drawn chart, such as ECharts' `convertToPixel` after a first draw. The labels of the reference lines then sit at their lines. |
| `pixelOf`, `tileOf` | After a first draw. `pixelOf`: `(value) => px`, a value's height in the drawn chart, such as ECharts' `convertToPixel`: the labels of the reference lines then sit at their lines. `tileOf`: `(index, name) => { width, height } \| null`, the tile of a treemap's item `index` named `name`, such as `drawnTiles(chart)` gives: each label then stands in its tile's middle, cut to fit. `drawnTiles` gives `null` for an item it cannot match by name, such as in a tree with children. |

It adds the theme's colours from the tokens, and:

Expand All @@ -480,11 +480,11 @@ It adds the theme's colours from the tokens, and:
- A legend moved below a narrow chart.
- The category axis laid out for the chart's size (`categoryLabelLayout`: straight, slanted or every
n-th, `chart.axisLabels`). The option's `axisEvery` says when every n-th label is written.
- Room on the right for the values at the end of horizontal bars, and fewer value ticks where a
narrow axis needs them.
- A heatmap's row names and cell numbers where its cells have room.
- A treemap's labels in `--pk-text` or `--pk-surface`, whichever has the higher contrast on the tile
(`labelColorOn(fill, candidates)`). Below 4.5:1, the label gets an outline in the other one.
- Room on the right for the values at the end of horizontal bars, fewer value ticks on a narrow axis.
- A heatmap's row names and numbers where its cells have room. Each number takes the one of
`--pk-text` and `--pk-surface` with the higher contrast on its cell if it reaches 4.5:1, else
`#000000` or `#ffffff` (`labelColorOn`). A treemap's labels on a plate, cut to their tiles with
`tileOf`, as [Charts › Treemap](../use/charts.md#treemap) describes.

pivotkit-react adds its DOM tooltip through `tooltipFormatter`. Its `readColor` turns any colour the
browser reads into `#rrggbb`. pivotkit-report's keeps the colours ECharts reads. Any other one
Expand Down Expand Up @@ -537,8 +537,8 @@ The view's display settings are part of the option:
- The hidden legend entries of `chart.hidden` as `legend.selected`. Without a legend, the option has
one that is not shown.
- The reference lines (`chart.referenceLines`) as silent `markLine`s, with the value axis's
`dataMin` and `dataMax` reaching them. The high and low points as silent `markPoint`s, their
labels kept inside the plot and apart by `decorateOption`.
`dataMin` and `dataMax` reaching them. The high and low points as silent `markPoint`s, their labels
kept inside the plot and apart by `decorateOption` ([limits](../concepts/charts.md#high-and-low-points)).
- Fixed colours (`chart.colors`, `colorMap`) as `itemStyle.color` of a series or a slice, and the
line's and the fill's colour of a line or an area. `tooltip.shareFormatter` writes a share in the
locale's way.
Expand Down
10 changes: 10 additions & 0 deletions docs/reference/theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ The chart reads these tokens in the current theme:
| The heatmap | `--pk-heat-low`/`--pk-heat-high` |
| The title's size and weight | `--pk-chart-title-size`, `--pk-weight-strong` |
| Its other text: the axes, the legend, the labels on bars, slices and cells, the heatmap's scale | `--pk-chart-text-size` |
| The text on a treemap's tiles, on a plate ([treemap](../use/charts.md#treemap)) | `--pk-text` on `--pk-surface` |
| The numbers on a heatmap's cells: of the two, the one with the higher contrast on the cell if it reaches 4.5:1, else black or white | `--pk-text`, `--pk-surface` |
| The labels of high and low points, with an outline around the letters | `--pk-muted`, outlined in `--pk-surface` |
| The labels of reference lines | `--pk-muted` |
| The corners of bars and pie slices | `--pk-radius-chart` |
| The corners of the tooltip | `--pk-radius-card` |
| The tooltip's total line and the series under the pointer | `--pk-border`, `--pk-weight-strong` |
Expand All @@ -227,6 +231,12 @@ The chart reads these tokens in the current theme:
| The axis line | `--pk-chart-axis`, else `--pk-border` |
| The grid | `--pk-grid`, else `--pk-border` |

Black (`#000000`) and white (`#ffffff`) are fixed values, not tokens. The contrast of `--pk-text`
and of `--pk-muted` on `--pk-surface` is the theme's: the chart does not change them. Without a
`--pk-surface` the chart can draw, a treemap's text has no plate and takes a heatmap's ink. That
is a missing `--pk-surface`, or in pivotkit-report on its own a form ECharts does not read, such as
`oklch()` or `color-mix()`. A missing `--pk-surface` also leaves the points' labels without an outline.

The heatmap's colours work in any form the browser reads, `oklch()` too. The chart mixes the colour
of each cell from them. It takes them as plain sRGB colours: a colour's alpha is dropped, and a
colour outside sRGB, such as a P3 one, is clipped to its nearest sRGB colour. The HTML report and the SVG of the Export menu get them as the screen draws
Expand Down
26 changes: 16 additions & 10 deletions docs/use/charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ report: the report itself, field list included, is at least 1,024 pixels wide.
![A treemap of 20 countries by population, each tile named with its value](../assets/screenshots/chart-treemap-light.png#only-light)
![A treemap of 20 countries by population, each tile named with its value](../assets/screenshots/chart-treemap-dark.png#only-dark)

- Each tile shows its name and value. A small tile cuts the text with "…". The tooltip shows both.
- Each tile shows its name and value in its middle, on a plate in the background's colour. The
plate looks the same on every tile, whatever the tile's colour.
- A name wider than its tile ends in "…" after at least 4 characters; a value that does not fit is
left out. A tile with less room, or lower than a line, shows no text. Point at or tap a tile for both.
- A row with a total of 0 or less gets no tile.
- The colours only tell the tiles apart. They do not stand for a value.
- The text on a tile is light or dark, whichever reads better on its colour.
- Without a background colour the chart can draw, the text has no plate. It then takes the text or
background colour, else black or white, that reads on its tile ([Theming](../reference/theming.md#chart-colours)).
- It has no legend. **Chart settings › Series** hides a tile or sets its colour.
- With a field on Columns, a tile adds up every column, as a pie does.
- A click on a tile opens no rows.
Expand Down Expand Up @@ -311,8 +315,9 @@ target you set. High and low points mark the highest and the lowest value of eac
- Each line has a label right of the plot, at the line's height. It starts with a short sample of
the line's dash in the line's colour, then the name and the value, written short as on the axis,
such as "Target 500K". A label of a line close to another moves just below it.
- On a chart narrower than 480 px, such as on a phone, the labels name the lines only. A label
that cannot sit near its line is left out there; the tooltip still names the line.
- On a chart narrower than 480 px, such as on a phone, the names stay only where all labels fit in
30 % of the width. Else a label writes the value (a trend its name) after its dash in the series'
colour, as in the legend. A label that cannot sit near its line is left out; the tooltip names it.
- The value axis reaches every line. A target higher than every bar still shows.
- The tooltip lists the lines at the category with their whole values: a trend with its value there.
- The chart image, the HTML report and the chart as SVG draw the lines too.
Expand All @@ -325,15 +330,16 @@ target you set. High and low points mark the highest and the lowest value of eac
![A line for each year of monthly temperatures, each year's highest and lowest month marked with a dot and a label with ▲ or ▼ and its value](../assets/screenshots/chart-points-light.png#only-light)
![A line for each year of monthly temperatures, each year's highest and lowest month marked with a dot and a label with ▲ or ▼ and its value](../assets/screenshots/chart-points-dark.png#only-dark)

- The dot has the series' colour. Its label starts with ▲ for the highest value or ▼ for the
lowest, in the same colour, then the value as the table writes it.
- The dot has the series' colour. Its label, in the muted text colour (`--pk-muted`), starts with
▲ for the highest value or ▼ for the lowest, then the value as the table writes it.
- On a line, the highest label sits above its dot and the lowest below it.
- On bars and areas, both labels sit above the dot. On a bar, that is past the bar's end.
- A label never stretches the axis across zero. Near zero, it sits beside its dot.
- Labels have an outline in the background's colour, so they read over a line.
- A stack marks the highest and lowest total, in the neutral colour of a target.
- Two labels that would cover each other move beside their dots. A label that still has no room
is left out. Its dot stays, and the tooltip names the value.
- Labels that would cover each other or another bar of a group move beside their dots or above
the group. In dense grouped bars the chart's highest and lowest label come first, and some
others are left out; the tooltip has the value.
- With more than 8 series, every dot stays, but only the chart's highest and lowest value keep a
label.
- Where two categories share the highest value, the first one gets the dot. A series whose values
Expand Down Expand Up @@ -399,8 +405,8 @@ Point at a bar, a segment of stacked bars or a point of a line to see a tooltip.
- A series without a value at the category is left out.
- A long series name ends in "…". When more series are there than fit, the last line says how many
more there are, and whether the total includes them.
- On a phone, tap a bar, a point or a heatmap cell to see its tooltip. Tap it again to open
[its menu](#filter-from-the-chart).
- On a phone, tap a bar, a point, a heatmap cell or a treemap tile to see its tooltip. Tap a bar, a
point or a cell again to open [its menu](#filter-from-the-chart).
- A pie's tooltip shows the value's name, the slice and its value. With a field on Columns, a slice
adds up every column.
- A heatmap's tooltip shows the value's name, the cell's row and column and its value.
Expand Down
30 changes: 30 additions & 0 deletions packages/pivotkit-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@ All notable changes to `pivotkit-core` are documented in this file. The format i
A bundle that splits by file keeps them out of a page's first load until an export needs them
([#772](https://github.com/eizedev/pivotkit/issues/772)). The public API is unchanged.
- The README says that a minor release of 0.x can break things, with links to Versioning and Upgrading.
- `labelColorOn(fill, candidates)` can return `#000000` or `#ffffff`, not one of the candidates, where
none reaches 4.5:1 on the fill ([#914](https://github.com/eizedev/pivotkit/issues/914)).

### Added

- `decorateOption` takes `tileOf(index, name)`, a treemap's tiles after a first draw, and
`drawnTiles(chart)` reads them from an ECharts instance. A treemap's labels then stand in their
tiles' middle, cut to fit.

### Fixed

- Text on coloured fills reads at 4.5:1 or more in both themes
([#914](https://github.com/eizedev/pivotkit/issues/914)):
- A treemap writes its labels in `--pk-text` on a plate in `--pk-surface`, the same on every tile.
With `tileOf`, a name wider than its tile ends in "…" and a value that does not fit is left out;
a cut name keeps at least 4 characters. A tile with less room, or lower than a line, has no label,
so no plate stands without words.
Without a `--pk-surface` the chart can draw, no label has a plate.
- A heatmap's numbers take `--pk-text` or `--pk-surface`, else black or white, whichever reaches
4.5:1 on the cell. `labelColorOn` gives black or white where neither candidate reaches it.
- High and low points ([#913](https://github.com/eizedev/pivotkit/issues/913)):
- The ▲ and ▼ take the muted text colour (`--pk-muted`), as the value does. A light series colour made them hard to read.
- In grouped bars a label no longer crosses another bar of its group. It moves beside its dot or
above the group's highest bar. In dense grouped bars the chart's highest and lowest are placed
first and some other labels are left out; the tooltip has the value.
- Reference lines ([#913](https://github.com/eizedev/pivotkit/issues/913)):
- On a chart narrower than 480 px, the labels keep the lines' names where all fit in 30 % of the
width. Else each writes the value instead of the name; a trend keeps its name.
- The sample before an average's label takes the series' colour from `colorMap` and
`chart.colors`, as the line does.

## [0.10.0] - 2026-11-24

Expand Down
23 changes: 20 additions & 3 deletions packages/pivotkit-core/src/chart-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* over the host's colorMap. Names match without regard to case; a name in neither keeps the palette's
* colour. Only a drawn chart needs this module.
*/
import { EXTREME_INKS } from "./defaults.js";

/**
* A colour a host may name: hex of 3, 4, 6 or 8 digits, rgb(), rgba(), hsl(), hsla() or a CSS colour
Expand Down Expand Up @@ -88,9 +89,17 @@ export function contrastOf(a, b) {
return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
}

/** The contrast text needs on its background (WCAG 2.2 AA, normal text). */
export const TEXT_CONTRAST = 4.5;

/**
* The text colour of `candidates` (the theme's tokens) with the highest WCAG contrast on `fill`: the
* label on a treemap's tile. A colour it cannot read (not hex or rgb()) gives the first candidate.
* The colour of text on a coloured area (#914): of `candidates` (the theme's text and background
* colours, one dark and one light), the one with the highest WCAG contrast on `fill`. Where none
* reaches TEXT_CONTRAST (a mid blue between the theme's two), white or black: the one on the best ink's
* side where it reaches TEXT_CONTRAST, else the other. One of them always reaches 4.58:1 on an opaque
* colour. A fill it cannot read (not hex or rgb()) gives
* the first candidate. Used for a heatmap's cell numbers; decorateOption puts a treemap's labels on a
* background of their own instead (treemapLabels in chart-style.js).
* @param {string} fill
* @param {string[]} candidates
*/
Expand All @@ -99,5 +108,13 @@ export function labelColorOn(fill, candidates) {
if (!read.length) {
return candidates[0];
}
return read.reduce((best, x) => (/** @type {number} */ (x.ratio) > /** @type {number} */ (best.ratio) ? x : best)).c;
const best = read.reduce((a, x) => (/** @type {number} */ (x.ratio) > /** @type {number} */ (a.ratio) ? x : a));
if (/** @type {number} */ (best.ratio) >= TEXT_CONTRAST) {
return best.c;
}
// the extreme on the best ink's side first (a light ink white), so the ink changes side only where it must
const [black, white] = EXTREME_INKS;
const light = /** @type {number} */ (contrastOf(best.c, black)) > /** @type {number} */ (contrastOf(best.c, white));
const [near, far] = light ? [white, black] : [black, white];
return /** @type {number} */ (contrastOf(fill, near)) >= TEXT_CONTRAST ? near : far;
}
Loading
Loading