Mercurial > dive4elements > river
changeset 7893:56e7e6c18c26 facet-metadata
Use the metadata to write csv header when exporting a chart.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 21 May 2014 11:41:06 +0200 |
parents | e844be34a606 |
children | 42076d94977e |
files | artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java |
diffstat | 1 files changed, 31 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java Wed May 21 11:40:14 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java Wed May 21 11:41:06 2014 +0200 @@ -20,8 +20,6 @@ import java.awt.Graphics2D; import java.awt.Transparency; -import java.awt.geom.Rectangle2D.Double; - import java.awt.geom.Rectangle2D; import java.io.IOException; @@ -30,6 +28,7 @@ import java.io.UnsupportedEncodingException; import java.text.NumberFormat; +import java.util.Map; import org.jfree.chart.ChartRenderingInfo; @@ -50,6 +49,7 @@ import org.dive4elements.artifacts.common.utils.XMLUtils; +import org.dive4elements.river.jfree.XYMetaSeriesCollection; import org.dive4elements.river.utils.Formatter; @@ -317,7 +317,11 @@ for (int j = 0; j < scount; j++) { Comparable seriesKey = data.getSeriesKey(j); log.debug("series key: " + seriesKey.toString()); - writeCSVHeader(writer, seriesKey.toString()); + Map<String, String> metaData = null; + if (data instanceof XYMetaSeriesCollection) { + metaData = ((XYMetaSeriesCollection) data).getMetaData(); + } + writeCSVHeader(writer, seriesKey.toString(), metaData); writeCSVData(writer, data, format); } } @@ -330,11 +334,31 @@ } - protected static void writeCSVHeader(CSVWriter writer, String key) { + protected static void writeCSVHeader( + CSVWriter writer, + String key, + Map<String, String> metaData) + { writer.writeNext(new String[] {"#"}); - writer.writeNext(new String[] {"# " + key}); - writer.writeNext(new String[] {"#"}); - writer.writeNext(new String[] {"X", "Y"}); + if (metaData != null) { + writer.writeNext(new String[] {"# " + key}); + for (Map.Entry<String, String> entry: metaData.entrySet()) { + if (entry.getKey().equals("X") || entry.getKey().equals("Y")) { + continue; + } + writer.writeNext(new String[] + {"# " + entry.getKey() + " " + entry.getValue()}); + } + writer.writeNext(new String[] {"#"}); + writer.writeNext(new String[] { + metaData.get("X") != null ? metaData.get("X") : "X", + metaData.get("Y") != null ? metaData.get("Y") : "Y"}); + } + else { + writer.writeNext(new String[] {"# " + key}); + writer.writeNext(new String[] {"#"}); + writer.writeNext(new String[] {"X", "Y"}); + } }