Mercurial > dive4elements > river
changeset 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 | f16b66839e59 |
children | 583314dafdb6 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java |
diffstat | 2 files changed, 85 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Aug 25 10:50:30 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Aug 25 10:53:25 2011 +0000 @@ -1,3 +1,9 @@ +2011-08-25 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + * src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java: + Plot MainValues delivered by MainValuesFacet in much the same ways than + Annotations in LongitudinalSection plots. + 2011-08-25 Felix Wolfsteller <felix.wolfsteller@intevation.de> * src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Thu Aug 25 10:50:30 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Thu Aug 25 10:53:25 2011 +0000 @@ -2,11 +2,17 @@ import org.apache.log4j.Logger; +import java.util.ArrayList; +import java.util.List; + import org.w3c.dom.Document; import org.jfree.chart.JFreeChart; import org.jfree.chart.title.TextTitle; import org.jfree.data.xy.XYSeries; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.XYPlot; +import org.jfree.ui.TextAnchor; import de.intevation.artifacts.Artifact; @@ -15,7 +21,9 @@ import de.intevation.flys.artifacts.FLYSArtifact; 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. @@ -43,6 +51,16 @@ public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve"; public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; + /** List of MainValues (Annotations in plot). */ + protected static List<MainValue> mainValues; + + + /** Trivial Constructor. */ + public ComputedDischargeCurveGenerator () { + super(); + mainValues = new ArrayList<MainValue>(); + } + @Override protected String getChartTitle() { @@ -79,9 +97,12 @@ FLYSArtifact flys = (FLYSArtifact) artifact; Facet f = flys.getNativeFacet(facet); - if (name != null && name.equals(COMPUTED_DISCHARGE_Q)) { + if (name.equals(COMPUTED_DISCHARGE_Q)) { doQOut((WQKms) f.getData(artifact, context), attr); } + else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES)) { + doMainValueAnnotations(f.getData(artifact, context), attr); + } else { logger.warn("Unknown facet type for computed discharge: " + name); return; @@ -89,6 +110,63 @@ } + /** + * Add MainValues as annotations to plot. + */ + protected void doMainValueAnnotations(Object o, Document theme) { + this.mainValues = (List<MainValue>) o; + } + + + /** Generate Chart with annotations. */ + @Override + public JFreeChart generateChart() { + JFreeChart c = super.generateChart(); + XYPlot p = (XYPlot) c.getPlot(); + redoAnnotations(p, p.getDomainAxis()); + return c; + } + + + /** + * 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) { + plot.clearAnnotations(); + ValueAxis yAxis = plot.getRangeAxis(); + float posY = 140.f; + if (yAxis != null) { + posY = (float) yAxis.getRange().getLowerBound(); + // Add some (2%) space between Text and axis. + // TODO have all the position logic in StickyAxisAnnotation + // (then merge LongitudinalSectioNGenerator). + posY += 0.02f * (yAxis.getRange().getUpperBound() + - yAxis.getRange().getLowerBound()); + } + // Add all MainValues as annotations. + // TODO Implement and handle second facet for annotations on + // vertical axis. + for (MainValue mv: mainValues) { + if (mv.getMainValue().getType().getName() == "W") { + continue; + } + float posX = mv.getValue().floatValue(); + + String text = mv.getMainValue().getName(); + StickyAxisAnnotation ta = new StickyAxisAnnotation(text, posX, posY); + plot.getRenderer().addAnnotation(ta); + } + } + + + /** + * Add Q-Series to plot. + * @param wqkms actual data + * @param theme theme to use. + */ protected void doQOut(WQKms wqkms, Document theme) { int size = wqkms.size();