comparison artifacts/src/main/java/org/dive4elements/river/exports/DischargeGenerator.java @ 8320:b1303070c050

Generate a W in CM axis if there are W data.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 24 Sep 2014 17:39:29 +0200
parents cfb3a4d0c637
children c44775cd79f2
comparison
equal deleted inserted replaced
8319:3c534a1bcf8e 8320:b1303070c050
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the 5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 package org.dive4elements.river.exports; 8 package org.dive4elements.river.exports;
9 9
10 public class DischargeGenerator extends DiagramGenerator 10 import java.awt.Font;
11
12 import org.apache.commons.logging.Log;
13 import org.apache.commons.logging.LogFactory;
14 import org.apache.log4j.Logger;
15 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
16 import org.dive4elements.river.exports.injector.InjectorConstants;
17 import org.dive4elements.river.jfree.AxisDataset;
18 import org.jfree.chart.axis.NumberAxis;
19 import org.jfree.chart.plot.XYPlot;
20 import org.jfree.data.Range;
21
22 public class DischargeGenerator
23 extends DiagramGenerator
24 implements InjectorConstants
11 { 25 {
26 private static Logger log = Logger.getLogger(DiagramGenerator.class);
27
12 public DischargeGenerator() { 28 public DischargeGenerator() {
29 }
30
31 @Override
32 public void addDatasets(XYPlot plot) {
33 super.addDatasets(plot);
34
35 Object pnp = context.getContextValue(PNP);
36 if (!(pnp instanceof Number)) {
37 return;
38 }
39
40 double pnpValue = ((Number)pnp).doubleValue();
41
42 int wAxisIndex = diagramAttributes.getAxisIndex("W");
43 if (wAxisIndex == -1) {
44 log.warn("No W axis found.");
45 return;
46 }
47
48 AxisDataset data = datasets.get(wAxisIndex);
49 if (data == null) {
50 // No W axis
51 return;
52 }
53
54 Range range = inCm(data.getRange(), pnpValue);
55
56 // Do we have an index for W in cm?
57 NumberAxis wInCmAxis = createWinCMAxis(wAxisIndex);
58 wInCmAxis.setRange(range.getLowerBound(), range.getUpperBound());
59
60 plot.setRangeAxis(plot.getRangeAxisCount(), wInCmAxis);
61 }
62
63 private static Range inCm(Range r, double pnpValue) {
64 double l = r.getLowerBound();
65 double u = r.getUpperBound();
66 l = (l - pnpValue)*100d;
67 u = (u - pnpValue)*100d;
68 return new Range(l, u);
69 }
70
71 private NumberAxis createWinCMAxis(int wAxisIndex) {
72
73 Font labelFont = new Font(
74 DEFAULT_FONT_NAME,
75 Font.BOLD,
76 getYAxisFontSize(wAxisIndex));
77
78 String axisName = "W.in.cm";
79
80 // TODO: I18N
81 IdentifiableNumberAxis axis = new IdentifiableNumberAxis(
82 axisName, "W.in.cm");
83
84 axis.setAutoRangeIncludesZero(false);
85 axis.setLabelFont(labelFont);
86 axis.setTickLabelFont(labelFont);
87
88 return axis;
13 } 89 }
14 } 90 }
15 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 91 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org