changeset 7595:ce1b8a59934e

issue1558: Allow fixed axis for timeseries-diagrams.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 21 Nov 2013 17:27:14 +0100
parents eb4ca9a7eaca
children 12c4c8d0ac41
files artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.java
diffstat 1 files changed, 53 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.java	Thu Nov 21 15:40:05 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.java	Thu Nov 21 17:27:14 2013 +0100
@@ -122,6 +122,8 @@
 
         applySeriesAttributes(plot);
 
+        consumeAxisSettings(plot);
+
         addAnnotationsToRenderer(plot);
         addLogo(plot);
         aggregateLegendEntries(plot);
@@ -262,6 +264,56 @@
         plot.getRenderer().addAnnotation(xyannotation, org.jfree.ui.Layer.BACKGROUND);
     }
 
+    /**
+     * This method zooms the plot to the specified ranges in the attribute
+     * document or to the ranges specified by the min/max values in the
+     * datasets. <b>Note:</b> We determine the range manually if no zoom ranges
+     * are given, because JFreeCharts auto-zoom adds a margin to the left and
+     * right of the data area.
+     *
+     * Copy of implementation in XYChartGenerator.
+     *
+     * @param plot The XYPlot.
+     */
+    protected void consumeAxisSettings(XYPlot plot) {
+        logger.debug("Zoom to specified ranges.");
+
+        Bounds xrange = getDomainAxisRange();
+        Bounds yrange = getValueAxisRange();
+
+        ValueAxis xAxis = plot.getDomainAxis();
+
+        Range fixedXRange = getRangeForAxisFromSettings("X");
+        if (fixedXRange != null) {
+            xAxis.setRange(fixedXRange);
+        }
+        else {
+            zoomX(plot, xAxis, getXBounds(0), xrange);
+        }
+
+        for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) {
+            ValueAxis yaxis = plot.getRangeAxis(i);
+
+            if (yaxis instanceof IdentifiableNumberAxis) {
+                IdentifiableNumberAxis idAxis = (IdentifiableNumberAxis) yaxis;
+
+                Range fixedRange = getRangeForAxisFromSettings(idAxis.getId());
+                if (fixedRange != null) {
+                    yaxis.setRange(fixedRange);
+                    continue;
+                }
+            }
+
+            if (yaxis == null) {
+                logger.debug("Zoom problem: no Y Axis for index: " + i);
+                continue;
+            }
+
+            logger.debug("Prepare zoom settings for y axis at index: " + i);
+            zoomY(plot, yaxis, getYBounds(Integer.valueOf(i)), yrange);
+        }
+    }
+
 
     @Override
     protected Series getSeriesOf(XYDataset dataset, int idx) {
@@ -528,7 +580,7 @@
 
 
     /**
-     * Adjusts the axes of a plot. This method sets the <i>labelFont</i> of the
+     * Adjusts the (look of) axes of a plot. This method sets the <i>labelFont</i> of the
      * X axis.
      *
      * (Duplicate in XYChartGenerator).

http://dive4elements.wald.intevation.org