-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
a version of .newPlot that does the .update logic behind the scenes #1850
Comments
Those are arguably |
I'd vote for adding a new |
Arriving at the delta spec between two subsequent specs sounds similar to a DOM diffing algo. With Étienne's |
This has been bugging me a bit, but the one problem I do see with this is that there's not currently a internal/virtual state to diff against. That is, One alternative is to allow passing the diffs themselves (like what the workspace does—specific attrs to update). The downside here is that you're just doing react's job for it, which does help you integrate plotly into a react app, but it's a bit pointless and awkward, declaratively speaking. In order to really say it's a properly reactified, we'd have to duplicate the state internally. That is, we'd clone The downside is that it requires a full copy of the data (with the possible exception of data arrays which could potentially be aliased). The most natural way to accomplish this would be to simply always clone the input when you plot. Perhaps The alternative is that the react component could manage the cloned data. |
Feel free to skim as I'm not sure if it's relevant here, but in addition to the API perimeter (input data in long arrays) there are also lots of calculations that happen inside the plots and traces, and some kind of diffing would be interesting there as well, for example, new data that breaches current axis domains may need to trigger axis tick etc. recalc, but if new data is within current bounds, it doesn't. Wouldn't the
which could maybe tackled by separating the API to a purely The |
...before I forget, Mike Bostock's heavy use of functional components is somewhere in between full batch recalculation that can be achieved by plain JS (imperatively or via functional programming), and the use of a reactive library. The setter methods can be written such a way that other inputs are considered constant, ie. some manual code can perform a more efficient update. Internally the functional component can cache (eagerly or lazily) things however it fits best. |
@rreusser - This is assuming that the user is modifying their In other words, this is assuming the user is doing something like:
And so therefore In my case (Dash), we're creating entirely new data and layout instances. It's more like:
In which case, the objects will always be different ( |
@chriddyp that's correct. The loophole is this case: data = [{'x': [1, 2, 3]}]
Plotly.react(data)
data[0].marker = {color: 'blue'};
data = [{'x': [1, 10, 3]}]
Plotly.react(data) It's not perfectly clear to me whether the marker will end up blue or not. Perhaps you shouldn't do this, but this approach doesn't prevent you from being able to do that. That's why I thought perhaps |
Side note: lots of people (mis?)use the plotly API this way: data = [{'x': [1, 2, 3]}]
Plotly.newPlot(gd, data)
data[0].marker = {color: 'blue'};
Plotly.redraw(gd) |
An alternative that has some interesting (good and bad) side effects: diff |
Closed by #2341 |
In Dash, I'd like the Graph component to do smart
restyle
andrelayout
updates when I callnewPlot
orplot
(or some new method). Dash users deal withfigure
s and not diffs.Programming this logic myself is a lot of work that other groups could benefit from if it was done centrally in plotly.js. I wrote a lot of the logic in the workspace and it took a while to work through all the kinks. Some of the edge cases included:
newPlot
instead ofupdate
at the startaddTraces
manually instead ofupdate
newPlot
instead ofupdate
when switching between 2D, 3D, or ternarynewPlot
when switching to a financial chart typeHere is that code
This would form the basis of a plotly.js React component.
Dash users will benefit from this immediately with:
Ideally, this logic would work its way into a robust
.animate
method as well (.animate method that can handle any type of figure diff #1849)cc @rreusser @alexcjohnson @etpinard @cpsievert @monfera @jackparmer
The text was updated successfully, but these errors were encountered: