comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java @ 2587:bece6f604899

Removed references to Range and replaced those with references to Bounds in ChartGenerators. flys-artifacts/trunk@4143 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 15 Mar 2012 10:30:03 +0000
parents c7b0dfa6a52c
children d75b427da50a
comparison
equal deleted inserted replaced
2586:8cd6358eb7f8 2587:bece6f604899
51 import de.intevation.flys.model.River; 51 import de.intevation.flys.model.River;
52 52
53 import de.intevation.flys.artifacts.FLYSArtifact; 53 import de.intevation.flys.artifacts.FLYSArtifact;
54 import de.intevation.flys.artifacts.resources.Resources; 54 import de.intevation.flys.artifacts.resources.Resources;
55 import de.intevation.flys.jfree.Bounds; 55 import de.intevation.flys.jfree.Bounds;
56 import de.intevation.flys.jfree.DoubleBounds;
56 import de.intevation.flys.jfree.EnhancedLineAndShapeRenderer; 57 import de.intevation.flys.jfree.EnhancedLineAndShapeRenderer;
57 import de.intevation.flys.jfree.StableXYDifferenceRenderer; 58 import de.intevation.flys.jfree.StableXYDifferenceRenderer;
58 import de.intevation.flys.jfree.StyledAreaSeriesCollection; 59 import de.intevation.flys.jfree.StyledAreaSeriesCollection;
59 import de.intevation.flys.jfree.Style; 60 import de.intevation.flys.jfree.Style;
60 import de.intevation.flys.jfree.StyledSeries; 61 import de.intevation.flys.jfree.StyledSeries;
176 protected abstract YAxisWalker getYAxisWalker(); 177 protected abstract YAxisWalker getYAxisWalker();
177 178
178 179
179 protected abstract Series getSeriesOf(XYDataset dataset, int idx); 180 protected abstract Series getSeriesOf(XYDataset dataset, int idx);
180 181
181
182 /**
183 * This method is used to set the range of the X axis at index <i>axis</i>.
184 *
185 * @param axis The index of an X axis.
186 * @param range The new range for the X axis at index <i>axis</i>.
187 */
188 protected abstract void setXRange(int axis, Range range);
189
190
191 /**
192 * This method is used to set the range of the Y axis at index <i>axis</i>.
193 *
194 * @param axis The index of an Y axis.
195 * @param range The new range for the Y axis at index <i>axis</i>.
196 */
197 protected abstract void setYRange(int axis, Range range);
198
199
200 /** 182 /**
201 * Returns the default title of a chart. 183 * Returns the default title of a chart.
202 * 184 *
203 * @return the default title of a chart. 185 * @return the default title of a chart.
204 */ 186 */
238 * 220 *
239 * @param range A new range. 221 * @param range A new range.
240 * @param idx The index of the X axis that should be comined with 222 * @param idx The index of the X axis that should be comined with
241 * <i>range</i>. 223 * <i>range</i>.
242 */ 224 */
243 protected abstract void combineXRanges(Range range, int idx); 225 protected abstract void combineXBounds(Bounds bounds, int idx);
226
227
228 /**
229 * Combines the ranges of the Y axis at index <i>idx</i>.
230 *
231 * @param range A new range.
232 * @param idx The index of the Y axis that should be comined with
233 * <i>range</i>.
234 */
235 protected abstract void combineYBounds(Bounds bounds, int index);
244 236
245 237
246 /** 238 /**
247 * This method is used to determine the ranges for axes at a given index. 239 * This method is used to determine the ranges for axes at a given index.
248 * 240 *
859 return; 851 return;
860 } 852 }
861 853
862 AxisDataset axisDataset = getAxisDataset(idx); 854 AxisDataset axisDataset = getAxisDataset(idx);
863 855
864 Range[] xyRanges = ChartHelper.getRanges(dataset); 856 Bounds[] xyBounds = ChartHelper.getBounds(dataset);
865 857
866 if (xyRanges == null) { 858 if (xyBounds == null) {
867 logger.warn("Skip XYDataset for Axis (invalid ranges): " + idx); 859 logger.warn("Skip XYDataset for Axis (invalid ranges): " + idx);
868 return; 860 return;
869 } 861 }
870 862
871 if (visible) { 863 if (visible) {
872 if (logger.isDebugEnabled()) { 864 if (logger.isDebugEnabled()) {
873 logger.debug("Add new AxisDataset at index: " + idx); 865 logger.debug("Add new AxisDataset at index: " + idx);
874 logger.debug("X extent: " + xyRanges[0]); 866 logger.debug("X extent: " + xyBounds[0]);
875 logger.debug("Y extent: " + xyRanges[1]); 867 logger.debug("Y extent: " + xyBounds[1]);
876 } 868 }
877 869
878 axisDataset.addDataset(dataset); 870 axisDataset.addDataset(dataset);
879 combineXRanges(xyRanges[0], 0); 871 }
880 } 872
881 else { 873 combineXBounds(xyBounds[0], 0);
882 combineXRanges(xyRanges[0], 0); 874 combineYBounds(xyBounds[1], idx);
883
884 // TODO
885 // Expand y range provided by 'timeseries' to have a proper range
886 // set which includes all data.
887 // iw: I am not sure if we still need this
888 }
889 } 875 }
890 876
891 877
892 /** 878 /**
893 * This method grants access to the AxisDatasets stored in <i>datasets</i>. 879 * This method grants access to the AxisDatasets stored in <i>datasets</i>.
1127 if (axis.getAutoRangeIncludesZero()) { 1113 if (axis.getAutoRangeIncludesZero()) {
1128 axisDataset.setRange( 1114 axisDataset.setRange(
1129 Range.expandToInclude(axisDataset.getRange(), 0d)); 1115 Range.expandToInclude(axisDataset.getRange(), 0d));
1130 } 1116 }
1131 1117
1132 setYRange(axisIndex, expandPointRange(axisDataset.getRange())); 1118 setYBounds(axisIndex, expandPointRange(axisDataset.getRange()));
1133 1119
1134 // Add contained datasets, mapping to axis. 1120 // Add contained datasets, mapping to axis.
1135 for (XYDataset dataset: axisDataset.getDatasets()) { 1121 for (XYDataset dataset: axisDataset.getDatasets()) {
1136 plot.setDataset(datasetIndex, dataset); 1122 plot.setDataset(datasetIndex, dataset);
1137 plot.mapDatasetToRangeAxis(datasetIndex, axisIndex); 1123 plot.mapDatasetToRangeAxis(datasetIndex, axisIndex);
1278 /** 1264 /**
1279 * Expands a given range if it collapses into one point. 1265 * Expands a given range if it collapses into one point.
1280 * 1266 *
1281 * @param Range to be expanded if upper == lower bound. 1267 * @param Range to be expanded if upper == lower bound.
1282 */ 1268 */
1283 private Range expandPointRange(Range range) { 1269 private Bounds expandPointRange(Range range) {
1284 if (range != null && range.getLowerBound() == range.getUpperBound()) { 1270 if (range == null) {
1285 return ChartHelper.expandRange(range, 5); 1271 return null;
1286 } 1272 }
1287 return range; 1273 else if (range.getLowerBound() == range.getUpperBound()) {
1274 double hi = range.getUpperBound();
1275 double lo = range.getLowerBound();
1276 double add = (hi - lo) / 100 * 5;
1277
1278 return new DoubleBounds(lo-add, hi+add);
1279 }
1280
1281 return new DoubleBounds(range.getLowerBound(), range.getUpperBound());
1288 } 1282 }
1289 1283
1290 1284
1291 /** 1285 /**
1292 * Creates a new instance of EnhancedLineAndShapeRenderer. 1286 * Creates a new instance of EnhancedLineAndShapeRenderer.

http://dive4elements.wald.intevation.org