changeset 648:d4c4fefb095b

The matrix that is used to transform chart image coordinates into chart coordinates supports inverted x-axis now. flys-artifacts/trunk@2037 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 01 Jun 2011 09:18:00 +0000
parents bb484489d3df
children 44175d4720f8
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java
diffstat 2 files changed, 27 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jun 01 08:01:07 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jun 01 09:18:00 2011 +0000
@@ -1,3 +1,10 @@
+2011-06-01  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java:
+	  Interchange the lower and upper x value of the chart if the x-axis is
+	  inverted before the matrix values are computed. Now, the matrix is able
+	  to work with charts that have an inverted x-axis.
+
 2011-06-01  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java: New. A
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java	Wed Jun 01 08:01:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java	Wed Jun 01 09:18:00 2011 +0000
@@ -11,6 +11,7 @@
 
 import org.jfree.chart.ChartRenderingInfo;
 import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.ValueAxis;
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.data.Range;
 
@@ -86,11 +87,11 @@
 
         Rectangle2D dataArea = info.getPlotInfo().getDataArea();
 
-        XYPlot plot   = (XYPlot) chart.getPlot();
-        Range  xRange = plot.getDomainAxis().getRange();
-        Range  yRange = plot.getRangeAxis().getRange();
+        XYPlot    plot  = (XYPlot) chart.getPlot();
+        ValueAxis xAxis = plot.getDomainAxis();
+        ValueAxis yAxis = plot.getRangeAxis();
 
-        double[] tm = createTransformationMatrix(dataArea, xRange, yRange);
+        double[] tm = createTransformationMatrix(dataArea, xAxis, yAxis);
 
         cr.addAttr(tf, "sx", String.valueOf(tm[0]), true);
         cr.addAttr(tf, "sy", String.valueOf(tm[1]), true);
@@ -113,19 +114,32 @@
      */
     protected static double[] createTransformationMatrix(
         Rectangle2D dataArea,
-        Range       xRange,
-        Range       yRange)
+        ValueAxis   xAxis,
+        ValueAxis   yAxis)
     {
+        logger.debug("InfoGeneratorHelper.createTransformationMatrix");
+
         double offsetX = dataArea.getX();
         double width   = dataArea.getWidth() - 1;
         double offsetY = dataArea.getY();
         double height  = dataArea.getHeight();
 
+        Range xRange = xAxis.getRange();
+        Range yRange = yAxis.getRange();
+
         double lowerX  = xRange.getLowerBound();
         double upperX  = xRange.getUpperBound();
         double lowerY  = yRange.getLowerBound();
         double upperY  = yRange.getUpperBound();
 
+        if (xAxis.isInverted()) {
+            logger.info("X-Axis is inverted!");
+
+            double tmp = upperX;
+            upperX = lowerX;
+            lowerX = tmp;
+        }
+
         double dMoveX = upperX - lowerX;
         double fMoveX = width * lowerX;
         double dMoveY = lowerY - upperY;

http://dive4elements.wald.intevation.org