tmf.ui: make XY charts zoom on CTRL-MOUSEWHEEL
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 10 Jun 2016 21:40:08 +0000 (17:40 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 21 Jun 2016 18:31:33 +0000 (14:31 -0400)
This makes the control much more inline with tracecompass as mousewheel
is typically for moving up-down.

Change-Id: I6de6a809e0b15161e6059939d8aedff65f2a596e
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/75102
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/TmfMouseWheelZoomProvider.java

index 2c7a63acba76c47a6baf45a7f7840eb3041327de..f67fef7f13fbbb359fc5f8e929c816502b83eab3 100644 (file)
 
 package org.eclipse.tracecompass.tmf.ui.viewers.xycharts;
 
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.MouseWheelListener;
 import org.swtchart.IAxis;
+import org.swtchart.Range;
 
 /**
  * Class for providing zooming based on mouse wheel. It centers the zoom on
@@ -71,32 +73,39 @@ public class TmfMouseWheelZoomProvider extends TmfBaseProvider implements MouseW
     public synchronized void mouseScrolled(MouseEvent event) {
         ITmfChartTimeProvider viewer = getChartViewer();
 
-        long oldDuration = viewer.getWindowDuration();
-
-        if (oldDuration == 0 || event.count == 0) {
-            return;
+        final int count = event.count;
+        if (count != 0 && (event.stateMask & SWT.CTRL) != 0) {
+            final int x = event.x;
+            zoom(viewer, count, x);
         }
+    }
 
+    private void zoom(ITmfChartTimeProvider viewer, final int count, final int x) {
         // Compute the new time range
-        long newDuration = oldDuration;
+        long newDuration = viewer.getWindowDuration();
+        if (newDuration == 0 || count == 0) {
+            return;
+        }
         double ratio = 1.0;
-        if (event.count > 0) {
+        if (count > 0) {
             ratio = ZOOM_FACTOR;
-            newDuration = Math.round(ZOOM_FACTOR * oldDuration);
+            newDuration = Math.round(ZOOM_FACTOR * newDuration);
         } else {
             ratio = 1.0 / ZOOM_FACTOR;
-            newDuration = (long) Math.ceil(oldDuration * ratio);
+            newDuration = (long) Math.ceil(newDuration * ratio);
         }
         newDuration = Math.max(MIN_WINDOW_SIZE, newDuration);
 
         // Center the zoom on mouse position, distribute new duration and adjust for boundaries.
         IAxis xAxis = getChart().getAxisSet().getXAxis(0);
-        long timeAtXPos = limitXDataCoordinate(xAxis.getDataCoordinate(event.x)) + viewer.getTimeOffset();
+        long timeAtXPos = limitXDataCoordinate(xAxis.getDataCoordinate(x)) + viewer.getTimeOffset();
         // Note: ratio = newDuration/oldDuration
         long newWindowStartTime = timeAtXPos - Math.round(ratio * (timeAtXPos - viewer.getWindowStartTime()));
         long newWindowEndTime = validateWindowEndTime(newWindowStartTime, newWindowStartTime + newDuration);
         newWindowStartTime = validateWindowStartTime(newWindowStartTime);
         viewer.updateWindow(newWindowStartTime, newWindowEndTime);
+        xAxis.setRange(new Range(newWindowStartTime - viewer.getTimeOffset(),
+            newWindowEndTime - viewer.getTimeOffset()));
     }
 
     // ------------------------------------------------------------------------
This page took 0.028059 seconds and 5 git commands to generate.