diff artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java @ 9555:ef5754ba5573

Implemented legend aggregation based on type of themes. Added theme-editor style configuration for aggregated legend entries. Only configured themes get aggregated.
author gernotbelger
date Tue, 23 Oct 2018 16:26:48 +0200
parents ee6508687e3f
children
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java	Mon Oct 22 18:26:05 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java	Tue Oct 23 16:26:48 2018 +0200
@@ -33,13 +33,12 @@
 import org.dive4elements.river.themes.ThemeDocument;
 import org.dive4elements.river.utils.Formatter;
 import org.dive4elements.river.utils.RiverUtils;
-import org.jfree.chart.LegendItemCollection;
+import org.jfree.chart.LegendItem;
 import org.jfree.chart.annotations.XYBoxAnnotation;
 import org.jfree.chart.annotations.XYTextAnnotation;
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.data.xy.XYSeries;
 
-
 /**
  * An OutGenerator that generates cross section graphs.
  */
@@ -165,7 +164,7 @@
     }
 
     @Override
-    protected void doAddFurtherAnnotations(XYPlot plot, List<RiverAnnotation> annotations) {
+    protected void doAddFurtherAnnotations(XYPlot plot, LegendAggregator legendBuilder, List<RiverAnnotation> annotations) {
 
         // Paints for the boxes/lines.
         Stroke basicStroke = new BasicStroke(1.0f);
@@ -189,17 +188,14 @@
             if (theme != null) {
                 textStyle = theme.parseComplexTextStyle();
                 if (fa.getLabel() != null) {
-                    LegendItemCollection lic = new LegendItemCollection();
-                    LegendItemCollection old = plot.getFixedLegendItems();
-                    lic.add(createLegendItem(theme, fa.getLabel()));
-                    // (Re-)Add prior legend entries.
-                    if (old != null) {
-                        old.addAll(lic);
-                    }
-                    else {
-                        old = lic;
-                    }
-                    plot.setFixedLegendItems(old);
+                    
+                    Color color = theme.parseLineColorField();
+                    if (color == null)
+                        color = Color.BLACK;
+
+                    final String themeType = null;
+                    
+                    legendBuilder.addLegendItem(themeType, new LegendItem(fa.getLabel(), color));
                 }
             }
 
@@ -282,17 +278,20 @@
         
         CallContext context = getContext();
 
+        final String facetDescription = artifactFacet.getFacetDescription();
+        final String facetName = artifactFacet.getFacetName();
+        
         if (name.equals(CROSS_SECTION)) {
-            doCrossSectionOut(
+            doCrossSectionOut(facetName,
                     artifactFacet.getData(context),
-                    artifactFacet.getFacetDescription(),
+                    facetDescription,
                     attr,
                     visible);
         }
         else if (name.endsWith(CROSS_SECTION_WATER_LINE)) {
-            doCrossSectionWaterLineOut(
+            doCrossSectionWaterLineOut(facetName,
                     artifactFacet.getData(context),
-                    artifactFacet.getFacetDescription(),
+                    facetDescription,
                     attr,
                     visible);
         }
@@ -304,7 +303,7 @@
         }
         else if (name.equals(HYK)) {
             doHyk(artifactFacet.getData(context),
-                    artifactFacet.getFacetDescription(),
+                    facetDescription,
                     attr,
                     visible);
         }
@@ -312,9 +311,9 @@
             VegetationZonesCrossSectionProcessor.generateSeries(this, artifactFacet, context, attr, visible);
         }
         else if (FacetTypes.IS.MANUALLINE(name)) {
-            doCrossSectionWaterLineOut(
+            doCrossSectionWaterLineOut(facetName,
                     artifactFacet.getData(context),
-                    artifactFacet.getFacetDescription(),
+                    facetDescription,
                     attr,
                     visible);
         }
@@ -345,6 +344,7 @@
      * @param theme Theme for the data series.
      */
     protected void doCrossSectionWaterLineOut(
+            String facetName,
             Object   o,
             String   seriesName,
             ThemeDocument theme,
@@ -354,7 +354,7 @@
 
         Lines.LineData lines = (Lines.LineData) o;
         // DO NOT SORT DATA! This destroys the gaps indicated by NaNs.
-        StyledXYSeries series = new StyledXYSeries(seriesName, false, theme);
+        StyledXYSeries series = new StyledXYSeries(facetName, seriesName, false, theme);
 
         CallContext context = getContext();
         
@@ -433,7 +433,8 @@
      * @param seriesName name of the data (line) to display in legend.
      * @param theme Theme for the data series.
      */
-    protected void doCrossSectionOut(
+    private void doCrossSectionOut(
+            String facetName,
             Object   o,
             String   seriesName,
             ThemeDocument theme,
@@ -441,7 +442,7 @@
             ) {
         log.debug("CrossSectionGenerator.doCrossSectionOut");
 
-        XYSeries series = new StyledXYSeries(seriesName, theme);
+        XYSeries series = new StyledXYSeries(facetName, seriesName, theme);
 
         StyledSeriesBuilder.addPoints(series, (double [][]) o, false);
 

http://dive4elements.wald.intevation.org