Mercurial > dive4elements > river
changeset 2321:991e4a5df323
Enabled styling in timeseries charts.
flys-artifacts/trunk@4003 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 09 Feb 2012 14:27:47 +0000 |
parents | bb04f958b7aa |
children | c0eafd430244 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/jfree/Style.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledSeries.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledTimeSeries.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledXYSeries.java flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java |
diffstat | 8 files changed, 245 insertions(+), 114 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Feb 09 14:26:03 2012 +0000 +++ b/flys-artifacts/ChangeLog Thu Feb 09 14:27:47 2012 +0000 @@ -1,3 +1,31 @@ +2012-02-09 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/jfree/Style.java: New. A Style object + needs to implements a method applyTheme() which takes a + XYLineAndShapeRenderer. + + * src/main/java/de/intevation/flys/jfree/XYStyle.java: New. This subclass of + Style modifies the XYLineAndShapeRenderer specified in applyTheme(). + + * src/main/java/de/intevation/flys/jfree/StyledSeries.java: New. This + interface defines two methods getStyle() and setStyle() to adjust and + retrieve the Style of a series. + + * src/main/java/de/intevation/flys/jfree/StyledTimeSeries.java: New. + Implementation of StyledSeries that subclasses JFreeChart's TimeSeries. + + * src/main/java/de/intevation/flys/jfree/StyledXYSeries.java: Removed the + code for adapting a XYLineAndShapeRenderer. Instead of implementing this + stuff in StyledXYSeries itself, this instance now implements StyledSeries + and stores an instance of XYStyle. + + * src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java: + Create new instances of StyledTimeSeries now which enables styling in this + chart. + + * src/main/java/de/intevation/flys/exports/ChartGenerator.java: Enabled + styling of series for all series that implement StyledSeries. + 2012-02-09 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java(relateWs):
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Thu Feb 09 14:26:03 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Thu Feb 09 14:27:47 2012 +0000 @@ -52,7 +52,8 @@ import de.intevation.flys.jfree.EnhancedLineAndShapeRenderer; import de.intevation.flys.jfree.StableXYDifferenceRenderer; import de.intevation.flys.jfree.StyledAreaSeriesCollection; -import de.intevation.flys.jfree.StyledXYSeries; +import de.intevation.flys.jfree.Style; +import de.intevation.flys.jfree.StyledSeries; import de.intevation.flys.utils.FLYSUtils; import de.intevation.flys.utils.ThemeAccess; @@ -1177,6 +1178,8 @@ * @param idx The index of the renderer / dataset. */ protected void applyLineTheme(XYPlot plot, XYDataset dataset, int idx) { + logger.debug("Apply LineTheme for dataset at index: " + idx); + LegendItemCollection lic = new LegendItemCollection(); LegendItemCollection anno = plot.getFixedLegendItems(); @@ -1187,8 +1190,9 @@ for (int s = 0, num = dataset.getSeriesCount(); s < num; s++) { Series series = getSeriesOf(dataset, s); - if (series instanceof StyledXYSeries) { - ((StyledXYSeries) series).applyTheme(renderer, s); + if (series instanceof StyledSeries) { + Style style = ((StyledSeries) series).getStyle(); + style.applyTheme(renderer, s); } // special case: if there is just one single item, we need to enable
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java Thu Feb 09 14:26:03 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java Thu Feb 09 14:27:47 2012 +0000 @@ -24,6 +24,7 @@ import de.intevation.flys.artifacts.model.HistoricalWQTimerange; import de.intevation.flys.artifacts.model.Timerange; import de.intevation.flys.artifacts.model.WQTimerange; +import de.intevation.flys.jfree.StyledTimeSeries; import de.intevation.flys.utils.FLYSUtils; @@ -199,6 +200,7 @@ TimeSeriesCollection tsc = newTimeSeriesCollection( wqt.getTimeranges(), wqt.getQs(), + theme, desc); addAxisDataset(tsc, 0, visible); @@ -219,6 +221,7 @@ TimeSeriesCollection tsc = newTimeSeriesCollection( wqt.getTimeranges(), wqt.getDiffs(), + theme, desc); addAxisDataset(tsc, 0, visible); @@ -234,12 +237,13 @@ protected TimeSeriesCollection newTimeSeriesCollection( Timerange[] timeranges, double[] values, + Document theme, String desc ) { logger.debug("Create new TimeSeriesCollection for: " + desc); TimeSeriesCollection tsc = new TimeSeriesCollection(); - TimeSeries series = new TimeSeries(desc); + TimeSeries series = new StyledTimeSeries(desc, theme); for (int i = 0, n = timeranges.length; i < n; i++) { RegularTimePeriod[] rtp = newRegularTimePeriod(timeranges[i]);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/Style.java Thu Feb 09 14:27:47 2012 +0000 @@ -0,0 +1,13 @@ +package de.intevation.flys.jfree; + +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface Style { + + XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledSeries.java Thu Feb 09 14:27:47 2012 +0000 @@ -0,0 +1,13 @@ +package de.intevation.flys.jfree; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface StyledSeries { + + void setStyle(Style style); + + Style getStyle(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledTimeSeries.java Thu Feb 09 14:27:47 2012 +0000 @@ -0,0 +1,39 @@ +package de.intevation.flys.jfree; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; + +import org.jfree.data.time.TimeSeries; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class StyledTimeSeries extends TimeSeries implements StyledSeries { + + private static final Logger logger = + Logger.getLogger(StyledTimeSeries.class); + + + protected Style style; + + + public StyledTimeSeries(String key, Document theme) { + super(key); + setStyle(new XYStyle(theme)); + } + + + @Override + public void setStyle(Style style) { + this.style = style; + } + + + @Override + public Style getStyle() { + return style; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledXYSeries.java Thu Feb 09 14:26:03 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledXYSeries.java Thu Feb 09 14:27:47 2012 +0000 @@ -1,31 +1,22 @@ package de.intevation.flys.jfree; -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.geom.Ellipse2D; import org.apache.log4j.Logger; import org.w3c.dom.Document; -import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.jfree.data.xy.XYSeries; -import de.intevation.flys.utils.ThemeUtil; /** - * Dataseries in two dimensions with additional theme-document and further - * display options. - * The theme-document will later "style" the graphical representation. - * The display options can be used to control the z-order and the axis of the - * dataseries. + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ -public class StyledXYSeries extends XYSeries { - - protected Document theme; +public class StyledXYSeries extends XYSeries implements StyledSeries { private static final Logger logger = Logger.getLogger(StyledXYSeries.class); + protected Style style; + public StyledXYSeries(String key, Document theme) { this(key, true, theme); @@ -39,109 +30,19 @@ */ public StyledXYSeries(String key, boolean sorted, Document theme) { super(key, sorted); - this.theme = theme; - } - - - /** - * Applies line color, size and type attributes to renderer, also - * whether to draw lines and/or points. - */ - public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){ - applyLineColor(r, idx); - applyLineSize(r, idx); - applyLineType(r, idx); - applyShowLine(r, idx); - applyShowPoints(r, idx); - applyPointSize(r, idx); - applyShowMinimum(r, idx); - applyShowMaximum(r, idx); - - return r; - } - - - /** Set line color to renderer. */ - protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { - Color c = ThemeUtil.parseLineColorField(theme); - r.setSeriesPaint(idx, c); - } - - - protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { - int size = ThemeUtil.parseLineWidth(theme); - r.setSeriesStroke( - idx, - new BasicStroke(Integer.valueOf(size))); + setStyle(new XYStyle(theme)); } - protected void applyLineType(XYLineAndShapeRenderer r, int idx) { - int size = ThemeUtil.parseLineWidth(theme); - float[] dashes = ThemeUtil.parseLineStyle(theme); - - // Do not apply the dashed style. - if (dashes.length <= 1) { - return; - } - - r.setSeriesStroke( - idx, - new BasicStroke(Integer.valueOf(size), - BasicStroke.CAP_BUTT, - BasicStroke.JOIN_ROUND, - 1.0f, - dashes, - 0.0f)); - } - - - protected void applyPointSize(XYLineAndShapeRenderer r, int idx) { - int size = ThemeUtil.parsePointWidth(theme); - int dim = 2 * size; - - r.setSeriesShape(idx, new Ellipse2D.Double(-size, -size, dim, dim)); + @Override + public void setStyle(Style style) { + this.style = style; } - /** - * Sets form and visibility of points. - */ - protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) { - boolean show = ThemeUtil.parseShowPoints(theme); - - r.setSeriesShapesVisible(idx, show); - r.setDrawOutlines(true); - } - - - protected void applyShowLine(XYLineAndShapeRenderer r, int idx) { - boolean show = ThemeUtil.parseShowLine(theme); - r.setSeriesLinesVisible(idx, show); - } - - - protected void applyShowMinimum(XYLineAndShapeRenderer r, int idx) { - if (!(r instanceof EnhancedLineAndShapeRenderer)) { - return; - } - - boolean visible = ThemeUtil.parseShowMinimum(theme); - - EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r; - er.setIsMinimumShapeVisisble(idx, visible); - } - - - protected void applyShowMaximum(XYLineAndShapeRenderer r, int idx) { - if (!(r instanceof EnhancedLineAndShapeRenderer)) { - return; - } - - boolean visible = ThemeUtil.parseShowMaximum(theme); - - EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r; - er.setIsMaximumShapeVisible(idx, visible); + @Override + public Style getStyle() { + return style; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java Thu Feb 09 14:27:47 2012 +0000 @@ -0,0 +1,129 @@ +package de.intevation.flys.jfree; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.geom.Ellipse2D; + + +import org.w3c.dom.Document; + +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; + +import de.intevation.flys.utils.ThemeUtil; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class XYStyle implements Style { + + protected Document theme; + + + public XYStyle(Document theme) { + this.theme = theme; + } + + + /** + * Applies line color, size and type attributes to renderer, also + * whether to draw lines and/or points. + */ + public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){ + applyLineColor(r, idx); + applyLineSize(r, idx); + applyLineType(r, idx); + applyShowLine(r, idx); + applyShowPoints(r, idx); + applyPointSize(r, idx); + applyShowMinimum(r, idx); + applyShowMaximum(r, idx); + + return r; + } + + + /** Set line color to renderer. */ + protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { + Color c = ThemeUtil.parseLineColorField(theme); + r.setSeriesPaint(idx, c); + } + + + protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { + int size = ThemeUtil.parseLineWidth(theme); + r.setSeriesStroke( + idx, + new BasicStroke(Integer.valueOf(size))); + } + + + protected void applyLineType(XYLineAndShapeRenderer r, int idx) { + int size = ThemeUtil.parseLineWidth(theme); + float[] dashes = ThemeUtil.parseLineStyle(theme); + + // Do not apply the dashed style. + if (dashes.length <= 1) { + return; + } + + r.setSeriesStroke( + idx, + new BasicStroke(Integer.valueOf(size), + BasicStroke.CAP_BUTT, + BasicStroke.JOIN_ROUND, + 1.0f, + dashes, + 0.0f)); + } + + + protected void applyPointSize(XYLineAndShapeRenderer r, int idx) { + int size = ThemeUtil.parsePointWidth(theme); + int dim = 2 * size; + + r.setSeriesShape(idx, new Ellipse2D.Double(-size, -size, dim, dim)); + } + + + /** + * Sets form and visibility of points. + */ + protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) { + boolean show = ThemeUtil.parseShowPoints(theme); + + r.setSeriesShapesVisible(idx, show); + r.setDrawOutlines(true); + } + + + protected void applyShowLine(XYLineAndShapeRenderer r, int idx) { + boolean show = ThemeUtil.parseShowLine(theme); + r.setSeriesLinesVisible(idx, show); + } + + + protected void applyShowMinimum(XYLineAndShapeRenderer r, int idx) { + if (!(r instanceof EnhancedLineAndShapeRenderer)) { + return; + } + + boolean visible = ThemeUtil.parseShowMinimum(theme); + + EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r; + er.setIsMinimumShapeVisisble(idx, visible); + } + + + protected void applyShowMaximum(XYLineAndShapeRenderer r, int idx) { + if (!(r instanceof EnhancedLineAndShapeRenderer)) { + return; + } + + boolean visible = ThemeUtil.parseShowMaximum(theme); + + EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r; + er.setIsMaximumShapeVisible(idx, visible); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :