comparison flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java @ 1812:dd084cf3f284

Refactored to allow mainvalues in discharge curve diagrams, too. flys-artifacts/trunk@3141 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 02 Nov 2011 12:12:48 +0000
parents 41ba2276d785
children 3918bd7eb4e1
comparison
equal deleted inserted replaced
1811:4ee833095e75 1812:dd084cf3f284
12 12
13 import de.intevation.artifacts.Artifact; 13 import de.intevation.artifacts.Artifact;
14 14
15 import de.intevation.artifactdatabase.state.Facet; 15 import de.intevation.artifactdatabase.state.Facet;
16 16
17 import de.intevation.flys.artifacts.model.FacetTypes;
17 import de.intevation.flys.model.Gauge; 18 import de.intevation.flys.model.Gauge;
18 import de.intevation.flys.model.River; 19 import de.intevation.flys.model.River;
19 20
21 import de.intevation.flys.artifacts.FLYSArtifact;
20 import de.intevation.flys.artifacts.WINFOArtifact; 22 import de.intevation.flys.artifacts.WINFOArtifact;
21 23
22 import de.intevation.flys.artifacts.model.WQKms; 24 import de.intevation.flys.artifacts.model.WQKms;
23 25
24 import de.intevation.flys.utils.FLYSUtils; 26 import de.intevation.flys.utils.FLYSUtils;
27 import de.intevation.flys.jfree.FLYSAnnotation;
25 28
26 /** 29 /**
27 * An OutGenerator that generates discharge curves. 30 * An OutGenerator that generates discharge curves.
28 * 31 *
29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 32 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
30 */ 33 */
31 public class DischargeCurveGenerator extends XYChartGenerator { 34 public class DischargeCurveGenerator
35 extends XYChartGenerator
36 implements FacetTypes {
32 37
33 /** The logger used in this generator. */ 38 /** The logger used in this generator. */
34 private static Logger logger = 39 private static Logger logger =
35 Logger.getLogger(DischargeCurveGenerator.class); 40 Logger.getLogger(DischargeCurveGenerator.class);
36 41
60 protected String getChartTitle() { 65 protected String getChartTitle() {
61 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); 66 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
62 } 67 }
63 68
64 69
70 /**
71 * Empty (suppress subtitle).
72 */
65 @Override 73 @Override
66 protected void addSubtitles(JFreeChart chart) { 74 protected void addSubtitles(JFreeChart chart) {
67 75 ;
68 } 76 }
69 77
70 78
71 protected String getXAxisLabel() { 79 protected String getXAxisLabel() {
72 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); 80 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT);
91 99
92 100
93 public void doOut( 101 public void doOut(
94 Artifact artifact, 102 Artifact artifact,
95 Facet facet, 103 Facet facet,
96 Document attr, 104 Document theme,
97 boolean visible 105 boolean visible
98 ) { 106 ) {
99 logger.debug("DischargeCurveGenerator.doOut: " + facet.getName()); 107 logger.debug("DischargeCurveGenerator.doOut: " + facet.getName());
100 108
101 if (!(artifact instanceof WINFOArtifact)) { 109 String name = facet.getName();
102 logger.debug("Artifact is no instance of WINFOArtifact."); 110
103 return; 111 FLYSArtifact flysArtifact = (FLYSArtifact) artifact;
104 }
105
106 WINFOArtifact flysArtifact = (WINFOArtifact) artifact;
107 112
108 Facet nativeFacet = flysArtifact.getNativeFacet(facet); 113 Facet nativeFacet = flysArtifact.getNativeFacet(facet);
109 114
110 if (nativeFacet == null) { 115 if (nativeFacet == null) {
111 logger.debug("no facet found"); 116 logger.debug("no facet found");
112 return; 117 return;
113 } 118 }
114 119
115 WQKms wqkms = (WQKms)nativeFacet.getData(flysArtifact, context); 120 if (name.equals(DISCHARGE_CURVE)) {
121 doDischargeOut(
122 (WINFOArtifact) flysArtifact,
123 nativeFacet.getData(flysArtifact, context),
124 nativeFacet.getDescription(),
125 theme,
126 visible);
127 }
128 else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)
129 || name.equals(MAINVALUES_Q))
130 {
131 doMainValueQAnnotations(
132 nativeFacet.getData(artifact, context), facet, theme, visible);
133 }
134 else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)
135 || name.equals(MAINVALUES_W))
136 {
137 doMainValueWAnnotations(
138 nativeFacet.getData(artifact, context), facet, theme, visible);
139 }
140 else {
141 logger.warn("DischargeCurveGenerator.doOut: Unknown facet name: " + name);
142 return;
143 }
144 }
145
146
147 /**
148 * Add series with discharge curve to diagram.
149 */
150 protected void doDischargeOut(
151 WINFOArtifact artifact,
152 Object o,
153 String description,
154 Document theme,
155 boolean visible)
156 {
157 WQKms wqkms = (WQKms) o;
116 158
117 String gaugeName = wqkms.getName(); 159 String gaugeName = wqkms.getName();
118 160
119 River river = FLYSUtils.getRiver(flysArtifact); 161 River river = FLYSUtils.getRiver(artifact);
120 162
121 if (river == null) { 163 if (river == null) {
122 logger.debug("no river found"); 164 logger.debug("no river found");
123 return; 165 return;
124 } 166 }
128 if (gauge == null) { 170 if (gauge == null) {
129 logger.debug("no gauge found"); 171 logger.debug("no gauge found");
130 return; 172 return;
131 } 173 }
132 174
133 double [][] values = new double [][] { 175 XYSeries series = new StyledXYSeries(description, theme);
134 wqkms.getQs(), wqkms.getWs() }; 176
135 177 StyledSeriesBuilder.addPointsQW(series, wqkms);
136 int size = values != null ? values[0].length : 0;
137
138 XYSeries series = new StyledXYSeries(facet.getDescription(), attr);
139
140 for (int i = 0; i < size; i++) {
141 series.add(values[0][i], values[1][i]);
142 }
143 178
144 addFirstAxisSeries(series, visible); 179 addFirstAxisSeries(series, visible);
145 } 180 }
181
182
183
184 /**
185 * Store W MainValues as annotations for later plotting.
186 */
187 protected void doMainValueWAnnotations(
188 Object o,
189 Facet facet,
190 Document theme,
191 boolean visible
192 ) {
193 logger.debug("ComputedDischargeCurveGenerator set W MainValues.");
194
195 FLYSAnnotation fa = (FLYSAnnotation) o;
196 fa.setTheme(theme);
197 fa.setLabel(facet.getDescription());
198 addAnnotations(fa, visible);
199 }
200
201
202 /**
203 * Store Q MainValues as annotations for later plotting.
204 */
205 protected void doMainValueQAnnotations(
206 Object o,
207 Facet facet,
208 Document theme,
209 boolean visible
210 ) {
211 logger.debug("ComputedDischargeCurveGenerator set Q MainValues.");
212
213 FLYSAnnotation fa = (FLYSAnnotation) o;
214 fa.setTheme(theme);
215 fa.setLabel(facet.getDescription());
216 addAnnotations(fa, visible);
217 }
218
219
220
146 } 221 }
147 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 222 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org