comparison artifacts/src/main/java/org/dive4elements/river/exports/XYChartGenerator.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 8ca2c711a632
children bbf6cf555e89
comparison
equal deleted inserted replaced
8201:4b8c5a08de04 8202:e4606eae8ea5
72 @Override 72 @Override
73 protected abstract YAxisWalker getYAxisWalker(); 73 protected abstract YAxisWalker getYAxisWalker();
74 74
75 public static final int AXIS_SPACE = 5; 75 public static final int AXIS_SPACE = 5;
76 76
77 /** The logger that is used in this generator. */ 77 /** The log that is used in this generator. */
78 private static Logger logger = Logger.getLogger(XYChartGenerator.class); 78 private static Logger log = Logger.getLogger(XYChartGenerator.class);
79 79
80 protected List<Marker> domainMarkers = new ArrayList<Marker>(); 80 protected List<Marker> domainMarkers = new ArrayList<Marker>();
81 81
82 protected List<Marker> valueMarkers = new ArrayList<Marker>(); 82 protected List<Marker> valueMarkers = new ArrayList<Marker>();
83 83
101 /** 101 /**
102 * Generate the chart anew (including localized axis and all). 102 * Generate the chart anew (including localized axis and all).
103 */ 103 */
104 @Override 104 @Override
105 public JFreeChart generateChart() { 105 public JFreeChart generateChart() {
106 logger.debug("XYChartGenerator.generateChart"); 106 log.debug("XYChartGenerator.generateChart");
107 107
108 JFreeChart chart = ChartFactory.createXYLineChart( 108 JFreeChart chart = ChartFactory.createXYLineChart(
109 getChartTitle(), 109 getChartTitle(),
110 getXAxisLabel(), 110 getXAxisLabel(),
111 getYAxisLabel(0), 111 getYAxisLabel(0),
184 184
185 /** Add a logo as background annotation to plot. */ 185 /** Add a logo as background annotation to plot. */
186 protected void addLogo(XYPlot plot) { 186 protected void addLogo(XYPlot plot) {
187 String logo = showLogo(); 187 String logo = showLogo();
188 if (logo == null) { 188 if (logo == null) {
189 logger.debug("No logo to show chosen"); 189 log.debug("No logo to show chosen");
190 return; 190 return;
191 } 191 }
192 192
193 ImageIcon imageIcon = null; 193 ImageIcon imageIcon = null;
194 if (logo.equals("none")) { 194 if (logo.equals("none")) {
230 } 230 }
231 else if (placev.equals("center")) { 231 else if (placev.equals("center")) {
232 yPos = ((Double)getYBounds(0).getUpper() + (Double)getYBounds(0).getLower())/2d; 232 yPos = ((Double)getYBounds(0).getUpper() + (Double)getYBounds(0).getLower())/2d;
233 } 233 }
234 else { 234 else {
235 logger.debug("Unknown place-v value: " + placev); 235 log.debug("Unknown place-v value: " + placev);
236 } 236 }
237 237
238 if (placeh == null || placeh.equals("none")) { 238 if (placeh == null || placeh.equals("none")) {
239 placeh = "center"; 239 placeh = "center";
240 } 240 }
246 } 246 }
247 else if (placeh.equals("center")) { 247 else if (placeh.equals("center")) {
248 xPos = ((Double)getXBounds(0).getUpper() + (Double)getXBounds(0).getLower())/2d; 248 xPos = ((Double)getXBounds(0).getUpper() + (Double)getXBounds(0).getLower())/2d;
249 } 249 }
250 else { 250 else {
251 logger.debug("Unknown place-h value: " + placeh); 251 log.debug("Unknown place-h value: " + placeh);
252 } 252 }
253 253
254 logger.debug("logo position: " + xPos + "/" + yPos); 254 log.debug("logo position: " + xPos + "/" + yPos);
255 255
256 org.jfree.ui.RectangleAnchor anchor 256 org.jfree.ui.RectangleAnchor anchor
257 = org.jfree.ui.RectangleAnchor.TOP; 257 = org.jfree.ui.RectangleAnchor.TOP;
258 if (placev.equals("top")) { 258 if (placev.equals("top")) {
259 if (placeh.equals("left")) { 259 if (placeh.equals("left")) {
306 } 306 }
307 307
308 308
309 @Override 309 @Override
310 protected AxisDataset createAxisDataset(int idx) { 310 protected AxisDataset createAxisDataset(int idx) {
311 logger.debug("Create new AxisDataset for index: " + idx); 311 log.debug("Create new AxisDataset for index: " + idx);
312 return new AxisDataset(idx); 312 return new AxisDataset(idx);
313 } 313 }
314 314
315 315
316 /** 316 /**
317 * Put debug output about datasets. 317 * Put debug output about datasets.
318 */ 318 */
319 public void debugDatasets(XYPlot plot) { 319 public void debugDatasets(XYPlot plot) {
320 logger.debug("Number of datasets: " + plot.getDatasetCount()); 320 log.debug("Number of datasets: " + plot.getDatasetCount());
321 for (int i = 0, P = plot.getDatasetCount(); i < P; i++) { 321 for (int i = 0, P = plot.getDatasetCount(); i < P; i++) {
322 if (plot.getDataset(i) == null) { 322 if (plot.getDataset(i) == null) {
323 logger.debug("Dataset #" + i + " is null"); 323 log.debug("Dataset #" + i + " is null");
324 continue; 324 continue;
325 } 325 }
326 logger.debug("Dataset #" + i + ":" + plot.getDataset(i)); 326 log.debug("Dataset #" + i + ":" + plot.getDataset(i));
327 XYSeriesCollection series = (XYSeriesCollection) plot.getDataset(i); 327 XYSeriesCollection series = (XYSeriesCollection) plot.getDataset(i);
328 logger.debug("X-Extend of Dataset: " + series.getSeries(0).getMinX() 328 log.debug("X-Extend of Dataset: " + series.getSeries(0).getMinX()
329 + " " + series.getSeries(0).getMaxX()); 329 + " " + series.getSeries(0).getMaxX());
330 logger.debug("Y-Extend of Dataset: " + series.getSeries(0).getMinY() 330 log.debug("Y-Extend of Dataset: " + series.getSeries(0).getMinY()
331 + " " + series.getSeries(0).getMaxY()); 331 + " " + series.getSeries(0).getMaxY());
332 } 332 }
333 } 333 }
334 334
335 335
336 /** 336 /**
337 * Put debug output about axes. 337 * Put debug output about axes.
338 */ 338 */
339 public void debugAxis(XYPlot plot) { 339 public void debugAxis(XYPlot plot) {
340 logger.debug("..............."); 340 log.debug("...............");
341 for (int i = 0, P = plot.getRangeAxisCount(); i < P; i++) { 341 for (int i = 0, P = plot.getRangeAxisCount(); i < P; i++) {
342 if (plot.getRangeAxis(i) == null) 342 if (plot.getRangeAxis(i) == null)
343 logger.debug("Range-Axis #" + i + " == null"); 343 log.debug("Range-Axis #" + i + " == null");
344 else { 344 else {
345 logger.debug("Range-Axis " + i + " != null [" + 345 log.debug("Range-Axis " + i + " != null [" +
346 plot.getRangeAxis(i).getRange().getLowerBound() + 346 plot.getRangeAxis(i).getRange().getLowerBound() +
347 " " + plot.getRangeAxis(i).getRange().getUpperBound() + 347 " " + plot.getRangeAxis(i).getRange().getUpperBound() +
348 "]"); 348 "]");
349 } 349 }
350 } 350 }
351 for (int i = 0, P = plot.getDomainAxisCount(); i < P; i++) { 351 for (int i = 0, P = plot.getDomainAxisCount(); i < P; i++) {
352 if (plot.getDomainAxis(i) == null) 352 if (plot.getDomainAxis(i) == null)
353 logger.debug("Domain-Axis #" + i + " == null"); 353 log.debug("Domain-Axis #" + i + " == null");
354 else { 354 else {
355 logger.debug("Domain-Axis " + i + " != null [" + 355 log.debug("Domain-Axis " + i + " != null [" +
356 plot.getDomainAxis(i).getRange().getLowerBound() + 356 plot.getDomainAxis(i).getRange().getLowerBound() +
357 " " + plot.getDomainAxis(i).getRange().getUpperBound() + 357 " " + plot.getDomainAxis(i).getRange().getUpperBound() +
358 "]"); 358 "]");
359 } 359 }
360 } 360 }
361 logger.debug("..............."); 361 log.debug("...............");
362 } 362 }
363 363
364 364
365 /** 365 /**
366 * Registers an area to be drawn. 366 * Registers an area to be drawn.
368 * @param index 'axis index' 368 * @param index 'axis index'
369 * @param visible Whether or not to be visible (important for range calculations). 369 * @param visible Whether or not to be visible (important for range calculations).
370 */ 370 */
371 public void addAreaSeries(StyledAreaSeriesCollection area, int index, boolean visible) { 371 public void addAreaSeries(StyledAreaSeriesCollection area, int index, boolean visible) {
372 if (area == null) { 372 if (area == null) {
373 logger.warn("Cannot yet render above/under curve."); 373 log.warn("Cannot yet render above/under curve.");
374 return; 374 return;
375 } 375 }
376 376
377 AxisDataset axisDataset = (AxisDataset) getAxisDataset(index); 377 AxisDataset axisDataset = (AxisDataset) getAxisDataset(index);
378 378
396 public void addAxisSeries(XYSeries series, int index, boolean visible) { 396 public void addAxisSeries(XYSeries series, int index, boolean visible) {
397 if (series == null) { 397 if (series == null) {
398 return; 398 return;
399 } 399 }
400 400
401 logger.debug("Y Range of XYSeries: " + 401 log.debug("Y Range of XYSeries: " +
402 series.getMinY() + " | " + series.getMaxY()); 402 series.getMinY() + " | " + series.getMaxY());
403 403
404 addAxisDataset(new XYSeriesCollection(series), index, visible); 404 addAxisDataset(new XYSeriesCollection(series), index, visible);
405 405
406 } 406 }
465 * @param index index of axis to be merged. 465 * @param index index of axis to be merged.
466 */ 466 */
467 @Override 467 @Override
468 protected void combineXBounds(Bounds bounds, int index) { 468 protected void combineXBounds(Bounds bounds, int index) {
469 if (!(bounds instanceof DoubleBounds)) { 469 if (!(bounds instanceof DoubleBounds)) {
470 logger.warn("Unsupported Bounds type: " + bounds.getClass()); 470 log.warn("Unsupported Bounds type: " + bounds.getClass());
471 return; 471 return;
472 } 472 }
473 473
474 DoubleBounds dBounds = (DoubleBounds) bounds; 474 DoubleBounds dBounds = (DoubleBounds) bounds;
475 475
490 490
491 491
492 @Override 492 @Override
493 protected void combineYBounds(Bounds bounds, int index) { 493 protected void combineYBounds(Bounds bounds, int index) {
494 if (!(bounds instanceof DoubleBounds)) { 494 if (!(bounds instanceof DoubleBounds)) {
495 logger.warn("Unsupported Bounds type: " + bounds.getClass()); 495 log.warn("Unsupported Bounds type: " + bounds.getClass());
496 return; 496 return;
497 } 497 }
498 498
499 DoubleBounds dBounds = (DoubleBounds) bounds; 499 DoubleBounds dBounds = (DoubleBounds) bounds;
500 500
517 /** 517 /**
518 * If no data is visible, draw at least empty axis. 518 * If no data is visible, draw at least empty axis.
519 */ 519 */
520 private void recoverEmptyPlot(XYPlot plot) { 520 private void recoverEmptyPlot(XYPlot plot) {
521 if (plot.getRangeAxis() == null) { 521 if (plot.getRangeAxis() == null) {
522 logger.debug("debug: No range axis"); 522 log.debug("debug: No range axis");
523 plot.setRangeAxis(createYAxis(0)); 523 plot.setRangeAxis(createYAxis(0));
524 } 524 }
525 } 525 }
526 526
527 527
534 Integer key = Integer.valueOf(i); 534 Integer key = Integer.valueOf(i);
535 Bounds b = getXBounds(key); 535 Bounds b = getXBounds(key);
536 536
537 537
538 if (b != null && b.getLower().equals(b.getUpper())) { 538 if (b != null && b.getLower().equals(b.getUpper())) {
539 logger.debug("Check whether to expand a x axis.i ("+b.getLower() + "-" + b.getUpper()+")"); 539 log.debug("Check whether to expand a x axis.i ("+b.getLower() + "-" + b.getUpper()+")");
540 setXBounds(key, ChartHelper.expandBounds(b, 5)); 540 setXBounds(key, ChartHelper.expandBounds(b, 5));
541 } 541 }
542 } 542 }
543 } 543 }
544 544
551 * right of the data area. 551 * right of the data area.
552 * 552 *
553 * @param plot The XYPlot. 553 * @param plot The XYPlot.
554 */ 554 */
555 protected void autoZoom(XYPlot plot) { 555 protected void autoZoom(XYPlot plot) {
556 logger.debug("Zoom to specified ranges."); 556 log.debug("Zoom to specified ranges.");
557 557
558 Range xrange = getDomainAxisRange(); 558 Range xrange = getDomainAxisRange();
559 Range yrange = getValueAxisRange(); 559 Range yrange = getValueAxisRange();
560 560
561 ValueAxis xAxis = plot.getDomainAxis(); 561 ValueAxis xAxis = plot.getDomainAxis();
580 continue; 580 continue;
581 } 581 }
582 } 582 }
583 583
584 if (yaxis == null) { 584 if (yaxis == null) {
585 logger.debug("Zoom problem: no Y Axis for index: " + i); 585 log.debug("Zoom problem: no Y Axis for index: " + i);
586 continue; 586 continue;
587 } 587 }
588 588
589 logger.debug("Prepare zoom settings for y axis at index: " + i); 589 log.debug("Prepare zoom settings for y axis at index: " + i);
590 zoomY(plot, yaxis, getYBounds(Integer.valueOf(i)), yrange); 590 zoomY(plot, yaxis, getYBounds(Integer.valueOf(i)), yrange);
591 } 591 }
592 } 592 }
593 593
594 594
595 protected Range getDomainAxisRange() { 595 protected Range getDomainAxisRange() {
596 String[] ranges = getDomainAxisRangeFromRequest(); 596 String[] ranges = getDomainAxisRangeFromRequest();
597 597
598 if (ranges == null || ranges.length < 2) { 598 if (ranges == null || ranges.length < 2) {
599 logger.debug("No zoom range for domain axis specified."); 599 log.debug("No zoom range for domain axis specified.");
600 return null; 600 return null;
601 } 601 }
602 602
603 if (ranges[0].length() > 0 && ranges[1].length() > 0) { 603 if (ranges[0].length() > 0 && ranges[1].length() > 0) {
604 try { 604 try {
605 double from = Double.parseDouble(ranges[0]); 605 double from = Double.parseDouble(ranges[0]);
606 double to = Double.parseDouble(ranges[1]); 606 double to = Double.parseDouble(ranges[1]);
607 607
608 if (from == 0 && to == 0) { 608 if (from == 0 && to == 0) {
609 logger.debug("No range specified. Lower and upper X == 0"); 609 log.debug("No range specified. Lower and upper X == 0");
610 return null; 610 return null;
611 } 611 }
612 612
613 if (from > to) { 613 if (from > to) {
614 double tmp = to; 614 double tmp = to;
617 } 617 }
618 618
619 return new Range(from, to); 619 return new Range(from, to);
620 } 620 }
621 catch (NumberFormatException nfe) { 621 catch (NumberFormatException nfe) {
622 logger.warn("Wrong values for domain axis range."); 622 log.warn("Wrong values for domain axis range.");
623 } 623 }
624 } 624 }
625 625
626 return null; 626 return null;
627 } 627 }
629 629
630 protected Range getValueAxisRange() { 630 protected Range getValueAxisRange() {
631 String[] ranges = getValueAxisRangeFromRequest(); 631 String[] ranges = getValueAxisRangeFromRequest();
632 632
633 if (ranges == null || ranges.length < 2) { 633 if (ranges == null || ranges.length < 2) {
634 logger.debug("No range specified. Lower and upper Y == 0"); 634 log.debug("No range specified. Lower and upper Y == 0");
635 return null; 635 return null;
636 } 636 }
637 637
638 if (ranges[0].length() > 0 && ranges[1].length() > 0) { 638 if (ranges[0].length() > 0 && ranges[1].length() > 0) {
639 try { 639 try {
640 double from = Double.parseDouble(ranges[0]); 640 double from = Double.parseDouble(ranges[0]);
641 double to = Double.parseDouble(ranges[1]); 641 double to = Double.parseDouble(ranges[1]);
642 642
643 if (from == 0 && to == 0) { 643 if (from == 0 && to == 0) {
644 logger.debug("No range specified. Lower and upper Y == 0"); 644 log.debug("No range specified. Lower and upper Y == 0");
645 return null; 645 return null;
646 } 646 }
647 647
648 return from > to 648 return from > to
649 ? new Range(to, from) 649 ? new Range(to, from)
650 : new Range(from, to); 650 : new Range(from, to);
651 } 651 }
652 catch (NumberFormatException nfe) { 652 catch (NumberFormatException nfe) {
653 logger.warn("Wrong values for value axis range."); 653 log.warn("Wrong values for value axis range.");
654 } 654 }
655 } 655 }
656 656
657 return null; 657 return null;
658 } 658 }
686 686
687 if (x != null) { 687 if (x != null) {
688 Bounds computed = calculateZoom(bounds, x); 688 Bounds computed = calculateZoom(bounds, x);
689 computed.applyBounds(axis, AXIS_SPACE); 689 computed.applyBounds(axis, AXIS_SPACE);
690 690
691 logger.debug("Zoom axis to: " + computed); 691 log.debug("Zoom axis to: " + computed);
692 692
693 return true; 693 return true;
694 } 694 }
695 695
696 bounds.applyBounds(axis, AXIS_SPACE); 696 bounds.applyBounds(axis, AXIS_SPACE);
706 */ 706 */
707 protected Bounds calculateZoom(Bounds bounds, Range range) { 707 protected Bounds calculateZoom(Bounds bounds, Range range) {
708 double min = bounds.getLower().doubleValue(); 708 double min = bounds.getLower().doubleValue();
709 double max = bounds.getUpper().doubleValue(); 709 double max = bounds.getUpper().doubleValue();
710 710
711 if (logger.isDebugEnabled()) { 711 if (log.isDebugEnabled()) {
712 logger.debug("Minimum is: " + min); 712 log.debug("Minimum is: " + min);
713 logger.debug("Maximum is: " + max); 713 log.debug("Maximum is: " + max);
714 logger.debug("Lower zoom is: " + range.getLowerBound()); 714 log.debug("Lower zoom is: " + range.getLowerBound());
715 logger.debug("Upper zoom is: " + range.getUpperBound()); 715 log.debug("Upper zoom is: " + range.getUpperBound());
716 } 716 }
717 717
718 double diff = max > min ? max - min : min - max; 718 double diff = max > min ? max - min : min - max;
719 719
720 DoubleBounds computed = new DoubleBounds( 720 DoubleBounds computed = new DoubleBounds(
731 * 731 *
732 * @return a Range[] as follows: [x-Range, y-Range]. 732 * @return a Range[] as follows: [x-Range, y-Range].
733 */ 733 */
734 @Override 734 @Override
735 public Range[] getRangesForAxis(int index) { 735 public Range[] getRangesForAxis(int index) {
736 logger.debug("getRangesForAxis " + index); 736 log.debug("getRangesForAxis " + index);
737 737
738 Bounds rx = getXBounds(Integer.valueOf(0)); 738 Bounds rx = getXBounds(Integer.valueOf(0));
739 Bounds ry = getYBounds(Integer.valueOf(index)); 739 Bounds ry = getYBounds(Integer.valueOf(index));
740 740
741 if (rx == null) { 741 if (rx == null) {
742 logger.warn("Range for x axis not set." + 742 log.warn("Range for x axis not set." +
743 " Using default values: 0 - 1."); 743 " Using default values: 0 - 1.");
744 rx = new DoubleBounds(0, 1); 744 rx = new DoubleBounds(0, 1);
745 } 745 }
746 if (ry == null) { 746 if (ry == null) {
747 logger.warn("Range for y" + index + 747 log.warn("Range for y" + index +
748 " axis not set. Using default values: 0 - 1."); 748 " axis not set. Using default values: 0 - 1.");
749 ry = new DoubleBounds(0, 1); 749 ry = new DoubleBounds(0, 1);
750 } 750 }
751 751
752 return new Range[] { 752 return new Range[] {
828 828
829 if (axis != null) { 829 if (axis != null) {
830 localizeDomainAxis(axis); 830 localizeDomainAxis(axis);
831 } 831 }
832 else { 832 else {
833 logger.warn("Domain axis at " + i + " is null."); 833 log.warn("Domain axis at " + i + " is null.");
834 } 834 }
835 } 835 }
836 836
837 for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) { 837 for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) {
838 ValueAxis axis = plot.getRangeAxis(i); 838 ValueAxis axis = plot.getRangeAxis(i);
839 839
840 if (axis != null) { 840 if (axis != null) {
841 localizeRangeAxis(axis); 841 localizeRangeAxis(axis);
842 } 842 }
843 else { 843 else {
844 logger.warn("Range axis at " + i + " is null."); 844 log.warn("Range axis at " + i + " is null.");
845 } 845 }
846 } 846 }
847 } 847 }
848 848
849 849
896 String name = array.getString(2); 896 String name = array.getString(2);
897 boolean act = array.getBoolean(3); 897 boolean act = array.getBoolean(3);
898 if (!act) { 898 if (!act) {
899 continue; 899 continue;
900 } 900 }
901 //logger.debug(" x " + x + " y " + y ); 901 //log.debug(" x " + x + " y " + y );
902 series.add(x, y, false); 902 series.add(x, y, false);
903 xy.add(new CollisionFreeXYTextAnnotation(name, x, y)); 903 xy.add(new CollisionFreeXYTextAnnotation(name, x, y));
904 } 904 }
905 } 905 }
906 catch(JSONException e){ 906 catch(JSONException e){
907 logger.error("Could not decode json."); 907 log.error("Could not decode json.");
908 } 908 }
909 909
910 RiverAnnotation annotations = new RiverAnnotation(null, null, null, theme); 910 RiverAnnotation annotations = new RiverAnnotation(null, null, null, theme);
911 annotations.setTextAnnotations(xy); 911 annotations.setTextAnnotations(xy);
912 912

http://dive4elements.wald.intevation.org