[PATCH 4 of 5] Use the metadata to write csv header when exporting a chart
Wald Commits
scm-commit at wald.intevation.org
Wed May 21 11:43:51 CEST 2014
# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1400665266 -7200
# Branch facet-metadata
# Node ID 56e7e6c18c26d6e352034fd1dd6f2021be9bf033
# Parent e844be34a606564149d88ee41acd6e7ca047dca5
Use the metadata to write csv header when exporting a chart.
diff -r e844be34a606 -r 56e7e6c18c26 artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java
--- 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"});
+ }
}
More information about the Dive4Elements-commits
mailing list