Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesQFacet.java @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | cd5eb8f5f6f1 |
children | 35a6c9a49a76 |
comparison
equal
deleted
inserted
replaced
3387:5ffad8bde8ad | 3468:f37e7e8907cb |
---|---|
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 | |
37 /** Trivial Constructor. */ | |
38 public MainValuesQFacet(String name, String description, boolean atGauge) { | |
39 this.description = description; | |
40 this.name = name; | |
41 this.index = 0; | |
42 this.isAtGauge = atGauge; | |
43 } | |
44 | |
45 | |
46 /** | |
47 * Set the hit-point in Q where a line drawn from the axis would hit the | |
48 * curve in WQDay (if hit). | |
49 * Employ linear interpolation. | |
50 */ | |
51 protected static void setHitPoint(WQDay wqday, StickyAxisAnnotation annotation) { | |
52 int idx = 0; | |
53 float q = annotation.getPos(); | |
54 boolean qIncreases = wqday.getQ(0) < wqday.getQ(wqday.size()-1); | |
55 if (qIncreases) { | |
56 while (idx < wqday.size() && wqday.getQ(idx) < q) { | |
57 idx++; | |
58 } | |
59 } | |
60 else { | |
61 idx = wqday.size() -1; | |
62 while (idx > 0 && wqday.getQ(idx) > q) { | |
63 idx--; | |
64 } | |
65 } | |
66 | |
67 double day = 0d; | |
68 int mod = (qIncreases) ? -1 : +1; | |
69 if (idx != 0 && idx <= wqday.size()-1) { | |
70 day = Linear.linear(q, wqday.getQ(idx +mod), wqday.getQ(idx), | |
71 wqday.getDay(idx+mod), wqday.getDay(idx)); | |
72 annotation.setHitPoint((float)day); | |
73 } | |
74 else { | |
75 logger.debug("StickyAnnotation does not hit wqday curve"); | |
76 } | |
77 } | |
78 | |
79 | |
80 /** | |
81 * Returns the data this facet requires. | |
82 * | |
83 * @param artifact the owner artifact. | |
84 * @param context the CallContext (ignored). | |
85 * | |
86 * @return the data. | |
87 */ | |
88 @Override | |
89 public Object getData(Artifact artifact, CallContext context) { | |
90 MainValuesArtifact mvArtifact = (MainValuesArtifact) artifact; | |
91 | |
92 List<NamedDouble> qs = mvArtifact.getMainValuesQ(isAtGauge); | |
93 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); | |
94 | |
95 WQDay wqdays = null; | |
96 List<DataProvider> providers = context. | |
97 getDataProvider(DurationCurveFacet.BB_DURATIONCURVE); | |
98 if (providers.size() < 1) { | |
99 logger.warn("Could not find durationcurve data provider."); | |
100 } | |
101 else { | |
102 wqdays = (WQDay) providers.get(0).provideData( | |
103 DurationCurveFacet.BB_DURATIONCURVE, | |
104 null, | |
105 context); | |
106 } | |
107 | |
108 // Rather specific case, Q-Annotations at a maybe second yaxis. | |
109 StickyAxisAnnotation annotation = null; | |
110 if (this.name.equals(DURATION_MAINVALUES_Q)) { | |
111 for (NamedDouble q: qs) { | |
112 annotation = | |
113 new StickyAxisAnnotation( | |
114 q.getName(), | |
115 (float) q.getValue(), | |
116 StickyAxisAnnotation.SimpleAxis.Y_AXIS, | |
117 DurationCurveGenerator.YAXIS.Q.idx); | |
118 xy.add(annotation); | |
119 if (wqdays != null) { | |
120 setHitPoint(wqdays, annotation); | |
121 } | |
122 } | |
123 } | |
124 else { | |
125 for (NamedDouble q: qs) { | |
126 annotation = | |
127 new StickyAxisAnnotation( | |
128 q.getName(), | |
129 (float) q.getValue(), | |
130 StickyAxisAnnotation.SimpleAxis.X_AXIS); | |
131 xy.add(annotation); | |
132 if (wqdays != null) { | |
133 setHitPoint(wqdays, annotation); | |
134 } | |
135 } | |
136 } | |
137 | |
138 return new FLYSAnnotation(description, xy); | |
139 } | |
140 | |
141 | |
142 /** | |
143 * Create a deep copy of this Facet. | |
144 * @return a deep copy. | |
145 */ | |
146 @Override | |
147 public MainValuesQFacet deepCopy() { | |
148 MainValuesQFacet copy = new MainValuesQFacet(this.name, | |
149 description, this.isAtGauge); | |
150 copy.set(this); | |
151 return copy; | |
152 } | |
153 } | |
154 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |