[PATCH] Generate a W in CM axis if there are W data
Wald Commits
scm-commit at wald.intevation.org
Wed Sep 24 17:39:36 CEST 2014
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1411573169 -7200
# Node ID b1303070c0506d787222e98b453c8dbd2f2f673b
# Parent 3c534a1bcf8ebf73a80a2fd158517bf4264a0bd5
Generate a W in CM axis if there are W data.
diff -r 3c534a1bcf8e -r b1303070c050 artifacts/src/main/java/org/dive4elements/river/exports/DischargeGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DischargeGenerator.java Wed Sep 24 16:42:55 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DischargeGenerator.java Wed Sep 24 17:39:29 2014 +0200
@@ -7,9 +7,85 @@
*/
package org.dive4elements.river.exports;
-public class DischargeGenerator extends DiagramGenerator
+import java.awt.Font;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.Logger;
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.river.exports.injector.InjectorConstants;
+import org.dive4elements.river.jfree.AxisDataset;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.plot.XYPlot;
+import org.jfree.data.Range;
+
+public class DischargeGenerator
+extends DiagramGenerator
+implements InjectorConstants
{
+ private static Logger log = Logger.getLogger(DiagramGenerator.class);
+
public DischargeGenerator() {
}
+
+ @Override
+ public void addDatasets(XYPlot plot) {
+ super.addDatasets(plot);
+
+ Object pnp = context.getContextValue(PNP);
+ if (!(pnp instanceof Number)) {
+ return;
+ }
+
+ double pnpValue = ((Number)pnp).doubleValue();
+
+ int wAxisIndex = diagramAttributes.getAxisIndex("W");
+ if (wAxisIndex == -1) {
+ log.warn("No W axis found.");
+ return;
+ }
+
+ AxisDataset data = datasets.get(wAxisIndex);
+ if (data == null) {
+ // No W axis
+ return;
+ }
+
+ Range range = inCm(data.getRange(), pnpValue);
+
+ // Do we have an index for W in cm?
+ NumberAxis wInCmAxis = createWinCMAxis(wAxisIndex);
+ wInCmAxis.setRange(range.getLowerBound(), range.getUpperBound());
+
+ plot.setRangeAxis(plot.getRangeAxisCount(), wInCmAxis);
+ }
+
+ private static Range inCm(Range r, double pnpValue) {
+ double l = r.getLowerBound();
+ double u = r.getUpperBound();
+ l = (l - pnpValue)*100d;
+ u = (u - pnpValue)*100d;
+ return new Range(l, u);
+ }
+
+ private NumberAxis createWinCMAxis(int wAxisIndex) {
+
+ Font labelFont = new Font(
+ DEFAULT_FONT_NAME,
+ Font.BOLD,
+ getYAxisFontSize(wAxisIndex));
+
+ String axisName = "W.in.cm";
+
+ // TODO: I18N
+ IdentifiableNumberAxis axis = new IdentifiableNumberAxis(
+ axisName, "W.in.cm");
+
+ axis.setAutoRangeIncludesZero(false);
+ axis.setLabelFont(labelFont);
+ axis.setTickLabelFont(labelFont);
+
+ return axis;
+ }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
More information about the Dive4Elements-commits
mailing list