Skip to content

fix(echarts): plots without a grid clear of title, toolbox and legend; labels on fills by contrast - #38

Merged
eizedev merged 2 commits into
mainfrom
fix/echarts-layout-contrast
Nov 6, 2026
Merged

eizedev merged 2 commits into
mainfrom
fix/echarts-layout-contrast

Conversation

@eizedev

@eizedev eizedev commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Charts without a cartesian grid now keep their plot clear of title, toolbox and legend at every size, and labels on filled shapes take the text colour with the higher contrast to the fill.

Fixes #30
Fixes #31
Fixes #32

What changed

  • Components/layout.js (new), one place for both:
    • fitPlot() estimates the bands that title, toolbox and legend take from the option (legend lines of a Plain legend from the item texts and the width). It then moves the plot out of them. Funnel and treemap start below the toolbox. Pie, sunburst, gauge (rings move together), polar/radialbar and radar move down, and shrink only when they would otherwise touch the toolbox, title or legend. Anything set in -Options (top, bottom, center, radius) is kept.
    • insideLabelColors() colours labels on fills: funnel stages, pie slices with inside labels, treemap tiles and sunburst rings (deeper rings lightened as ECharts draws them). It uses the palette colours ECharts assigns, from -Palette or the current theme. A label.color from -Options stays.
  • shared/js/contrast.js (new): WCAG contrast helper. It picks dark (#1f2430) or white text, whichever contrasts more.
  • EChart.jsx applies both after the width rules. It applies them again when the chart's size or its number of legend lines changes; this happens only for these chart types, cartesian charts are unaffected. It also re-applies them when the theme changes.
  • buildOption.js:
    • The boxplot grid starts below the toolbox.
    • The pie's own estimate for plain legends is gone, because fitPlot replaces it.
  • CHANGELOG (Fixed), module README (Legend and Layout), AGENTS.md (shared/js).

Treemap group headers are not recoloured: they sit on the theme's gap colour, not on the tile.

Test plan

  • npm test: 71/71, including new tests for fitPlot, legendRows, insideLabelColors and the contrast helper
  • Pester 27/27, PSScriptAnalyzer 0 findings (as CI runs them)
  • Docs site browser tests: 15/15 in Chromium, Firefox and WebKit
  • Test app on PSU 2026.3.4 with funnel, pie, donut, radialbar, treemap and sunburst:
    • at about 420 px and full width, light and dark, palette #003452, #4D7186, #A8B7C4
    • funnel and pie variants with 7 stages, a Plain legend and a title
    • result: no overlap of plot with toolbox, title or legend, measured from the rendered element bounds, before 5 overlaps
    • result: every label on a fill has a contrast ratio of 4.87 or more, read from the rendered fills and text colours
    • same overlap result in Firefox and WebKit, no page errors
  • The same app on PSU 2026.2.5, light and dark: no overlaps, no page errors
  • Docs site measured at 1440, 700 and 420 px: no new overlaps

Not covered here, still open:

  • The layered network graph overlaps its legend and toolbox below about 700 px; at 420 px its nodes leave the chart.
  • Funnel labels on the smallest stages still run past the stage edge.

Places checked: module README, CHANGELOG, AGENTS.md, root README (no layout details), docs site examples (no change needed).

🤖 Generated with Claude Code

eizedev and others added 2 commits November 6, 2026 13:22
…; labels on fills by contrast

Charts without a cartesian grid (funnel, treemap, pie, sunburst, gauge, polar,
radialbar, radar) are placed for the size they have: below title and toolbox,
above a legend that wraps over several lines (layout.js fitPlot, applied in
EChart.jsx after the width rules and again when the size changes). Boxplots
start below the toolbox like the other cartesian charts.

Labels inside funnel stages, pie slices, treemap tiles and sunburst rings take
dark or white text by WCAG contrast with the palette colour ECharts assigns
(shared/js/contrast.js, layout.js insideLabelColors).

Fixes #30, fixes #31, fixes #32

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant