Commit | Line | Data |
---|---|---|
83842d7d | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2013, 2014 Ericsson |
83842d7d BH |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Alexandre Montplaisir - Initial API and implementation | |
11 | * Bernd Hufmann - Updated to new TMF chart framework | |
12 | *******************************************************************************/ | |
13 | package org.eclipse.linuxtools.tracing.examples.ui.viewers.histogram; | |
14 | ||
15 | import java.util.Arrays; | |
16 | import java.util.List; | |
17 | ||
18 | import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; | |
19 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
20 | import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; | |
21 | import org.eclipse.linuxtools.tmf.ui.viewers.xycharts.barcharts.TmfBarChartViewer; | |
8192f2c6 | 22 | import org.eclipse.linuxtools.tmf.ui.views.statistics.TmfStatisticsModule; |
83842d7d BH |
23 | import org.eclipse.swt.SWT; |
24 | import org.eclipse.swt.widgets.Composite; | |
25 | import org.eclipse.swt.widgets.Display; | |
26 | import org.swtchart.Chart; | |
27 | import org.swtchart.IAxis; | |
28 | import org.swtchart.ISeries; | |
29 | import org.swtchart.LineStyle; | |
30 | ||
31 | /** | |
32 | * Histogram Viewer implementation based on TmfBarChartViewer. | |
33 | * | |
34 | * @author Alexandre Montplaisir | |
35 | * @author Bernd Hufmann | |
36 | */ | |
37 | @SuppressWarnings("restriction") | |
38 | public class NewHistogramViewer extends TmfBarChartViewer { | |
39 | ||
40 | /** | |
41 | * Creates a Histogram Viewer instance. | |
42 | * @param parent | |
43 | * The parent composite to draw in. | |
44 | */ | |
45 | public NewHistogramViewer(Composite parent) { | |
46 | super(parent, null, null, null, TmfBarChartViewer.MINIMUM_BAR_WIDTH); | |
47 | ||
48 | Chart swtChart = getSwtChart(); | |
49 | ||
50 | IAxis xAxis = swtChart.getAxisSet().getXAxis(0); | |
51 | IAxis yAxis = swtChart.getAxisSet().getYAxis(0); | |
52 | ||
53 | /* Hide the grid */ | |
54 | xAxis.getGrid().setStyle(LineStyle.NONE); | |
55 | yAxis.getGrid().setStyle(LineStyle.NONE); | |
56 | ||
57 | /* Hide the legend */ | |
58 | swtChart.getLegend().setVisible(false); | |
59 | ||
60 | addSeries("Number of events", Display.getDefault().getSystemColor(SWT.COLOR_BLUE).getRGB()); //$NON-NLS-1$ | |
61 | } | |
62 | ||
63 | @Override | |
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]; | |
67 | ||
68 | Thread thread = new Thread("Histogram viewer update") { //$NON-NLS-1$ | |
69 | @Override | |
70 | public void run() { | |
71 | double x[] = getXAxis(start, end, nb); | |
72 | final long yLong[] = new long[nb]; | |
73 | Arrays.fill(y, 0.0); | |
74 | ||
75 | /* Add the values for each trace */ | |
76 | for (ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) { | |
8192f2c6 AM |
77 | /* Retrieve the statistics object */ |
78 | final TmfStatisticsModule statsMod = | |
79 | trace.getAnalysisModuleOfClass(TmfStatisticsModule.class, TmfStatisticsModule.ID); | |
80 | if (statsMod == null) { | |
81 | /* No statistics module available for this trace */ | |
82 | continue; | |
83 | } | |
84 | final ITmfStatistics stats = statsMod.getStatistics(); | |
83842d7d BH |
85 | List<Long> values = stats.histogramQuery(start, end, nb); |
86 | ||
87 | for (int i = 0; i < nb; i++) { | |
88 | yLong[i] += values.get(i); | |
89 | } | |
90 | } | |
91 | ||
92 | for (int i = 0; i < nb; i++) { | |
93 | y[i] += yLong[i]; /* casting from long to double */ | |
94 | } | |
95 | ||
96 | /* Update the viewer */ | |
97 | drawChart(series, x, y); | |
98 | } | |
99 | }; | |
100 | thread.start(); | |
101 | } | |
102 | return; | |
103 | } | |
104 | } |