comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java @ 767:79401c871da4

Added and repaired javadoc in de.intevation.gnv.chart package. gnv-artifacts/trunk@823 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 24 Mar 2010 14:48:55 +0000
parents b98d1adee7a6
children 9a828e5a2390
comparison
equal deleted inserted replaced
766:a23ce49423d5 767:79401c871da4
21 import de.intevation.gnv.geobackend.base.Result; 21 import de.intevation.gnv.geobackend.base.Result;
22 import de.intevation.gnv.state.describedata.KeyValueDescibeData; 22 import de.intevation.gnv.state.describedata.KeyValueDescibeData;
23 23
24 24
25 /** 25 /**
26 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> 26 * This class is used to create xy charts of vertical profiles.
27 *
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
27 */ 29 */
28 public class VerticalProfileChart 30 public class VerticalProfileChart
29 extends AbstractXYLineChart 31 extends AbstractXYLineChart
30 { 32 {
33 /**
34 * Default axis identifier which is used if @see #getDependendAxisName does
35 * not return a value. The value of this field is {@value}.
36 */
31 public static final String DEFAULT_AXIS = "KPOSITION"; 37 public static final String DEFAULT_AXIS = "KPOSITION";
32 38
39 /**
40 * Logger used for logging with log4j.
41 */
33 private static Logger log = Logger.getLogger(VerticalProfileChart.class); 42 private static Logger log = Logger.getLogger(VerticalProfileChart.class);
34 43
44 /**
45 * Constant used for gap detection. Its value is {@value}.
46 */
35 protected final double PERCENTAGE = 5.0; 47 protected final double PERCENTAGE = 5.0;
48
49 /**
50 * Constnat used for gap detection in @see #gridDetection. Its value is
51 * {@value}.
52 */
36 protected final double GAP_MAX_LEVEL = Math.sqrt(2.0); 53 protected final double GAP_MAX_LEVEL = Math.sqrt(2.0);
54
55 /**
56 * Constant used for gap detection in @see #addGaps. Its value is {@value}.
57 */
37 protected final int GAP_MAX_VALUES = 60; 58 protected final int GAP_MAX_VALUES = 60;
38 59
39 /** Map to store max ranges of each parameter (axis.setAutoRange(true) 60 /**
40 * doesn't seem to work properly. */ 61 * Map to store max ranges of each parameter
62 * (org.jfree.chart.axis.Axis.setAutoRange(true) doesn't seem to work
63 * properly.
64 */
41 protected Map values; 65 protected Map values;
42 66
43 67
68 /**
69 * Constructor used to create xy-charts.
70 *
71 * @param labels Labels used to be displayed in title, subtitle and so on.
72 * @param theme ChartTheme used to adjust the rendering of this chart.
73 * @param parameters Collection containing a bunch of parameters.
74 * @param measurements Collection containing a bunch of measurements.
75 * @param dates Collection containing a bunch of date objects.
76 * @param result Collection containing a bunch of <code>Result</code>
77 * objects which contain the actual data items to be displayed.
78 * @param timeGaps Collection with timegap definitions.
79 * @param locale Locale used to specify the format of labels, numbers, ...
80 * @param linesVisible Render lines between data points if true, otherwise
81 * not.
82 * @param shapesVisible Render vertices as points if true, otherwise not.
83 */
44 public VerticalProfileChart( 84 public VerticalProfileChart(
45 ChartLabels labels, 85 ChartLabels labels,
46 ChartTheme theme, 86 ChartTheme theme,
47 Collection parameters, 87 Collection parameters,
48 Collection measurements, 88 Collection measurements,
68 this.ranges = new HashMap(); 108 this.ranges = new HashMap();
69 this.values = new HashMap(); 109 this.values = new HashMap();
70 } 110 }
71 111
72 112
113 /**
114 * @see de.intevation.gnv.chart.AbstractXYLineChart#initData()
115 */
116 @Override
73 protected void initData() { 117 protected void initData() {
74 log.debug("init data for VerticalProfileChart"); 118 log.debug("init data for VerticalProfileChart");
75 119
76 String breakPoint1 = null; 120 String breakPoint1 = null;
77 String breakPoint2 = null; 121 String breakPoint2 = null;
143 187
144 addDatasets(); 188 addDatasets();
145 } 189 }
146 190
147 191
192 /**
193 * Extract the important value from <code>Result</code> object.
194 *
195 * @param row <code>Result</code> object which contains a required value.
196 *
197 * @return X-ordinate
198 */
148 protected Object getValue(Result row) { 199 protected Object getValue(Result row) {
149 return row.getDouble("XORDINATE"); 200 return row.getDouble("XORDINATE");
150 } 201 }
151 202
152 203
204 /**
205 * General method to start a gap detection. The switch between standard gap
206 * detection method <code>addGaps</code> and a specialized method
207 * <code>addGapsOnGrid</code> is done by a parameter <code>DATEID</code>
208 * which is stored a each <code>Result</code> object. Specialized method is
209 * used if <code>DATEID</code> equals 2, otherwise the standard method is
210 * used.
211 *
212 * @param results Array of <code>Result</code> objects storing data of
213 * this chart.
214 * @param series Series used to add gaps.
215 * @param startPos Index of first element of series in results.
216 * @param endPos Index of last element of series in results.
217 */
153 protected void gapDetection( 218 protected void gapDetection(
154 Result[] results, 219 Result[] results,
155 Series series, 220 Series series,
156 int startPos, 221 int startPos,
157 int endPos 222 int endPos
163 else 228 else
164 addGaps(results, series, startValue, endValue, startPos, endPos); 229 addGaps(results, series, startValue, endValue, startPos, endPos);
165 } 230 }
166 231
167 232
233 /**
234 * Method to expand max range of a range axis identified by seriesKey.
235 * <code>LOWER_MARGIN</code> and <code>UPPER_MARGIN</code> are used to
236 * expand the range.
237 *
238 * @param seriesKey Key to identify the series stored at the current
239 * Dataset.
240 * @param idx Currently not used.
241 */
168 protected void prepareRangeAxis(String seriesKey, int idx) { 242 protected void prepareRangeAxis(String seriesKey, int idx) {
169 XYPlot plot = chart.getXYPlot(); 243 XYPlot plot = chart.getXYPlot();
170 NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); 244 NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
171 245
172 Range xRange = (Range) values.get(seriesKey); 246 Range xRange = (Range) values.get(seriesKey);
173 xAxis.setRange(Range.expand(xRange, LOWER_MARGIN, UPPER_MARGIN)); 247 xAxis.setRange(Range.expand(xRange, LOWER_MARGIN, UPPER_MARGIN));
174 log.debug("Max X-Range of dataset is: " + xRange.toString()); 248 log.debug("Max X-Range of dataset is: " + xRange.toString());
175 } 249 }
176 250
177 251
252 /**
253 * @see de.intevation.gnv.chart.AbstractXYLineChart#addValue(Result, Series)
254 */
255 @Override
178 protected void addValue(Result row, Series series) { 256 protected void addValue(Result row, Series series) {
179 ((XYSeries) series).add( 257 ((XYSeries) series).add(
180 row.getDouble("XORDINATE"), 258 row.getDouble("XORDINATE"),
181 row.getDouble("YORDINATE") 259 row.getDouble("YORDINATE")
182 ); 260 );
183 } 261 }
184 262
185 263
264 /**
265 * @see de.intevation.gnv.chart.AbstractXYLineChart#addSeries(Series, String,
266 * int)
267 */
268 @Override
186 protected void addSeries(Series series, String parameter, int idx) { 269 protected void addSeries(Series series, String parameter, int idx) {
187 log.debug("add series (" + parameter + ")to chart"); 270 log.debug("add series (" + parameter + ")to chart");
188 271
189 if (series == null) { 272 if (series == null) {
190 log.warn("no data to add"); 273 log.warn("no data to add");
201 xysc.addSeries((XYSeries) series); 284 xysc.addSeries((XYSeries) series);
202 datasets.put(parameter, xysc); 285 datasets.put(parameter, xysc);
203 } 286 }
204 287
205 288
289 /**
290 * Method to add processed datasets to plot. Each dataset is adjusted using
291 * <code>prepareAxis</code> and <code>adjustRenderer</code> methods.
292 */
206 protected void addDatasets() { 293 protected void addDatasets() {
207 Iterator iter = parameters.iterator(); 294 Iterator iter = parameters.iterator();
208 XYPlot plot = chart.getXYPlot(); 295 XYPlot plot = chart.getXYPlot();
209 int idx = 0; 296 int idx = 0;
210 297
230 } 317 }
231 } 318 }
232 } 319 }
233 320
234 321
322 /**
323 * Method used to store the max y-range of each parameter in this chart.
324 *
325 * @param values Map to store max values for each parameter.
326 * @param val Value used to be a Double.
327 * @param parameter Title used to identify a range object stored in values.
328 */
235 protected void storeMaxValue(Map values, Object val, String parameter) { 329 protected void storeMaxValue(Map values, Object val, String parameter) {
236 double value = ((Double) val).doubleValue(); 330 double value = ((Double) val).doubleValue();
237 Range range = null; 331 Range range = null;
238 332
239 range = values.containsKey(parameter) 333 range = values.containsKey(parameter)
248 342
249 values.put(parameter, new Range(lower, upper)); 343 values.put(parameter, new Range(lower, upper));
250 } 344 }
251 345
252 346
347 /**
348 * @see de.intevation.gnv.chart.AbstractXYLineChart#localizeDomainAxis(Axis,
349 * Locale)
350 */
351 @Override
253 protected void localizeDomainAxis(Axis axis, Locale locale) { 352 protected void localizeDomainAxis(Axis axis, Locale locale) {
254 // call localizeRangeAxis from superclass which formats NumberAxis 353 // call localizeRangeAxis from superclass which formats NumberAxis
255 super.localizeRangeAxis(axis, locale); 354 super.localizeRangeAxis(axis, locale);
256 } 355 }
257 356
258 357
358 /**
359 * @see de.intevation.gnv.chart.AbstractXYLineChart#createSeriesName(String,
360 * String, String)
361 */
362 @Override
259 protected String createSeriesName( 363 protected String createSeriesName(
260 String breakPoint1, 364 String breakPoint1,
261 String breakPoint2, 365 String breakPoint2,
262 String breakPoint3 366 String breakPoint3
263 ) { 367 ) {
267 findValueTitle(measurements, breakPoint2) + 371 findValueTitle(measurements, breakPoint2) +
268 "m"; 372 "m";
269 } 373 }
270 374
271 375
376 /**
377 * Method used to add gaps between data points on grids. The real detection
378 * is done in <code>gridDetection</code>.
379 *
380 * @param results Array of <code>Result</code> objects storing the relevant
381 * values.
382 * @param series Series object where the gaps are added to.
383 * @param startPos Index of first element which should be used in gap
384 * detection. Other series are stored in results as well.
385 * @param endPos Index of last element which should be used in gap
386 * detection.
387 */
272 protected void addGapsOnGrid( 388 protected void addGapsOnGrid(
273 Result[] results, 389 Result[] results,
274 Series series, 390 Series series,
275 int startPos, 391 int startPos,
276 int endPos 392 int endPos
305 } 421 }
306 } 422 }
307 } 423 }
308 424
309 425
426 /**
427 * Standarad method to add gaps. There are two different methods to detect
428 * gaps. <code>simpleDetection</code> is used if the number of data points
429 * in this chart is lower than <code>GAP_MAX_VALUES</code>. Otherwise
430 * <code>specialDetection</code> is used. A data point with
431 * <code>null</code> value is added where a gap should be. This lets
432 * JFreeChart break the current graph.
433 *
434 * @param results Array of <code>Result</code> objects storing the relevant
435 * values.
436 * @param series Series object where the gaps are added to.
437 * @param startValue First data point value in series.
438 * @param endValue Last data point value in series.
439 * @param startPos Index of first data point in results which contains all
440 * data points of all series.
441 * @param endPos Index of last data point in results which contains all data
442 * points of all series.
443 */
310 protected void addGaps( 444 protected void addGaps(
311 Result[] results, 445 Result[] results,
312 Series series, 446 Series series,
313 double startValue, 447 double startValue,
314 double endValue, 448 double endValue,
345 } 479 }
346 } 480 }
347 } 481 }
348 482
349 483
484 /**
485 * Simple method to detect gaps. A gap is detected if the delta between two
486 * data points (current, last) is bigger than <code>PERCENTAGE</code> percent
487 * of delta of start and end.
488 * <br>
489 * (smallDelta &gt; delta / 100 * PERCENTAGE)
490 *
491 * @param start First data point value in a series.
492 * @param end Last data point value in a series.
493 * @param last Left value
494 * @param current Right value
495 *
496 * @return true, if a gap is detected between last and current - otherwise
497 * false.
498 */
350 protected boolean simpleDetection( 499 protected boolean simpleDetection(
351 double start, 500 double start,
352 double end, 501 double end,
353 double last, 502 double last,
354 double current 503 double current
358 507
359 return (smallDelta > delta / 100 * PERCENTAGE); 508 return (smallDelta > delta / 100 * PERCENTAGE);
360 } 509 }
361 510
362 511
512 /**
513 * Method to detect gaps between two data points. Following formula is used
514 * for detection:<br>
515 * smallDelta &gt; (3.0 / (count - 1) * delta)<br>
516 * smallDelta = current - last<br>
517 * delta = end - start
518 *
519 * @param start First data point value in a series.
520 * @param end Last data point value in a series.
521 * @param last Left value
522 * @param current Right value
523 *
524 * @return true, if a gap is detected between last and current - otherwise
525 * false.
526 */
363 protected boolean specialDetection( 527 protected boolean specialDetection(
364 double start, 528 double start,
365 double end, 529 double end,
366 double last, 530 double last,
367 double current, 531 double current,
372 536
373 return (smallDelta > (3.0 / (count - 1) * delta)); 537 return (smallDelta > (3.0 / (count - 1) * delta));
374 } 538 }
375 539
376 540
541 /**
542 * Method used to detect gaps between two data points grids. If the delta
543 * between current and last is bigger than <code>GAP_MAX_LEVEL</code>, a gap
544 * is detected.
545 *
546 * @param last Left value
547 * @param current Right value
548 *
549 * @return True, if a gap was detected - otherwise false.
550 */
377 protected boolean gridDetection(double last, double current) { 551 protected boolean gridDetection(double last, double current) {
378 if (log.isDebugEnabled()) { 552 if (log.isDebugEnabled()) {
379 log.debug("######################################################"); 553 log.debug("######################################################");
380 log.debug("Parameters for gap detection"); 554 log.debug("Parameters for gap detection");
381 log.debug("Defined gap size for grids: " + GAP_MAX_LEVEL); 555 log.debug("Defined gap size for grids: " + GAP_MAX_LEVEL);
385 } 559 }
386 return (Math.abs(current - last) > GAP_MAX_LEVEL); 560 return (Math.abs(current - last) > GAP_MAX_LEVEL);
387 } 561 }
388 562
389 563
564 /**
565 * This method returns the key which is used to retrieve the y-value served
566 * by a <code>Result</code> object.
567 *
568 * @param first <code>Result</code> object - not used in this class.
569 * @param second <code>Result</code> object - not used in this class.
570 *
571 * @return the string "KPOSITION"
572 */
390 protected String getDependendAxisName(Result first, Result second) { 573 protected String getDependendAxisName(Result first, Result second) {
391 return "KPOSITION"; 574 return "KPOSITION";
392 } 575 }
393 } 576 }
394 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 577 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org