Mercurial > dive4elements > river
changeset 2050:c4e0e433f825
Use axes ranges specified in ChartSettings for zooming in charts.
flys-artifacts/trunk@3540 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 27 Dec 2011 07:17:07 +0000 |
parents | 2d5f2bc68cc6 |
children | 4ba5036109d2 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java |
diffstat | 4 files changed, 123 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Dec 23 15:10:13 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Dec 27 07:17:07 2011 +0000 @@ -1,3 +1,17 @@ +2011-12-27 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/exports/ChartSettings.java: Modified the + signature of addAxisSection(). This method now accepts AxisSections only. + In addition, there is a new method getAxisSection(String) that returns an + AxisSection specified by its identifier. + + * src/main/java/de/intevation/flys/exports/AxisSection.java: Added new + methods getIdentifier(), isFixed(), getUpperRange() and getLowerRange() to + retrieve the attributes supported by this Section. + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Make use + of axes ranges specified in ChartSettings if an axis is fixed. + 2011-12-23 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/exports/IdentifiableNumberAxis.java: New.
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java Fri Dec 23 15:10:13 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java Tue Dec 27 07:17:07 2011 +0000 @@ -43,6 +43,13 @@ } + public String getIdentifier() { + StringAttribute attr = (StringAttribute) getAttribute(IDENTIFIER_ATTR); + + return attr != null ? (String) attr.getValue() : null; + } + + public void setLabel(String label) { if (label == null) { return; @@ -87,6 +94,12 @@ } + public Boolean isFixed() { + BooleanAttribute attr = (BooleanAttribute) getAttribute(FIXATION_ATTR); + return attr != null ? (Boolean) attr.getValue() : null; + } + + public void setUpperRange(double upperRange) { Attribute attr = getAttribute(UPPERRANGE_ATTR); if (attr == null) { @@ -99,6 +112,13 @@ } + public Double getUpperRange() { + DoubleAttribute attr = (DoubleAttribute) getAttribute(UPPERRANGE_ATTR); + + return attr != null ? (Double) attr.getValue() : null; + } + + public void setLowerRange(double lowerRange) { Attribute attr = getAttribute(LOWERRANGE_ATTR); if (attr == null) { @@ -111,6 +131,13 @@ } + public Double getLowerRange() { + DoubleAttribute attr = (DoubleAttribute) getAttribute(LOWERRANGE_ATTR); + + return attr != null ? (Double) attr.getValue() : null; + } + + @Override public void toXML(Node parent) { Document owner = parent.getOwnerDocument();
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java Fri Dec 23 15:10:13 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java Tue Dec 27 07:17:07 2011 +0000 @@ -94,7 +94,7 @@ * * @param axisSection The Section specific for a chart axis. */ - public void addAxisSection(Section axisSection) { + public void addAxisSection(AxisSection axisSection) { if (axisSection != null) { axesSection.addSubsection(axisSection); } @@ -102,6 +102,28 @@ /** + * This method returns an AxisSection specified by <i>axisId</i> or null if + * no AxisSection is existing with identifier <i>axisId</i>. + * + * @param axisId The identifier of the wanted AxisSection. + * + * @return the AxisSection specified by <i>axisId</i> or null. + */ + public AxisSection getAxisSection(String axisId) { + for (int i = 0, n = axesSection.getSubsectionCount(); i < n; i++) { + AxisSection as = (AxisSection) axesSection.getSubsection(i); + String id = as.getIdentifier(); + + if (id != null && id.equals(axisId)) { + return as; + } + } + + return null; + } + + + /** * Parses the settings from <i>settings</i>. The result is a new * ChartSettings instance. *
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Fri Dec 23 15:10:13 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Tue Dec 27 07:17:07 2011 +0000 @@ -663,14 +663,27 @@ Range xrange = getDomainAxisRange(); Range yrange = getValueAxisRange(); - zoomX(plot, plot.getDomainAxis(), xRanges.get(0), xrange); + ValueAxis xAxis = plot.getDomainAxis(); + + Range fixedXRange = getRangeForAxisFromSettings("X"); + if (fixedXRange != null) { + xAxis.setRange(fixedXRange); + } + else { + zoomX(plot, xAxis, xRanges.get(0), xrange); + } for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) { ValueAxis yaxis = plot.getRangeAxis(i); if (yaxis instanceof IdentifiableNumberAxis) { - logger.info("!!! IdentifiableNumberAxis found !!!"); - // TODO Watch for fixed axes and the specified range + IdentifiableNumberAxis idAxis = (IdentifiableNumberAxis) yaxis; + + Range fixedRange = getRangeForAxisFromSettings(idAxis.getId()); + if (fixedRange != null) { + yaxis.setRange(fixedRange); + continue; + } } if (yaxis == null) { @@ -749,6 +762,41 @@ /** + * This method searches for a specific axis in the <i>settings</i> if + * <i>settings</i> is set. If the axis was found, this method returns the + * specified axis range if the axis range is fixed. Otherwise, this method + * returns null. + * + * @param axisId The identifier of an axis. + * + * @return the specified axis range from <i>settings</i> if the axis is + * fixed, otherwise null. + */ + public Range getRangeForAxisFromSettings(String axisId) { + ChartSettings chartSettings = getChartSettings(); + if (chartSettings == null) { + return null; + } + + AxisSection as = chartSettings.getAxisSection(axisId); + Boolean fixed = as.isFixed(); + + if (fixed != null && fixed) { + Double upper = as.getUpperRange(); + Double lower = as.getLowerRange(); + + if (upper != null && lower != null) { + return lower < upper + ? new Range(lower, upper) + : new Range(upper, lower); + } + } + + return null; + } + + + /** * Add annotations to Renderer. */ protected void addAnnotationsToRenderer(XYPlot plot) { @@ -1105,8 +1153,8 @@ settings.setChartSection(chartSection); settings.setLegendSection(legendSection); - List<Section> axisSections = buildAxisSections(); - for (Section axisSection: axisSections) { + List<AxisSection> axisSections = buildAxisSections(); + for (AxisSection axisSection: axisSections) { settings.addAxisSection(axisSection); } @@ -1147,8 +1195,8 @@ * * @return a list of Sections for each axis in this chart. */ - protected List<Section> buildAxisSections() { - List<Section> axisSections = new ArrayList<Section>(); + protected List<AxisSection> buildAxisSections() { + List<AxisSection> axisSections = new ArrayList<AxisSection>(); axisSections.addAll(buildXAxisSections()); axisSections.addAll(buildYAxisSections()); @@ -1162,8 +1210,8 @@ * * @return a List that contains a Section for the X axis. */ - protected List<Section> buildXAxisSections() { - List<Section> axisSections = new ArrayList<Section>(); + protected List<AxisSection> buildXAxisSections() { + List<AxisSection> axisSections = new ArrayList<AxisSection>(); String identifier = "X"; @@ -1191,8 +1239,8 @@ * * @return a list of Y axis sections. */ - protected List<Section> buildYAxisSections() { - List<Section> axisSections = new ArrayList<Section>(); + protected List<AxisSection> buildYAxisSections() { + List<AxisSection> axisSections = new ArrayList<AxisSection>(); YAxisWalker walker = getYAxisWalker(); for (int i = 0, n = walker.length(); i < n; i++) {