Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 52487a7b6aee6956a89f1835f365c948e2dc470b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*******************************************************************************
 * Copyright (c) 2011, 2012 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Francois Chouinard - Initial API and implementation
 *   Bernd Hufmann - Added setter and getter and bar width support
 *   Francois Chouinard - Moved from LTTng to TMF
 *   Patrick Tasse - Support selection range
 *******************************************************************************/

package org.eclipse.linuxtools.tmf.ui.views.histogram;

import java.util.Arrays;

/**
 * Convenience class/struct for scaled histogram data.
 *
 * @version 1.0
 * @author Francois Chouinard
 */
public class HistogramScaledData {

    // ------------------------------------------------------------------------
    // Constants
    // ------------------------------------------------------------------------

    /**
     * Indicator value that bucket is out of range (not filled).
     */
    public static final int OUT_OF_RANGE_BUCKET = -1;

    // ------------------------------------------------------------------------
    // Attributes
    // ------------------------------------------------------------------------
    /**
     * Width of histogram canvas (number of pixels).
     */
    public int fWidth;
    /**
     * Height of histogram canvas (number of pixels).
     */
    public int fHeight;
    /**
     * Width of one histogram bar (number of pixels).
     */
    public int fBarWidth;
    /**
     * Array of scaled values
     */
    public int[] fData;
    /**
     * The bucket duration of a scaled data bucket.
     */
    public long fBucketDuration;
    /**
     * The maximum number of events of all buckets.
     */
    public long fMaxValue;
    /**
     * The index of the current bucket.
     */
    @Deprecated
    public int fCurrentBucket;
    /**
     * The index of the selection begin bucket.
     * @since 2.1
     */
    public int fSelectionBeginBucket;
    /**
     * The index of the selection end bucket.
     * @since 2.1
     */
    public int fSelectionEndBucket;
    /**
     * The index of the last bucket.
     */
    public int fLastBucket;
    /**
     * The scaling factor used to fill the scaled data.
     */
    public double fScalingFactor;
    /**
     * Time of first bucket.
     */
    public long fFirstBucketTime;
    /**
     * The time of the first event.
     */
    public long fFirstEventTime;

    // ------------------------------------------------------------------------
    // Constructor
    // ------------------------------------------------------------------------

    /**
     * Constructor.
     * @param width the canvas width
     * @param height the canvas height
     * @param barWidth the required bar width
     */
    public HistogramScaledData(int width, int height, int barWidth) {
        fWidth = width;
        fHeight = height;
        fBarWidth = barWidth;
        fData = new int[width/fBarWidth];
        Arrays.fill(fData, 0);
        fBucketDuration = 1;
        fMaxValue = 0;
        fSelectionBeginBucket = 0;
        fSelectionEndBucket = 0;
        fLastBucket = 0;
        fScalingFactor = 1;
        fFirstBucketTime = 0;
    }

    /**
     * Copy constructor
     * @param other another scaled data.
     */
    public HistogramScaledData(HistogramScaledData other) {
        fWidth = other.fWidth;
        fHeight = other.fHeight;
        fBarWidth = other.fBarWidth;
        fData = Arrays.copyOf(other.fData, fWidth);
        fBucketDuration = other.fBucketDuration;
        fMaxValue = other.fMaxValue;
        fSelectionBeginBucket = other.fSelectionBeginBucket;
        fSelectionEndBucket = other.fSelectionEndBucket;
        fLastBucket = other.fLastBucket;
        fScalingFactor = other.fScalingFactor;
        fFirstBucketTime = other.fFirstBucketTime;
    }

    // ------------------------------------------------------------------------
    // Setter and Getter
    // ------------------------------------------------------------------------

    /**
     * Returns the time of the first bucket of the scaled data.
     * @return the time of the first bucket.
     */
    public long getFirstBucketTime() {
        return fFirstBucketTime;
    }

    /**
     * Set the first event time.
     * @param firstEventTime The time to set
     */
    public void setFirstBucketTime(long firstEventTime) {
        fFirstBucketTime = firstEventTime;
    }

    /**
     * Returns the time of the last bucket.
     * @return last bucket time
     */
    public long getLastBucketTime() {
        return getBucketStartTime(fLastBucket);
    }

    /**
     * Returns the time of the bucket start time for given index.
     * @param index A bucket index.
     * @return the time of the bucket start time
     */
    public long getBucketStartTime(int index) {
        return fFirstBucketTime + index * fBucketDuration;
    }

    /**
     * Returns the time of the bucket end time for given index.
     * @param index A bucket index.
     * @return the time of the bucket end time
     */
    public long getBucketEndTime(int index) {
        return getBucketStartTime(index) + fBucketDuration;
    }
}

Back to the top