Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDeltaWtGenerator.java @ 3212:abc2db630815
Work in generalized annotations for chart generators
flys-artifacts/trunk@4835 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Fri, 29 Jun 2012 12:35:06 +0000 |
parents | ae14f412ba10 |
children | 1aec30e75bcb |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDeltaWtGenerator.java Thu Jun 28 16:20:33 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDeltaWtGenerator.java Fri Jun 29 12:35:06 2012 +0000 @@ -16,6 +16,8 @@ import de.intevation.flys.exports.TimeseriesChartGenerator; +import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation; +import de.intevation.flys.jfree.FLYSAnnotation; import de.intevation.flys.jfree.StyledTimeSeries; import de.intevation.flys.utils.FLYSUtils; @@ -25,12 +27,20 @@ import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + import javax.xml.xpath.XPathConstants; import org.apache.log4j.Logger; import org.jfree.chart.JFreeChart; +import org.jfree.chart.annotations.XYTextAnnotation; + import org.jfree.chart.plot.IntervalMarker; import org.jfree.chart.plot.ValueMarker; @@ -246,10 +256,20 @@ TimeSeries interpol = new StyledTimeSeries(desc + "interpol", theme); if (qwds == null) { + logger.debug("doAnalysisEventsOut: qwds == null"); return; } + + if (qwds.length == 0) { + logger.debug("doAnalysisEventsOut: qwds.length == 0"); + return; + } + + Map<Integer, int[]> annoIdxMap = new HashMap<Integer, int[]>(); + for (int i = 0; i < qwds.length; i++) { if (qwds[i] == null) { + logger.debug("doAnalysisEventsOut: qwds[" + i + "] == null"); continue; } RegularTimePeriod rtp = new Day(qwds[i].getDate()); @@ -259,6 +279,9 @@ interpol.add(rtp, value); } else { + annoIdxMap.put( + i, + new int[]{series.getItemCount(), tsc.getSeriesCount()}); series.add(rtp, value); } } @@ -267,6 +290,30 @@ addAxisDataset(tsc, 0, visible); addAttribute(desc + "interpol", "interpolate"); addAttribute(desc, "outline"); + + doQWDTextAnnotations(annoIdxMap, tsc, qwds, theme, visible); + } + + + protected void doQWDTextAnnotations(Map<Integer, int[]> annoIdxMap, + TimeSeriesCollection tsc, QWD[] qwds, Document theme, boolean visible) { + List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>(); + Set<Map.Entry<Integer, int[]>> entries = annoIdxMap.entrySet(); + for(Map.Entry<Integer, int[]> entry : entries) { + QWD qwd = qwds[entry.getKey()]; + int[] idxs = entry.getValue(); + double x = tsc.getXValue(idxs[0], idxs[1]); + XYTextAnnotation anno = new CollisionFreeXYTextAnnotation( + qwd.getQ() + " m\u00B3/s", + x, + qwd.getDeltaW()); + textAnnos.add(anno); + logger.debug("annotation: " + x + "/" + qwd.getDeltaW()); + } + + FLYSAnnotation flysAnno = new FLYSAnnotation(null, null, null, theme); + flysAnno.setTextAnnotations(textAnnos); + addAnnotations(flysAnno, visible); } @@ -288,6 +335,9 @@ if (qwds == null) { return; } + + Map<Integer, int[]> annoIdxMap = new HashMap<Integer, int[]>(); + for (int i = 0; i < qwds.length; i++) { if (qwds[i] == null) { continue; @@ -299,8 +349,12 @@ interpol.addOrUpdate(rtp, value); } else { + annoIdxMap.put( + i, + new int[]{series.getItemCount(), tsc.getSeriesCount()}); series.addOrUpdate(rtp, value); } + } tsc.addSeries(series); tsc.addSeries(interpol); @@ -308,6 +362,8 @@ addAxisDataset(tsc, 0, visible); addAttribute(desc + "interpol", "interpolate"); addAttribute(desc, "outline"); + + //doQWDTextAnnotations(annoIdxMap, tsc, qwds, theme, visible); }