Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 2000:e71719483546
Improved the ChartSettings - now, each chart writes proper AxisSections into the ChartSettings.
flys-artifacts/trunk@3441 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 16 Dec 2011 13:37:58 +0000 |
parents | 210020108ca4 |
children | 79b15491177a |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Fri Dec 16 11:47:57 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Fri Dec 16 13:37:58 2011 +0000 @@ -112,6 +112,31 @@ } + /** + * A mini interface that allows to walk over the YAXIS enums defined in + * subclasses. + */ + public interface YAxisWalker { + int length(); + String getId(int idx); + } + + + protected YAxisWalker getYAxisWalker() { + return new YAxisWalker() { + @Override + public int length() { + return 0; + } + + @Override + public String getId(int idx) { + return null; + } + }; + } + + /** The logger that is used in this generator. */ private static Logger logger = Logger.getLogger(XYChartGenerator.class); @@ -206,6 +231,16 @@ */ protected abstract String getYAxisLabel(); + + /** + * Returns the Y-Axis label of a chart at position <i>pos</i>. + * + * @return the Y-Axis label of a chart at position <i>0</i>. + */ + protected String getYAxisLabel(int pos) { + return getYAxisLabel(); + } + /** * Generate chart. */ @@ -922,13 +957,27 @@ /** - * Creates new Sections for chart axes. Subclasses of this ChartGenerator - * should override this method to include all necessary Y axes in that - * concrete chart. The only Section contained in the list is the X axis. + * Creates a list of Sections that contains all axes of the chart (including + * X and Y axes). + * + * @return a list of Sections for each axis in this chart. + */ + protected List<Section> buildAxisSections() { + List<Section> axisSections = new ArrayList<Section>(); + + axisSections.addAll(buildXAxisSections()); + axisSections.addAll(buildYAxisSections()); + + return axisSections; + } + + + /** + * Creates a new Section for chart's X axis. * * @return a List that contains a Section for the X axis. */ - protected List<Section> buildAxisSections() { + protected List<Section> buildXAxisSections() { List<Section> axisSections = new ArrayList<Section>(); String identifier = "X"; @@ -948,5 +997,37 @@ return axisSections; } + + + /** + * Creates a list of Section for the chart's Y axes. This method makes use + * of <i>getYAxisWalker</i> to be able to access all Y axes defined in + * subclasses. + * + * @return a list of Y axis sections. + */ + protected List<Section> buildYAxisSections() { + List<Section> axisSections = new ArrayList<Section>(); + + 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; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :