comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 673:b22f21b173a7

Changed the zoom process - the values in the chart request document are percentual values that apply to every axis. flys-artifacts/trunk@2095 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 09 Jun 2011 10:48:13 +0000
parents 434146596838
children be4709640aac
comparison
equal deleted inserted replaced
672:bc1e4878d7e3 673:b22f21b173a7
104 104
105 addDatasets(chart); 105 addDatasets(chart);
106 addSubtitles(chart); 106 addSubtitles(chart);
107 adjustPlot(plot); 107 adjustPlot(plot);
108 adjustAxes(plot); 108 adjustAxes(plot);
109 zoom(plot); 109 autoZoom(plot);
110 110
111 return chart; 111 return chart;
112 } 112 }
113 113
114 114
119 * are given, because JFreeCharts auto-zoom adds a margin to the left and 119 * are given, because JFreeCharts auto-zoom adds a margin to the left and
120 * right of the data area. 120 * right of the data area.
121 * 121 *
122 * @param plot The XYPlot. 122 * @param plot The XYPlot.
123 */ 123 */
124 protected void zoom(XYPlot plot) { 124 protected void autoZoom(XYPlot plot) {
125 logger.debug("Zoom to specified ranges."); 125 logger.debug("Zoom to specified ranges.");
126 126
127 Range[] ranges = null; 127 Range xrange = getDomainAxisRange();
128 128 Range yrange = getValueAxisRange();
129 boolean x = zoomX(plot); 129
130 if (!x) { 130 for (int i = 0, num = plot.getDatasetCount(); i < num; i++) {
131 XYDataset dataset = plot.getDataset(); 131 XYDataset dataset = plot.getDataset(i);
132 132 Range[] ranges = getRangesForDataset(dataset);
133 ranges = getRangesForDataset(dataset); 133
134 134 if (i == 0) {
135 logger.debug("No x range specified. Set manually: " + ranges[0]); 135 ValueAxis xaxis = plot.getDomainAxis();
136 136 zoom(plot, xaxis, ranges[0], xrange);
137 ValueAxis axis = plot.getDomainAxis(); 137 }
138 axis.setRange(ranges[0]); 138
139 ValueAxis yaxis = plot.getRangeAxis(i);
140
141 if (yaxis == null) {
142 continue;
143 }
144
145 zoom(plot, yaxis, ranges[1], yrange);
139 } 146 }
140
141 boolean y = zoomY(plot);
142 if (!y) {
143 XYDataset dataset = plot.getDataset();
144
145 if (ranges == null) {
146 ranges = getRangesForDataset(dataset);
147 }
148
149 logger.debug("No y range specified. Set manually: " + ranges[1]);
150
151 ValueAxis axis = plot.getRangeAxis();
152 axis.setRange(ranges[1]);
153 }
154 } 147 }
155 148
156 149
157 /** 150 /**
158 * Zooms the x axis to the range specified in the attribute document. 151 * Zooms the x axis to the range specified in the attribute document.
159 * 152 *
160 * @param plot The XYPlot. 153 * @param plot The XYPlot.
154 * @param axis The axis the shoud be modified.
155 * @param range The whole range specified by a dataset.
156 * @param x A user defined range (null permitted).
161 * 157 *
162 * @return true, if a zoom range was specified, otherwise false. 158 * @return true, if a zoom range was specified, otherwise false.
163 */ 159 */
164 protected boolean zoomX(XYPlot plot) { 160 protected boolean zoom(XYPlot plot, ValueAxis axis, Range range, Range x) {
165 Range xrange = getDomainAxisRange(); 161 if (x != null) {
166 if (xrange != null) { 162 double min = range.getLowerBound();
167 ValueAxis xaxis = plot.getDomainAxis(); 163 double max = range.getUpperBound();
168 xaxis.setRange(xrange); 164 double diff = max > min ? max - min : min - max;
169 165
170 logger.debug("Zoom chart to X: " + xrange); 166 Range computed = new Range(
167 min + x.getLowerBound() * diff,
168 min + x.getUpperBound() * diff);
169
170 axis.setRange(computed);
171
172 logger.debug("Zoom axis to: " + computed);
171 173
172 return true; 174 return true;
173 } 175 }
174 176
177 axis.setRange(range);
175 return false; 178 return false;
176 } 179 }
177 180
178 181
179 /** 182 /**
180 * Zooms the y axis to the range specified in the attribute document.
181 *
182 * @param plot The XYPlot.
183 *
184 * @return true, if a zoom range was specified, otherwise false.
185 */
186 protected boolean zoomY(XYPlot plot) {
187 Range yrange = getValueAxisRange();
188 if (yrange != null) {
189 ValueAxis yaxis = plot.getRangeAxis();
190 yaxis.setRange(yrange);
191
192 logger.debug("Zoom chart to Y: " + yrange);
193
194 return true;
195 }
196
197 return false;
198 }
199
200
201 /**
202 * This method extracts the minimum and maximum values for x and y axes. 183 * This method extracts the minimum and maximum values for x and y axes.
203 * 184 *
204 * @param dataset The dataset that should be observed. 185 * @param dataset The dataset that should be observed.
205 * 186 *
206 * @return a Range[] as follows: [x-Range, y-Range]. 187 * @return a Range[] as follows: [x-Range, y-Range].
207 */ 188 */
208 protected Range[] getRangesForDataset(XYDataset dataset) { 189 public static Range[] getRangesForDataset(XYDataset dataset) {
209 double[] xr = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; 190 double[] xr = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
210 double[] yr = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; 191 double[] yr = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
211 192
212 int sCount = dataset.getSeriesCount(); 193 int sCount = dataset.getSeriesCount();
213 194

http://dive4elements.wald.intevation.org