comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java @ 1824:982956bde69e

Added a dataset to zero mapper to circumvent shortcommings in XYDifferenceRenderer. flys-artifacts/trunk@3153 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 03 Nov 2011 12:28:38 +0000
parents 7a11b37d8594
children 0e9c0b49b4ef
comparison
equal deleted inserted replaced
1823:7a11b37d8594 1824:982956bde69e
71 * 18-May-2007 : Set dataset and seriesKey for LegendItem (DG); 71 * 18-May-2007 : Set dataset and seriesKey for LegendItem (DG);
72 * 05-Nov-2007 : Draw item labels if visible (RW); 72 * 05-Nov-2007 : Draw item labels if visible (RW);
73 * 17-Jun-2008 : Apply legend shape, font and paint attributes (DG); 73 * 17-Jun-2008 : Apply legend shape, font and paint attributes (DG);
74 * 74 *
75 */ 75 */
76 76 package de.intevation.flys.jfree;
77 package org.jfree.chart.renderer.xy;
78 77
79 import java.awt.Color; 78 import java.awt.Color;
80 import java.awt.Graphics2D; 79 import java.awt.Graphics2D;
81 import java.awt.Paint; 80 import java.awt.Paint;
82 import java.awt.Shape; 81 import java.awt.Shape;
87 import java.io.IOException; 86 import java.io.IOException;
88 import java.io.ObjectInputStream; 87 import java.io.ObjectInputStream;
89 import java.io.ObjectOutputStream; 88 import java.io.ObjectOutputStream;
90 import java.util.Collections; 89 import java.util.Collections;
91 import java.util.LinkedList; 90 import java.util.LinkedList;
91 import java.util.Iterator;
92 92
93 import org.jfree.chart.LegendItem; 93 import org.jfree.chart.LegendItem;
94 import org.jfree.chart.axis.ValueAxis; 94 import org.jfree.chart.axis.ValueAxis;
95 import org.jfree.chart.entity.EntityCollection; 95 import org.jfree.chart.entity.EntityCollection;
96 import org.jfree.chart.entity.XYItemEntity; 96 import org.jfree.chart.entity.XYItemEntity;
106 import org.jfree.ui.RectangleEdge; 106 import org.jfree.ui.RectangleEdge;
107 import org.jfree.util.PaintUtilities; 107 import org.jfree.util.PaintUtilities;
108 import org.jfree.util.PublicCloneable; 108 import org.jfree.util.PublicCloneable;
109 import org.jfree.util.ShapeUtilities; 109 import org.jfree.util.ShapeUtilities;
110 110
111 import org.jfree.chart.renderer.xy.AbstractXYItemRenderer;
112 import org.jfree.chart.renderer.xy.XYItemRenderer;
113 import org.jfree.chart.renderer.xy.XYItemRendererState;
114
111 /** 115 /**
112 * A renderer for an {@link XYPlot} that highlights the differences between two 116 * A renderer for an {@link XYPlot} that highlights the differences between two
113 * series. The example shown here is generated by the 117 * series. The example shown here is generated by the
114 * <code>DifferenceChartDemo1.java</code> program included in the JFreeChart 118 * <code>DifferenceChartDemo1.java</code> program included in the JFreeChart
115 * demo collection: 119 * demo collection:
133 private boolean shapesVisible; 137 private boolean shapesVisible;
134 138
135 /** The shape to display in the legend item. */ 139 /** The shape to display in the legend item. */
136 private transient Shape legendLine; 140 private transient Shape legendLine;
137 141
142 private XYDatasetToZeroMapper mapper;
143
138 /** 144 /**
139 * This flag controls whether or not the x-coordinates (in Java2D space) 145 * This flag controls whether or not the x-coordinates (in Java2D space)
140 * are rounded to integers. When set to true, this can avoid the vertical 146 * are rounded to integers. When set to true, this can avoid the vertical
141 * striping that anti-aliasing can generate. However, the rounding may not 147 * striping that anti-aliasing can generate. However, the rounding may not
142 * be appropriate for output in high resolution formats (for example, 148 * be appropriate for output in high resolution formats (for example,
148 154
149 /** 155 /**
150 * Creates a new renderer with default attributes. 156 * Creates a new renderer with default attributes.
151 */ 157 */
152 public StableXYDifferenceRenderer() { 158 public StableXYDifferenceRenderer() {
153 this(Color.green, Color.red, false); 159 this(Color.green, Color.red, false, null);
154 } 160 }
155 161
156 /** 162 /**
157 * Creates a new renderer. 163 * Creates a new renderer.
158 * 164 *
161 * @param negativePaint the highlight color for negative differences 167 * @param negativePaint the highlight color for negative differences
162 * (<code>null</code> not permitted). 168 * (<code>null</code> not permitted).
163 * @param shapes draw shapes? 169 * @param shapes draw shapes?
164 */ 170 */
165 public StableXYDifferenceRenderer(Paint positivePaint, Paint negativePaint, 171 public StableXYDifferenceRenderer(Paint positivePaint, Paint negativePaint,
166 boolean shapes) { 172 boolean shapes,
173 XYDatasetToZeroMapper mapper) {
167 if (positivePaint == null) { 174 if (positivePaint == null) {
168 throw new IllegalArgumentException( 175 throw new IllegalArgumentException(
169 "Null 'positivePaint' argument."); 176 "Null 'positivePaint' argument.");
170 } 177 }
171 if (negativePaint == null) { 178 if (negativePaint == null) {
175 this.positivePaint = positivePaint; 182 this.positivePaint = positivePaint;
176 this.negativePaint = negativePaint; 183 this.negativePaint = negativePaint;
177 this.shapesVisible = shapes; 184 this.shapesVisible = shapes;
178 this.legendLine = new Line2D.Double(-7.0, 0.0, 7.0, 0.0); 185 this.legendLine = new Line2D.Double(-7.0, 0.0, 7.0, 0.0);
179 this.roundXCoordinates = false; 186 this.roundXCoordinates = false;
187 this.mapper = mapper;
180 } 188 }
181 189
182 /** 190 /**
183 * Returns the paint used to highlight positive differences. 191 * Returns the paint used to highlight positive differences.
184 * 192 *
383 int series, 391 int series,
384 int item, 392 int item,
385 CrosshairState crosshairState, 393 CrosshairState crosshairState,
386 int pass) { 394 int pass) {
387 395
388 if (pass == 0) { 396 if (mapper == null) {
389 drawItemPass0(g2, dataArea, info, plot, domainAxis, rangeAxis, 397 switch (pass) {
390 dataset, series, item, crosshairState); 398 case 0:
391 } 399 drawItemPass0(g2, dataArea, info,
392 else if (pass == 1) { 400 plot, domainAxis, rangeAxis,
393 drawItemPass1(g2, dataArea, info, plot, domainAxis, rangeAxis, 401 dataset, series, item, crosshairState);
394 dataset, series, item, crosshairState); 402 break;
403 case 1:
404 drawItemPass1(g2, dataArea, info,
405 plot, domainAxis, rangeAxis,
406 dataset, series, item, crosshairState);
407 }
408 }
409 else {
410 for (Iterator<XYDataset> iter = mapper.iterator(dataset);
411 iter.hasNext();
412 ) {
413 switch (pass) {
414 case 0:
415 drawItemPass0(g2, dataArea, info,
416 plot, domainAxis, rangeAxis,
417 dataset, series, item, crosshairState);
418 break;
419 case 1:
420 drawItemPass1(g2, dataArea, info,
421 plot, domainAxis, rangeAxis,
422 dataset, series, item, crosshairState);
423 }
424 } // for all segments
395 } 425 }
396 426
397 } 427 }
398 428
399 /** 429 /**
1237 this.positivePaint = SerialUtilities.readPaint(stream); 1267 this.positivePaint = SerialUtilities.readPaint(stream);
1238 this.negativePaint = SerialUtilities.readPaint(stream); 1268 this.negativePaint = SerialUtilities.readPaint(stream);
1239 this.legendLine = SerialUtilities.readShape(stream); 1269 this.legendLine = SerialUtilities.readShape(stream);
1240 } 1270 }
1241 } 1271 }
1242

http://dive4elements.wald.intevation.org