Mercurial > dive4elements > river
changeset 2775:5016609663e2
Draw line from w-annotation to duration curve, rough version.
flys-artifacts/trunk@4514 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 25 May 2012 09:13:43 +0000 (2012-05-25) |
parents | b2727413fae2 |
children | 69dd2aabbd0a |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesWFacet.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java |
diffstat | 4 files changed, 109 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri May 25 09:05:07 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri May 25 09:13:43 2012 +0000 @@ -1,3 +1,14 @@ +2012-05-25 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Draw line of w-mainvalue to duration curve, baby version. + + * src/main/java/de/intevation/flys/artifacts/model/MainValuesWFacet.java: + Calculate where mainvalue hits a duration curve. + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: + If StickyAxisAnnotation has a hit point set, add line annotation + to hit (the duration) curve. + 2012-05-25 Raimund Renkert <raimund.renkert@intevation.de> * doc/conf/themes.xml:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesWFacet.java Fri May 25 09:05:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesWFacet.java Fri May 25 09:13:43 2012 +0000 @@ -3,13 +3,18 @@ import java.util.ArrayList; import java.util.List; +import org.apache.log4j.Logger; + import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.DataProvider; import de.intevation.artifactdatabase.state.DefaultFacet; import de.intevation.flys.artifacts.MainValuesArtifact; +import de.intevation.flys.artifacts.math.Linear; import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.WQDay; import de.intevation.flys.jfree.FLYSAnnotation; import de.intevation.flys.jfree.StickyAxisAnnotation; @@ -21,6 +26,9 @@ extends DefaultFacet implements FacetTypes { + /** Own logger. */ + private static Logger logger = Logger.getLogger(RelativePointFacet.class); + /** Do we want MainValues at Gauge (not interpolated)? */ protected boolean isAtGauge; @@ -34,6 +42,40 @@ /** + * Set the hit-point in W where a line drawn from the axis would hit the + * curve in WQDay (if hit). + * Employ linear interpolation. + */ + protected static void setHitPoint(WQDay wqday, StickyAxisAnnotation annotation) { + int idx = 0; + float w = annotation.getPos(); + boolean wIncreases = wqday.getW(0) < wqday.getW(wqday.size()-1); + if (wIncreases) { + while (idx < wqday.size() && wqday.getW(idx) < w) { + idx++; + } + } + else { + idx = wqday.size() -1; + while (idx > 0 && wqday.getW(idx) > w) { + idx--; + } + } + + double day = 0d; + int mod = (wIncreases) ? -1 : +1; + if (idx != 0 && idx <= wqday.size()-1) { + day = Linear.linear(w, wqday.getW(idx +mod), wqday.getW(idx), + wqday.getDay(idx+mod), wqday.getDay(idx)); + annotation.setHitPoint((float)day); + } + else { + logger.debug("StickyAnnotation does not hit wqday curve"); + } + } + + + /** * Returns the data this facet requires. * * @param artifact the owner artifact. @@ -48,11 +90,30 @@ List<NamedDouble> ws = mvArtifact.getMainValuesW(isAtGauge); List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); + // BLACKBOARD/DURATIONCURVE / reference point ... + WQDay wqdays = null; + List<DataProvider> providers = context. + getDataProvider(DurationCurveFacet.BB_DURATIONCURVE); + if (providers.size() < 1) { + logger.warn("Could not find durationcurve data provider."); + } + else { + wqdays = (WQDay) providers.get(0).provideData( + DurationCurveFacet.BB_DURATIONCURVE, + null, + context); + } + for (NamedDouble w: ws) { - xy.add(new StickyAxisAnnotation( - w.getName(), - (float) w.getValue(), - StickyAxisAnnotation.SimpleAxis.Y_AXIS)); + StickyAxisAnnotation annotation = + new StickyAxisAnnotation( + w.getName(), + (float) w.getValue(), + StickyAxisAnnotation.SimpleAxis.Y_AXIS); + xy.add(annotation); + if (wqdays != null) { + setHitPoint(wqdays, annotation); + } } return new FLYSAnnotation(description, xy);
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Fri May 25 09:05:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Fri May 25 09:13:43 2012 +0000 @@ -713,7 +713,7 @@ /** * Add a text and a line annotation. - * @area convenience to determine positions in plot. + * @param area convenience to determine positions in plot. */ public void addStickyAnnotation( StickyAxisAnnotation annotation, @@ -813,6 +813,13 @@ // Add the Annotations to renderer. plot.getRenderer(rendererIndex).addAnnotation(textAnnotation, org.jfree.ui.Layer.FOREGROUND); + if (!Float.isNaN(annotation.getHitPoint())) { + // New line annotation to hit curve. + XYLineAnnotation hitLineAnnotation = new XYLineAnnotation(area.atLeft(), + annotation.getPos(), annotation.getHitPoint(), annotation.getPos()); + plot.getRenderer(rendererIndex).addAnnotation(hitLineAnnotation, + org.jfree.ui.Layer.BACKGROUND); + } plot.getRenderer(rendererIndex).addAnnotation(lineAnnotation, org.jfree.ui.Layer.FOREGROUND); } @@ -826,7 +833,7 @@ logger.debug("XYChartGenerator.addAnnotationsToRenderer"); if (annotations == null) { - logger.debug("XYChartGenerator.addBoxAnnotations: no annotations."); + logger.debug("XYChartGenerator.addAnnotationsToRenderer: no annotations."); return; }
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java Fri May 25 09:05:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java Fri May 25 09:13:43 2012 +0000 @@ -30,8 +30,17 @@ /** The 1-dimensional position of this annotation. */ protected float pos; + /** + * Optional field used when from axis a line should be drawn that + * hits a curve or something similar (current scenario: duration curves). + * This value is in the "other" dimension than the pos - field. + */ + protected float hitPoint; + + /** The text to display at axis. */ String text; + /** * Constructor with implicit sticky x-axis. * @param text the text to display. @@ -55,6 +64,7 @@ this(text, pos, stickAxis, 0); } + public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis, int axisSymbol ) { @@ -62,6 +72,7 @@ this.text = text; this.pos = pos; this.axisSymbol = axisSymbol; + this.hitPoint = Float.NaN; } @@ -88,14 +99,27 @@ return this.getStickyAxis() == SimpleAxis.X_AXIS; } + /** Get text to be displayed at axis. */ public String getText() { return this.text; } + public int getAxisSymbol() { return this.axisSymbol; } + + /** Set where to hit a curve (if any). */ + public void setHitPoint(float pos) { + this.hitPoint = pos; + } + + /** Get where to hit a curve (if any). */ + public float getHitPoint() { + return this.hitPoint; + } + /** Set sticky axis to the X axis if it is currently Y, and vice versa. */ public void flipStickyAxis() { if (this.getStickyAxis() == SimpleAxis.X_AXIS) {