Last active
January 8, 2019 17:19
-
-
Save ajcrites/d694f802e6005398e227be19f804dc14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class TimesTable extends React.Component<{ timesTable, pointCount, lineColor }> { | |
canvasRef = React.createRef(); | |
redraw = () => { | |
this.canvasRef.current.height = window.innerHeight; | |
this.canvasRef.current.width = window.innerWidth; | |
this.forceUpdate(); | |
}; | |
componentDidMount() { | |
const canvas = this.canvasRef.current; | |
canvas.height = window.innerHeight; | |
canvas.width = window.innerWidth; | |
window.addEventListener('resize', this.redraw); | |
} | |
componentWillUnmount() { | |
window.removeEventListener('resize', this.redraw); | |
} | |
componentDidUpdate() { | |
// Setting width/height even to the same value clears the canvas | |
this.canvasRef.current.width = this.canvasRef.current.width; | |
} | |
render() { | |
return ( | |
<canvas ref={this.canvasRef}> | |
<Viz ctx={this.canvasRef.current ? this.canvasRef.current.getContext('2d') : null} {...this.props} /> | |
</canvas> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment