Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java @ 334:e37930705daa
Changed the way of adding data to charts. Same parameters have one axis - not each parameter its own one.
gnv-artifacts/trunk@400 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 07 Dec 2009 17:03:24 +0000 |
parents | 22a6493e8460 |
children | e964a3d8f7bc |
comparison
equal
deleted
inserted
replaced
333:19571fd1d0e8 | 334:e37930705daa |
---|---|
1 package de.intevation.gnv.chart; | 1 package de.intevation.gnv.chart; |
2 | 2 |
3 import java.util.Collection; | 3 import java.util.Collection; |
4 import java.util.HashMap; | |
4 import java.util.Iterator; | 5 import java.util.Iterator; |
5 import java.util.Locale; | 6 import java.util.Locale; |
6 | 7 |
7 import org.apache.log4j.Logger; | 8 import org.apache.log4j.Logger; |
8 | 9 |
14 import org.jfree.data.xy.XYSeries; | 15 import org.jfree.data.xy.XYSeries; |
15 import org.jfree.data.general.Series; | 16 import org.jfree.data.general.Series; |
16 import org.jfree.data.xy.XYSeriesCollection; | 17 import org.jfree.data.xy.XYSeriesCollection; |
17 | 18 |
18 import de.intevation.gnv.geobackend.base.Result; | 19 import de.intevation.gnv.geobackend.base.Result; |
20 import de.intevation.gnv.transition.describedata.KeyValueDescibeData; | |
19 | 21 |
20 | 22 |
21 /** | 23 /** |
22 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> | 24 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> |
23 */ | 25 */ |
48 this.timeGaps = timeGaps; | 50 this.timeGaps = timeGaps; |
49 this.locale = locale; | 51 this.locale = locale; |
50 this.PLOT_ORIENTATION = PlotOrientation.HORIZONTAL; | 52 this.PLOT_ORIENTATION = PlotOrientation.HORIZONTAL; |
51 this.linesVisible = linesVisible; | 53 this.linesVisible = linesVisible; |
52 this.shapesVisible = shapesVisible; | 54 this.shapesVisible = shapesVisible; |
55 this.datasets = new HashMap(); | |
53 } | 56 } |
54 | 57 |
55 | 58 |
56 protected void initData() { | 59 protected void initData() { |
57 log.debug("init data for VerticalProfileChart"); | 60 log.debug("init data for VerticalProfileChart"); |
76 !row.getString("GROUP3").equals(breakPoint3) | 79 !row.getString("GROUP3").equals(breakPoint3) |
77 ) { | 80 ) { |
78 log.debug("prepare data/plot for next dataset"); | 81 log.debug("prepare data/plot for next dataset"); |
79 | 82 |
80 if(series != null) { | 83 if(series != null) { |
81 addSeries(series, idx); | 84 addSeries(series, seriesName, idx); |
82 prepareAxis(((String)series.getKey()), idx); | |
83 adjustRenderer(idx++, linesVisible, shapesVisible); | |
84 } | 85 } |
85 | 86 |
86 // prepare variables for next plot | 87 // prepare variables for next plot |
87 breakPoint1 = row.getString("GROUP1"); | 88 breakPoint1 = row.getString("GROUP1"); |
88 breakPoint2 = row.getString("GROUP2"); | 89 breakPoint2 = row.getString("GROUP2"); |
99 } | 100 } |
100 | 101 |
101 addValue(row, series); | 102 addValue(row, series); |
102 } | 103 } |
103 | 104 |
104 addSeries(series, idx); | 105 addSeries(series, seriesName, idx); |
105 | 106 |
106 if (series != null) { | 107 addDatasets(); |
107 prepareAxis(((String)series.getKey()), idx); | |
108 adjustRenderer(idx++, linesVisible, shapesVisible); | |
109 } | |
110 } | 108 } |
111 | 109 |
112 | 110 |
113 protected void addValue(Result row, Series series) { | 111 protected void addValue(Result row, Series series) { |
114 // TODO look for gaps between two values | 112 // TODO look for gaps between two values |
117 row.getDouble("YORDINATE") | 115 row.getDouble("YORDINATE") |
118 ); | 116 ); |
119 } | 117 } |
120 | 118 |
121 | 119 |
122 protected void addSeries(Series series, int idx) { | 120 protected void addSeries(Series series, String label, int idx) { |
123 log.debug("add series to verticalprofile chart"); | 121 log.debug("add series (" + label + ")to chart"); |
124 XYPlot plot = chart.getXYPlot(); | |
125 | 122 |
126 if (series == null) { | 123 if (series == null) { |
127 log.warn("no data to add"); | 124 log.warn("no data to add"); |
128 return; | 125 return; |
129 } | 126 } |
130 | 127 |
131 XYSeriesCollection xysc = new XYSeriesCollection((XYSeries)series); | 128 XYSeriesCollection xysc = null; |
132 plot.setDataset(idx, xysc); | 129 String parameter = findParameter(label); |
130 | |
131 if (datasets.containsKey(parameter)) | |
132 xysc = (XYSeriesCollection) datasets.get(parameter); | |
133 else | |
134 xysc = new XYSeriesCollection(); | |
135 | |
136 xysc.addSeries((XYSeries) series); | |
137 datasets.put(parameter, xysc); | |
138 } | |
139 | |
140 | |
141 protected void addDatasets() { | |
142 Iterator iter = parameters.iterator(); | |
143 XYPlot plot = chart.getXYPlot(); | |
144 int idx = 0; | |
145 | |
146 XYSeriesCollection xysc = null; | |
147 KeyValueDescibeData data = null; | |
148 String key = null; | |
149 while (iter.hasNext()) { | |
150 data = (KeyValueDescibeData) iter.next(); | |
151 key = data.getValue(); | |
152 | |
153 if (datasets.containsKey(key)) { | |
154 xysc = (XYSeriesCollection)datasets.get(key); | |
155 plot.setDataset(idx, xysc ); | |
156 log.debug("Added " + key + " parameter to plot."); | |
157 prepareAxis(key, idx); | |
158 adjustRenderer( | |
159 idx++, | |
160 xysc.getSeriesCount(), | |
161 linesVisible, | |
162 shapesVisible | |
163 ); | |
164 } | |
165 } | |
133 } | 166 } |
134 | 167 |
135 | 168 |
136 protected void localizeDomainAxis(Axis axis, Locale locale) { | 169 protected void localizeDomainAxis(Axis axis, Locale locale) { |
137 // call localizeRangeAxis from superclass which formats NumberAxis | 170 // call localizeRangeAxis from superclass which formats NumberAxis |