comparison flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java @ 1034:bf3b3a8d089b

Slightly improved rendering of annotations in LongitudinalSection-plots. flys-artifacts/trunk@2495 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 16 Aug 2011 11:43:47 +0000
parents 10bafb4f46cc
children 9f69a5f0af98
comparison
equal deleted inserted replaced
1033:821aaceb2776 1034:bf3b3a8d089b
12 import org.jfree.chart.axis.ValueAxis; 12 import org.jfree.chart.axis.ValueAxis;
13 import org.jfree.chart.plot.XYPlot; 13 import org.jfree.chart.plot.XYPlot;
14 import org.jfree.chart.title.TextTitle; 14 import org.jfree.chart.title.TextTitle;
15 import org.jfree.data.Range; 15 import org.jfree.data.Range;
16 import org.jfree.data.xy.XYSeries; 16 import org.jfree.data.xy.XYSeries;
17 import org.jfree.ui.TextAnchor;
17 18
18 import org.w3c.dom.Document; 19 import org.w3c.dom.Document;
19 20
20 import de.intevation.artifacts.Artifact; 21 import de.intevation.artifacts.Artifact;
21 22
101 @Override 102 @Override
102 public JFreeChart generateChart() { 103 public JFreeChart generateChart() {
103 JFreeChart c = super.generateChart(); 104 JFreeChart c = super.generateChart();
104 XYPlot p = (XYPlot) c.getPlot(); 105 XYPlot p = (XYPlot) c.getPlot();
105 106
106 for (Annotation a: annotations) { 107 redoAnnotations(p, p.getDomainAxis());
107 double pos = a.getRange().getA().doubleValue(); 108
108 XYTextAnnotation ta = new XYTextAnnotation(a.getPosition().getValue(), pos, 140);
109 ta.setRotationAngle(270.0 / (Math.PI * 2.0));
110 p.addAnnotation(ta);
111 XYLineAnnotation la = new XYLineAnnotation(pos, 0, pos, 140);
112 p.addAnnotation(la);
113 }
114 return c; 109 return c;
115 } 110 }
116 111
117 112
118 protected String getXAxisLabel() { 113 protected String getXAxisLabel() {
132 msg(I18N_2YAXIS_LABEL, I18N_2YAXIS_LABEL_DEFAULT)); 127 msg(I18N_2YAXIS_LABEL, I18N_2YAXIS_LABEL_DEFAULT));
133 128
134 plot.setRangeAxis(1, qAxis); 129 plot.setRangeAxis(1, qAxis);
135 130
136 invertXAxis(plot.getDomainAxis()); 131 invertXAxis(plot.getDomainAxis());
132 }
133
134
135 /**
136 * Remove all annotations from plot and re-insert them at an approximately
137 * okay position. The followed approach is naive but side-effect free.
138 */
139 protected void redoAnnotations(XYPlot plot, ValueAxis axis) {
140 plot.clearAnnotations();
141 ValueAxis yAxis = plot.getRangeAxis();
142 float posY = 140.f;
143 if (yAxis != null) {
144 posY = (float) yAxis.getRange().getLowerBound();
145 // Lets add some (1%) space between Text and Axis .
146 posY += 0.1f * (yAxis.getRange().getUpperBound()
147 - yAxis.getRange().getLowerBound());
148 }
149 double freeFrom = axis.getRange().getLowerBound();
150 //logger.warn("Axis lower Bound: " + freeFrom);
151
152 // Assuming ordered annotations.
153 for (Annotation a: annotations) {
154 float posX = (float) a.getRange().getA().doubleValue();
155 if (posX < freeFrom) { continue; }
156 String text = a.getPosition().getValue();
157
158 XYTextAnnotation ta = new XYTextAnnotation(text, posX, posY);
159 double rotation = 270.0f * (Math.PI / 180.0f);
160 ta.setRotationAngle(rotation);
161 ta.setRotationAnchor(TextAnchor.CENTER_LEFT);
162 ta.setTextAnchor(TextAnchor.CENTER_LEFT);
163 plot.getRenderer().addAnnotation(ta);
164 XYLineAnnotation la = new XYLineAnnotation(posX, 0, posX, posY);
165 plot.getRenderer().addAnnotation(la);
166 freeFrom += 2.0;
167 }
137 } 168 }
138 169
139 170
140 /** 171 /**
141 * This method overrides the XYChartGenerators zoomY method to include the 0 172 * This method overrides the XYChartGenerators zoomY method to include the 0

http://dive4elements.wald.intevation.org