comparison flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java @ 1684:bdb05dc9b763

Bugfix: #353 Enabled chart's to be drawn with proper axes set even if no data is contained. flys-artifacts/trunk@2902 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 07 Oct 2011 10:51:09 +0000
parents fbe18ad4caff
children 0053a4529f2f
comparison
equal deleted inserted replaced
1683:acb4d20b130e 1684:bdb05dc9b763
2 2
3 import org.apache.log4j.Logger; 3 import org.apache.log4j.Logger;
4 4
5 import org.jfree.chart.JFreeChart; 5 import org.jfree.chart.JFreeChart;
6 import org.jfree.chart.axis.NumberAxis; 6 import org.jfree.chart.axis.NumberAxis;
7 import org.jfree.chart.axis.ValueAxis;
8 import org.jfree.chart.plot.XYPlot; 7 import org.jfree.chart.plot.XYPlot;
9 import org.jfree.chart.title.TextTitle; 8 import org.jfree.chart.title.TextTitle;
10 import org.jfree.data.Range;
11 import org.jfree.data.xy.XYSeries; 9 import org.jfree.data.xy.XYSeries;
12 10
13 import org.w3c.dom.Document; 11 import org.w3c.dom.Document;
14 12
15 import de.intevation.artifacts.Artifact; 13 import de.intevation.artifacts.Artifact;
125 plot.setRangeAxis(1, qAxis); 123 plot.setRangeAxis(1, qAxis);
126 } 124 }
127 125
128 126
129 /** 127 /**
130 * Overrides XYChartGenerators.zoomY() to include the 0 value on the Q axis.
131 */
132 @Override
133 protected boolean zoomY(XYPlot plot, ValueAxis axis, Range range, Range x) {
134 if (plot.getRangeAxisIndex(axis) == 1) {
135 // we want the Q axis to start at 0 if no zooming has been done
136 range = new Range(0d, range.getUpperBound());
137 }
138
139 return super.zoomY(plot, axis, range, x);
140 }
141
142
143 /**
144 * Let one facet do its job. 128 * Let one facet do its job.
145 */ 129 */
146 public void doOut(Artifact artifact, Facet facet, Document attr) { 130 public void doOut(
131 Artifact artifact,
132 Facet facet,
133 Document attr,
134 boolean visible
135 ) {
147 String name = facet.getName(); 136 String name = facet.getName();
148 137
149 logger.debug("CrossSectionGenerator.doOut: " + name); 138 logger.debug("CrossSectionGenerator.doOut: " + name);
150 139
151 if (name == null) { 140 if (name == null) {
159 if (f == null) { 148 if (f == null) {
160 return; 149 return;
161 } 150 }
162 151
163 if (name.equals(CROSS_SECTION)) { 152 if (name.equals(CROSS_SECTION)) {
164 doCrossSectionOut(f.getData(artifact, context), f.getDescription(), attr); 153 doCrossSectionOut(
154 f.getData(artifact, context),
155 f.getDescription(),
156 attr,
157 visible);
165 } 158 }
166 else if (name.equals(CROSS_SECTION_WATER_LINE)) { 159 else if (name.equals(CROSS_SECTION_WATER_LINE)) {
167 doCrossSectionWaterLineOut(f.getData(artifact, context), f.getDescription(), attr); 160 doCrossSectionWaterLineOut(
161 f.getData(artifact, context),
162 f.getDescription(),
163 attr,
164 visible);
168 } 165 }
169 else { 166 else {
170 logger.warn("CrossSection.doOut: Unknown facet name: " + name); 167 logger.warn("CrossSection.doOut: Unknown facet name: " + name);
171 return; 168 return;
172 } 169 }
177 * Do cross sections waterline out. 174 * Do cross sections waterline out.
178 * 175 *
179 * @param seriesName name of the data (line) to display in legend. 176 * @param seriesName name of the data (line) to display in legend.
180 * @param theme Theme for the data series. 177 * @param theme Theme for the data series.
181 */ 178 */
182 protected void doCrossSectionWaterLineOut(Object o, String seriesName, Document theme) { 179 protected void doCrossSectionWaterLineOut(
180 Object o,
181 String seriesName,
182 Document theme,
183 boolean visible
184 ) {
183 logger.debug("CrossSectionGenerator.doCrossSectionWaterLineOut"); 185 logger.debug("CrossSectionGenerator.doCrossSectionWaterLineOut");
184 186
185 XYSeries series = new StyledXYSeries(seriesName, theme); 187 XYSeries series = new StyledXYSeries(seriesName, theme);
186 188
187 double[][] a = (double [][]) o; 189 double[][] a = (double [][]) o;
188 double [] pxs = a[0]; 190 double [] pxs = a[0];
189 for (int i = 0; i < pxs.length; i++) { 191 for (int i = 0; i < pxs.length; i++) {
190 series.add (a[0][i], a[1][i]); 192 series.add (a[0][i], a[1][i]);
191 } 193 }
192 addFirstAxisSeries(series); 194 addFirstAxisSeries(series, visible);
193 } 195 }
194 196
195 197
196 /** 198 /**
197 * Do cross sections out. 199 * Do cross sections out.
198 * 200 *
199 * @param seriesName name of the data (line) to display in legend. 201 * @param seriesName name of the data (line) to display in legend.
200 * @param theme Theme for the data series. 202 * @param theme Theme for the data series.
201 */ 203 */
202 protected void doCrossSectionOut(Object o, String seriesName, Document theme) { 204 protected void doCrossSectionOut(
205 Object o,
206 String seriesName,
207 Document theme,
208 boolean visible
209 ) {
203 logger.debug("CrossSectionGenerator.doCrossSectionOut"); 210 logger.debug("CrossSectionGenerator.doCrossSectionOut");
204 211
205 XYSeries series = new StyledXYSeries(seriesName, theme); 212 XYSeries series = new StyledXYSeries(seriesName, theme);
206 213
207 double[][] a = (double [][]) o; 214 double[][] a = (double [][]) o;
208 double [] pxs = a[0]; 215 double [] pxs = a[0];
209 for (int i = 0; i < pxs.length; i++) { 216 for (int i = 0; i < pxs.length; i++) {
210 series.add (a[0][i], a[1][i]); 217 series.add (a[0][i], a[1][i]);
211 } 218 }
212 addFirstAxisSeries(series); 219 addFirstAxisSeries(series, visible);
213 } 220 }
214 } 221 }
215 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 222 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org