Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.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 | 094ed9d1f2ad |
children |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.java Mon Oct 22 18:26:05 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.java Tue Oct 23 16:26:48 2018 +0200 @@ -17,7 +17,6 @@ import org.dive4elements.river.jfree.RiverAnnotation; import org.dive4elements.river.jfree.StyledTimeSeries; import org.dive4elements.river.jfree.TimeBounds; -import org.dive4elements.river.jfree.AxisDataset; import org.dive4elements.river.themes.ThemeDocument; import java.awt.Color; @@ -27,7 +26,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -36,15 +34,12 @@ import org.apache.log4j.Logger; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; -import org.jfree.chart.LegendItem; -import org.jfree.chart.LegendItemCollection; import org.jfree.chart.annotations.XYAnnotation; import org.jfree.chart.annotations.XYImageAnnotation; import org.jfree.chart.annotations.XYTextAnnotation; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.Marker; import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.jfree.data.Range; import org.jfree.data.general.Series; import org.jfree.data.time.FixedMillisecond; @@ -84,10 +79,10 @@ public TimeseriesChartGenerator() { super(); - xBounds = new HashMap<Integer, Bounds>(); - yBounds = new HashMap<Integer, Bounds>(); - domainMarker = new ArrayList<Marker>(); - valueMarker = new ArrayList<Marker>(); + xBounds = new HashMap<>(); + yBounds = new HashMap<>(); + domainMarker = new ArrayList<>(); + valueMarker = new ArrayList<>(); } @Override @@ -111,7 +106,11 @@ plot.setBackgroundPaint(Color.WHITE); adjustPlot(plot); - addDatasets(plot); + + final LegendAggregator legendBuilder = createLegendBuilder(); + + addDatasets(plot, legendBuilder); + adjustAxes(plot); addDomainAxisMarker(plot); addValueAxisMarker(plot); @@ -119,14 +118,15 @@ consumeAxisSettings(plot); - addAnnotationsToRenderer(plot); + addAnnotationsToRenderer(plot, legendBuilder); + legendBuilder.apply(context, plot); + addLogo(plot); - aggregateLegendEntries(plot); + return chart; } - /** * Return left most data points x value (on first axis). * Shortcut, especially to be overridden in (LS) charts where @@ -321,19 +321,6 @@ return ((TimeSeriesCollection) dataset).getSeries(idx); } - - /** - * This method creates new instances of AxisDataset. - * - * @param idx The symbol for the new AxisDataset. - */ - @Override - protected AxisDataset createAxisDataset(int idx) { - log.debug("Create a new AxisDataset for index: " + idx); - return new AxisDataset(idx); - } - - @Override protected void combineXBounds(Bounds bounds, int index) { if (bounds != null) { @@ -634,13 +621,14 @@ boolean visible, int axisIndex ) { + final String facetName = aandf.getFacetName(); String seriesName = aandf.getFacetDescription(); - TimeSeries series = new StyledTimeSeries(seriesName, theme); + + TimeSeries series = new StyledTimeSeries(facetName, seriesName, theme); // Add text annotations for single points. - List<XYTextAnnotation> xy = new ArrayList<XYTextAnnotation>(); - HashMap<FixedMillisecond, String> names = - new HashMap<FixedMillisecond, String>(); + List<XYTextAnnotation> xy = new ArrayList<>(); + HashMap<FixedMillisecond, String> names = new HashMap<>(); try { JSONArray points = new JSONArray((String) o);