changeset 2132:e8fc770d2f8c

'New Chart' for computed discharge curve. flys-artifacts/trunk@3707 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 18 Jan 2012 14:36:16 +0000
parents e50a928187cd
children 767ce9d1991f
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/chart.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/EmptyFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 10 files changed, 173 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jan 18 13:39:16 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jan 18 14:36:16 2012 +0000
@@ -1,3 +1,27 @@
+2012-01-18  Raimund Renkert <raimund.renkert@intevation.de>
+
+	'New Chart' for computed discharge curve.
+
+	* doc/conf/artifacts/chart.xml: Fixed transitions and added state for km input.
+
+	* src/main/java/de/intevation/flys/artifacts/model/EmptyFacet.java:
+	  New. Added an empty facet to avoid deleting an empty output.
+
+	* src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java,
+	  src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java,
+	  src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java:
+	  Changed some return values if the artifact is a ChartArtifact.
+
+	* src/main/java/de/intevation/flys/exports/ChartGenerator.java,
+	  src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java:
+	  Changed casts from WINFOArtifact to FLYSArtifact.
+
+	* src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java:
+	  Add an empty facet if the artifact is a ChartArtifact.
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java:
+	  Set a default axis range if the range is null.
+
 2012-01-18	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	Added stub hyk infrastructure.
--- a/flys-artifacts/doc/conf/artifacts/chart.xml	Wed Jan 18 13:39:16 2012 +0000
+++ b/flys-artifacts/doc/conf/artifacts/chart.xml	Wed Jan 18 14:36:16 2012 +0000
@@ -14,36 +14,40 @@
             <data name="chart_type" type="String" />
          </state>
 
-         <transition transition="de.intevation.flys.artifacts.transitions.DefaultTransition">
+         <transition transition="de.intevation.flys.artifacts.transitions.ValueCompareTransition">
              <from state="state.chart.type"/>
              <to state="state.chart.w_differences"/>
-             <condition data="chart_type" value="new.chart.w_differences" operator="equals"/>
-         </transition>
-
-         <transition transition="de.intevation.flys.artifacts.transitions.DefaultTransition">
-             <from state="state.chart.type"/>
-             <to state="state.chart.durationcurve"/>
-             <condition data="chart_type" value="new.chart.durationcurve" operator="equals"/>
+             <condition data="chart_type" value="chart.new.w_differences" operator="equal"/>
          </transition>
 
-         <transition transition="de.intevation.flys.artifacts.transitions.DefaultTransition">
+         <transition transition="de.intevation.flys.artifacts.transitions.ValueCompareTransition">
              <from state="state.chart.type"/>
-             <to state="state.chart.computeddischargecurve"/>
-             <condition data="chart_type" value="new.chart.computeddischargecurve" operator="equals"/>
+             <to state="state.chart.durationcurve"/>
+             <condition data="chart_type" value="chart.new.durationcurve" operator="equal"/>
          </transition>
 
-         <transition transition="de.intevation.flys.artifacts.transitions.DefaultTransition">
+         <transition transition="de.intevation.flys.artifacts.transitions.ValueCompareTransition">
+             <from state="state.chart.type"/>
+             <to state="state.chart.km"/>
+             <condition data="chart_type" value="chart.new.computeddischargecurve" operator="equal"/>
+         </transition>
+
+         <transition transition="de.intevation.flys.artifacts.transitions.ValueCompareTransition">
              <from state="state.chart.type"/>
              <to state="state.chart.waterlevel"/>
-             <condition data="chart_type" value="new.chart.waterlevel" operator="equals"/>
+             <condition data="chart_type" value="chart.new.waterlevel" operator="equal"/>
          </transition>
 
-         <transition transition="de.intevation.flys.artifacts.transitions.DefaultTransition">
+         <transition transition="de.intevation.flys.artifacts.transitions.ValueCompareTransition">
              <from state="state.chart.type"/>
              <to state="state.chart.discharge_longitudinal_section"/>
