comparison flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java @ 369:2ce7b473620e

Implemented the chart creation of a longitudinal section chart - W and Q facets. flys-artifacts/trunk@1778 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 29 Apr 2011 10:13:24 +0000
parents 8830eecad69e
children 60f63539d004
comparison
equal deleted inserted replaced
368:3e66a5705c39 369:2ce7b473620e
1 package de.intevation.flys.exports; 1 package de.intevation.flys.exports;
2
3 import java.io.IOException;
4 2
5 import org.apache.log4j.Logger; 3 import org.apache.log4j.Logger;
6 4
7 import org.jfree.data.xy.DefaultXYDataset; 5 import org.jfree.data.xy.XYDataset;
6 import org.jfree.data.xy.XYSeries;
7 import org.jfree.data.xy.XYSeriesCollection;
8 8
9 import org.w3c.dom.Document; 9 import org.w3c.dom.Document;
10 10
11 import de.intevation.artifacts.Artifact; 11 import de.intevation.artifacts.Artifact;
12 12
17 /** 17 /**
18 * An OutGenerator that generates discharge curves. 18 * An OutGenerator that generates discharge curves.
19 * 19 *
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
21 */ 21 */
22 public class LongitudinalSectionGenerator extends ChartGenerator { 22 public class LongitudinalSectionGenerator extends XYChartGenerator {
23 23
24 /** The logger that is used in this generator.*/ 24 /** The logger that is used in this generator.*/
25 private static Logger logger = 25 private static Logger logger =
26 Logger.getLogger(LongitudinalSectionGenerator.class); 26 Logger.getLogger(LongitudinalSectionGenerator.class);
27 27
28 28
29 protected DefaultXYDataset dataset; 29 public static final String LONGITUDINAL_SECTION_W =
30 "longitudinal_section.w";
31
32 public static final String LONGITUDINAL_SECTION_Q =
33 "longitudinal_section.q";
34
35
36 /** The storage for the series to be drawn in this chart.*/
37 protected XYSeriesCollection dataset;
30 38
31 39
32 public LongitudinalSectionGenerator() { 40 public LongitudinalSectionGenerator() {
33 super(); 41 super();
34 42
35 this.dataset = new DefaultXYDataset(); 43 this.dataset = new XYSeriesCollection();
44 }
45
46
47 protected String getChartTitle() {
48 // TODO i18n
49 return "Wasserstand für Gewässer";
50 }
51
52
53 protected String getXAxisLabel() {
54 return "km";
55 }
56
57
58 protected String getYAxisLabel() {
59 return "W [NN + m]";
60 }
61
62
63 protected XYDataset getXYDataset() {
64 return dataset;
36 } 65 }
37 66
38 67
39 public void doOut(Artifact artifact, String facet, Document attr) { 68 public void doOut(Artifact artifact, String facet, Document attr) {
40 logger.debug("LongitudinalSectionGenerator.doOut: " + facet); 69 logger.debug("LongitudinalSectionGenerator.doOut: " + facet);
41 70
71 if (facet == null) {
72 logger.error("No facet name for doOut(). No output generated!");
73 return;
74 }
75
76 if (facet.equals(LONGITUDINAL_SECTION_W)) {
77 doWOut(getWaterlevelData(artifact));
78 }
79 else if (facet.equals(LONGITUDINAL_SECTION_Q)) {
80 doQOut(getWaterlevelData(artifact));
81 }
82 else {
83 logger.warn("Unknown facet name: " + facet);
84 return;
85 }
86 }
87
88
89 /**
90 * Returns the waterlevel data computed by the WINFOArtifact.
91 *
92 * @param artifact The WINFOArtifact.
93 *
94 * @return the computed waterlevel data.
95 */
96 protected WQKms[] getWaterlevelData(Artifact artifact) {
42 WINFOArtifact winfoArtifact = (WINFOArtifact) artifact; 97 WINFOArtifact winfoArtifact = (WINFOArtifact) artifact;
43 WQKms[] wqkms = winfoArtifact.getWaterlevelData(); 98 WQKms[] wqkms = winfoArtifact.getWaterlevelData();
44 99
45 logger.debug("Got " + wqkms.length + " WQKms objects."); 100 logger.debug("Got " + wqkms.length + " WQKms objects.");
101
102 return wqkms;
46 } 103 }
47 104
48 105
49 public void generate() 106 /**
50 throws IOException 107 * Process the output for W facets in a longitudinal section curve.
51 { 108 *
52 logger.debug("LongitudinalSectionGenerator.generate"); 109 * @param wqkms An array of WQKms values.
110 */
111 protected void doWOut(WQKms[] wqkms) {
112 logger.debug("LongitudinalSectionGenerator.doWOut");
53 113
54 // TODO Implement me! 114 int idx = 0;
115 for (WQKms tmp: wqkms) {
116 XYSeries series = new XYSeries(getSeriesName(tmp, "w", idx++));
117
118 double[] target = new double[3];
119 int size = tmp.size();
120
121 if (logger.isDebugEnabled()) {
122 logger.debug("Generate series: " + series.getKey());
123
124 logger.debug("Start km: " + tmp.getKms(0));
125 logger.debug("End km: " + tmp.getKms(size-1));
126 logger.debug("Values : " + size);
127 }
128
129 for (int i = 0; i < size; i++) {
130 target = tmp.get(i, target);
131
132 logger.debug("++ W Tuple: " + target[2] + " -> " + target[0]);
133 series.add(target[2], target[0]);
134 }
135
136 dataset.addSeries(series);
137 }
138 }
139
140
141 /**
142 * Process the output for Q facets in a longitudinal section curve.
143 *
144 * @param wqkms An array of WQKms values.
145 */
146 protected void doQOut(WQKms[] wqkms) {
147 logger.debug("LongitudinalSectionGenerator.doQOut");
148
149 int idx = 0;
150 for (WQKms tmp: wqkms) {
151 XYSeries series = new XYSeries(getSeriesName(tmp, "Q", idx++));
152
153 double[] target = new double[3];
154 int size = tmp.size();
155
156 if (logger.isDebugEnabled()) {
157 logger.debug("Generate series: " + series.getKey());
158
159 logger.debug("Start km: " + tmp.getKms(0));
160 logger.debug("End km: " + tmp.getKms(size-1));
161 logger.debug("Values : " + size);
162 }
163
164 for (int i = 0; i < size; i++) {
165 target = tmp.get(i, target);
166
167 logger.debug("++ Q Tuple: " + target[2] + " -> " + target[1]);
168 series.add(target[2], target[1]);
169 }
170
171 dataset.addSeries(series);
172 }
173 }
174
175
176 protected String getSeriesName(WQKms wqkms, String prefix, int idx) {
177 return prefix + "-" + idx;
55 } 178 }
56 } 179 }
57 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 180 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org