Skip to content

feat: yDomain — auto-fitted and explicit y-domains for cartesian charts#6

Open
DloomPlz wants to merge 1 commit into
Boring-Software-Inc:mainfrom
DloomPlz:feat/y-domain
Open

feat: yDomain — auto-fitted and explicit y-domains for cartesian charts#6
DloomPlz wants to merge 1 commit into
Boring-Software-Inc:mainfrom
DloomPlz:feat/y-domain

Conversation

@DloomPlz

Copy link
Copy Markdown
Contributor

Motivation

The y-scale is currently always [0, max]. That's right for bars and stacks, but for value time-series it has two sharp edges:

  1. High-magnitude, low-variance series flatten. A $4M portfolio moving ±$50k renders as a near-flat line — the signal is in the variance, and the zero anchor throws it away.
  2. Negative values clamp. A PnL series that dips below 0 can't render at all.

There's also no way to pin the domain from outside, which matters when a host draws DOM overlays that must share the chart's value↔pixel mapping (e.g. a draggable price-range slider over an area chart).

What this adds

A yDomain prop on the cartesian roots (AreaChart/LineChart/BarChart) plus a passthrough on Sparkline:

  • "zero" (default — no behavior change): today's zero-anchored, nice()d domain.
  • "auto": [min − pad, max + pad] fitted to the data (8% pad), negatives supported. Area fills anchor to the domain floor.
  • [lo, hi]: explicit domain used verbatim (no padding, no nice()), so a host can reproduce the exact mapping: y = plotH * (1 − (v − lo)/(hi − lo)).

Stacked/percent stacks stay zero-anchored (yDomain is ignored there, as documented). YDomain is exported from the index. Registry JSON regenerated with npm run build.

Adds a yDomain prop to the cartesian roots (and a passthrough on
Sparkline), alongside the existing zero-anchored default:

- "auto": domain [min − pad, max + pad] fitted to the data. A
  high-magnitude series with small relative variance (a $4M portfolio
  moving ±$50k) keeps its shape instead of flattening against the
  0 baseline, and negative values render instead of clamping.
- [lo, hi]: explicit domain used verbatim (no padding, no nice()), so a
  host can reproduce the exact value↔pixel mapping outside the chart —
  e.g. a draggable range-slider overlay.

Default stays "zero" everywhere, so existing charts are unchanged.
Stacked/percent stacks stay zero-anchored. Registry JSON regenerated
via npm run build.
@tripwire-dev

tripwire-dev Bot commented Jul 13, 2026

Copy link
Copy Markdown

passed — nothing tripped. good to merge.

View on Tripwire

@DloomPlz

Copy link
Copy Markdown
Contributor Author

Rebased onto the registry/CLI architecture + the #12 memoization rework. The domain is normalized to primitive deps before feeding the new computeBands/buildYScale memos, so a host passing a fresh [lo, hi] tuple each render can't invalidate them. Registry JSON regenerated; suite green (24/24).

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.

1 participant