-
-
Notifications
You must be signed in to change notification settings - Fork 137
Graph not changing on input change #59
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
Comments
I'm just in the middle of updating the documentation and pulling together a release of this component which clears up this behaviour :) |
Awesome @nicolaskruchten any ETA & solution for the in the meantime? |
Literally 10 minutes and I'll have the new version on NPM :) |
OK, please try using version 1.7.0 and let me know if you're still having issues. If so, please provide some sample code that shows what is happening and explain what you would expect to have happen :) |
(sorry, hit the wrong button) |
Also, please check out the new notes in the |
Sadly it still doesn't work, will provide some code samples tomorrow. |
OK. Are you adding data points to a data array or something like that? If you want to mutate the input you'll have to bump the revision number. |
Yes and yes haha. I am indeed adding datapoints to an array, but creating a new array in the process. Also I bump the revision number. the onUpdate callback is called btw. |
So the |
exactly |
Very strange. I'd love to see some sample code and I can help you debug :) |
class Monitoring extends React.Component {
state = {
realtimeData: [
{
type: "scatter",
mode: "lines+points",
x: [1, 2, 3],
y: [2, 6, 3],
marker: { color: "#fdcc00" },
line: { shape: "spline" }
}
]
};
componentDidMount() {
// Simulate realtime data
setInterval(() => {
let newRealtimeData = [...this.state.realtimeData];
newRealtimeData[0].x.push(newRealtimeData[0].x.length + 1);
newRealtimeData[0].y.push(Math.floor(Math.random() * 6) + 1);
this.setState({
realtimeData: newRealtimeData
});
}, 2000);
}
render() {
return (
<div>
<MonitorChart
realtimeData={this.state.realtimeData}
/>
</div>
}
} const MonitorChart = props => {
const { realtimeData } = props;
return (
<div>
<Panel
header={<PanelHeader number={1} stageName={"Chart"} />}
initialOpen={true}
>
<Chart data={realtimeData} />
</Panel>
</div>
);
}; class Chart extends React.Component {
state = {
revisionNo: 1
};
componentWillReceiveProps(nextProps) {
this.setState((prevState, props) => {
return { revisionNo: prevState.revisionNo + 1 };
});
}
updateHandler = () => {
console.log("Updated");
};
render() {
return (
<div style={{ marginTop: "10px" }}>
<Plot
divId={"chartmonitoring"}
revision={this.state.revisionNo}
style={{
width: "90%",
height: "100%"
}}
useResizeHandler={true}
data={this.props.data}
onUpdate={this.updateHandler}
/>
</div>
);
}
} I'm using webpack with the |
Thanks for this, I'll try to debug it this morning :) |
OK, here's a stripped-down CodePen version of your code: https://codepen.io/nicolaskruchten/pen/XEWmGY?editors=1010 The issue is that although you're creating a copy of the You have two options moving forward:
|
@nicolaskruchten I'm experiencing a similar issue. I have a chart that is not being refreshed even when both the
but based on the code, it seems that even if the revision prop is defined and has changed, at least one of the second and third conditions still has to be true in order for the plot to be refreshed, meaning that only bumping the |
@antoinerg can you take a look at this please? |
Hey, everyone! Take a look in this solution with explanations in how to create a graph using React and Plot.ly with the life cycle of the React. https://medium.com/@jmmccota/plotly-react-and-dynamic-data-d40c7292dbfb |
I've run into the same issue and inside of the componentWillUpdate code the values of nextProps and this.props is always the same, making the equality check always true and it does not rerender. I tried changing the method to shouldComponentUpdate, and the references of "this" to "_this3" like in the other functions, but could not fix it. Ultimately I wrapped the component in a div and used the chart's datarevision as that div's key. It causes the entire div and plot to be recreated from scratch (rather than update), but it works. |
@dmt0 can you grab this one too plz? |
OK, so our readme says:
Our code is:
So clearly as per the code we have to change revision AND identity of data or layout. @jaredrcleghorn is that what you're referring to? |
@dmt0 Yes that is what I was referring to. If I know what the desired functionality was, I would be happy to fix either the code or the README and submit a pull request myself, but the whole problem is that I don't know which one is wrong. |
@dmt0 this seems like I made a coding or refactoring error... I'm pretty sure the readme describes the desired behaviour. |
@nicolaskruchten Yeah, I've been looking at blame, and it seems that you were fixing the infinite loop issue, let's chat :) |
Yeah. You know, the @jaredrcleghorn what do you think? Is |
If we bump the major version, I would also like to replace |
BTW, tested @jaredrcleghorn's PR against our RCE, things work. |
I don't claim to be an expert, but wouldn't shouldComponentUpdate be preferable to componentDidUpdate? That way you can use this logic to prevent the update. |
@GrandVizierOlaf
Tried it out, in our setup, things work. |
@nicolaskruchten It would have been useful to me in the situation I was in when I originally posted on this issue. I got around the problem by basically changing the identity of one of the other props for the sole purpose of forcing a refresh, so it would have been much cleaner if I had been able to use |
we can do this anyway, without bumping the major version number IMO. It might be nicer to use |
Previously, chaning the revision prop alone was not sufficient to cause the plot to be refreshed, contrary to the behavior indicated in the REAMDE. Fix this so that the revision prop can be used to force the plot to be refreshed. Resolves: #59
Previously, chaning the revision prop alone was not sufficient to cause the plot to be refreshed, contrary to the behavior indicated in the REAMDE. Fix this so that the revision prop can be used to force the plot to be refreshed. Resolves: #59
Fix is merged and will be available after the next version bump :) |
Fixed released in v2.3.0. Gonna close this issue. Feel free to let us know if problems remain. |
According to the docs:
This component currently creates a new plot every time the input changes.
It seems like the graph would do a redraw once the data changed. When passing updated props to the
<Plot/>
data attribute the plot stays the same.Even when checking in
componentWillReceiveProps()
thenextProps.data
is different than thethis.props.data
.Update:
The same seems true when incrementing the revision attribute.
The text was updated successfully, but these errors were encountered: