# HG changeset patch # User Ingo Weinzierl # Date 1324970227 0 # Node ID c4e0e433f825b36d4dcd71172c5011e2d3d05e2d # Parent 2d5f2bc68cc630bd18282e7e02cb25f3255c6893 Use axes ranges specified in ChartSettings for zooming in charts. flys-artifacts/trunk@3540 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 2d5f2bc68cc6 -r c4e0e433f825 flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/exports/IdentifiableNumberAxis.java: New. diff -r 2d5f2bc68cc6 -r c4e0e433f825 flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java --- 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(); diff -r 2d5f2bc68cc6 -r c4e0e433f825 flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java --- 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 axisId or null if + * no AxisSection is existing with identifier axisId. + * + * @param axisId The identifier of the wanted AxisSection. + * + * @return the AxisSection specified by axisId 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 settings. The result is a new * ChartSettings instance. * diff -r 2d5f2bc68cc6 -r c4e0e433f825 flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- 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 settings if + * settings 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 settings 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
axisSections = buildAxisSections(); - for (Section axisSection: axisSections) { + List 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
buildAxisSections() { - List
axisSections = new ArrayList
(); + protected List buildAxisSections() { + List axisSections = new ArrayList(); axisSections.addAll(buildXAxisSections()); axisSections.addAll(buildYAxisSections()); @@ -1162,8 +1210,8 @@ * * @return a List that contains a Section for the X axis. */ - protected List
buildXAxisSections() { - List
axisSections = new ArrayList
(); + protected List buildXAxisSections() { + List axisSections = new ArrayList(); String identifier = "X"; @@ -1191,8 +1239,8 @@ * * @return a list of Y axis sections. */ - protected List
buildYAxisSections() { - List
axisSections = new ArrayList
(); + protected List buildYAxisSections() { + List axisSections = new ArrayList(); YAxisWalker walker = getYAxisWalker(); for (int i = 0, n = walker.length(); i < n; i++) {