changeset 8885:e5f688820951

Some minor changes on chart: allow area-themes to consider range; allow for axis-margins
author gernotbelger
date Wed, 14 Feb 2018 18:10:28 +0100
parents 7a8c12706834
children cc86b0f9b3c3
files 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/jfree/AxisDataset.java artifacts/src/main/java/org/dive4elements/river/jfree/DoubleBounds.java artifacts/src/main/java/org/dive4elements/river/jfree/StyledAreaSeriesCollection.java artifacts/src/main/java/org/dive4elements/river/themes/ThemeDocument.java
diffstat 6 files changed, 47 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java	Tue Feb 13 14:53:23 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java	Wed Feb 14 18:10:28 2018 +0100
@@ -1485,6 +1485,9 @@
         axis.setAutoRangeIncludesZero(false);
         axis.setLabelFont(labelFont);
         axis.setTickLabelFont(labelFont);
+        // REMARK: we overwrite the default values to 0.0, because in earlier version margins were never applied.
+        axis.setLowerMargin(0);
+        axis.setUpperMargin(0);
 
         return axis;
     }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java	Tue Feb 13 14:53:23 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java	Wed Feb 14 18:10:28 2018 +0100
@@ -392,7 +392,11 @@
         if (logarithmic) {
             return new LogarithmicAxis(label);
         }
-        return new NumberAxis(label);
+        final NumberAxis axis = new NumberAxis(label);
+        // REMARK: we overwrite the default values to 0.0, because in earlier version margins were never applied.
+        axis.setLowerMargin(0);
+        axis.setUpperMargin(0);
+        return axis;
     }
 
 
--- a/artifacts/src/main/java/org/dive4elements/river/jfree/AxisDataset.java	Tue Feb 13 14:53:23 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/jfree/AxisDataset.java	Wed Feb 14 18:10:28 2018 +0100
@@ -71,10 +71,15 @@
         for (XYDataset dataset: datasets) {
             Range newRange = null;
             if (dataset instanceof StyledAreaSeriesCollection) {
-                /* We do not include areas in the range calculation because
-                 * they are used with very large / small values to draw areas
-                 * with axis boundaries */
-                continue;
+                final StyledAreaSeriesCollection areaSeries = (StyledAreaSeriesCollection) dataset;
+                if( areaSeries.shouldCalculateRange() )
+                    newRange = areaSeries.getRangeBounds(false);
+                else {
+                    /* For most area themes, we do not include areas in the range calculation because
+                     * they are used with very large / small values to draw areas
+                     * with axis boundaries */
+                    continue;
+                }
             } else if (dataset instanceof RangeInfo) {
                 /* The usual case for most series */
                 newRange = ((RangeInfo) dataset).getRangeBounds(false);
--- a/artifacts/src/main/java/org/dive4elements/river/jfree/DoubleBounds.java	Tue Feb 13 14:53:23 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/jfree/DoubleBounds.java	Wed Feb 14 18:10:28 2018 +0100
@@ -51,7 +51,7 @@
 
     @Override
     public void applyBounds(ValueAxis axis) {
-        axis.setRange(new Range(lower, upper));
+        axis.setRangeWithMargins(new Range(lower, upper));
     }
 
 
@@ -67,7 +67,7 @@
             axis.setRange(new Range(Math.max(lower-space, 0.0001),
                         Math.max(upper+space, 0.0002)));
         } else {
-            axis.setRange(new Range(lower-space, upper+space));
+            axis.setRangeWithMargins(new Range(lower-space, upper+space));
         }
     }
 
--- a/artifacts/src/main/java/org/dive4elements/river/jfree/StyledAreaSeriesCollection.java	Tue Feb 13 14:53:23 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/jfree/StyledAreaSeriesCollection.java	Wed Feb 14 18:10:28 2018 +0100
@@ -27,14 +27,13 @@
     private static final long serialVersionUID = 5274940965666948237L;
 
     /** Mode, how to draw/which areas to fill. */
-    public enum FILL_MODE {UNDER, ABOVE, BETWEEN};
+    public enum FILL_MODE {UNDER, ABOVE, BETWEEN}
 
     /** MODE in use. */
