changeset 3131:bac0b2721451

FixA: Added delta W(t) chart in fix analysis. flys-artifacts/trunk@4732 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 20 Jun 2012 16:10:59 +0000
parents 0dd569e9b9f1
children 459750878157
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/fixanalysis.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/doc/conf/themes.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDeviationFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDeltaWtGenerator.java
diffstat 9 files changed, 682 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jun 20 15:33:32 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jun 20 16:10:59 2012 +0000
@@ -1,3 +1,31 @@
+2012-06-20  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Added delta W(t) chart in fix analysis.
+
+	* src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java:
+	  Added facet types for deta W(t) chart.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java:
+	  Changed facet index to determine the sector index and the analysis period
+	  index.
+
+	* src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java:
+	  Calculate a facet index including the sector index and the analysis period
+	  index.
+	  Added new facet for delta W(t) chart.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixDeviationFacet.java:
+	  New. Facet to display the standard deviation in delta W(t) chart.
+
+	* src/main/java/de/intevation/flys/exports/fixings/FixDeltaWtGenerator.java:
+	  New. Generator for the delta W(t) chart.
+
+	* doc/conf/artifacts/fixanalysis.xml:
+	  Updated facets in outputmodes.
+
+	* doc/conf/conf.xml:
+	  Added output generator to config.
+
 2012-06-20  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java:
--- a/flys-artifacts/doc/conf/artifacts/fixanalysis.xml	Wed Jun 20 15:33:32 2012 +0000
+++ b/flys-artifacts/doc/conf/artifacts/fixanalysis.xml	Wed Jun 20 16:10:59 2012 +0000
@@ -140,18 +140,19 @@
                 </outputmode>
                 <outputmode name="fix_deltawt_curve" description="output.fix_deltawt_curve" mine-type="image/png" type="chart">
                     <facets>
-                        <facet name="fix_sector_average_dwt" description="Average values for Ws in Q sectors."/>
+                        <facet name="fix_sector_average_dwt_0" description="Average values for Ws in Q sectors."/>
+                        <facet name="fix_sector_average_dwt_1" description="Average values for Ws in Q sectors."/>
+                        <facet name="fix_sector_average_dwt_2" description="Average values for Ws in Q sectors."/>
+                        <facet name="fix_sector_average_dwt_3" description="Average values for Ws in Q sectors."/>
                         <facet name="fix_analysis_events_dwt" description="Raw event values used in the calculation"/>
                         <facet name="fix_reference_events_dwt" description="Raw event values used in the calculation"/>
                         <facet name="fix_analysis_periods_dwt" description="Dateranges of analysis periods."/>
+                        <facet name="fix_deviation_dwt" description="The standard variance"/>
                     </facets>
                 </outputmode>
                 <outputmode name="fix_longitudinal_section_curve" description="output.fix_longitudinal_section_curve" mine-type="image/png" type="chart">
                     <facets>
                         <facet name="fix_sector_average_ls" description="Average values for Ws in Q sectors."/>
-                        <facet name="fix_analysis_events_ls" description="Raw event values used in the calculation"/>
-                        <facet name="fix_reference_events_ls" description="Raw event values used in the calculation"/>
-                        <facet name="fix_analysis_periods_ls" description="Dateranges of analysis periods."/>
                         <facet name="longitudinal_section.annotations" description="facet.longitudinal_section.annotations"/>
                     </facets>
                 </outputmode>
--- a/flys-artifacts/doc/conf/conf.xml	Wed Jun 20 15:33:32 2012 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Wed Jun 20 16:10:59 2012 +0000
@@ -265,6 +265,7 @@
         <output-generator name="sq_relation_f_chartinfo">de.intevation.flys.exports.sq.SQRelationInfoGenerator</output-generator>
         <output-generator name="sq_relation_export">de.intevation.flys.exports.SQRelationExporter</output-generator>
         <output-generator name="fix_deltawt_export">de.intevation.flys.exports.DeltaWtExporter</output-generator>
