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