Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java @ 9123:1cc7653ca84f
Cleanup of ChartGenerator and ChartGenerator2 code. Put some of the copy/pasted code into a common abstraction.
author | gernotbelger |
---|---|
date | Tue, 05 Jun 2018 19:21:16 +0200 |
parents | 07d51fd4864c |
children | 55e2155ab52d |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java Tue Jun 05 19:10:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java Tue Jun 05 19:21:16 2018 +0200 @@ -10,9 +10,7 @@ import java.awt.Color; import java.awt.Font; - import java.text.NumberFormat; - import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -21,62 +19,43 @@ import java.util.List; import java.util.Map; import java.util.Set; - +import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.regex.Matcher; - -import java.io.OutputStream; import javax.swing.ImageIcon; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; - import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.artifactdatabase.state.Facet; - import org.dive4elements.artifacts.CallContext; - import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.exports.DiagramAttributes.AxisAttributes; import org.dive4elements.river.exports.process.Processor; - -import org.dive4elements.river.jfree.RiverAnnotation; -import org.dive4elements.river.jfree.AnnotationHelper; import org.dive4elements.river.jfree.AxisDataset; import org.dive4elements.river.jfree.Bounds; import org.dive4elements.river.jfree.DoubleBounds; +import org.dive4elements.river.jfree.RiverAnnotation; import org.dive4elements.river.jfree.StyledAreaSeriesCollection; import org.dive4elements.river.jfree.XYMetaSeriesCollection; - import org.dive4elements.river.themes.ThemeDocument; - import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.LegendItem; - import org.jfree.chart.annotations.XYAnnotation; import org.jfree.chart.annotations.XYImageAnnotation; - import org.jfree.chart.axis.LogarithmicAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; - import org.jfree.chart.plot.Marker; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; - import org.jfree.data.Range; - import org.jfree.data.general.Series; - import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; -import org.w3c.dom.Document; - -import org.apache.commons.lang.StringUtils; - /** * The main diagram creation class. @@ -102,9 +81,9 @@ /** The log that is used in this generator. */ private static Logger log = Logger.getLogger(DiagramGenerator.class); - protected List<Marker> domainMarkers = new ArrayList<Marker>(); + protected List<Marker> domainMarkers = new ArrayList<>(); - protected List<Marker> valueMarkers = new ArrayList<Marker>(); + protected List<Marker> valueMarkers = new ArrayList<>(); /** The max X range to include all X values of all series for each axis. */ protected Map<Integer, Bounds> xBounds; @@ -144,17 +123,7 @@ diagramAttributes = da.new Instance(); } - @Override - public void init( - String outName, - Document request, - OutputStream out, - CallContext context - ) { - super.init(outName, request, out, context); - } - - private void setInvertedFromConfig() { + private void setInvertedFromConfig(CallContext context) { DiagramAttributes.DomainAxisAttributes dx = diagramAttributes.getDomainAxis(); @@ -175,13 +144,13 @@ * Generate the chart anew (including localized axis and all). */ @Override - public JFreeChart generateChart() { + protected JFreeChart generateChart(CallContext context) { log.debug("DiagramGenerator.generateChart"); postProcess(); JFreeChart chart = ChartFactory.createXYLineChart( - getChartTitle(), + getChartTitle(context), "", "", null, @@ -191,13 +160,13 @@ false); XYPlot plot = (XYPlot) chart.getPlot(); - ValueAxis axis = createXAxis(getXAxisLabel()); + ValueAxis axis = createXAxis(context, getXAxisLabel()); plot.setDomainAxis(axis); chart.setBackgroundPaint(Color.WHITE); plot.setBackgroundPaint(Color.WHITE); - addSubtitles(chart); - addMetadataSubtitle(chart); + addSubtitles(context, chart); + addMetadataSubtitle(context, chart); adjustPlot(plot); //debugAxis(plot); @@ -215,7 +184,7 @@ localizeAxes(plot); - setInvertedFromConfig(); + setInvertedFromConfig(context); adjustAxes(plot); if (!(axis instanceof LogarithmicAxis)) { @@ -230,10 +199,8 @@ //debugAxis(plot); // These have to go after the autozoom. - AnnotationHelper.addAnnotationsToRenderer(annotations, plot, - getChartSettings(), datasets); - AnnotationHelper.addYAnnotationsToRenderer(yAnnotations, plot, - getChartSettings(), datasets); + addAnnotationsToRenderer(plot); + addYAnnotationsToRenderer(plot); // Add a logo (maybe). addLogo(plot); @@ -249,10 +216,6 @@ return chart; } - public String getOutName() { - return outName; - } - /** * Return left most data points x value (on first axis). */ @@ -393,7 +356,7 @@ } - protected NumberAxis createXAxis(String label) { + protected NumberAxis createXAxis(final CallContext context, String label) { boolean logarithmic = (Boolean)diagramAttributes.getDomainAxis(). isLog().evaluate((D4EArtifact)getMaster(), context); @@ -1113,7 +1076,7 @@ } @Override - public String getDefaultChartTitle() { + protected final String getDefaultChartTitle(CallContext context) { DiagramAttributes.Title dTitle = diagramAttributes.getTitle(); if (dTitle == null) { return "Title not configured in conf.xml"; @@ -1122,8 +1085,9 @@ return dTitle.evaluate((D4EArtifact)getMaster(), context); } + @Override - public String getDefaultChartSubtitle() { + protected String getDefaultChartSubtitle(CallContext context) { String parts = ""; DiagramAttributes.Title dTitle = diagramAttributes.getSubtitle(); if (dTitle == null && @@ -1154,7 +1118,7 @@ * Get internationalized label for the x axis. */ @Override - protected String getDefaultXAxisLabel() { + protected String getDefaultXAxisLabel(CallContext context) { DiagramAttributes.DomainAxisAttributes dx = diagramAttributes.getDomainAxis(); @@ -1167,8 +1131,7 @@ return "Domain Axis Title not configured in conf.xml"; } - @Override - protected String getDefaultYAxisLabel(String axisName) { + protected final String getDefaultYAxisLabel(String axisName) { Set labelSet = axesLabels.get(diagramAttributes.getAxisIndex(axisName)); log.debug("Labels for axis: " + labelSet); if (labelSet != null && !labelSet.isEmpty()) { @@ -1198,8 +1161,9 @@ * * @return a list of Y axis sections. */ - protected List<AxisSection> buildYAxisSections() { - List<AxisSection> axisSections = new ArrayList<AxisSection>(); + @Override + protected final List<AxisSection> buildYAxisSections() { + List<AxisSection> axisSections = new ArrayList<>(); List<DiagramAttributes.AxisAttributes> axesAttrs = diagramAttributes.getAxesAttributes(); @@ -1315,7 +1279,7 @@ final AxisAttributes axisAttributes = diagramAttributes.getAxesAttributes().get(index); - boolean logarithmic = (Boolean)axisAttributes.isLog().evaluate((D4EArtifact)getMaster(), context); + boolean logarithmic = (Boolean)axisAttributes.isLog().evaluate((D4EArtifact)getMaster(), getContext()); NumberAxis axis; if (logarithmic) { @@ -1347,4 +1311,4 @@ public void addSubtitle(String part) { this.subTitleParts.add(part); } -} +} \ No newline at end of file