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

Immutable scales. #121

Open
mbostock opened this issue Oct 26, 2017 · 3 comments
Open

Immutable scales. #121

mbostock opened this issue Oct 26, 2017 · 3 comments
Milestone

Comments

@mbostock
Copy link
Member

What if scales were immutable, and all methods that currently mutate scales instead returned new scales? It would eliminate the need for scale.copy, simplify the logic in d3-axis, and generally make scales easier to understand.

It would require a change to the implicit domain behavior of ordinal scales: these scales mutate on use! It’s not too onerous to require you to initialize the scale’s domain, however, and that is already a strongly recommended pattern for deterministic behavior and generating keys.

@mbostock mbostock added this to the 2.0 milestone Oct 26, 2017
@curran
Copy link
Contributor

curran commented Oct 27, 2017

FWIW, The mutation on use with ordinal scales really confused me the first time I came across it.

@hhalex
Copy link

hhalex commented Mar 17, 2018

I totally agree, I think immutability should be the way to go for simple data structures.

@thomassuckow
Copy link

I'm working on a charting "library" and was finding that immutable scales are pretty much a necessity to keep my sanity. Especially as I implement zooming which has to muck with the domain.

Have you thought about this further?

The other thing that I am thinking about is that the tick marks should probably also be separated. As is, you can't "wrap" a scale because if the original scales domain is not updates the tick marks are not generated appropriately. The log and linear tick marks would probably be roughly the same if separated. Have a tick mark generator and pass it a scale, and it can work it's magic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants