1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 Ericsson
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
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 *******************************************************************************/
15 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.histogram
;
17 import java
.util
.Arrays
;
20 * Convenience class/struct for scaled histogram data.
23 * @author Francois Chouinard
25 public class HistogramScaledData
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
32 * Indicator value that bucket is out of range (not filled).
34 public static final int OUT_OF_RANGE_BUCKET
= -1;
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 * Width of histogram canvas (number of pixels).
44 * Height of histogram canvas (number of pixels).
48 * Width of one histogram bar (number of pixels).
52 * Array of scaled values
56 * The bucket duration of a scaled data bucket.
58 public long fBucketDuration
;
60 * The maximum number of events of all buckets.
62 public long fMaxValue
;
64 * The index of the current bucket.
66 public int fCurrentBucket
;
68 * The index of the last bucket.
70 public int fLastBucket
;
72 * The scaling factor used to fill the scaled data.
74 public double fScalingFactor
;
76 * Time of first bucket.
78 public long fFirstBucketTime
;
80 * The time of the first event.
82 public long fFirstEventTime
;
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
90 * @param width the canvas width
91 * @param height the canvas height
92 * @param barWidth the required bar width
94 public HistogramScaledData(int width
, int height
, int barWidth
) {
98 fData
= new int[width
/fBarWidth
];
99 Arrays
.fill(fData
, 0);
105 fFirstBucketTime
= 0;
110 * @param other another scaled data.
112 public HistogramScaledData(HistogramScaledData other
) {
113 fWidth
= other
.fWidth
;
114 fHeight
= other
.fHeight
;
115 fBarWidth
= other
.fBarWidth
;
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
;
122 fFirstBucketTime
= other
.fFirstBucketTime
;
125 // ------------------------------------------------------------------------
127 // ------------------------------------------------------------------------
130 * Returns the time of the first bucket of the scaled data.
131 * @return the time of the first bucket.
133 public long getFirstBucketTime() {
134 return fFirstBucketTime
;
138 * Set the first event time.
139 * @param firstEventTime The time to set
141 public void setFirstBucketTime(long firstEventTime
) {
142 fFirstBucketTime
= firstEventTime
;
146 * Returns the time of the last bucket.
147 * @return last bucket time
149 public long getLastBucketTime() {
150 return getBucketStartTime(fLastBucket
);
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
158 public long getBucketStartTime(int index
) {
159 return fFirstBucketTime
+ index
* fBucketDuration
;
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
167 public long getBucketEndTime(int index
) {
168 return getBucketStartTime(index
) + fBucketDuration
;