annotate gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonRenderer.java @ 515:234d9892e497

Fixed "Profilschnitte" for gnv/issue153. gnv-artifacts/trunk@609 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 22 Jan 2010 18:51:47 +0000
parents bc5901bb4525
children 9a828e5a2390
rev   line source
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.jfreechart;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
3 import java.util.ArrayList;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
4
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import java.awt.Color;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.awt.Graphics2D;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 import java.awt.Paint;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import java.awt.Shape;
447
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
9 import java.awt.BasicStroke;
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
10 import java.awt.FontMetrics;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
11 import java.awt.Font;
447
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
12
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import java.awt.geom.GeneralPath;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import java.awt.geom.Rectangle2D;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import java.awt.geom.Rectangle2D.Double;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 import org.jfree.data.Range;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
19 import org.jfree.chart.axis.ValueAxis;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
20
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
21 import org.jfree.ui.RectangleEdge;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
22
447
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
23 import org.apache.log4j.Logger;
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
24
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
25 import org.jfree.text.TextUtilities;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
26
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
27
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 /**
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
29 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
30 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 */
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 public class PolygonRenderer
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 {
447
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
34 private static Logger log = Logger.getLogger(
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
35 PolygonRenderer.class);
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
36
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 public interface PaintLookup {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 Paint getPaint(int index);
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 } // interface PaintLookup
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
43 public static class DefaultLabelGenerator
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
44 implements PolygonSeriesLabelGenerator
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
45 {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
46 public DefaultLabelGenerator() {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
47 }
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
49 public String generateLabel(PolygonSeries series) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
50 Object label = series.getAttribute("label");
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
51 return label != null
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
52 ? toString(label)
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
53 : null;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
54 }
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
56 protected String toString(Object label) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
57 return label.toString();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
58 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
59 } // class DefaultLabelGenerator
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
61 public static final PolygonSeriesLabelGenerator
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
62 DEFAULT_LABEL_GENERATOR_INSTANCE = new DefaultLabelGenerator();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
63
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
64 protected PaintLookup lookup;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
65 protected PolygonSeriesLabelGenerator labelGenerator;
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 public PolygonRenderer(PaintLookup lookup) {
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
68 this(lookup, null);
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
71 public PolygonRenderer(
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
72 PaintLookup lookup,
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
73 PolygonSeriesLabelGenerator labelGenerator
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
74 ) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
75 this.lookup = lookup;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
76 this.labelGenerator = labelGenerator;
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
79 public void drawPolygons(
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 Graphics2D graphics,
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
81 PolygonPlot plot,
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
82 Rectangle2D area,
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 PolygonDataset dataset
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 ) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 int seriesCount = dataset.getSeriesCount();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 for (int i = 0; i < seriesCount; i++) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 PolygonSeries series = dataset.getSeries(i);
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 Integer colorIdx = (Integer)series.getAttribute("fill");
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 if (colorIdx != null) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 Paint paint = lookup.getPaint(colorIdx.intValue());
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 graphics.setPaint(paint != null ? paint : Color.black);
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
93 graphics.fill(constructShape(plot, area, series, true));
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 else {
447
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
96 Number lineWidth = (Number)series.getAttribute("line.width");
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
97 BasicStroke stroke = new BasicStroke(
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
98 lineWidth != null ? lineWidth.floatValue() : 1f);
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
99 graphics.setStroke(stroke);
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 graphics.setPaint(Color.black);
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
101 graphics.draw(constructShape(plot, area, series, false));
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 }
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
104 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
105
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
106 public void drawLabels(
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
107 final Graphics2D graphics,
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
108 final PolygonPlot plot,
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
109 final Rectangle2D area,
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
110 PolygonDataset dataset
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
111 ) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
112 if (labelGenerator == null) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
113 return;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
114 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
115
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
116 final ArrayList<Rectangle2D> bboxes = new ArrayList<Rectangle2D>();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
117
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
118 Font font = graphics.getFont();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
119 font = font.deriveFont(Font.PLAIN, Math.max(8, font.getSize()-3));
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
120 graphics.setFont(font);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
121 FontMetrics metrics = graphics.getFontMetrics(font);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
122
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
123 for (int i = dataset.getSeriesCount()-1; i >= 0; --i) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
124 PolygonSeries series = dataset.getSeries(i);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
125
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
126 String label = labelGenerator.generateLabel(series);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
127 if (label == null) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
128 continue;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
129 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
130
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
131 final Rectangle2D box = TextUtilities.getTextBounds(
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
132 label, graphics, metrics);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
133
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
134 for (int j = series.getItemCount()-1; j >= 0; --j) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
135 final CompactXYItems ring = series.getItem(j);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
136 LevelOrderIndices loi = new LevelOrderIndices(ring.size()-1);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
137 Rectangle2D r = (Rectangle2D)loi.visit(
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
138 new LevelOrderIndices.Visitor()
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
139 {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
140 ValueAxis da = plot.getDomainAxis();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
141 ValueAxis ra = plot.getRangeAxis();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
142 RectangleEdge de = plot.getDomainAxisEdge();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
143 RectangleEdge re = plot.getRangeAxisEdge();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
144 Rectangle2D.Double r = new Rectangle2D.Double(
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
145 0d, 0d, box.getWidth(), box.getHeight());
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
146
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
147 public Object visit(int index) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
148 r.x = da.valueToJava2D(ring.getX(index), area, de)
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
149 - 0.5*box.getWidth();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
150 r.y = ra.valueToJava2D(ring.getY(index), area, re)
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
151 + 0.5*box.getHeight();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
152
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
153 for (Rectangle2D b: bboxes) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
154 if (b.intersects(r)) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
155 return null;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
156 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
157 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
158 return r;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
159 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
160 });
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
161
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
162 if (r != null) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
163 bboxes.add(r);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
164 graphics.drawString(
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
165 label, (float)r.getX(), (float)r.getY());
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
166 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
167 } // for all items in series
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
168 } // for all series
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
171 protected Shape constructShape(
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
172 PolygonPlot plot,
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
173 Rectangle2D area,
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
174 PolygonSeries series,
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
175 boolean close
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
176 ) {
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
177 ValueAxis da = plot.getDomainAxis();
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
178 ValueAxis ra = plot.getRangeAxis();
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
179 RectangleEdge de = plot.getDomainAxisEdge();
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
180 RectangleEdge re = plot.getRangeAxisEdge();
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
181
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 CompactXYItems [] rings = series.getRings();
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
183 GeneralPath path = new GeneralPath();
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
184
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 for (int i = 0; i < rings.length; ++i) {
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
186
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 CompactXYItems ring = rings[i];
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
188
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189 double [] data = ring.getData();
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
190
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191 if (data.length >= 2) {
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
192 path.moveTo(
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
193 (float)da.valueToJava2D(data[0], area, de),
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
194 (float)ra.valueToJava2D(data[1], area, re));
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 for (int j = 2; j < data.length;) {
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
197 path.lineTo(
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
198 (float)da.valueToJava2D(data[j++], area, de),
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
199 (float)ra.valueToJava2D(data[j++], area, re));
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200 }
437
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 422
diff changeset
201 if (close) {
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 422
diff changeset
202 path.closePath();
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 422
diff changeset
203 }
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
204 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
205 return path;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
206 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
207
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
208 public Rectangle2D getBoundingBox(PolygonDataset dataset) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
209 Rectangle2D bbox = null;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
210
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
211 for (int i = 0, N = dataset.getSeriesCount(); i < N; i++) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
212 Range domain = dataset.getSeries(i).getDomainBounds();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
213 Range range = dataset.getSeries(i).getRangeBounds();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
214
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
215 double x = domain.getLowerBound();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
216 double y = range.getLowerBound();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
217 double w = Math.abs(domain.getUpperBound() - x);
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
218 double h = Math.abs(range.getUpperBound() - y);
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
219
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
220 if (bbox == null) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
221 bbox = new Rectangle2D.Double(x, y, w, h);
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
222 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223 else {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224 bbox.add(new Rectangle2D.Double(x, y, w, h));
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
225 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
226 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
227
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
228 return bbox;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
229 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
230
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
231 public Rectangle2D getBounds(PolygonSeries series) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
232
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
233 Range domain = series.getDomainBounds();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
234 Range range = series.getRangeBounds();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
235
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
236 return new Rectangle2D.Double(
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
237 domain.getLowerBound(), range.getLowerBound(),
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
238 domain.getUpperBound(), range.getUpperBound()
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
239 );
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
240 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
241 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
242 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org