-             <condition data="chart_type" value="new.chart.discharge_longitudinal_section" operator="equals"/>
+             <condition data="chart_type" value="chart.new.discharge_longitudinal_section" operator="equal"/>
          </transition>
 
+         <state id="state.chart.km" description="state.chart.km" state="de.intevation.flys.artifacts.states.LocationSelect">
+             <data name="ld_locations" type="Double[]"/>
+         </state>
+
          <state id="state.chart.w_differences" description="state.winfo.w_differences" state="de.intevation.flys.artifacts.states.WDifferencesState">
             <outputmodes>
                 <outputmode name="w_differences" description="output.w_differences" mime-type="image/png" type="chart">
@@ -73,22 +77,6 @@
             </outputmodes>
         </state>
 
-        <state id="state.chart.computeddischargecurve" description="state.winfo.computeddischargecurve" state="de.intevation.flys.artifacts.states.ComputedDischargeCurveState">
-            <outputmodes>
-                <outputmode name="computed_discharge_curve" description="output.computed_discharge_curve" mime-type="image/png" type="chart">
-                    <facets>
-                        <facet name="computed_discharge_curve.q" description="facet.computed_discharge_curve.q"/>
-                        <facet name="computed_discharge_curve.mainvalues.q" description="facet.computed_discharge_curve.mainvalues.q"/>
-                        <facet name="computed_discharge_curve.mainvalues.w" description="facet.computed_discharge_curve.mainvalues.w"/>
-                        <facet name="other.wqkms" description="facet.other.wqkms"/>
-                        <facet name="other.wq"    description="Point-like data like fixations"/>
-                        <facet name="other.wq"    description="Point-like data like fixations"/>
-                        <facet name="other.wkms.interpol" description="Height over km, like flood protections."/>
-                    </facets>
-                </outputmode>
-            </outputmodes>
-        </state>
-
         <state id="state.chart.waterlevel" description="state.winfo.waterlevel" state="de.intevation.flys.artifacts.states.WaterlevelState">
             <outputmodes>
                 <outputmode name="longitudinal_section" description="output.longitudinal_section" mime-type="image/png" type="chart">
@@ -122,5 +110,29 @@
                 </outputmode>
             </outputmodes>
         </state>
+
+        <transition transition="de.intevation.flys.artifacts.transitions.ValueCompareTransition">
+            <from state="state.chart.km"/>
+            <to state="state.chart.computeddischargecurve"/>
+            <condition data="chart_type" value="chart.new.computeddischargecurve" operator="equal"/>
+        </transition>
+
+        <state id="state.chart.computeddischargecurve" description="state.chart.computeddischargecurve" state="de.intevation.flys.artifacts.states.ComputedDischargeCurveState">
+            <outputmodes>
+                <outputmode name="computed_discharge_curve" description="output.computed_discharge_curve" mime-type="image/png" type="chart">
+                    <facets>
+                        <facet name="empty.facet" description="Empty"/>
+                        <facet name="computed_discharge_curve.q" description="facet.computed_discharge_curve.q"/>
+                        <facet name="computed_discharge_curve.mainvalues.q" description="facet.computed_discharge_curve.mainvalues.q"/>
+                        <facet name="computed_discharge_curve.mainvalues.w" description="facet.computed_discharge_curve.mainvalues.w"/>
+                        <facet name="other.wqkms" description="facet.other.wqkms"/>
+                        <facet name="other.wq" description="Point-like data like fixations"/>
+                        <facet name="other.wq" description="Point-like data like fixations"/>
+                        <facet name="other.wkms.interpol" description="Height over km, like flood protections."/>
+                    </facets>
+                </outputmode>
+            </outputmodes>
+        </state>
+
     </states>
 </artifact>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java	Wed Jan 18 13:39:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java	Wed Jan 18 14:36:16 2012 +0000
