Skip to content

Allow static domains, to improve UX when toggling datapoints #3099

Description

@neefrehman
  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

I'm currently working on a chart that starts with multiple bars being visible, that allows users to toggle them off so they can focus on a smaller set of datapoints. Recharts allows this toggling to be done very easily with the hide prop, but I've noticed that the domain of the axis will always adapt to fit only the currently displayed data. This negatively affects the user's ability to make comparisons when toggling datapoints.

Minimal codesandbox example here

It would be great to include a way to set the domain of an axis as static, i.e. always including data even if it's hidden. I've made local changes to generateCategoricalChart.tsx and can verify that the behaviour is easy to implement by removing the !item.props.hide check when filtering the graphicalItems.

If this feature is one you would consider implementing, I'd like to agree on the right API that would update those filter predicates, and I'd be happy to open a pull request with the implementation.

What does the proposed API look like?

I have two ideas for this API. My preference would be for this first approach, as I feel it's the simplest:

<YAxis includeHidden /> // maybe `staticDomain` also works as a prop name?

We could also have a boolean flag on the graphical items themselves, so we can still ignore some items if we want:

<Bar onDomain hide={booleanState} /> // by default, `onDomain`'s value would be `!hide`

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Feature requests or future priority issuesfeature requestIssues that are feature requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions