Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesQFacet.java @ 3318:dbe2f85bf160
merged flys-artifacts/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:35 +0200 |
parents | 0f7abd95c6e2 |
children | cd5eb8f5f6f1 |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
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.jfree.FLYSAnnotation; | |
17 import de.intevation.flys.jfree.StickyAxisAnnotation; | |
18 | |
19 import de.intevation.flys.exports.DurationCurveGenerator; | |
20 | |
21 | |
22 /** | |
23 * Facet to show Main Q Values. | |
24 * TODO Join with W implementation. | |
25 */ | |
26 public class MainValuesQFacet | |
27 extends DefaultFacet | |
28 implements FacetTypes { | |
29 | |
30 /** Own logger. */ | |
31 private static Logger logger = Logger.getLogger(RelativePointFacet.class); | |
32 | |
33 /** Do we want MainValues at Gauge (not interpolated)? */ | |
34 protected boolean isAtGauge; | |
35 | |
36 /** Trivial Constructor. */ | |
37 public MainValuesQFacet(String name, String description, boolean atGauge) { | |
38 this.description = description; | |
39 this.name = name; | |
40 this.index = 0; | |
41 this.isAtGauge = atGauge; | |
42 } | |
43 | |
44 /** | |
45 * Set the hit-point in Q 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 q = annotation.getPos(); | |
52 boolean qIncreases = wqday.getQ(0) < wqday.getQ(wqday.size()-1); | |
53 if (qIncreases) { | |
54 while (idx < wqday.size() && wqday.getQ(idx) < q) { | |
55 idx++; | |
56 } | |
57 } | |
58 else { | |
59 idx = wqday.size() -1; | |
60 while (idx > 0 && wqday.getQ(idx) > q) { | |
61 idx--; | |
62 } | |
63 } | |
64 | |
65 double day = 0d; | |
66 int mod = (qIncreases) ? -1 : +1; | |
67 if (idx != 0 && idx <= wqday.size()-1) { | |
68 day = Linear.linear(q, wqday.getQ(idx +mod), wqday.getQ(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> qs = mvArtifact.getMainValuesQ(isAtGauge); | |
91 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); | |
92 | |
93 WQDay wqdays = null; | |
94 List<DataProvider> providers = context. | |
95 getDataProvider(DurationCurveFacet.BB_DURATIONCURVE); | |
96 if (providers.size() < 1) { | |
97 logger.warn("Could not find durationcurve data provider."); | |
98 } | |
99 else { | |
100 wqdays = (WQDay) providers.get(0).provideData( | |
101 DurationCurveFacet.BB_DURATIONCURVE, | |
102 null, | |
103 context); | |
104 } | |
105 | |
106 // Rather specific case, Q-Annotations at a maybe second yaxis. | |
107 StickyAxisAnnotation annotation = null; | |
108 if (this.name.equals(DURATION_MAINVALUES_Q)) { | |
109 for (NamedDouble q: qs) { | |
110 annotation = | |
111 new StickyAxisAnnotation( | |
112 q.getName(), | |
113 (float) q.getValue(), | |
114 StickyAxisAnnotation.SimpleAxis.Y_AXIS, | |
115 DurationCurveGenerator.YAXIS.Q.idx); | |
116 xy.add(annotation); | |
117 if (wqdays != null) { | |
118 setHitPoint(wqdays, annotation); | |
119 } | |
120 } | |
121 } | |
122 else { | |
123 for (NamedDouble q: qs) { | |
124 annotation = | |
125 new StickyAxisAnnotation( | |
126 q.getName(), | |
127 (float) q.getValue(), | |
128 StickyAxisAnnotation.SimpleAxis.X_AXIS); | |
129 xy.add(annotation); | |
130 if (wqdays != null) { | |
131 setHitPoint(wqdays, annotation); | |
132 } | |
133 } | |
134 } | |
135 | |
136 return new FLYSAnnotation(description, xy); | |
137 } | |
138 | |
139 | |
140 /** | |
141 * Create a deep copy of this Facet. | |
142 * @return a deep copy. | |
143 */ | |
144 @Override | |
145 public MainValuesQFacet deepCopy() { | |
146 MainValuesQFacet copy = new MainValuesQFacet(this.name, | |
147 description, this.isAtGauge); | |
148 copy.set(this); | |
149 return copy; | |
150 } | |
151 } | |
152 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |