Skip to content

Commit

Permalink
Added resize listener after handler was created (#49452) (#49707)
Browse files Browse the repository at this point in the history
  • Loading branch information
igoristic authored Oct 30, 2019
1 parent 8107ecc commit 20e5760
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class ChartTarget extends React.Component {
componentWillUnmount() {
this.shutdownChart();
window.removeEventListener('resize', this._handleResize);
this.componentUnmounted = true;
}

filterByShow(seriesToShow) {
Expand Down Expand Up @@ -62,7 +63,6 @@ export class ChartTarget extends React.Component {

componentDidMount() {
this.renderChart();
window.addEventListener('resize', this._handleResize, false);
}

componentDidUpdate() {
Expand Down Expand Up @@ -94,6 +94,9 @@ export class ChartTarget extends React.Component {
const data = this.filterData(series, this.props.seriesToShow);

this.plot = $.plot(target, data, await this.getOptions());
if (this.componentUnmounted || !this.plot) {
return;
}

this._handleResize = () => {
if (!this.plot) { return; }
Expand All @@ -110,6 +113,8 @@ export class ChartTarget extends React.Component {
}
};

window.addEventListener('resize', this._handleResize, false);

this.handleMouseLeave = () => {
eventBus.trigger('thorPlotLeave', []);
};
Expand Down

0 comments on commit 20e5760

Please sign in to comment.