1 37 38 package org.jfree.data; 39 40 import java.util.Arrays ; 41 import java.util.Date ; 42 import java.util.Vector ; 43 44 50 public class DefaultContourDataset extends AbstractDataset implements ContourDataset { 51 52 53 protected String seriesName = null; 54 55 56 protected Number [] xValues = null; 57 58 59 protected Number [] yValues = null; 60 61 62 protected Number [] zValues = null; 63 64 65 protected int xIndex[] = null; 66 67 68 boolean[] dateAxis = new boolean[3]; 69 70 73 public DefaultContourDataset() { 74 } 75 76 84 public DefaultContourDataset(String seriesName, 85 Object [] xData, 86 Object [] yData, 87 Object [] zData) { 88 89 this.seriesName = seriesName; 90 initialize(xData, yData, zData); 91 } 92 93 100 public void initialize(Object [] xData, 101 Object [] yData, 102 Object [] zData) { 103 104 xValues = new Double [xData.length]; 105 yValues = new Double [yData.length]; 106 zValues = new Double [zData.length]; 107 108 115 Vector tmpVector = new Vector (); double x = 1.123452e31; for (int k = 0; k < xValues.length; k++) { 118 if (xData[k] != null) { 119 Number xNumber = null; 120 if (xData[k] instanceof Number ) { 121 xNumber = (Number ) xData[k]; 122 } 123 else if (xData[k] instanceof Date ) { 124 dateAxis[0] = true; 125 Date xDate = (Date ) xData[k]; 126 xNumber = new Long (xDate.getTime()); } 128 else { 129 xNumber = new Integer (0); 130 } 131 xValues[k] = new Double (xNumber.doubleValue()); 133 if (x != xValues[k].doubleValue()) { 135 tmpVector.add(new Integer (k)); x = xValues[k].doubleValue(); } 138 } 139 } 140 141 Object [] inttmp = tmpVector.toArray(); 142 xIndex = new int[inttmp.length]; 144 for (int i = 0; i < inttmp.length; i++) { 145 xIndex[i] = ((Integer ) inttmp[i]).intValue(); 146 } 147 for (int k = 0; k < yValues.length; k++) { yValues[k] = (Double ) yData[k]; 149 if (zData[k] != null) { 150 zValues[k] = (Double ) zData[k]; 151 } 152 } 153 } 154 155 162 public static Object [][] formObjectArray(double[][] data) { 163 Object [][] object = new Double [data.length][data[0].length]; 164 165 for (int i = 0; i < object.length; i++) { 166 for (int j = 0; j < object[i].length; j++) { 167 object[i][j] = new Double (data[i][j]); 168 } 169 } 170 return object; 171 } 172 173 180 public static Object [] formObjectArray(double[] data) { 181 182 Object [] object = new Double [data.length]; 183 for (int i = 0; i < object.length; i++) { 184 object[i] = new Double (data[i]); 185 } 186 return object; 187 } 188 189 198 public int getItemCount(int series) { 199 if (series > 0) { 200 System.out.println("Only one series for contour"); 201 } 202 return zValues.length; 203 } 204 205 210 public double getMaxZValue() { 211 double zMax = -1.e20; 212 for (int k = 0; k < zValues.length; k++) { 213 if (zValues[k] != null) { 214 zMax = Math.max(zMax, zValues[k].doubleValue()); 215 } 216 } 217 return zMax; 218 } 219 220 225 public double getMinZValue() { 226 227 double zMin = 1.e20; 228 for (int k = 0; k < zValues.length; k++) { 229 if (zValues[k] != null) { 230 zMin = Math.min(zMin, zValues[k].doubleValue()); 231 } 232 } 233 return zMin; 234 } 235 236 244 public Range getZValueRange(Range x, Range y) { 245 246 double minX = x.getLowerBound(); 247 double minY = y.getLowerBound(); 248 double maxX = x.getUpperBound(); 249 double maxY = y.getUpperBound(); 250 251 double zMin = 1.e20; 252 double zMax = -1.e20; 253 for (int k = 0; k < zValues.length; k++) { 254 if (xValues[k].doubleValue() >= minX 255 && xValues[k].doubleValue() <= maxX 256 && yValues[k].doubleValue() >= minY 257 && yValues[k].doubleValue() <= maxY) { 258 if (zValues[k] != null) { 259 zMin = Math.min(zMin, zValues[k].doubleValue()); 260 zMax = Math.max(zMax, zValues[k].doubleValue()); 261 } 262 } 263 } 264 265 return new Range(zMin, zMax); 266 } 267 268 278 public double getMinZValue(double minX, double minY, double maxX, double maxY) { 279 280 double zMin = 1.e20; 281 for (int k = 0; k < zValues.length; k++) { 282 if (zValues[k] != null) 283 zMin = Math.min(zMin, zValues[k].doubleValue()); 284 } 285 return zMin; 286 287 } 288 289 296 public int getSeriesCount() { 297 return 1; 298 } 299 300 309 public String getSeriesName(int series) { 310 if (series > 0) { 311 System.out.println("Only one series for contour"); 312 } 313 return seriesName; 314 } 315 316 321 public int[] getXIndices() { 322 return xIndex; 323 } 324 325 330 public Number [] getXValues() { 331 return xValues; 332 } 333 334 343 public Number getXValue(int series, int item) { 344 if (series > 0) { 345 System.out.println("Only one series for contour"); 346 } 347 return xValues[item]; 348 } 349 350 357 public Number getXValue(int item) { 358 return xValues[item]; 359 } 360 361 366 public Number [] getYValues() { 367 return yValues; 368 } 369 370 379 public Number getYValue(int series, int item) { 380 if (series > 0) { 381 System.out.println("Only one series for contour"); 382 } 383 return yValues[item]; 384 } 385 386 391 public Number [] getZValues() { 392 return zValues; 393 } 394 395 404 public Number getZValue(int series, int item) { 405 if (series > 0) { 406 System.out.println("Only one series for contour"); 407 } 408 return zValues[item]; 409 } 410 411 416 public int[] indexX() { 417 int[] index = new int[xValues.length]; 418 for (int k = 0; k < index.length; k++) { 419 index[k] = indexX(k); 420 } 421 return index; 422 } 423 424 431 public int indexX(int k) { 432 int i = Arrays.binarySearch(xIndex, k); 433 if (i >= 0) { 434 return i; 435 } else { 436 return -1 * i - 2; 437 } 438 } 439 440 441 448 public int indexY(int k) { return (k / xValues.length); 450 } 451 452 460 public int indexZ(int i, int j) { 461 return xValues.length * j + i; 462 } 463 464 471 public boolean isDateAxis(int axisNumber) { 472 if (axisNumber < 0 || axisNumber > 2) { 473 return false; } 475 return dateAxis[axisNumber]; 476 } 477 478 483 public void setSeriesNames(String [] seriesNames) { 484 if (seriesNames.length > 1) { 485 System.out.println("Contours only support one series"); 486 } 487 seriesName = seriesNames[0]; 488 fireDatasetChanged(); 489 } 490 491 } 492 | Popular Tags |