comparison artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.java @ 8202:e4606eae8ea5

sed src/**/*.java 's/logger/log/g'
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 12:58:17 +0200
parents 8b8407c71ee2
children 42b258294067
comparison
equal deleted inserted replaced
8201:4b8c5a08de04 8202:e4606eae8ea5
67 67
68 protected Map<String, String> attributes; 68 protected Map<String, String> attributes;
69 69
70 protected boolean domainZeroLineVisible; 70 protected boolean domainZeroLineVisible;
71 71
72 private static final Logger logger = 72 private static final Logger log =
73 Logger.getLogger(TimeseriesChartGenerator.class); 73 Logger.getLogger(TimeseriesChartGenerator.class);
74 74
75 public static final int AXIS_SPACE = 5; 75 public static final int AXIS_SPACE = 5;
76 76
77 protected Map<Integer, Bounds> xBounds; 77 protected Map<Integer, Bounds> xBounds;
94 94
95 95
96 96
97 @Override 97 @Override
98 public JFreeChart generateChart() { 98 public JFreeChart generateChart() {
99 logger.info("Generate Timeseries Chart."); 99 log.info("Generate Timeseries Chart.");
100 100
101 JFreeChart chart = ChartFactory.createTimeSeriesChart( 101 JFreeChart chart = ChartFactory.createTimeSeriesChart(
102 getChartTitle(), 102 getChartTitle(),
103 getXAxisLabel(), 103 getXAxisLabel(),
104 getYAxisLabel(0), 104 getYAxisLabel(0),
156 * Copy from XYChartGenerator. 156 * Copy from XYChartGenerator.
157 */ 157 */
158 protected void addLogo(XYPlot plot) { 158 protected void addLogo(XYPlot plot) {
159 String logo = showLogo(); 159 String logo = showLogo();
160 if (logo == null) { 160 if (logo == null) {
161 logger.debug("No logo to show chosen"); 161 log.debug("No logo to show chosen");
162 return; 162 return;
163 } 163 }
164 164
165 ImageIcon imageIcon = null; 165 ImageIcon imageIcon = null;
166 if (logo.equals("none")) { 166 if (logo.equals("none")) {
200 } 200 }
201 else if (placev.equals("center")) { 201 else if (placev.equals("center")) {
202 yPos = ((Double)getYBounds(0).getUpper() + (Double)getYBounds(0).getLower())/2d; 202 yPos = ((Double)getYBounds(0).getUpper() + (Double)getYBounds(0).getLower())/2d;
203 } 203 }
204 else { 204 else {
205 logger.debug("Unknown place-v value: " + placev); 205 log.debug("Unknown place-v value: " + placev);
206 } 206 }
207 207
208 if (placeh == null || placeh.equals("none")) { 208 if (placeh == null || placeh.equals("none")) {
209 placeh = "center"; 209 placeh = "center";
210 } 210 }
216 } 216 }
217 else if (placeh.equals("center")) { 217 else if (placeh.equals("center")) {
218 xPos = ((Long)getXBounds(0).getUpper() + (Long)getXBounds(0).getLower())/2d; 218 xPos = ((Long)getXBounds(0).getUpper() + (Long)getXBounds(0).getLower())/2d;
219 } 219 }
220 else { 220 else {
221 logger.debug("Unknown place-h value: " + placeh); 221 log.debug("Unknown place-h value: " + placeh);
222 } 222 }
223 223
224 logger.debug("logo position: " + xPos + "/" + yPos); 224 log.debug("logo position: " + xPos + "/" + yPos);
225 225
226 org.jfree.ui.RectangleAnchor anchor 226 org.jfree.ui.RectangleAnchor anchor
227 = org.jfree.ui.RectangleAnchor.TOP; 227 = org.jfree.ui.RectangleAnchor.TOP;
228 if (placev.equals("top")) { 228 if (placev.equals("top")) {
229 if (placeh.equals("left")) { 229 if (placeh.equals("left")) {
274 * Copy of implementation in XYChartGenerator. 274 * Copy of implementation in XYChartGenerator.
275 * 275 *
276 * @param plot The XYPlot. 276 * @param plot The XYPlot.
277 */ 277 */
278 protected void consumeAxisSettings(XYPlot plot) { 278 protected void consumeAxisSettings(XYPlot plot) {
279 logger.debug("Zoom to specified ranges."); 279 log.debug("Zoom to specified ranges.");
280 280
281 Bounds xrange = getDomainAxisRange(); 281 Bounds xrange = getDomainAxisRange();
282 Bounds yrange = getValueAxisRange(); 282 Bounds yrange = getValueAxisRange();
283 283
284 ValueAxis xAxis = plot.getDomainAxis(); 284 ValueAxis xAxis = plot.getDomainAxis();
303 continue; 303 continue;
304 } 304 }
305 } 305 }
306 306
307 if (yaxis == null) { 307 if (yaxis == null) {
308 logger.debug("Zoom problem: no Y Axis for index: " + i); 308 log.debug("Zoom problem: no Y Axis for index: " + i);
309 continue; 309 continue;
310 } 310 }
311 311
312 logger.debug("Prepare zoom settings for y axis at index: " + i); 312 log.debug("Prepare zoom settings for y axis at index: " + i);
313 zoomY(plot, yaxis, getYBounds(Integer.valueOf(i)), yrange); 313 zoomY(plot, yaxis, getYBounds(Integer.valueOf(i)), yrange);
314 } 314 }
315 } 315 }
316 316
317 317
326 * 326 *
327 * @param idx The symbol for the new AxisDataset. 327 * @param idx The symbol for the new AxisDataset.
328 */ 328 */
329 @Override 329 @Override
330 protected AxisDataset createAxisDataset(int idx) { 330 protected AxisDataset createAxisDataset(int idx) {
331 logger.debug("Create a new AxisDataset for index: " + idx); 331 log.debug("Create a new AxisDataset for index: " + idx);
332 return new AxisDataset(idx); 332 return new AxisDataset(idx);
333 } 333 }
334 334
335 335
336 @Override 336 @Override
403 } 403 }
404 } 404 }
405 405
406 406
407 public Bounds[] getBoundsForAxis(int index) { 407 public Bounds[] getBoundsForAxis(int index) {
408 logger.debug("Return x and y bounds for axis at: " + index); 408 log.debug("Return x and y bounds for axis at: " + index);
409 409
410 Bounds rx = getXBounds(Integer.valueOf(index)); 410 Bounds rx = getXBounds(Integer.valueOf(index));
411 Bounds ry = getYBounds(Integer.valueOf(index)); 411 Bounds ry = getYBounds(Integer.valueOf(index));
412 412
413 if (rx == null) { 413 if (rx == null) {
414 logger.warn("Range for x axis not set." + 414 log.warn("Range for x axis not set." +
415 " Using default values: 0 - 1."); 415 " Using default values: 0 - 1.");
416 rx = new TimeBounds(0l, 1l); 416 rx = new TimeBounds(0l, 1l);
417 } 417 }
418 418
419 if (ry == null) { 419 if (ry == null) {
420 logger.warn("Range for y axis not set." + 420 log.warn("Range for y axis not set." +
421 " Using default values: 0 - 1."); 421 " Using default values: 0 - 1.");
422 ry = new DoubleBounds(0l, 1l); 422 ry = new DoubleBounds(0l, 1l);
423 } 423 }
424 424
425 logger.debug("X Bounds at index " + index + " is: " + rx); 425 log.debug("X Bounds at index " + index + " is: " + rx);
426 logger.debug("Y Bounds at index " + index + " is: " + ry); 426 log.debug("Y Bounds at index " + index + " is: " + ry);
427 427
428 return new Bounds[] {rx, ry}; 428 return new Bounds[] {rx, ry};
429 } 429 }
430 430
431 431
432 /** Get (zoom)values from request. */ 432 /** Get (zoom)values from request. */
433 public Bounds getDomainAxisRange() { 433 public Bounds getDomainAxisRange() {
434 String[] ranges = getDomainAxisRangeFromRequest(); 434 String[] ranges = getDomainAxisRangeFromRequest();
435 435
436 if (ranges == null || ranges.length < 2) { 436 if (ranges == null || ranges.length < 2) {
437 logger.debug("No zoom range for domain axis specified."); 437 log.debug("No zoom range for domain axis specified.");
438 return null; 438 return null;
439 } 439 }
440 440
441 if (ranges[0] == null || ranges[1] == null) { 441 if (ranges[0] == null || ranges[1] == null) {
442 logger.warn("Invalid ranges for domain axis specified!"); 442 log.warn("Invalid ranges for domain axis specified!");
443 return null; 443 return null;
444 } 444 }
445 445
446 try { 446 try {
447 double lower = Double.parseDouble(ranges[0]); 447 double lower = Double.parseDouble(ranges[0]);
448 double upper = Double.parseDouble(ranges[1]); 448 double upper = Double.parseDouble(ranges[1]);
449 449
450 return new DoubleBounds(lower, upper); 450 return new DoubleBounds(lower, upper);
451 } 451 }
452 catch (NumberFormatException nfe) { 452 catch (NumberFormatException nfe) {
453 logger.warn("Invalid ranges for domain axis specified: " + nfe); 453 log.warn("Invalid ranges for domain axis specified: " + nfe);
454 } 454 }
455 455
456 return null; 456 return null;
457 } 457 }
458 458
459 459
460 public Bounds getValueAxisRange() { 460 public Bounds getValueAxisRange() {
461 String[] ranges = getValueAxisRangeFromRequest(); 461 String[] ranges = getValueAxisRangeFromRequest();
462 462
463 if (ranges == null || ranges.length < 2) { 463 if (ranges == null || ranges.length < 2) {
464 logger.debug("No zoom range for domain axis specified."); 464 log.debug("No zoom range for domain axis specified.");
465 return null; 465 return null;
466 } 466 }
467 467
468 if (ranges[0] == null || ranges[1] == null) { 468 if (ranges[0] == null || ranges[1] == null) {
469 logger.warn("Invalid ranges for domain axis specified!"); 469 log.warn("Invalid ranges for domain axis specified!");
470 return null; 470 return null;
471 } 471 }
472 472
473 try { 473 try {
474 double lower = Double.parseDouble(ranges[0]); 474 double lower = Double.parseDouble(ranges[0]);
475 double upper = Double.parseDouble(ranges[1]); 475 double upper = Double.parseDouble(ranges[1]);
476 476
477 return new DoubleBounds(lower, upper); 477 return new DoubleBounds(lower, upper);
478 } 478 }
479 catch (NumberFormatException nfe) { 479 catch (NumberFormatException nfe) {
480 logger.warn("Invalid ranges for domain axis specified: " + nfe); 480 log.warn("Invalid ranges for domain axis specified: " + nfe);
481 } 481 }
482 482
483 return null; 483 return null;
484 } 484 }
485 485
486 486
487 protected void adaptZoom(XYPlot plot) { 487 protected void adaptZoom(XYPlot plot) {
488 logger.debug("Adapt zoom of Timeseries chart."); 488 log.debug("Adapt zoom of Timeseries chart.");
489 489
490 zoomX(plot, plot.getDomainAxis(), getXBounds(0), getDomainAxisRange()); 490 zoomX(plot, plot.getDomainAxis(), getXBounds(0), getDomainAxisRange());
491 491
492 Bounds valueAxisBounds = getValueAxisRange(); 492 Bounds valueAxisBounds = getValueAxisRange();
493 493
510 XYPlot plot, 510 XYPlot plot,
511 ValueAxis axis, 511 ValueAxis axis,
512 Bounds total,//we could equally nicely getXBounds(0) 512 Bounds total,//we could equally nicely getXBounds(0)
513 Bounds user 513 Bounds user
514 ) { 514 ) {
515 if (logger.isDebugEnabled()) { 515 if (log.isDebugEnabled()) {
516 logger.debug("== Zoom X axis =="); 516 log.debug("== Zoom X axis ==");
517 logger.debug(" Total axis range : " + total); 517 log.debug(" Total axis range : " + total);
518 logger.debug(" User defined range: " + user); 518 log.debug(" User defined range: " + user);
519 } 519 }
520 520
521 if (user != null) { 521 if (user != null) {
522 long min = total.getLower().longValue(); 522 long min = total.getLower().longValue();
523 long max = total.getUpper().longValue(); 523 long max = total.getUpper().longValue();
526 long newMin = Math.round(min + user.getLower().doubleValue() * diff); 526 long newMin = Math.round(min + user.getLower().doubleValue() * diff);
527 long newMax = Math.round(min + user.getUpper().doubleValue() * diff); 527 long newMax = Math.round(min + user.getUpper().doubleValue() * diff);
528 528
529 TimeBounds newBounds = new TimeBounds(newMin, newMax); 529 TimeBounds newBounds = new TimeBounds(newMin, newMax);
530 530
531 logger.debug(" Zoom axis to: " + newBounds); 531 log.debug(" Zoom axis to: " + newBounds);
532 532
533 newBounds.applyBounds(axis, AXIS_SPACE); 533 newBounds.applyBounds(axis, AXIS_SPACE);
534 } 534 }
535 else { 535 else {
536 logger.debug("No user specified zoom values found!"); 536 log.debug("No user specified zoom values found!");
537 if (total != null && axis != null) { 537 if (total != null && axis != null) {
538 total.applyBounds(axis, AXIS_SPACE); 538 total.applyBounds(axis, AXIS_SPACE);
539 } 539 }
540 } 540 }
541 } 541 }
548 XYPlot plot, 548 XYPlot plot,
549 ValueAxis axis, 549 ValueAxis axis,
550 Bounds total, 550 Bounds total,
551 Bounds user 551 Bounds user
552 ) { 552 ) {
553 if (logger.isDebugEnabled()) { 553 if (log.isDebugEnabled()) {
554 logger.debug("== Zoom Y axis =="); 554 log.debug("== Zoom Y axis ==");
555 logger.debug(" Total axis range : " + total); 555 log.debug(" Total axis range : " + total);
556 logger.debug(" User defined range: " + user); 556 log.debug(" User defined range: " + user);
557 } 557 }
558 558
559 if (user != null) { 559 if (user != null) {
560 double min = total.getLower().doubleValue(); 560 double min = total.getLower().doubleValue();
561 double max = total.getUpper().doubleValue(); 561 double max = total.getUpper().doubleValue();
564 double newMin = min + user.getLower().doubleValue() * diff; 564 double newMin = min + user.getLower().doubleValue() * diff;
565 double newMax = min + user.getUpper().doubleValue() * diff; 565 double newMax = min + user.getUpper().doubleValue() * diff;
566 566
567 DoubleBounds newBounds = new DoubleBounds(newMin, newMax); 567 DoubleBounds newBounds = new DoubleBounds(newMin, newMax);
568 568
569 logger.debug(" Zoom axis to: " + newBounds); 569 log.debug(" Zoom axis to: " + newBounds);
570 570
571 newBounds.applyBounds(axis, AXIS_SPACE); 571 newBounds.applyBounds(axis, AXIS_SPACE);
572 } 572 }
573 else { 573 else {
574 logger.debug("No user specified zoom values found!"); 574 log.debug("No user specified zoom values found!");
575 if (total != null && axis != null) { 575 if (total != null && axis != null) {
576 total.applyBounds(axis, AXIS_SPACE); 576 total.applyBounds(axis, AXIS_SPACE);
577 } 577 }
578 } 578 }
579 } 579 }
658 series.add(day, y, false); 658 series.add(day, y, false);
659 names.put(day, name); 659 names.put(day, name);
660 } 660 }
661 } 661 }
662 catch(JSONException ex) { 662 catch(JSONException ex) {
663 logger.error("Could not decode json"); 663 log.error("Could not decode json");
664 } 664 }
665 catch(ParseException ex) { 665 catch(ParseException ex) {
666 logger.error("Could not parse date string"); 666 log.error("Could not parse date string");
667 } 667 }
668 668
669 TimeSeriesCollection tsc = new TimeSeriesCollection(); 669 TimeSeriesCollection tsc = new TimeSeriesCollection();
670 tsc.addSeries(series); 670 tsc.addSeries(series);
671 // Add Annotations. 671 // Add Annotations.
672 for (int i = 0, S = series.getItemCount(); i < S; i++) { 672 for (int i = 0, S = series.getItemCount(); i < S; i++) {
673 double x = tsc.getXValue(0, i); 673 double x = tsc.getXValue(0, i);
674 double y = tsc.getYValue(0, i); 674 double y = tsc.getYValue(0, i);
675 xy.add(new CollisionFreeXYTextAnnotation( 675 xy.add(new CollisionFreeXYTextAnnotation(
676 names.get(series.getTimePeriod(i)), x, y)); 676 names.get(series.getTimePeriod(i)), x, y));
677 logger.debug("doPoints(): x=" + x + " y=" + y); 677 log.debug("doPoints(): x=" + x + " y=" + y);
678 } 678 }
679 RiverAnnotation annotations = 679 RiverAnnotation annotations =
680 new RiverAnnotation(null, null, null, theme); 680 new RiverAnnotation(null, null, null, theme);
681 annotations.setTextAnnotations(xy); 681 annotations.setTextAnnotations(xy);
682 682
685 685
686 addAxisDataset(tsc, axisIndex, visible); 686 addAxisDataset(tsc, axisIndex, visible);
687 } 687 }
688 688
689 public void addDomainAxisMarker(XYPlot plot) { 689 public void addDomainAxisMarker(XYPlot plot) {
690 logger.debug("domainmarkers: " + domainMarker.size()); 690 log.debug("domainmarkers: " + domainMarker.size());
691 for (Marker marker: domainMarker) { 691 for (Marker marker: domainMarker) {
692 logger.debug("adding domain marker"); 692 log.debug("adding domain marker");
693 plot.addDomainMarker(marker, Layer.BACKGROUND); 693 plot.addDomainMarker(marker, Layer.BACKGROUND);
694 } 694 }
695 domainMarker.clear(); 695 domainMarker.clear();
696 } 696 }
697 697
698 public void addValueAxisMarker(XYPlot plot) { 698 public void addValueAxisMarker(XYPlot plot) {
699 for (Marker marker: valueMarker) { 699 for (Marker marker: valueMarker) {
700 logger.debug("adding value marker.."); 700 log.debug("adding value marker..");
701 plot.addRangeMarker(marker, Layer.BACKGROUND); 701 plot.addRangeMarker(marker, Layer.BACKGROUND);
702 } 702 }
703 valueMarker.clear(); 703 valueMarker.clear();
704 } 704 }
705 705
761 legendItem.getLine(), 761 legendItem.getLine(),
762 legendItem.getLineStroke(), 762 legendItem.getLineStroke(),
763 legendItem.getLinePaint() 763 legendItem.getLinePaint()
764 ); 764 );
765 interLegend.setSeriesKey(series.getKey()); 765 interLegend.setSeriesKey(series.getKey());
766 logger.debug("applySeriesAttributes: draw unfilled legend item"); 766 log.debug("applySeriesAttributes: draw unfilled legend item");
767 plot.getLegendItems().add(interLegend); 767 plot.getLegendItems().add(interLegend);
768 } 768 }
769 } 769 }
770 } 770 }
771 771

http://dive4elements.wald.intevation.org