comparison flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java @ 923:7ca4a287cd0e

#135 Modified the way to store datasets for different chart axes. flys-artifacts/trunk@2275 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 01 Jul 2011 11:16:11 +0000
parents 5f5e67aceb8c
children f7761914f745
comparison
equal deleted inserted replaced
922:95356252c309 923:7ca4a287cd0e
12 import org.jfree.chart.plot.XYPlot; 12 import org.jfree.chart.plot.XYPlot;
13 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; 13 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
14 import org.jfree.chart.title.TextTitle; 14 import org.jfree.chart.title.TextTitle;
15 import org.jfree.data.Range; 15 import org.jfree.data.Range;
16 import org.jfree.data.xy.XYSeries; 16 import org.jfree.data.xy.XYSeries;
17 import org.jfree.data.xy.XYSeriesCollection;
18 17
19 import de.intevation.artifacts.Artifact; 18 import de.intevation.artifacts.Artifact;
20 19
21 import de.intevation.artifactdatabase.state.Facet; 20 import de.intevation.artifactdatabase.state.Facet;
22 21
36 implements FacetTypes 35 implements FacetTypes
37 { 36 {
38 private static Logger logger = 37 private static Logger logger =
39 Logger.getLogger(DurationCurveGenerator.class); 38 Logger.getLogger(DurationCurveGenerator.class);
40 39
41 /** The storage for the W series to be drawn in this chart.*/
42 protected XYSeriesCollection w;
43
44 /** The storage for the Q series to be drawn in this chart.*/
45 protected XYSeriesCollection q;
46
47 40
48 public static final String I18N_DURATION_W = 41 public static final String I18N_DURATION_W =
49 "chart.duration.curve.curve.w"; 42 "chart.duration.curve.curve.w";
50 43
51 public static final String I18N_DURATION_Q = 44 public static final String I18N_DURATION_Q =
73 "W [NN + m]"; 66 "W [NN + m]";
74 67
75 68
76 public DurationCurveGenerator() { 69 public DurationCurveGenerator() {
77 super(); 70 super();
78
79 this.w = new XYSeriesCollection();
80 this.q = new XYSeriesCollection();
81 } 71 }
82 72
83 73
84 protected String getChartTitle() { 74 protected String getChartTitle() {
85 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); 75 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
120 110
121 return zoomin; 111 return zoomin;
122 } 112 }
123 113
124 114
125 public void addDatasets(JFreeChart chart) {
126 XYPlot plot = (XYPlot) chart.getPlot();
127
128 plot.setDataset(0, w);
129 plot.setDataset(1, q);
130 }
131
132
133 protected void adjustPlot(XYPlot plot) { 115 protected void adjustPlot(XYPlot plot) {
134 super.adjustPlot(plot); 116 super.adjustPlot(plot);
135 117
136 // TODO REMOVE THIS CODE, IF WE HAVE INTRODUCED THEMES! 118 // TODO REMOVE THIS CODE, IF WE HAVE INTRODUCED THEMES!
137 XYLineAndShapeRenderer rw = (XYLineAndShapeRenderer) 119 //XYLineAndShapeRenderer rw = (XYLineAndShapeRenderer)
138 plot.getRendererForDataset(w); 120 // plot.getRendererForDataset(w);
139 121
140 XYLineAndShapeRenderer rq = null; 122 //XYLineAndShapeRenderer rq = null;
141 try { 123 //try {
142 rq = (XYLineAndShapeRenderer) rw.clone(); 124 // rq = (XYLineAndShapeRenderer) rw.clone();
143 } 125 //}
144 catch (Exception e) { 126 //catch (Exception e) {
145 logger.error(e, e); 127 // logger.error(e, e);
146 } 128 //}
147 129
148 int wNum = w.getSeriesCount(); 130 //int wNum = w.getSeriesCount();
149 int qNum = q.getSeriesCount(); 131 //int qNum = q.getSeriesCount();
150 132
151 for (int i = 0; i < wNum; i++) { 133 //for (int i = 0; i < wNum; i++) {
152 rw.setSeriesPaint(i, Color.BLUE); 134 // rw.setSeriesPaint(i, Color.BLUE);
153 } 135 //}
154 136
155 for (int i = 0; i < qNum; i++) { 137 //for (int i = 0; i < qNum; i++) {
156 rq.setSeriesPaint(i, Color.GREEN); 138 // rq.setSeriesPaint(i, Color.GREEN);
157 } 139 //}
158 140
159 plot.setRenderer(0, rw); 141 //plot.setRenderer(0, rw);
160 plot.setRenderer(1, rq); 142 //plot.setRenderer(1, rq);
161 } 143 }
162 144
163 145
164 protected void adjustAxes(XYPlot plot) { 146 protected void adjustAxes(XYPlot plot) {
165 super.adjustAxes(plot); 147 super.adjustAxes(plot);
166 148
167 NumberAxis qAxis = new NumberAxis("Q [m\u00b3/s]"); 149 NumberAxis qAxis = new NumberAxis("Q [m\u00b3/s]");
168 150
169 plot.setRangeAxis(1, qAxis); 151 plot.setRangeAxis(1, qAxis);
170 plot.mapDatasetToRangeAxis(1, 1);
171 } 152 }
172 153
173 154
174 @Override 155 @Override
175 public void doOut(Artifact artifact, Facet facet, Document attr) { 156 public void doOut(Artifact artifact, Facet facet, Document attr) {
217 double w = wqdays.getW(i); 198 double w = wqdays.getW(i);
218 199
219 series.add((double) day, w); 200 series.add((double) day, w);
220 } 201 }
221 202
222 this.w.addSeries(series); 203 addFirstAxisSeries(series);
223 } 204 }
224 205
225 206
226 /** 207 /**
227 * Creates the series for a duration curve's Q facet. 208 * Creates the series for a duration curve's Q facet.
242 double q = wqdays.getQ(i); 223 double q = wqdays.getQ(i);
243 224
244 series.add((double) day, q); 225 series.add((double) day, q);
245 } 226 }
246 227
247 this.q.addSeries(series); 228 addSecondAxisSeries(series);
248 } 229 }
249 230
250 231
251 protected String getSeriesName(String river, String type) { 232 protected String getSeriesName(String river, String type) {
252 Object[] args = new Object[] { river }; 233 Object[] args = new Object[] { river };

http://dive4elements.wald.intevation.org