1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alexandre Montplaisir - Initial API and implementation
11 * Bernd Hufmann - Updated to new TMF chart framework
12 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.examples
.ui
.viewers
.histogram
;
15 import java
.util
.Arrays
;
16 import java
.util
.List
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.Display
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.ITmfStatistics
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.TmfStatisticsModule
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
25 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.xycharts
.barcharts
.TmfBarChartViewer
;
26 import org
.swtchart
.Chart
;
27 import org
.swtchart
.IAxis
;
28 import org
.swtchart
.ISeries
;
29 import org
.swtchart
.LineStyle
;
32 * Histogram Viewer implementation based on TmfBarChartViewer.
34 * @author Alexandre Montplaisir
35 * @author Bernd Hufmann
37 public class NewHistogramViewer
extends TmfBarChartViewer
{
40 * Creates a Histogram Viewer instance.
42 * The parent composite to draw in.
44 public NewHistogramViewer(Composite parent
) {
45 super(parent
, null, null, null, TmfBarChartViewer
.MINIMUM_BAR_WIDTH
);
47 Chart swtChart
= getSwtChart();
49 IAxis xAxis
= swtChart
.getAxisSet().getXAxis(0);
50 IAxis yAxis
= swtChart
.getAxisSet().getYAxis(0);
53 xAxis
.getGrid().setStyle(LineStyle
.NONE
);
54 yAxis
.getGrid().setStyle(LineStyle
.NONE
);
57 swtChart
.getLegend().setVisible(false);
59 addSeries("Number of events", Display
.getDefault().getSystemColor(SWT
.COLOR_BLUE
).getRGB()); //$NON-NLS-1$
63 protected void readData(final ISeries series
, final long start
, final long end
, final int nb
) {
64 if (getTrace() != null) {
65 final double y
[] = new double[nb
];
67 Thread thread
= new Thread("Histogram viewer update") { //$NON-NLS-1$
70 double x
[] = getXAxis(start
, end
, nb
);
71 final long yLong
[] = new long[nb
];
74 /* Add the values for each trace */
75 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(getTrace())) {
76 /* Retrieve the statistics object */
77 final TmfStatisticsModule statsMod
=
78 trace
.getAnalysisModuleOfClass(TmfStatisticsModule
.class, TmfStatisticsModule
.ID
);
79 if (statsMod
== null) {
80 /* No statistics module available for this trace */
83 statsMod
.waitForInitialization();
84 final ITmfStatistics stats
= statsMod
.getStatistics();
87 * Should not be null after waitForInitialization()
90 throw new IllegalStateException();
92 List
<Long
> values
= stats
.histogramQuery(start
, end
, nb
);
94 for (int i
= 0; i
< nb
; i
++) {
95 yLong
[i
] += values
.get(i
);
99 for (int i
= 0; i
< nb
; i
++) {
100 y
[i
] += yLong
[i
]; /* casting from long to double */
103 /* Update the viewer */
104 drawChart(series
, x
, y
);