changeset 7388:c4a03db67198

BedHeightSoundingProcessor: refactored to avoid drifting behavior when using old/new style diagram generators.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 17 Oct 2013 10:50:04 +0200
parents cfac25ad6b3e
children 2c3031b6a831
files artifacts/src/main/java/org/dive4elements/river/exports/process/BedHeightSoundingProcessor.java
diffstat 1 files changed, 20 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/BedHeightSoundingProcessor.java	Thu Oct 17 09:40:12 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/BedHeightSoundingProcessor.java	Thu Oct 17 10:50:04 2013 +0200
@@ -40,7 +40,25 @@
             ArtifactAndFacet bundle,
             ThemeDocument    theme,
             boolean          visible) {
-        CallContext context = generator.getCallContext();
+        XYSeries series = prepareSeries(bundle, theme, generator.getCallContext());
+        generator.addAxisSeries(series, axisName, visible);
+    }
+
+    @Override
+    public void doOut(
+            XYChartGenerator generator,
+            ArtifactAndFacet bundle,
+            ThemeDocument theme,
+            boolean visible,
+            int index
+    ) {
+        XYSeries series = prepareSeries(bundle, theme, generator.getCallContext());
+        generator.addAxisSeries(series, index, visible);
+    }
+
+    /** Prepare an series, independent of axis. */
+    private XYSeries prepareSeries(ArtifactAndFacet bundle,
+        ThemeDocument theme, CallContext context) {
         Object data = bundle.getData(context);
         XYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
                 theme);
@@ -63,42 +81,9 @@
                 series.add(bvalue.getStation(), bvalue.getSoundingWidth());
             }
         }
-        generator.addAxisSeries(series, axisName, visible);
+        return series;
     }
 
-    @Override
-    public void doOut(
-            XYChartGenerator generator,
-            ArtifactAndFacet bundle,
-            ThemeDocument theme,
-            boolean visible,
-            int index
-    ) {
-        CallContext context = generator.getCallContext();
-        Object data = bundle.getData(context);
-        XYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
-                theme);
-        if (data instanceof BedHeightSingle) {
-            BedHeightSingle bData = (BedHeightSingle)data;
-            double[] width = bData.getMorphWidths();
-            double[] stations = bData.getStations().toNativeArray();
-
-            logger.debug("doBedheightSingleOut");
-
-            for (int i = 0; i < width.length; i++) {
-                series.add(stations[i], width[i], false);
-            }
-        } else if (data instanceof List<?>) {
-            List<BedHeightSingleValue> bData = (List<BedHeightSingleValue>)data;
-
-            logger.debug("doBedheightSingleValueOut");
-
-            for(BedHeightSingleValue bvalue: bData) {
-                series.add(bvalue.getStation(), bvalue.getSoundingWidth());
-            }
-        }
-        generator.addAxisSeries(series, index, visible);
-    }
 
     @Override
     public boolean canHandle(String facettype) {

http://dive4elements.wald.intevation.org