# HG changeset patch # User Felix Wolfsteller # Date 1313495027 0 # Node ID bf3b3a8d089bc90750b97c345b648f0b41e8caee # Parent 821aaceb2776d239ba722fd83e5915be0d6fb908 Slightly improved rendering of annotations in LongitudinalSection-plots. flys-artifacts/trunk@2495 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 821aaceb2776 -r bf3b3a8d089b flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon Aug 15 10:56:58 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Aug 16 11:43:47 2011 +0000 @@ -1,3 +1,11 @@ +2011-08-16 Felix Wolfsteller + + Slightly improved rendering of annotations. + + * src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java: + Slightly improved rendering of annotations. Still no valid collision + detection. Annotations are drawn every 2 km; first come first serve. + 2011-08-15 Sascha L. Teichmann Fix for flys/issue191 diff -r 821aaceb2776 -r bf3b3a8d089b flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Mon Aug 15 10:56:58 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Tue Aug 16 11:43:47 2011 +0000 @@ -14,6 +14,7 @@ import org.jfree.chart.title.TextTitle; import org.jfree.data.Range; import org.jfree.data.xy.XYSeries; +import org.jfree.ui.TextAnchor; import org.w3c.dom.Document; @@ -103,14 +104,8 @@ JFreeChart c = super.generateChart(); XYPlot p = (XYPlot) c.getPlot(); - for (Annotation a: annotations) { - double pos = a.getRange().getA().doubleValue(); - XYTextAnnotation ta = new XYTextAnnotation(a.getPosition().getValue(), pos, 140); - ta.setRotationAngle(270.0 / (Math.PI * 2.0)); - p.addAnnotation(ta); - XYLineAnnotation la = new XYLineAnnotation(pos, 0, pos, 140); - p.addAnnotation(la); - } + redoAnnotations(p, p.getDomainAxis()); + return c; } @@ -138,6 +133,42 @@ /** + * Remove all annotations from plot and re-insert them at an approximately + * okay position. The followed approach is naive but side-effect free. + */ + protected void redoAnnotations(XYPlot plot, ValueAxis axis) { + plot.clearAnnotations(); + ValueAxis yAxis = plot.getRangeAxis(); + float posY = 140.f; + if (yAxis != null) { + posY = (float) yAxis.getRange().getLowerBound(); + // Lets add some (1%) space between Text and Axis . + posY += 0.1f * (yAxis.getRange().getUpperBound() + - yAxis.getRange().getLowerBound()); + } + double freeFrom = axis.getRange().getLowerBound(); + //logger.warn("Axis lower Bound: " + freeFrom); + + // Assuming ordered annotations. + for (Annotation a: annotations) { + float posX = (float) a.getRange().getA().doubleValue(); + if (posX < freeFrom) { continue; } + String text = a.getPosition().getValue(); + + XYTextAnnotation ta = new XYTextAnnotation(text, posX, posY); + double rotation = 270.0f * (Math.PI / 180.0f); + ta.setRotationAngle(rotation); + ta.setRotationAnchor(TextAnchor.CENTER_LEFT); + ta.setTextAnchor(TextAnchor.CENTER_LEFT); + plot.getRenderer().addAnnotation(ta); + XYLineAnnotation la = new XYLineAnnotation(posX, 0, posX, posY); + plot.getRenderer().addAnnotation(la); + freeFrom += 2.0; + } + } + + + /** * This method overrides the XYChartGenerators zoomY method to include the 0 * value on the Q axis. */