[PATCH 2 of 2] Reimplemented baseline for tkh. Extended area-dataset to be able to draw baseline

Wald Commits scm-commit at wald.intevation.org
Tue Feb 12 14:08:24 CET 2019


# HG changeset patch
# User gernotbelger
# Date 1549976896 -3600
# Node ID 6b2496d719361280e96bcb74a893cda9b7d432ce
# Parent  8f59aa01c22af2d1d8cdc54b65c8653aa12062ed
Reimplemented baseline for tkh. Extended area-dataset to be able to draw baseline.

diff -r 8f59aa01c22a -r 6b2496d71936 artifacts/doc/conf/themes/default.xml
--- a/artifacts/doc/conf/themes/default.xml	Tue Feb 12 14:06:27 2019 +0100
+++ b/artifacts/doc/conf/themes/default.xml	Tue Feb 12 14:08:16 2019 +0100
@@ -2709,6 +2709,8 @@
       <field name="showarealabel" type="boolean" display="Flächenbeschriftung anzeigen" default="false" hints="hidden"/>
 
       <field name="showmaximum" type="boolean" display="Maximum anzeigen" default="false"/>
+
+      <field name="baselineColor" type="Color" display="Farbe der 0-Linie" default="0, 0, 0" hints="hidden"/>
     </fields>
   </theme>
   <theme name="SInfoFlowDepthDevelopment">
diff -r 8f59aa01c22a -r 6b2496d71936 artifacts/doc/conf/themes/second.xml
--- a/artifacts/doc/conf/themes/second.xml	Tue Feb 12 14:06:27 2019 +0100
+++ b/artifacts/doc/conf/themes/second.xml	Tue Feb 12 14:08:16 2019 +0100
@@ -2697,6 +2697,8 @@
       <field name="showarealabel" type="boolean" display="Flächenbeschriftung anzeigen" default="false" hints="hidden"/>
 
       <field name="showmaximum" type="boolean" display="Maximum anzeigen" default="false"/>
+
+      <field name="baselineColor" type="Color" display="Farbe der 0-Linie" default="0, 0, 0" hints="hidden"/>
     </fields>
   </theme>
   <theme name="SInfoFlowDepthDevelopment">
diff -r 8f59aa01c22a -r 6b2496d71936 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthChartExtender.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthChartExtender.java	Tue Feb 12 14:06:27 2019 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthChartExtender.java	Tue Feb 12 14:08:16 2019 +0100
@@ -9,9 +9,6 @@
  */
 package org.dive4elements.river.artifacts.sinfo.flowdepth;
 
-import java.awt.BasicStroke;
-import java.awt.Stroke;
-
 import org.dive4elements.river.exports.ChartExtender;
 import org.dive4elements.river.exports.DiagramGenerator;
 import org.jfree.chart.axis.ValueAxis;
@@ -60,15 +57,6 @@
 
     @Override
     public void afterGenerateChart(final DiagramGenerator generator, final XYPlot plot) {
-        final ValueAxis tkhAxis = generator.getAxis(TKH_AXIS);
-        if (tkhAxis != null) {
-            /* show baseline if tkhAxis is present */
-
-            // TODO: it would probably better to configure this via the ChartSettings, but currently no chart settings are loaded,
-            // so it is unclear if that feature still works.
-            final Stroke baselineStroke = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
-            plot.setRangeZeroBaselineStroke(baselineStroke);
-            plot.setRangeZeroBaselineVisible(true);
-        }
+        /* nothing to do */
     }
 }
\ No newline at end of file
diff -r 8f59aa01c22a -r 6b2496d71936 artifacts/src/main/java/org/dive4elements/river/jfree/StableXYDifferenceRenderer.java
--- a/artifacts/src/main/java/org/dive4elements/river/jfree/StableXYDifferenceRenderer.java	Tue Feb 12 14:06:27 2019 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/jfree/StableXYDifferenceRenderer.java	Tue Feb 12 14:08:16 2019 +0100
@@ -120,6 +120,7 @@
 import org.jfree.chart.renderer.xy.AbstractXYItemRenderer;
 import org.jfree.chart.renderer.xy.XYItemRendererState;
 import org.jfree.chart.urls.XYURLGenerator;
+import org.jfree.data.Range;
 import org.jfree.data.xy.DefaultXYDataset;
 import org.jfree.data.xy.XYDataset;
 import org.jfree.data.xy.XYSeries;
@@ -196,6 +197,8 @@
     /** Font to draw label of calculated area with. */
     private Font labelFont;
 
