Skip to content

Commit

Permalink
feat: add resize observer
Browse files Browse the repository at this point in the history
  • Loading branch information
scmmishra authored Apr 18, 2021
1 parent 10b1010 commit 12533f3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/js/charts/BaseChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ export default class BaseChart {

// Bind window events
this.boundDrawFn = () => this.draw(true);
if (ResizeObserver) {
this.resizeObserver = new ResizeObserver(this.boundDrawFn);
this.resizeObserver.observe(this.parent);
}
window.addEventListener('resize', this.boundDrawFn);
window.addEventListener('orientationchange', this.boundDrawFn);
}

destroy() {
if (this.resizeObserver) this.resizeObserver.disconnect();
window.removeEventListener('resize', this.boundDrawFn);
window.removeEventListener('orientationchange', this.boundDrawFn);
}
Expand Down

0 comments on commit 12533f3

Please sign in to comment.