From 00419b1f24089a6c21d0c3dd0af903562c728863 Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Tue, 30 Oct 2012 14:21:53 -0400 Subject: [PATCH] Fix for the time range histogram 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 Reviewed-on: https://git.eclipse.org/r/8428 Tested-by: Hudson CI --- .../views/histogram/HistogramDataModel.java | 44 +++++++++++++++++-- .../views/histogram/TimeRangeHistogram.java | 2 +- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramDataModel.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramDataModel.java index 30ad107c99..1dbd20dd15 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramDataModel.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramDataModel.java @@ -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. *

* - * @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(); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/TimeRangeHistogram.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/TimeRangeHistogram.java index 1b0a456282..c747f4e984 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/TimeRangeHistogram.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/TimeRangeHistogram.java @@ -17,7 +17,6 @@ package org.eclipse.linuxtools.tmf.ui.views.histogram; import org.eclipse.swt.widgets.Composite; /** - *

* A basic histogram widget that displays the event distribution of a specific time range of a trace. * It has the following additional features: *