Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java @ 3984:89d7e97e9c9a
Manual points working in fixing Delta W/t char (#462).
author | Christian Lins <clins@intevation.de> |
---|---|
date | Sat, 29 Sep 2012 20:09:27 +0200 |
parents | 8490faba00e7 |
children | 7cc05da7e35c |
comparison
equal
deleted
inserted
replaced
3983:65e369ac4f99 | 3984:89d7e97e9c9a |
---|---|
1 package de.intevation.flys.exports; | 1 package de.intevation.flys.exports; |
2 | 2 |
3 import de.intevation.artifactdatabase.state.ArtifactAndFacet; | 3 import de.intevation.artifactdatabase.state.ArtifactAndFacet; |
4 import de.intevation.flys.artifacts.resources.Resources; | |
4 import de.intevation.flys.jfree.Bounds; | 5 import de.intevation.flys.jfree.Bounds; |
5 import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation; | 6 import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation; |
6 import de.intevation.flys.jfree.DoubleBounds; | 7 import de.intevation.flys.jfree.DoubleBounds; |
7 import de.intevation.flys.jfree.FLYSAnnotation; | 8 import de.intevation.flys.jfree.FLYSAnnotation; |
8 import de.intevation.flys.jfree.StyledTimeSeries; | 9 import de.intevation.flys.jfree.StyledTimeSeries; |
9 import de.intevation.flys.jfree.TimeBounds; | 10 import de.intevation.flys.jfree.TimeBounds; |
10 | 11 |
11 import java.awt.Color; | 12 import java.awt.Color; |
12 import java.awt.Font; | 13 import java.awt.Font; |
14 import java.text.DateFormat; | |
15 import java.text.ParseException; | |
13 import java.util.ArrayList; | 16 import java.util.ArrayList; |
14 import java.util.Date; | 17 import java.util.Date; |
15 import java.util.HashMap; | 18 import java.util.HashMap; |
16 import java.util.List; | 19 import java.util.List; |
17 import java.util.Map; | 20 import java.util.Map; |
654 xaxis.setLabelFont(labelFont); | 657 xaxis.setLabelFont(labelFont); |
655 xaxis.setTickLabelFont(labelFont); | 658 xaxis.setTickLabelFont(labelFont); |
656 } | 659 } |
657 | 660 |
658 | 661 |
662 protected Date decodeXAxisValue(JSONArray array) throws JSONException, ParseException { | |
663 try { | |
664 double x = array.getDouble(0); | |
665 long l = (new Double(x)).longValue(); | |
666 return new Date(l); | |
667 } | |
668 catch(JSONException ex) { | |
669 String str = array.getString(0); | |
670 DateFormat df = DateFormat.getDateInstance( | |
671 DateFormat.MEDIUM, Resources.getLocale(context.getMeta())); | |
672 return df.parse(str); | |
673 } | |
674 } | |
675 | |
659 /** | 676 /** |
660 * Do Points out. | 677 * Do Points out. |
661 */ | 678 */ |
662 protected void doPoints( | 679 protected void doPoints( |
663 Object o, | 680 Object o, |
675 | 692 |
676 try { | 693 try { |
677 JSONArray points = new JSONArray((String) o); | 694 JSONArray points = new JSONArray((String) o); |
678 for (int i = 0, P = points.length(); i < P; i++) { | 695 for (int i = 0, P = points.length(); i < P; i++) { |
679 JSONArray array = points.getJSONArray(i); | 696 JSONArray array = points.getJSONArray(i); |
680 double x = array.getDouble(0); | 697 |
681 double y = array.getDouble(1); | 698 double y = array.getDouble(1); |
682 String name = array.getString(2); | 699 String name = array.getString(2); |
683 boolean act = array.getBoolean(3); | 700 boolean act = array.getBoolean(3); |
684 if (!act) { | 701 if (!act) { |
685 continue; | 702 continue; |
686 } | 703 } |
687 long l = (new Double(x)).longValue(); | 704 |
688 Date date = new Date(l); | 705 Date date = decodeXAxisValue(array); |
706 | |
689 Day day = new Day(date); | 707 Day day = new Day(date); |
690 series.add(day, y, false); | 708 series.add(day, y, false); |
691 names.put(day, name); | 709 names.put(day, name); |
692 } | 710 } |
693 } | 711 } |
694 catch(JSONException e){ | 712 catch(JSONException ex) { |
695 logger.error("Could not decode json."); | 713 logger.error("Could not decode json"); |
714 } | |
715 catch(ParseException ex) { | |
716 logger.error("Could not parse date string"); | |
696 } | 717 } |
697 | 718 |
698 TimeSeriesCollection tsc = new TimeSeriesCollection(); | 719 TimeSeriesCollection tsc = new TimeSeriesCollection(); |
699 tsc.addSeries(series); | 720 tsc.addSeries(series); |
700 // Add Annotations. | 721 // Add Annotations. |
701 for (int i = 0, S = series.getItemCount(); i < S; i++) { | 722 for (int i = 0, S = series.getItemCount(); i < S; i++) { |
702 double x = tsc.getXValue(0, i); | 723 double x = tsc.getXValue(0, i); |
703 double y = tsc.getYValue(0, i); | 724 double y = tsc.getYValue(0, i); |
704 xy.add(new CollisionFreeXYTextAnnotation( | 725 xy.add(new CollisionFreeXYTextAnnotation( |
705 names.get(series.getTimePeriod(i)), x, y)); | 726 names.get(series.getTimePeriod(i)), x, y)); |
727 logger.debug("doPoints(): x=" + x + " y=" + y); | |
706 } | 728 } |
707 FLYSAnnotation annotations = | 729 FLYSAnnotation annotations = |
708 new FLYSAnnotation(null, null, null, theme); | 730 new FLYSAnnotation(null, null, null, theme); |
709 annotations.setTextAnnotations(xy); | 731 annotations.setTextAnnotations(xy); |
710 | 732 |