Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 3906:fc6c6f6039df
Fix for area clipping problem in longitudinal section char
flys-artifacts/trunk@5572 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Sat, 22 Sep 2012 17:04:44 +0000 |
parents | 7b14d00bca8a |
children | 2f6d4f92d628 |
comparison
equal
deleted
inserted
replaced
3905:8bbb9e173297 | 3906:fc6c6f6039df |
---|---|
1 package de.intevation.flys.exports; | 1 package de.intevation.flys.exports; |
2 | 2 |
3 import java.awt.Color; | |
4 import java.awt.Font; | |
5 import java.text.NumberFormat; | |
6 import java.util.ArrayList; | |
7 import java.util.HashMap; | |
8 import java.util.List; | |
9 import java.util.Map; | |
10 | |
11 import javax.swing.ImageIcon; | |
12 | |
13 import org.apache.log4j.Logger; | |
14 import org.jfree.chart.ChartFactory; | |
15 import org.jfree.chart.JFreeChart; | |
16 import org.jfree.chart.LegendItem; | |
17 import org.jfree.chart.annotations.XYAnnotation; | |
18 import org.jfree.chart.annotations.XYImageAnnotation; | |
19 import org.jfree.chart.annotations.XYTextAnnotation; | |
20 import org.jfree.chart.axis.NumberAxis; | |
21 import org.jfree.chart.axis.ValueAxis; | |
22 import org.jfree.chart.plot.Marker; | |
23 import org.jfree.chart.plot.PlotOrientation; | |
24 import org.jfree.chart.plot.XYPlot; | |
25 import org.jfree.data.Range; | |
26 import org.jfree.data.general.Series; | |
27 import org.jfree.data.xy.XYDataset; | |
28 import org.jfree.data.xy.XYSeries; | |
29 import org.jfree.data.xy.XYSeriesCollection; | |
30 import org.json.JSONArray; | |
31 import org.json.JSONException; | |
32 import org.w3c.dom.Document; | |
33 | |
3 import de.intevation.artifactdatabase.state.ArtifactAndFacet; | 34 import de.intevation.artifactdatabase.state.ArtifactAndFacet; |
4 | |
5 import de.intevation.flys.jfree.Bounds; | 35 import de.intevation.flys.jfree.Bounds; |
6 import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation; | 36 import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation; |
7 import de.intevation.flys.jfree.DoubleBounds; | 37 import de.intevation.flys.jfree.DoubleBounds; |
8 import de.intevation.flys.jfree.FLYSAnnotation; | 38 import de.intevation.flys.jfree.FLYSAnnotation; |
9 import de.intevation.flys.jfree.StyledAreaSeriesCollection; | 39 import de.intevation.flys.jfree.StyledAreaSeriesCollection; |
10 import de.intevation.flys.jfree.StyledXYSeries; | 40 import de.intevation.flys.jfree.StyledXYSeries; |
11 | |
12 import java.awt.Color; | |
13 import java.awt.Font; | |
14 import javax.swing.ImageIcon; | |
15 | |
16 import java.text.NumberFormat; | |
17 | |
18 import java.util.ArrayList; | |
19 import java.util.HashMap; | |
20 import java.util.List; | |
21 import java.util.Map; | |
22 | |
23 import org.apache.log4j.Logger; | |
24 | |
25 import org.jfree.chart.ChartFactory; | |
26 import org.jfree.chart.JFreeChart; | |
27 import org.jfree.chart.LegendItem; | |
28 | |
29 import org.jfree.chart.annotations.XYAnnotation; | |
30 import org.jfree.chart.annotations.XYImageAnnotation; | |
31 import org.jfree.chart.annotations.XYTextAnnotation; | |
32 | |
33 import org.jfree.chart.axis.NumberAxis; | |
34 import org.jfree.chart.axis.ValueAxis; | |
35 | |
36 import org.jfree.chart.plot.Marker; | |
37 import org.jfree.chart.plot.PlotOrientation; | |
38 import org.jfree.chart.plot.XYPlot; | |
39 | |
40 import org.jfree.data.Range; | |
41 | |
42 import org.jfree.data.general.Series; | |
43 | |
44 import org.jfree.data.xy.XYDataset; | |
45 import org.jfree.data.xy.XYSeries; | |
46 import org.jfree.data.xy.XYSeriesCollection; | |
47 | |
48 import org.json.JSONArray; | |
49 import org.json.JSONException; | |
50 | |
51 import org.w3c.dom.Document; | |
52 | 41 |
53 | 42 |
54 /** | 43 /** |
55 * An abstract base class for creating XY charts. | 44 * An abstract base class for creating XY charts. |
56 * | 45 * |
69 public abstract class XYChartGenerator extends ChartGenerator { | 58 public abstract class XYChartGenerator extends ChartGenerator { |
70 | 59 |
71 public class XYAxisDataset implements AxisDataset { | 60 public class XYAxisDataset implements AxisDataset { |
72 /** Symbolic integer, but also coding the priority (0 goes first). */ | 61 /** Symbolic integer, but also coding the priority (0 goes first). */ |
73 protected int axisSymbol; | 62 protected int axisSymbol; |
63 | |
74 /** List of assigned datasets (in order). */ | 64 /** List of assigned datasets (in order). */ |
75 protected List<XYDataset> datasets; | 65 protected List<XYDataset> datasets; |
66 | |
76 /** Range to use to include all given datasets. */ | 67 /** Range to use to include all given datasets. */ |
77 protected Range range; | 68 protected Range range; |
69 | |
78 /** Index of axis in plot. */ | 70 /** Index of axis in plot. */ |
79 protected int plotAxisIndex; | 71 protected int plotAxisIndex; |
80 | 72 |
81 /** Create AxisDataset. */ | 73 /** Create AxisDataset. */ |
82 public XYAxisDataset(int symb) { | 74 public XYAxisDataset(int symb) { |
128 | 120 |
129 | 121 |
130 /** Get Array of Datasets. */ | 122 /** Get Array of Datasets. */ |
131 @Override | 123 @Override |
132 public XYDataset[] getDatasets() { | 124 public XYDataset[] getDatasets() { |
133 return (XYDataset[]) | 125 return datasets.toArray(new XYDataset[datasets.size()]); |
134 datasets.toArray(new XYDataset[datasets.size()]); | |
135 } | 126 } |
136 | 127 |
137 | 128 |
138 /** Add a Dataset that describes an area. */ | 129 /** Add a Dataset that describes an area. */ |
139 public void addArea(StyledAreaSeriesCollection series) { | 130 public void addArea(StyledAreaSeriesCollection series) { |
140 this.datasets.add(series); | 131 this.datasets.add(series); |
141 } | 132 List<?> allSeries = series.getSeries(); |
142 | 133 for (int n = 0; n < allSeries.size(); n++) { |
143 // TODO obsolete? | 134 includeYRange((XYSeries)allSeries.get(n)); |
135 } | |
136 } | |
137 | |
144 /** True if to be rendered as area. */ | 138 /** True if to be rendered as area. */ |
145 @Override | 139 @Override |
146 public boolean isArea(XYDataset series) { | 140 public boolean isArea(XYDataset series) { |
147 return (series instanceof StyledAreaSeriesCollection); | 141 return (series instanceof StyledAreaSeriesCollection); |
148 } | 142 } |
170 return this.plotAxisIndex; | 164 return this.plotAxisIndex; |
171 } | 165 } |
172 } // class AxisDataset | 166 } // class AxisDataset |
173 | 167 |
174 /** Enumerator over existing axes. */ | 168 /** Enumerator over existing axes. */ |
169 @Override | |
175 protected abstract YAxisWalker getYAxisWalker(); | 170 protected abstract YAxisWalker getYAxisWalker(); |
176 | 171 |
177 public static final int AXIS_SPACE = 5; | 172 public static final int AXIS_SPACE = 5; |
178 | 173 |
179 /** The logger that is used in this generator. */ | 174 /** The logger that is used in this generator. */ |
198 | 193 |
199 | 194 |
200 /** | 195 /** |
201 * Generate the chart anew (including localized axis and all). | 196 * Generate the chart anew (including localized axis and all). |
202 */ | 197 */ |
198 @Override | |
203 public JFreeChart generateChart() { | 199 public JFreeChart generateChart() { |
204 logger.debug("XYChartGenerator.generateChart"); | 200 logger.debug("XYChartGenerator.generateChart"); |
205 | 201 |
206 JFreeChart chart = ChartFactory.createXYLineChart( | 202 JFreeChart chart = ChartFactory.createXYLineChart( |
207 getChartTitle(), | 203 getChartTitle(), |
477 | 473 |
478 | 474 |
479 /** | 475 /** |
480 * Add given series if visible, if not visible adjust ranges (such that | 476 * Add given series if visible, if not visible adjust ranges (such that |
481 * all points in data would be plotted once visible). | 477 * all points in data would be plotted once visible). |
482 * @param series the dataseries to include in plot. | 478 * @param series the data series to include in plot. |
483 * @param index ('symbolic') index of the series and of its axis. | 479 * @param index ('symbolic') index of the series and of its axis. |
484 * @param visible whether or not the data should be plotted. | 480 * @param visible whether or not the data should be plotted. |
485 */ | 481 */ |
486 public void addAxisSeries(XYSeries series, int index, boolean visible) { | 482 public void addAxisSeries(XYSeries series, int index, boolean visible) { |
487 if (series == null) { | 483 if (series == null) { |