layercake icon indicating copy to clipboard operation
layercake copied to clipboard

Should auto-calculated ordinal domain return sorted?

Open mhkeller opened this issue 2 years ago • 7 comments

Currently, if you set an accessor for x y or z and you pass in an ordinal scale, the domain will be calculated as unique elements, say, for a color scale. The order of these unique elements is just based on when they appear in the data. Should .sort() be called on them so that the appearance is more consistent?

This could be a potential breaking change for some charts.

mhkeller avatar Sep 08 '23 19:09 mhkeller

Yea I think this would be a good idea.

mhkeller avatar Sep 19 '23 16:09 mhkeller

Implemented in 8.0.0

mhkeller avatar Sep 20 '23 02:09 mhkeller

I'm re-opening this since some people have found this behavior surprising. Maybe better to turn this off by default. Any thoughts welcome

mhkeller avatar May 17 '24 17:05 mhkeller

@techniq @rgieseke @jtrim-ons any preference on this one?

mhkeller avatar May 24 '24 21:05 mhkeller

I personally find it surprising, and while yDomain={[...new Set(data.map((d) => d.name))]} does work, I think reverting to the pre-8.0.0 state would be a better default IMO, but not major if you don't.

techniq avatar May 24 '24 22:05 techniq

I have no strong preference here, thanks for the heads-up! Not sure if there is an example in the gallery which demonstrates this already?

rgieseke avatar May 27 '24 17:05 rgieseke

@techniq For what it's worth, since 8.1.0 you should be able to set xDomainSort={false} and avoid the step of looping through your data to get the uniques.

mhkeller avatar Jun 05 '24 02:06 mhkeller