@@ -206,23 +206,45 @@ export class ChartViewport extends UI.Widget.VBox {
206206 this . totalTime = totalTime ;
207207 }
208208
209- private onMouseWheel ( e : Event ) : void {
210- const wheelEvent = ( e as WheelEvent ) ;
211- const doZoomInstead = wheelEvent . shiftKey !==
212- ( Common . Settings . Settings . instance ( ) . moduleSetting ( 'flamechart-selected-navigation' ) . get ( ) === 'classic' ) ;
213- const panVertically = ! doZoomInstead && ( wheelEvent . deltaY || Math . abs ( wheelEvent . deltaX ) === 53 ) ;
214- const panHorizontally = doZoomInstead && Math . abs ( wheelEvent . deltaX ) > Math . abs ( wheelEvent . deltaY ) ;
215- if ( panVertically ) {
216- this . vScrollElement . scrollTop += ( wheelEvent . deltaY || wheelEvent . deltaX ) / 53 * this . offsetHeight / 8 ;
217- } else if ( panHorizontally ) {
218- this . handlePanGesture ( wheelEvent . deltaX , /* animate */ true ) ;
219- } else { // Zoom.
220- const wheelZoomSpeed = 1 / 53 ;
221- this . handleZoomGesture ( Math . pow ( 1.2 , ( wheelEvent . deltaY || wheelEvent . deltaX ) * wheelZoomSpeed ) - 1 ) ;
209+ /**
210+ * The mouse wheel can results in flamechart zoom, scroll and pan actions, depending on the scroll deltas and the selected navigation:
211+ *
212+ * Classic navigation:
213+ * 1. Mouse Wheel --> Zoom
214+ * 2. Mouse Wheel + Shift --> Scroll
215+ * 3. Trackpad: Mouse Wheel AND horizontal scroll (deltaX > deltaY): --> Pan left/right
216+ *
217+ * Modern navigation:
218+ * 1. Mouse Wheel -> Scroll
219+ * 2. Mouse Wheel + Shift -> Pan left/right
220+ * 3. Mouse Wheel + Ctrl/Cmd -> Zoom
221+ * 4. Trackpad: Mouse Wheel AND horizontal scroll (deltaX > deltaY): --> Zoom
222+ */
223+ private onMouseWheel ( wheelEvent : WheelEvent ) : void {
224+ const navigation = Common . Settings . Settings . instance ( ) . moduleSetting ( 'flamechart-selected-navigation' ) . get ( ) ;
225+ const scrollDelta = ( wheelEvent . deltaY || wheelEvent . deltaX ) / 53 * this . offsetHeight / 8 ;
226+ const zoomDelta = Math . pow ( 1.2 , ( wheelEvent . deltaY || wheelEvent . deltaX ) * 1 / 53 ) - 1 ;
227+
228+ if ( navigation === 'classic' ) {
229+ if ( wheelEvent . shiftKey ) { // Scroll
230+ this . vScrollElement . scrollTop += scrollDelta ;
231+ } else if ( Math . abs ( wheelEvent . deltaX ) > Math . abs ( wheelEvent . deltaY ) ) { // Pan left/right
232+ this . handlePanGesture ( wheelEvent . deltaX , /* animate */ true ) ;
233+ } else { // Zoom
234+ this . handleZoomGesture ( zoomDelta ) ;
235+ }
236+ } else if ( navigation === 'modern' ) {
237+ if ( wheelEvent . shiftKey ) { // Pan left/right
238+ this . handlePanGesture ( wheelEvent . deltaY , /* animate */ true ) ;
239+ } else if ( wheelEvent . ctrlKey || Math . abs ( wheelEvent . deltaX ) > Math . abs ( wheelEvent . deltaY ) ) { // Zoom
240+ this . handleZoomGesture ( zoomDelta ) ;
241+ } else { // Scroll
242+ this . vScrollElement . scrollTop += scrollDelta ;
243+ }
222244 }
223245
224246 // Block swipe gesture.
225- e . consume ( true ) ;
247+ wheelEvent . consume ( true ) ;
226248 }
227249
228250 private startDragging ( event : MouseEvent ) : boolean {
0 commit comments