comparison flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDeltaWtGenerator.java @ 3438:b9aff8d6ff74

Simplify annotation code flys-artifacts/trunk@5101 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Christian Lins <christian.lins@intevation.de>
date Mon, 23 Jul 2012 09:37:12 +0000
parents 97ad960f5579
children b9c2becbcc9e
comparison
equal deleted inserted replaced
3437:e111902834d3 3438:b9aff8d6ff74
245 boolean visible 245 boolean visible
246 ) { 246 ) {
247 logger.debug("doAnalysisEventsOut: desc = " + desc); 247 logger.debug("doAnalysisEventsOut: desc = " + desc);
248 248
249 QWD[] qwds = (QWD[]) data; 249 QWD[] qwds = (QWD[]) data;
250 doQWDEventsOut(qwds, desc, theme, visible);
251 }
252
253
254 protected void doQWDEventsOut(QWD[] qwds, String desc, Document theme, boolean visible)
255 {
250 TimeSeriesCollection tsc = new TimeSeriesCollection(); 256 TimeSeriesCollection tsc = new TimeSeriesCollection();
251 257
252 TimeSeries series = new StyledTimeSeries(desc, theme); 258 TimeSeries series = new StyledTimeSeries(desc, theme);
253 TimeSeries interpol = new StyledTimeSeries(desc + "interpol", theme); 259 TimeSeries interpol = new StyledTimeSeries(desc + "interpol", theme);
254 260
255 if (qwds == null) { 261 if (qwds == null) {
256 logger.debug("doAnalysisEventsOut: qwds == null"); 262 logger.debug("doQWDEventsOut: qwds == null");
257 return; 263 return;
258 } 264 }
259 265
260 if (qwds.length == 0) { 266 if (qwds.length == 0) {
261 logger.debug("doAnalysisEventsOut: qwds.length == 0"); 267 logger.debug("doQWDEventsOut: qwds.length == 0");
262 return; 268 return;
263 } 269 }
264 270
265 Map<Integer, int[]> annoIdxMap = new HashMap<Integer, int[]>(); 271 Map<Integer, int[]> annoIdxMap = new HashMap<Integer, int[]>();
266 272
267 int idxInterpol = 0; 273 int idxInterpol = 0;
268 int idxRegular = 0; 274 int idxRegular = 0;
269 for (int i = 0; i < qwds.length; i++) { 275 for (int i = 0; i < qwds.length; i++) {
270 if (qwds[i] == null) { 276 if (qwds[i] == null) {
271 logger.debug("doAnalysisEventsOut: qwds[" + i + "] == null"); 277 logger.debug("doQWDEventsOut: qwds[" + i + "] == null");
272 continue;
273 }
274 RegularTimePeriod rtp = new Day(qwds[i].getDate());
275 double value = qwds[i].getDeltaW();
276 boolean interpolate = qwds[i].getInterpolated();
277 if (interpolate) {
278 interpol.add(rtp, value);
279 annoIdxMap.put(
280 i,
281 new int[]{1, idxInterpol++});
282 }
283 else {
284 series.add(rtp, value);
285 annoIdxMap.put(
286 i,
287 new int[]{0, idxRegular++});
288 }
289 }
290 tsc.addSeries(series);
291 tsc.addSeries(interpol);
292 addAxisDataset(tsc, 0, visible);
293 addAttribute(desc + "interpol", "interpolate");
294 addAttribute(desc, "outline");
295
296 if (visible) {
297 doQWDTextAnnotations(annoIdxMap, tsc, qwds, theme, visible);
298 }
299 }
300
301
302 /**
303 * @param annoIdxMap map of index in qwds to series/dataitem indices in tsc.
304 */
305 protected void doQWDTextAnnotations(Map<Integer, int[]> annoIdxMap,
306 TimeSeriesCollection tsc, QWD[] qwds, Document theme,
307 boolean visible) {
308 logger.debug("doQWDTextAnnotation()");
309
310 if (!visible || !ThemeUtil.parseShowPointLabel(theme)) {
311 logger.debug("doQWDTextAnnotation: annotation not visible");
312 return;
313 }
314
315 List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>();
316 Set<Map.Entry<Integer, int[]>> entries = annoIdxMap.entrySet();
317
318 for(Map.Entry<Integer, int[]> entry : entries) {
319 QWD qwd = qwds[entry.getKey()];
320 int[] idxs = entry.getValue();
321 double x = tsc.getXValue(idxs[0], idxs[1]);
322 XYTextAnnotation anno = new CollisionFreeXYTextAnnotation(
323 qwd.getQ() + " m\u00B3/s",
324 x,
325 qwd.getDeltaW());
326 textAnnos.add(anno);
327 logger.debug("annotation: " + x + "/" + qwd.getDeltaW());
328 }
329
330 FLYSAnnotation flysAnno = new FLYSAnnotation(null, null, null, theme);
331 flysAnno.setTextAnnotations(textAnnos);
332 addAnnotations(flysAnno);
333 }
334
335
336 protected void doReferenceEventsOut(
337 FLYSArtifact artifact,
338 Object data,
339 String desc,
340 Document theme,
341 boolean visible
342 ) {
343 logger.debug("doReferenceEventsOut: desc = " + desc);
344
345 QWD[] qwds = (QWD[]) data;
346 TimeSeriesCollection tsc = new TimeSeriesCollection();
347
348 TimeSeries series = new StyledTimeSeries(desc, theme);
349 TimeSeries interpol = new StyledTimeSeries(desc + "interpol", theme);
350
351 if (qwds == null) {
352 return;
353 }
354
355 Map<Integer, int[]> annoIdxMap = new HashMap<Integer, int[]>();
356
357 int idxInterpol = 0;
358 int idxRegular = 0;
359 for (int i = 0; i < qwds.length; i++) {
360 if (qwds[i] == null) {
361 continue; 278 continue;
362 } 279 }
363 RegularTimePeriod rtp = new Day(qwds[i].getDate()); 280 RegularTimePeriod rtp = new Day(qwds[i].getDate());
364 double value = qwds[i].getDeltaW(); 281 double value = qwds[i].getDeltaW();
365 boolean interpolate = qwds[i].getInterpolated(); 282 boolean interpolate = qwds[i].getInterpolated();
380 } 297 }
381 } 298 }
382 } 299 }
383 tsc.addSeries(series); 300 tsc.addSeries(series);
384 tsc.addSeries(interpol); 301 tsc.addSeries(interpol);
385
386 addAxisDataset(tsc, 0, visible); 302 addAxisDataset(tsc, 0, visible);
387 addAttribute(desc + "interpol", "interpolate"); 303 addAttribute(desc + "interpol", "interpolate");
388 addAttribute(desc, "outline"); 304 addAttribute(desc, "outline");
389 305
390 doQWDTextAnnotations(annoIdxMap, tsc, qwds, theme, visible); 306 doQWDTextAnnotations(annoIdxMap, tsc, qwds, theme, visible);
307 }
308
309
310 /**
311 * @param annoIdxMap map of index in qwds to series/data item indices in tsc.
312 */
313 protected void doQWDTextAnnotations(Map<Integer, int[]> annoIdxMap,
314 TimeSeriesCollection tsc, QWD[] qwds, Document theme,
315 boolean visible) {
316 logger.debug("doQWDTextAnnotation()");
317
318 if (!visible || !ThemeUtil.parseShowPointLabel(theme)) {
319 logger.debug("doQWDTextAnnotation: annotation not visible");
320 return;
321 }
322
323 List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>();
324 Set<Map.Entry<Integer, int[]>> entries = annoIdxMap.entrySet();
325
326 for(Map.Entry<Integer, int[]> entry : entries) {
327 QWD qwd = qwds[entry.getKey()];
328 int[] idxs = entry.getValue();
329 double x = tsc.getXValue(idxs[0], idxs[1]);
330 XYTextAnnotation anno = new CollisionFreeXYTextAnnotation(
331 qwd.getQ() + " m\u00B3/s",
332 x,
333 qwd.getDeltaW());
334 textAnnos.add(anno);
335 }
336
337 FLYSAnnotation flysAnno = new FLYSAnnotation(null, null, null, theme);
338 flysAnno.setTextAnnotations(textAnnos);
339 addAnnotations(flysAnno);
340 }
341
342
343 protected void doReferenceEventsOut(
344 FLYSArtifact artifact,
345 Object data,
346 String desc,
347 Document theme,
348 boolean visible
349 ) {
350 logger.debug("doReferenceEventsOut: desc = " + desc);
351
352 QWD[] qwds = (QWD[]) data;
353 doQWDEventsOut(qwds, desc, theme, visible);
391 } 354 }
392 355
393 356
394 protected void doDeviationOut( 357 protected void doDeviationOut(
395 FLYSArtifact artifact, 358 FLYSArtifact artifact,

http://dive4elements.wald.intevation.org