changeset 3154:a08538e21b55

Re-enable legend item aggregation. flys-artifacts/trunk@4766 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Sat, 23 Jun 2012 18:15:17 +0000
parents 46b9391b122a
children 74c974b10c75
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 2 files changed, 32 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sat Jun 23 14:31:02 2012 +0000
+++ b/flys-artifacts/ChangeLog	Sat Jun 23 18:15:17 2012 +0000
@@ -1,3 +1,9 @@
+2012-06-23	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java:
+	  Re-enable legend entry aggregation, take the threshold from
+	  settings.
+
 2012-06-23	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/ChartSettings.java:
@@ -359,7 +365,6 @@
 	  src/main/resources/messages_de.properties: Added i18n strings for chart
 	  titles and axes labels.
 
->>>>>>> .r4722
 2012-06-19	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	Fix issue681 (wrong vertical lines in duration curve q-mainvalues on
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Sat Jun 23 14:31:02 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Sat Jun 23 18:15:17 2012 +0000
@@ -254,7 +254,7 @@
         // These have to go after the autozoom.
         addAnnotationsToRenderer(plot);
 
-        //aggregateLegendEntries(plot);
+        aggregateLegendEntries(plot);
 
         return chart;
     }
@@ -1357,7 +1357,16 @@
         // Find "similar" entries if aggregation is enabled.
 
         int maxListSize = 0;
-        int AGGR_THRESHOLD = 2;
+        int AGGR_THRESHOLD = 0;
+
+        Integer threshold = getChartSettings().getLegendSection()
+            .getAggregationThreshold();
+
+        AGGR_THRESHOLD = (threshold != null) ? threshold.intValue() : 0;
+
+        if (AGGR_THRESHOLD > old.getItemCount() || AGGR_THRESHOLD <= 0){
+            return;
+        }
 
         HashMap<String, List<LegendItem>> entries = new LinkedHashMap<String, List<LegendItem>>();
         for (Iterator i = old.iterator(); i.hasNext();) {
@@ -1387,22 +1396,24 @@
         for (Map.Entry<String, List<LegendItem>> cursor: entries.entrySet()) {
             List<LegendItem> itemList = cursor.getValue();
             if (itemList.size() >= AGGR_THRESHOLD) {
-                // TODO now do merging
+                // Now do merging.
+                LegendItem item = (LegendItem) itemList.get(0);
+                // Unfortunately we cannot clone and just setDescription, as this
+                // method was added in JFreeChart 1.0.14 (we are at .13).
+                LegendItem merged = new LegendItem(
+                    mergeLegendNames(itemList), item.getDescription(), item.getToolTipText(),
+                    item.getURLText(), item.isShapeVisible(), item.getShape(),
+                    item.isShapeFilled(), item.getFillPaint(), item.isShapeOutlineVisible(),
+                    item.getOutlinePaint(), item.getOutlineStroke(), item.isLineVisible(),
+                    item.getLine(), item.getLineStroke(), item.getLinePaint());
+                newLegend.add(merged);
             }
             else {
-                // TODO create singular new entry
+                // Do not merge entries.
+                for (LegendItem li: itemList) {
+                    newLegend.add(li); 
+                }
             }
-
-           LegendItem item = (LegendItem) itemList.get(0);
-           // Unfortunately we cannot clone and just setDescription, as this
-           // method was added in JFreeChart 1.0.14 (we are at .13).
-           LegendItem merged = new LegendItem(
-               mergeLegendNames(itemList), item.getDescription(), item.getToolTipText(),
-               item.getURLText(), item.isShapeVisible(), item.getShape(),
-               item.isShapeFilled(), item.getFillPaint(), item.isShapeOutlineVisible(),
-               item.getOutlinePaint(), item.getOutlineStroke(), item.isLineVisible(),
-               item.getLine(), item.getLineStroke(), item.getLinePaint());
-           newLegend.add(merged);
         }
 
         plot.setFixedLegendItems (newLegend);

http://dive4elements.wald.intevation.org