Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/exports/AnnotationRenderer.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 | 1cc7653ca84f |
children |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/AnnotationRenderer.java Mon Oct 22 18:26:05 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/AnnotationRenderer.java Tue Oct 23 16:26:48 2018 +0200 @@ -11,7 +11,6 @@ import java.awt.BasicStroke; import java.awt.Color; -import java.awt.Font; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -26,7 +25,6 @@ import org.dive4elements.river.themes.TextStyle; import org.dive4elements.river.themes.ThemeDocument; import org.jfree.chart.LegendItem; -import org.jfree.chart.LegendItemCollection; import org.jfree.chart.annotations.XYLineAnnotation; import org.jfree.chart.annotations.XYTextAnnotation; import org.jfree.chart.plot.XYPlot; @@ -42,16 +40,10 @@ private static float ANNOTATIONS_AXIS_OFFSET = 0.02f; - private final ChartSettings settings; - private final Map<Integer, AxisDataset> datasets; - private final String fontName; - - public AnnotationRenderer(final ChartSettings settings, final Map<Integer, AxisDataset> datasets, final String fontName) { - this.settings = settings; + public AnnotationRenderer(final Map<Integer, AxisDataset> datasets) { this.datasets = datasets; - this.fontName = fontName; } /** @@ -66,7 +58,7 @@ * @param datasets * Map of axis index and datasets */ - public final void addAnnotationsToRenderer(final XYPlot plot, final List<RiverAnnotation> annotations) { + public final void addAnnotationsToRenderer(final XYPlot plot, final LegendAggregator legendBuilder, final List<RiverAnnotation> annotations) { if (annotations == null || annotations.isEmpty()) { log.debug("addAnnotationsToRenderer: no annotations."); return; @@ -88,10 +80,6 @@ textStyle = theme.parseComplexTextStyle(); lineStyle = theme.parseComplexLineStyle(); if (fa.getLabel() != null) { - // Legend handling, maybe misplaced? - final LegendItemCollection lic = new LegendItemCollection(); - LegendItemCollection old = plot.getFixedLegendItems(); - Color color = theme.parseLineColorField(); if (color == null) { color = Color.BLACK; @@ -104,22 +92,12 @@ final LegendItem newItem = new LegendItem(fa.getLabel(), color); - final LegendSection ls = this.settings != null ? this.settings.getLegendSection() : null; - - final Integer size = ls != null ? ls.getFontSize() : null; - - newItem.setLabelFont(new Font(this.fontName, Font.PLAIN, size)); - newItem.setLabelPaint(textColor); - lic.add(newItem); - // (Re-)Add prior legend entries. - if (old != null) { - old.addAll(lic); - } else { - old = lic; - } - plot.setFixedLegendItems(old); + // REMARK: connection to facet is lost at this point + final String themeType = null; + + legendBuilder.addLegendItem(themeType, newItem); } } @@ -231,7 +209,8 @@ renderer.addAnnotation(lineAnnotation, org.jfree.ui.Layer.FOREGROUND); } - public final void addYAnnotationsToRenderer(final XYPlot plot, final SortedMap<Integer, RiverAnnotation> yAnnotations) { + public final void addYAnnotationsToRenderer(final XYPlot plot, final LegendAggregator legendBuilder, + final SortedMap<Integer, RiverAnnotation> yAnnotations) { final List<RiverAnnotation> annotations = new ArrayList<>(); for (final Map.Entry<Integer, RiverAnnotation> entry : yAnnotations.entrySet()) { @@ -249,7 +228,7 @@ } } - addAnnotationsToRenderer(plot, annotations); + addAnnotationsToRenderer(plot, legendBuilder, annotations); } /**