comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java @ 2644:0a84313efe60

Stub for labeling dataseries in EnhancedLineAndShapeRenerer. flys-artifacts/trunk@4299 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 25 Apr 2012 15:15:39 +0000
parents 42b05a4bed25
children 4b7a28e81643
comparison
equal deleted inserted replaced
2643:d6794864a4b8 2644:0a84313efe60
31 31
32 protected BooleanList isMinimumShapeVisible; 32 protected BooleanList isMinimumShapeVisible;
33 protected BooleanList isMaximumShapeVisible; 33 protected BooleanList isMaximumShapeVisible;
34 34
35 protected Map<Integer, Double> seriesMinimum; 35 protected Map<Integer, Double> seriesMinimum;
36 protected Map<Integer, Double> seriesMinimumX;
36 protected Map<Integer, Double> seriesMaximum; 37 protected Map<Integer, Double> seriesMaximum;
37 38
38 39
39 public EnhancedLineAndShapeRenderer(boolean lines, boolean shapes) { 40 public EnhancedLineAndShapeRenderer(boolean lines, boolean shapes) {
40 super(lines, shapes); 41 super(lines, shapes);
41 this.isMinimumShapeVisible = new BooleanList(); 42 this.isMinimumShapeVisible = new BooleanList();
42 this.isMaximumShapeVisible = new BooleanList(); 43 this.isMaximumShapeVisible = new BooleanList();
43 this.seriesMinimum = new HashMap<Integer, Double>(); 44 this.seriesMinimum = new HashMap<Integer, Double>();
44 this.seriesMaximum = new HashMap<Integer, Double>(); 45 this.seriesMaximum = new HashMap<Integer, Double>();
46 this.seriesMinimumX = new HashMap<Integer, Double>();
45 } 47 }
46 48
47 49
48 public boolean getItemShapeVisible(XYDataset dataset, int series, int item){ 50 public boolean getItemShapeVisible(XYDataset dataset, int series, int item){
49 if (super.getItemShapeVisible(series, item)) { 51 if (super.getItemShapeVisible(series, item)) {
145 double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); 147 double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
146 148
147 if (getItemShapeVisible(dataset, series, item)) { 149 if (getItemShapeVisible(dataset, series, item)) {
148 Shape shape = null; 150 Shape shape = null;
149 151
150 // OPTIMIZE instead of calculating minimum and maximum for every 152 // OPTIMIZE: instead of calculating minimum and maximum for every
151 // point, calculate it just once (assume that dataset 153 // point, calculate it just once (assume that dataset
152 // content does not change during rendering). 154 // content does not change during rendering).
155 // NOTE: Above OPTIMIZE might already be fulfilled to most extend.
153 boolean isMinimum = isMinimumShapeVisible(series) 156 boolean isMinimum = isMinimumShapeVisible(series)
154 && isMinimum(dataset, series, item); 157 && isMinimum(dataset, series, item);
155 158
156 boolean isMaximum = isMaximumShapeVisible(series) 159 boolean isMaximum = isMaximumShapeVisible(series)
157 && isMaximum(dataset, series, item); 160 && isMaximum(dataset, series, item);
212 g2.setStroke(getItemOutlineStroke(series, item)); 215 g2.setStroke(getItemOutlineStroke(series, item));
213 g2.draw(shape); 216 g2.draw(shape);
214 } 217 }
215 } 218 }
216 // TODO labeling of waterlevels could happen here, too. 219 // TODO labeling of waterlevels could happen here, too.
217 } 220 } // if (getItemShapeVisible(dataset, series, item))
218 221
219 double xx = transX1; 222 double xx = transX1;
220 double yy = transY1; 223 double yy = transY1;
221 if (orientation == PlotOrientation.HORIZONTAL) { 224 if (orientation == PlotOrientation.HORIZONTAL) {
222 xx = transY1; 225 xx = transY1;
227 if (isItemLabelVisible(series, item)) { 230 if (isItemLabelVisible(series, item)) {
228 drawItemLabel(g2, orientation, dataset, series, item, xx, yy, 231 drawItemLabel(g2, orientation, dataset, series, item, xx, yy,
229 (y1 < 0.0)); 232 (y1 < 0.0));
230 } 233 }
231 234
235 boolean doWaterlevelLabel = false;
236 if (isMinimumX (dataset, series, item)) {
237 String waterlevelLabel = "label";
238 // TODO Force water of some German rivers to flow direction mountains.
239 g2.drawString("waterlevel label", (float)xx, (float)yy-3f);
240 }
241
232 int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); 242 int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
233 int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); 243 int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
234 updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, 244 updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
235 rangeAxisIndex, transX1, transY1, orientation); 245 rangeAxisIndex, transX1, transY1, orientation);
236 246
268 278
269 return isMaximumShapeVisible.getBoolean(series); 279 return isMaximumShapeVisible.getBoolean(series);
270 } 280 }
271 281
272 282
283 public boolean isMinimumX(XYDataset dataset, int series, int item) {
284 return dataset.getXValue(series, item) == getMinimumX(dataset, series);
285 }
286
287 public double getMinimumX(XYDataset dataset, int series) {
288 Integer key = Integer.valueOf(series);
289 Double old = seriesMinimumX.get(key);
290
291 if (old != null) {
292 return old.doubleValue();
293 }
294
295 logger.debug("Compute minimum of Series: " + series);
296
297 double min = Double.MAX_VALUE;
298
299 for (int i = 0, n = dataset.getItemCount(series); i < n; i++) {
300 double tmpValue = dataset.getXValue(series, i);
301
302 if (tmpValue < min) {
303 min = tmpValue;
304 }
305 }
306
307 seriesMinimumX.put(key, Double.valueOf(min));
308
309 return min;
310 }
311
273 public boolean isMinimum(XYDataset dataset, int series, int item) { 312 public boolean isMinimum(XYDataset dataset, int series, int item) {
274 return dataset.getYValue(series, item) == getMinimum(dataset, series); 313 return dataset.getYValue(series, item) == getMinimum(dataset, series);
275 } 314 }
276 315
277 316
304 public boolean isMaximum(XYDataset dataset, int series, int item) { 343 public boolean isMaximum(XYDataset dataset, int series, int item) {
305 return dataset.getYValue(series, item) == getMaximum(dataset, series); 344 return dataset.getYValue(series, item) == getMaximum(dataset, series);
306 } 345 }
307 346
308 347
348 //
309 public double getMaximum(XYDataset dataset, int series) { 349 public double getMaximum(XYDataset dataset, int series) {
310 Integer key = Integer.valueOf(series); 350 Integer key = Integer.valueOf(series);
311 Double old = seriesMaximum.get(key); 351 Double old = seriesMaximum.get(key);
312 352
313 if (old != null) { 353 if (old != null) {

http://dive4elements.wald.intevation.org