diff --git a/app/client/components/ChartView.ts b/app/client/components/ChartView.ts index f67341f3..1c79772a 100644 --- a/app/client/components/ChartView.ts +++ b/app/client/components/ChartView.ts @@ -105,21 +105,18 @@ export class ChartView extends Disposable { private _options: ObjObservable; private _chartDom: HTMLElement; private _update: () => void; + private _resize: () => void; public create(gristDoc: GristDoc, viewSectionModel: ViewSectionRec) { BaseView.call(this as any, gristDoc, viewSectionModel); this._chartDom = this.autoDispose(this.buildDom()); + this._resize = this.autoDispose(Delay.untilAnimationFrame(this._resizeChart, this)); + // Note that .viewPane is used by ViewLayout to insert the actual DOM into the document. this.viewPane = this._chartDom; - // Resize if the window resizes since that can change the layout leaf size. - // TODO: Belongs into ViewLayout which already does BaseView.onResize for side-pane open/close. - const resizeChart = this.autoDispose(Delay.untilAnimationFrame(this._resizeChart, this)); - window.addEventListener('resize', resizeChart); - this.autoDisposeCallback(() => window.removeEventListener('resize', resizeChart)); - this._chartType = this.viewSection.chartTypeDef; this._options = this.viewSection.optionsObj; @@ -142,7 +139,7 @@ export class ChartView extends Disposable { } protected onResize() { - this._resizeChart(); + this._resize(); } protected buildDom() {