Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 2051:4ba5036109d2
Make use of user defined axes labels during chart creation.
flys-artifacts/trunk@3541 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 27 Dec 2011 07:52:25 +0000 |
parents | c4e0e433f825 |
children | c7f18fa0d685 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Tue Dec 27 07:17:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Tue Dec 27 07:52:25 2011 +0000 @@ -290,15 +290,31 @@ * * @return the X-Axis label of a chart. */ - protected abstract String getXAxisLabel(); + protected String getXAxisLabel() { + ChartSettings chartSettings = getChartSettings(); + if (chartSettings == null) { + return getDefaultXAxisLabel(); + } + + AxisSection as = chartSettings.getAxisSection("X"); + if (as != null) { + String label = as.getLabel(); + + if (label != null) { + return label; + } + } + + return getDefaultXAxisLabel(); + } /** - * Returns the Y-Axis label of a chart. + * Returns the default X-Axis label of a chart. * - * @return the Y-Axis label of a chart. + * @return the default X-Axis label of a chart. */ - protected abstract String getYAxisLabel(); + protected abstract String getDefaultXAxisLabel(); /** @@ -307,9 +323,36 @@ * @return the Y-Axis label of a chart at position <i>0</i>. */ protected String getYAxisLabel(int pos) { - return getYAxisLabel(); + ChartSettings chartSettings = getChartSettings(); + if (chartSettings == null) { + return getDefaultYAxisLabel(pos); + } + + YAxisWalker walker = getYAxisWalker(); + AxisSection as = chartSettings.getAxisSection(walker.getId(pos)); + if (as != null) { + String label = as.getLabel(); + + if (label != null) { + return label; + } + } + + return getDefaultYAxisLabel(pos); } + + /** + * This method is called to retrieve the default label for an Y axis at + * position <i>pos</i>. + * + * @param pos The position of an Y axis. + * + * @return the default Y axis label at position <i>pos</i>. + */ + protected abstract String getDefaultYAxisLabel(int pos); + + /** * Generate chart. */ @@ -370,7 +413,7 @@ JFreeChart chart = ChartFactory.createXYLineChart( getChartTitle(), getXAxisLabel(), - getYAxisLabel(), + getYAxisLabel(0), null, PlotOrientation.VERTICAL, isLegendVisible(), @@ -586,7 +629,7 @@ * Shall be overriden by subclasses. */ protected NumberAxis createYAxis(int index) { - NumberAxis axis = new NumberAxis(getYAxisLabel()); + NumberAxis axis = new NumberAxis(getYAxisLabel(index)); axis.setAutoRangeIncludesZero(false); return axis; }