Mercurial > dive4elements > river
changeset 423:bab867fb37e8
Charts are generated using the size defined in the incoming request document.
flys-artifacts/trunk@1908 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 12 May 2011 09:11:16 +0000 |
parents | 3b83341e0cf4 |
children | 82bd39f27569 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java |
diffstat | 3 files changed, 79 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed May 11 16:31:38 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu May 12 09:11:16 2011 +0000 @@ -1,3 +1,13 @@ +2011-05-11 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/exports/ChartGenerator.java: Added new + methods that return the requested chart size as integer array [width, + height]. The requested size is read from the incomding request document. + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: The size + of a chart is no longer static. The requested size is fetched using + ChartGenerator.getSize(). + 2011-05-11 Ingo Weinzierl <ingo@intevation.de> ISSUE-52
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Wed May 11 16:31:38 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Thu May 12 09:11:16 2011 +0000 @@ -3,13 +3,19 @@ import java.io.IOException; import java.io.OutputStream; +import javax.xml.xpath.XPathConstants; + import org.apache.log4j.Logger; import org.w3c.dom.Document; +import org.w3c.dom.Node; import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + import de.intevation.flys.model.River; import de.intevation.flys.artifacts.FLYSArtifact; @@ -27,6 +33,18 @@ private static Logger logger = Logger.getLogger(ChartGenerator.class); + /** The default chart width, if no other width is set.*/ + public static final int DEFAULT_CHART_WIDTH = 600; + + /** The default chart height, if no other height is set.*/ + public static final int DEFAULT_CHART_HEIGHT = 400; + + /** The XPath that points to the chart size of the incoming request + * document.*/ + public static final String XPATH_CHART_SIZE = + "/art:action/art:attributes/art:size"; + + /** The document of the incoming out() request.*/ protected Document request; @@ -79,6 +97,54 @@ } + /** + * Returns the size of a chart export as array which has been specified by + * the incoming request document. + * + * @return the size of a chart as [width, height] or the result of + * getDefaultSize() if no width or height are given in the request document. + */ + protected int[] getSize() { + int[] size = new int[2]; + + Node sizeEl = (Node) XMLUtils.xpath( + request, + XPATH_CHART_SIZE, + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + + if (sizeEl != null) { + String w = XMLUtils.xpathString( + sizeEl, "@art:width", ArtifactNamespaceContext.INSTANCE); + + String h = XMLUtils.xpathString( + sizeEl, "@art:height", ArtifactNamespaceContext.INSTANCE); + + if (w != null && w.length() > 0 && h != null && h.length() > 0) { + try { + size[0] = Integer.parseInt(w); + size[1] = Integer.parseInt(h); + } + catch (NumberFormatException nfe) { + logger.warn("Wrong values for chart width/height."); + } + } + } + + return size[0] > 0 && size[1] > 0 ? size : getDefaultSize(); + } + + + /** + * Returns the default size of a chart export as array. + * + * @return the default size of a chart as [width, height]. + */ + protected int[] getDefaultSize() { + return new int[] { DEFAULT_CHART_WIDTH, DEFAULT_CHART_HEIGHT }; + } + + public abstract void doOut(Artifact artifact, String facet, Document attr); public abstract void generate() throws IOException;
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Wed May 11 16:31:38 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Thu May 12 09:11:16 2011 +0000 @@ -87,11 +87,13 @@ adjustPlot(plot); adjustAxes(plot); + int[] size = getSize(); + ChartExportHelper.exportImage( out, chart, "png", - 600, 400); + size[0], size[1]); }