comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java @ 1083:d0db31d1f64c

Enable plotting of some annotations that look like MainValues. flys-artifacts/trunk@2580 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 25 Aug 2011 10:53:25 +0000
parents d10efbe2e5c0
children 07878836ee0d
comparison
equal deleted inserted replaced
1082:f16b66839e59 1083:d0db31d1f64c
1 package de.intevation.flys.exports; 1 package de.intevation.flys.exports;
2 2
3 import org.apache.log4j.Logger; 3 import org.apache.log4j.Logger;
4
5 import java.util.ArrayList;
6 import java.util.List;
4 7
5 import org.w3c.dom.Document; 8 import org.w3c.dom.Document;
6 9
7 import org.jfree.chart.JFreeChart; 10 import org.jfree.chart.JFreeChart;
8 import org.jfree.chart.title.TextTitle; 11 import org.jfree.chart.title.TextTitle;
9 import org.jfree.data.xy.XYSeries; 12 import org.jfree.data.xy.XYSeries;
13 import org.jfree.chart.axis.ValueAxis;
14 import org.jfree.chart.plot.XYPlot;
15 import org.jfree.ui.TextAnchor;
10 16
11 import de.intevation.artifacts.Artifact; 17 import de.intevation.artifacts.Artifact;
12 18
13 import de.intevation.artifactdatabase.state.Facet; 19 import de.intevation.artifactdatabase.state.Facet;
14 20
15 import de.intevation.flys.artifacts.FLYSArtifact; 21 import de.intevation.flys.artifacts.FLYSArtifact;
16 import de.intevation.flys.artifacts.model.FacetTypes; 22 import de.intevation.flys.artifacts.model.FacetTypes;
17 import de.intevation.flys.artifacts.model.WQKms; 23 import de.intevation.flys.artifacts.model.WQKms;
24 import de.intevation.flys.jfree.StickyAxisAnnotation;
18 25
26 import de.intevation.flys.model.MainValue;
19 27
20 /** 28 /**
21 * An OutGenerator that generates discharge curves. 29 * An OutGenerator that generates discharge curves.
22 * 30 *
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 31 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
40 public static final String I18N_YAXIS_LABEL = 48 public static final String I18N_YAXIS_LABEL =
41 "chart.computed.discharge.curve.yaxis.label"; 49 "chart.computed.discharge.curve.yaxis.label";
42 50
43 public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve"; 51 public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve";
44 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; 52 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]";
53
54 /** List of MainValues (Annotations in plot). */
55 protected static List<MainValue> mainValues;
56
57
58 /** Trivial Constructor. */
59 public ComputedDischargeCurveGenerator () {
60 super();
61 mainValues = new ArrayList<MainValue>();
62 }
45 63
46 64
47 @Override 65 @Override
48 protected String getChartTitle() { 66 protected String getChartTitle() {
49 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); 67 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
77 logger.debug("ComputedDischargeCurveGenerator.doOut: " + name); 95 logger.debug("ComputedDischargeCurveGenerator.doOut: " + name);
78 96
79 FLYSArtifact flys = (FLYSArtifact) artifact; 97 FLYSArtifact flys = (FLYSArtifact) artifact;
80 Facet f = flys.getNativeFacet(facet); 98 Facet f = flys.getNativeFacet(facet);
81 99
82 if (name != null && name.equals(COMPUTED_DISCHARGE_Q)) { 100 if (name.equals(COMPUTED_DISCHARGE_Q)) {
83 doQOut((WQKms) f.getData(artifact, context), attr); 101 doQOut((WQKms) f.getData(artifact, context), attr);
102 }
103 else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES)) {
104 doMainValueAnnotations(f.getData(artifact, context), attr);
84 } 105 }
85 else { 106 else {
86 logger.warn("Unknown facet type for computed discharge: " + name); 107 logger.warn("Unknown facet type for computed discharge: " + name);
87 return; 108 return;
88 } 109 }
89 } 110 }
90 111
91 112
113 /**
114 * Add MainValues as annotations to plot.
115 */
116 protected void doMainValueAnnotations(Object o, Document theme) {
117 this.mainValues = (List<MainValue>) o;
118 }
119
120
121 /** Generate Chart with annotations. */
122 @Override
123 public JFreeChart generateChart() {
124 JFreeChart c = super.generateChart();
125 XYPlot p = (XYPlot) c.getPlot();
126 redoAnnotations(p, p.getDomainAxis());
127 return c;
128 }
129
130
131 /**
132 * Recalculate some annotation positions and add them to plot.
133 * Annotations represent MainValues.
134 * @param plot Plot to add annotations to.
135 * @param valueAxis ignored.
136 */
137 protected void redoAnnotations(XYPlot plot, ValueAxis axis) {
138 plot.clearAnnotations();
139 ValueAxis yAxis = plot.getRangeAxis();
140 float posY = 140.f;
141 if (yAxis != null) {
142 posY = (float) yAxis.getRange().getLowerBound();
143 // Add some (2%) space between Text and axis.
144 // TODO have all the position logic in StickyAxisAnnotation
145 // (then merge LongitudinalSectioNGenerator).
146 posY += 0.02f * (yAxis.getRange().getUpperBound()
147 - yAxis.getRange().getLowerBound());
148 }
149 // Add all MainValues as annotations.
150 // TODO Implement and handle second facet for annotations on
151 // vertical axis.
152 for (MainValue mv: mainValues) {
153 if (mv.getMainValue().getType().getName() == "W") {
154 continue;
155 }
156 float posX = mv.getValue().floatValue();
157
158 String text = mv.getMainValue().getName();
159 StickyAxisAnnotation ta = new StickyAxisAnnotation(text, posX, posY);
160 plot.getRenderer().addAnnotation(ta);
161 }
162 }
163
164
165 /**
166 * Add Q-Series to plot.
167 * @param wqkms actual data
168 * @param theme theme to use.
169 */
92 protected void doQOut(WQKms wqkms, Document theme) { 170 protected void doQOut(WQKms wqkms, Document theme) {
93 int size = wqkms.size(); 171 int size = wqkms.size();
94 172
95 double[] res = new double[3]; 173 double[] res = new double[3];
96 174

http://dive4elements.wald.intevation.org