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