import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.logging.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentInfo;
/* The desired number of points per pixel */
private static final double RESOLUTION = 1.0;
+ private static final Logger LOGGER = TraceCompassLog.getLogger(TmfCommonXLineChartViewer.class);
+ private static final String LOG_STRING_WITH_PARAM = "[TmfCommonXLineChart:%s] viewerId=%s, %s"; //$NON-NLS-1$
+ private static final String LOG_STRING = "[TmfCommonXLineChart:%s] viewerId=%s"; //$NON-NLS-1$
private static final int[] LINE_COLORS = { SWT.COLOR_BLUE, SWT.COLOR_RED, SWT.COLOR_GREEN,
SWT.COLOR_MAGENTA, SWT.COLOR_CYAN,
*/
public TmfCommonXLineChartViewer(Composite parent, String title, String xLabel, String yLabel) {
super(parent, title, xLabel, yLabel);
-
+ getSwtChart().getTitle().setVisible(false);
+ getSwtChart().getLegend().setPosition(SWT.BOTTOM);
+ getSwtChart().getAxisSet().getXAxes()[0].getTitle().setVisible(false);
setResolution(RESOLUTION);
setTooltipProvider(new TmfCommonXLineChartTooltipProvider(this));
}
reinitialize();
}
+ /**
+ * Formats a log message for this class
+ *
+ * @param event
+ * The event to log, that will be appended to the class name to
+ * make the full event name
+ * @param parameters
+ * The string of extra parameters to add to the log message, in
+ * the format name=value[, name=value]*, or <code>null</code> for
+ * no params
+ * @return The complete log message for this class
+ */
+ private String getLogMessage(String event, @Nullable String parameters) {
+ if (parameters == null) {
+ return String.format(LOG_STRING, event, getClass().getName());
+ }
+ return String.format(LOG_STRING_WITH_PARAM, event, getClass().getName(), parameters);
+ }
+
/**
* Forces a reinitialization of the data sources, even if it has already
* been initialized for this trace before
protected void reinitialize() {
fSeriesValues.clear();
Thread thread = new Thread() {
+ // Don't use TmfUiRefreshHandler (bug 467751)
@Override
public void run() {
+ LOGGER.info(() -> getLogMessage("InitializeThreadStart", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
initializeDataSource();
- getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- if (!getSwtChart().isDisposed()) {
- /* Delete the old series */
- clearContent();
- createSeries();
+ if (!getSwtChart().isDisposed()) {
+ getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (!getSwtChart().isDisposed()) {
+ /* Delete the old series */
+ clearContent();
+ createSeries();
+ }
}
- }
- });
+ });
+ }
+ LOGGER.info(() -> getLogMessage("InitializeThreadEnd", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
}
};
thread.start();
@Override
public void run() {
- updateData(getWindowStartTime(), getWindowEndTime(), fNumRequests, fMonitor);
+ LOGGER.info(() -> getLogMessage("UpdateThreadStart", "numRequests=" + fNumRequests + ", tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ LOGGER.info(() -> getLogMessage("UpdateDataStart", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
+ updateData(getWindowStartTime(), getWindowEndTime(), fNumRequests, fMonitor);
+ LOGGER.info(() -> getLogMessage("UpdateDataEnd", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ });
updateThreadFinished(this);
+ LOGGER.info(() -> getLogMessage("UpdateThreadEnd", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
}
public void cancel() {
+ LOGGER.info(() -> getLogMessage("UpdateThreadCanceled", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
fMonitor.setCanceled(true);
}
}
private synchronized void newUpdateThread() {
cancelUpdate();
- final int numRequests = (int) (getSwtChart().getPlotArea().getBounds().width * fResolution);
- fUpdateThread = new UpdateThread(numRequests);
- fUpdateThread.start();
+ if (!getSwtChart().isDisposed()) {
+ final int numRequests = (int) (getSwtChart().getPlotArea().getBounds().width * fResolution);
+ fUpdateThread = new UpdateThread(numRequests);
+ fUpdateThread.start();
+ }
}
private synchronized void updateThreadFinished(UpdateThread thread) {
/**
* 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.
* @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;
}
int lastX = xValues.length - 1;
double end = (start == xValues[lastX]) ? start + 1 : xValues[lastX];
getSwtChart().getAxisSet().getXAxis(0).setRange(new Range(start, end));
- getSwtChart().getAxisSet().getXAxis(0).adjustRange();
if (maxy > miny) {
getSwtChart().getAxisSet().getYAxis(0).setRange(new Range(miny, maxy));
}
getSwtChart().redraw();
if (isSendTimeAlignSignals()) {
- // The width of the chart might have changed and its time
- // axis might be misaligned with the other views
+ // The width of the chart might have changed and its
+ // time axis might be misaligned with the other views
Point viewPos = TmfCommonXLineChartViewer.this.getParent().getParent().toDisplay(0, 0);
int axisPos = getSwtChart().toDisplay(0, 0).x + getPointAreaOffset();
int timeAxisOffset = axisPos - viewPos.x;