-    protected FILL_MODE mode;
+    private FILL_MODE mode;
 
     /** Theme-document with attributes about actual visual representation. */
-    protected ThemeDocument theme;
-
+    private ThemeDocument theme;
 
     /**
      * @param theme the theme-document.
@@ -70,6 +69,7 @@
         applyShowShape(renderer);
         applyOutlineColor(renderer);
         applyOutlineStyle(renderer);
+        applyShowLine(renderer);
         applyShowAreaLabel(renderer);
         if (mode == FILL_MODE.UNDER) {
             renderer.setAreaCalculationMode(
@@ -90,7 +90,7 @@
     }
 
 
-    protected void applyFillColor(StableXYDifferenceRenderer renderer) {
+    private void applyFillColor(StableXYDifferenceRenderer renderer) {
         Color paint = theme.parseAreaBackgroundColor();
 
         int transparency = theme.parseAreaTransparency();
@@ -119,34 +119,28 @@
     }
 
 
-    protected void applyShowShape(StableXYDifferenceRenderer renderer) {
+    private void applyShowShape(StableXYDifferenceRenderer renderer) {
         boolean show = theme.parseAreaShowBorder();
         renderer.setDrawOutline(show);
     }
 
 
-    protected void applyShowLine(StableXYDifferenceRenderer renderer) {
+    private void applyShowLine(StableXYDifferenceRenderer renderer) {
         boolean show = theme.parseShowLine();
         renderer.setShapesVisible(show);
     }
 
-
-    protected void applyOutlineColor(StableXYDifferenceRenderer renderer) {
+    private void applyOutlineColor(StableXYDifferenceRenderer renderer) {
         Color c = theme.parseLineColorField();
         renderer.setOutlinePaint(c);
     }
 
-    protected void applyOutlineWidth(StableXYDifferenceRenderer renderer) {
-        // int size = theme.parseLineWidth();
-        // XXX: Why is this not set?
-    }
-
     /** Inform renderer whether it should draw a label. */
-    protected void applyShowAreaLabel(StableXYDifferenceRenderer renderer) {
+    private void applyShowAreaLabel(StableXYDifferenceRenderer renderer) {
         renderer.setLabelArea(theme.parseShowAreaLabel());
     }
 
-    protected void applyOutlineStyle(StableXYDifferenceRenderer renderer) {
+    private void applyOutlineStyle(StableXYDifferenceRenderer renderer) {
         float[] dashes = theme.parseLineStyle();
         int size       = theme.parseLineWidth();
 
@@ -166,5 +160,9 @@
 
         renderer.setOutlineStroke(stroke);
     }
+
+    public boolean shouldCalculateRange() {
+        return theme.parseCalculateRange();
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifacts/src/main/java/org/dive4elements/river/themes/ThemeDocument.java	Tue Feb 13 14:53:23 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/themes/ThemeDocument.java	Wed Feb 14 18:10:28 2018 +0100
@@ -120,6 +120,9 @@
 
     public final static String USE_FILL_PAINT = "usefillpaint";
 
+    /* boolean parameter if the range of this theme should be considered when auto-zooming. Only works for area-series at the moment */
+    private static final String CALCULATE_RANGE = "calculateRange";
+
     private Map<String, String> values;
 
     public ThemeDocument() {
@@ -608,7 +611,7 @@
         return parseColor(lineColorStr);
     }
 
-
+    // FIXME: check, this is defined in default.xml, but never used. Instead the StyledAreaSeriesCollection used lineColor etc
     public Color parseAreaLineColorField() {
         String lineColorStr = getAreaLineColorString();
         if (log.isDebugEnabled()) {
@@ -812,5 +815,15 @@
     private String getAreaShowBorderString() {
         return getValue(AREA_SHOW_BORDER);
     }
+    
+    
+    public boolean parseCalculateRange() {
+        return parseBoolean(getCalculateRangeString(), false);
+    }
+
+    
+    private String getCalculateRangeString() {
+        return getValue(CALCULATE_RANGE);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org