π Bug: linear yScale ignores custom domain min value unless zero: false is explicitly set
Summary
When setting a custom domain for a linear yScale in @visx/xychart, the minimum value is ignored and overridden to 0 β even if the domain specifies a positive minimum β unless zero: false is explicitly provided.
This behavior is unexpected and undocumented. It leads to confusing chart visuals, especially when plotting data where 0 is not relevant (e.g. implied volatility, percentages, interest rates, etc.).
π Reproduction
Code
<XYChart
height={400}
width={600}
xScale={{ type: 'point' }}
yScale={{ type: 'linear', domain: [1, 10] }} // β Still renders from 0
>
<AnimatedLineSeries
dataKey="test"
data={[{ x: 'A', y: 2 }, { x: 'B', y: 9 }]}
xAccessor={d => d.x}
yAccessor={d => d.y}
/>
</XYChart>
β
Expected Behavior
The y-axis should start at 1 and end at 10, as defined in the domain.
β Actual Behavior
The y-axis starts at 0 and ends at 10, ignoring the minimum domain value (1).
π οΈ Workaround
Explicitly set zero: false in the yScale config to prevent the scale from forcibly including 0:
yScale={{ type: 'linear', domain: [1, 10], zero: false }}
π Analysis
According to the ScaleConfig type:
zero?: boolean // If true, ensures that a zero baseline value is included in the scale domain.
β οΈ However
zero is implicitly treated as true by default.
- This overrides any explicitly provided domain minimum.
- This behavior is not documented or expected.
- It causes misleading visualizations when
0 is irrelevant.
π₯ This breaks the assumption that the domain is absolute unless overridden by nice: true, for example.
π Suggestions
- β
Best fix: Honor user-provided domain fully unless
zero: true is explicitly set.
- βοΈ Alternative: Update the documentation to clearly indicate that
zero: true is assumed by default.
- β οΈ Bonus: Emit a console warning when a non-zero domain min is overridden silently.
π§ Environment
@visx/xychart: ^3.12.0
- React:
18+
- Browser: All modern browsers
- TypeScript: β
Yes
π Bug:
linearyScale ignores custom domain min value unlesszero: falseis explicitly setSummary
When setting a custom
domainfor alinearyScalein@visx/xychart, the minimum value is ignored and overridden to0β even if the domain specifies a positive minimum β unlesszero: falseis explicitly provided.This behavior is unexpected and undocumented. It leads to confusing chart visuals, especially when plotting data where
0is not relevant (e.g. implied volatility, percentages, interest rates, etc.).π Reproduction
Code
β Expected Behavior
The y-axis should start at 1 and end at 10, as defined in the
domain.β Actual Behavior
The y-axis starts at 0 and ends at 10, ignoring the minimum domain value (
1).π οΈ Workaround
Explicitly set
zero: falsein theyScaleconfig to prevent the scale from forcibly including 0:π Analysis
According to the
ScaleConfigtype:zerois implicitly treated astrueby default.0is irrelevant.π₯ This breaks the assumption that the domain is absolute unless overridden by
nice: true, for example.π Suggestions
zero: trueis explicitly set.zero: trueis assumed by default.π§ Environment
@visx/xychart:^3.12.018+