# HG changeset patch # User Ingo Weinzierl # Date 1323969042 0 # Node ID 0bd7c3cf0af167a166a1fa220c78882e3a2da768 # Parent 5c1e7c1e9e09fc8761e23c6142114b236a49a47b Added axis sections into charts Settings. flys-artifacts/trunk@3427 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 5c1e7c1e9e09 -r 0bd7c3cf0af1 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Dec 15 15:58:56 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Dec 15 17:10:42 2011 +0000 @@ -1,3 +1,19 @@ +2011-12-15 Ingo Weinzierl + + * src/main/java/de/intevation/flys/exports/AxisSection.java: Added methods + to set the axis label and id. + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Improved + the ChartSettings that will now contain a set of AxisSections. The new + buildAxisSections() method in this class is not implemented and needs to + be implemented by subclasses. + + * src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java: + Override buildAxisSections() of XYChartGenerator to create an AxisSection + for each axis that is able to be displayed in this sort of chart. In + addition, there is a new method getYAxisLabel(int) that returns the label + for a specific Y axis. + 2011-12-15 Ingo Weinzierl * src/main/java/de/intevation/flys/exports/IntegerAttribute.java: New. diff -r 5c1e7c1e9e09 -r 0bd7c3cf0af1 flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java Thu Dec 15 15:58:56 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java Thu Dec 15 17:10:42 2011 +0000 @@ -14,8 +14,44 @@ */ public class AxisSection extends DefaultSection { - public AxisSection(String id) { - super(id); + public static final String IDENTIFIER_ATTR = "id"; + public static final String LABEL_ATTR = "label"; + + + public AxisSection() { + super("axis"); + } + + + public void setIdentifier(String identifier) { + if (identifier == null || identifier.length() == 0) { + return; + } + + Attribute attr = getAttribute(IDENTIFIER_ATTR); + if (attr == null) { + attr = new StringAttribute(IDENTIFIER_ATTR, identifier, false); + addAttribute(IDENTIFIER_ATTR, attr); + } + else { + attr.setValue(identifier); + } + } + + + public void setLabel(String label) { + if (label == null) { + return; + } + + Attribute attr = getAttribute(LABEL_ATTR); + if (attr == null) { + attr = new StringAttribute(LABEL_ATTR, label, true); + addAttribute(LABEL_ATTR, attr); + } + else { + attr.setValue(label); + } } diff -r 5c1e7c1e9e09 -r 0bd7c3cf0af1 flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Thu Dec 15 15:58:56 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Thu Dec 15 17:10:42 2011 +0000 @@ -1,6 +1,8 @@ package de.intevation.flys.exports; import java.awt.Font; +import java.util.ArrayList; +import java.util.List; import org.apache.log4j.Logger; @@ -14,6 +16,7 @@ import org.w3c.dom.Document; import de.intevation.artifactdatabase.state.ArtifactAndFacet; +import de.intevation.artifactdatabase.state.Section; import de.intevation.artifactdatabase.state.Facet; import de.intevation.flys.artifacts.FLYSArtifact; @@ -191,16 +194,8 @@ @Override protected NumberAxis createYAxis(int index) { Font labelFont = new Font("Tahoma", Font.BOLD, 14); - 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); - } + String label = getYAxisLabel(index); + NumberAxis axis = new NumberAxis(label); // "Q" Axis shall include 0. if (index == YAXIS.Q.idx) { @@ -213,6 +208,24 @@ return axis; } + + protected String getYAxisLabel(int index) { + 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; + } + + /** * Get default value for the second Y-Axis' label (if no translation was * found). @@ -450,5 +463,28 @@ ? prefix + "(" + name +")" : name; } + + + @Override + protected List
buildAxisSections() { + List
axisSections = new ArrayList
(); + + for (YAXIS axis: YAXIS.values()) { + String identifier = axis.toString(); + + AxisSection axisSection = new AxisSection(); + axisSection.setIdentifier(identifier); + axisSection.setLabel(getYAxisLabel(axis.idx)); + + // TODO font-size + // TODO fixation + // TODO lower + // TODO upper + + axisSections.add(axisSection); + } + + return axisSections; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 5c1e7c1e9e09 -r 0bd7c3cf0af1 flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Thu Dec 15 15:58:56 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Thu Dec 15 17:10:42 2011 +0000 @@ -885,6 +885,11 @@ settings.setChartSection(chartSection); settings.setLegendSection(legendSection); + List
axisSections = buildAxisSections(); + for (Section axisSection: axisSections) { + settings.addAxisSection(axisSection); + } + return settings; } @@ -914,5 +919,17 @@ legendSection.setFontSize(getLegendFontSize()); return legendSection; } + + + /** + * Creates new Sections for chart axes. Subclasses of this ChartGenerator + * should override this method to include all necessary axes in that + * concrete chart. + * + * @return an empty list. + */ + protected List
buildAxisSections() { + return new ArrayList
(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :