-
-
Notifications
You must be signed in to change notification settings - Fork 137
Closed
Description
Seeking feedback from @etpinard @alexcjohnson @bpostlethwaite on the best location for Plotly.react
. I can imagine a few possibilities:
- it should go in
plotly.js
and we just have to add a couple lines of code to this repo to make use of it.
- Pro: react-like functionality usable from any library
- Con: more code in plotly.js
- it goes in this repo. It computes a diff (maybe using the schema to figure out what to do about array data, with optional flag to apply immutable-like reference-change logic to simplify diff computation) and sends the result to the relevant plotly.js API methods.
- Pro/con: opposites of above
Unless I'm wrong, sounds like @alexcjohnson is/will be working on Plotly.react
. I just wanted to confirm that's what this will link up with.
Activity
rreusser commentedon Oct 18, 2017
@nicolaskruchten Sounds good! Alternatively, maybe it's worthwhile to add a "don't be clever" switch that tells it to replot even when
Plotly.react
is available (which would amount to a not-even-one-line override when checking the availability ofPlotly.react
).nicolaskruchten commentedon Oct 18, 2017
Yeah the
no_cleverness
flag might be a nice feature for me :)Nauss commentedon Oct 20, 2017
I'm using plotly.js in a React environment and I would like to add this:
This is just a quick remark, I'll be happy to go into more details if needed.
rreusser commentedon Oct 20, 2017
@Nauss Thanks for the feedback!
Regarding your first point, that's the precise concern. The standard react-like approach is to clone everything, compare it to the new input, and apply changes. For plotly.js, that won't work for cases like yours. We've been talking about applying some heuristics instead. Specifically:
immutable
mode that only checks the reference (and length, perhaps)revision
counter so that you can tell it when the plot has been revised and it needs, at the very least, to redraw the traces. (implemented currently, though it leads to a fullnewPlot
instead of just indicating it needs to restyle the traces.)As for resizing, there are perhaps a couple options. First, I added a
fit
prop that lets you automatically adjust the plot to the size of the parent container when the window resizes. This is a common use case, but not very general. For more general resizes, you should be able to just change the size in the layout and it will decide it only needs to executePlotly.relayout
to resize the plot—which is the best performing way to resize a plot.Hope that addresses your concerns! Please feel free to follow up though!
Nauss commentedon Oct 20, 2017
Thanks for the quick answer :)
We have a naive implementation for now but I'll try v1.0 next and come back here for a feedback.
Thanks for the great work !!
rreusser commentedon Oct 20, 2017
@Nauss Sounds good! Just to be clear, v1.0 does do a full replot on every change. It's meeting our current need, though it might not be adequate for you until v2.0. Regarding the mouse resizing, I think there's no reason you couldn't use
overflow: hidden
on your panel and not pass the updated size layout until mouseup.swiperii commentedon Dec 17, 2017
We are trying to use
react-plotly.js
in our react app, which displays e.g. scatter plots of real-time production data. That is, our data series are updated with new data regularly. And without aPlotly.react
method, all user interactions (zoom area, point selections, toolbar choice,...) are of course reset for each new data point.Is there any way to avoid this with the current plotly react component? Any workaround that would allow us to add data without completely resetting the plot state?
If not, what is the current status of the
Plotly.react
method? Any chance that this type of scenario will be supported in the near future?fixes #103
fixes #103
fixes #103
fixes #103
nicolaskruchten commentedon Jan 23, 2018
@swiperii if you want to create a separate issue I'd be happy to try to help you accomplish your goals within the current framework. Most likely you'll need to handle the updates and feed the layout back to the props along with the new data points.
nicolaskruchten commentedon Jan 23, 2018
To clarify the next steps... The
Plotly.react
functionality will be added to plotly.js, and progress on that can be tracked here: plotly/plotly.js#1850Once the upstream functionality is in place, this React component will be modified to take advantage of it and we can then close this current issue :)
swiperii commentedon Jan 24, 2018
@nicolaskruchten Thanks for your response. I have currently made my own Plotly.react method that uses add/deleteTraces, restyle and some ugly hacks to make data updates work together with zoom and selections. There are still some bugs though, so I eagerly look forward to the real thing :)
nicolaskruchten commentedon Feb 12, 2018
Good news! The
Plotly.react
method is implemented in plotly.js version 1.34.0 and this React wrapper already takes advantage of it, so just upgrade plotly.js and things should be more reactive!AyoCodess commentedon Nov 22, 2021
is there a solution for this?. As the plot automatically re-draws when any the data object changes. i.e an x-axis data point.
bpostlethwaite commentedon Nov 23, 2021
There is a Plotly react component that was produced from this here: https://github.com/plotly/react-plotly.js/
There is also the .react method on the vanilla plotly object.