comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 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 6c91e05a5f51
children 8c78c707aa2d
comparison
equal deleted inserted replaced
3153:46b9391b122a 3154:a08538e21b55
252 autoZoom(plot); 252 autoZoom(plot);
253 253
254 // These have to go after the autozoom. 254 // These have to go after the autozoom.
255 addAnnotationsToRenderer(plot); 255 addAnnotationsToRenderer(plot);
256 256
257 //aggregateLegendEntries(plot); 257 aggregateLegendEntries(plot);
258 258
259 return chart; 259 return chart;
260 } 260 }
261 261
262 262
1355 public void aggregateLegendEntries(XYPlot plot) { 1355 public void aggregateLegendEntries(XYPlot plot) {
1356 LegendItemCollection old = plot.getLegendItems(); 1356 LegendItemCollection old = plot.getLegendItems();
1357 // Find "similar" entries if aggregation is enabled. 1357 // Find "similar" entries if aggregation is enabled.
1358 1358
1359 int maxListSize = 0; 1359 int maxListSize = 0;
1360 int AGGR_THRESHOLD = 2; 1360 int AGGR_THRESHOLD = 0;
1361
1362 Integer threshold = getChartSettings().getLegendSection()
1363 .getAggregationThreshold();
1364
1365 AGGR_THRESHOLD = (threshold != null) ? threshold.intValue() : 0;
1366
1367 if (AGGR_THRESHOLD > old.getItemCount() || AGGR_THRESHOLD <= 0){
1368 return;
1369 }
1361 1370
1362 HashMap<String, List<LegendItem>> entries = new LinkedHashMap<String, List<LegendItem>>(); 1371 HashMap<String, List<LegendItem>> entries = new LinkedHashMap<String, List<LegendItem>>();
1363 for (Iterator i = old.iterator(); i.hasNext();) { 1372 for (Iterator i = old.iterator(); i.hasNext();) {
1364 LegendItem item = (LegendItem) i.next(); 1373 LegendItem item = (LegendItem) i.next();
1365 String hash = legendItemHash(item); 1374 String hash = legendItemHash(item);
1385 // entry if needed. 1394 // entry if needed.
1386 LegendItemCollection newLegend = new LegendItemCollection(); 1395 LegendItemCollection newLegend = new LegendItemCollection();
1387 for (Map.Entry<String, List<LegendItem>> cursor: entries.entrySet()) { 1396 for (Map.Entry<String, List<LegendItem>> cursor: entries.entrySet()) {
1388 List<LegendItem> itemList = cursor.getValue(); 1397 List<LegendItem> itemList = cursor.getValue();
1389 if (itemList.size() >= AGGR_THRESHOLD) { 1398 if (itemList.size() >= AGGR_THRESHOLD) {
1390 // TODO now do merging 1399 // Now do merging.
1400 LegendItem item = (LegendItem) itemList.get(0);
1401 // Unfortunately we cannot clone and just setDescription, as this
1402 // method was added in JFreeChart 1.0.14 (we are at .13).
1403 LegendItem merged = new LegendItem(
1404 mergeLegendNames(itemList), item.getDescription(), item.getToolTipText(),
1405 item.getURLText(), item.isShapeVisible(), item.getShape(),
1406 item.isShapeFilled(), item.getFillPaint(), item.isShapeOutlineVisible(),
1407 item.getOutlinePaint(), item.getOutlineStroke(), item.isLineVisible(),
1408 item.getLine(), item.getLineStroke(), item.getLinePaint());
1409 newLegend.add(merged);
1391 } 1410 }
1392 else { 1411 else {
1393 // TODO create singular new entry 1412 // Do not merge entries.
1394 } 1413 for (LegendItem li: itemList) {
1395 1414 newLegend.add(li);
1396 LegendItem item = (LegendItem) itemList.get(0); 1415 }
1397 // Unfortunately we cannot clone and just setDescription, as this 1416 }
1398 // method was added in JFreeChart 1.0.14 (we are at .13).
1399 LegendItem merged = new LegendItem(
1400 mergeLegendNames(itemList), item.getDescription(), item.getToolTipText(),
1401 item.getURLText(), item.isShapeVisible(), item.getShape(),
1402 item.isShapeFilled(), item.getFillPaint(), item.isShapeOutlineVisible(),
1403 item.getOutlinePaint(), item.getOutlineStroke(), item.isLineVisible(),
1404 item.getLine(), item.getLineStroke(), item.getLinePaint());
1405 newLegend.add(merged);
1406 } 1417 }
1407 1418
1408 plot.setFixedLegendItems (newLegend); 1419 plot.setFixedLegendItems (newLegend);
1409 } 1420 }
1410 1421

http://dive4elements.wald.intevation.org