Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/XYChartGenerator.java @ 7116:3c7471b929d1
Merge branch generator-refectoring into default.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 24 Sep 2013 12:29:44 +0200 |
parents | 1f38656b68c4 4f6b3ba542de |
children | 8ca2c711a632 |
comparison
equal
deleted
inserted
replaced
7095:bdadffad35b1 | 7116:3c7471b929d1 |
---|---|
44 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation; | 44 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation; |
45 import org.dive4elements.river.jfree.DoubleBounds; | 45 import org.dive4elements.river.jfree.DoubleBounds; |
46 import org.dive4elements.river.jfree.RiverAnnotation; | 46 import org.dive4elements.river.jfree.RiverAnnotation; |
47 import org.dive4elements.river.jfree.StyledAreaSeriesCollection; | 47 import org.dive4elements.river.jfree.StyledAreaSeriesCollection; |
48 import org.dive4elements.river.jfree.StyledXYSeries; | 48 import org.dive4elements.river.jfree.StyledXYSeries; |
49 import org.dive4elements.river.jfree.AxisDataset; | |
50 import org.dive4elements.river.jfree.AnnotationHelper; | |
49 import org.dive4elements.river.themes.ThemeDocument; | 51 import org.dive4elements.river.themes.ThemeDocument; |
50 | 52 |
51 | 53 |
52 /** | 54 /** |
53 * An abstract base class for creating XY charts. | 55 * An abstract base class for creating XY charts. |
64 * | 66 * |
65 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 67 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
66 */ | 68 */ |
67 public abstract class XYChartGenerator extends ChartGenerator { | 69 public abstract class XYChartGenerator extends ChartGenerator { |
68 | 70 |
69 public static class XYAxisDataset implements AxisDataset { | |
70 /** Symbolic integer, but also coding the priority (0 goes first). */ | |
71 protected int axisSymbol; | |
72 | |
73 /** List of assigned datasets (in order). */ | |
74 protected List<XYDataset> datasets; | |
75 | |
76 /** Range to use to include all given datasets. */ | |
77 protected Range range; | |
78 | |
79 /** Index of axis in plot. */ | |
80 protected int plotAxisIndex; | |
81 | |
82 /** Create AxisDataset. */ | |
83 public XYAxisDataset(int symb) { | |
84 this.axisSymbol = symb; | |
85 datasets = new ArrayList<XYDataset>(); | |
86 } | |
87 | |
88 /** Merge (or create given range with range so far (if any). */ | |
89 private void mergeRanges(Range subRange) { | |
90 // Avoid merging NaNs, as they take min/max place forever. | |
91 if (subRange == null || | |
92 Double.isNaN(subRange.getLowerBound()) || | |
93 Double.isNaN(subRange.getUpperBound())) { | |
94 return; | |
95 } | |
96 if (range == null) { | |
97 range = subRange; | |
98 return; | |
99 } | |
100 range = Range.combine(range, subRange); | |
101 } | |
102 | |
103 | |
104 /** Add a dataset to internal list for this axis. */ | |
105 @Override | |
106 public void addDataset(XYDataset dataset) { | |
107 datasets.add(dataset); | |
108 includeYRange(((XYSeriesCollection) dataset).getSeries(0)); | |
109 } | |
110 | |
111 /** Add a dataset, include its range. */ | |
112 public void addDataset(XYSeries series) { | |
113 addDataset(new XYSeriesCollection(series)); | |
114 } | |
115 | |
116 | |
117 /** Set Range for this axis. */ | |
118 @Override | |
119 public void setRange(Range range) { | |
120 this.range = range; | |
121 } | |
122 | |
123 | |
124 /** Get Range for this axis. */ | |
125 @Override | |
126 public Range getRange() { | |
127 return range; | |
128 } | |
129 | |
130 | |
131 /** Get Array of Datasets. */ | |
132 @Override | |
133 public XYDataset[] getDatasets() { | |
134 return datasets.toArray(new XYDataset[datasets.size()]); | |
135 } | |
136 | |
137 | |
138 /** Add a Dataset that describes an area. */ | |
139 public void addArea(StyledAreaSeriesCollection series) { | |
140 this.datasets.add(series); | |
141 List<?> allSeries = series.getSeries(); | |
142 /* We do not include the bounds/ranges, if the area includes | |
143 * points at "infinity"/BIG_DOUBLE_VALUE, the charts extents are | |
144 * expanded to include these very small/big value. | |
145 * This is especially used when showing "area above axis". */ | |
146 } | |
147 | |
148 /** True if to be rendered as area. */ | |
149 @Override | |
150 public boolean isArea(XYDataset series) { | |
151 return (series instanceof StyledAreaSeriesCollection); | |
152 } | |
153 | |
154 /** Adjust range to include given dataset. */ | |
155 public void includeYRange(XYSeries dataset) { | |
156 mergeRanges(new Range(dataset.getMinY(), dataset.getMaxY())); | |
157 } | |
158 | |
159 /** True if no datasets given. */ | |
160 @Override | |
161 public boolean isEmpty() { | |
162 return this.datasets.isEmpty(); | |
163 } | |
164 | |
165 /** Set the 'real' axis index that this axis is mapped to. */ | |
166 @Override | |
167 public void setPlotAxisIndex(int axisIndex) { | |
168 this.plotAxisIndex = axisIndex; | |
169 } | |
170 | |
171 /** Get the 'real' axis index that this axis is mapped to. */ | |
172 @Override | |
173 public int getPlotAxisIndex() { | |
174 return this.plotAxisIndex; | |
175 } | |
176 } // class AxisDataset | |
177 | |
178 /** Enumerator over existing axes. */ | 71 /** Enumerator over existing axes. */ |
179 @Override | 72 @Override |
180 protected abstract YAxisWalker getYAxisWalker(); | 73 protected abstract YAxisWalker getYAxisWalker(); |
181 | 74 |
182 public static final int AXIS_SPACE = 5; | 75 public static final int AXIS_SPACE = 5; |
256 } | 149 } |
257 | 150 |
258 //debugAxis(plot); | 151 //debugAxis(plot); |
259 | 152 |
260 // These have to go after the autozoom. | 153 // These have to go after the autozoom. |
261 addAnnotationsToRenderer(plot); | 154 AnnotationHelper.addAnnotationsToRenderer(annotations, plot, |
155 getChartSettings(), datasets); | |
262 | 156 |
263 // Add a logo (maybe). | 157 // Add a logo (maybe). |
264 addLogo(plot); | 158 addLogo(plot); |
265 | 159 |
266 aggregateLegendEntries(plot); | 160 aggregateLegendEntries(plot); |
413 } | 307 } |
414 | 308 |
415 | 309 |
416 @Override | 310 @Override |
417 protected AxisDataset createAxisDataset(int idx) { | 311 protected AxisDataset createAxisDataset(int idx) { |
418 logger.debug("Create new XYAxisDataset for index: " + idx); | 312 logger.debug("Create new AxisDataset for index: " + idx); |
419 return new XYAxisDataset(idx); | 313 return new AxisDataset(idx); |
420 } | 314 } |
421 | 315 |
422 | 316 |
423 /** | 317 /** |
424 * Put debug output about datasets. | 318 * Put debug output about datasets. |
479 if (area == null) { | 373 if (area == null) { |
480 logger.warn("Cannot yet render above/under curve."); | 374 logger.warn("Cannot yet render above/under curve."); |
481 return; | 375 return; |
482 } | 376 } |
483 | 377 |
484 XYAxisDataset axisDataset = (XYAxisDataset) getAxisDataset(index); | 378 AxisDataset axisDataset = (AxisDataset) getAxisDataset(index); |
485 | 379 |
486 if (visible) { | 380 if (visible) { |
487 axisDataset.addArea(area); | 381 axisDataset.addArea(area); |
488 } | 382 } |
489 else { | 383 else { |
508 logger.debug("Y Range of XYSeries: " + | 402 logger.debug("Y Range of XYSeries: " + |
509 series.getMinY() + " | " + series.getMaxY()); | 403 series.getMinY() + " | " + series.getMaxY()); |
510 | 404 |
511 addAxisDataset(new XYSeriesCollection(series), index, visible); | 405 addAxisDataset(new XYSeriesCollection(series), index, visible); |
512 | 406 |
513 XYAxisDataset axisDataset = (XYAxisDataset) getAxisDataset(index); | |
514 | |
515 if (!visible) { | |
516 // Do this also when not visible to have axis scaled by default such | |
517 // that every data-point could be seen (except for annotations). | |
518 axisDataset.includeYRange(series); | |
519 } | |
520 } | 407 } |
521 | 408 |
522 | 409 |
523 /** | 410 /** |
524 * Add the given vertical marker to the chart. | 411 * Add the given vertical marker to the chart. |