Commit | Line | Data |
---|---|---|
c392540b | 1 | /******************************************************************************* |
576f0a4e | 2 | * Copyright (c) 2011, 2014 Ericsson |
20ff3b75 | 3 | * |
c392540b FC |
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 | |
20ff3b75 | 8 | * |
c392540b FC |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
d26274e7 | 11 | * Bernd Hufmann - Added setter and getter and bar width support |
e0752744 | 12 | * Francois Chouinard - Moved from LTTng to TMF |
0fcf3b09 | 13 | * Patrick Tasse - Support selection range |
95aa81ef | 14 | * Jean-Christian Kouamé - Support to manage lost events |
2fc582d2 | 15 | * Xavier Raynaud - Support multi-trace coloring |
c392540b FC |
16 | *******************************************************************************/ |
17 | ||
e0752744 | 18 | package org.eclipse.linuxtools.tmf.ui.views.histogram; |
c392540b FC |
19 | |
20 | import java.util.Arrays; | |
21 | ||
22 | /** | |
c392540b | 23 | * Convenience class/struct for scaled histogram data. |
20ff3b75 | 24 | * |
b544077e BH |
25 | * @version 1.0 |
26 | * @author Francois Chouinard | |
c392540b FC |
27 | */ |
28 | public class HistogramScaledData { | |
29 | ||
30 | // ------------------------------------------------------------------------ | |
31 | // Constants | |
32 | // ------------------------------------------------------------------------ | |
33 | ||
b544077e BH |
34 | /** |
35 | * Indicator value that bucket is out of range (not filled). | |
36 | */ | |
c392540b FC |
37 | public static final int OUT_OF_RANGE_BUCKET = -1; |
38 | ||
39 | // ------------------------------------------------------------------------ | |
40 | // Attributes | |
41 | // ------------------------------------------------------------------------ | |
b544077e BH |
42 | /** |
43 | * Width of histogram canvas (number of pixels). | |
44 | */ | |
c392540b | 45 | public int fWidth; |
b544077e BH |
46 | /** |
47 | * Height of histogram canvas (number of pixels). | |
48 | */ | |
c392540b | 49 | public int fHeight; |
b544077e | 50 | /** |
20ff3b75 | 51 | * Width of one histogram bar (number of pixels). |
b544077e | 52 | */ |
fbd124dd | 53 | public int fBarWidth; |
b544077e BH |
54 | /** |
55 | * Array of scaled values | |
56 | */ | |
2fc582d2 | 57 | public HistogramBucket[] fData; |
95aa81ef JCK |
58 | /** |
59 | * Array of scaled values combined including the lost events. | |
60 | * This array contains the number of lost events for each bar in the histogram | |
46a59db7 | 61 | * @since 2.2 |
95aa81ef JCK |
62 | */ |
63 | public final int[] fLostEventsData; | |
b544077e BH |
64 | /** |
65 | * The bucket duration of a scaled data bucket. | |
66 | */ | |
c392540b | 67 | public long fBucketDuration; |
b544077e | 68 | /** |
20ff3b75 | 69 | * The maximum number of events of all buckets. |
b544077e | 70 | */ |
c392540b | 71 | public long fMaxValue; |
95aa81ef JCK |
72 | /** |
73 | * the maximum of events of all buckets including the lost events | |
46a59db7 | 74 | * @since 2.2 |
95aa81ef JCK |
75 | */ |
76 | public long fMaxCombinedValue; | |
0fcf3b09 PT |
77 | /** |
78 | * The index of the selection begin bucket. | |
79 | * @since 2.1 | |
80 | */ | |
81 | public int fSelectionBeginBucket; | |
82 | /** | |
83 | * The index of the selection end bucket. | |
84 | * @since 2.1 | |
85 | */ | |
86 | public int fSelectionEndBucket; | |
b544077e | 87 | /** |
20ff3b75 | 88 | * The index of the last bucket. |
b544077e | 89 | */ |
c392540b | 90 | public int fLastBucket; |
b544077e BH |
91 | /** |
92 | * The scaling factor used to fill the scaled data. | |
93 | */ | |
c392540b | 94 | public double fScalingFactor; |
95aa81ef JCK |
95 | /** |
96 | * The scaling factor used to fill the scaled data including the lost events. | |
46a59db7 | 97 | * @since 2.2 |
95aa81ef JCK |
98 | */ |
99 | public double fScalingFactorCombined; | |
100 | /** | |
101 | * The scaling factor used to fill the combining scaled data including lost events | |
102 | */ | |
b544077e BH |
103 | /** |
104 | * Time of first bucket. | |
105 | */ | |
fbd124dd | 106 | public long fFirstBucketTime; |
b544077e BH |
107 | /** |
108 | * The time of the first event. | |
109 | */ | |
fbd124dd | 110 | public long fFirstEventTime; |
95aa81ef JCK |
111 | /** |
112 | * show the lost events or not | |
46a59db7 | 113 | * @since 2.2 |
95aa81ef JCK |
114 | */ |
115 | public static volatile boolean hideLostEvents = false; | |
2fc582d2 | 116 | |
c392540b FC |
117 | // ------------------------------------------------------------------------ |
118 | // Constructor | |
119 | // ------------------------------------------------------------------------ | |
120 | ||
b544077e BH |
121 | /** |
122 | * Constructor. | |
123 | * @param width the canvas width | |
124 | * @param height the canvas height | |
125 | * @param barWidth the required bar width | |
126 | */ | |
fbd124dd | 127 | public HistogramScaledData(int width, int height, int barWidth) { |
c392540b FC |
128 | fWidth = width; |
129 | fHeight = height; | |
fbd124dd | 130 | fBarWidth = barWidth; |
2fc582d2 | 131 | fData = new HistogramBucket[width / fBarWidth]; |
95aa81ef | 132 | fLostEventsData = new int[width / fBarWidth]; |
c392540b FC |
133 | fBucketDuration = 1; |
134 | fMaxValue = 0; | |
95aa81ef | 135 | fMaxCombinedValue = 0; |
0fcf3b09 PT |
136 | fSelectionBeginBucket = 0; |
137 | fSelectionEndBucket = 0; | |
c392540b FC |
138 | fLastBucket = 0; |
139 | fScalingFactor = 1; | |
95aa81ef | 140 | fScalingFactorCombined = 1; |
fbd124dd | 141 | fFirstBucketTime = 0; |
c392540b FC |
142 | } |
143 | ||
b544077e BH |
144 | /** |
145 | * Copy constructor | |
146 | * @param other another scaled data. | |
147 | */ | |
c392540b FC |
148 | public HistogramScaledData(HistogramScaledData other) { |
149 | fWidth = other.fWidth; | |
150 | fHeight = other.fHeight; | |
fbd124dd | 151 | fBarWidth = other.fBarWidth; |
95aa81ef JCK |
152 | fData = Arrays.copyOf(other.fData, other.fData.length); |
153 | fLostEventsData = Arrays.copyOf(other.fLostEventsData, other.fLostEventsData.length); | |
c392540b FC |
154 | fBucketDuration = other.fBucketDuration; |
155 | fMaxValue = other.fMaxValue; | |
95aa81ef | 156 | fMaxCombinedValue = other.fMaxCombinedValue; |
0fcf3b09 PT |
157 | fSelectionBeginBucket = other.fSelectionBeginBucket; |
158 | fSelectionEndBucket = other.fSelectionEndBucket; | |
c392540b FC |
159 | fLastBucket = other.fLastBucket; |
160 | fScalingFactor = other.fScalingFactor; | |
95aa81ef | 161 | fScalingFactorCombined = other.fScalingFactorCombined; |
fbd124dd BH |
162 | fFirstBucketTime = other.fFirstBucketTime; |
163 | } | |
20ff3b75 | 164 | |
fbd124dd BH |
165 | // ------------------------------------------------------------------------ |
166 | // Setter and Getter | |
167 | // ------------------------------------------------------------------------ | |
e0752744 | 168 | |
b544077e BH |
169 | /** |
170 | * Returns the time of the first bucket of the scaled data. | |
171 | * @return the time of the first bucket. | |
172 | */ | |
fbd124dd BH |
173 | public long getFirstBucketTime() { |
174 | return fFirstBucketTime; | |
c392540b FC |
175 | } |
176 | ||
b544077e | 177 | /** |
20ff3b75 AM |
178 | * Set the first event time. |
179 | * @param firstEventTime The time to set | |
b544077e | 180 | */ |
fbd124dd BH |
181 | public void setFirstBucketTime(long firstEventTime) { |
182 | fFirstBucketTime = firstEventTime; | |
183 | } | |
20ff3b75 | 184 | |
b544077e BH |
185 | /** |
186 | * Returns the time of the last bucket. | |
187 | * @return last bucket time | |
188 | */ | |
fbd124dd BH |
189 | public long getLastBucketTime() { |
190 | return getBucketStartTime(fLastBucket); | |
191 | } | |
20ff3b75 | 192 | |
b544077e BH |
193 | /** |
194 | * Returns the time of the bucket start time for given index. | |
195 | * @param index A bucket index. | |
196 | * @return the time of the bucket start time | |
197 | */ | |
fbd124dd BH |
198 | public long getBucketStartTime(int index) { |
199 | return fFirstBucketTime + index * fBucketDuration; | |
200 | } | |
20ff3b75 | 201 | |
b544077e BH |
202 | /** |
203 | * Returns the time of the bucket end time for given index. | |
204 | * @param index A bucket index. | |
205 | * @return the time of the bucket end time | |
206 | */ | |
fbd124dd BH |
207 | public long getBucketEndTime(int index) { |
208 | return getBucketStartTime(index) + fBucketDuration; | |
209 | } | |
95aa81ef | 210 | } |