feat: yDomain — auto-fitted and explicit y-domains for cartesian charts#6
Open
DloomPlz wants to merge 1 commit into
Open
feat: yDomain — auto-fitted and explicit y-domains for cartesian charts#6DloomPlz wants to merge 1 commit into
DloomPlz wants to merge 1 commit into
Conversation
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.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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: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
yDomainprop on the cartesian roots (AreaChart/LineChart/BarChart) plus a passthrough onSparkline:"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, nonice()), so a host can reproduce the exact mapping:y = plotH * (1 − (v − lo)/(hi − lo)).Stacked/percent stacks stay zero-anchored (
yDomainis ignored there, as documented).YDomainis exported from the index. Registry JSON regenerated withnpm run build.