Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/exports/XYChartGenerator.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 | d8e753d0fdb9 |
children | 8f59aa01c22a |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/XYChartGenerator.java Mon Oct 22 18:26:05 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/XYChartGenerator.java Tue Oct 23 16:26:48 2018 +0200 @@ -36,6 +36,7 @@ import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; +import org.jfree.ui.RectangleInsets; import org.json.JSONArray; import org.json.JSONException; @@ -77,9 +78,9 @@ /** The log that is used in this generator. */ private static Logger log = Logger.getLogger(XYChartGenerator.class); - protected List<Marker> domainMarkers = new ArrayList<Marker>(); + protected List<Marker> domainMarkers = new ArrayList<>(); - protected List<Marker> valueMarkers = new ArrayList<Marker>(); + protected List<Marker> valueMarkers = new ArrayList<>(); /** The max X range to include all X values of all series for each axis. */ protected Map<Integer, Bounds> xBounds; @@ -93,8 +94,8 @@ public XYChartGenerator() { super(); - xBounds = new HashMap<Integer, Bounds>(); - yBounds = new HashMap<Integer, Bounds>(); + xBounds = new HashMap<>(); + yBounds = new HashMap<>(); } @@ -127,7 +128,9 @@ //debugAxis(plot); - addDatasets(plot); + final LegendAggregator legendBuilder = createLegendBuilder(); + + addDatasets(plot, legendBuilder); //debugDatasets(plot); @@ -151,13 +154,14 @@ //debugAxis(plot); + // These have to go after the autozoom. - addAnnotationsToRenderer(plot); + addAnnotationsToRenderer(plot, legendBuilder); // Add a logo (maybe). addLogo(plot); - aggregateLegendEntries(plot); + legendBuilder.apply(context, plot); return chart; } @@ -315,14 +319,6 @@ return ((XYSeriesCollection) dataset).getSeries(idx); } - - @Override - protected AxisDataset createAxisDataset(int idx) { - log.debug("Create new AxisDataset for index: " + idx); - return new AxisDataset(idx); - } - - /** * Put debug output about datasets. */ @@ -911,7 +907,7 @@ int axisIndex ) { String seriesName = aandf.getFacetDescription(); - XYSeries series = new StyledXYSeries(seriesName, theme); + XYSeries series = new StyledXYSeries(aandf.getFacetName(), seriesName, theme); // Add text annotations for single points. List<XYTextAnnotation> xy = new ArrayList<XYTextAnnotation>(); @@ -946,44 +942,6 @@ addAxisSeries(series, axisIndex, visible); } - - /** - * Create a hash from a legenditem. - * This hash can then be used to merge legend items labels. - * @return hash for given legenditem to identify mergeables. - */ - public static String legendItemHash(LegendItem li) { - // TODO Do proper implementation. - // Ensure that only mergable sets are created. - // getFillPaint() - // getFillPaintTransformer() - // getLabel() - // getLine() - // getLinePaint() - // getLineStroke() - // getOutlinePaint() - // getOutlineStroke() - // Shape getShape() - // String getToolTipText() - // String getURLText() - // boolean isLineVisible() - // boolean isShapeFilled() - // boolean isShapeOutlineVisible() - // boolean isShapeVisible() - String hash = li.getLinePaint().toString(); - String label = li.getLabel(); - if (label.startsWith("W (") || label.startsWith("W(")) { - hash += "-W-"; - } - else if (label.startsWith("Q(") || label.startsWith("Q (")) { - hash += "-Q-"; - } - - // WQ.java holds example of using regex Matcher/Pattern. - - return hash; - } - /** True if x axis has been inverted. */ public boolean isInverted() { return inverted;