# HG changeset patch # User Ingo Weinzierl # Date 1328539050 0 # Node ID 7b8d59436be3f4bfeb652a029ad431ed180cdde5 # Parent 4a8b519b64bd1dc9638ea7b2fd3402d0cc624fcb Set proper bounds for date axes in the chart info document; tell the transformation matrix which type it is (date/number). flys-artifacts/trunk@3930 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 4a8b519b64bd -r 7b8d59436be3 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon Feb 06 14:22:26 2012 +0000 +++ b/flys-artifacts/ChangeLog Mon Feb 06 14:37:30 2012 +0000 @@ -1,3 +1,9 @@ +2012-02-06 Ingo Weinzierl + + * src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java: Set + proper bounds for date axis elements; tell the transformation matrix which + type it is (number/date). + 2012-02-06 Felix Wolfsteller * src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java: diff -r 4a8b519b64bd -r 7b8d59436be3 flys-artifacts/src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java Mon Feb 06 14:22:26 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java Mon Feb 06 14:37:30 2012 +0000 @@ -4,6 +4,8 @@ import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Rectangle2D; +import java.util.Date; + import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -12,6 +14,7 @@ import org.jfree.chart.ChartRenderingInfo; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; +import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.data.Range; @@ -141,25 +144,38 @@ int pos) { logger.debug("createAxisElement " + pos); - Range range = axis.getRange(); + logger.debug("Axis is from type: " + axis.getClass()); Element e = cr.create(type); cr.addAttr(e, "pos", String.valueOf(pos), true); - cr.addAttr(e, "from", String.valueOf(range.getLowerBound()), true); - cr.addAttr(e, "to", String.valueOf(range.getUpperBound()), true); - - logger.debug("Axis is from type: " + axis.getClass()); if (axis instanceof DateAxis) { - logger.debug("Add axis type: date"); - cr.addAttr(e, "axistype", "date", true); + prepareDateAxisElement( + e, cr, (DateAxis) axis, dataset, type, pos); } else { - logger.debug("Add axis type: number"); - cr.addAttr(e, "axistype", "number", true); + prepareNumberAxisElement( + e, cr, (NumberAxis) axis, dataset, type, pos); } - //Range[] rs = generator.getRangesForDataset(dataset); + return e; + } + + + protected Element prepareNumberAxisElement( + Element e, + ElementCreator cr, + NumberAxis axis, + XYDataset dataset, + String type, + int pos + ) { + Range range = axis.getRange(); + + cr.addAttr(e, "from", String.valueOf(range.getLowerBound()), true); + cr.addAttr(e, "to", String.valueOf(range.getUpperBound()), true); + cr.addAttr(e, "axistype", "number", true); + Range[] rs = generator.getRangesForAxis(pos); Range r = null; @@ -177,6 +193,29 @@ } + protected Element prepareDateAxisElement( + Element e, + ElementCreator cr, + DateAxis axis, + XYDataset dataset, + String type, + int pos + ) { + Date from = axis.getMinimumDate(); + Date to = axis.getMaximumDate(); + + cr.addAttr(e, "axistype", "date", true); + cr.addAttr(e, "from", String.valueOf(from.getTime()), true); + cr.addAttr(e, "to", String.valueOf(to.getTime()), true); + + // TODO Get correct min/max + cr.addAttr(e, "min", String.valueOf(from.getTime()), true); + cr.addAttr(e, "max", String.valueOf(to.getTime()), true); + + return e; + } + + /** * This method appends the values of a transformation matrix to transform * image pixel coordinates into chart coordinates. @@ -253,6 +292,20 @@ cr.addAttr(matrix, "tx", String.valueOf(tm[2]), true); cr.addAttr(matrix, "ty", String.valueOf(tm[3]), true); + if (xAxis instanceof DateAxis) { + cr.addAttr(matrix, "xtype", "date", true); + } + else { + cr.addAttr(matrix, "xtype", "number", true); + } + + if (yAxis instanceof DateAxis) { + cr.addAttr(matrix, "ytype", "date", true); + } + else { + cr.addAttr(matrix, "ytype", "number", true); + } + return matrix; } @@ -279,8 +332,8 @@ double offsetY = dataArea.getY(); double height = dataArea.getHeight(); - Range xRange = xAxis.getRange(); - Range yRange = yAxis.getRange(); + Range xRange = getRangeFromAxis(xAxis); + Range yRange = getRangeFromAxis(yAxis); double lowerX = xRange.getLowerBound(); double upperX = xRange.getUpperBound(); @@ -325,5 +378,19 @@ return new double[] { 1d, 1d, 0d, 0d }; } + + + protected static Range getRangeFromAxis(ValueAxis axis) { + if (axis instanceof DateAxis) { + DateAxis dAxis = (DateAxis) axis; + Date min = dAxis.getMinimumDate(); + Date max = dAxis.getMaximumDate(); + + return new Range(min.getTime(), max.getTime()); + } + else { + return axis.getRange(); + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :