1 /*
2 * put your module comment here
3 * formatted with JxBeauty (c) johann.langhofer@nextra.at
4 */
5
6
7 package edu.psu.geovista.app.scatterplot;
8
9
10 /***
11 * Title:
12 * Description:
13 * Copyright: Copyright (c) 2001
14 * Company:
15 * @author
16 * @version 1.0
17 */
18 public class DataArray {
19 private double[] dataArray;
20 private double[] extent = new double[2];
21 private double[] dataExtent = new double[2];
22 private double[] MMExtent = new double[2];
23 private double alterBase;
24
25 /***
26 * put your documentation comment here
27 */
28 public DataArray () {
29 }
30
31 /***
32 * put your documentation comment here
33 * @param double[] dataArray
34 */
35 public DataArray (double[] dataArray) {
36 this.dataArray = dataArray;
37 this.calculateExtents(this.dataArray);
38 }
39
40 /***
41 * put your documentation comment here
42 * @param dataArray
43 */
44 public void setDataArray (double[] dataArray) {
45 this.dataArray = dataArray;
46 this.calculateExtents(this.dataArray);
47 }
48
49 /***
50 * put your documentation comment here
51 * @param dataArray[]
52 */
53 private void calculateExtents (double[] dataArray) {
54 //Calculate the minimum and maximum value in an array.
55 //extent[0] is minimum and extent[1] is maximum.
56 if (dataArray == null){
57 return;
58 }
59 this.dataExtent[0] = Double.POSITIVE_INFINITY;
60 this.dataExtent[1] = Double.NEGATIVE_INFINITY;
61 for (int i = 0; i < dataArray.length; i++) {
62 if (!Double.isNaN(dataArray[i])) {
63 this.dataExtent[0] = Math.min(this.dataExtent[0], dataArray[i]);
64 this.dataExtent[1] = Math.max(this.dataExtent[1], dataArray[i]);
65 }
66 }
67 this.extent[0] = this.dataExtent[0];
68 this.extent[1] = this.dataExtent[1];
69 this.calculateCoorExtents();
70 }
71
72 private void calculateCoorExtents (){
73 //Find out the possible minimum and maximum values for axis based on the array.
74 //MMExtent[] are the extremes on axis and alterBase is the tick spacing.
75 double unitrange = (extent[1]-extent[0])/5;
76 alterBase = Math.pow(10, Math.floor(Math.log(unitrange)/Math.log(10)));
77 double ratio = unitrange/alterBase;
78 if (ratio<1.5) alterBase = alterBase;
79 else if (ratio<3) alterBase = 2*alterBase;
80 else if (ratio<7.5) alterBase = 5*alterBase;
81 else alterBase = 10*alterBase;
82 MMExtent[1] = alterBase*Math.ceil(extent[1]/alterBase);
83 MMExtent[0] = alterBase*Math.floor(extent[0]/alterBase);
84 }
85
86 /***
87 * Return the data ranges which will be displayed.
88 * @return double[] extent
89 */
90 public void setDataExtent () {
91 this.extent = dataExtent;
92 this.calculateCoorExtents();
93 }
94
95 /***
96 * Return the data ranges which will be displayed.
97 * @return double[] extent
98 */
99 public void setExtent (double[] extents) {
100 this.extent = extents;
101 this.calculateCoorExtents();
102 }
103
104 /***
105 * Return the data ranges which will be displayed.
106 * @return double[] extent
107 */
108 public double[] getExtent () {
109 return extent;
110 }
111
112 /***
113 * put your documentation comment here
114 * @param int index
115 * @return double dataArray[index]
116 */
117 public double getValueAtIndex (int index) {
118 // if ((index < 0) || (index >= values.length))
119 // throw new IllegalArgumentException("index = " + index + " is out of range");
120 return dataArray[index];
121 }
122
123 /***
124 * Return the length of data array.
125 * @return int length
126 */
127 public int length () {
128 return dataArray.length;
129 }
130
131 /***
132 * Return the extents on coordinate axies.
133 * @return double[] MMExtent.
134 */
135 public double[] getMaxMinCoorValue () {
136 return MMExtent;
137 }
138
139 /***
140 * Return the base of labels.
141 * @return double alterBase
142 */
143 public double getMajorTick () {
144 return alterBase;
145 }
146
147 /***
148 * Return the number of ticks on axis.
149 * @return int tickNumber
150 */
151 public int getTickNumber () {
152 int tickNumber = (int)((MMExtent[1] - MMExtent[0])/alterBase);
153 return tickNumber;
154 }
155 }
156
157
158
This page was automatically generated by Maven