Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesWFacet.java @ 2775:5016609663e2
Draw line from w-annotation to duration curve, rough version.
flys-artifacts/trunk@4514 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 25 May 2012 09:13:43 +0000 |
parents | c68f4f227c09 |
children | 772d0c8100d3 |
comparison
equal
deleted
inserted
replaced
2774:b2727413fae2 | 2775:5016609663e2 |
---|---|
1 package de.intevation.flys.artifacts.model; | 1 package de.intevation.flys.artifacts.model; |
2 | 2 |
3 import java.util.ArrayList; | 3 import java.util.ArrayList; |
4 import java.util.List; | 4 import java.util.List; |
5 | 5 |
6 import org.apache.log4j.Logger; | |
7 | |
6 import de.intevation.artifacts.Artifact; | 8 import de.intevation.artifacts.Artifact; |
7 import de.intevation.artifacts.CallContext; | 9 import de.intevation.artifacts.CallContext; |
10 import de.intevation.artifacts.DataProvider; | |
8 | 11 |
9 import de.intevation.artifactdatabase.state.DefaultFacet; | 12 import de.intevation.artifactdatabase.state.DefaultFacet; |
10 | 13 |
11 import de.intevation.flys.artifacts.MainValuesArtifact; | 14 import de.intevation.flys.artifacts.MainValuesArtifact; |
15 import de.intevation.flys.artifacts.math.Linear; | |
12 import de.intevation.flys.artifacts.model.FacetTypes; | 16 import de.intevation.flys.artifacts.model.FacetTypes; |
17 import de.intevation.flys.artifacts.model.WQDay; | |
13 import de.intevation.flys.jfree.FLYSAnnotation; | 18 import de.intevation.flys.jfree.FLYSAnnotation; |
14 import de.intevation.flys.jfree.StickyAxisAnnotation; | 19 import de.intevation.flys.jfree.StickyAxisAnnotation; |
15 | 20 |
16 | 21 |
17 /** | 22 /** |
19 */ | 24 */ |
20 public class MainValuesWFacet | 25 public class MainValuesWFacet |
21 extends DefaultFacet | 26 extends DefaultFacet |
22 implements FacetTypes { | 27 implements FacetTypes { |
23 | 28 |
29 /** Own logger. */ | |
30 private static Logger logger = Logger.getLogger(RelativePointFacet.class); | |
31 | |
24 /** Do we want MainValues at Gauge (not interpolated)? */ | 32 /** Do we want MainValues at Gauge (not interpolated)? */ |
25 protected boolean isAtGauge; | 33 protected boolean isAtGauge; |
26 | 34 |
27 /** Trivial Constructor. */ | 35 /** Trivial Constructor. */ |
28 public MainValuesWFacet(String name, String description, boolean atGauge) { | 36 public MainValuesWFacet(String name, String description, boolean atGauge) { |
29 this.description = description; | 37 this.description = description; |
30 this.name = name; | 38 this.name = name; |
31 this.index = 0; | 39 this.index = 0; |
32 this.isAtGauge = atGauge; | 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) { | |
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 } | |
33 } | 75 } |
34 | 76 |
35 | 77 |
36 /** | 78 /** |
37 * Returns the data this facet requires. | 79 * Returns the data this facet requires. |
46 MainValuesArtifact mvArtifact = (MainValuesArtifact) artifact; | 88 MainValuesArtifact mvArtifact = (MainValuesArtifact) artifact; |
47 | 89 |
48 List<NamedDouble> ws = mvArtifact.getMainValuesW(isAtGauge); | 90 List<NamedDouble> ws = mvArtifact.getMainValuesW(isAtGauge); |
49 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); | 91 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); |
50 | 92 |
93 // BLACKBOARD/DURATIONCURVE / reference point ... | |
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 | |
51 for (NamedDouble w: ws) { | 107 for (NamedDouble w: ws) { |
52 xy.add(new StickyAxisAnnotation( | 108 StickyAxisAnnotation annotation = |
53 w.getName(), | 109 new StickyAxisAnnotation( |
54 (float) w.getValue(), | 110 w.getName(), |
55 StickyAxisAnnotation.SimpleAxis.Y_AXIS)); | 111 (float) w.getValue(), |
112 StickyAxisAnnotation.SimpleAxis.Y_AXIS); | |
113 xy.add(annotation); | |
114 if (wqdays != null) { | |
115 setHitPoint(wqdays, annotation); | |
116 } | |
56 } | 117 } |
57 | 118 |
58 return new FLYSAnnotation(description, xy); | 119 return new FLYSAnnotation(description, xy); |
59 } | 120 } |
60 | 121 |