@@ -23,7 +23,7 @@
 import de.intevation.artifactdatabase.state.Output;
 
 import de.intevation.flys.artifacts.datacage.Recommendations;
-
+import de.intevation.flys.artifacts.ChartArtifact;
 
 public class CollectionMonitor implements Hook {
 
@@ -73,6 +73,10 @@
         FLYSArtifact flys,
         CallContext  context)
     {
+        if (flys instanceof ChartArtifact) {
+            return new String[0];
+        }
+
         List<Output>  outs = flys.getCurrentOutputs(context);
 
         int num = outs == null ? 0 : outs.size();
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java	Wed Jan 18 13:39:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java	Wed Jan 18 14:36:16 2012 +0000
@@ -161,7 +161,7 @@
         CallMeta meta)
     {
         logger.debug("WQKmsInterpolArtifact.initialize");
-        WINFOArtifact winfo = (WINFOArtifact) artifact;
+        FLYSArtifact winfo = (FLYSArtifact) artifact;
         importData(winfo, "river");
         importData(winfo, "ld_locations");
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/EmptyFacet.java	Wed Jan 18 14:36:16 2012 +0000
@@ -0,0 +1,33 @@
+package de.intevation.flys.artifacts.model;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.state.DefaultFacet;
+import de.intevation.artifactdatabase.state.Facet;
+
+public class EmptyFacet
+extends      DefaultFacet
+{
+    /** Trivial constructor. */
+    public EmptyFacet() {
+        super(0, "empty.facet", "empty.facet");
+    }
+
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        return null;
+    }
+
+
+    /**
+     * Return a deep copy.
+     */
+    @Override
+    public Facet deepCopy() {
+        EmptyFacet copy = new EmptyFacet();
+        copy.set(this);
+        return copy;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java	Wed Jan 18 13:39:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java	Wed Jan 18 14:36:16 2012 +0000
@@ -23,6 +23,8 @@
 
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
+import de.intevation.flys.artifacts.ChartArtifact;
+
 import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.GaugesFactory;
@@ -158,6 +160,9 @@
     ) {
         logger.debug("computeFeed");
 
+        if (artifact instanceof ChartArtifact) {
+            return null;
+        }
         WINFOArtifact winfo = (WINFOArtifact)artifact;
 
         CalculationResult res = old instanceof CalculationResult
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java	Wed Jan 18 13:39:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java	Wed Jan 18 14:36:16 2012 +0000
@@ -10,11 +10,13 @@
 
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
+import de.intevation.flys.artifacts.ChartArtifact;
 
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.WaterlevelFacet;
 import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.ReportFacet;
+import de.intevation.flys.artifacts.model.EmptyFacet;
 import de.intevation.flys.artifacts.model.WQKms;
 import de.intevation.flys.artifacts.model.CalculationResult;
 
@@ -48,40 +50,49 @@
         List<Facet>  facets,
         Object       old
     ) {
-        WINFOArtifact winfo = (WINFOArtifact)artifact;
-
-        CalculationResult res = old instanceof CalculationResult
-            ? (CalculationResult)old
-            : winfo.getComputedDischargeCurveData();
-
-        WQKms [] wqkms = (WQKms [])res.getData();
-
-        if (facets != null && wqkms.length > 0) {
-            for (int i = 0; i < wqkms.length; ++i) {
+        logger.debug("ComputedDischargeCurveState.computeAdvance");
+        if(artifact instanceof WINFOArtifact) {
+            WINFOArtifact winfo = (WINFOArtifact)artifact;
 
-                Object[] args = new Object[] {
-                    FLYSUtils.getRiver(winfo).getName(),
-                    wqkms[i].getName()
-                };
+            CalculationResult res = old instanceof CalculationResult
+                ? (CalculationResult)old
+                : winfo.getComputedDischargeCurveData();
 
-                String name = Resources.getMsg(
-                    context.getMeta(),
-                    "chart.computed.discharge.curve.curve.label",
-                    "",
-                    args);
+            WQKms [] wqkms = (WQKms [])res.getData();
 
-                facets.add(new WaterlevelFacet(i, COMPUTED_DISCHARGE_Q, name));
-                facets.add(new WaterlevelFacet(i, AT, "AT data"));
+            if (facets != null && wqkms.length > 0) {
+                for (int i = 0; i < wqkms.length; ++i) {
+
+                    Object[] args = new Object[] {
+                        FLYSUtils.getRiver(winfo).getName(),
+                        wqkms[i].getName()
+                    };
+
+                    String name = Resources.getMsg(
+                        context.getMeta(),
+                        "chart.computed.discharge.curve.curve.label",
+                        "",
+                        args);
+
+                    facets.add(new WaterlevelFacet(i, COMPUTED_DISCHARGE_Q, name));
+                    facets.add(new WaterlevelFacet(i, AT, "AT data"));
+                }
+
+                facets.add(new DataFacet(CSV, "CSV data"));
+
+                if (res.getReport().hasProblems()) {
+                    facets.add(new ReportFacet());
+                }
             }
 
-            facets.add(new DataFacet(CSV, "CSV data"));
-
-            if (res.getReport().hasProblems()) {
-                facets.add(new ReportFacet());
-            }
+            return res;
         }
-
-        return res;
+        else if(artifact instanceof ChartArtifact) {
+            ChartArtifact chart = (ChartArtifact)artifact;
+            facets.add(new EmptyFacet());
+            return null;
+        }
+        return null;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java	Wed Jan 18 13:39:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java	Wed Jan 18 14:36:16 2012 +0000
@@ -10,6 +10,7 @@
 
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
+import de.intevation.flys.artifacts.ChartArtifact;
 
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.ReportFacet;
@@ -36,6 +37,10 @@
         List<Facet>  facets,
         Object       old
     ) {
+        if (artifact instanceof ChartArtifact) {
+            return null;
+        }
+
         WINFOArtifact winfo = (WINFOArtifact)artifact;
 
         CalculationResult res = old instanceof CalculationResult
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Wed Jan 18 13:39:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Wed Jan 18 14:36:16 2012 +0000
@@ -27,7 +27,7 @@
 import de.intevation.flys.model.River;
 
 import de.intevation.flys.artifacts.WINFOArtifact;
-
+import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.resources.Resources;
 import de.intevation.flys.utils.FLYSUtils;
 
@@ -215,7 +215,7 @@
 
 
     protected String getRiverName() {
-        WINFOArtifact flys = (WINFOArtifact) master;
+        FLYSArtifact flys = (FLYSArtifact) master;
 
         River river = FLYSUtils.getRiver(flys);
         return (river != null) ? river.getName() : "";
@@ -223,7 +223,7 @@
 
 
     protected double[] getRange() {
-        WINFOArtifact flys = (WINFOArtifact) master;
+        FLYSArtifact flys = (FLYSArtifact) master;
 
         return FLYSUtils.getKmRange(flys);
     }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Wed Jan 18 13:39:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Wed Jan 18 14:36:16 2012 +0000
@@ -914,10 +914,21 @@
      */
     public Range[] getRangesForAxis(int index) {
         logger.debug("getRangesForAxis " + index);
-        return new Range[] {
-            xRanges.get(Integer.valueOf(0)),
-            yRanges.get(Integer.valueOf(index))
-        };
+
+        Range rx = xRanges.get(Integer.valueOf(0));
+        Range ry = yRanges.get(Integer.valueOf(index));
+
+        if (rx == null) {
+            logger.warn("Range for x axis not set." +
+                        " Using default values: 0 - 1.");
+            rx = new Range(0, 1);
+        }
+        if (ry == null) {
+            logger.warn("Range for y" + index +
+                        " axis not set. Using default values: 0 - 1.");
+            ry = new Range(0, 1);
+        }
+        return new Range[] {rx, ry};
     }
 
 

http://dive4elements.wald.intevation.org