# HG changeset patch # User Ingo Weinzierl # Date 1317813798 0 # Node ID dd9dfe1e48fa48d399a814920d64464097a5494d # Parent 6e840e213fdf2b5005e03f6ced11c125017e60b5 Bugfixes for various issues: Improved rendering process of annotations. flys-artifacts/trunk@2894 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 6e840e213fdf -r dd9dfe1e48fa flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Oct 05 10:36:40 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Oct 05 11:23:18 2011 +0000 @@ -1,4 +1,27 @@ -2011-10-04 Sascha L. Teichmann +2011-10-05 Ingo Weinzierl + + flys/issue347 (W-INFO / Wasserspiegellagenberechnung, Längsschnittdiagramm) + flys/issue303 (Keine Streckenfavoriten, wenn nur Q im Längsschnittdiagram ausgewählt) + flys/issue353 (W-INFO / Wasserspiegellagenberechnung, Diagramm) + + * src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java: New. A + wrapper for Annotations which allows us to provide a description for a + set of annotations. + + * src/main/java/de/intevation/flys/artifacts/model/AnnotationFacet.java: + The getData() will now return an instance of FLYSAnnotation that wraps + the Annotations returned by the AnnotationArtifact. The lebel of + FLYSAnnotation is the description of this Facet. + + * src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java: + Modified the way to add Annotations. We will no longer create an empty + series to support a LegendItem for a set of Annotations, but we will add + a LegendItem manually to the LegendItemCollection of the plot. In + addition, we are now able to display annotations if one of the two + y-axes are missing. If there are no y-axes existing, we are not able to + display annotations yet. + +2011-10-05 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java: Lifted the wrong point. Now all backjump corrections look fine. :-) diff -r 6e840e213fdf -r dd9dfe1e48fa flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AnnotationFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AnnotationFacet.java Wed Oct 05 10:36:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AnnotationFacet.java Wed Oct 05 11:23:18 2011 +0000 @@ -1,11 +1,16 @@ package de.intevation.flys.artifacts.model; +import java.util.List; + import org.apache.log4j.Logger; import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.AnnotationArtifact; +import de.intevation.flys.jfree.FLYSAnnotation; + +import de.intevation.flys.model.Annotation; import de.intevation.artifactdatabase.state.DefaultFacet; import de.intevation.artifactdatabase.state.Facet; @@ -48,7 +53,9 @@ @Override public Object getData(Artifact artifact, CallContext context) { AnnotationArtifact annotationArtifact = (AnnotationArtifact) artifact; - return annotationArtifact.getAnnotations(); + List annotations = annotationArtifact.getAnnotations(); + + return new FLYSAnnotation(description, annotations); } diff -r 6e840e213fdf -r dd9dfe1e48fa flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Wed Oct 05 10:36:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Wed Oct 05 11:23:18 2011 +0000 @@ -6,13 +6,14 @@ import org.apache.log4j.Logger; import org.jfree.chart.JFreeChart; +import org.jfree.chart.LegendItem; +import org.jfree.chart.LegendItemCollection; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.title.TextTitle; import org.jfree.data.Range; import org.jfree.data.xy.XYSeries; -import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.TextAnchor; import org.w3c.dom.Document; @@ -26,6 +27,7 @@ import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.WQKms; +import de.intevation.flys.jfree.FLYSAnnotation; import de.intevation.flys.jfree.StickyAxisAnnotation; import de.intevation.flys.model.Annotation; import de.intevation.flys.utils.FLYSUtils; @@ -71,15 +73,12 @@ protected boolean inverted; /** List of annotations to insert in plot. */ - protected List annotations; - - /** Pseudo-Dataseries to have a legend for the annotations. */ - protected XYSeriesCollection pseudoAnnotationData = null; + protected List annotations; public LongitudinalSectionGenerator() { super(); - annotations = new ArrayList(); + annotations = new ArrayList(); } @@ -165,27 +164,53 @@ plot.clearAnnotations(); // TODO Position calculation could/should be done in // the StickyAxisAnnotation-Implementation itself. - ValueAxis yAxis = plot.getRangeAxis(); + + int idx = 0; + ValueAxis yAxis = plot.getRangeAxis(idx); + + if (yAxis == null) { + if (plot.getRangeAxisCount() >= 2) { + yAxis = plot.getRangeAxis(++idx); + } + } + + if (yAxis == null) { + // XXX There is no y-axis that might be used to add annotations. If + // we absolutely want to display annotations, we need to create a + // virtual dataset for an axis. + return; + } + float posY = 140.f; - if (yAxis != null) { - posY = (float) yAxis.getRange().getLowerBound(); - // Add some (2%) space between Text and axis. - posY += 0.02f * (yAxis.getRange().getUpperBound() - - yAxis.getRange().getLowerBound()); - } + posY = (float) yAxis.getRange().getLowerBound(); + // Add some (2%) space between Text and axis. + posY += 0.02f * (yAxis.getRange().getUpperBound() + - yAxis.getRange().getLowerBound()); + + LegendItemCollection lic = plot.getLegendItems(); // Add all annotations. - for (Annotation a: annotations) { - float posX = (float) a.getRange().getA().doubleValue(); - String text = a.getPosition().getValue(); + for (FLYSAnnotation fa: annotations) { + lic.add(new LegendItem(fa.getLabel())); - StickyAxisAnnotation ta = new StickyAxisAnnotation(text, posX, posY); - double rotation = 270.0f * (Math.PI / 180.0f); - ta.setRotationAngle(rotation); - ta.setRotationAnchor(TextAnchor.CENTER_LEFT); - ta.setTextAnchor(TextAnchor.CENTER_LEFT); - plot.getRenderer().addAnnotation(ta); + for (Annotation a: fa.getAnnotations()) { + float posX = (float) a.getRange().getA().doubleValue(); + String text = a.getPosition().getValue(); + + StickyAxisAnnotation ta = new StickyAxisAnnotation( + text, + posX, + posY); + + double rotation = 270.0f * (Math.PI / 180.0f); + ta.setRotationAngle(rotation); + ta.setRotationAnchor(TextAnchor.CENTER_LEFT); + ta.setTextAnchor(TextAnchor.CENTER_LEFT); + plot.getRenderer(idx).addAnnotation(ta); + } } + + plot.setFixedLegendItems(lic); } @@ -271,16 +296,10 @@ */ protected void doAnnotationsOut(Object o, Document theme) { logger.debug("LongitudinalSectionGenerator.doAnnotationsOut"); - this.annotations = (List) o; - // Add (empty) pseudo series to have legend entry for annotations. - if (pseudoAnnotationData == null) { - pseudoAnnotationData = new XYSeriesCollection(); - } - // Localized legend. - Object[] args = new Object[] {getRiverName()}; - String label = msg(I18N_ANNOTATIONS_LABEL, "", args); - pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme)); + // Add all annotations in list o to our annotation pool. + FLYSAnnotation fa = (FLYSAnnotation) o; + annotations.add(fa); } @@ -353,19 +372,6 @@ /** - * Add datasets to plot. - * @param plot plot to add datasets to. - */ - @Override - protected void addDatasets(XYPlot plot) { - super.addDatasets(plot); - if (pseudoAnnotationData != null) { - plot.setDataset(2, pseudoAnnotationData); - } - } - - - /** * Get name of series (displayed in legend). * @return name of the series. */ diff -r 6e840e213fdf -r dd9dfe1e48fa flys-artifacts/src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java Wed Oct 05 11:23:18 2011 +0000 @@ -0,0 +1,28 @@ +package de.intevation.flys.jfree; + +import java.util.List; + +import de.intevation.flys.model.Annotation; + + +public class FLYSAnnotation { + + protected List annotations; + + protected String label; + + + public FLYSAnnotation(String label, List annotations) { + this.label = label; + this.annotations = annotations; + } + + public String getLabel() { + return label; + } + + public List getAnnotations() { + return annotations; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :