From: Geneviève Bastien Date: Wed, 30 Mar 2016 15:59:56 +0000 (-0400) Subject: tmf.ui: Return minimal number of X values in XY viewer X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;ds=sidebyside;h=5c75d7d27ca71c648cc8128f7f0ce0823b6493dc;p=deliverable%2Ftracecompass.git tmf.ui: Return minimal number of X values in XY viewer When the number of time steps is lower than the requested number of X values, only those steps will be returned. Change-Id: I94c877906083584546d4921e2bd90d82b5e72c49 Signed-off-by: Geneviève Bastien Reviewed-on: https://git.eclipse.org/r/69546 Reviewed-by: Hudson CI Reviewed-by: Matthew Khouzam --- diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java index ee5a1c0e70..6342a2b96a 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java @@ -203,8 +203,9 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer { /** * Convenience method to compute the values of the X axis for a given time - * range. This method will return nb values depending, equally separated - * from start to end. + * range. This method will return at most nb values, equally separated from + * start to end. The step between values will be at least 1.0, so the number + * of values returned can be lower than nb. * * The returned time values are in internal time, ie to get trace time, the * time offset needs to be added to those values. @@ -214,17 +215,23 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer { * @param end * End time of the range * @param nb - * The number of steps in the x axis. + * The maximum number of steps in the x axis. * @return The time values (converted to double) to match every step. */ protected static final double[] getXAxis(long start, long end, int nb) { - - double timestamps[] = new double[nb]; long steps = (end - start); - double step = steps / (double) nb; + int nbVals = nb; + if (steps < nb) { + nbVals = (int) steps; + if (nbVals <= 0) { + nbVals = 1; + } + } + double step = steps / (double) nbVals; + double timestamps[] = new double[nbVals]; double curTime = 1; - for (int i = 0; i < nb; i++) { + for (int i = 0; i < nbVals; i++) { timestamps[i] = curTime; curTime += step; }