tmf: Show closest event tool tip when hovering over blank space
authorPatrick Tasse <patrick.tasse@gmail.com>
Mon, 1 Feb 2016 22:57:55 +0000 (17:57 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Tue, 2 Feb 2016 22:05:07 +0000 (17:05 -0500)
Show the tool tip for the closest between the next and previous event
when hovering over the blank space of a time graph entry, if the
distance to the event position is within a threshold.

Change-Id: I8a95d488e03c1d5012a1ee0bd4597f863b2ba3b6
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/65612
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java

index 0f6d1b18089d9de04a2a4b39d263aec2397110db..c7cb8329f3b0473d0ea39a27509df2aed1eac667 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (c) 2007, 2014 Intel Corporation, Ericsson
+ * Copyright (c) 2007, 2016 Intel Corporation, Ericsson
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -59,6 +59,8 @@ public class TimeGraphTooltipHandler {
 
     private static final int OFFSET = 16;
 
+    private static final int HOVER_MAX_DIST = 10;
+
     private Shell fTipShell;
     private Composite fTipComposite;
     private ITimeDataProvider fTimeDataProvider;
@@ -183,6 +185,34 @@ public class TimeGraphTooltipHandler {
                         currPixelTime = nextEvent.getTime();
                     }
 
+                    /*
+                     * if there is still no current event, use the closest
+                     * between the next and previous event, as long as they are
+                     * within a distance threshold
+                     */
+                    if (currEvent == null || currEvent instanceof NullTimeEvent) {
+                        int nextDelta = Integer.MAX_VALUE;
+                        int prevDelta = Integer.MAX_VALUE;
+                        long nextTime = 0;
+                        long prevTime = 0;
+                        if (nextEvent != null && !(nextEvent instanceof NullTimeEvent)) {
+                            nextTime = nextEvent.getTime();
+                            nextDelta = Math.abs(timeGraphControl.getXForTime(nextTime) - pt.x);
+                        }
+                        ITimeEvent prevEvent = Utils.findEvent(entry, currPixelTime, -1);
+                        if (prevEvent != null && !(prevEvent instanceof NullTimeEvent)) {
+                            prevTime = prevEvent.getTime() + prevEvent.getDuration() - 1;
+                            prevDelta = Math.abs(pt.x - timeGraphControl.getXForTime(prevTime));
+                        }
+                        if (nextDelta < HOVER_MAX_DIST && nextDelta <= prevDelta) {
+                            currEvent = nextEvent;
+                            currPixelTime = nextTime;
+                        } else if (prevDelta < HOVER_MAX_DIST) {
+                            currEvent = prevEvent;
+                            currPixelTime = prevTime;
+                        }
+                    }
+
                     // state name
                     String stateTypeName = fTimeGraphProvider.getStateTypeName(entry);
                     String entryName = entry.getName();
This page took 0.025929 seconds and 5 git commands to generate.