tmf: Fix value of time offset in XY chart viewer being wrong for a while
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Mon, 27 Apr 2015 19:00:08 +0000 (15:00 -0400)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tue, 28 Apr 2015 19:14:31 +0000 (15:14 -0400)
Right after calling setWindowStartTime/setWindowEndTime, the value of
getTimeOffset was wrong until setTimeOffset was called later, in a data
building thread for example.

Since the time offset is deduced from the start time (startTime - 1), we can
remove this field and setter. This means that the time offset will always be
consistent with the start time. Similarly, the window duration can be deduced
(startTime - endTime) therefore we can remove this setting and field as well.

An example of how this bug can manifest itself is inside a resize listener.
If both windowStartTime and timeOffset are used to calculate the position of a
value on the chart, since the timeOffset can be inconsistent, the position
would be wrong.

Change-Id: If59a9d2c0dfc24245949f8ba693dd89e6498820f
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/46591
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/TmfTimeViewer.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/TmfXYChartViewer.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/barcharts/TmfBarChartViewer.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java

index 91c5fa3e1e42f338f62b8b8a22026842f5e7a437..9d8a2bb23d24379563e5f8431aff857c43c9b247 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
+ * Copyright (c) 2014, 2015 École Polytechnique de Montréal and others.
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -57,8 +57,6 @@ public abstract class TmfTimeViewer extends TmfViewer implements ITmfTimeProvide
     private long fWindowStartTime;
     /** End time of current time range */
     private long fWindowEndTime;
-    /** Duration of current time range */
-    private long fWindowDuration;
     /** Current begin time of selection range */
     private long fSelectionBeginTime;
     /** Current end of selection range */
@@ -142,16 +140,6 @@ public abstract class TmfTimeViewer extends TmfViewer implements ITmfTimeProvide
         fWindowEndTime = windowEndTime;
     }
 
-    /**
-     * Sets the duration of the current time range window (visible range)
-     *
-     * @param windowDuration
-     *            The window duration
-     */
-    protected void setWindowDuration(long windowDuration) {
-        fWindowDuration = windowDuration;
-    }
-
     /**
      * Sets the begin time of the selected range.
      *
@@ -217,7 +205,7 @@ public abstract class TmfTimeViewer extends TmfViewer implements ITmfTimeProvide
 
     @Override
     public long getWindowDuration() {
-        return fWindowDuration;
+        return getWindowEndTime() - getWindowStartTime();
     }
 
     @Override
@@ -249,7 +237,6 @@ public abstract class TmfTimeViewer extends TmfViewer implements ITmfTimeProvide
 
         setWindowStartTime(windowStartTime);
         setWindowEndTime(windowEndTime);
-        setWindowDuration(windowEndTime - windowStartTime);
 
         // Build the new time range; keep the current time
         TmfTimeRange timeRange = new TmfTimeRange(
@@ -279,7 +266,6 @@ public abstract class TmfTimeViewer extends TmfViewer implements ITmfTimeProvide
 
         long windowStartTime = windowRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
         long windowEndTime = windowRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
-        long windowDuration = windowEndTime - windowStartTime;
         long startTime = fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
         long endTime = fTrace.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
 
@@ -288,7 +274,6 @@ public abstract class TmfTimeViewer extends TmfViewer implements ITmfTimeProvide
         setStartTime(startTime);
         setWindowStartTime(windowStartTime);
         setWindowEndTime(windowEndTime);
-        setWindowDuration(windowDuration);
         setEndTime(endTime);
     }
 
@@ -301,7 +286,6 @@ public abstract class TmfTimeViewer extends TmfViewer implements ITmfTimeProvide
         setSelectionEndTime(0);
         setStartTime(0);
         setWindowStartTime(0);
-        setWindowDuration(0);
         setEndTime(0);
         setWindowEndTime(0);
         setTrace(null);
@@ -393,11 +377,9 @@ public abstract class TmfTimeViewer extends TmfViewer implements ITmfTimeProvide
                 // Update the time range
                 long windowStartTime = range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
                 long windowEndTime = range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
-                long windowDuration = windowEndTime - windowStartTime;
 
                 setWindowStartTime(windowStartTime);
                 setWindowEndTime(windowEndTime);
-                setWindowDuration(windowDuration);
             }
         }
     }
index 3787989aa7ff63a81632ccd5daaa303283ef23da..0aec6b89e8ba506deee1a41e85528178e7c57e3a 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2013, 2014 Ericsson, École Polytechnique de Montréal
+ * Copyright (c) 2013, 2015 Ericsson, École Polytechnique de Montréal
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -39,11 +39,6 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
-    /**
-     * The offset to apply to any x position. This offset ensures better
-     * precision when converting long to double and back.
-     */
-    private long fTimeOffset;
     /** The SWT Chart reference */
     private Chart fSwtChart;
     /** The mouse selection provider */
@@ -107,16 +102,6 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
     // ------------------------------------------------------------------------
     // Getter/Setters
     // ------------------------------------------------------------------------
-    /**
-     * Sets the time offset to apply.
-     * @see ITmfChartTimeProvider#getTimeOffset()
-     *
-     * @param timeOffset
-     *            The time offset to apply
-     */
-    protected void setTimeOffset(long timeOffset) {
-        fTimeOffset = timeOffset;
-    }
 
     /**
      * Sets the SWT Chart reference
@@ -214,7 +199,7 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
 
     @Override
     public long getTimeOffset() {
-        return fTimeOffset;
+        return getWindowStartTime() - 1;
     }
 
     // ------------------------------------------------------------------------
index b97c757923c27318b92fda05b2657266ed89f1be..23c721b02469cb90766435afdc6fdc205b24f142 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2013, 2014 Ericsson
+ * Copyright (c) 2013, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -172,8 +172,7 @@ public abstract class TmfBarChartViewer extends TmfXYChartViewer {
      *            Number of steps. This will be the size of the returned array.
      * @return The time values (converted to double) that match every step
      */
-    protected final double[] getXAxis(long start, long end, int nb) {
-        setTimeOffset(start - 1);
+    protected final static double[] getXAxis(long start, long end, int nb) {
         double timestamps[] = new double[nb];
         long steps = (end - start);
         double step = steps / (double) nb;
index daa46a66143acbb1045857aabd2784cef58c2f8e..e42a0155cd4da63541bba512935f4ebd99122ec5 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
+ * Copyright (c) 2014, 2015 École Polytechnique de Montréal and others.
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -205,8 +205,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
      *            The number of steps in the x axis.
      * @return The time values (converted to double) to match every step.
      */
-    protected final double[] getXAxis(long start, long end, int nb) {
-        setTimeOffset(start - 1);
+    protected final static double[] getXAxis(long start, long end, int nb) {
 
         double timestamps[] = new double[nb];
         long steps = (end - start);
This page took 0.044976 seconds and 5 git commands to generate.