[PATCH 3 of 3] issue1493: Use other numberformat for csv data from diagram
Wald Commits
scm-commit at wald.intevation.org
Thu Sep 19 09:06:42 CEST 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1379575012 -7200
# Node ID b5e9b8b5c8d6e553ced3f9ac5add9931d117bb02
# Parent 50b9959330de00b5c2e0b7c51838e7c6a724cfd1
issue1493: Use other numberformat for csv data from diagram.
diff -r 50b9959330de -r b5e9b8b5c8d6 artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java Wed Sep 18 18:40:52 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java Thu Sep 19 09:16:52 2013 +0200
@@ -305,6 +305,9 @@
log.warn("Wrong encoding for CSV export.");
return;
}
+
+ NumberFormat format = Formatter.getCSVFormatter(context);
+
XYPlot plot = chart.getXYPlot();
int count = plot.getDatasetCount();
for (int i = 0; i < count; i++) {
@@ -314,7 +317,7 @@
Comparable seriesKey = data.getSeriesKey(j);
log.debug("series key: " + seriesKey.toString());
writeCSVHeader(writer, seriesKey.toString());
- writeCSVData(writer, data, context);
+ writeCSVData(writer, data, format);
}
}
try {
@@ -334,19 +337,18 @@
}
- protected static void writeCSVData(CSVWriter writer, XYDataset data, CallContext context) {
+ /** Get x/y data from axis set and write it, on pair per line. */
+ protected static void writeCSVData(
+ CSVWriter writer, XYDataset data, NumberFormat format) {
int series = data.getSeriesCount();
- // TODO: Instantiate at other place, use
- // better formatter.
- NumberFormat numberFormat = Formatter.getWaterlevelW(context);
for (int i = 0; i < series; i++) {
int items = data.getItemCount(i);
for (int j = 0; j < items; j++) {
log.debug("write data: " + data.getX(i, j) + ", " + data.getY(i, j));
try {
writer.writeNext(new String[] {
- numberFormat.format(data.getX(i, j)),
- numberFormat.format(data.getY(i, j))});
+ format.format(data.getX(i, j)),
+ format.format(data.getY(i, j))});
}
catch (NumberFormatException nfe) {
writer.writeNext(new String[] {
diff -r 50b9959330de -r b5e9b8b5c8d6 artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java Wed Sep 18 18:40:52 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java Thu Sep 19 09:16:52 2013 +0200
@@ -99,6 +99,10 @@
public static final int SQ_RELATION_B_MAX_DIGITS = 3;
public static final int SQ_RELATION_B_MIN_DIGITS = 3;
+ // OTHER
+ public static final int CSV_DIAGRAM_DATA_MAX_DIGITS = 3;
+ public static final int CSV_DIAGRAM_DATA_MIN_DIGITS = 3;
+
/**
* Creates a localized NumberFormatter with given range of decimal digits.
* @param m CallMeta to find the locale.
@@ -191,6 +195,18 @@
WATERLEVEL_KM_MAX_DIGITS);
}
+ /**
+ * Returns the number formatter for data exported from diagram (not from
+ * calculation.
+ *
+ * @return the number formatter for csv data from diagra.
+ */
+ public static NumberFormat getCSVFormatter(CallContext context) {
+ return getFormatter(
+ context,
+ CSV_DIAGRAM_DATA_MIN_DIGITS,
+ CSV_DIAGRAM_DATA_MAX_DIGITS);
+ }
public static NumberFormat getWaterlevelW(CallMeta meta) {
return getFormatter(
More information about the Dive4elements-commits
mailing list