[PATCH 1 of 3] issue1378: Also add ability to add text-annotations
Wald Commits
scm-commit at wald.intevation.org
Wed Aug 21 14:52:07 CEST 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1377080685 -7200
# Node ID 5a1078fd53e112359124b377a57a406784a10c32
# Parent b410729bdcdd3f84a358791d43fe619466cb0dcc
issue1378: Also add ability to add text-annotations.
diff -r b410729bdcdd -r 5a1078fd53e1 artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java Wed Aug 21 12:01:50 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java Wed Aug 21 12:24:45 2013 +0200
@@ -8,10 +8,15 @@
package org.dive4elements.river.exports;
+import java.util.ArrayList;
+import java.util.List;
+
import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.river.artifacts.model.FacetTypes;
import org.dive4elements.river.artifacts.model.WQKms;
+import org.dive4elements.river.exports.process.DischargeProcessor;
+import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation;
import org.dive4elements.river.jfree.Bounds;
import org.dive4elements.river.jfree.RiverAnnotation;
import org.dive4elements.river.jfree.StickyAxisAnnotation;
@@ -19,6 +24,7 @@
import org.dive4elements.river.model.Gauge;
import org.dive4elements.river.model.River;
import org.dive4elements.river.utils.RiverUtils;
+import org.dive4elements.river.utils.ThemeUtil;
import org.apache.log4j.Logger;
import org.jfree.chart.annotations.XYTextAnnotation;
@@ -279,6 +285,28 @@
addAxisSeries(series, YAXIS.W.idx, visible);
}
+
+ /** Add a point annotation at given x and y coordinates. */
+ protected void addPointTextAnnotation(
+ String title,
+ double x,
+ double y,
+ Document theme
+ ) {
+ List<XYTextAnnotation> textAnnos =
+ new ArrayList<XYTextAnnotation>();
+ XYTextAnnotation anno = new CollisionFreeXYTextAnnotation(
+ title,
+ x,
+ y);
+ textAnnos.add(anno);
+ RiverAnnotation flysAnno = new RiverAnnotation(
+ null, null, null, theme);
+ flysAnno.setTextAnnotations(textAnnos);
+ addAnnotations(flysAnno);
+ }
+
+
/**
* Add WQ Data to plot.
* @param wq data as double[][]
@@ -291,8 +319,9 @@
) {
logger.debug("DischargeCurveGenerator: doWQOut");
double [][] data = (double [][]) wq;
+ String title = aaf.getFacetDescription();
- XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme);
+ XYSeries series = new StyledXYSeries(title, theme);
double translate = getCurrentGaugeDatum();
if (translate != 0d) {
@@ -303,6 +332,23 @@
StyledSeriesBuilder.addPoints(series, data, true);
addAxisSeries(series, YAXIS.W.idx, visible);
}
+
+ if(visible && ThemeUtil.parseShowPointLabel(theme)
+ && data != null && data.length != 0) {
+
+ double[] xs = data[0];
+ double[] ys = data[1];
+ for (int i = 0; i < xs.length; i++) {
+ double x = xs[i];
+ double y = ys[i];
+
+ if (translate != 0d) {
+ y = (y-translate)*100d;
+ }
+
+ addPointTextAnnotation(title, x, y, theme);
+ }
+ }
}
}
More information about the Dive4elements-commits
mailing list