Skip to content

Commit

Permalink
fix: try to get canvas post mounting (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
monfera authored Jan 23, 2020
1 parent 05c2b24 commit 141f465
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/chart_types/partition_chart/renderer/canvas/partition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ class PartitionComponent extends React.Component<PartitionProps> {
}
}

private tryCanvasContext() {
const canvas = this.canvasRef.current;
this.ctx = canvas && canvas.getContext('2d');
}

componentDidUpdate() {
if (!this.ctx) {
this.tryCanvasContext();
}
if (this.props.initialized) {
this.drawCanvas();
this.props.onChartRendered();
Expand All @@ -54,8 +62,7 @@ class PartitionComponent extends React.Component<PartitionProps> {
componentDidMount() {
// the DOM element has just been appended, and getContext('2d') is always non-null,
// so we could use a couple of ! non-null assertions but no big plus
const canvas = this.canvasRef.current;
this.ctx = canvas && canvas.getContext('2d');
this.tryCanvasContext();
this.drawCanvas();
}

Expand Down

0 comments on commit 141f465

Please sign in to comment.