Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Don't attempt to resize unmounted graphs #563

Merged
merged 7 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Fixed
- Fixed `min_date_allowed` and `max_date_allowed` bug in `DatePickerRange` [#551]https://github.com/plotly/dash-core-components/issues/551)
- Fixed unwanted `resize()` calls on unmounted `Graph`s [#534](https://github.com/plotly/dash-core-components/issues/534)

### Changed
- Changed `dcc.Checklist` prop `values` to `value`, to match all the other input components [#558](https://github.com/plotly/dash-core-components/pull/558). Also improved prop types for `Dropdown` and `RadioItems` `value` props to consistently accept both strings and numbers.
Expand Down
23 changes: 17 additions & 6 deletions src/components/Graph.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class PlotlyGraph extends Component {
super(props);
this.bindEvents = this.bindEvents.bind(this);
this._hasPlotted = false;
this.graphResize = this.graphResize.bind(this);
}

plot(props) {
Expand All @@ -111,9 +112,13 @@ class PlotlyGraph extends Component {
config: config,
}).then(() => {
if (!this._hasPlotted) {
this.bindEvents();
Plotly.Plots.resize(document.getElementById(id));
this._hasPlotted = true;
// double-check gd hasn't been unmounted
const gd = document.getElementById(id);
if (gd) {
this.bindEvents();
Plotly.Plots.resize(gd);
this._hasPlotted = true;
}
}
});
}
Expand Down Expand Up @@ -141,6 +146,13 @@ class PlotlyGraph extends Component {
return Plotly.extendTraces(id, updateData, traceIndices, maxPoints);
}

graphResize() {
const graphDiv = document.getElementById(this.props.id);
if (graphDiv) {
Plotly.Plots.resize(graphDiv);
}
}

bindEvents() {
const {id, setProps, clear_on_unhover} = this.props;

Expand Down Expand Up @@ -195,16 +207,15 @@ class PlotlyGraph extends Component {

componentDidMount() {
this.plot(this.props).then(() => {
window.addEventListener('resize', () => {
Plotly.Plots.resize(document.getElementById(this.props.id));
});
window.addEventListener('resize', this.graphResize);
});
}

componentWillUnmount() {
if (this.eventEmitter) {
this.eventEmitter.removeAllListeners();
}
window.removeEventListener('resize', this.graphResize);
}

shouldComponentUpdate(nextProps) {
Expand Down
Loading