Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java @ 3242:1dca41dba135
Move annotation code to base class ChartGenerator
flys-artifacts/trunk@4874 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Wed, 04 Jul 2012 22:28:44 +0000 |
parents | b0eee4c1eaa0 |
children | c27c4e06dd87 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java Wed Jul 04 06:54:39 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java Wed Jul 04 22:28:44 2012 +0000 @@ -1,25 +1,8 @@ package de.intevation.flys.exports; -import de.intevation.artifactdatabase.state.ArtifactAndFacet; -import de.intevation.artifactdatabase.state.Facet; - -import de.intevation.flys.jfree.Bounds; -import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation; -import de.intevation.flys.jfree.DoubleBounds; -import de.intevation.flys.jfree.FLYSAnnotation; -import de.intevation.flys.jfree.StyledTimeSeries; -import de.intevation.flys.jfree.TimeBounds; - -import de.intevation.flys.themes.ThemeAccess; - -import de.intevation.flys.artifacts.model.HYKFactory; - -import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Paint; -import java.awt.Stroke; - import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -27,37 +10,31 @@ import java.util.Map; import org.apache.log4j.Logger; - import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; -import org.jfree.chart.LegendItemCollection; - -import org.jfree.chart.annotations.XYBoxAnnotation; import org.jfree.chart.annotations.XYTextAnnotation; - import org.jfree.chart.axis.ValueAxis; - import org.jfree.chart.plot.Marker; import org.jfree.chart.plot.XYPlot; - import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; - import org.jfree.data.Range; - import org.jfree.data.general.Series; - import org.jfree.data.time.Day; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; - import org.jfree.data.xy.XYDataset; - import org.jfree.ui.Layer; - import org.json.JSONArray; import org.json.JSONException; +import org.w3c.dom.Document; -import org.w3c.dom.Document; +import de.intevation.artifactdatabase.state.ArtifactAndFacet; +import de.intevation.flys.jfree.Bounds; +import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation; +import de.intevation.flys.jfree.DoubleBounds; +import de.intevation.flys.jfree.FLYSAnnotation; +import de.intevation.flys.jfree.StyledTimeSeries; +import de.intevation.flys.jfree.TimeBounds; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> @@ -183,10 +160,6 @@ } // end of TimeseriesAxisDataset class - - /** List of annotations to insert in plot. */ - protected List<FLYSAnnotation> annotations; - protected List<Marker> domainMarker; protected List<Marker> valueMarker; @@ -593,213 +566,7 @@ addAxisDataset(tsc, axisIndex, visible); } - /** - * Register annotations like MainValues for later plotting - * - * @param o list of annotations (data of facet). - * @param facet The facet. This facet does NOT support any data objects. Use - * FLYSArtifact.getNativeFacet() instead to retrieve a Facet which supports - * data. - * @param theme Theme document for given annotations. - * @param visible The visibility of the annotations. - */ - protected void doAnnotations( - FLYSAnnotation annotations, - ArtifactAndFacet aandf, - Document theme, - boolean visible - ){ - // Running into trouble here. - logger.debug("doAnnotations"); - - // Add all annotations to our annotation pool. - annotations.setTheme(theme); - if (aandf != null) { - Facet facet = aandf.getFacet(); - annotations.setLabel(aandf.getFacetDescription()); - } - else { - logger.debug( - "Art/Facet for Annotations is null. " + - "This should never happen!"); - } - - addAnnotations(annotations, visible); - } - - - - /** - * Adds annotations to list (if visible is true). - */ - public void addAnnotations(FLYSAnnotation annotation, boolean visible) { - if (!visible) { - return; - } - - if (annotations == null) { - annotations = new ArrayList<FLYSAnnotation>(); - } - - annotations.add(annotation); - } - - - /** Add annotations (Sticky, Text and hyk zones). */ - /* public void addAnnotationsToRenderer(XYPlot plot) { - logger.debug("addAnnotationsToRenderer"); - - if (annotations == null) { - logger.debug("addAnnotationsToRenderer: no annotations."); - return; - } - - // Paints for the boxes/lines. - Stroke basicStroke = new BasicStroke(1.0f); - - Paint linePaint = new Color(255, 0,0,60); - Paint fillPaint = new Color(0, 255,0,60); - Paint tranPaint = new Color(0, 0,0, 0); - - // OPTMIMIZE: Pre-calculate positions - Area area = new Area( - plot.getDomainAxis(0).getRange(), - plot.getRangeAxis().getRange()); - - // Walk over all Annotation sets. - for (FLYSAnnotation fa: annotations) { - - // Access text styling, if any. - Document theme = fa.getTheme(); - ThemeAccess.TextStyle textStyle = null; - ThemeAccess.LineStyle lineStyle = null; - - // Get Themeing information and add legend item. - if (theme != null) { - ThemeAccess themeAccess = new ThemeAccess(theme); - textStyle = themeAccess.parseTextStyle(); - lineStyle = themeAccess.parseLineStyle(); - if (fa.getLabel() != null) { - LegendItemCollection lic = new LegendItemCollection(); - LegendItemCollection old = plot.getFixedLegendItems(); - lic.add(createLegendItem(theme, fa.getLabel())); - // (Re-)Add prior legend entries. - if (old != null) { - old.addAll(lic); - } - else { - old = lic; - } - plot.setFixedLegendItems(old); - } - } - - // Other Text Annotations (e.g. labels of manual points). - for (XYTextAnnotation ta: fa.getTextAnnotations()) { - // Style the text. - if (textStyle != null) { - textStyle.apply(ta); - } - ta.setY(area.above(0.05d, ta.getY())); - plot.getRenderer().addAnnotation(ta, org.jfree.ui.Layer.FOREGROUND); - } - } - }*/ - - /** - * Add the annotations (Sticky, Text and hyk zones) stored - * in the annotations field. - */ - public void addAnnotationsToRenderer(XYPlot plot) { - logger.debug("addAnnotationsToRenderer"); - - if (annotations == null) { - logger.debug("addAnnotationsToRenderer: no annotations."); - return; - } - - // Paints for the boxes/lines. - Stroke basicStroke = new BasicStroke(1.0f); - - Paint linePaint = new Color(255, 0,0,60); - Paint fillPaint = new Color(0, 255,0,60); - Paint tranPaint = new Color(0, 0,0, 0); - - // OPTMIMIZE: Pre-calculate positions - Area area = new Area( - plot.getDomainAxis(0).getRange(), - plot.getRangeAxis().getRange()); - - // Walk over all Annotation sets. - for (FLYSAnnotation fa: annotations) { - - // Access text styling, if any. - Document theme = fa.getTheme(); - ThemeAccess.TextStyle textStyle = null; - ThemeAccess.LineStyle lineStyle = null; - - // Get Themeing information and add legend item. - if (theme != null) { - ThemeAccess themeAccess = new ThemeAccess(theme); - textStyle = themeAccess.parseTextStyle(); - lineStyle = themeAccess.parseLineStyle(); - if (fa.getLabel() != null) { - LegendItemCollection lic = new LegendItemCollection(); - LegendItemCollection old = plot.getFixedLegendItems(); - lic.add(createLegendItem(theme, fa.getLabel())); - // (Re-)Add prior legend entries. - if (old != null) { - old.addAll(lic); - } - else { - old = lic; - } - plot.setFixedLegendItems(old); - } - } - - // The 'Sticky' Annotations (at axis, with line and text). - /* for (StickyAxisAnnotation sta: fa.getAxisTextAnnotations()) { - addStickyAnnotation( - sta, plot, area, lineStyle, textStyle, theme); - }*/ - - // Other Text Annotations (e.g. labels of manual points). - for (XYTextAnnotation ta: fa.getTextAnnotations()) { - // Style the text. - if (textStyle != null) { - textStyle.apply(ta); - } - ta.setY(area.above(0.05d, ta.getY())); - plot.getRenderer().addAnnotation(ta, org.jfree.ui.Layer.FOREGROUND); - } - - // Hyks. - for (HYKFactory.Zone zone: fa.getBoxes()) { - // For each zone, create a box to fill with color, a box to draw - // the lines and a text to display the type. - fillPaint = colorForHYKZone(zone.getName()); - - XYBoxAnnotation boxA = new XYBoxAnnotation(zone.getFrom(), area.atGround(), - zone.getTo(), area.ofGround(0.03f), basicStroke, tranPaint, fillPaint); - XYBoxAnnotation boxB = new XYBoxAnnotation(zone.getFrom(), area.atGround(), - zone.getTo(), area.atTop(), basicStroke, fillPaint, tranPaint); - - XYTextAnnotation tex = new XYTextAnnotation(zone.getName(), - zone.getFrom() + (zone.getTo() - zone.getFrom()) / 1.0d, - area.ofGround(0.015f)); - if (textStyle != null) { - textStyle.apply(tex); - } - - plot.getRenderer().addAnnotation(boxA, org.jfree.ui.Layer.BACKGROUND); - plot.getRenderer().addAnnotation(boxB, org.jfree.ui.Layer.BACKGROUND); - plot.getRenderer().addAnnotation(tex, org.jfree.ui.Layer.BACKGROUND); - } - } - } - - /** Get color for hyk zones by their type (which is the name). */ + /** Get color for hyk zones by their type (which is the name). */ public Paint colorForHYKZone(String zoneName) { if (zoneName.startsWith("R")) { // Brownish.