comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java @ 2107:51b9899f819d

StableXYDifferenceRenderer: Replaced System.err.println()s with proper logging. flys-artifacts/trunk@3665 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 12 Jan 2012 16:01:01 +0000
parents fd95bfbb2ec2
children b5cc53a84b66
comparison
equal deleted inserted replaced
2106:d7176cef0aa0 2107:51b9899f819d
119 119
120 import gnu.trove.TDoubleArrayList; 120 import gnu.trove.TDoubleArrayList;
121 121
122 import de.intevation.flys.artifacts.math.Linear; 122 import de.intevation.flys.artifacts.math.Linear;
123 123
124 import org.apache.log4j.Logger;
125
124 /** 126 /**
125 * A renderer for an {@link XYPlot} that highlights the differences between two 127 * A renderer for an {@link XYPlot} that highlights the differences between two
126 * series. The example shown here is generated by the 128 * series. The example shown here is generated by the
127 * <code>DifferenceChartDemo1.java</code> program included in the JFreeChart 129 * <code>DifferenceChartDemo1.java</code> program included in the JFreeChart
128 * demo collection: 130 * demo collection:
130 * <img src="../../../../../images/StableXYDifferenceRendererSample.png" 132 * <img src="../../../../../images/StableXYDifferenceRendererSample.png"
131 * alt="StableXYDifferenceRendererSample.png" /> 133 * alt="StableXYDifferenceRendererSample.png" />
132 */ 134 */
133 public class StableXYDifferenceRenderer extends AbstractXYItemRenderer 135 public class StableXYDifferenceRenderer extends AbstractXYItemRenderer
134 implements XYItemRenderer, PublicCloneable { 136 implements XYItemRenderer, PublicCloneable {
137
138 private static Logger log = Logger.getLogger(StableXYDifferenceRenderer.class);
135 139
136 /** For serialization. */ 140 /** For serialization. */
137 private static final long serialVersionUID = -8447915602375584857L; 141 private static final long serialVersionUID = -8447915602375584857L;
138 142
139 /** The paint used to highlight positive differences (y(0) > y(1)). */ 143 /** The paint used to highlight positive differences (y(0) > y(1)). */
485 int N = xs.size(); 489 int N = xs.size();
486 if (N == 0 || xs.getQuick(N-1) < x) { 490 if (N == 0 || xs.getQuick(N-1) < x) {
487 xs.add(x); 491 xs.add(x);
488 return true; 492 return true;
489 } 493 }
490 System.err.println("pushed smaller"); 494 log.debug("pushed smaller");
491 return false; 495 return false;
492 } 496 }
493 497
494 protected static List<XYDataset> splitByNaNsTwoSeries( 498 protected static List<XYDataset> splitByNaNsTwoSeries(
495 XYDataset dataset 499 XYDataset dataset
496 ) { 500 ) {
501 boolean debug = log.isDebugEnabled();
502
497 List<XYDataset> datasets = new ArrayList<XYDataset>(); 503 List<XYDataset> datasets = new ArrayList<XYDataset>();
498 504
499 int N = dataset.getItemCount(0); 505 int N = dataset.getItemCount(0);
500 int M = dataset.getItemCount(1); 506 int M = dataset.getItemCount(1);
501 507
530 int nj = j+1; 536 int nj = j+1;
531 for (; nj < M && !Double.isNaN(dataset.getXValue(1, nj)); ++nj); 537 for (; nj < M && !Double.isNaN(dataset.getXValue(1, nj)); ++nj);
532 for (; nj < M && Double.isNaN(dataset.getXValue(1, nj)); ++nj); 538 for (; nj < M && Double.isNaN(dataset.getXValue(1, nj)); ++nj);
533 539
534 if (ni == N && nj == M) { // no more splits 540 if (ni == N && nj == M) { // no more splits
535 System.err.println("no more splits ...."); 541 log.debug("no more splits ....");
536 for (; i < ni; ++i) { 542 for (; i < ni; ++i) {
537 double x = dataset.getXValue(0, i); 543 double x = dataset.getXValue(0, i);
538 double y = dataset.getYValue(0, i); 544 double y = dataset.getYValue(0, i);
539 if (!Double.isNaN(x) 545 if (!Double.isNaN(x)
540 && !Double.isNaN(y) 546 && !Double.isNaN(y)
558 datasets.add(ds); 564 datasets.add(ds);
559 } 565 }
560 break; 566 break;
561 } 567 }
562 568
563 System.err.println("ni: " + ni + " " + N); 569 if (debug) {
564 System.err.println("nj: " + nj + " " + M); 570 log.debug("ni: " + ni + " " + N);
571 log.debug("nj: " + nj + " " + M);
572 }
565 573
566 double xni = ni < N 574 double xni = ni < N
567 ? dataset.getXValue(0, ni) 575 ? dataset.getXValue(0, ni)
568 : Double.MAX_VALUE; 576 : Double.MAX_VALUE;
569 577
595 siy.add(y); 603 siy.add(y);
596 } 604 }
597 pushxi = x; pushyi = y; 605 pushxi = x; pushyi = y;
598 } 606 }
599 else { // x > xns: intersection 607 else { // x > xns: intersection
600 System.err.println("xns: " + xns); 608 if (debug) {
601 System.err.println("x/y: " + x + " / " + y); 609 log.debug("xns: " + xns);
610 log.debug("x/y: " + x + " / " + y);
611 }
602 int SIX = six.size(); 612 int SIX = six.size();
603 if (SIX > 0) { // should always be true 613 if (SIX > 0) { // should always be true
604 double yns = Linear.linear( 614 double yns = Linear.linear(
605 xns, 615 xns,
606 six.getQuick(SIX-1), x, 616 six.getQuick(SIX-1), x,
607 siy.getQuick(SIX-1), y); 617 siy.getQuick(SIX-1), y);
608 System.err.println("intersection at: " + yns); 618 if (debug) {
619 log.debug("intersection at: " + yns);
620 }
609 if (add(six, xns)) { 621 if (add(six, xns)) {
610 siy.add(yns); 622 siy.add(yns);
611 } 623 }
612 pushxi = xns; 624 pushxi = xns;
613 pushyi = yns; 625 pushyi = yns;
639 if (SJX > 0) { // should always be true 651 if (SJX > 0) { // should always be true
640 double yns = Linear.linear( 652 double yns = Linear.linear(
641 xns, 653 xns,
642 sjx.getQuick(SJX-1), x, 654 sjx.getQuick(SJX-1), x,
643 sjy.getQuick(SJX-1), y); 655 sjy.getQuick(SJX-1), y);
644 System.err.println("intersection at: " + yns); 656 if (debug) {
657 log.debug("intersection at: " + yns);
658 }
645 if (add(sjx, xns)) { 659 if (add(sjx, xns)) {
646 sjy.add(yns); 660 sjy.add(yns);
647 } 661 }
648 pushxj = xns; pushyj = yns; 662 pushxj = xns; pushyj = yns;
649 } 663 }
700 addSeries(ds, dataset.getSeriesKey(0), six, siy); 714 addSeries(ds, dataset.getSeriesKey(0), six, siy);
701 addSeries(ds, dataset.getSeriesKey(1), sjx, sjy); 715 addSeries(ds, dataset.getSeriesKey(1), sjx, sjy);
702 datasets.add(ds); 716 datasets.add(ds);
703 } 717 }
704 718
705 System.err.println("datasets after split: " + datasets.size()); 719 if (debug) {
720 log.debug("datasets after split: " + datasets.size());
721 }
706 722
707 return datasets; 723 return datasets;
708 } 724 }
709 725
710 public static List<XYDataset> splitByNaNs(XYDataset dataset) { 726 public static List<XYDataset> splitByNaNs(XYDataset dataset) {

http://dive4elements.wald.intevation.org