+        <output-generator name="fix_deltawt_curve">de.intevation.flys.exports.fixings.FixDeltaWtGenerator</output-generator>
         <!-- Error report generators. -->
         <output-generator name="discharge_longitudinal_section_report">de.intevation.flys.exports.ReportGenerator</output-generator>
         <output-generator name="waterlevel_report">de.intevation.flys.exports.ReportGenerator</output-generator>
--- a/flys-artifacts/doc/conf/themes.xml	Wed Jun 20 15:33:32 2012 +0000
+++ b/flys-artifacts/doc/conf/themes.xml	Wed Jun 20 16:10:59 2012 +0000
@@ -973,6 +973,76 @@
             </inherits>
         </theme>
 
+        <theme name="FixingDeltaWtAverage0">
+            <inherits>
+                <inherit from="ColorPoints"/>
+            </inherits>
+            <fields>
+                <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+                <field name="showlines" type="boolean" default="false"/>
+                <field name="pointsize"  type="int"     display="Punktdicke"           default="3"/>
+                <field name="pointcolor" type="Color" display="Punktfarbe" default="0, 128, 0"/>
+            </fields>
+        </theme>
+        <theme name="FixingDeltaWtAverage1">
+            <inherits>
+                <inherit from="ColorPoints"/>
+            </inherits>
+            <fields>
+                <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+                <field name="showlines" type="boolean" default="false"/>
+                <field name="pointsize"  type="int"     display="Punktdicke"           default="3"/>
+                <field name="pointcolor" type="Color" display="Punktfarbe" default="0, 0, 255"/>
+            </fields>
+        </theme>
+        <theme name="FixingDeltaWtAverage2">
+            <inherits>
+                <inherit from="ColorPoints"/>
+            </inherits>
+            <fields>
+                <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+                <field name="showlines" type="boolean" default="false"/>
+                <field name="pointsize"  type="int"     display="Punktdicke"           default="3"/>
+                <field name="pointcolor" type="Color" display="Punktfarbe" default="255, 0, 255"/>
+            </fields>
+        </theme>
+        <theme name="FixingDeltaWtAverage3">
+            <inherits>
+                <inherit from="ColorPoints"/>
+            </inherits>
+            <fields>
+                <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+                <field name="showlines" type="boolean" default="false"/>
+                <field name="pointsize"  type="int"     display="Punktdicke"           default="3"/>
+                <field name="pointcolor" type="Color" display="Punktfarbe" default="255, 0, 0"/>
+            </fields>
+        </theme>
+
+
+        <theme name="FixingDeltaWtAnalysis">
+            <inherits>
+                <inherit from="ColorPoints"/>
+            </inherits>
+            <fields>
+                <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+                <field name="showlines" type="boolean" default="false"/>
+                <field name="pointsize"  type="int"     display="Punktdicke"           default="3"/>
+                <field name="pointcolor" type="Color" display="Punktfarbe" default="0, 255, 0"/>
+            </fields>
+        </theme>
+
+        <theme name="FixingDeltaWtReference">
+            <inherits>
+                <inherit from="ColorPoints"/>
+            </inherits>
+            <fields>
+                <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+                <field name="showlines" type="boolean" default="false"/>
+                <field name="pointsize"  type="int"     display="Punktdicke"           default="3"/>
+                <field name="pointcolor" type="Color" display="Punktfarbe" default="0, 80, 160"/>
+            </fields>
+        </theme>
+
 </themegroup>
 
     <themegroup name="default-2">
@@ -1862,6 +1932,63 @@
             </fields>
         </theme>
 
