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 static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
17 import java
.util
.Arrays
;
18 import java
.util
.List
;
20 import org
.eclipse
.swt
.SWT
;
21 import org
.eclipse
.swt
.widgets
.Composite
;
22 import org
.eclipse
.swt
.widgets
.Display
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.ITmfStatistics
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.TmfStatisticsModule
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
28 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.xycharts
.barcharts
.TmfBarChartViewer
;
29 import org
.swtchart
.Chart
;
30 import org
.swtchart
.IAxis
;
31 import org
.swtchart
.ISeries
;
32 import org
.swtchart
.LineStyle
;
35 * Histogram Viewer implementation based on TmfBarChartViewer.
37 * @author Alexandre Montplaisir
38 * @author Bernd Hufmann
40 public class NewHistogramViewer
extends TmfBarChartViewer
{
43 * Creates a Histogram Viewer instance.
45 * The parent composite to draw in.
47 public NewHistogramViewer(Composite parent
) {
48 super(parent
, null, null, null, TmfBarChartViewer
.MINIMUM_BAR_WIDTH
);
50 Chart swtChart
= getSwtChart();
52 IAxis xAxis
= swtChart
.getAxisSet().getXAxis(0);
53 IAxis yAxis
= swtChart
.getAxisSet().getYAxis(0);
56 xAxis
.getGrid().setStyle(LineStyle
.NONE
);
57 yAxis
.getGrid().setStyle(LineStyle
.NONE
);
60 swtChart
.getLegend().setVisible(false);
62 addSeries("Number of events", Display
.getDefault().getSystemColor(SWT
.COLOR_BLUE
).getRGB()); //$NON-NLS-1$
66 protected void readData(final ISeries series
, final long start
, final long end
, final int nb
) {
67 if (getTrace() != null) {
68 final double y
[] = new double[nb
];
70 Thread thread
= new Thread("Histogram viewer update") { //$NON-NLS-1$
73 double x
[] = getXAxis(start
, end
, nb
);
74 final long yLong
[] = new long[nb
];
77 /* Add the values for each trace */
78 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(getTrace())) {
79 trace
= checkNotNull(trace
);
80 /* Retrieve the statistics object */
81 final TmfStatisticsModule statsMod
=
82 TmfTraceUtils
.getAnalysisModuleOfClass(trace
, TmfStatisticsModule
.class, TmfStatisticsModule
.ID
);
83 if (statsMod
== null) {
84 /* No statistics module available for this trace */
87 statsMod
.waitForInitialization();
88 final ITmfStatistics stats
= statsMod
.getStatistics();
91 * Should not be null after waitForInitialization()
94 throw new IllegalStateException();
96 List
<Long
> values
= stats
.histogramQuery(start
, end
, nb
);
98 for (int i
= 0; i
< nb
; i
++) {
99 yLong
[i
] += values
.get(i
);
103 for (int i
= 0; i
< nb
; i
++) {
104 y
[i
] += yLong
[i
]; /* casting from long to double */
107 /* Update the viewer */
108 drawChart(series
, x
, y
);