From bc7fa4fc1cf0c54854d6ef15940e16f9bafe83c6 Mon Sep 17 00:00:00 2001 From: Jamie Wong Date: Sun, 26 Nov 2017 20:03:34 -0800 Subject: [PATCH] simple pinch-to-zoom support --- flamechart.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/flamechart.tsx b/flamechart.tsx index cefe29e..b9db721 100644 --- a/flamechart.tsx +++ b/flamechart.tsx @@ -391,9 +391,17 @@ export class FlamechartView extends Component { // initiated momentum scrolling may still take effect. // Figure out how to prevent this. // - // Also, support drag-based panning, and pinch-to-zoom - if (ev.metaKey) { - const multiplier = 1 + (ev.deltaY / 100) + // Also, support drag-based panning. + if (ev.metaKey || ev.ctrlKey) { + let multiplier = 1 + (ev.deltaY / 100) + + // On Chrome & Firefox, pinch-to-zoom maps to + // WheelEvent + Ctrl Key. We'll accelerate it in + // this case, since it feels a bit sluggish otherwise. + if (ev.ctrlKey) { + multiplier = 1 + (ev.deltaY / 40) + } + this.zoom(new Vec2(ev.offsetX, ev.offsetY), multiplier) } else { this.pan(new Vec2(ev.deltaX, ev.deltaY))