Fix for the time range histogram
authorFrancois Chouinard <fchouinard@gmail.com>
Tue, 30 Oct 2012 18:21:53 +0000 (14:21 -0400)
committerFrancois Chouinard <fchouinard@gmail.com>
Tue, 30 Oct 2012 20:23:52 +0000 (16:23 -0400)
The time range histogram doesn't refresh very well when the new range
has no events either at the start or the end. This patch properly keeps
the range.

Change-Id: I414bb9288327dd9cf56ca8eb22ac2672f4e9e362
Signed-off-by: Francois Chouinard <fchouinard@gmail.com>
Reviewed-on: https://git.eclipse.org/r/8428
Tested-by: Hudson CI
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 30ad107c9962a4aa05d5741fe7c979a4a1fb97da..1dbd20dd15ff1d8c1354e22d731be9a7bfb5968a 100644 (file)
@@ -11,6 +11,7 @@
  *   Bernd Hufmann - Implementation of new interfaces/listeners and support for
  *                   time stamp in any order
  *   Francois Chouinard - Moved from LTTng to TMF
+ *   Francois Chouinard - Added support for empty initial buckets
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.views.histogram;
@@ -58,7 +59,7 @@ import org.eclipse.core.runtime.ListenerList;
  * a nice result when visualizing the histogram.
  * <p>
  *
- * @version 1.0
+ * @version 2.0
  * @author Francois Chouinard
  */
 public class HistogramDataModel implements IHistogramDataModel {
@@ -106,7 +107,16 @@ public class HistogramDataModel implements IHistogramDataModel {
      * Default constructor with default number of buckets.
      */
     public HistogramDataModel() {
-        this(DEFAULT_NUMBER_OF_BUCKETS);
+        this(0, DEFAULT_NUMBER_OF_BUCKETS);
+    }
+
+    /**
+     * Default constructor with default number of buckets.
+     * @param startTime The histogram start time
+     * @since 2.0
+     */
+    public HistogramDataModel(long startTime) {
+        this(startTime, DEFAULT_NUMBER_OF_BUCKETS);
     }
 
     /**
@@ -114,6 +124,17 @@ public class HistogramDataModel implements IHistogramDataModel {
      * @param nbBuckets A number of buckets.
      */
     public HistogramDataModel(int nbBuckets) {
+        this(0, nbBuckets);
+    }
+
+    /**
+     * Constructor with non-default number of buckets.
+     * @param startTime the histogram start time
+     * @param nbBuckets A number of buckets.
+     * @since 2.0
+     */
+    public HistogramDataModel(long startTime, int nbBuckets) {
+        fFirstBucketTime = fFirstEventTime = fLastEventTime = startTime;
         fNbBuckets = nbBuckets;
         fBuckets = new long[nbBuckets];
         fModelListeners = new ListenerList();
@@ -127,7 +148,7 @@ public class HistogramDataModel implements IHistogramDataModel {
     public HistogramDataModel(HistogramDataModel other) {
         fNbBuckets = other.fNbBuckets;
         fBuckets = Arrays.copyOf(other.fBuckets, fNbBuckets);
-        fBucketDuration = Math.max(other.fBucketDuration,1);
+        fBucketDuration = Math.max(other.fBucketDuration, 1);
         fNbEvents = other.fNbEvents;
         fLastBucket = other.fLastBucket;
         fFirstBucketTime = other.fFirstBucketTime;
@@ -186,6 +207,21 @@ public class HistogramDataModel implements IHistogramDataModel {
         return fFirstEventTime;
     }
 
+    /**
+     * Sets the model start time
+     * @param startTime the histogram range start time
+     * @param endTime the histogram range end time
+     * @since 2.0
+     */
+    public void setTimeRange(long startTime, long endTime) {
+        fFirstBucketTime = fFirstEventTime = fLastEventTime = startTime;
+        fBucketDuration = 1;
+        updateEndTime();
+        while (endTime >= fTimeLimit) {
+            mergeBuckets();
+        }
+    }
+
     /**
      * Returns the time of the last event in the model.
      * @return the time of last event.
@@ -311,7 +347,7 @@ public class HistogramDataModel implements IHistogramDataModel {
         }
 
         // Set the start/end time if not already done
-        if ((fLastBucket == 0) && (fBuckets[0] == 0) && (timestamp > 0)) {
+        if ((fFirstBucketTime == 0) && (fLastBucket == 0) && (fBuckets[0] == 0) && (timestamp > 0)) {
             fFirstBucketTime = timestamp;
             fFirstEventTime = timestamp;
             updateEndTime();
index 1b0a45628214aabdb07c45fea88793e044e05f11..c747f4e984b1e95fd9b58ef5c0315f5cf05bca20 100644 (file)
@@ -17,7 +17,6 @@ package org.eclipse.linuxtools.tmf.ui.views.histogram;
 import org.eclipse.swt.widgets.Composite;
 
 /**
- * <p>
  * A basic histogram widget that displays the event distribution of a specific time range of a trace.
  * It has the following additional features:
  * <ul>
@@ -81,6 +80,7 @@ public class TimeRangeHistogram extends Histogram {
      */
     public synchronized void setTimeRange(long startTime, long duration) {
         fZoom.setNewRange(startTime, duration);
+        getDataModel().setTimeRange(startTime, startTime + duration);
     }
 
     /**
This page took 0.026826 seconds and 5 git commands to generate.