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