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