Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/extreme/ExtremeWQCurveGenerator.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-artifacts/src/main/java/org/dive4elements/river/exports/extreme/ExtremeWQCurveGenerator.java@bd047b71ab37 |
children | 4897a58c8746 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.exports.extreme; | |
2 | |
3 import java.awt.Color; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 import org.jfree.chart.JFreeChart; | |
7 import org.jfree.chart.plot.Marker; | |
8 import org.jfree.chart.plot.ValueMarker; | |
9 import org.jfree.chart.title.TextTitle; | |
10 import org.jfree.data.xy.XYSeries; | |
11 import org.w3c.dom.Document; | |
12 | |
13 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
14 import org.dive4elements.artifactdatabase.state.Facet; | |
15 import org.dive4elements.river.artifacts.access.FixAnalysisAccess; | |
16 import org.dive4elements.river.artifacts.model.DateRange; | |
17 import org.dive4elements.river.artifacts.model.FacetTypes; | |
18 import org.dive4elements.river.artifacts.model.extreme.Curve; | |
19 import org.dive4elements.river.artifacts.model.extreme.ExtremeCurveFacet; | |
20 import org.dive4elements.river.artifacts.resources.Resources; | |
21 import org.dive4elements.river.exports.fixings.FixWQCurveGenerator; | |
22 import org.dive4elements.river.exports.StyledSeriesBuilder; | |
23 import org.dive4elements.river.jfree.JFreeUtil; | |
24 import org.dive4elements.river.jfree.StyledXYSeries; | |
25 | |
26 import org.dive4elements.river.utils.ThemeUtil; | |
27 | |
28 | |
29 /** | |
30 * Generator for WQ fixing charts. | |
31 * @author <a href="mailto:christian.lins@intevation.de">Christian Lins</a> | |
32 */ | |
33 public class ExtremeWQCurveGenerator | |
34 extends FixWQCurveGenerator | |
35 implements FacetTypes | |
36 { | |
37 /** Private logger. */ | |
38 private static Logger logger = | |
39 Logger.getLogger(ExtremeWQCurveGenerator.class); | |
40 | |
41 public static final String I18N_CHART_TITLE = | |
42 "chart.extreme.wq.title"; | |
43 | |
44 public static final String I18N_CHART_SUBTITLE = | |
45 "chart.extreme.wq.subtitle"; | |
46 | |
47 public static final String I18N_CHART_SUBTITLE1 = | |
48 "chart.extreme.wq.subtitle1"; | |
49 | |
50 public static final String I18N_XAXIS_LABEL = | |
51 "chart.extreme.wq.xaxis.label"; | |
52 | |
53 public static final String I18N_YAXIS_LABEL = | |
54 "chart.extreme.wq.yaxis.label"; | |
55 | |
56 public static final String I18N_CHART_TITLE_DEFAULT = | |
57 "Extremkurvenanalyse"; | |
58 | |
59 public static final String I18N_XAXIS_LABEL_DEFAULT = | |
60 "Q [m\u00B3/s]"; | |
61 | |
62 public static final String I18N_YAXIS_LABEL_DEFAULT = | |
63 "W [NN + m]"; | |
64 | |
65 | |
66 @Override | |
67 public boolean prepareChartData(ArtifactAndFacet aaf, Document theme, boolean visible) { | |
68 if (!super.prepareChartData(aaf, theme, visible)) { | |
69 String name = aaf.getFacetName(); | |
70 if (name.equals(EXTREME_WQ_CURVE)) { | |
71 doExtremeCurveOut(aaf, theme, visible); | |
72 return true; | |
73 } | |
74 else if (name.equals(EXTREME_WQ_CURVE_BASE)) { | |
75 doExtremeCurveBaseOut(aaf, theme, visible); | |
76 return true; | |
77 } | |
78 return false; | |
79 } | |
80 return true; | |
81 } | |
82 | |
83 /** Do Extreme Curve nonextrapolated points out. */ | |
84 protected void doExtremeCurveBaseOut(ArtifactAndFacet aaf, Document theme, boolean visible) { | |
85 logger.debug("doExtremeCurveBaseOut"); | |
86 ExtremeCurveFacet facet = (ExtremeCurveFacet) aaf.getFacet(); | |
87 Curve curve = (Curve) facet.getData(aaf.getArtifact(), context); | |
88 if (curve == null) { | |
89 logger.warn("doExtremeCurveBaseOut: Facet does not contain Curve"); | |
90 return; | |
91 } | |
92 | |
93 XYSeries qwseries = new StyledXYSeries(aaf.getFacetDescription(), theme); | |
94 StyledSeriesBuilder.addPointsQW(qwseries, curve.getQs(), curve.getWs()); | |
95 | |
96 addAxisSeries(qwseries, YAXIS.W.idx, visible); | |
97 } | |
98 | |
99 | |
100 /** Do Extreme Curve out */ | |
101 protected void doExtremeCurveOut(ArtifactAndFacet aaf, Document theme, boolean visible) { | |
102 logger.debug("doExtremeCurveOut"); | |
103 ExtremeCurveFacet facet = (ExtremeCurveFacet) aaf.getFacet(); | |
104 Curve curve = (Curve) facet.getData(aaf.getArtifact(), context); | |
105 if (curve == null) { | |
106 logger.warn("doExtremeCurveOut: Facet does not contain Curve"); | |
107 return; | |
108 } | |
109 | |
110 double maxQ = curve.getSuggestedMaxQ(); | |
111 if (maxQ == Double.MAX_VALUE) { | |
112 maxQ = 8000; | |
113 } | |
114 | |
115 StyledXYSeries series = JFreeUtil.sampleFunction2D( | |
116 curve, | |
117 theme, | |
118 aaf.getFacetDescription(), | |
119 500, // number of samples | |
120 0.0 , // start | |
121 maxQ); // end | |
122 | |
123 // Add marker from where on its extrapolated. | |
124 if (ThemeUtil.parseShowExtraMark(theme)) { | |
125 double[] qs = curve.getQs(); | |
126 double extrapolateFrom = qs[qs.length-1]; | |
127 | |
128 Marker m = new ValueMarker(extrapolateFrom); | |
129 m.setPaint(Color.black); | |
130 addDomainMarker(m); | |
131 } | |
132 | |
133 addAxisSeries(series, 0, visible); | |
134 } | |
135 | |
136 | |
137 @Override | |
138 protected String getChartTitle() { | |
139 return Resources.format( | |
140 context.getMeta(), | |
141 I18N_CHART_TITLE, | |
142 I18N_CHART_TITLE_DEFAULT, | |
143 context.getContextValue(CURRENT_KM)); | |
144 } | |
145 | |
146 | |
147 @Override | |
148 protected String getDefaultChartTitle() { | |
149 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); | |
150 } | |
151 | |
152 @Override | |
153 protected String getDefaultChartSubtitle() { | |
154 FixAnalysisAccess access = new FixAnalysisAccess(artifact, context); | |
155 DateRange dateRange = access.getDateRange(); | |
156 DateRange refRange = access.getReferencePeriod(); | |
157 | |
158 if (dateRange != null && refRange != null) { | |
159 return Resources.format( | |
160 context.getMeta(), | |
161 I18N_CHART_SUBTITLE, | |
162 "", | |
163 access.getRiver(), | |
164 dateRange.getFrom(), | |
165 dateRange.getTo(), | |
166 refRange.getFrom(), | |
167 refRange.getTo()); | |
168 } | |
169 | |
170 return null; | |
171 } | |
172 | |
173 @Override | |
174 protected void addSubtitles(JFreeChart chart) { | |
175 String defaultSubtitle = getDefaultChartSubtitle(); | |
176 | |
177 if (defaultSubtitle == null || defaultSubtitle.length() == 0) { | |
178 return; | |
179 } | |
180 | |
181 chart.addSubtitle(new TextTitle(defaultSubtitle)); | |
182 } | |
183 | |
184 @Override | |
185 protected String getDefaultXAxisLabel() { | |
186 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); | |
187 } | |
188 | |
189 @Override | |
190 protected String getDefaultYAxisLabel(int pos) { | |
191 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); | |
192 } | |
193 } | |
194 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |