# HG changeset patch # User Andre Heinecke # Date 1379681744 -7200 # Node ID 726d998dce295a1d21440eeb9a259dde307d26e0 # Parent eb24d5203d17b9340527adb78d74ba8fbfbf2578 Remove Axis Walker, unabstract Diagram generator Diagram generator can now be used as an instance configured in the out-generators config diff -r eb24d5203d17 -r 726d998dce29 artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java --- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java Fri Sep 20 14:54:26 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java Fri Sep 20 14:55:44 2013 +0200 @@ -126,16 +126,7 @@ /** List of annotations to insert in plot. */ protected List annotations = new ArrayList(); - /** - * A mini interface that allows to walk over the YAXIS enums defined in - * subclasses. - */ - public interface YAxisWalker { - - int length(); - - String getId(int idx); - } // end of YAxisWalker interface + protected abstract List buildYAxisSections(); /** * Default constructor that initializes internal data structures. @@ -169,8 +160,6 @@ boolean visible); - protected abstract YAxisWalker getYAxisWalker(); - protected abstract Series getSeriesOf(XYDataset dataset, int idx); @@ -181,6 +170,13 @@ */ protected abstract String getDefaultChartTitle(); + /** + * Returns the default Y-Axis label of a chart. + * + * @return the default Y-Axis label of a chart. + */ + protected abstract String getDefaultYAxisLabel(int index); + /** * Returns the default X-Axis label of a chart. @@ -189,18 +185,6 @@ */ protected abstract String getDefaultXAxisLabel(); - - /** - * This method is called to retrieve the default label for an Y axis at - * position pos. - * - * @param pos The position of an Y axis. - * - * @return the default Y axis label at position pos. - */ - protected abstract String getDefaultYAxisLabel(int pos); - - /** * This method is used to create new AxisDataset instances which may differ * in concrete subclasses. @@ -481,38 +465,6 @@ /** - * Creates a list of Section for the chart's Y axes. This method makes use - * of getYAxisWalker to be able to access all Y axes defined in - * subclasses. - * - * @return a list of Y axis sections. - */ - protected List buildYAxisSections() { - List axisSections = new ArrayList(); - - YAxisWalker walker = getYAxisWalker(); - for (int i = 0, n = walker.length(); i < n; i++) { - AxisSection ySection = new AxisSection(); - ySection.setIdentifier(walker.getId(i)); - ySection.setLabel(getYAxisLabel(i)); - ySection.setFontSize(14); - ySection.setFixed(false); - - // XXX We are able to find better default ranges that [0,0], the - // only problem is, that we do NOT have a better range than [0,0] - // for each axis, because the initial chart will not have a dataset - // for each axis set! - ySection.setUpperRange(0d); - ySection.setLowerRange(0d); - - axisSections.add(ySection); - } - - return axisSections; - } - - - /** * Returns the settings as ChartSettings. * * @return the settings as ChartSettings or null, if @@ -804,6 +756,10 @@ return fontSize != null ? fontSize : DEFAULT_FONT_SIZE; } + /** + * Glue between axis names and index. + */ + protected abstract String axisIndexToName(int index); /** * This method returns the font size for an Y axis. If the font size is @@ -812,15 +768,13 @@ * * @return the font size for the x axis. */ - protected int getYAxisFontSize(int pos) { + protected int getYAxisFontSize(int index) { ChartSettings chartSettings = getChartSettings(); if (chartSettings == null) { return DEFAULT_FONT_SIZE; } - YAxisWalker walker = getYAxisWalker(); - - AxisSection as = chartSettings.getAxisSection(walker.getId(pos)); + AxisSection as = chartSettings.getAxisSection(axisIndexToName(index)); if (as == null) { return DEFAULT_FONT_SIZE; } @@ -829,7 +783,6 @@ return fontSize != null ? fontSize : DEFAULT_FONT_SIZE; } - /** * This method returns the export dimension specified in ChartSettings as * int array [width,height]. @@ -860,6 +813,8 @@ * @return the Y-Axis label of a chart at position 0. */ protected String getYAxisLabel(int pos) { + return "TODO lalal"; + /* ChartSettings chartSettings = getChartSettings(); if (chartSettings == null) { return getDefaultYAxisLabel(pos); @@ -875,7 +830,7 @@ } } - return getDefaultYAxisLabel(pos); + return getDefaultYAxisLabel(pos);*/ } @@ -1417,9 +1372,7 @@ * @return an instance of IdentifiableNumberAxis. */ protected NumberAxis createNumberAxis(int idx, String label) { - YAxisWalker walker = getYAxisWalker(); - - return new IdentifiableNumberAxis(walker.getId(idx), label); + return new IdentifiableNumberAxis(axisIndexToName(idx), label); } @@ -1428,7 +1381,6 @@ * Shall be overriden by subclasses. */ protected NumberAxis createYAxis(int index) { - YAxisWalker walker = getYAxisWalker(); Font labelFont = new Font( DEFAULT_FONT_NAME, @@ -1436,7 +1388,7 @@ getYAxisFontSize(index)); IdentifiableNumberAxis axis = new IdentifiableNumberAxis( - walker.getId(index), + axisIndexToName(index), getYAxisLabel(index)); axis.setAutoRangeIncludesZero(false); diff -r eb24d5203d17 -r 726d998dce29 artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java --- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java Fri Sep 20 14:54:26 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java Fri Sep 20 14:55:44 2013 +0200 @@ -284,5 +284,13 @@ } return -1; } + + public String getAxisName(int index) { + AxisAttributes att = axesAttrs.get(index); + if (att == null) { + return ""; /* null? */ + } + return att.getName(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r eb24d5203d17 -r 726d998dce29 artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java --- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java Fri Sep 20 14:54:26 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java Fri Sep 20 14:55:44 2013 +0200 @@ -41,6 +41,7 @@ import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.artifactdatabase.state.Facet; +import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.exports.process.Processor; import org.dive4elements.river.jfree.AxisDataset; import org.dive4elements.river.jfree.AnnotationHelper; @@ -71,11 +72,7 @@ *
  • There should always be a Y-Axis on the "left".
  • * */ -public abstract class DiagramGenerator extends ChartGenerator2 { - - /** Enumerator over existing axes. */ - @Override - protected abstract YAxisWalker getYAxisWalker(); +public class DiagramGenerator extends ChartGenerator2 { public static final int AXIS_SPACE = 5; @@ -110,7 +107,6 @@ diagramAttributes = new DiagramAttributes(config); } - /** * Generate the chart anew (including localized axis and all). */ @@ -375,6 +371,15 @@ logger.debug("..............."); } + /** + * Registers an area to be drawn. + * @param area Area to be drawn. + * @param axisName Name of the axis. + * @param visible Whether or not to be visible (important for range calculations). + */ + public void addAreaSeries(StyledAreaSeriesCollection area, String axisName, boolean visible) { + addAreaSeries(area, diagramAttributes.getAxisIndex(axisName), visible); + } /** * Registers an area to be drawn. @@ -399,13 +404,12 @@ } } - /** * Add given series if visible, if not visible adjust ranges (such that * all points in data would be plotted once visible). - * @param series the data series to include in plot. - * @param index ('symbolic') index of the series and of its axis. - * @param visible whether or not the data should be plotted. + * @param series the data series to include in plot. + * @param index index of the axis. + * @param visible whether or not the data should be plotted. */ public void addAxisSeries(XYSeries series, int index, boolean visible) { if (series == null) { @@ -416,8 +420,17 @@ series.getMinY() + " | " + series.getMaxY()); addAxisDataset(new XYSeriesCollection(series), index, visible); + } - AxisDataset axisDataset = (AxisDataset) getAxisDataset(index); + /** + * Add given series if visible, if not visible adjust ranges (such that + * all points in data would be plotted once visible). + * @param series the data series to include in plot. + * @param axisName name of the axis. + * @param visible whether or not the data should be plotted. + */ + public void addAxisSeries(XYSeries series, String axisName, boolean visible) { + addAxisSeries(series, diagramAttributes.getAxisIndex(axisName), visible); } @@ -981,6 +994,93 @@ this.inverted = inverted; } + @Override + public String getDefaultChartTitle() { + DiagramAttributes.Title dTitle = diagramAttributes.getTitle(); + if (dTitle == null) { + return "Title not configured in conf.xml"; + } + + return dTitle.evaluate((D4EArtifact)getMaster(), context); + } + + @Override + public String getDefaultChartSubtitle() { + DiagramAttributes.Title dTitle = diagramAttributes.getSubtitle(); + if (dTitle == null) { + return "Subtitle not configured in conf.xml"; + } + + return dTitle.evaluate((D4EArtifact)getMaster(), context); + } + + /** + * Get internationalized label for the x axis. + */ + @Override + protected String getDefaultXAxisLabel() { + return "TODO X axis label"; +/* D4EArtifact flys = (D4EArtifact) master; + + return msg( + I18N_XAXIS_LABEL, + I18N_XAXIS_LABEL_DEFAULT, + new Object[] { RiverUtils.getRiver(flys).getName() }); */ + } + + @Override + protected String getDefaultYAxisLabel(int index) { + return "TODO Y Axis label"; +/* String label = "default"; + + if (index == YAXIS.W.idx) { + label = getWAxisLabel(); + } + else if (index == YAXIS.Q.idx) { + label = msg(getQAxisLabelKey(), getQAxisDefaultLabel()); + } + else if (index == YAXIS.D.idx) { + label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT); + } + + return label;*/ + } + + + /** + * Creates a list of Section for the chart's Y axes. + * + * @return a list of Y axis sections. + */ + protected List buildYAxisSections() { + List axisSections = new ArrayList(); + + List axesAttrs = diagramAttributes.getAxesAttributes(); + + for (int i = 0, n = axesAttrs.size(); i < n; i++) { + AxisSection ySection = new AxisSection(); + ySection.setIdentifier(diagramAttributes.getAxisName(i)); + ySection.setLabel(getYAxisLabel(i)); + ySection.setFontSize(14); + ySection.setFixed(false); + + // XXX We are able to find better default ranges that [0,0], the + // only problem is, that we do NOT have a better range than [0,0] + // for each axis, because the initial chart will not have a dataset + // for each axis set! + ySection.setUpperRange(0d); + ySection.setLowerRange(0d); + + axisSections.add(ySection); + } + + return axisSections; + } + + protected String axisIndexToName(int index) { + return diagramAttributes.getAxisName(index); + } + /** Add the acutal data to the diagram according to the processors. * For every outable facets, this function is * called and handles the data accordingly. */ @@ -1004,7 +1104,7 @@ for (Processor pr: diagramAttributes.getProcessors()) { if (pr.canHandle(facetName)) { -// pr.doOut(this, bundle, theme, visible, 0); + pr.doOut(this, bundle, theme, visible); } } }