+    private Color baseLineColor = null;
+
     /** Whether or not to draw a label that shows the title of the theme. */
     private boolean drawTitleLabel = false;
 
@@ -304,6 +307,10 @@
         this.labelBGColor = color;
     }
 
+    public void setBaseLineColor(final Color baseLineColor) {
+        this.baseLineColor = baseLineColor;
+    }
+
     /**
      * Sets color that is used if drawOutline is true.
      */
@@ -1261,6 +1268,8 @@
             // draw labels: only once per theme!
             drawAreaLabel(g2, dataArea, plot, domainAxis, rangeAxis);
             drawTitleLabel(g2, dataArea, info.getOwner().getEntityCollection(), dataset);
+
+            drawZeroBaseline(g2, dataArea, plot, domainAxis, rangeAxis);
         }
     }
 
@@ -1310,6 +1319,37 @@
         }
     }
 
+    private void drawZeroBaseline(final Graphics2D g2, final Rectangle2D dataArea, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis) {
+
+        if (this.baseLineColor == null)
+            return;
+
+        final PlotOrientation orientation = plot.getOrientation();
+        final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
+        final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
+
+        final Range domainRange = domainAxis.getRange();
+        final double x0 = domainRange.getLowerBound();
+        final double x1 = domainRange.getUpperBound();
+
+        final double screenX0 = domainAxis.valueToJava2D(x0, dataArea, domainAxisLocation);
+        final double screenX1 = domainAxis.valueToJava2D(x1, dataArea, domainAxisLocation);
+        final double screenY = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation);
+
+        Shape baseLine;
+        if (PlotOrientation.HORIZONTAL == orientation)
+            baseLine = new Line2D.Double(screenY, screenX0, screenY, screenX1);
+        else
+            baseLine = new Line2D.Double(screenX0, screenY, screenX1, screenY);
+
+        if (baseLine.intersects(dataArea)) {
+            g2.setPaint(this.baseLineColor);
+            g2.setStroke(new BasicStroke(2));
+
+            g2.draw(baseLine);
+        }
+    }
+
     /**
      * Draws the visual representation of a single data item, second pass. In
      * the second pass, the renderer draws the lines and shapes for the
diff -r 8f59aa01c22a -r 6b2496d71936 artifacts/src/main/java/org/dive4elements/river/jfree/StyledAreaSeriesCollection.java
--- a/artifacts/src/main/java/org/dive4elements/river/jfree/StyledAreaSeriesCollection.java	Tue Feb 12 14:06:27 2019 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/jfree/StyledAreaSeriesCollection.java	Tue Feb 12 14:08:16 2019 +0100
@@ -144,6 +144,7 @@
         applyShowLineLabel(renderer);
         applyPointStyle(renderer);
         applyShowMinimumMaximum(renderer);
+        applyBaseLineStyle(renderer);
         if (this.mode == FILL_MODE.UNDER) {
             renderer.setAreaCalculationMode(StableXYDifferenceRenderer.CALCULATE_NEGATIVE_AREA);
         } else if (this.mode == FILL_MODE.ABOVE) {
@@ -168,6 +169,11 @@
         // renderer.setIsMaximumShapeVisible(maximumVisible);
     }
 
+    private void applyBaseLineStyle(final StableXYDifferenceRenderer renderer) {
+        final Color c = this.theme.parseBaseLineColor();
+        renderer.setBaseLineColor(c);
+    }
+
     private void applyFillColor(final StableXYDifferenceRenderer renderer) {
 
         Paint paint = parseFillPaint();
diff -r 8f59aa01c22a -r 6b2496d71936 artifacts/src/main/java/org/dive4elements/river/themes/ThemeDocument.java
--- a/artifacts/src/main/java/org/dive4elements/river/themes/ThemeDocument.java	Tue Feb 12 14:06:27 2019 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/themes/ThemeDocument.java	Tue Feb 12 14:08:16 2019 +0100
@@ -124,6 +124,8 @@
 
     public final static String SHOWEXTRAMARK = "showextramark";
 
+    private final static String BASE_LINE_COLOR = "baselineColor";
+
     /* 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";
 
@@ -596,6 +598,10 @@
         return parseInteger(getTransparencyString(), 50);
     }
 
+    public Color parseBaseLineColor() {
+        final String colorStr = getValue(BASE_LINE_COLOR);
+        return parseColor(colorStr);
+    }
 
     /**
      * Gets color from color field.


More information about the Dive4Elements-commits mailing list