comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesWFacet.java @ 2793:6310b1582f2d

merged flys-artifacts/2.7
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:30 +0200
parents 772d0c8100d3
children 0f7abd95c6e2
comparison
equal deleted inserted replaced
2548:ada02bbd3b7f 2793:6310b1582f2d
1 package de.intevation.flys.artifacts.model;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.apache.log4j.Logger;
7
8 import de.intevation.artifacts.Artifact;
9 import de.intevation.artifacts.CallContext;
10 import de.intevation.artifacts.DataProvider;
11
12 import de.intevation.artifactdatabase.state.DefaultFacet;
13
14 import de.intevation.flys.artifacts.MainValuesArtifact;
15 import de.intevation.flys.artifacts.math.Linear;
16 import de.intevation.flys.artifacts.model.FacetTypes;
17 import de.intevation.flys.artifacts.model.WQDay;
18 import de.intevation.flys.jfree.FLYSAnnotation;
19 import de.intevation.flys.jfree.StickyAxisAnnotation;
20
21
22 /**
23 * Facet to show Main W Values.
24 */
25 public class MainValuesWFacet
26 extends DefaultFacet
27 implements FacetTypes {
28
29 /** Own logger. */
30 private static Logger logger = Logger.getLogger(RelativePointFacet.class);
31
32 /** Do we want MainValues at Gauge (not interpolated)? */
33 protected boolean isAtGauge;
34
35 /** Trivial Constructor. */
36 public MainValuesWFacet(String name, String description, boolean atGauge) {
37 this.description = description;
38 this.name = name;
39 this.index = 0;
40 this.isAtGauge = atGauge;
41 }
42
43
44 /**
45 * Set the hit-point in W where a line drawn from the axis would hit the
46 * curve in WQDay (if hit).
47 * Employ linear interpolation.
48 */
49 protected static void setHitPoint(WQDay wqday, StickyAxisAnnotation annotation) {
50 int idx = 0;
51 float w = annotation.getPos();
52 boolean wIncreases = wqday.getW(0) < wqday.getW(wqday.size()-1);
53 if (wIncreases) {
54 while (idx < wqday.size() && wqday.getW(idx) < w) {
55 idx++;
56 }
57 }
58 else {
59 idx = wqday.size() -1;
60 while (idx > 0 && wqday.getW(idx) > w) {
61 idx--;
62 }
63 }
64
65 double day = 0d;
66 int mod = (wIncreases) ? -1 : +1;
67 if (idx != 0 && idx < wqday.size()-1-mod) {
68 day = Linear.linear(w, wqday.getW(idx +mod), wqday.getW(idx),
69 wqday.getDay(idx+mod), wqday.getDay(idx));
70 annotation.setHitPoint((float)day);
71 }
72 else {
73 logger.debug("StickyAnnotation does not hit wqday curve");
74 }
75 }
76
77
78 /**
79 * Returns the data this facet requires.
80 *
81 * @param artifact the owner artifact.
82 * @param context the CallContext (ignored).
83 *
84 * @return the data.
85 */
86 @Override
87 public Object getData(Artifact artifact, CallContext context) {
88 MainValuesArtifact mvArtifact = (MainValuesArtifact) artifact;
89
90 List<NamedDouble> ws = mvArtifact.getMainValuesW(isAtGauge);
91 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>();
92
93 // Find whether a duration curve is on the blackboard.
94 WQDay wqdays = null;
95 List<DataProvider> providers = context.
96 getDataProvider(DurationCurveFacet.BB_DURATIONCURVE);
97 if (providers.size() < 1) {
98 logger.warn("Could not find durationcurve data provider.");
99 }
100 else {
101 wqdays = (WQDay) providers.get(0).provideData(
102 DurationCurveFacet.BB_DURATIONCURVE,
103 null,
104 context);
105 }
106
107 for (NamedDouble w: ws) {
108 StickyAxisAnnotation annotation =
109 new StickyAxisAnnotation(
110 w.getName(),
111 (float) w.getValue(),
112 StickyAxisAnnotation.SimpleAxis.Y_AXIS);
113 xy.add(annotation);
114 if (wqdays != null) {
115 setHitPoint(wqdays, annotation);
116 }
117 }
118
119 return new FLYSAnnotation(description, xy);
120 }
121
122
123 /**
124 * Create a deep copy of this Facet.
125 * @return a deep copy.
126 */
127 @Override
128 public MainValuesWFacet deepCopy() {
129 MainValuesWFacet copy = new MainValuesWFacet(this.name,
130 description, this.isAtGauge);
131 copy.set(this);
132 return copy;
133 }
134 }
135 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org