tmf: Fix time range histogram to show its full range
authorPatrick Tasse <patrick.tasse@gmail.com>
Fri, 8 Nov 2013 16:36:31 +0000 (11:36 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Mon, 25 Nov 2013 20:48:27 +0000 (15:48 -0500)
- Set the end time of the time range histogram to the time range end
time (instead of the last event time)
- Display the time range text controls even when model has no events
- Snap selection to the end time
- Draw the delimiter to the right of the end time instead of last event
time
- Fill the area to the right of the delimiter with the background color
- Draw selection range anywhere in the histogram range regardless of
last event time

Change-Id: I913d22a20d79a3ca138902acd0d9cc815918cbc9
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/18307
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
IP-Clean: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramDataModel.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/TimeRangeHistogram.java

index 4c679215794a6d65ca8c24200bb296d710ae16f0..d2690bef07ba0d53a2f6136651b3653198999b56 100644 (file)
@@ -100,6 +100,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
     private final Color fLastEventColor = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED);
     private final Color fHistoBarColor = new Color(Display.getDefault(), 74, 112, 139);
     private final Color fLostEventColor = new Color(Display.getCurrent(), 208, 62, 120);
+    private final Color fFillColor = Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -509,15 +510,8 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
                         synchronized (fDataModel) {
                             if (fScaledData != null) {
                                 fCanvas.redraw();
-                                if (fDataModel.getNbEvents() != 0) {
-                                    // Display histogram and update X-,Y-axis
-                                    // labels
-                                    fTimeRangeStartText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getFirstBucketTime()));
-                                    fTimeRangeEndText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime()));
-                                } else {
-                                    fTimeRangeStartText.setText(""); //$NON-NLS-1$
-                                    fTimeRangeEndText.setText(""); //$NON-NLS-1$
-                                }
+                                // Display histogram and update X-,Y-axis labels
+                                updateRangeTextControls();
                                 long maxNbEvents = HistogramScaledData.hideLostEvents ? fScaledData.fMaxValue : fScaledData.fMaxCombinedValue;
                                 fMaxNbEventsText.setText(Long.toString(maxNbEvents));
                                 // The Y-axis area might need to be re-sized
@@ -553,9 +547,24 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
     // ------------------------------------------------------------------------
 
     private void updateSelectionTime() {
+        fSelectionBegin = Math.min(fSelectionBegin, fDataModel.getEndTime());
+        fSelectionEnd = Math.min(fSelectionEnd, fDataModel.getEndTime());
         ((HistogramView) fParentView).updateSelectionTime(fSelectionBegin, fSelectionEnd);
     }
 
+    /**
+     * Update the range text controls
+     */
+    private void updateRangeTextControls() {
+        if (fDataModel != null && fDataModel.getStartTime() < fDataModel.getEndTime()) {
+            fTimeRangeStartText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getStartTime()));
+            fTimeRangeEndText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime()));
+        } else {
+            fTimeRangeStartText.setText(""); //$NON-NLS-1$
+            fTimeRangeEndText.setText(""); //$NON-NLS-1$
+        }
+    }
+
     // ------------------------------------------------------------------------
     // PaintListener
     // ------------------------------------------------------------------------
@@ -630,13 +639,13 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
                 }
             }
 
-            // Add a dashed line as a delimiter (at the right of the last bar)
-            int lastEventIndex = limit - 1;
-            while (lastEventIndex >= 0 && scaledData.fData[lastEventIndex] == 0) {
-                lastEventIndex--;
-            }
-            lastEventIndex += (lastEventIndex < limit - 1) ? 1 : 0;
-            drawDelimiter(imageGC, fLastEventColor, height, lastEventIndex);
+            // Add a dashed line as a delimiter
+            int delimiterIndex = (int) ((getDataModel().getEndTime() - scaledData.getFirstBucketTime()) / scaledData.fBucketDuration) + 1;
+            drawDelimiter(imageGC, fLastEventColor, height, delimiterIndex);
+
+            // Fill the area to the right of delimiter with background color
+            imageGC.setBackground(fFillColor);
+            imageGC.fillRectangle(delimiterIndex + 1, 0, width - (delimiterIndex + 1), height);
 
             // Draw the selection bars
             int alpha = imageGC.getAlpha();
@@ -647,7 +656,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
             if (beginBucket >= 0 && beginBucket < limit) {
                 imageGC.drawLine(beginBucket, 0, beginBucket, height);
             }
-            final int endBucket = Math.min(lastEventIndex, scaledData.fSelectionEndBucket);
+            final int endBucket = scaledData.fSelectionEndBucket;
             if (endBucket >= 0 && endBucket < limit && endBucket != beginBucket) {
                 imageGC.drawLine(endBucket, 0, endBucket, height);
             }
@@ -804,11 +813,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
             return;
         }
 
-        String newTS = TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getFirstBucketTime());
-        fTimeRangeStartText.setText(newTS);
-
-        newTS = TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime());
-        fTimeRangeEndText.setText(newTS);
+        updateRangeTextControls();
 
         fComposite.layout();
     }
