Added resize listener after handler was created (#49452) (#49708)

This commit is contained in:
igoristic 2019-10-30 04:32:11 -04:00 committed by GitHub
parent 2eb2e17e07
commit a586f3025f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,6 +35,7 @@ export class ChartTarget extends React.Component {
componentWillUnmount() {
this.shutdownChart();
window.removeEventListener('resize', this._handleResize);
this.componentUnmounted = true;
}
filterByShow(seriesToShow) {
@ -62,7 +63,6 @@ export class ChartTarget extends React.Component {
componentDidMount() {
this.renderChart();
window.addEventListener('resize', this._handleResize, false);
}
componentDidUpdate() {
@ -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; }
@ -110,6 +113,8 @@ export class ChartTarget extends React.Component {
}
};
window.addEventListener('resize', this._handleResize, false);
this.handleMouseLeave = () => {
eventBus.trigger('thorPlotLeave', []);
};