comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java @ 1085:07878836ee0d

Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale. flys-artifacts/trunk@2588 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 26 Aug 2011 08:49:18 +0000
parents f16b66839e59
children e298c4d28927
comparison
equal deleted inserted replaced
1084:583314dafdb6 1085:07878836ee0d
9 import java.awt.geom.Line2D; 9 import java.awt.geom.Line2D;
10 10
11 import org.jfree.chart.annotations.XYTextAnnotation; 11 import org.jfree.chart.annotations.XYTextAnnotation;
12 import org.jfree.chart.axis.ValueAxis; 12 import org.jfree.chart.axis.ValueAxis;
13 import org.jfree.chart.util.LineUtilities; 13 import org.jfree.chart.util.LineUtilities;
14 import org.jfree.text.TextUtilities;
15 import org.jfree.chart.plot.PlotOrientation; 14 import org.jfree.chart.plot.PlotOrientation;
16 import org.jfree.chart.plot.XYPlot; 15 import org.jfree.chart.plot.XYPlot;
17 import org.jfree.chart.entity.XYAnnotationEntity; 16 import org.jfree.chart.entity.XYAnnotationEntity;
18 import org.jfree.chart.plot.PlotRenderingInfo; 17 import org.jfree.chart.plot.PlotRenderingInfo;
19 import org.jfree.chart.ChartRenderingInfo; 18 import org.jfree.chart.ChartRenderingInfo;
20 import org.jfree.chart.plot.Plot; 19 import org.jfree.chart.plot.Plot;
21 20
21 import org.jfree.data.Range;
22
23 import org.jfree.text.TextUtilities;
24
22 import org.jfree.ui.RectangleEdge; 25 import org.jfree.ui.RectangleEdge;
23 import org.jfree.ui.TextAnchor; 26 import org.jfree.ui.TextAnchor;
24 27
25 28
26 /** 29 /**
41 } 44 }
42 45
43 /** Which axis to stick to. */ 46 /** Which axis to stick to. */
44 protected SimpleAxis stickyAxis = SimpleAxis.X_AXIS; 47 protected SimpleAxis stickyAxis = SimpleAxis.X_AXIS;
45 48
49 /** The 1-dimensional position of this annotation. */
50 protected float pos;
51
46 52
47 /** 53 /**
48 * Trivial constructor. 54 * Trivial constructor.
49 * 55 *
50 * @param text Text to display. 56 * @param text Text to display.
51 * @param x X-position in dataspace (typical horizontal, in km). 57 * @param x X-position in dataspace (typical horizontal, in km).
52 * @param y Y-position in dataspace (typical vertical, in m). 58 * @param y Y-position in dataspace (typical vertical, in m).
59 * @deprecated
53 */ 60 */
54 public StickyAxisAnnotation(String text, float x, float y) { 61 public StickyAxisAnnotation(String text, float x, float y) {
55 super(text, x, y); 62 super(text, x, y);
56 setStickyAxis(SimpleAxis.X_AXIS); 63 setStickyAxis(SimpleAxis.X_AXIS);
57 } 64 }
58 65
66
67 /**
68 * Constructor with given explicit axis.
69 * @param text the text to display.
70 * @param pos the position at which to draw the text and mark.
71 * @param stickyAxis the axis at which to stick (and to which 'pos' is
72 * relative).
73 */
74 public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis) {
75 super(text, pos, pos);
76 setStickyAxis(stickAxis);
77 this.pos = pos;
78 }
79
80 /**
81 * Legacy-Constructor.
82 * @deprecated
83 */
59 public StickyAxisAnnotation(String text, float x, float y, 84 public StickyAxisAnnotation(String text, float x, float y,
60 SimpleAxis stickAxis) { 85 SimpleAxis stickAxis) {
61 super(text, x, y); 86 super(text, x, y);
62 setStickyAxis(stickAxis); 87 setStickyAxis(stickAxis);
63 } 88 this.pos = x;
64 89 }
65 90
66 91
67 /** 92 /**
68 * Sets the "sticky axis" (whether to draw annotations at the 93 * Sets the "sticky axis" (whether to draw annotations at the
69 * X- or the Y-Axis. 94 * X- or the Y-Axis.
72 */ 97 */
73 public void setStickyAxis(SimpleAxis stickyAxis) { 98 public void setStickyAxis(SimpleAxis stickyAxis) {
74 this.stickyAxis = stickyAxis; 99 this.stickyAxis = stickyAxis;
75 if (stickyAxis == SimpleAxis.X_AXIS) { 100 if (stickyAxis == SimpleAxis.X_AXIS) {
76 this.setRotationAngle(270f * (Math.PI / 180f)); 101 this.setRotationAngle(270f * (Math.PI / 180f));
102 this.setRotationAnchor(TextAnchor.CENTER_LEFT);
103 this.setTextAnchor(TextAnchor.CENTER_LEFT);
104 } else {
105 this.setRotationAngle(0f * (Math.PI / 180f));
77 this.setRotationAnchor(TextAnchor.CENTER_LEFT); 106 this.setRotationAnchor(TextAnchor.CENTER_LEFT);
78 this.setTextAnchor(TextAnchor.CENTER_LEFT); 107 this.setTextAnchor(TextAnchor.CENTER_LEFT);
79 } 108 }
80 } 109 }
81 110
129 } 158 }
130 159
131 g2.setPaint(this.paint); 160 g2.setPaint(this.paint);
132 g2.setStroke(this.stroke); 161 g2.setStroke(this.stroke);
133 */ 162 */
134 j2DY1 = (float) RectangleEdge.coordinate(dataArea, domainEdge); 163 if (this.stickyAxis == SimpleAxis.X_AXIS) {
135 double rangeLow = rangeAxis.getRange().getLowerBound(); 164 j2DY1 = (float) RectangleEdge.coordinate(dataArea, domainEdge);
136 // Line ends at 1.5% of full distance. 165 double rangeLow = rangeAxis.getRange().getLowerBound();
137 j2DY2 = (float) rangeAxis.valueToJava2D( 166 // Line ends at 1.5% of full distance.
138 (1f - 0.015f) * rangeLow + 0.015f * 167 j2DY2 = (float) rangeAxis.valueToJava2D(
139 rangeAxis.getRange().getUpperBound(), 168 (1f - 0.015f) * rangeLow + 0.015f *
140 dataArea, rangeEdge); 169 rangeAxis.getRange().getUpperBound(),
141 j2DX1 = (float) domainAxis.valueToJava2D(x, dataArea, domainEdge); 170 dataArea, rangeEdge);
142 j2DX2 = j2DX1; 171 j2DX1 = (float) domainAxis.valueToJava2D(x, dataArea, domainEdge);
172 j2DX2 = j2DX1;
173 } else {
174 j2DX1 = (float) RectangleEdge.coordinate(dataArea, rangeEdge);
175 Range domainRange = domainAxis.getRange();
176 double rangeLow = domainRange.getLowerBound();
177 // Line ends at 1.5% of full distance.
178 j2DX2 = (float) domainAxis.valueToJava2D(
179 (1f - 0.015f) * rangeLow + 0.015f *
180 domainRange.getUpperBound(),
181 dataArea, domainEdge);
182 j2DY1 = (float) rangeAxis.valueToJava2D(pos, dataArea, rangeEdge);
183 j2DY2 = j2DY1;
184 }
143 185
144 Line2D line = new Line2D.Float(j2DX1, j2DY1, j2DX2, j2DY2); 186 Line2D line = new Line2D.Float(j2DX1, j2DY1, j2DX2, j2DY2);
145 187
146 // line is clipped to avoid JRE bug 6574155, for more info 188 // line is clipped to avoid JRE bug 6574155, for more info
147 // see JFreeChart bug 2221495 189 // see JFreeChart bug 2221495
185 PlotOrientation orientation = plot.getOrientation(); 227 PlotOrientation orientation = plot.getOrientation();
186 RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( 228 RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
187 plot.getDomainAxisLocation(), orientation); 229 plot.getDomainAxisLocation(), orientation);
188 RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( 230 RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
189 plot.getRangeAxisLocation(), orientation); 231 plot.getRangeAxisLocation(), orientation);
190 float anchorX = (float) domainAxis.valueToJava2D( 232 float anchorX = 0f;
191 getX(), dataArea, domainEdge); 233 float anchorY = 0.0f;
192 float anchorY = (float) rangeAxis.valueToJava2D( 234 if (this.stickyAxis == SimpleAxis.X_AXIS) {
193 getY(), dataArea, rangeEdge); 235 // Text starts at 1.5% of full distance.
236 float rangeLow = (float) rangeAxis.getRange().getLowerBound();
237 float y = rangeLow + 0.02f * ((float)
238 rangeAxis.getRange().getUpperBound() - rangeLow);
239 setY(y);
240
241 anchorX = (float) domainAxis.valueToJava2D(
242 getX(), dataArea, domainEdge);
243 anchorY = (float) rangeAxis.valueToJava2D(
244 getY(), dataArea, rangeEdge);
245 } else {
246 float rangeLow = (float) domainAxis.getRange().getLowerBound();
247 float x = rangeLow + 0.02f * ((float)
248 domainAxis.getRange().getUpperBound() - rangeLow);
249 setX(x);
250 anchorX = (float) domainAxis.valueToJava2D(
251 getX(), dataArea, domainEdge);
252 anchorY = (float) rangeAxis.valueToJava2D(
253 getY(), dataArea, rangeEdge);
254 }
194 if (orientation == PlotOrientation.HORIZONTAL) { 255 if (orientation == PlotOrientation.HORIZONTAL) {
195 float tempAnchor = anchorX; 256 float tempAnchor = anchorX;
196 anchorX = anchorY; 257 anchorX = anchorY;
197 anchorY = tempAnchor; 258 anchorY = tempAnchor;
198 } 259 }

http://dive4elements.wald.intevation.org