Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[color-chart] How should a chart look if the underlying <color-scale> has only one color? #128

Open
DmitrySharabin opened this issue Oct 16, 2024 · 1 comment

Comments

@DmitrySharabin
Copy link
Collaborator

For now, it throws because the getAxis() function returns NaN for min, max, and steps when calculating the corresponding props for the X-axis.

I checked what Excel does when it gets only one data point. It looks like Excel calculates the range based on an ”assumption“ that the chart should look nice. If I understand correctly, it uses 1 as the X coord (if not explicitly specified). I suggest that the one data point will never be outside the range.

image

We can probably do something similar (for the range of X).

@LeaVerou
Copy link
Member

Unlike Excel, we actually know what the domain for Y is here, so we could pick a certain slice of that (e.g. ±5% of the range). Not sure what a good X range would be. Any hardcoded range will fail in certain cases, e.g. if we pick [0, 1], what happens if x is -5 or 100? Perhaps a good heuristic might be using 0 as either a min or a max (for negative X) and then ±abs(x) for the other direction (so that the data point ends up in the middle).

If we don't have an X at all, 1 seems like a reasonable assumption. Tying into the other issue about getX(), I'd rather we pick a value that works more broadly for the default getX() (e.g. (c, i) => i + 1)

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

No branches or pull requests

2 participants