Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java @ 6467:0f997d6397c6
FixWQCurveGenerator: Introduce second (cm) axis.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 27 Jun 2013 10:44:31 +0200 |
parents | b9c5bb510b39 |
children | 4bbad31c8616 |
comparison
equal
deleted
inserted
replaced
6466:cf514239d290 | 6467:0f997d6397c6 |
---|---|
8 | 8 |
9 package org.dive4elements.river.exports.fixings; | 9 package org.dive4elements.river.exports.fixings; |
10 | 10 |
11 import java.awt.BasicStroke; | 11 import java.awt.BasicStroke; |
12 import java.awt.Color; | 12 import java.awt.Color; |
13 import java.awt.Font; | |
13 import java.text.DateFormat; | 14 import java.text.DateFormat; |
14 import java.util.ArrayList; | 15 import java.util.ArrayList; |
15 import java.util.List; | 16 import java.util.List; |
16 | 17 |
17 import org.apache.log4j.Logger; | 18 import org.apache.log4j.Logger; |
18 import org.jfree.chart.JFreeChart; | 19 import org.jfree.chart.JFreeChart; |
19 import org.jfree.chart.annotations.XYTextAnnotation; | 20 import org.jfree.chart.annotations.XYTextAnnotation; |
21 import org.jfree.chart.axis.NumberAxis; | |
20 import org.jfree.chart.plot.Marker; | 22 import org.jfree.chart.plot.Marker; |
21 import org.jfree.chart.plot.ValueMarker; | 23 import org.jfree.chart.plot.ValueMarker; |
22 import org.jfree.chart.title.TextTitle; | 24 import org.jfree.chart.title.TextTitle; |
23 import org.jfree.data.xy.XYSeries; | 25 import org.jfree.data.xy.XYSeries; |
24 import org.jfree.ui.RectangleAnchor; | 26 import org.jfree.ui.RectangleAnchor; |
42 import org.dive4elements.river.artifacts.model.fixings.FixWQCurveFacet; | 44 import org.dive4elements.river.artifacts.model.fixings.FixWQCurveFacet; |
43 import org.dive4elements.river.artifacts.model.fixings.QWD; | 45 import org.dive4elements.river.artifacts.model.fixings.QWD; |
44 import org.dive4elements.river.artifacts.model.fixings.QWI; | 46 import org.dive4elements.river.artifacts.model.fixings.QWI; |
45 import org.dive4elements.river.artifacts.resources.Resources; | 47 import org.dive4elements.river.artifacts.resources.Resources; |
46 import org.dive4elements.river.exports.ChartGenerator; | 48 import org.dive4elements.river.exports.ChartGenerator; |
49 import org.dive4elements.river.exports.DischargeCurveGenerator; | |
50 import org.dive4elements.river.exports.SyncNumberAxis; | |
47 import org.dive4elements.river.exports.StyledSeriesBuilder; | 51 import org.dive4elements.river.exports.StyledSeriesBuilder; |
48 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation; | 52 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation; |
49 import org.dive4elements.river.jfree.RiverAnnotation; | 53 import org.dive4elements.river.jfree.RiverAnnotation; |
50 import org.dive4elements.river.jfree.JFreeUtil; | 54 import org.dive4elements.river.jfree.JFreeUtil; |
51 import org.dive4elements.river.jfree.StickyAxisAnnotation; | 55 import org.dive4elements.river.jfree.StickyAxisAnnotation; |
92 "W [NN + m]"; | 96 "W [NN + m]"; |
93 | 97 |
94 public static final double EPSILON = 0.001d; | 98 public static final double EPSILON = 0.001d; |
95 | 99 |
96 public static enum YAXIS { | 100 public static enum YAXIS { |
97 W(0); | 101 WCm(0), |
102 W(1); | |
98 public int idx; | 103 public int idx; |
99 private YAXIS(int c) { | 104 private YAXIS(int c) { |
100 idx = c; | 105 idx = c; |
101 } | 106 } |
102 } | 107 } |
103 | 108 |
104 | 109 |
105 /** Needed to access data to create subtitle. */ | 110 /** Needed to access data to create subtitle. */ |
106 protected D4EArtifact artifact; | 111 protected D4EArtifact artifact; |
112 | |
113 // TODO dupe of ComputedDischargeCurveGenerator | |
114 protected SyncNumberAxis secondYAxis; | |
115 // TODO dupe of ComputedDischargeCurveGenerator | |
116 protected NumberAxis firstYAxis; | |
117 | |
118 | |
119 /** | |
120 * Create Y (range) axis for given index, here with a special axis | |
121 * that depends on other axis (does translation and scaling for | |
122 * special case at gauge in cm). | |
123 */ | |
124 // TODO dupe of ComputedDischargeCurveGenerator | |
125 @Override | |
126 protected NumberAxis createYAxis(int index) { | |
127 logger.debug("createYAxis: " + index); | |
128 if (index == 1) { | |
129 firstYAxis = super.createYAxis(1); | |
130 if (secondYAxis != null) { | |
131 secondYAxis.setProxyAxis(firstYAxis); | |
132 } | |
133 return firstYAxis; | |
134 } | |
135 YAxisWalker walker = getYAxisWalker(); | |
136 | |
137 Font labelFont = new Font( | |
138 DEFAULT_FONT_NAME, | |
139 Font.BOLD, | |
140 getYAxisFontSize(index)); | |
141 | |
142 SyncNumberAxis axis = new SyncNumberAxis( | |
143 walker.getId(index), | |
144 getYAxisLabel(index), | |
145 firstYAxis); | |
146 | |
147 axis.setAutoRangeIncludesZero(false); | |
148 axis.setLabelFont(labelFont); | |
149 axis.setTickLabelFont(labelFont); | |
150 axis.setShift((double)-getCurrentGaugeDatum()); | |
151 | |
152 secondYAxis = axis; | |
153 return axis; | |
154 } | |
155 | |
156 public double getCurrentGaugeDatum() { | |
157 if (context.getContextValue(CURRENT_KM) != null) { | |
158 return DischargeCurveGenerator.getCurrentGaugeDatum( | |
159 (Double) context.getContextValue(CURRENT_KM), | |
160 (D4EArtifact) getMaster(), 0.1d); | |
161 } | |
162 else return 0d; | |
163 } | |
107 | 164 |
108 | 165 |
109 @Override | 166 @Override |
110 public void doOut(ArtifactAndFacet aaf, Document doc, boolean visible) { | 167 public void doOut(ArtifactAndFacet aaf, Document doc, boolean visible) { |
111 logger.debug("doOut: " + aaf.getFacetName()); | 168 logger.debug("doOut: " + aaf.getFacetName()); |
610 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); | 667 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); |
611 } | 668 } |
612 | 669 |
613 @Override | 670 @Override |
614 protected String getDefaultYAxisLabel(int pos) { | 671 protected String getDefaultYAxisLabel(int pos) { |
615 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); | 672 D4EArtifact flys = (D4EArtifact) master; |
673 | |
674 String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); | |
675 if (pos == 0 && getCurrentGaugeDatum() != 0) | |
676 unit = "cm"; | |
677 | |
678 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT, new Object[] { unit }); | |
616 } | 679 } |
617 | 680 |
618 @Override | 681 @Override |
619 protected ChartGenerator.YAxisWalker getYAxisWalker() { | 682 protected ChartGenerator.YAxisWalker getYAxisWalker() { |
620 return new YAxisWalker() { | 683 return new YAxisWalker() { |