Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java @ 1089:e298c4d28927
Improved mainvalues rendering.
flys-artifacts/trunk@2592 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 26 Aug 2011 11:15:24 +0000 |
parents | 07878836ee0d |
children | 0eb585cd3882 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Fri Aug 26 11:11:46 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Fri Aug 26 11:15:24 2011 +0000 @@ -11,18 +11,19 @@ import org.jfree.data.xy.XYSeries; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.annotations.XYAnnotation; import de.intevation.artifacts.Artifact; import de.intevation.artifactdatabase.state.Facet; import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.model.NamedDouble; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.WQKms; import de.intevation.flys.jfree.StickyAxisAnnotation; -import de.intevation.flys.model.MainValue; /** * An OutGenerator that generates discharge curves. @@ -50,11 +51,8 @@ public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve"; public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; - /** List of W MainValues (Annotations in plot). */ - protected static List<MainValue> mainValuesW; - - /** List of Q MainValues (Annotations in plot). */ - protected static List<MainValue> mainValuesQ; + /** List of Annotations (specifically, Main Values). */ + protected List<XYAnnotation> annotations; // TODO Add pseudodataseries for having mainvalue-text in legend. // TODO Let theme pass through to annotations-facets. @@ -63,8 +61,7 @@ /** Trivial Constructor. */ public ComputedDischargeCurveGenerator () { super(); - mainValuesQ = new ArrayList<MainValue>(); - mainValuesW = new ArrayList<MainValue>(); + annotations= new ArrayList<XYAnnotation>(); } @@ -112,10 +109,10 @@ doQOut((WQKms) f.getData(artifact, context), attr); } else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)) { - doMainValueWAnnotations(f.getData(artifact, context), attr); + doMainValueQAnnotations(f.getData(artifact, context), attr); } else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)) { - doMainValueQAnnotations(f.getData(artifact, context), attr); + doMainValueWAnnotations(f.getData(artifact, context), attr); } else { logger.warn("Unknown facet type for computed discharge: " + name); @@ -129,7 +126,15 @@ */ protected void doMainValueWAnnotations(Object o, Document theme) { logger.debug("ComputedDischargeCurveGenerator set W MainValues."); - this.mainValuesW = (List<MainValue>) o; + List<NamedDouble> mainValuesW = (List<NamedDouble>) o; + for (NamedDouble mv: mainValuesW) { + float pos = (float) mv.getValue(); + String text = mv.getName(); + StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos, + StickyAxisAnnotation.SimpleAxis.Y_AXIS); + logger.debug("Adding W: " + text + " : " + pos); + this.annotations.add(ta); + } } @@ -138,7 +143,13 @@ */ protected void doMainValueQAnnotations(Object o, Document theme) { logger.debug("ComputedDischargeCurveGenerator set Q MainValues."); - this.mainValuesQ = (List<MainValue>) o; + List<NamedDouble> mainValuesQ = (List<NamedDouble>) o; + for (NamedDouble mv: mainValuesQ) { + float pos = (float) mv.getValue(); + String text = mv.getName(); + StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos); + this.annotations.add(ta); + } } @@ -147,7 +158,7 @@ public JFreeChart generateChart() { JFreeChart c = super.generateChart(); XYPlot p = (XYPlot) c.getPlot(); - redoAnnotations(p, p.getDomainAxis()); + redoAnnotations(p); return c; } @@ -156,24 +167,12 @@ * Recalculate some annotation positions and add them to plot. * Annotations represent MainValues. * @param plot Plot to add annotations to. - * @param valueAxis ignored. */ - protected void redoAnnotations(XYPlot plot, ValueAxis axis) { + protected void redoAnnotations(XYPlot plot) { plot.clearAnnotations(); - // Add all MainValues as annotations. - for (MainValue mv: mainValuesQ) { - float pos = mv.getValue().floatValue(); - String text = mv.getMainValue().getName(); - StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos, - StickyAxisAnnotation.SimpleAxis.X_AXIS); - plot.getRenderer().addAnnotation(ta); - } - for (MainValue mv: mainValuesW) { - float pos = mv.getValue().floatValue(); - String text = mv.getMainValue().getName(); - StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos, - StickyAxisAnnotation.SimpleAxis.Y_AXIS); - plot.getRenderer().addAnnotation(ta); + + for (XYAnnotation a: annotations) { + plot.addAnnotation(a, false); } }