+        <theme name="FixingDeltaWtAverage0">
+            <inherits>
+                <inherit from="ColorPoints"/>
+            </inherits>
+            <fields>
+                <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+                <field name="pointcolor" type="Color" display="Punktfarbe" default="0, 128, 0"/>
+            </fields>
+        </theme>
+        <theme name="FixingDeltaWtAverage1">
+            <inherits>
+                <inherit from="ColorPoints"/>
+            </inherits>
+            <fields>
+                <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+                <field name="pointcolor" type="Color" display="Punktfarbe" default="0, 0, 255"/>
+            </fields>
+        </theme>
+        <theme name="FixingDeltaWtAverage2">
+            <inherits>
+                <inherit from="ColorPoints"/>
+            </inherits>
+            <fields>
+                <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+                <field name="pointcolor" type="Color" display="Punktfarbe" default="255, 0, 255"/>
+            </fields>
+        </theme>
+        <theme name="FixingDeltaWtAverage3">
+            <inherits>
+                <inherit from="ColorPoints"/>
+            </inherits>
+            <fields>
+                <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+                <field name="pointcolor" type="Color" display="Punktfarbe" default="255, 0, 0"/>
+            </fields>
+        </theme>
+
+        <theme name="FixingDeltaWtAnalysis">
+            <inherits>
+                <inherit from="ColorPoints"/>
+            </inherits>
+            <fields>
+                <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+                <field name="pointcolor" type="Color" display="Punktfarbe" default="0, 255, 0"/>
+            </fields>
+        </theme>
+
+        <theme name="FixingDeltaWtReference">
+            <inherits>
+                <inherit from="ColorPoints"/>
+            </inherits>
+            <fields>
+                <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+                <field name="showlines" type="boolean" default="false"/>
+                <field name="pointcolor" type="Color" display="Punktfarbe" default="0, 255, 0"/>
+            </fields>
+        </theme>
 
         <theme name="FixingSectorAverageWQ">
             <inherits>
@@ -1903,7 +2030,6 @@
             <inherits>
             </inherits>
         </theme>
-
     </themegroup>
 
     <!-- Virtual themes are following now!
@@ -2404,6 +2530,11 @@
         <mapping from="fix_outliers" to="FixingOutlier"/>
         <mapping from="fix_wq_curve" to="FixingWQCurve"/>
         <mapping from="fix_reference_events_wq" to="FixingReferenceEventsWQ"/>
-
+        <mapping from="fix_sector_average_dwt_0" to="FixingDeltaWtAverage0"/>
+        <mapping from="fix_sector_average_dwt_1" to="FixingDeltaWtAverage1"/>
+        <mapping from="fix_sector_average_dwt_2" to="FixingDeltaWtAverage2"/>
+        <mapping from="fix_sector_average_dwt_3" to="FixingDeltaWtAverage3"/>
+        <mapping from="fix_analysis_events_dwt" to="FixingDeltaWtAnalysis"/>
+        <mapping from="fix_reference_events_dwt" to="FixingDeltaWtReference"/>
     </mappings>
 </themes>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Wed Jun 20 15:33:32 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Wed Jun 20 16:10:59 2012 +0000
@@ -241,5 +241,7 @@
     String FIX_ANALYSIS_PERIODS_WQ = "fix_analysis_periods_wq";
 
     String FIX_DERIVATE = "fix_derivate";
+
+    String FIX_DEVIATION_DWT = "fix_deviation_dwt";
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java	Wed Jun 20 15:33:32 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java	Wed Jun 20 16:10:59 2012 +0000
@@ -87,8 +87,11 @@
             }
 
             QWD[] qwdData = null;
