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 | ||
2bdf0193 | 18 | package org.eclipse.tracecompass.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 | |
95aa81ef JCK |
61 | */ |
62 | public final int[] fLostEventsData; | |
b544077e BH |
63 | /** |
64 | * The bucket duration of a scaled data bucket. | |
65 | */ | |
c392540b | 66 | public long fBucketDuration; |
b544077e | 67 | /** |
20ff3b75 | 68 | * The maximum number of events of all buckets. |
b544077e | 69 | */ |
c392540b | 70 | public long fMaxValue; |
95aa81ef JCK |
71 | /** |
72 | * the maximum of events of all buckets including the lost events | |
95aa81ef JCK |
73 | */ |
74 | public long fMaxCombinedValue; | |
0fcf3b09 PT |
75 | /** |
76 | * The index of the selection begin bucket. | |
0fcf3b09 PT |
77 | */ |
78 | public int fSelectionBeginBucket; | |
79 | /** | |
80 | * The index of the selection end bucket. | |
0fcf3b09 PT |
81 | */ |
82 | public int fSelectionEndBucket; | |
b544077e | 83 | /** |
20ff3b75 | 84 | * The index of the last bucket. |
b544077e | 85 | */ |
c392540b | 86 | public int fLastBucket; |
b544077e BH |
87 | /** |
88 | * The scaling factor used to fill the scaled data. | |
89 | */ | |
c392540b | 90 | public double fScalingFactor; |
95aa81ef JCK |
91 | /** |
92 | * The scaling factor used to fill the scaled data including the lost events. | |
95aa81ef JCK |
93 | */ |
94 | public double fScalingFactorCombined; | |
95 | /** | |
96 | * The scaling factor used to fill the combining scaled data including lost events | |
97 | */ | |
b544077e BH |
98 | /** |
99 | * Time of first bucket. | |
100 | */ | |
fbd124dd | 101 | public long fFirstBucketTime; |
b544077e BH |
102 | /** |
103 | * The time of the first event. | |
104 | */ | |
fbd124dd | 105 | public long fFirstEventTime; |
95aa81ef JCK |
106 | /** |
107 | * show the lost events or not | |
95aa81ef JCK |
108 | */ |
109 | public static volatile boolean hideLostEvents = false; | |
2fc582d2 | 110 | |
c392540b FC |
111 | // ------------------------------------------------------------------------ |
112 | // Constructor | |
113 | // ------------------------------------------------------------------------ | |
114 | ||
b544077e BH |
115 | /** |
116 | * Constructor. | |
117 | * @param width the canvas width | |
118 | * @param height the canvas height | |
119 | * @param barWidth the required bar width | |
120 | */ | |
fbd124dd | 121 | public HistogramScaledData(int width, int height, int barWidth) { |
c392540b FC |
122 | fWidth = width; |
123 | fHeight = height; | |
fbd124dd | 124 | fBarWidth = barWidth; |
2fc582d2 | 125 | fData = new HistogramBucket[width / fBarWidth]; |
95aa81ef | 126 | fLostEventsData = new int[width / fBarWidth]; |
c392540b FC |
127 | fBucketDuration = 1; |
128 | fMaxValue = 0; | |
95aa81ef | 129 | fMaxCombinedValue = 0; |
0fcf3b09 PT |
130 | fSelectionBeginBucket = 0; |
131 | fSelectionEndBucket = 0; | |
c392540b FC |
132 | fLastBucket = 0; |
133 | fScalingFactor = 1; | |
95aa81ef | 134 | fScalingFactorCombined = 1; |
fbd124dd | 135 | fFirstBucketTime = 0; |
c392540b FC |
136 | } |
137 | ||
b544077e BH |
138 | /** |
139 | * Copy constructor | |
140 | * @param other another scaled data. | |
141 | */ | |
c392540b FC |
142 | public HistogramScaledData(HistogramScaledData other) { |
143 | fWidth = other.fWidth; | |
144 | fHeight = other.fHeight; | |
fbd124dd | 145 | fBarWidth = other.fBarWidth; |
95aa81ef JCK |
146 | fData = Arrays.copyOf(other.fData, other.fData.length); |
147 | fLostEventsData = Arrays.copyOf(other.fLostEventsData, other.fLostEventsData.length); | |
c392540b FC |
148 | fBucketDuration = other.fBucketDuration; |
149 | fMaxValue = other.fMaxValue; | |
95aa81ef | 150 | fMaxCombinedValue = other.fMaxCombinedValue; |
0fcf3b09 PT |
151 | fSelectionBeginBucket = other.fSelectionBeginBucket; |
152 | fSelectionEndBucket = other.fSelectionEndBucket; | |
c392540b FC |
153 | fLastBucket = other.fLastBucket; |
154 | fScalingFactor = other.fScalingFactor; | |
95aa81ef | 155 | fScalingFactorCombined = other.fScalingFactorCombined; |
fbd124dd BH |
156 | fFirstBucketTime = other.fFirstBucketTime; |
157 | } | |
20ff3b75 | 158 | |
fbd124dd BH |
159 | // ------------------------------------------------------------------------ |
160 | // Setter and Getter | |
161 | // ------------------------------------------------------------------------ | |
e0752744 | 162 | |
b544077e BH |
163 | /** |
164 | * Returns the time of the first bucket of the scaled data. | |
165 | * @return the time of the first bucket. | |
166 | */ | |
fbd124dd BH |
167 | public long getFirstBucketTime() { |
168 | return fFirstBucketTime; | |
c392540b FC |
169 | } |
170 | ||
b544077e | 171 | /** |
20ff3b75 AM |
172 | * Set the first event time. |
173 | * @param firstEventTime The time to set | |
b544077e | 174 | */ |
fbd124dd BH |
175 | public void setFirstBucketTime(long firstEventTime) { |
176 | fFirstBucketTime = firstEventTime; | |
177 | } | |
20ff3b75 | 178 | |
b544077e BH |
179 | /** |
180 | * Returns the time of the last bucket. | |
181 | * @return last bucket time | |
182 | */ | |
fbd124dd BH |
183 | public long getLastBucketTime() { |
184 | return getBucketStartTime(fLastBucket); | |
185 | } | |
20ff3b75 | 186 | |
b544077e BH |
187 | /** |
188 | * Returns the time of the bucket start time for given index. | |
189 | * @param index A bucket index. | |
190 | * @return the time of the bucket start time | |
191 | */ | |
fbd124dd BH |
192 | public long getBucketStartTime(int index) { |
193 | return fFirstBucketTime + index * fBucketDuration; | |
194 | } | |
20ff3b75 | 195 | |
b544077e BH |
196 | /** |
197 | * Returns the time of the bucket end time for given index. | |
198 | * @param index A bucket index. | |
199 | * @return the time of the bucket end time | |
200 | */ | |
fbd124dd BH |
201 | public long getBucketEndTime(int index) { |
202 | return getBucketStartTime(index) + fBucketDuration; | |
203 | } | |
95aa81ef | 204 | } |