# HG changeset patch # User Felix Wolfsteller # Date 1314357324 0 # Node ID e298c4d289277a169daa3cdda95157d54fa71595 # Parent 1f5b92531f726fbb264cc0177495c1a956c97263 Improved mainvalues rendering. flys-artifacts/trunk@2592 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 1f5b92531f72 -r e298c4d28927 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Aug 26 11:11:46 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Aug 26 11:15:24 2011 +0000 @@ -1,3 +1,15 @@ +2011-08-26 Felix Wolfsteller + + * src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java: + Use NamedDoubles instead of MainValues, try to adjust scale of Ws. + + * src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java: + Use NamedDoubles instead of MainValues, generalize annotation handling, to + allow easier reusability and themeing. + + * src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java: + Added convenience constructor, exemplary switch on bordered text. + 2011-08-26 Felix Wolfsteller * doc/conf/meta-data.xml: diff -r 1f5b92531f72 -r e298c4d28927 flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java Fri Aug 26 11:11:46 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java Fri Aug 26 11:15:24 2011 +0000 @@ -17,8 +17,9 @@ import de.intevation.artifacts.CallMeta; import de.intevation.flys.artifacts.model.RiverFactory; +import de.intevation.flys.artifacts.model.MainValuesQFacet; import de.intevation.flys.artifacts.model.MainValuesWFacet; -import de.intevation.flys.artifacts.model.MainValuesQFacet; +import de.intevation.flys.artifacts.model.NamedDouble; import de.intevation.artifactdatabase.data.DefaultStateData; import de.intevation.flys.artifacts.states.StaticState; @@ -166,6 +167,11 @@ : null; } + /** + * Access the Gauge that the mainvalues are taken from. + * @return Gauge that main values are taken from or null in case of + * invalid parameterization. + */ protected Gauge getGauge() { River river = getRiver(); @@ -179,28 +185,57 @@ return river.determineGaugeByPosition(location); } - public List getMainValuesQ() { - List filteredList = new ArrayList(); + + /** + * Get datum of Gauge. + * @return datum of gauge. + */ + public double getGaugeDatum() { + Gauge gauge = getGauge(); + if (gauge == null) { return 0.0f; } + return gauge.getDatum().doubleValue(); + } + + + /** + * Get a list of "Q" main values. + * @return list of Q main values. + */ + public List getMainValuesQ() { + List filteredList = new ArrayList(); Gauge gauge = getGauge(); if (gauge != null) { List orig = gauge.getMainValues(); for (MainValue mv : orig) { if (mv.getMainValue().getType().getName().equals("Q")) { - filteredList.add(mv); + filteredList.add(new NamedDouble( + mv.getMainValue().getName(), + mv.getValue().doubleValue() + )); } } } return filteredList; } - public List getMainValuesW() { - List filteredList = new ArrayList(); + + /** + * Get a list of "W" main values. + * @return list of W main values. + */ + public List getMainValuesW() { + List filteredList = new ArrayList(); Gauge gauge = getGauge(); + double datum = gauge.getDatum().doubleValue(); + logger.debug("DATUM:: " + datum); if (gauge != null) { List orig = gauge.getMainValues(); for (MainValue mv : orig) { if (mv.getMainValue().getType().getName().equals("W")) { - filteredList.add(mv); + filteredList.add(new NamedDouble( + mv.getMainValue().getName(), + mv.getValue().doubleValue()/100.f + datum + )); } } } diff -r 1f5b92531f72 -r e298c4d28927 flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Fri Aug 26 11:11:46 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Fri Aug 26 11:15:24 2011 +0000 @@ -11,18 +11,19 @@ import org.jfree.data.xy.XYSeries; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.annotations.XYAnnotation; import de.intevation.artifacts.Artifact; import de.intevation.artifactdatabase.state.Facet; import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.model.NamedDouble; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.WQKms; import de.intevation.flys.jfree.StickyAxisAnnotation; -import de.intevation.flys.model.MainValue; /** * An OutGenerator that generates discharge curves. @@ -50,11 +51,8 @@ public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve"; public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; - /** List of W MainValues (Annotations in plot). */ - protected static List mainValuesW; - - /** List of Q MainValues (Annotations in plot). */ - protected static List mainValuesQ; + /** List of Annotations (specifically, Main Values). */ + protected List annotations; // TODO Add pseudodataseries for having mainvalue-text in legend. // TODO Let theme pass through to annotations-facets. @@ -63,8 +61,7 @@ /** Trivial Constructor. */ public ComputedDischargeCurveGenerator () { super(); - mainValuesQ = new ArrayList(); - mainValuesW = new ArrayList(); + annotations= new ArrayList(); } @@ -112,10 +109,10 @@ doQOut((WQKms) f.getData(artifact, context), attr); } else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)) { - doMainValueWAnnotations(f.getData(artifact, context), attr); + doMainValueQAnnotations(f.getData(artifact, context), attr); } else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)) { - doMainValueQAnnotations(f.getData(artifact, context), attr); + doMainValueWAnnotations(f.getData(artifact, context), attr); } else { logger.warn("Unknown facet type for computed discharge: " + name); @@ -129,7 +126,15 @@ */ protected void doMainValueWAnnotations(Object o, Document theme) { logger.debug("ComputedDischargeCurveGenerator set W MainValues."); - this.mainValuesW = (List) o; + List mainValuesW = (List) o; + for (NamedDouble mv: mainValuesW) { + float pos = (float) mv.getValue(); + String text = mv.getName(); + StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos, + StickyAxisAnnotation.SimpleAxis.Y_AXIS); + logger.debug("Adding W: " + text + " : " + pos); + this.annotations.add(ta); + } } @@ -138,7 +143,13 @@ */ protected void doMainValueQAnnotations(Object o, Document theme) { logger.debug("ComputedDischargeCurveGenerator set Q MainValues."); - this.mainValuesQ = (List) o; + List mainValuesQ = (List) o; + for (NamedDouble mv: mainValuesQ) { + float pos = (float) mv.getValue(); + String text = mv.getName(); + StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos); + this.annotations.add(ta); + } } @@ -147,7 +158,7 @@ public JFreeChart generateChart() { JFreeChart c = super.generateChart(); XYPlot p = (XYPlot) c.getPlot(); - redoAnnotations(p, p.getDomainAxis()); + redoAnnotations(p); return c; } @@ -156,24 +167,12 @@ * Recalculate some annotation positions and add them to plot. * Annotations represent MainValues. * @param plot Plot to add annotations to. - * @param valueAxis ignored. */ - protected void redoAnnotations(XYPlot plot, ValueAxis axis) { + protected void redoAnnotations(XYPlot plot) { plot.clearAnnotations(); - // Add all MainValues as annotations. - for (MainValue mv: mainValuesQ) { - float pos = mv.getValue().floatValue(); - String text = mv.getMainValue().getName(); - StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos, - StickyAxisAnnotation.SimpleAxis.X_AXIS); - plot.getRenderer().addAnnotation(ta); - } - for (MainValue mv: mainValuesW) { - float pos = mv.getValue().floatValue(); - String text = mv.getMainValue().getName(); - StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos, - StickyAxisAnnotation.SimpleAxis.Y_AXIS); - plot.getRenderer().addAnnotation(ta); + + for (XYAnnotation a: annotations) { + plot.addAnnotation(a, false); } } diff -r 1f5b92531f72 -r e298c4d28927 flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java --- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java Fri Aug 26 11:11:46 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java Fri Aug 26 11:15:24 2011 +0000 @@ -65,6 +65,16 @@ /** + * Constructor with implicit sticky x-axis. + * @param text the text to display. + * @param pos the position at which to draw the text and mark. + */ + public StickyAxisAnnotation(String text, float pos) { + this(text, pos, pos, SimpleAxis.X_AXIS); + } + + + /** * Constructor with given explicit axis. * @param text the text to display. * @param pos the position at which to draw the text and mark. @@ -290,7 +300,7 @@ TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); // Draw outline. - if (false) { + if (true) { g2.setStroke(getOutlineStroke()); g2.setPaint(getOutlinePaint()); g2.draw(hotspot);