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
.core
.trace
.TmfTraceUtils
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.xycharts
.barcharts
.TmfBarChartViewer
;
27 import org
.swtchart
.Chart
;
28 import org
.swtchart
.IAxis
;
29 import org
.swtchart
.ISeries
;
30 import org
.swtchart
.LineStyle
;
33 * Histogram Viewer implementation based on TmfBarChartViewer.
35 * @author Alexandre Montplaisir
36 * @author Bernd Hufmann
38 public class NewHistogramViewer
extends TmfBarChartViewer
{
41 * Creates a Histogram Viewer instance.
43 * The parent composite to draw in.
45 public NewHistogramViewer(Composite parent
) {
46 super(parent
, null, null, null, TmfBarChartViewer
.MINIMUM_BAR_WIDTH
);
48 Chart swtChart
= getSwtChart();
50 IAxis xAxis
= swtChart
.getAxisSet().getXAxis(0);
51 IAxis yAxis
= swtChart
.getAxisSet().getYAxis(0);
54 xAxis
.getGrid().setStyle(LineStyle
.NONE
);
55 yAxis
.getGrid().setStyle(LineStyle
.NONE
);
58 swtChart
.getLegend().setVisible(false);
60 addSeries("Number of events", Display
.getDefault().getSystemColor(SWT
.COLOR_BLUE
).getRGB()); //$NON-NLS-1$
64 protected void readData(final ISeries series
, final long start
, final long end
, final int nb
) {
65 if (getTrace() != null) {
66 final double y
[] = new double[nb
];
68 Thread thread
= new Thread("Histogram viewer update") { //$NON-NLS-1$
71 double x
[] = getXAxis(start
, end
, nb
);
72 final long yLong
[] = new long[nb
];
75 /* Add the values for each trace */
76 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(getTrace())) {
77 /* Retrieve the statistics object */
78 final TmfStatisticsModule statsMod
=
79 TmfTraceUtils
.getAnalysisModuleOfClass(trace
, TmfStatisticsModule
.class, TmfStatisticsModule
.ID
);
80 if (statsMod
== null) {
81 /* No statistics module available for this trace */
84 statsMod
.waitForInitialization();
85 final ITmfStatistics stats
= statsMod
.getStatistics();
88 * Should not be null after waitForInitialization()
91 throw new IllegalStateException();
93 List
<Long
> values
= stats
.histogramQuery(start
, end
, nb
);
95 for (int i
= 0; i
< nb
; i
++) {
96 yLong
[i
] += values
.get(i
);
100 for (int i
= 0; i
< nb
; i
++) {
101 y
[i
] += yLong
[i
]; /* casting from long to double */
104 /* Update the viewer */
105 drawChart(series
, x
, y
);