Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/process/SQRelationProcessor.java @ 7240:bb4a6b0077cf
Add SQRelation Processor
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 04 Oct 2013 17:00:05 +0200 |
parents | |
children | e3f2d8c006fb |
comparison
equal
deleted
inserted
replaced
7239:a62c5b48ccab | 7240:bb4a6b0077cf |
---|---|
1 /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.exports.process; | |
10 | |
11 import org.apache.log4j.Logger; | |
12 import org.jfree.data.xy.XYSeries; | |
13 | |
14 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
15 import org.dive4elements.artifacts.CallContext; | |
16 import org.dive4elements.river.exports.DiagramGenerator; | |
17 import org.dive4elements.river.jfree.StyledXYSeries; | |
18 import org.dive4elements.river.themes.ThemeDocument; | |
19 import org.dive4elements.river.artifacts.model.FacetTypes; | |
20 | |
21 import org.dive4elements.river.jfree.JFreeUtil; | |
22 | |
23 import org.dive4elements.river.artifacts.model.sq.SQ; | |
24 import org.dive4elements.river.artifacts.model.sq.SQFunction; | |
25 | |
26 public class SQRelationProcessor extends DefaultProcessor { | |
27 | |
28 public static final String I18N_AXIS_LABEL = | |
29 "chart.sq_relation.yaxis.label"; | |
30 public static final String I18N_AXIS_LABEL_DEFAULT = | |
31 ""; | |
32 | |
33 private final static Logger logger = | |
34 Logger.getLogger(SQRelationProcessor.class); | |
35 | |
36 @Override | |
37 public void doOut( | |
38 DiagramGenerator generator, | |
39 ArtifactAndFacet bundle, | |
40 ThemeDocument theme, | |
41 boolean visible) { | |
42 CallContext context = generator.getCallContext(); | |
43 String facetName = bundle.getFacetName(); | |
44 XYSeries series; | |
45 Object data = bundle.getData(context); | |
46 String desc = bundle.getFacetDescription(); | |
47 | |
48 if (data == null) { | |
49 // Check has been here before so we keep it but | |
50 // this should never happen. | |
51 logger.error("Data is null for facet: " + facetName); | |
52 return; | |
53 } | |
54 | |
55 if (FacetTypes.IS.SQ_CURVE(facetName)) { | |
56 SQFunction func = (SQFunction) data; | |
57 | |
58 series = JFreeUtil.sampleFunction2DPositive( | |
59 func.getFunction(), | |
60 theme, | |
61 desc, | |
62 500, | |
63 Math.max(func.getMinQ(), 0.01), | |
64 Math.max(func.getMaxQ(), 0.02)); | |
65 | |
66 } else if (FacetTypes.IS.SQ_MEASUREMENT(facetName) || | |
67 FacetTypes.IS.SQ_OUTLIER(facetName)) { | |
68 | |
69 SQ[] sqs = (SQ[]) data; | |
70 series = new StyledXYSeries(desc, theme); | |
71 | |
72 for (SQ sq: sqs) { | |
73 double q = sq.getQ(); | |
74 double s = sq.getS(); | |
75 if (s > 0d && q > 0d) { | |
76 series.add(q, s, false); | |
77 } | |
78 } | |
79 } else { | |
80 logger.error("Could not handle: " + facetName); | |
81 return; | |
82 } | |
83 | |
84 if (logger.isDebugEnabled()) { | |
85 logger.debug("Series '" + desc + "' has " | |
86 + series.getItemCount() + " items."); | |
87 | |
88 logger.debug(" -> min x = " + series.getMinX()); | |
89 logger.debug(" -> max x = " + series.getMaxX()); | |
90 logger.debug(" -> min y = " + series.getMinY()); | |
91 logger.debug(" -> max y = " + series.getMaxY()); | |
92 } | |
93 | |
94 generator.addAxisSeries(series, axisName, visible); | |
95 } | |
96 | |
97 @Override | |
98 public boolean canHandle(String facettype) { | |
99 return FacetTypes.IS.SQ_CURVE(facettype) || | |
100 FacetTypes.IS.SQ_MEASUREMENT(facettype) || | |
101 FacetTypes.IS.SQ_OUTLIER(facettype); | |
102 } | |
103 | |
104 @Override | |
105 public String getAxisLabel(DiagramGenerator generator) { | |
106 return generator.msg( | |
107 I18N_AXIS_LABEL, | |
108 I18N_AXIS_LABEL_DEFAULT); | |
109 } | |
110 } |