An open source design system that's fully customizable and agent ready
ChartV2 — Phase 1 Plan (make it good, in place)
Living plan for getting packages/lab/src/ChartV2/ production-ready in place — no
renames, no deleting Chart v1, no new package, no docsite. Guiding principle
(from the owner): real, production-ready fixes; default to the proper fix
whenever it's obviously right.
Status legend: [ ] todo · [~] in progress · [x] done
0. How to run / review
pnpm -F @astryxdesign/build build # prereq
pnpm -F @astryxdesign/core build # prereq (lab typecheck needs core's dist)
pnpm storybook # http://localhost:6006 (Lab / ChartV2*)
pnpm -F @astryxdesign/lab typecheck # ChartV2 currently typechecks clean
pnpm test # vitest (no ChartV2 tests exist yet)
Visual review harness (how we "look at every chart"): a Playwright script
screenshots every ChartV2 story in light + dark by hitting
iframe.html?id=<storyId>&globals=colorMode:{light|dark}. Story IDs come from
http://localhost:6006/index.json. Kept in /tmp/chartv2-shots/. This is the
review loop — re-run after each change and eyeball the diffs.
1. Confirmed findings (evidence)
Scale / domain
- Continuous marks (line/area/dot) glue to plot edges + overshoot escapes.
computeLayoutsets y-domain to exactly[min,max](.nice()adds no padding when bounds are already round).Simple Line: Jan(38)=min sits on the axis, Jun(52)=max at top, and themonotonecurve overshoots above the plot. There is no clipPath (v1 hasastryx-chart-plot) so overshoot renders into the margin. Bars look fine only because they forceincludeZero. →layout.ts:128-136, no clip inChart.tsx:295-346. - Empty data breaks scales → streaming renders nothing. With
data=[],isNumericXis false (xValues.length > 0guard), so x falls into the band branch with an empty domain; y-domain becomes[Infinity,-Infinity].streamGLthen maps pushed points throughxScale(n)/yScale(n)→undefined/NaN→ blank. Verified blank after 5s. →layout.ts:44-60,84-136,streamGL.tsx:146-152. streamGL cannot work withoutxDomain/yDomainon the root. - Financial composite is misleading: volume bars (500–1500) share the price
y-axis (80–130) and crush the candlesticks/MA to a sliver. Inherent to one
shared scale. Story needs rethinking (drop volume, or a documented secondary-axis
pattern). →
ChartV2Advanced.stories.tsx:121-171.
Chrome / layout
- Band axis draws every category → candlestick x-labels overlap into a smear
(30 "Day N" labels). Auto-skip only runs if caller passes
maxTicks. Needs width-aware default skipping. →ChartAxis.tsx:89-113. - Reference-line label badges clip at the right edge ("Acceptable"); text width
is estimated (
label.length*5.5+8) and can overrun. →referenceLine.tsx:70-71,177. - Mixed Marks with
legend="end"clips the last bar/label (chart area shrinks but plot width/label centering overflow). →Chart.tsx:277-282. - Heatmap top row clips slightly at the plot top. →
heatmapGL.tsx:102-105.
Broken defaults / correctness
- Every mark's default color token is undefined.
--color-chart-1(bar/line/dot/area/band) and--color-positive/--color-negative(candlestick) do not exist inpackages/core/src/theme. Default-colored marks render black fills / invisible strokes. All current stories dodge this by passing explicit hex. →bar.tsx:72,line.tsx:35,dot.tsx:22,area.tsx:37,band.tsx,candlestick.tsx:21-22. - Duplicate-key collision. Series identity =
dataKey(key: dataKey). Two series on one dataKey collide in theresolvedmap (layout.tsresolved.set(s.key,…)) and in React keys (Chart.tsxkey={s.key}), silently dropping data. Live React warning fires onAreaGradient(area('revenue')+line('revenue')). AlsoareabuildsgradientId = area-grad-${dataKey}→ duplicate DOM ids. →types.ts:52-54, all mark factories,layout.ts:219,Chart.tsx:310-316. - streamGL hardcodes
key:'stream'→ two streams collide. →streamGL.tsx:228. - Inconsistent color API.
bar/dotacceptColorAccessor(string | fn);line/area/band/etc. accept onlystring. Accessor-colored series also vanish from the legend:deriveLegendItemsdrops any series withcolor == null, and accessor series setcolor: undefined. →bar.tsx:12-14,83,dot.tsx:11,30,line.tsx:26-27,area.tsx:26-27,legend.ts:18-32. dot.dodgeis a stubbed TODO (declared, never used). →dot.tsx:17,48.key={i}array-index React keys in mark render loops → reconciliation bugs on reorder/stream. →bar.tsx:151,line.tsx:88,dot.tsx:58,candlestick.tsx:83,errorBar.tsx:67.- No color palette API (v1 has
useChartColors/getChartColorswithcategorical/sequential/diverging/semantic/structural/alpha). v2 ships none. → compareChart/useChartColors.ts,Chart/getChartColors.ts. - heatmapGL builds its own y band scale (breaks one-shared-scale). →
heatmapGL.tsx:102-105.
Works well (leave alone)
All bar variants, negative values, grouped/stacked, mixed, area + stacked area, confidence bands, error bars + reference band, WebGL scatter, heatmap coloring, legend, swatch, and dark mode across the board.
2. Locked decisions
- Palette API → build the real thing (reuse v1's
getChartColors/useChartColorsfrom the same package; wire marks to consume it + fix the broken default token). - heatmapGL scale → real fix: teach the chart root a categorical y-scale so the heatmap shares it.
yBaseline/yDomain/xDomain→ full v1 parity (required for streaming).- Mark names (
bar/line/dot) → deferred to packaging (not a bug; on the "not now" list). No renames now.
3. Work items (ordered)
Ordered to build foundation first and keep each step independently verifiable via the screenshot harness.
W1 — Series identity (_uid) [ ]
- Problem: duplicate-key collision (#3) +
key={i}(#7) + streamGL key (#5). - Approach: add layout-assigned
_uid(mutable field, mirrors_isTopOfStack) =${index}:${key}; use it as the true identity for theresolvedmap, theChartrender key, tooltip lookups (resolved.get,resolvedKeys), and hover-dot keys.keystays a semantic label. Replace everykey={i}in mark render loops with a stable per-datum key (e.g.${dataIndex}is fine within a series, but prefer the x-value; index-in-series is acceptable since series are_uid-scoped). FixareagradientIdto include_uid. - Files:
types.ts,layout.ts,Chart.tsx,ChartTooltip.tsx,tooltip.ts,marks/{bar,line,dot,candlestick,errorBar,area}.tsx. - Verify:
AreaGradientReact warning gone; a new "two series, same dataKey" story renders both.
W2 — Domain / baseline parity + clip + continuous headroom [ ]
- Problem: edge-gluing + overshoot + empty-data breakage (#2, streaming).
- Approach: add
yBaseline?: 'auto'|'zero'|'data',yDomain?,xDomain?toChartProps; thread intocomputeLayout(mirror v1Chart/Chart.tsx:150-220: explicit domains authoritative + no.nice();zerosymmetric;autoincludes 0). Precedence:yDomain> rootyBaseline> per-markincludeZero. Add aclipPath(like v1astryx-chart-plot) around the marks layer. Add small domain headroom for continuous-only charts (no bar/includeZero, no explicit domain) so line/area/dot endpoints aren't glued to edges. Handle empty-data: ifxDomaingiven, honor it even whendata=[](so streaming has a real numeric scale); likewiseyDomain. - Files:
Chart.tsx,layout.ts,types.ts(SeriesContext already carries scales). - Verify:
Simple Lineno longer clips; streaming story (givenxDomain/yDomain, or a rolling window) draws.
W3 — Streaming works end-to-end [ ]
- Depends on W2. Update
StreamingLinestory to pass a domain / rolling window (v1 "stable streaming window"). Confirm streamGL maps points and the axis slides. - Files:
ChartV2Advanced.stories.tsx, possiblystreamGL.tsx(guard when scale isn't linear).
W4 — Color: unified accessor + palette API + legend fix [ ]
- Problem: inconsistent color (#4), broken default token, accessor legend drop, no palette (#8).
- Approach:
- Re-export v1 palette from ChartV2 (
useChartColors,getChartColors, types) viaChartV2/index.ts+ packageindex.ts. - Marks default
colortoundefined= "auto"; the Chart root resolves a categorical palette (useChartColors().categorical(n)) and assigns a color to each series lacking one, by index — store as_resolvedColoron the def (like_uid); marks readself._resolvedColor ?? ownColor. Fixes the broken token AND gives multi-series auto colors. - Widen
line/area(andbandwhere sensible) to acceptColorAccessorfor parity withbar/dot. Share oneColorAccessortype (move totypes.ts). - Legend: show accessor-colored series using a representative color (resolve the accessor at index 0, or the assigned palette color) instead of dropping them.
- Re-export v1 palette from ChartV2 (
- Files:
ChartV2/index.ts, packageindex.ts,types.ts,Chart.tsx,legend.ts,marks/{bar,dot,line,area,band,candlestick}.tsx. - Verify: default-colored multi-series chart shows distinct colors; new accessor-colored story appears in legend; dark mode palette adapts.
W5 — dot.dodge [ ]
- Implement real dodge (offset overlapping points at the same x by radius), or
remove the option. Prefer implement (production-ready). →
dot.tsx.
W6 — heatmapGL shares the chart scale [ ]
- Add categorical y-scale support to the chart root so the heatmap reads the shared y-scale instead of building its own. Bigger core change; do after W1–W4 land.
- Files:
layout.ts,types.ts(ChartScale/SeriesContext),Chart.tsx,ChartAxis.tsx/ChartGrid.tsx(categorical y),marks/heatmapGL.tsx. - Verify: heatmap rows align to a shared left axis; no own
scaleBand.
W7 — Axis label auto-density [ ]
- Width-aware default label skipping for band axes (fix candlestick smear) without
requiring
maxTicks. →ChartAxis.tsx:89-113.
W8 — Story-level fixes [ ]
- Reference-line label clipping (measure/clamp badge x). Mixed-marks
legend="end"clipping. Financial composite rework (secondary-axis story or drop volume). Heatmap top-row clip.
W9 — New stories (review targets from the brief) [ ]
- Plain SVG
dotscatter (not WebGL). dotGLInteractivehover.referenceLinesolo: singley;y+y2band;xline.- Edge cases: empty data, single point, all zero, all negative, one huge outlier.
- Accessor-colored series (exercises the legend fix).
- Duplicate-dataKey series (exercises W1).
- Dark-mode coverage confirmed for each via the harness.
W10 — Tests + final verification [ ]
- Add colocated vitest for:
layout(domain/baseline/empty/stacking),_uiduniqueness,legendderivation (incl. accessor),tooltipderivation. Runpnpm test,pnpm -F @astryxdesign/lab typecheck,lint, and re-screenshot all forms light+dark.
4. To verify / open questions
- Confirm exact set of missing tokens and the right categorical token names to
default to (palette resolves
--color-data-categorical-*). - Headroom amount for continuous charts (e.g. ~5%) — pick + document.
- heatmap categorical-y: does introducing a band y-scale disturb any existing numeric-y consumer? (Guard: only when a mark requests categorical y.)
- Should
yBaselinedefault stay'auto'-equivalent given per-markincludeZeroalready exists? (Lean: root override wins; keep per-mark default.)
5. Out of scope (deferred)
Rename ChartV2 → Chart · delete Chart v1 · move to packages/charts · docsite
second-library support + README · publish + CI.