index d1336642a8f9ee1b63864fbd8d99b8c8e05296b3..7f4a9b6ff4730e7168963da74a0b1bee49fe0275 100644 (file)
@@ -96,7 +96,7 @@ public class HistogramDataModel implements IHistogramDataModel {
     // Timestamps
     private long fFirstBucketTime; // could be negative when analyzing events with descending order!!!
     private long fFirstEventTime;
-    private long fLastEventTime;
+    private long fEndTime;
     private long fSelectionBegin;
     private long fSelectionEnd;
     private long fTimeLimit;
@@ -146,7 +146,7 @@ public class HistogramDataModel implements IHistogramDataModel {
      * @since 2.0
      */
     public HistogramDataModel(long startTime, int nbBuckets) {
-        fFirstBucketTime = fFirstEventTime = fLastEventTime = startTime;
+        fFirstBucketTime = fFirstEventTime = fEndTime = startTime;
         fNbBuckets = nbBuckets;
         fBuckets = new long[nbBuckets];
         fLostEventsBuckets = new long[nbBuckets];
@@ -169,7 +169,7 @@ public class HistogramDataModel implements IHistogramDataModel {
         fLastBucket = other.fLastBucket;
         fFirstBucketTime = other.fFirstBucketTime;
         fFirstEventTime = other.fFirstEventTime;
-        fLastEventTime = other.fLastEventTime;
+        fEndTime = other.fEndTime;
         fSelectionBegin = other.fSelectionBegin;
         fSelectionEnd = other.fSelectionEnd;
         fTimeLimit = other.fTimeLimit;
@@ -239,7 +239,7 @@ public class HistogramDataModel implements IHistogramDataModel {
      * @since 2.0
      */
     public void setTimeRange(long startTime, long endTime) {
-        fFirstBucketTime = fFirstEventTime = fLastEventTime = startTime;
+        fFirstBucketTime = fFirstEventTime = fEndTime = startTime;
         fBucketDuration = 1;
         updateEndTime();
         while (endTime >= fTimeLimit) {
@@ -248,12 +248,25 @@ public class HistogramDataModel implements IHistogramDataModel {
     }
 
     /**
-     * Returns the time of the last event in the model.
+     * Set the end time. Setting this ensures that the corresponding bucket is
+     * displayed regardless of the event counts.
      *
-     * @return the time of last event.
+     * @param endTime
+     *            the time of the last used bucket
+     * @since 2.2
+     */
+    public void setEndTime(long endTime) {
+        fEndTime = endTime;
+        fLastBucket = (int) ((endTime - fFirstBucketTime) / fBucketDuration);
+    }
+
+    /**
+     * Returns the end time.
+     *
+     * @return the time of the last used bucket
      */
     public long getEndTime() {
-        return fLastEventTime;
+        return fEndTime;
     }
 
     /**
@@ -357,7 +370,7 @@ public class HistogramDataModel implements IHistogramDataModel {
         Arrays.fill(fLostEventsBuckets, 0);
         fNbEvents = 0;
         fFirstBucketTime = 0;
-        fLastEventTime = 0;
+        fEndTime = 0;
         fSelectionBegin = 0;
         fSelectionEnd = 0;
         fLastBucket = 0;
@@ -451,8 +464,8 @@ public class HistogramDataModel implements IHistogramDataModel {
             fFirstEventTime = timestamp;
         }
 
-        if (fLastEventTime < timestamp) {
-            fLastEventTime = timestamp;
+        if (fEndTime < timestamp) {
+            fEndTime = timestamp;
         }
 
         if (timestamp >= fFirstBucketTime) {
@@ -603,14 +616,14 @@ public class HistogramDataModel implements IHistogramDataModel {
         // Set selection begin and end index in the scaled histogram
         if (fSelectionBegin < fFirstBucketTime) {
             result.fSelectionBeginBucket = -1;
-        } else if (fSelectionBegin > fLastEventTime) {
+        } else if (fSelectionBegin > fEndTime) {
             result.fSelectionBeginBucket = fLastBucket;
         } else {
             result.fSelectionBeginBucket = (int) ((fSelectionBegin - fFirstBucketTime) / fBucketDuration) / bucketsPerBar;
         }
         if (fSelectionEnd < fFirstBucketTime) {
             result.fSelectionEndBucket = -1;
-        } else if (fSelectionEnd > fLastEventTime) {
+        } else if (fSelectionEnd > fEndTime) {
             result.fSelectionEndBucket = fLastBucket;
         } else {
             result.fSelectionEndBucket = (int) ((fSelectionEnd - fFirstBucketTime) / fBucketDuration) / bucketsPerBar;
index 3e4300e5b3d0679726323365c3f3b2479da071b6..58b784c934e511cbd0328576b39e6e9aa1dcaf26 100644 (file)
@@ -77,6 +77,7 @@ public class TimeRangeHistogram extends Histogram {
         fZoom.setNewRange(startTime, duration);
         if (getDataModel().getNbEvents() == 0) {
             getDataModel().setTimeRange(startTime, startTime + duration);
+            getDataModel().setEndTime(startTime + duration);
         }
     }
 
This page took 0.03007 seconds and 5 git commands to generate.