From 11196aa0fdcc934f1d895ad588ba8f28e20f8a9e Mon Sep 17 00:00:00 2001 From: Jamie Wong Date: Sun, 26 Nov 2017 20:39:55 -0800 Subject: [PATCH] Resize handling WIP --- flamechart.tsx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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