Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/model/MainValuesQFacet.java @ 8331:27d42c9ee367
Main values: Reduce code duplication and correct logic to specify whether we are at gauge or not.
author | "Tom Gottfried <tom@intevation.de>" |
---|---|
date | Fri, 26 Sep 2014 09:44:48 +0200 |
parents | e4606eae8ea5 |
children | 5e38e2924c07 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/MainValuesQFacet.java Fri Sep 26 08:40:20 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/MainValuesQFacet.java Fri Sep 26 09:44:48 2014 +0200 @@ -22,10 +22,13 @@ import org.dive4elements.river.artifacts.MainValuesArtifact; import org.dive4elements.river.jfree.RiverAnnotation; import org.dive4elements.river.jfree.StickyAxisAnnotation; +import org.dive4elements.river.jfree.StickyAxisAnnotation.SimpleAxis; import org.dive4elements.river.exports.DurationCurveGenerator; import org.dive4elements.river.exports.fixings.FixChartGenerator; +import static org.dive4elements.river.exports.injector.InjectorConstants.PNP; + /** * Facet to show Main Q Values. @@ -38,16 +41,11 @@ /** Own log. */ private static Logger log = Logger.getLogger(MainValuesQFacet.class); - /** Do we want MainValues at Gauge (not interpolated)? */ - protected boolean isAtGauge; - - /** Trivial Constructor. */ - public MainValuesQFacet(String name, String description, boolean atGauge) { + public MainValuesQFacet(String name, String description) { this.description = description; this.name = name; this.index = 0; - this.isAtGauge = atGauge; } /** @@ -82,23 +80,24 @@ public Object getData(Artifact artifact, CallContext context) { MainValuesArtifact mvArtifact = (MainValuesArtifact) artifact; - List<NamedDouble> qs = mvArtifact.getMainValuesQ(isAtGauge); + List<NamedDouble> qs = mvArtifact.getMainValuesQ( + context.getContextValue(PNP)); List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); + // Find whether a duration curve is on the blackboard. WQDay wqdays = null; List<DataProvider> providers = context. getDataProvider(DurationCurveFacet.BB_DURATIONCURVE); if (providers.size() < 1) { - log.warn("Could not find durationcurve data provider."); // Do we have a current km in context? // If so, we are likely fetching data for a navigable // diagram (i.e. in fixation branch). Object xkm = context.getContextValue(FixChartGenerator.CURRENT_KM); if (xkm != null) { Double ckm = (Double)xkm; - // Return linearly interpolated values, in m if not at gauge, - // in cm if at gauge. - qs = mvArtifact.getMainValuesQ(new double[] {ckm}); + qs = mvArtifact.getMainValuesQ( + new double[] {ckm}, + context.getContextValue(PNP)); } } else { @@ -110,39 +109,31 @@ // Rather specific case, Q-Annotations at a maybe second yaxis. StickyAxisAnnotation annotation = null; - if (this.name.equals(DURATION_MAINVALUES_Q)) { - for (NamedDouble q: qs) { - if (Double.isNaN(q.getValue())) { - log.warn("NaN MainValue " + q.getName()); - continue; - } - annotation = - new StickyAxisAnnotation( - q.getName(), - (float) q.getValue(), - StickyAxisAnnotation.SimpleAxis.Y_AXIS, - DurationCurveGenerator.YAXIS.Q.idx); - xy.add(annotation); - if (wqdays != null) { - setHitPoint(wqdays, annotation); - } + + // defaults if not drawing a duration curve + SimpleAxis axis = SimpleAxis.X_AXIS; + int axisSymbol = 0; + + if (providers.size() >= 1) { + // for duration curve, overwrite previously given default + axis = SimpleAxis.Y_AXIS; + axisSymbol = DurationCurveGenerator.YAXIS.Q.idx; + } + + for (NamedDouble q: qs) { + if (Double.isNaN(q.getValue())) { + log.warn("NaN MainValue " + q.getName()); + continue; } - } - else { - for (NamedDouble q: qs) { - if (Double.isNaN(q.getValue())) { - log.warn("NaN MainValue " + q.getName()); - continue; - } - annotation = - new StickyAxisAnnotation( - q.getName(), - (float) q.getValue(), - StickyAxisAnnotation.SimpleAxis.X_AXIS); - xy.add(annotation); - if (wqdays != null) { - setHitPoint(wqdays, annotation); - } + annotation = + new StickyAxisAnnotation( + q.getName(), + (float) q.getValue(), + axis, + axisSymbol); + xy.add(annotation); + if (wqdays != null) { + setHitPoint(wqdays, annotation); } } @@ -157,7 +148,7 @@ @Override public MainValuesQFacet deepCopy() { MainValuesQFacet copy = new MainValuesQFacet(this.name, - description, this.isAtGauge); + description); copy.set(this); return copy; }