Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/sq/SQRelationGenerator.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/sq/SQRelationGenerator.java@bd047b71ab37 |
children | 4897a58c8746 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.exports.sq; | |
2 | |
3 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
4 import org.dive4elements.artifactdatabase.state.Facet; | |
5 | |
6 import org.dive4elements.river.artifacts.model.FacetTypes; | |
7 | |
8 import org.dive4elements.river.artifacts.model.sq.SQ; | |
9 import org.dive4elements.river.artifacts.model.sq.SQFunction; | |
10 | |
11 import org.dive4elements.river.exports.XYChartGenerator; | |
12 | |
13 import org.dive4elements.river.jfree.JFreeUtil; | |
14 import org.dive4elements.river.jfree.StyledXYSeries; | |
15 | |
16 import org.apache.log4j.Logger; | |
17 | |
18 import org.jfree.chart.axis.LogarithmicAxis; | |
19 import org.jfree.chart.axis.NumberAxis; | |
20 | |
21 import org.jfree.data.xy.XYSeries; | |
22 | |
23 import org.w3c.dom.Document; | |
24 | |
25 /** | |
26 * An OutGenerator that generates charts for MINFO sq relation. | |
27 * | |
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
29 */ | |
30 public class SQRelationGenerator | |
31 extends XYChartGenerator | |
32 implements FacetTypes | |
33 { | |
34 public enum YAXIS { | |
35 S(0); | |
36 protected int idx; | |
37 private YAXIS(int c) { | |
38 idx = c; | |
39 } | |
40 } | |
41 | |
42 | |
43 public static final String I18N_XAXIS_LABEL = | |
44 "chart.sq_relation.xaxis.label"; | |
45 | |
46 public static final String I18N_YAXIS_LABEL = | |
47 "chart.sq_relation.yaxis.label"; | |
48 | |
49 | |
50 /** The logger that is used in this generator. */ | |
51 private static Logger logger = Logger.getLogger(SQRelationGenerator.class); | |
52 | |
53 | |
54 @Override | |
55 protected YAxisWalker getYAxisWalker() { | |
56 return new YAxisWalker() { | |
57 @Override | |
58 public int length() { | |
59 return YAXIS.values().length; | |
60 } | |
61 | |
62 @Override | |
63 public String getId(int idx) { | |
64 YAXIS[] yaxes = YAXIS.values(); | |
65 return yaxes[idx].toString(); | |
66 } | |
67 }; | |
68 } | |
69 | |
70 | |
71 @Override | |
72 public String getDefaultChartTitle() { | |
73 return "TODO: CHART TITLE"; | |
74 } | |
75 | |
76 | |
77 @Override | |
78 protected String getDefaultXAxisLabel() { | |
79 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL); | |
80 } | |
81 | |
82 | |
83 @Override | |
84 protected String getDefaultYAxisLabel(int index) { | |
85 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL); | |
86 } | |
87 | |
88 | |
89 @Override | |
90 protected NumberAxis createXAxis(String label) { | |
91 return new LogarithmicAxis(label); | |
92 } | |
93 | |
94 | |
95 @Override | |
96 protected NumberAxis createYAxis(int index) { | |
97 return new LogarithmicAxis(getDefaultYAxisLabel(index)); | |
98 } | |
99 | |
100 | |
101 @Override | |
102 public void doOut( | |
103 ArtifactAndFacet artifactAndFacet, | |
104 Document attr, | |
105 boolean visible | |
106 ) { | |
107 logger.debug("doOut"); | |
108 | |
109 Facet facet = artifactAndFacet.getFacet(); | |
110 String name = facet != null ? facet.getName() : null; | |
111 | |
112 if (name == null || name.length() == 0) { | |
113 logger.warn("Invalid facet with no name given!"); | |
114 return; | |
115 } | |
116 | |
117 if (IS.SQ_CURVE(name)) { | |
118 doSQCurveOut(artifactAndFacet, attr, visible); | |
119 } | |
120 else if (IS.SQ_MEASUREMENT(name)) { | |
121 doSQOut(artifactAndFacet, attr, visible); | |
122 } | |
123 else if (IS.SQ_OUTLIER(name)) { | |
124 doSQOut(artifactAndFacet, attr, visible); | |
125 } | |
126 else if (IS.MANUALPOINTS(name)) { | |
127 doPoints( | |
128 artifactAndFacet.getData(context), | |
129 artifactAndFacet, | |
130 attr, | |
131 visible, | |
132 YAXIS.S.idx); | |
133 } | |
134 } | |
135 | |
136 | |
137 protected void doSQCurveOut( | |
138 ArtifactAndFacet artifactAndFacet, | |
139 Document attr, | |
140 boolean visible | |
141 ) { | |
142 String desc = artifactAndFacet.getFacetDescription(); | |
143 logger.debug("doSQCurveOut: " + desc); | |
144 | |
145 SQFunction func = (SQFunction) artifactAndFacet.getData(context); | |
146 | |
147 if (func == null) { | |
148 return; | |
149 } | |
150 | |
151 XYSeries series = JFreeUtil.sampleFunction2DPositive( | |
152 func.getFunction(), | |
153 attr, | |
154 desc, | |
155 500, | |
156 Math.max(func.getMinQ(), 0.01), | |
157 Math.max(func.getMaxQ(), 0.02)); | |
158 | |
159 if (logger.isDebugEnabled()) { | |
160 logger.debug("Series '" + desc + "' has " | |
161 + series.getItemCount() + " items."); | |
162 | |
163 logger.debug(" -> min x = " + series.getMinX()); | |
164 logger.debug(" -> max x = " + series.getMaxX()); | |
165 logger.debug(" -> min y = " + series.getMinY()); | |
166 logger.debug(" -> max y = " + series.getMaxY()); | |
167 } | |
168 | |
169 addAxisSeries(series, YAXIS.S.idx, visible); | |
170 } | |
171 | |
172 | |
173 protected void doSQOut( | |
174 ArtifactAndFacet artifactAndFacet, | |
175 Document attr, | |
176 boolean visible | |
177 ) { | |
178 String desc = artifactAndFacet.getFacetDescription(); | |
179 logger.debug("doSQOut: " + desc); | |
180 | |
181 SQ[] sqs = (SQ[]) artifactAndFacet.getData(context); | |
182 if (sqs == null) { | |
183 logger.debug("No SQs found for facet"); | |
184 return; | |
185 } | |
186 XYSeries series = new StyledXYSeries(desc, attr); | |
187 | |
188 for (SQ sq: sqs) { | |
189 double q = sq.getQ(); | |
190 double s = sq.getS(); | |
191 if (s > 0d && q > 0d) { | |
192 series.add(q, s, false); | |
193 } | |
194 } | |
195 | |
196 if (logger.isDebugEnabled()) { | |
197 logger.debug("Series '" + desc + "' has " | |
198 + series.getItemCount() + " items."); | |
199 | |
200 logger.debug(" -> min x = " + series.getMinX()); | |
201 logger.debug(" -> max x = " + series.getMaxX()); | |
202 logger.debug(" -> min y = " + series.getMinY()); | |
203 logger.debug(" -> max y = " + series.getMaxY()); | |
204 } | |
205 | |
206 addAxisSeries(series, YAXIS.S.idx, visible); | |
207 } | |
208 } | |
209 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |