diff flys-artifacts/src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java @ 673:b22f21b173a7

Changed the zoom process - the values in the chart request document are percentual values that apply to every axis. flys-artifacts/trunk@2095 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 09 Jun 2011 10:48:13 +0000
parents 51172d56e8bc
children bdb05dc9b763
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java	Thu Jun 09 10:31:22 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java	Thu Jun 09 10:48:13 2011 +0000
@@ -14,6 +14,7 @@
 import org.jfree.chart.axis.ValueAxis;
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.data.Range;
+import org.jfree.data.xy.XYDataset;
 
 import de.intevation.artifacts.common.ArtifactNamespaceContext;
 import de.intevation.artifacts.common.utils.XMLUtils;
@@ -31,7 +32,11 @@
         Logger.getLogger(InfoGeneratorHelper.class);
 
 
-    private InfoGeneratorHelper() {
+    protected XYChartGenerator generator;
+
+
+    public InfoGeneratorHelper(XYChartGenerator generator) {
+        this.generator = generator;
     }
 
 
@@ -43,7 +48,7 @@
      *
      * @return the info document.
      */
-    public static Document createInfoDocument(
+    public Document createInfoDocument(
         JFreeChart         chart,
         ChartRenderingInfo info)
     {
@@ -59,7 +64,7 @@
         Element chartinfo = cr.create("chartinfo");
 
         chartinfo.appendChild(createAxesElements(cr, chart));
-        chartinfo.appendChild(createTransformationElement(cr, chart, info));
+        chartinfo.appendChild(createTransformationElements(cr, chart, info));
 
         doc.appendChild(chartinfo);
 
@@ -76,7 +81,7 @@
      *
      * @return an element with axes information.
      */
-    protected static Element createAxesElements(
+    protected Element createAxesElements(
         ElementCreator     cr,
         JFreeChart         chart)
     {
@@ -89,8 +94,10 @@
         int dAxisCount = plot.getDomainAxisCount();
         for (int i = 0; i < dAxisCount; i++) {
             ValueAxis axis = plot.getDomainAxis(i);
+            XYDataset data = plot.getDataset(i);
+
             if (axis != null) {
-                Element e = createAxisElement(cr, axis, "domain", i);
+                Element e = createAxisElement(cr, axis, data, "domain", i);
                 axes.appendChild(e);
             }
         }
@@ -98,10 +105,15 @@
         int rAxisCount = plot.getRangeAxisCount();
         for (int i = 0; i < rAxisCount; i++) {
             ValueAxis axis = plot.getRangeAxis(i);
-            if (axis != null) {
-                Element e = createAxisElement(cr, axis, "range", i);
-                axes.appendChild(e);
+            XYDataset data = plot.getDataset(i);
+
+            if (axis == null || data == null) {
+                logger.warn("Axis or dataset is empty at pos: " + i);
+                continue;
             }
+
+            Element e = createAxisElement(cr, axis, data, "range", i);
+            axes.appendChild(e);
         }
 
         return axes;
@@ -114,14 +126,16 @@
      *
      * @param cr The ElementCreator
      * @param axis The axis that provides range information.
+     * @param dataset The dataset for min/max determination.
      * @param type The axis type ('domain' or 'range').
      * @param pos The position in the chart.
      *
      * @return An element that contains range information of a given axis.
      */
-    protected static Element createAxisElement(
+    protected Element createAxisElement(
         ElementCreator cr,
         ValueAxis      axis,
+        XYDataset      dataset,
         String         type,
         int            pos)
     {
@@ -132,6 +146,19 @@
         cr.addAttr(e, "from", String.valueOf(range.getLowerBound()), true);
         cr.addAttr(e, "to", String.valueOf(range.getUpperBound()), true);
 
+        Range[] rs = generator.getRangesForDataset(dataset);
+        Range   r  = null;
+
+        if (type.equals("range")) {
+            r = rs[1];
+        }
+        else {
+            r = rs[0];
+        }
+
+        cr.addAttr(e, "min", String.valueOf(r.getLowerBound()), true);
+        cr.addAttr(e, "max", String.valueOf(r.getUpperBound()), true);
+
         return e;
     }
 
@@ -146,12 +173,12 @@
      *
      * @return an element that contains one or more transformation matrix.
      */
-    protected static Element createTransformationElement(
+    protected Element createTransformationElements(
         ElementCreator     cr,
         JFreeChart         chart,
         ChartRenderingInfo info)
     {
-        logger.debug("InfoGeneratorHelper.createTransformationElement");
+        logger.debug("InfoGeneratorHelper.createTransformationElements");
 
         Element tf = cr.create("transformation-matrix");
 
@@ -159,16 +186,60 @@
 
         XYPlot    plot  = (XYPlot) chart.getPlot();
         ValueAxis xAxis = plot.getDomainAxis();
-        ValueAxis yAxis = plot.getRangeAxis();
 
+        if (xAxis == null) {
+            logger.error("There is no x axis in the chart!");
+            return null;
+        }
+
+        for (int i  = 0, num = plot.getRangeAxisCount(); i < num; i++) {
+            ValueAxis yAxis = plot.getRangeAxis(i);
+
+            if (yAxis == null) {
+                logger.warn("No y axis at pos " + i + " existing.");
+                continue;
+            }
+
+            Element matrix = createTransformationElement(
+                cr, xAxis, yAxis, dataArea, i);
+
+            tf.appendChild(matrix);
+        }
+
+        return tf;
+    }
+
+
+    /**
+     * Creates an element that contains values used to transform coordinates
+     * of a coordinate system A into a coordinate system B.
+     *
+     * @param cr The ElementCreator.
+     * @param xAxis The x axis of the target coordinate system.
+     * @param yAxis The y axis of the target coordinate system.
+     * @param dataArea The pixel coordinates of the chart image.
+     * @param pos The dataset position.
+     *
+     * @return an element that contains transformation matrix values.
+     */
+    protected Element createTransformationElement(
+        ElementCreator cr,
+        ValueAxis      xAxis,
+        ValueAxis      yAxis,
+        Rectangle2D    dataArea,
+        int            pos)
+    {
         double[] tm = createTransformationMatrix(dataArea, xAxis, yAxis);
 
-        cr.addAttr(tf, "sx", String.valueOf(tm[0]), true);
-        cr.addAttr(tf, "sy", String.valueOf(tm[1]), true);
-        cr.addAttr(tf, "tx", String.valueOf(tm[2]), true);
-        cr.addAttr(tf, "ty", String.valueOf(tm[3]), true);
+        Element matrix = cr.create("matrix");
 
-        return tf;
+        cr.addAttr(matrix, "pos", String.valueOf(pos), true);
+        cr.addAttr(matrix, "sx", String.valueOf(tm[0]), true);
+        cr.addAttr(matrix, "sy", String.valueOf(tm[1]), true);
+        cr.addAttr(matrix, "tx", String.valueOf(tm[2]), true);
+        cr.addAttr(matrix, "ty", String.valueOf(tm[3]), true);
+
+        return matrix;
     }
 
 

http://dive4elements.wald.intevation.org