Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.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 | f959faaa7c4a |
children | f7761914f745 |
comparison
equal
deleted
inserted
replaced
922:95356252c309 | 923:7ca4a287cd0e |
---|---|
10 import org.jfree.chart.plot.XYPlot; | 10 import org.jfree.chart.plot.XYPlot; |
11 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; | 11 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; |
12 import org.jfree.chart.title.TextTitle; | 12 import org.jfree.chart.title.TextTitle; |
13 import org.jfree.data.Range; | 13 import org.jfree.data.Range; |
14 import org.jfree.data.xy.XYSeries; | 14 import org.jfree.data.xy.XYSeries; |
15 import org.jfree.data.xy.XYSeriesCollection; | |
16 | 15 |
17 import org.w3c.dom.Document; | 16 import org.w3c.dom.Document; |
18 | 17 |
19 import de.intevation.artifacts.Artifact; | 18 import de.intevation.artifacts.Artifact; |
20 | 19 |
57 public static final String I18N_CHART_TITLE_DEFAULT = "W-L\u00e4ngsschnitt"; | 56 public static final String I18N_CHART_TITLE_DEFAULT = "W-L\u00e4ngsschnitt"; |
58 public static final String I18N_XAXIS_LABEL_DEFAULT = "km"; | 57 public static final String I18N_XAXIS_LABEL_DEFAULT = "km"; |
59 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; | 58 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; |
60 public static final String I18N_2YAXIS_LABEL_DEFAULT = "Q [m\u00b3/s]"; | 59 public static final String I18N_2YAXIS_LABEL_DEFAULT = "Q [m\u00b3/s]"; |
61 | 60 |
62 /** The storage for the W series to be drawn in this chart.*/ | |
63 protected XYSeriesCollection w; | |
64 | |
65 /** The storage for the Q series to be drawn in this chart.*/ | |
66 protected XYSeriesCollection q; | |
67 | 61 |
68 protected boolean inverted; | 62 protected boolean inverted; |
69 | 63 |
70 | 64 |
71 public LongitudinalSectionGenerator() { | 65 public LongitudinalSectionGenerator() { |
72 super(); | 66 super(); |
73 | |
74 this.w = new XYSeriesCollection(); | |
75 this.q = new XYSeriesCollection(); | |
76 } | 67 } |
77 | 68 |
78 | 69 |
79 protected String getChartTitle() { | 70 protected String getChartTitle() { |
80 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); | 71 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); |
111 protected String getYAxisLabel() { | 102 protected String getYAxisLabel() { |
112 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); | 103 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); |
113 } | 104 } |
114 | 105 |
115 | 106 |
116 @Override | |
117 protected void addDatasets(JFreeChart chart) { | |
118 XYPlot plot = (XYPlot) chart.getPlot(); | |
119 | |
120 plot.setDataset(0, w); | |
121 plot.setDataset(1, q); | |
122 } | |
123 | |
124 | |
125 protected void adjustPlot(XYPlot plot) { | 107 protected void adjustPlot(XYPlot plot) { |
126 super.adjustPlot(plot); | 108 super.adjustPlot(plot); |
127 | 109 |
128 // TODO REMOVE THIS CODE, IF WE HAVE INTRODUCED THEMES! | 110 //// TODO REMOVE THIS CODE, IF WE HAVE INTRODUCED THEMES! |
129 XYLineAndShapeRenderer rw = (XYLineAndShapeRenderer) | 111 //XYLineAndShapeRenderer rw = (XYLineAndShapeRenderer) |
130 plot.getRendererForDataset(w); | 112 // plot.getRendererForDataset(w); |
131 | 113 |
132 XYLineAndShapeRenderer rq = null; | 114 //XYLineAndShapeRenderer rq = null; |
133 try { | 115 //try { |
134 rq = (XYLineAndShapeRenderer) rw.clone(); | 116 // rq = (XYLineAndShapeRenderer) rw.clone(); |
135 } | 117 //} |
136 catch (Exception e) { | 118 //catch (Exception e) { |
137 logger.error(e, e); | 119 // logger.error(e, e); |
138 } | 120 //} |
139 | 121 |
140 int wNum = w.getSeriesCount(); | 122 //int wNum = w.getSeriesCount(); |
141 int qNum = q.getSeriesCount(); | 123 //int qNum = q.getSeriesCount(); |
142 | 124 |
143 for (int i = 0; i < wNum; i++) { | 125 //for (int i = 0; i < wNum; i++) { |
144 rw.setSeriesPaint(i, Color.BLUE); | 126 // rw.setSeriesPaint(i, Color.BLUE); |
145 } | 127 //} |
146 | 128 |
147 for (int i = 0; i < qNum; i++) { | 129 //for (int i = 0; i < qNum; i++) { |
148 rq.setSeriesPaint(i, Color.GREEN); | 130 // rq.setSeriesPaint(i, Color.GREEN); |
149 } | 131 //} |
150 | 132 |
151 plot.setRenderer(0, rw); | 133 //plot.setRenderer(0, rw); |
152 plot.setRenderer(1, rq); | 134 //plot.setRenderer(1, rq); |
153 } | 135 } |
154 | 136 |
155 | 137 |
156 protected void adjustAxes(XYPlot plot) { | 138 protected void adjustAxes(XYPlot plot) { |
157 super.adjustAxes(plot); | 139 super.adjustAxes(plot); |
158 | 140 |
159 NumberAxis qAxis = new NumberAxis( | 141 NumberAxis qAxis = new NumberAxis( |
160 msg(I18N_2YAXIS_LABEL, I18N_2YAXIS_LABEL_DEFAULT)); | 142 msg(I18N_2YAXIS_LABEL, I18N_2YAXIS_LABEL_DEFAULT)); |
161 | 143 |
162 plot.setRangeAxis(1, qAxis); | 144 plot.setRangeAxis(1, qAxis); |
163 plot.mapDatasetToRangeAxis(1, 1); | |
164 | 145 |
165 invertXAxis(plot.getDomainAxis()); | 146 invertXAxis(plot.getDomainAxis()); |
166 } | 147 } |
167 | 148 |
168 | 149 |
250 | 231 |
251 for (int i = 0; i < size; i++) { | 232 for (int i = 0; i < size; i++) { |
252 series.add(wqkms.getKms(i), wqkms.getW(i)); | 233 series.add(wqkms.getKms(i), wqkms.getW(i)); |
253 } | 234 } |
254 | 235 |
255 w.addSeries(series); | 236 addFirstAxisSeries(series); |
256 | 237 |
257 if (wqkms.guessWaterIncreasing()) { | 238 if (wqkms.guessWaterIncreasing()) { |
258 setInverted(true); | 239 setInverted(true); |
259 } | 240 } |
260 } | 241 } |
283 | 264 |
284 for (int i = 0; i < size; i++) { | 265 for (int i = 0; i < size; i++) { |
285 series.add(wqkms.getKms(i), wqkms.getQ(i)); | 266 series.add(wqkms.getKms(i), wqkms.getQ(i)); |
286 } | 267 } |
287 | 268 |
288 q.addSeries(series); | 269 addSecondAxisSeries(series); |
289 | 270 |
290 if (wqkms.guessWaterIncreasing()) { | 271 if (wqkms.guessWaterIncreasing()) { |
291 setInverted(true); | 272 setInverted(true); |
292 } | 273 } |
293 } | 274 } |