comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java @ 1085:07878836ee0d

Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale. flys-artifacts/trunk@2588 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 26 Aug 2011 08:49:18 +0000
parents d0db31d1f64c
children e298c4d28927
comparison
equal deleted inserted replaced
1084:583314dafdb6 1085:07878836ee0d
1 package de.intevation.flys.exports; 1 package de.intevation.flys.exports;
2
3 import org.apache.log4j.Logger; 2 import org.apache.log4j.Logger;
4 3
5 import java.util.ArrayList; 4 import java.util.ArrayList;
6 import java.util.List; 5 import java.util.List;
7 6
10 import org.jfree.chart.JFreeChart; 9 import org.jfree.chart.JFreeChart;
11 import org.jfree.chart.title.TextTitle; 10 import org.jfree.chart.title.TextTitle;
12 import org.jfree.data.xy.XYSeries; 11 import org.jfree.data.xy.XYSeries;
13 import org.jfree.chart.axis.ValueAxis; 12 import org.jfree.chart.axis.ValueAxis;
14 import org.jfree.chart.plot.XYPlot; 13 import org.jfree.chart.plot.XYPlot;
15 import org.jfree.ui.TextAnchor;
16 14
17 import de.intevation.artifacts.Artifact; 15 import de.intevation.artifacts.Artifact;
18 16
19 import de.intevation.artifactdatabase.state.Facet; 17 import de.intevation.artifactdatabase.state.Facet;
20 18
21 import de.intevation.flys.artifacts.FLYSArtifact; 19 import de.intevation.flys.artifacts.FLYSArtifact;
22 import de.intevation.flys.artifacts.model.FacetTypes; 20 import de.intevation.flys.artifacts.model.FacetTypes;
23 import de.intevation.flys.artifacts.model.WQKms; 21 import de.intevation.flys.artifacts.model.WQKms;
22
24 import de.intevation.flys.jfree.StickyAxisAnnotation; 23 import de.intevation.flys.jfree.StickyAxisAnnotation;
25 24
26 import de.intevation.flys.model.MainValue; 25 import de.intevation.flys.model.MainValue;
27 26
28 /** 27 /**
49 "chart.computed.discharge.curve.yaxis.label"; 48 "chart.computed.discharge.curve.yaxis.label";
50 49
51 public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve"; 50 public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve";
52 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; 51 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]";
53 52
54 /** List of MainValues (Annotations in plot). */ 53 /** List of W MainValues (Annotations in plot). */
55 protected static List<MainValue> mainValues; 54 protected static List<MainValue> mainValuesW;
55
56 /** List of Q MainValues (Annotations in plot). */
57 protected static List<MainValue> mainValuesQ;
58
59 // TODO Add pseudodataseries for having mainvalue-text in legend.
60 // TODO Let theme pass through to annotations-facets.
56 61
57 62
58 /** Trivial Constructor. */ 63 /** Trivial Constructor. */
59 public ComputedDischargeCurveGenerator () { 64 public ComputedDischargeCurveGenerator () {
60 super(); 65 super();
61 mainValues = new ArrayList<MainValue>(); 66 mainValuesQ = new ArrayList<MainValue>();
67 mainValuesW = new ArrayList<MainValue>();
62 } 68 }
63 69
64 70
65 @Override 71 @Override
66 protected String getChartTitle() { 72 protected String getChartTitle() {
92 public void doOut(Artifact artifact, Facet facet, Document attr) { 98 public void doOut(Artifact artifact, Facet facet, Document attr) {
93 String name = (facet != null) ? facet.getName() : null; 99 String name = (facet != null) ? facet.getName() : null;
94 100
95 logger.debug("ComputedDischargeCurveGenerator.doOut: " + name); 101 logger.debug("ComputedDischargeCurveGenerator.doOut: " + name);
96 102
103 if (name == null) {
104 logger.warn("Broken facet in computed discharge out generation.");
105 return;
106 }
107
97 FLYSArtifact flys = (FLYSArtifact) artifact; 108 FLYSArtifact flys = (FLYSArtifact) artifact;
98 Facet f = flys.getNativeFacet(facet); 109 Facet f = flys.getNativeFacet(facet);
99 110
100 if (name.equals(COMPUTED_DISCHARGE_Q)) { 111 if (name.equals(COMPUTED_DISCHARGE_Q)) {
101 doQOut((WQKms) f.getData(artifact, context), attr); 112 doQOut((WQKms) f.getData(artifact, context), attr);
102 } 113 }
103 else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES)) { 114 else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)) {
104 doMainValueAnnotations(f.getData(artifact, context), attr); 115 doMainValueWAnnotations(f.getData(artifact, context), attr);
116 }
117 else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)) {
118 doMainValueQAnnotations(f.getData(artifact, context), attr);
105 } 119 }
106 else { 120 else {
107 logger.warn("Unknown facet type for computed discharge: " + name); 121 logger.warn("Unknown facet type for computed discharge: " + name);
108 return; 122 return;
109 } 123 }
110 } 124 }
111 125
112 126
113 /** 127 /**
114 * Add MainValues as annotations to plot. 128 * Store W MainValues as annotations for later plotting.
115 */ 129 */
116 protected void doMainValueAnnotations(Object o, Document theme) { 130 protected void doMainValueWAnnotations(Object o, Document theme) {
117 this.mainValues = (List<MainValue>) o; 131 logger.debug("ComputedDischargeCurveGenerator set W MainValues.");
132 this.mainValuesW = (List<MainValue>) o;
133 }
134
135
136 /**
137 * Store Q MainValues as annotations for later plotting.
138 */
139 protected void doMainValueQAnnotations(Object o, Document theme) {
140 logger.debug("ComputedDischargeCurveGenerator set Q MainValues.");
141 this.mainValuesQ = (List<MainValue>) o;
118 } 142 }
119 143
120 144
121 /** Generate Chart with annotations. */ 145 /** Generate Chart with annotations. */
122 @Override 146 @Override
134 * @param plot Plot to add annotations to. 158 * @param plot Plot to add annotations to.
135 * @param valueAxis ignored. 159 * @param valueAxis ignored.
136 */ 160 */
137 protected void redoAnnotations(XYPlot plot, ValueAxis axis) { 161 protected void redoAnnotations(XYPlot plot, ValueAxis axis) {
138 plot.clearAnnotations(); 162 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. 163 // Add all MainValues as annotations.
150 // TODO Implement and handle second facet for annotations on 164 for (MainValue mv: mainValuesQ) {
151 // vertical axis. 165 float pos = mv.getValue().floatValue();
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(); 166 String text = mv.getMainValue().getName();
159 StickyAxisAnnotation ta = new StickyAxisAnnotation(text, posX, posY); 167 StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos,
168 StickyAxisAnnotation.SimpleAxis.X_AXIS);
169 plot.getRenderer().addAnnotation(ta);
170 }
171 for (MainValue mv: mainValuesW) {
172 float pos = mv.getValue().floatValue();
173 String text = mv.getMainValue().getName();
174 StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos,
175 StickyAxisAnnotation.SimpleAxis.Y_AXIS);
160 plot.getRenderer().addAnnotation(ta); 176 plot.getRenderer().addAnnotation(ta);
161 } 177 }
162 } 178 }
163 179
164 180

http://dive4elements.wald.intevation.org