diff --git a/flamechart.tsx b/flamechart.tsx index b9db721..0ca579c 100644 --- a/flamechart.tsx +++ b/flamechart.tsx @@ -410,6 +410,34 @@ export class FlamechartView extends Component { this.renderGL() } + componentDidMount() { + window.addEventListener('resize', () => { + const width = window.innerWidth + const height = window.innerHeight + if (this.canvas) { + const oldWidth = this.canvas.width + const oldHeight = this.canvas.height + this.canvas.width = width + this.canvas.height = height + + // Resize the world-space viewport rectangle to match the + // window size. + this.worldSpaceViewportRect = this.worldSpaceViewportRect.withSize( + this.worldSpaceViewportRect.size.timesPointwise(new Vec2( + width / oldWidth, + height / oldHeight + )) + ) + this.renderGL() + } + if (this.overlayCanvas) { + this.overlayCanvas.width = width * DEVICE_PIXEL_RATIO + this.overlayCanvas.height = height * DEVICE_PIXEL_RATIO + this.renderLabels() + } + }) + } + render() { // TODO(jlfwong): Handle node and/or window resizing