changeset 8935:3ac9cb0029b2

Introduced new hook for chart tweaking. Also consider area-themes when calculating zoom-bounds
author gernotbelger
date Tue, 06 Mar 2018 17:06:47 +0100
parents cef37cc093f2
children 93ea282c33e8
files artifacts/src/main/java/org/dive4elements/river/exports/ChartExtender.java artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java
diffstat 4 files changed, 49 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartExtender.java	Tue Mar 06 17:05:37 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartExtender.java	Tue Mar 06 17:06:47 2018 +0100
@@ -20,6 +20,12 @@
 public interface ChartExtender {
 
     /**
+     * Called before {@link DiagramGenerator#autoZoom(org.jfree.chart.plot.XYPlot)} is called, allows to tweak auto zoom
+     * behavior.
+     */
+    void beforeAutoZoom(DiagramGenerator generator);
+
+    /**
      * Called after {@link DiagramGenerator#autoZoom(org.jfree.chart.plot.XYPlot)} was called, allows to tweak auto zoom
      * behavior.
      */
@@ -27,7 +33,7 @@
 
     /**
      * Called after the complete chart is generated.
-     * 
+     *
      * @param plot
      */
     void afterGenerateChart(DiagramGenerator generator, XYPlot plot);
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java	Tue Mar 06 17:05:37 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java	Tue Mar 06 17:06:47 2018 +0100
@@ -1608,4 +1608,9 @@
     public final IdentifiableNumberAxis getAxis(final String axisName) {
         return axisNameToAxis.get(axisName);
     }
+    
+    /** Returns the number of registered y-axes */
+    public final int getNumYAxes() {
+        return axisNameToAxis.size();
+    }
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java	Tue Mar 06 17:05:37 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java	Tue Mar 06 17:06:47 2018 +0100
@@ -509,13 +509,31 @@
 
         AxisDataset axisDataset = (AxisDataset) getAxisDataset(index);
 
+        Bounds[] xyBounds = ChartHelper.getBounds(area);
+
+        if (xyBounds == null) {
+            log.warn("Skip XYDataset for Axis (invalid ranges): " + index);
+            return;
+        }
+        
+
         if (visible) {
+            if (log.isDebugEnabled()) {
+                log.debug("Add new AxisDataset at index: " + index);
+                log.debug("X extent: " + xyBounds[0]);
+                log.debug("Y extent: " + xyBounds[1]);
+            }
+
             axisDataset.addArea(area);
         }
-        else {
-            /* No range merging, for areas extending to infinity this
-             * causes problems. */
-        }
+
+        /* No range merging, for areas extending to infinity this causes problems. */
+        /* No range merging, for areas extending to infinity this causes problems. */
+        if( StyledSeriesBuilder.isBigDoubleValue( xyBounds[1].getLower() ) || StyledSeriesBuilder.isBigDoubleValue( xyBounds[1].getLower() ) )
+            return;
+        
+        combineXBounds(xyBounds[0], 0);
+        combineYBounds(xyBounds[1], index);
     }
 
     /**
@@ -719,6 +737,12 @@
     protected void autoZoom(XYPlot plot) {
         log.debug("Zoom to specified ranges.");
 
+        /* allow chart extenders to tweak zoom behavior */
+        final Collection<ChartExtender> extenders = this.diagramAttributes.getExtenders();
+        for (final ChartExtender extender : extenders) {
+            extender.beforeAutoZoom(this);
+        }        
+
         Range xrange = getDomainAxisRange();
         Range yrange = getValueAxisRange();
 
@@ -754,8 +778,6 @@
             zoom(plot, yaxis, getYBounds(Integer.valueOf(i)), yrange);
         }
         
-        /* allow chart extenders to tweak zoom behaviour */
-        final Collection<ChartExtender> extenders = this.diagramAttributes.getExtenders();
         for (final ChartExtender extender : extenders) {
             extender.afterAutoZoom(this);
         }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java	Tue Mar 06 17:05:37 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java	Tue Mar 06 17:06:47 2018 +0100
@@ -400,5 +400,14 @@
         ground.add(series.getMaxX(), BIG_DOUBLE_VALUE);
         return ground;
     }
+
+
+    /** Checks if a given value is the BIG_DOUBLE_VALUE  */
+    public static boolean isBigDoubleValue(Number value) {
+        if( value == null )
+            return false;
+        
+        return Math.abs( BIG_DOUBLE_VALUE  - Math.abs(value.doubleValue()) ) < 0.1;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org