[PATCH 1 of 2] Introduced new hook for chart tweaking

Wald Commits scm-commit at wald.intevation.org
Tue Mar 6 17:07:33 CET 2018


# HG changeset patch
# User gernotbelger
# Date 1520352407 -3600
# Node ID 3ac9cb0029b2be08f399921077c82a748c5cb22c
# Parent  cef37cc093f210f96dc145bdb9d6da569c3581e3
Introduced new hook for chart tweaking.
Also consider area-themes when calculating zoom-bounds

diff -r cef37cc093f2 -r 3ac9cb0029b2 artifacts/src/main/java/org/dive4elements/river/exports/ChartExtender.java
--- 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);
diff -r cef37cc093f2 -r 3ac9cb0029b2 artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java
--- 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
diff -r cef37cc093f2 -r 3ac9cb0029b2 artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java
--- 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);
         }
diff -r cef37cc093f2 -r 3ac9cb0029b2 artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java
--- 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 :


More information about the Dive4Elements-commits mailing list