From 12533f3b376328a8437109977910c8f2041572e5 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Sun, 18 Apr 2021 10:26:00 +0000 Subject: [PATCH] feat: add resize observer --- src/js/charts/BaseChart.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/js/charts/BaseChart.js b/src/js/charts/BaseChart.js index 328a163a..3cc5695d 100644 --- a/src/js/charts/BaseChart.js +++ b/src/js/charts/BaseChart.js @@ -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); }