# HG changeset patch # User Ingo Weinzierl # Date 1276002058 0 # Node ID 649f564a5184615515fbb11d99ccb71df91b565e # Parent 902bcd837995f40838d102e704f5768784c23426 Implemented a new output state and chart type for horizontal profiles using vector data. gnv-artifacts/trunk@1174 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 902bcd837995 -r 649f564a5184 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Mon Jun 07 17:15:04 2010 +0000 +++ b/gnv-artifacts/ChangeLog Tue Jun 08 13:00:58 2010 +0000 @@ -1,3 +1,11 @@ +2010-06-08 Ingo Weinzierl + + * src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshVectorOutputState.java: + A new output state for horizontal profiles using vector data. + + * src/main/java/de/intevation/gnv/chart/HorizontalProfileVectorChart.java: A + new horizontal profile chart type using vector data. + 2010-06-07 Ingo Weinzierl * doc/conf/products/verticalprofile/conf_mesh.xml, diff -r 902bcd837995 -r 649f564a5184 gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileVectorChart.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileVectorChart.java Tue Jun 08 13:00:58 2010 +0000 @@ -0,0 +1,140 @@ +package de.intevation.gnv.chart; + +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.geobackend.base.ResultDescriptor; + +import java.util.Collection; +import java.util.Iterator; +import java.util.Locale; + +import org.apache.log4j.Logger; + +import org.jfree.chart.ChartTheme; + +import org.jfree.chart.plot.XYPlot; + +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +/** + * This class is used to create xy charts of vertical profiles. + * + * @author Ingo Weinzierl + */ +public class HorizontalProfileVectorChart +extends HorizontalProfileChart +{ + private static Logger logger = + Logger.getLogger(HorizontalProfileVectorChart.class); + + + public HorizontalProfileVectorChart( + ChartLabels labels, + ChartTheme theme, + Collection parameters, + Collection measurements, + Collection dates, + Collection result, + Collection timeGaps, + Locale locale, + boolean linesVisible, + boolean shapesVisible + ) { + super(labels, theme, parameters, measurements, dates, result, + timeGaps, locale, linesVisible, shapesVisible); + } + + + @Override + protected void initData() { + Iterator iter = resultSet.iterator(); + Result row = null; + String seriesName = null; + XYSeries series = null; + + int idx = 0; + int startPos = 0; + int endPos = 0; + + double startValue = 0; + double endValue = 0; + + ResultDescriptor rd = null; + int idxSeries = -1; + int idxX = -1; + int idxY = -1; + + Result[] results = + (Result[]) resultSet.toArray(new Result[resultSet.size()]); + + while (iter.hasNext()) { + row = (Result) iter.next(); + + if (rd == null) { + rd = row.getResultDescriptor(); + idxSeries = rd.getColumnIndex("SERIES"); + idxX = rd.getColumnIndex("XORDINATE"); + idxY = rd.getColumnIndex("YORDINATE"); + } + + if (!row.getString(idxSeries).equals(seriesName)) { + logger.debug("prepare data/plot for next dataset."); + + if (series != null) { + gapDetection(results, series, startPos, endPos); + addSeries(series, seriesName, idx); + + startPos = endPos + 1; + } + + seriesName = row.getString(idxSeries); + + logger.debug("next data is '" + seriesName + "'"); + series = new XYSeries(seriesName); + } + + addValue(row, series); + Object x = getValue(row); + Double y = row.getDouble(idxY); + if (x != null && y != null) { + storeMaxRange(ranges, y, seriesName); + storeMaxValue(values, x, seriesName); + } + + endPos++; + } + + if (results.length == 0) + return; + + gapDetection(results, series, startPos, endPos); + addSeries(series, seriesName, idx); + + addDatasets(); + } + + + @Override + protected void addDatasets() { + XYPlot plot = chart.getXYPlot(); + int idx = 0; + + XYSeriesCollection sc = null; + Iterator iter = datasets.keySet().iterator(); + + while (iter.hasNext()) { + String key = (String) iter.next(); + sc = (XYSeriesCollection)datasets.get(key); + plot.setDataset(idx, sc ); + logger.debug("Added " + key + " parameter to plot."); + prepareAxis(key, idx); + adjustRenderer( + idx++, + sc.getSeriesCount(), + linesVisible, + shapesVisible + ); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r 902bcd837995 -r 649f564a5184 gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshVectorOutputState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshVectorOutputState.java Tue Jun 08 13:00:58 2010 +0000 @@ -0,0 +1,111 @@ +package de.intevation.gnv.state.profile.horizontal; + +import de.intevation.artifacts.CallContext; + +import de.intevation.gnv.artifacts.cache.CacheFactory; + +import de.intevation.gnv.chart.Chart; +import de.intevation.gnv.chart.ChartLabels; +import de.intevation.gnv.chart.HorizontalProfileVectorChart; + +import de.intevation.gnv.geobackend.base.Result; + +import de.intevation.gnv.utils.VectorDataProcessor; + +import java.util.Collection; +import java.util.Locale; + +import net.sf.ehcache.Cache; + +import org.apache.log4j.Logger; + +import org.jfree.chart.ChartTheme; + + +/** + * @author Ingo Weinzierl + */ +public class HorizontalProfileMeshVectorOutputState +extends HorizontalProfileMeshOutputState +{ + private static Logger logger = + Logger.getLogger(HorizontalProfileMeshVectorOutputState.class); + + public static final String[] RESULT_COLUMNS = { + "YORDINATE", "SHAPE", + "GROUP1", "GROUP2", "GROUP3", + "IPOSITION", "JPOSITION", + "DATAID", "MESHID", + "SERIES" + }; + + + @Override + protected Object getChartResult(String uuid, CallContext callContext) { + logger.debug("Fetch data for horizontalprofile chart with vector data"); + CacheFactory factory = CacheFactory.getInstance(); + + if (factory.isInitialized()) { + // we use a cache + logger.info("Using cache."); + Cache cache = factory.getCache(); + String key = "chart_" + getHash(); + + net.sf.ehcache.Element value = cache.get(key); + if (value != null) { + logger.debug("Found element in cache."); + return value.getObjectValue(); + } + else { + logger.debug("Element not in cache, we ask the database"); + Collection res = (Collection)getData(queryID); + res = VectorDataProcessor.process(res, RESULT_COLUMNS); + logger.debug("Got " + res.size() + " elements from database."); + + cache.put(new net.sf.ehcache.Element(key, res)); + + return res; + } + } + else { + // we don't use a cache, so we have to query the database every + // single time + logger.info("Not using a cache."); + return VectorDataProcessor.process( + getData(queryID), RESULT_COLUMNS); + } + } + + + @Override + protected Chart getChart( + ChartLabels chartLables, + ChartTheme theme, + Collection parameters, + Collection measurements, + Collection dates, + Object result, + Locale locale, + String uuid, + boolean linesVisible, + boolean shapesVisible, + CallContext callContext + ) { + Chart chart = new HorizontalProfileVectorChart( + chartLables, + theme, + parameters, + measurements, + dates, + (Collection)result, + timeGapDefinitions, + locale, + linesVisible, + shapesVisible + ); + chart.generateChart(); + + return chart; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :