(core) Fix JS error when switching to a page containing a chart.

Summary:
- The error appeared recently, due to more frequent resize calls (added for mobile)
- In fact, charts' own resize logic can now be simplified.

Test Plan: Added a test case (which fails without the fix)

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D2739
This commit is contained in:
Dmitry S 2021-02-25 10:07:05 -05:00
parent 05edd80ce7
commit 31ffd21b4e

View File

@ -105,21 +105,18 @@ export class ChartView extends Disposable {
private _options: ObjObservable<any>;
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() {