tmf: Add support for grid lines in time graph
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 11 Aug 2015 20:33:50 +0000 (16:33 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Thu, 20 Aug 2015 22:24:59 +0000 (18:24 -0400)
This adds support for optional grid lines in the time graph control. The
default is that grid lines are enabled. The grid line color can be set.

Change-Id: Ia52371e05d83a951e2e5babe0fb36c62f08c6d13
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/54039
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java

index 70e7b7c7b1fd1f1f61706a9b24520bc7f0e6e5cc..8ad54836b226483dc51f6c11632bbaca7060a9e6 100644 (file)
@@ -153,6 +153,8 @@ public class TimeGraphControl extends TimeGraphBaseControl
     private final Cursor fZoomCursor = Display.getDefault().getSystemCursor(SWT.CURSOR_SIZEWE);
     private final List<ViewerFilter> fFilters = new ArrayList<>();
     private MenuDetectEvent fPendingMenuDetectEvent = null;
+    private boolean fGridLinesVisible = true;
+    private Color fGridLineColor = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
     private boolean fHideArrows = false;
     private int fAutoExpandLevel = ALL_LEVELS;
 
@@ -947,6 +949,48 @@ public class TimeGraphControl extends TimeGraphBaseControl
         fTimeProvider.setStartFinishTimeNotify(time0, time1);
     }
 
+    /**
+     * Set the grid lines visibility. The default is true.
+     *
+     * @param visible
+     *            true to show the grid lines, false otherwise
+     * @since 2.0
+     */
+    public void setGridLinesVisible(boolean visible) {
+        fGridLinesVisible = visible;
+    }
+
+    /**
+     * Get the grid lines visibility.
+     *
+     * @return true if the grid lines are visible, false otherwise
+     * @since 2.0
+     */
+    public boolean getGridLinesVisible() {
+        return fGridLinesVisible;
+    }
+
+    /**
+     * Set the grid line color. The default is SWT.COLOR_GRAY.
+     *
+     * @param color
+     *            the grid line color
+     * @since 2.0
+     */
+    public void setGridLineColor(Color color) {
+        fGridLineColor = color;
+    }
+
+    /**
+     * Get the grid line color.
+     *
+     * @return the grid line color
+     * @since 2.0
+     */
+    public Color getGridLineColor() {
+        return fGridLineColor;
+    }
+
     /**
      * Hide arrows
      *
@@ -1317,6 +1361,9 @@ public class TimeGraphControl extends TimeGraphBaseControl
 
         drawBackground(bounds, nameSpace, gc);
 
+        // draw the grid lines
+        drawGridLines(bounds, gc);
+
         // draw items
         drawItems(bounds, fTimeProvider, fItemData.fExpandedItems, fTopIndex, nameSpace, gc);
         drawLinks(bounds, fTimeProvider, fItemData.fLinks, nameSpace, gc);
@@ -1431,6 +1478,25 @@ public class TimeGraphControl extends TimeGraphBaseControl
         }
     }
 
+    /**
+     * Draw the grid lines
+     *
+     * @param bounds
+     *            The rectangle of the area
+     * @param gc
+     *            Reference to the SWT GC object
+     * @since 2.0
+     */
+    public void drawGridLines(Rectangle bounds, GC gc) {
+        if (!fGridLinesVisible) {
+            return;
+        }
+        gc.setForeground(fGridLineColor);
+        for (int x : fTimeGraphScale.getTickList()) {
+            gc.drawLine(x, bounds.y, x, bounds.y + bounds.height);
+        }
+    }
+
     /**
      * Draw many items at once
      *
index d625ed854974c3b27c30a1a7a2b3cf8cb0a06901..3dccccdf5b9a7a1d20e3ab244ba52e283d8b25d4 100644 (file)
@@ -17,6 +17,7 @@ package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets;
 
 import java.text.NumberFormat;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
@@ -120,6 +121,7 @@ public class TimeGraphScale extends TimeGraphBaseControl implements
     private long fTime1bak;
     private boolean fIsInUpdate;
     private int fHeight;
+    private List<Integer> fTickList = new ArrayList<>();
 
     /**
      * Standard constructor
@@ -201,6 +203,16 @@ public class TimeGraphScale extends TimeGraphBaseControl implements
         redraw();
     }
 
+    /**
+     * Get the list of visible ticks of the time axis.
+     *
+     * @return the list of visible tick x-coordinates
+     * @since 2.0
+     */
+    public List<Integer> getTickList() {
+        return fTickList;
+    }
+
     private long calcTimeDelta(int width, double pixelsPerNanoSec) {
         long timeDelta;
         double minDelta = (pixelsPerNanoSec == 0) ? YEAR_IN_NS : width / pixelsPerNanoSec;
@@ -334,6 +346,7 @@ public class TimeGraphScale extends TimeGraphBaseControl implements
         gc.fillRectangle(rect0);
 
         if (time1 <= time0 || timeSpace < 2) {
+            fTickList.clear();
             return;
         }
 
@@ -386,6 +399,7 @@ public class TimeGraphScale extends TimeGraphBaseControl implements
             timeDraw.drawAbsHeader(gc, time, absHeaderRect);
         }
 
+        List<Integer> tickList = new ArrayList<>();
         while (true) {
             int x = rect.x + leftSpace + (int) (Math.floor((time - time0) * pixelsPerNanoSec));
             if (x >= rect.x + leftSpace + rect.width - rect0.width) {
@@ -397,6 +411,7 @@ public class TimeGraphScale extends TimeGraphBaseControl implements
                 if (x + rect0.width <= rect.x + rect.width) {
                     timeDraw.draw(gc, time, rect0);
                 }
+                tickList.add(x);
             }
             if (pixelsPerNanoSec == 0 || time > Long.MAX_VALUE - timeDelta || timeDelta == 0) {
                 break;
@@ -427,6 +442,7 @@ public class TimeGraphScale extends TimeGraphBaseControl implements
                 time += timeDelta;
             }
         }
+        fTickList = tickList;
     }
 
     private static void drawRangeDecorators(Rectangle rect, GC gc, int x1, int x2) {
This page took 0.029565 seconds and 5 git commands to generate.