-            if (index < periods.length) {
-                qwdData = periods[index].getQSectorAverages();
+            int sectorNdx = index & 3;
+            int periodNdx = index >> 2;
+
+            if (periodNdx < periods.length) {
+                qwdData = periods[periodNdx].getQSectorAverages();
             }
 
             if (logger.isDebugEnabled()) {
@@ -96,7 +99,10 @@
                 logger.debug("Found " + resSize + " result elements.");
             }
 
-            return qwdData;
+            if (qwdData == null) {
+                return null;
+            }
+            return qwdData[sectorNdx];
         }
         else {
             logger.warn("Artifact is no instance of FLYSArtifact.");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDeviationFacet.java	Wed Jun 20 16:10:59 2012 +0000
@@ -0,0 +1,102 @@
+package de.intevation.flys.artifacts.model.fixings;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.FixationArtifactAccess;
+
+import de.intevation.flys.artifacts.math.fitting.Function;
+import de.intevation.flys.artifacts.math.fitting.FunctionFactory;
+
+import de.intevation.flys.artifacts.model.CalculationResult;
+import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.Parameters;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * Facet to show the W|Q values.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class FixDeviationFacet
+extends      DataFacet
+implements   FacetTypes {
+
+    /** House logger. */
+    private static Logger logger = Logger.getLogger(FixDeviationFacet.class);
+
+
+    /** Trivial Constructor. */
+    public FixDeviationFacet() {
+    }
+
+
+    /**
+     * @param name
+     */
+    public FixDeviationFacet(String name, String description) {
+        super(0, name, description, ComputeType.ADVANCE, null, null);
+    }
+
+
+    /**
+     * Returns the data this facet requires.
+     *
+     * @param artifact the owner artifact.
+     * @param context  the CallContext (ignored).
+     *
+     * @return the data.
+     */
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        logger.debug("FixDeviationFacet.getData");
+        if (artifact instanceof FLYSArtifact) {
+            FLYSArtifact flys = (FLYSArtifact)artifact;
+            FixationArtifactAccess access = new FixationArtifactAccess(flys);
+
+            CalculationResult res =
+                (CalculationResult) flys.compute(context,
+                                                 ComputeType.ADVANCE,
+                                                 false);
+
+            FixResult result = (FixResult) res.getData();
+            double currentKm =
+                ((Double)context.getContextValue("currentKm")).doubleValue();
+
+            Parameters params = result.getParameters();
+
+            double[] stdDev =
+                params.interpolate("km", currentKm, new String[] {"std-dev"});
+
+            if(stdDev == null) {
+                logger.warn("getData: stdDev == null at km " + currentKm);
+                return null;
+            }
+
+            return stdDev;
+        }
+        else {
+            logger.debug("Not an instance of FixationArtifact.");
+            return null;
+        }
+    }
+
+
+    /**
+     * Create a deep copy of this Facet.
+     * @return a deep copy.
+     */
+    @Override
+    public FixDerivateFacet deepCopy() {
+        FixDerivateFacet copy = new FixDerivateFacet();
+        copy.set(this);
+        return copy;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java	Wed Jun 20 15:33:32 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java	Wed Jun 20 16:10:59 2012 +0000
@@ -23,6 +23,7 @@
 import de.intevation.flys.artifacts.model.fixings.FixOutlierFacet;
 import de.intevation.flys.artifacts.model.fixings.FixWQCurveFacet;
 import de.intevation.flys.artifacts.model.fixings.FixDerivateFacet;
+import de.intevation.flys.artifacts.model.fixings.FixDeviationFacet;
 
 import de.intevation.flys.artifacts.model.fixings.DateRange;
 
@@ -114,16 +115,21 @@
                 String description = sector + ": " +
                                      startDate + " - " +
                                      endDate;
+
+                int sectorNdx = j - access.getQSectorStart().intValue();
+                int facetNdx = i << 2;
+                facetNdx = facetNdx | j;
+
                 facets.add(
-                    new FixAvSectorFacet(j - access.getQSectorStart().intValue(),
-                                         FIX_SECTOR_AVERAGE_DWT,
+                    new FixAvSectorFacet(facetNdx,
+                                         FIX_SECTOR_AVERAGE_DWT + "_" + sectorNdx,
                                          description));
                 facets.add(
-                    new FixAvSectorFacet(j - access.getQSectorStart().intValue(),
+                    new FixAvSectorFacet(facetNdx,
                                          FIX_SECTOR_AVERAGE_LS,
                                          description));
                 facets.add(
-                    new FixAvSectorFacet(j - access.getQSectorStart().intValue(),
+                    new FixAvSectorFacet(facetNdx,
                                          FIX_SECTOR_AVERAGE_WQ,
                                          description));
 
@@ -177,6 +183,7 @@
                 I18N_DERIVATIVE,
                 I18N_DERIVATIVE)));
 
+        facets.add(new FixDeviationFacet(FIX_DEVIATION_DWT, "Abweichung"));
         return res;
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDeltaWtGenerator.java	Wed Jun 20 16:10:59 2012 +0000
@@ -0,0 +1,391 @@
+package de.intevation.flys.exports.fixings;
+
+import java.util.Date;
+
+import java.awt.Color;
+import java.awt.BasicStroke;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+
+import org.apache.log4j.Logger;
+
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.title.TextTitle;
+
+import org.jfree.data.general.SeriesException;
+import org.jfree.data.time.Day;
+import org.jfree.data.time.Month;
+import org.jfree.data.time.RegularTimePeriod;
+import org.jfree.data.time.TimeSeries;
+import org.jfree.data.time.TimeSeriesCollection;
+import org.jfree.chart.plot.Marker;
+import org.jfree.chart.plot.ValueMarker;
+import org.jfree.chart.plot.IntervalMarker;
+
+import java.io.OutputStream;
+
+import javax.xml.xpath.XPathConstants;
+
+import de.intevation.artifacts.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.CallContext;
+
+
+import de.intevation.artifactdatabase.state.ArtifactAndFacet;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.HistoricalWQTimerange;
+import de.intevation.flys.artifacts.model.Timerange;
+import de.intevation.flys.artifacts.model.WQTimerange;
+import de.intevation.flys.jfree.StyledTimeSeries;
+import de.intevation.flys.utils.FLYSUtils;
+import de.intevation.flys.exports.TimeseriesChartGenerator;
+import de.intevation.flys.artifacts.model.fixings.QWD;
+import de.intevation.flys.artifacts.model.fixings.DateRange;
+
+/**
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class FixDeltaWtGenerator
+extends      TimeseriesChartGenerator
+implements   FacetTypes
+{
+    private static Logger logger =
+        Logger.getLogger(FixDeltaWtGenerator.class);
+
+    public static final String XPATH_CHART_CURRENTKM =
+        "/art:action/art:attributes/art:currentKm";
+
+    public static final String I18N_CHART_TITLE =
+        "chart.fix.deltawt.title";
+
+    public static final String I18N_CHART_SUBTITLE =
+        "chart.fix.deltawt.subtitle";
+
+    public static final String I18N_XAXIS_LABEL =
+        "chart.fix.deltawt.xaxis.label";
+
+    public static final String I18N_YAXIS_LABEL =
+        "chart.fix.deltawt.yaxis.label";
+
+    public static final String I18N_YAXIS_SECOND_LABEL =
+        "chart.fix.deltawt.yaxis.second.label";
+
+
+    public static enum YAXIS {
+        dW(0);
+        protected int idx;
+        private YAXIS(int c) {
+            idx = c;
+        }
+    }
+
+
+    @Override
+    protected YAxisWalker getYAxisWalker() {
+        return new YAxisWalker() {
+            @Override
+            public int length() {
+                return YAXIS.values().length;
+            }
+
+            @Override
+            public String getId(int idx) {
+                YAXIS[] yaxes = YAXIS.values();
+                return yaxes[idx].toString();
+            }
+        };
+    }
+
+
+    @Override
+    protected String getDefaultChartTitle() {
+        return msg(I18N_CHART_TITLE, I18N_CHART_TITLE);
+    }
+
+
+    @Override
+    protected String getDefaultChartSubtitle() {
+        String[] args = new String[] {
+            FLYSUtils.getReferenceGaugeName((FLYSArtifact) master)
+        };
+
+        return msg(I18N_CHART_SUBTITLE, "", args);
+    }
+
+
+    /**
+     * Empty (suppress subtitle).
+     */
+    @Override
+    protected void addSubtitles(JFreeChart chart) {
+        String subtitle = getChartSubtitle();
+
+        if (subtitle != null && subtitle.length() > 0) {
+            chart.addSubtitle(new TextTitle(subtitle));
+        }
+    }
+
+
+    @Override
+    protected String getDefaultXAxisLabel() {
+        return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL);
+    }
+
+    @Override
+    protected String getDefaultYAxisLabel(int pos) {
+        if (pos == 0) {
+            return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL);
+        }
+        else if (pos == 1) {
+            return msg(I18N_YAXIS_SECOND_LABEL, I18N_YAXIS_SECOND_LABEL);
+        }
+        else {
+            return "NO TITLE FOR Y AXIS: " + pos;
+        }
+    }
+
+
+    public void doOut(
+        ArtifactAndFacet artifactFacet,
+        Document         theme,
+        boolean          visible
+    ) {
+        String name = artifactFacet.getFacetName();
+        logger.debug("FixDeltaWtGenerator.doOut: " + name);
+        logger.debug("Theme description is: " + artifactFacet.getFacetDescription());
+
+        if (name.contains(FIX_SECTOR_AVERAGE_DWT)) {
+            doSectorAverageOut(
+                (FLYSArtifact) artifactFacet.getArtifact(),
+                artifactFacet.getData(context),
+                artifactFacet.getFacetDescription(),
+                theme,
+                visible);
+        }
+        else if (name.equals(FIX_REFERENCE_EVENTS_DWT)) {
+            doReferenceEventsOut(
+                (FLYSArtifact) artifactFacet.getArtifact(),
+                artifactFacet.getData(context),
+                artifactFacet.getFacetDescription(),
+                theme,
+                visible);
+        }
+        else if (name.equals(FIX_ANALYSIS_EVENTS_DWT)) {
+            doAnalysisEventsOut(
+                (FLYSArtifact) artifactFacet.getArtifact(),
+                artifactFacet.getData(context),
+                artifactFacet.getFacetDescription(),
+                theme,
+                visible);
+        }
+        else if (name.equals(FIX_DEVIATION_DWT)) {
+            doDeviationOut(
+                (FLYSArtifact) artifactFacet.getArtifact(),
+                artifactFacet.getData(context),
+                artifactFacet.getFacetDescription(),
+                theme,
+                visible);
+        }
+        else if (name.equals(FIX_ANALYSIS_PERIODS_DWT)) {
+            doAnalysisPeriodsOut(
+                (FLYSArtifact) artifactFacet.getArtifact(),
+                artifactFacet.getData(context),
+                artifactFacet.getFacetDescription(),
+                theme,
+                visible);
+        }
+        else {
+           logger.warn("doOut(): unknown facet name: " + name);
+           return;
+        }
+    }
+
+
+    protected void doSectorAverageOut(
+        FLYSArtifact artifact,
+        Object       data,
+        String       desc,
+        Document     theme,
+        boolean      visible)
+    {
+        logger.debug("doSectorAverageOut(): description = " + desc);
+
+        QWD qwd = (QWD) data;
+        TimeSeriesCollection tsc = new TimeSeriesCollection();
+        TimeSeries        series = new StyledTimeSeries(desc, theme);
+
+        if (qwd == null) {
+            return;
+        }
+        RegularTimePeriod rtp = new Day(qwd.getDate());
+        double value =  qwd.getDeltaW();
+        series.add(rtp, value);
+        tsc.addSeries(series);
+
+        addAxisDataset(tsc, 0, visible);
+    }
+
+
+    protected void doAnalysisEventsOut(
+        FLYSArtifact artifact,
+        Object       data,
+        String       desc,
+        Document     theme,
+        boolean      visible
+    ) {
+        logger.debug("doAnalysisEventsOut: desc = " + desc);
+
+        QWD[] qwds = (QWD[]) data;
+        TimeSeriesCollection tsc = new TimeSeriesCollection();
+        TimeSeries        series = new StyledTimeSeries(desc, theme);
+
+        if (qwds == null) {
+            return;
+        }
+        for (int i = 0; i < qwds.length; i++) {
+            if (qwds[i] == null) {
+                continue;
+            }
+            RegularTimePeriod rtp = new Day(qwds[i].getDate());
+            double value =  qwds[i].getDeltaW();
+            series.add(rtp, value);
+        }
+        tsc.addSeries(series);
+
+        addAxisDataset(tsc, 0, visible);
+
+    }
+
+
+    protected void doReferenceEventsOut(
+        FLYSArtifact artifact,
+        Object       data,
+        String       desc,
+        Document     theme,
+        boolean      visible
+    ) {
+        logger.debug("doReferenceEventsOut: desc = " + desc);
+
+        QWD[] qwds = (QWD[]) data;
+        TimeSeriesCollection tsc = new TimeSeriesCollection();
+        TimeSeries        series = new StyledTimeSeries(desc, theme);
+
+        if (qwds == null) {
+            return;
+        }
+        for (int i = 0; i < qwds.length; i++) {
+            if (qwds[i] == null) {
+                continue;
+            }
+            logger.debug("adding..." + qwds[i].getDate() + "; val: " + qwds[i].getDeltaW());
+            RegularTimePeriod rtp = new Day(qwds[i].getDate());
+            double value =  qwds[i].getDeltaW();
+            series.addOrUpdate(rtp, value);
+        }
+        tsc.addSeries(series);
+
+        addAxisDataset(tsc, 0, visible);
+    }
+
+
+    protected void doDeviationOut(
+        FLYSArtifact artifact,
+        Object       data,
+        String       desc,
+        Document     theme,
+        boolean      visible
+    ) {
+        logger.debug("doDeviationOut: desc = " + desc);
+
+        if (data == null || !visible) {
+            logger.debug("no standard deviation");
+            return;
+        }
+        double[] value = (double[]) data;
+        IntervalMarker lower = new IntervalMarker((value[0] * -1), 0);
+        lower.setAlpha(0.2f);
+        lower.setPaint(Color.BLACK);
+        IntervalMarker upper = new IntervalMarker(0, value[0]);
+        upper.setAlpha(0.2f);
+        upper.setPaint(Color.BLACK);
+
+        valueMarker.add(lower);
+        valueMarker.add(upper);
+    }
+
+
+    protected void doAnalysisPeriodsOut(
+        FLYSArtifact artifact,
+        Object       data,
+        String       desc,
+        Document     theme,
+        boolean      visible
+    ) {
+        logger.debug("doHistoricalDischargeDifferenceOut: desc = " + desc);
+
+        DateRange[] ranges = (DateRange[]) data;
+        if (ranges == null || !visible) {
+            return;
+        }
+        for (int i = 0; i < ranges.length; i++) {
+            logger.debug("creating domain marker");
+            RegularTimePeriod start = new Month(ranges[i].getFrom());
+            RegularTimePeriod end = new Month(ranges[i].getTo());
+            IntervalMarker marker =
+                new IntervalMarker(start.getMiddleMillisecond(),
+                                   end.getMiddleMillisecond());
+            marker.setAlpha(0.3f);
+            if ((i % 2) == 0) {
+                marker.setPaint(Color.RED);
+            }
+            else {
+                marker.setPaint(Color.BLUE);
+            }
+            domainMarker.add(marker);
+        }
+        logger.debug("domainmarkers: " + domainMarker.size());
+    }
+
+
+    @Override
+    public void init(Document request, OutputStream out, CallContext context) {
+        super.init(request, out, context);
+
+        logger.debug("currentKm = " + new Double(getCurrentKmFromRequest()));
+        context.putContextValue("currentKm", new Double(getCurrentKmFromRequest()));
+
+        ValueMarker marker = new ValueMarker(0);
+        marker.setPaint(Color.black);
+        marker.setStroke(new BasicStroke(2));
+        valueMarker.add(marker);
+    }
+
+    public double getCurrentKmFromRequest() {
+        Element km = (Element)XMLUtils.xpath(
+            request,
+            XPATH_CHART_CURRENTKM,
+            XPathConstants.NODE,
+            ArtifactNamespaceContext.INSTANCE);
+
+        if (km == null) {
+            return -1d;
+        }
+
+        String uri = ArtifactNamespaceContext.NAMESPACE_URI;
+
+        String currentKm = km.getAttributeNS(uri, "km");
+        try {
+            double d = Double.valueOf(currentKm).doubleValue();
+            return d;
+        }
+        catch(NumberFormatException nfe) {
+            return -1d;
+        }
+    }
+
+
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org