Mercurial > dive4elements > river
changeset 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 (2011-12-16) |
parents | 02ce03329ef5 |
children | 28a5c163f9cd |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java |
diffstat | 6 files changed, 191 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Dec 16 11:47:57 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Dec 16 13:37:58 2011 +0000 @@ -1,3 +1,21 @@ +2011-12-16 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Defined an + interface YAxisWalker that allows to walk over each Y axis definition in + subclasses. This walker can be retrieved using the new getYAxisWalker() + method. The AxisSections are built in this class now. + + * src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java: + Implemented the YAxisWalker interface and the getYAxisWalker() method. + Removed the code to build AxisSections. + + * src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java: + Implemented getYAxisLabel(int pos) and getYAxisWalker(). + + * src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java, + src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java: + Implemented the getYAxisWalker() method. + 2011-12-16 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java Fri Dec 16 11:47:57 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java Fri Dec 16 13:37:58 2011 +0000 @@ -69,6 +69,23 @@ } + @Override + protected YAxisWalker getYAxisWalker() { + return new YAxisWalker() { + @Override + public int length() { + return YAXIS.values().length; + } + + @Override + public String getId(int idx) { + YAXIS[] yaxes = YAXIS.values(); + return yaxes[idx].toString(); + } + }; + } + + protected String getChartTitle() { return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java Fri Dec 16 11:47:57 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java Fri Dec 16 13:37:58 2011 +0000 @@ -84,15 +84,8 @@ @Override protected NumberAxis createYAxis(int index) { Font labelFont = new Font("Tahoma", Font.BOLD, 14); - String label = "default"; - if (index == YAXIS.W.idx) { - label = getYAxisLabel(); - } - else if (index == YAXIS.Q.idx) { - // TODO i18n for this label - label = "Q [m\u00b3/s]"; - //label = msg(get2YAxisLabelKey(), get2YAxisDefaultLabel()); - } + String label = getYAxisLabel(index); + NumberAxis axis = new NumberAxis(label); if (index == YAXIS.W.idx) { axis.setAutoRangeIncludesZero(false); @@ -126,17 +119,35 @@ } + @Override protected String getXAxisLabel() { return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); } + @Override protected String getYAxisLabel() { return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); } @Override + protected String getYAxisLabel(int index) { + String label = "default"; + if (index == YAXIS.W.idx) { + label = getYAxisLabel(); + } + else if (index == YAXIS.Q.idx) { + // TODO i18n for this label + label = "Q [m\u00b3/s]"; + //label = msg(get2YAxisLabelKey(), get2YAxisDefaultLabel()); + } + + return label; + } + + + @Override protected boolean zoomX(XYPlot plot, ValueAxis axis, Range range, Range x) { boolean zoomin = super.zoom(plot, axis, range, x); @@ -263,6 +274,23 @@ return type; } + + @Override + protected YAxisWalker getYAxisWalker() { + return new YAxisWalker() { + @Override + public int length() { + return YAXIS.values().length; + } + + @Override + public String getId(int idx) { + YAXIS[] yaxes = YAXIS.values(); + return yaxes[idx].toString(); + } + }; + } + // MainValue-Annotations should be visualized by a line that goes to the curve itself. } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Fri Dec 16 11:47:57 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Fri Dec 16 13:37:58 2011 +0000 @@ -100,6 +100,23 @@ } + @Override + protected YAxisWalker getYAxisWalker() { + return new YAxisWalker() { + @Override + public int length() { + return YAXIS.values().length; + } + + @Override + public String getId(int idx) { + YAXIS[] yaxes = YAXIS.values(); + return yaxes[idx].toString(); + } + }; + } + + public boolean isInverted() { return inverted; } @@ -463,32 +480,5 @@ ? prefix + "(" + name +")" : name; } - - - @Override - protected List<Section> buildAxisSections() { - List<Section> axisSections = super.buildAxisSections(); - - for (YAXIS axis: YAXIS.values()) { - String identifier = axis.toString(); - - AxisSection axisSection = new AxisSection(); - axisSection.setIdentifier(identifier); - axisSection.setLabel(getYAxisLabel(axis.idx)); - axisSection.setFontSize(14); - axisSection.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! - axisSection.setUpperRange(0d); - axisSection.setLowerRange(0d); - - axisSections.add(axisSection); - } - - return axisSections; - } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java Fri Dec 16 11:47:57 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java Fri Dec 16 13:37:58 2011 +0000 @@ -42,6 +42,23 @@ "chart.w_differences.subtitle"; + @Override + protected YAxisWalker getYAxisWalker() { + return new YAxisWalker() { + @Override + public int length() { + return YAXIS.values().length; + } + + @Override + public String getId(int idx) { + YAXIS[] yaxes = YAXIS.values(); + return yaxes[idx].toString(); + } + }; + } + + /** * Get internationalized title for chart. * @return internationalized Chart title.
--- 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 :