diff flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java @ 652:8fa4c5c9cd1a

Charts are zoomed to a specified view if the attribute document for the chart creation contains an x and/or y range. flys-artifacts/trunk@2047 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 03 Jun 2011 06:47:51 +0000
parents bab867fb37e8
children 45cd58a2a2bb
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Thu Jun 02 15:47:08 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Fri Jun 03 06:47:51 2011 +0000
@@ -10,6 +10,8 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
+import org.jfree.data.Range;
+
 import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.CallContext;
 
@@ -44,6 +46,12 @@
     public static final String XPATH_CHART_SIZE =
         "/art:action/art:attributes/art:size";
 
+    public static final String XPATH_CHART_X_RANGE =
+        "/art:action/art:attributes/art:xrange";
+
+    public static final String XPATH_CHART_Y_RANGE =
+        "/art:action/art:attributes/art:yrange";
+
 
     /** The document of the incoming out() request.*/
     protected Document request;
@@ -135,6 +143,96 @@
     }
 
 
+    protected Range getDomainAxisRange() {
+        Node xrange = (Node) XMLUtils.xpath(
+            request,
+            XPATH_CHART_X_RANGE,
+            XPathConstants.NODE,
+            ArtifactNamespaceContext.INSTANCE);
+
+        if (xrange == null) {
+            return null;
+        }
+
+        String lower = XMLUtils.xpathString(
+            xrange, "@art:from", ArtifactNamespaceContext.INSTANCE);
+
+        String upper = XMLUtils.xpathString(
+            xrange, "@art:to", ArtifactNamespaceContext.INSTANCE);
+
+        logger.debug("FOUND X RANGE: " + lower + " -> " + upper);
+
+        if (lower != null && upper != null) {
+            try {
+                double from = Double.parseDouble(lower);
+                double to   = Double.parseDouble(upper);
+
+                if (from == 0 && to == 0) {
+                    logger.debug("No range specified. Lower and upper X == 0");
+                    return null;
+                }
+
+                if (from > to) {
+                    double tmp = to;
+                    to         = from;
+                    from       = tmp;
+                }
+
+                return new Range(from, to);
+            }
+            catch (NumberFormatException nfe) {
+                logger.warn("Wrong values for domain axis range.");
+            }
+        }
+
+        return null;
+    }
+
+
+    protected Range getValueAxisRange() {
+        Node yrange = (Node) XMLUtils.xpath(
+            request,
+            XPATH_CHART_Y_RANGE,
+            XPathConstants.NODE,
+            ArtifactNamespaceContext.INSTANCE);
+
+        if (yrange == null) {
+            return null;
+        }
+
+        String lower = XMLUtils.xpathString(
+            yrange, "@art:from", ArtifactNamespaceContext.INSTANCE);
+
+        String upper = XMLUtils.xpathString(
+            yrange, "@art:to", ArtifactNamespaceContext.INSTANCE);
+
+        if (lower != null && upper != null) {
+            try {
+                double from = Double.parseDouble(lower);
+                double to   = Double.parseDouble(upper);
+
+                if (from == 0 && to == 0) {
+                    logger.debug("No range specified. Lower and upper Y == 0");
+                    return null;
+                }
+
+                if (from > to) {
+                    double tmp = to;
+                    to         = from;
+                    from       = tmp;
+                }
+
+                return new Range(from, to);
+            }
+            catch (NumberFormatException nfe) {
+                logger.warn("Wrong values for value axis range.");
+            }
+        }
+
+        return null;
+    }
+
+
     /**
      * Returns the default size of a chart export as array.
      *

http://dive4elements.wald.intevation.org