Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: error if chart destroyed during resize (#2547)
* fix: error if chart destroyed during resize

* chore: update chart spec to include chart destroyed variable used in forceFit

* fix: add suggested test
  • Loading branch information
jdbence committed Jun 12, 2020
1 parent b431148 commit 2290ed3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/chart/chart.ts
Expand Up @@ -156,9 +156,12 @@ export default class Chart extends View {
* 自动根据容器大小 resize 画布
*/
public forceFit() {
// 注意第二参数用 true,意思是即时 autoFit = false,forceFit() 调用之后一样是适配容器
const { width, height } = getChartSize(this.ele, true, this.width, this.height);
this.changeSize(width, height);
// skip if already destroyed
if(!this.destroyed){
// 注意第二参数用 true,意思是即时 autoFit = false,forceFit() 调用之后一样是适配容器
const { width, height } = getChartSize(this.ele, true, this.width, this.height);
this.changeSize(width, height);
}
}

private updateCanvasStyle() {
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/chart/chart-spec.ts
Expand Up @@ -174,6 +174,8 @@ describe('Chart', () => {
expect(chart.getLayer(LAYER.FORE).destroyed).toBe(true);
expect(destroyEvent).toBeCalledTimes(1);

expect(() => { chart.forceFit() }).not.toBeThrow();
expect(chart.destroyed).toBe(true);
expect(chart.canvas.destroyed).toBe(true);
expect(div.childNodes.length).toBe(0);

Expand Down

0 comments on commit 2290ed3

Please sign in to comment.