changeset 659:ab43f36f4af6

The ChartInfoGenerator appends axes range information to the document now. flys-artifacts/trunk@2065 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 07 Jun 2011 13:15:02 +0000
parents ed7c901ee712
children 627be3ca1ab6
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java
diffstat 2 files changed, 77 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jun 07 11:43:30 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jun 07 13:15:02 2011 +0000
@@ -1,3 +1,8 @@
+2011-06-07  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java:
+	  Append axes range information to the info document.
+
 2011-06-08  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java	Tue Jun 07 11:43:30 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java	Tue Jun 07 13:15:02 2011 +0000
@@ -58,6 +58,7 @@
 
         Element chartinfo = cr.create("chartinfo");
 
+        chartinfo.appendChild(createAxesElements(cr, chart));
         chartinfo.appendChild(createTransformationElement(cr, chart, info));
 
         doc.appendChild(chartinfo);
@@ -67,6 +68,77 @@
 
 
     /**
+     * This method create a axes element that contains all domain and range
+     * axes of the given chart.
+     *
+     * @param cr The ElementCreator.
+     * @param chart The chart that provides range information of its axes.
+     *
+     * @return an element with axes information.
+     */
+    protected static Element createAxesElements(
+        ElementCreator     cr,
+        JFreeChart         chart)
+    {
+        logger.debug("InfoGeneratorHelper.createRangeElements");
+
+        Element axes = cr.create("axes");
+
+        XYPlot plot = (XYPlot) chart.getPlot();
+
+        int dAxisCount = plot.getDomainAxisCount();
+        for (int i = 0; i < dAxisCount; i++) {
+            Element e = createAxisElement(
+                cr, plot.getDomainAxis(i), "domain", i);
+
+            if (e != null) {
+                axes.appendChild(e);
+            }
+        }
+
+        int rAxisCount = plot.getRangeAxisCount();
+        for (int i = 0; i < rAxisCount; i++) {
+            Element e = createAxisElement(
+                cr, plot.getRangeAxis(i), "range", i);
+
+            if (e != null) {
+                axes.appendChild(e);
+            }
+        }
+
+        return axes;
+    }
+
+
+    /**
+     * This method create a axis element for a given <i>axis</i> and
+     * <i>type</i>. Type can be one of 'domain' or 'range'.
+     *
+     * @param cr The ElementCreator
+     * @param axis The axis that provides range information.
+     * @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(
+        ElementCreator cr,
+        ValueAxis      axis,
+        String         type,
+        int            pos)
+    {
+        Range range = axis.getRange();
+
+        Element e = cr.create(type);
+        cr.addAttr(e, "pos", String.valueOf(pos), true);
+        cr.addAttr(e, "from", String.valueOf(range.getLowerBound()), true);
+        cr.addAttr(e, "to", String.valueOf(range.getUpperBound()), true);
+
+        return e;
+    }
+
+
+    /**
      * This method appends the values of a transformation matrix to transform
      * image pixel coordinates into chart coordinates.
      *

http://dive4elements.wald.intevation.org