Skip to content

Bug: linear yScale ignores custom domain min value unless zero: false is explicitly setΒ #1925

@VicAppFleverage

Description

@VicAppFleverage

πŸ› 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions