Commit | Line | Data |
---|---|---|
c392540b | 1 | /******************************************************************************* |
e0752744 | 2 | * Copyright (c) 2011, 2012 Ericsson |
c392540b FC |
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 | * Francois Chouinard - Initial API and implementation | |
fbd124dd | 11 | * Bernd Hufmann - Added setter and getter |
e0752744 | 12 | * Francois Chouinard - Moved from LTTng to TMF |
c392540b FC |
13 | *******************************************************************************/ |
14 | ||
e0752744 | 15 | package org.eclipse.linuxtools.tmf.ui.views.histogram; |
c392540b FC |
16 | |
17 | import java.util.Arrays; | |
18 | ||
19 | /** | |
c392540b | 20 | * Convenience class/struct for scaled histogram data. |
b544077e BH |
21 | * |
22 | * @version 1.0 | |
23 | * @author Francois Chouinard | |
c392540b FC |
24 | */ |
25 | public class HistogramScaledData { | |
26 | ||
27 | // ------------------------------------------------------------------------ | |
28 | // Constants | |
29 | // ------------------------------------------------------------------------ | |
30 | ||
b544077e BH |
31 | /** |
32 | * Indicator value that bucket is out of range (not filled). | |
33 | */ | |
c392540b FC |
34 | public static final int OUT_OF_RANGE_BUCKET = -1; |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Attributes | |
38 | // ------------------------------------------------------------------------ | |
b544077e BH |
39 | /** |
40 | * Width of histogram canvas (number of pixels). | |
41 | */ | |
c392540b | 42 | public int fWidth; |
b544077e BH |
43 | /** |
44 | * Height of histogram canvas (number of pixels). | |
45 | */ | |
c392540b | 46 | public int fHeight; |
b544077e BH |
47 | /** |
48 | * Width of one histogram bar (number of pixels). | |
49 | */ | |
fbd124dd | 50 | public int fBarWidth; |
b544077e BH |
51 | /** |
52 | * Array of scaled values | |
53 | */ | |
c392540b | 54 | public int[] fData; |
b544077e BH |
55 | /** |
56 | * The bucket duration of a scaled data bucket. | |
57 | */ | |
c392540b | 58 | public long fBucketDuration; |
b544077e BH |
59 | /** |
60 | * The maximum number of events of all buckets. | |
61 | */ | |
c392540b | 62 | public long fMaxValue; |
b544077e BH |
63 | /** |
64 | * The index of the current bucket. | |
65 | */ | |
c392540b | 66 | public int fCurrentBucket; |
b544077e BH |
67 | /** |
68 | * The index of the last bucket. | |
69 | */ | |
c392540b | 70 | public int fLastBucket; |
b544077e BH |
71 | /** |
72 | * The scaling factor used to fill the scaled data. | |
73 | */ | |
c392540b | 74 | public double fScalingFactor; |
b544077e BH |
75 | /** |
76 | * Time of first bucket. | |
77 | */ | |
fbd124dd | 78 | public long fFirstBucketTime; |
b544077e BH |
79 | /** |
80 | * The time of the first event. | |
81 | */ | |
fbd124dd | 82 | public long fFirstEventTime; |
c392540b FC |
83 | |
84 | // ------------------------------------------------------------------------ | |
85 | // Constructor | |
86 | // ------------------------------------------------------------------------ | |
87 | ||
b544077e BH |
88 | /** |
89 | * Constructor. | |
90 | * @param width the canvas width | |
91 | * @param height the canvas height | |
92 | * @param barWidth the required bar width | |
93 | */ | |
fbd124dd | 94 | public HistogramScaledData(int width, int height, int barWidth) { |
c392540b FC |
95 | fWidth = width; |
96 | fHeight = height; | |
fbd124dd BH |
97 | fBarWidth = barWidth; |
98 | fData = new int[width/fBarWidth]; | |
c392540b FC |
99 | Arrays.fill(fData, 0); |
100 | fBucketDuration = 1; | |
101 | fMaxValue = 0; | |
102 | fCurrentBucket = 0; | |
103 | fLastBucket = 0; | |
104 | fScalingFactor = 1; | |
fbd124dd | 105 | fFirstBucketTime = 0; |
c392540b FC |
106 | } |
107 | ||
b544077e BH |
108 | /** |
109 | * Copy constructor | |
110 | * @param other another scaled data. | |
111 | */ | |
c392540b FC |
112 | public HistogramScaledData(HistogramScaledData other) { |
113 | fWidth = other.fWidth; | |
114 | fHeight = other.fHeight; | |
fbd124dd | 115 | fBarWidth = other.fBarWidth; |
c392540b FC |
116 | fData = Arrays.copyOf(other.fData, fWidth); |
117 | fBucketDuration = other.fBucketDuration; | |
118 | fMaxValue = other.fMaxValue; | |
119 | fCurrentBucket = other.fCurrentBucket; | |
120 | fLastBucket = other.fLastBucket; | |
121 | fScalingFactor = other.fScalingFactor; | |
fbd124dd BH |
122 | fFirstBucketTime = other.fFirstBucketTime; |
123 | } | |
124 | ||
125 | // ------------------------------------------------------------------------ | |
126 | // Setter and Getter | |
127 | // ------------------------------------------------------------------------ | |
e0752744 | 128 | |
b544077e BH |
129 | /** |
130 | * Returns the time of the first bucket of the scaled data. | |
131 | * @return the time of the first bucket. | |
132 | */ | |
fbd124dd BH |
133 | public long getFirstBucketTime() { |
134 | return fFirstBucketTime; | |
c392540b FC |
135 | } |
136 | ||
b544077e BH |
137 | /** |
138 | * Set the first event time. | |
139 | * @param firstEventTime | |
140 | */ | |
fbd124dd BH |
141 | public void setFirstBucketTime(long firstEventTime) { |
142 | fFirstBucketTime = firstEventTime; | |
143 | } | |
144 | ||
b544077e BH |
145 | /** |
146 | * Returns the time of the last bucket. | |
147 | * @return last bucket time | |
148 | */ | |
fbd124dd BH |
149 | public long getLastBucketTime() { |
150 | return getBucketStartTime(fLastBucket); | |
151 | } | |
152 | ||
b544077e BH |
153 | /** |
154 | * Returns the time of the bucket start time for given index. | |
155 | * @param index A bucket index. | |
156 | * @return the time of the bucket start time | |
157 | */ | |
fbd124dd BH |
158 | public long getBucketStartTime(int index) { |
159 | return fFirstBucketTime + index * fBucketDuration; | |
160 | } | |
161 | ||
b544077e BH |
162 | /** |
163 | * Returns the time of the bucket end time for given index. | |
164 | * @param index A bucket index. | |
165 | * @return the time of the bucket end time | |
166 | */ | |
fbd124dd BH |
167 | public long getBucketEndTime(int index) { |
168 | return getBucketStartTime(index) + fBucketDuration; | |
169 | } | |
c392540b | 170 | } |