Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java @ 652:8fa4c5c9cd1a
Charts are zoomed to a specified view if the attribute document for the chart creation contains an x and/or y range.
flys-artifacts/trunk@2047 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 03 Jun 2011 06:47:51 +0000 |
parents | bab867fb37e8 |
children | 45cd58a2a2bb |
comparison
equal
deleted
inserted
replaced
651:e6cecb661bff | 652:8fa4c5c9cd1a |
---|---|
7 | 7 |
8 import org.apache.log4j.Logger; | 8 import org.apache.log4j.Logger; |
9 | 9 |
10 import org.w3c.dom.Document; | 10 import org.w3c.dom.Document; |
11 import org.w3c.dom.Node; | 11 import org.w3c.dom.Node; |
12 | |
13 import org.jfree.data.Range; | |
12 | 14 |
13 import de.intevation.artifacts.Artifact; | 15 import de.intevation.artifacts.Artifact; |
14 import de.intevation.artifacts.CallContext; | 16 import de.intevation.artifacts.CallContext; |
15 | 17 |
16 import de.intevation.artifacts.ArtifactNamespaceContext; | 18 import de.intevation.artifacts.ArtifactNamespaceContext; |
41 | 43 |
42 /** The XPath that points to the chart size of the incoming request | 44 /** The XPath that points to the chart size of the incoming request |
43 * document.*/ | 45 * document.*/ |
44 public static final String XPATH_CHART_SIZE = | 46 public static final String XPATH_CHART_SIZE = |
45 "/art:action/art:attributes/art:size"; | 47 "/art:action/art:attributes/art:size"; |
48 | |
49 public static final String XPATH_CHART_X_RANGE = | |
50 "/art:action/art:attributes/art:xrange"; | |
51 | |
52 public static final String XPATH_CHART_Y_RANGE = | |
53 "/art:action/art:attributes/art:yrange"; | |
46 | 54 |
47 | 55 |
48 /** The document of the incoming out() request.*/ | 56 /** The document of the incoming out() request.*/ |
49 protected Document request; | 57 protected Document request; |
50 | 58 |
133 | 141 |
134 return size[0] > 0 && size[1] > 0 ? size : getDefaultSize(); | 142 return size[0] > 0 && size[1] > 0 ? size : getDefaultSize(); |
135 } | 143 } |
136 | 144 |
137 | 145 |
146 protected Range getDomainAxisRange() { | |
147 Node xrange = (Node) XMLUtils.xpath( | |
148 request, | |
149 XPATH_CHART_X_RANGE, | |
150 XPathConstants.NODE, | |
151 ArtifactNamespaceContext.INSTANCE); | |
152 | |
153 if (xrange == null) { | |
154 return null; | |
155 } | |
156 | |
157 String lower = XMLUtils.xpathString( | |
158 xrange, "@art:from", ArtifactNamespaceContext.INSTANCE); | |
159 | |
160 String upper = XMLUtils.xpathString( | |
161 xrange, "@art:to", ArtifactNamespaceContext.INSTANCE); | |
162 | |
163 logger.debug("FOUND X RANGE: " + lower + " -> " + upper); | |
164 | |
165 if (lower != null && upper != null) { | |
166 try { | |
167 double from = Double.parseDouble(lower); | |
168 double to = Double.parseDouble(upper); | |
169 | |
170 if (from == 0 && to == 0) { | |
171 logger.debug("No range specified. Lower and upper X == 0"); | |
172 return null; | |
173 } | |
174 | |
175 if (from > to) { | |
176 double tmp = to; | |
177 to = from; | |
178 from = tmp; | |
179 } | |
180 | |
181 return new Range(from, to); | |
182 } | |
183 catch (NumberFormatException nfe) { | |
184 logger.warn("Wrong values for domain axis range."); | |
185 } | |
186 } | |
187 | |
188 return null; | |
189 } | |
190 | |
191 | |
192 protected Range getValueAxisRange() { | |
193 Node yrange = (Node) XMLUtils.xpath( | |
194 request, | |
195 XPATH_CHART_Y_RANGE, | |
196 XPathConstants.NODE, | |
197 ArtifactNamespaceContext.INSTANCE); | |
198 | |
199 if (yrange == null) { | |
200 return null; | |
201 } | |
202 | |
203 String lower = XMLUtils.xpathString( | |
204 yrange, "@art:from", ArtifactNamespaceContext.INSTANCE); | |
205 | |
206 String upper = XMLUtils.xpathString( | |
207 yrange, "@art:to", ArtifactNamespaceContext.INSTANCE); | |
208 | |
209 if (lower != null && upper != null) { | |
210 try { | |
211 double from = Double.parseDouble(lower); | |
212 double to = Double.parseDouble(upper); | |
213 | |
214 if (from == 0 && to == 0) { | |
215 logger.debug("No range specified. Lower and upper Y == 0"); | |
216 return null; | |
217 } | |
218 | |
219 if (from > to) { | |
220 double tmp = to; | |
221 to = from; | |
222 from = tmp; | |
223 } | |
224 | |
225 return new Range(from, to); | |
226 } | |
227 catch (NumberFormatException nfe) { | |
228 logger.warn("Wrong values for value axis range."); | |
229 } | |
230 } | |
231 | |
232 return null; | |
233 } | |
234 | |
235 | |
138 /** | 236 /** |
139 * Returns the default size of a chart export as array. | 237 * Returns the default size of a chart export as array. |
140 * | 238 * |
141 * @return the default size of a chart as [width, height]. | 239 * @return the default size of a chart as [width, height]. |
142 */ | 240 */ |