comparison artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadM3AProcessor.java @ 7685:270946b97539

(issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors This also removes duplicated code by basing the TA and MA processors on the same class
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 11 Dec 2013 17:13:26 +0100
parents e97867879a45
children eb48b244921d
comparison
equal deleted inserted replaced
7684:0141908fafe0 7685:270946b97539
3 * 3 *
4 * This file is Free Software under the GNU AGPL (>=v3) 4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the 5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8
9 package org.dive4elements.river.exports.process; 8 package org.dive4elements.river.exports.process;
10 9
11 import java.util.Set; 10 import org.apache.log4j.Logger;
12 11
13 import org.apache.log4j.Logger;
14 import org.jfree.data.xy.XYSeries;
15
16 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
17 import org.dive4elements.artifacts.CallContext;
18 import org.dive4elements.river.artifacts.model.FacetTypes; 12 import org.dive4elements.river.artifacts.model.FacetTypes;
19 import org.dive4elements.river.exports.DiagramGenerator; 13 import org.dive4elements.river.exports.DiagramGenerator;
20 import org.dive4elements.river.exports.StyledSeriesBuilder;
21 import org.dive4elements.river.jfree.StyledXYSeries;
22 import org.dive4elements.river.themes.ThemeDocument;
23 14
24 import org.dive4elements.river.artifacts.model.minfo.SedimentLoad; 15 public class SedimentLoadM3AProcessor extends SedimentLoadProcessor {
25 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFraction;
26
27 public class SedimentLoadM3AProcessor extends DefaultProcessor {
28 16
29 private final static Logger logger = 17 private final static Logger logger =
30 Logger.getLogger(SedimentLoadM3AProcessor.class); 18 Logger.getLogger(SedimentLoadM3AProcessor.class);
31 19
32 public static final String I18N_YAXIS_LABEL = 20 public static final String I18N_YAXIS_LABEL =
33 "chart.sedimentload.ls.yaxis.label.m3pera"; 21 "chart.sedimentload.ls.yaxis.label.m3pera";
34 public static final String I18N_YAXIS_LABEL_DEFAULT = "[m\u00b3/a]"; 22 public static final String I18N_YAXIS_LABEL_DEFAULT = "[m\u00b3/a]";
35
36 @Override
37 public void doOut(
38 DiagramGenerator generator,
39 ArtifactAndFacet bundle,
40 ThemeDocument theme,
41 boolean visible) {
42 logger.debug("doOut " + bundle.getFacetName());
43 CallContext context = generator.getCallContext();
44 XYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
45 theme);
46 Object data = bundle.getData(context);
47 String facetName = bundle.getFacetName();
48 double [][] points;
49
50 if (FacetTypes.IS.SEDIMENT_LOAD_M3A(facetName)) {
51 points = (double[][]) data;
52 } else if (FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facetName)) {
53 SedimentLoad load = (SedimentLoad) data;
54 Set<Double> kms = load.getKms();
55 points = new double[2][kms.size()];
56 int counter = 0;
57 for (Double km: kms) {
58 SedimentLoadFraction fraction = load.getFraction(km);
59 points[0][counter] = km;
60 points[1][counter] = fraction.getUnknown();
61 counter++;
62 }
63 } else {
64 logger.error("Unknown facet name: " + facetName);
65 return;
66 }
67
68 StyledSeriesBuilder.addPoints(series, points, true);
69
70 generator.addAxisSeries(series, axisName, visible);
71 }
72 23
73 @Override 24 @Override
74 public boolean canHandle(String facettype) { 25 public boolean canHandle(String facettype) {
75 return FacetTypes.IS.SEDIMENT_LOAD_M3A(facettype) || 26 return FacetTypes.IS.SEDIMENT_LOAD_M3A(facettype) ||
76 FacetTypes.SEDIMENT_LOAD_M3A_UNKNOWN.equals(facettype); 27 FacetTypes.SEDIMENT_LOAD_M3A_UNKNOWN.equals(facettype);

http://dive4elements.wald.intevation.org