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 * Patrick Tasse - Support selection range
14 *******************************************************************************/
16 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.histogram
;
18 import java
.util
.Arrays
;
21 * Convenience class/struct for scaled histogram data.
24 * @author Francois Chouinard
26 public class HistogramScaledData
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
33 * Indicator value that bucket is out of range (not filled).
35 public static final int OUT_OF_RANGE_BUCKET
= -1;
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 * Width of histogram canvas (number of pixels).
45 * Height of histogram canvas (number of pixels).
49 * Width of one histogram bar (number of pixels).
53 * Array of scaled values
57 * The bucket duration of a scaled data bucket.
59 public long fBucketDuration
;
61 * The maximum number of events of all buckets.
63 public long fMaxValue
;
65 * The index of the current bucket.
68 public int fCurrentBucket
;
70 * The index of the selection begin bucket.
73 public int fSelectionBeginBucket
;
75 * The index of the selection end bucket.
78 public int fSelectionEndBucket
;
80 * The index of the last bucket.
82 public int fLastBucket
;
84 * The scaling factor used to fill the scaled data.
86 public double fScalingFactor
;
88 * Time of first bucket.
90 public long fFirstBucketTime
;
92 * The time of the first event.
94 public long fFirstEventTime
;
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
102 * @param width the canvas width
103 * @param height the canvas height
104 * @param barWidth the required bar width
106 public HistogramScaledData(int width
, int height
, int barWidth
) {
109 fBarWidth
= barWidth
;
110 fData
= new int[width
/fBarWidth
];
111 Arrays
.fill(fData
, 0);
114 fSelectionBeginBucket
= 0;
115 fSelectionEndBucket
= 0;
118 fFirstBucketTime
= 0;
123 * @param other another scaled data.
125 public HistogramScaledData(HistogramScaledData other
) {
126 fWidth
= other
.fWidth
;
127 fHeight
= other
.fHeight
;
128 fBarWidth
= other
.fBarWidth
;
129 fData
= Arrays
.copyOf(other
.fData
, fWidth
);
130 fBucketDuration
= other
.fBucketDuration
;
131 fMaxValue
= other
.fMaxValue
;
132 fSelectionBeginBucket
= other
.fSelectionBeginBucket
;
133 fSelectionEndBucket
= other
.fSelectionEndBucket
;
134 fLastBucket
= other
.fLastBucket
;
135 fScalingFactor
= other
.fScalingFactor
;
136 fFirstBucketTime
= other
.fFirstBucketTime
;
139 // ------------------------------------------------------------------------
141 // ------------------------------------------------------------------------
144 * Returns the time of the first bucket of the scaled data.
145 * @return the time of the first bucket.
147 public long getFirstBucketTime() {
148 return fFirstBucketTime
;
152 * Set the first event time.
153 * @param firstEventTime The time to set
155 public void setFirstBucketTime(long firstEventTime
) {
156 fFirstBucketTime
= firstEventTime
;
160 * Returns the time of the last bucket.
161 * @return last bucket time
163 public long getLastBucketTime() {
164 return getBucketStartTime(fLastBucket
);
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
172 public long getBucketStartTime(int index
) {
173 return fFirstBucketTime
+ index
* fBucketDuration
;
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
181 public long getBucketEndTime(int index
) {
182 return getBucketStartTime(index
) + fBucketDuration
;