Generalize and move the Histogram view from LTTng to TMF
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / HistogramScaledData.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 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
12 * Francois Chouinard - Moved from LTTng to TMF
13 *******************************************************************************/
14
15 package org.eclipse.linuxtools.tmf.ui.views.histogram;
16
17 import java.util.Arrays;
18
19 /**
20 * <b><u>HistogramScaledData</u></b>
21 * <p>
22 * Convenience class/struct for scaled histogram data.
23 */
24 public class HistogramScaledData {
25
26 // ------------------------------------------------------------------------
27 // Constants
28 // ------------------------------------------------------------------------
29
30 public static final int OUT_OF_RANGE_BUCKET = -1;
31
32 // ------------------------------------------------------------------------
33 // Attributes
34 // ------------------------------------------------------------------------
35
36 public int fWidth;
37 public int fHeight;
38 public int fBarWidth;
39 public int[] fData;
40 public long fBucketDuration;
41 public long fMaxValue;
42 public int fCurrentBucket;
43 public int fLastBucket;
44 public double fScalingFactor;
45 public long fFirstBucketTime;
46 public long fFirstEventTime;
47
48 // ------------------------------------------------------------------------
49 // Constructor
50 // ------------------------------------------------------------------------
51
52 public HistogramScaledData(int width, int height, int barWidth) {
53 fWidth = width;
54 fHeight = height;
55 fBarWidth = barWidth;
56 fData = new int[width/fBarWidth];
57 Arrays.fill(fData, 0);
58 fBucketDuration = 1;
59 fMaxValue = 0;
60 fCurrentBucket = 0;
61 fLastBucket = 0;
62 fScalingFactor = 1;
63 fFirstBucketTime = 0;
64 }
65
66 public HistogramScaledData(HistogramScaledData other) {
67 fWidth = other.fWidth;
68 fHeight = other.fHeight;
69 fBarWidth = other.fBarWidth;
70 fData = Arrays.copyOf(other.fData, fWidth);
71 fBucketDuration = other.fBucketDuration;
72 fMaxValue = other.fMaxValue;
73 fCurrentBucket = other.fCurrentBucket;
74 fLastBucket = other.fLastBucket;
75 fScalingFactor = other.fScalingFactor;
76 fFirstBucketTime = other.fFirstBucketTime;
77 }
78
79 // ------------------------------------------------------------------------
80 // Setter and Getter
81 // ------------------------------------------------------------------------
82
83 public long getFirstBucketTime() {
84 return fFirstBucketTime;
85 }
86
87 public void setFirstBucketTime(long firstEventTime) {
88 fFirstBucketTime = firstEventTime;
89 }
90
91 public long getLastBucketTime() {
92 return getBucketStartTime(fLastBucket);
93 }
94
95 public long getBucketStartTime(int index) {
96 return fFirstBucketTime + index * fBucketDuration;
97 }
98
99 public long getBucketEndTime(int index) {
100 return getBucketStartTime(index) + fBucketDuration;
101 }
102
103 }
This page took 0.032166 seconds and 5 git commands to generate.