-
Notifications
You must be signed in to change notification settings - Fork 715
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
RFC: Consistency and Control #383
Conversation
Should we consider dropping our |
I always kind of liked the For the repo I'm working on it isn't a big deal so go for it. I like it when things get more consistent and changes will reduce overall confusion for new users! We use vx since The scale and accessor change is really nice as well. More power to the user. Nice job on the proposed changes and that's quite some work you had to do there 😅! |
Fixes collapsed line chart scales. For further information on the API change of vx/shape see airbnb/visx#383
Fixes collapsed line chart scales. For further information on the API change of vx/shape see airbnb/visx#383
Breaking changes are painful. I try to avoid them whenever possible. Getting vx to
v1
means I need to make a larger breaking change than I am typically comfortable with as a library author. In short, I made a poor design decision in the early days of this library that I now wish to fix. I hope you'll agree with me that it's for the best and will lead to a brighter future with more consistency and control.Summary
This pull request does the following:
additionalProps()
andcallOrValue()
zScale
prop tocolor
Motivation
Almost 2 years ago I started working on a library of components that brought together
react
andd3
at a lower-level than traditional charting libraries. Unfortunately, I made an api design choice that I've regretted for a long time now and it is time to rectify before releasing v1.Data Binding Before
Initially I thought the target audience would be existing
d3
developers that found themselves in a react codebase. So I went about making an api that would feel similar to d3 when it came to data binding.Let's walk through an example of rendering out a series of bars that are different colors based on each datum's name. (
data = [{ name: 'captain gary' }, // ...]
)So one coffee-fueled morning I thought "fine I'll bind props to data in react if you pass a function as a prop"
But wait, what about props that are typically functions like event handlers? Say you wanted to click on each colored bar and alert the bar's name. Well you would just pass a function that returns your click handler with the datum as the first argument.
🤦♂️ 🤦♂️
What's so bad about this? It no longer feels like
react
. vx components become special in the sense you need to know about this silly pattern and it's not like other react components. This is confusing: #50 #199 #328Data Binding After
Then came the realization that the target audience for
vx
was reallyreact
developers that needed data visualization without having to learnd3
.Seems like a confusing api tradeoff for the added ability of setting a prop based on a datum value. Along came render props. Let's take a look at what the new api looks like with render props.
This means vx components are no longer opaque boxes with special rules. You now have more control over what's rendered and it's more transparent how it works following common patterns in react land.
This is a change I've wanted to make for a long time. It took a lot boring work to make it happen, but I think it's finally ready.
What about Hooks?
I was just as surprised as everyone else about the react Hooks announcement at ReactConf. The day they were announced, I was finishing migrating all of the gallery tiles to the new api and I had the panic moment of, "oh no this new api is going to be dead-on-arrival".
The Hooks announcement talked about how hooks can replace render props with the benefit of not introducing a false hierarchy to your render. This is great and I look forward to updating vx to include hooks. That said, Hooks are still a proposal available on an alpha release of react. Currently, vx supports react 15 and 16. vx will look to support hooks in a future release. I see the render props api as an immediate improvement for all users of vx where hooks would only support those lucky enough to be in a codebase on 16.7 alpha.
Initial thoughts are hooks are the future of react, so vx will support them when they are more widely available.
Accessors + Scales Before
In the beginning, I found myself often having to apply my scale on the accessor value. So I turned this into a pattern in vx. You would pass in your scale and your accessor separately and vx would apply them for you. It used look like this:
behind the scenes vx would create a line path from d3-shape's line generator
Again this isn't transparent. Let's make it transparent.
Accessors + Scales After
This api simplifies what vx is doing behind the scenes as well to:
This gives transparency, consistency with the d3 api, and gives you more control over shape generation.
Closing thoughts
I worry about the early adopters that are not going to be happy about having to update their code due to these breaking changes, but the longer the I wait to make this the bigger the hill will be to climb.
Would love to hear your thoughts.
Changelog
💥 Breaking Changes
🏠 Internal
cc @williaster @conglei @techniq