comparison flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java @ 1125:65d8b3340397

Cleanups of CrossSection*. flys-artifacts/trunk@2635 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 01 Sep 2011 13:00:36 +0000
parents 111794adf285
children bcba246d9c03
comparison
equal deleted inserted replaced
1124:28a595b32980 1125:65d8b3340397
43 "chart.cross_section.xaxis.label"; 43 "chart.cross_section.xaxis.label";
44 44
45 public static final String I18N_YAXIS_LABEL = 45 public static final String I18N_YAXIS_LABEL =
46 "chart.cross_section.yaxis.label"; 46 "chart.cross_section.yaxis.label";
47 47
48 public static final String I18N_CHART_TITLE_DEFAULT = "Querschnittt"; 48 public static final String I18N_CHART_TITLE_DEFAULT = "Querprofildiagramm";
49 public static final String I18N_XAXIS_LABEL_DEFAULT = "m"; 49 public static final String I18N_XAXIS_LABEL_DEFAULT = "Abstand [m]";
50 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; 50 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]";
51
52
53 protected boolean inverted;
54 51
55 52
56 /** Trivial Constructor. */ 53 /** Trivial Constructor. */
57 public CrossSectionGenerator() { 54 public CrossSectionGenerator() {
58 super(); 55 super();
59 } 56 }
60 57
61 58
59 /**
60 * Get localized chart title.
61 */
62 protected String getChartTitle() { 62 protected String getChartTitle() {
63 // TODO get river etc for localized heading
63 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); 64 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
64 } 65 }
65 66
66 public boolean isInverted() {
67 return inverted;
68 }
69 67
70 public void setInverted(boolean inverted) { 68 /**
71 this.inverted = inverted; 69 * Add localized subtitle to chart.
72 } 70 */
73
74 @Override 71 @Override
75 protected void addSubtitles(JFreeChart chart) { 72 protected void addSubtitles(JFreeChart chart) {
76 double[] dist = getRange(); 73 double[] dist = getRange();
77 74
78 Object[] args = new Object[] { 75 Object[] args = new Object[] {
79 getRiverName(), 76 getRiverName(),
80 dist[0], 77 dist[0],
81 dist[1] 78 dist[1]
82 }; 79 };
83 80
84 //String subtitle = msg(I18N_CHART_SUBTITLE, "", args); 81 String subtitle = msg(I18N_CHART_SUBTITLE, "", args);
85 String subtitle = "bogus";
86 chart.addSubtitle(new TextTitle(subtitle)); 82 chart.addSubtitle(new TextTitle(subtitle));
87 } 83 }
88 84
89 @Override
90 public JFreeChart generateChart() {
91 JFreeChart c = super.generateChart();
92 XYPlot p = (XYPlot) c.getPlot();
93 85
94 return c; 86 /**
95 } 87 * Get localized X Axis label.
96 88 */
97
98 protected String getXAxisLabel() { 89 protected String getXAxisLabel() {
99 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); 90 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT);
100 } 91 }
101 92
102 93
94 /**
95 * Get localized Y Axis label.
96 */
103 protected String getYAxisLabel() { 97 protected String getYAxisLabel() {
104 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); 98 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
105 } 99 }
106 100
107 101
110 104
111 NumberAxis qAxis = new NumberAxis( 105 NumberAxis qAxis = new NumberAxis(
112 msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT)); 106 msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT));
113 107
114 plot.setRangeAxis(1, qAxis); 108 plot.setRangeAxis(1, qAxis);
115
116 invertXAxis(plot.getDomainAxis());
117 } 109 }
118 110
119 111
120 /** 112 /**
121 * This method overrides the XYChartGenerators zoomY method to include the 0 113 * Overrides XYChartGenerators.zoomY() to include the 0 value on the Q axis.
122 * value on the Q axis.
123 */ 114 */
124 @Override 115 @Override
125 protected boolean zoomY(XYPlot plot, ValueAxis axis, Range range, Range x) { 116 protected boolean zoomY(XYPlot plot, ValueAxis axis, Range range, Range x) {
126 if (plot.getRangeAxisIndex(axis) == 1) { 117 if (plot.getRangeAxisIndex(axis) == 1) {
127 // we want the Q axis to start at 0 if no zooming has been done 118 // we want the Q axis to start at 0 if no zooming has been done
128 range = new Range(0d, range.getUpperBound()); 119 range = new Range(0d, range.getUpperBound());
129 } 120 }
130 121
131 return super.zoomY(plot, axis, range, x); 122 return super.zoomY(plot, axis, range, x);
132 }
133
134
135 /**
136 * This method inverts the x-axis based on the kilometer information of the
137 * selected river. If the head of the river is at kilometer 0, the axis is
138 * not inverted, otherwise it is.
139 *
140 * @param xaxis The domain axis.
141 */
142 protected void invertXAxis(ValueAxis xaxis) {
143
144 if (inverted) {
145 logger.debug("Invert X-Axis.");
146 xaxis.setInverted(true);
147 }
148 } 123 }
149 124
150 125
151 /** 126 /**
152 * Let one facet do its job. 127 * Let one facet do its job.
186 * 161 *
187 * @param theme Theme for the data series. 162 * @param theme Theme for the data series.
188 */ 163 */
189 protected void doCrossSectionWaterLineOut(Object o, Document theme) { 164 protected void doCrossSectionWaterLineOut(Object o, Document theme) {
190 logger.debug("CrossSectionGenerator.doCrossSectionWaterLineOut"); 165 logger.debug("CrossSectionGenerator.doCrossSectionWaterLineOut");
191 XYSeries series = new StyledXYSeries("water", theme); 166 // TODO Series should get name like "Q=22.0"
167 XYSeries series = new StyledXYSeries("Q= ... ", theme);
192 168
193 double[][] a = (double [][]) o; 169 double[][] a = (double [][]) o;
194 double [] pxs = a[0]; 170 double [] pxs = a[0];
195 for (int i = 0; i < pxs.length; i++) { 171 for (int i = 0; i < pxs.length; i++) {
196 series.add (a[0][i], a[1][i]); 172 series.add (a[0][i], a[1][i]);
205 * @param theme Theme for the data series. 181 * @param theme Theme for the data series.
206 */ 182 */
207 protected void doCrossSectionOut(Object o, Document theme) { 183 protected void doCrossSectionOut(Object o, Document theme) {
208 logger.debug("CrossSectionGenerator.doCrossSectionOut"); 184 logger.debug("CrossSectionGenerator.doCrossSectionOut");
209 185
186 // TODO Series should get name of selected cross-section (e.g.
187 // "0-93.1(1990-2002).PRF") (exposed as getCrossSectionName in
188 // WINFOArtifact)
210 XYSeries series = new StyledXYSeries("aliquide", theme); 189 XYSeries series = new StyledXYSeries("aliquide", theme);
211 190
212 double[][] a = (double [][]) o; 191 double[][] a = (double [][]) o;
213 double [] pxs = a[0]; 192 double [] pxs = a[0];
214 for (int i = 0; i < pxs.length; i++) { 193 for (int i = 0; i < pxs.length; i++) {
215 series.add (a[0][i], a[1][i]); 194 series.add (a[0][i], a[1][i]);
216 } 195 }
217 addFirstAxisSeries(series); 196 addFirstAxisSeries(series);
218 } 197 }
219
220
221 /**
222 * Get name of series (displayed in legend).
223 * @return name of the series.
224 */
225 protected String getSeriesName(WQKms wqkms, String mode) {
226 String name = wqkms.getName();
227 String prefix = name != null && name.indexOf(mode) >= 0 ? null : mode;
228
229 return prefix != null && prefix.length() > 0
230 ? prefix + "(" + name +")"
231 : name;
232 }
233 } 198 }
234 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 199 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
235

http://dive4elements.wald.intevation.org