comparison artifacts/src/main/java/org/dive4elements/river/exports/DischargeGenerator.java @ 8571:bc803f4b6784

(issue1798) Adjust WinCM according to W in NHN axis on explicit zoom
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 27 Feb 2015 19:07:25 +0100
parents a82f24b773e7
children e6d0fc817e20
comparison
equal deleted inserted replaced
8570:1655588ed479 8571:bc803f4b6784
24 { 24 {
25 private static Logger log = Logger.getLogger(DischargeGenerator.class); 25 private static Logger log = Logger.getLogger(DischargeGenerator.class);
26 26
27 private String I18N_AXIS_LABEL = "chart.discharge.curve.yaxis.cm.label"; 27 private String I18N_AXIS_LABEL = "chart.discharge.curve.yaxis.cm.label";
28 28
29 private int wAxisIndex;
30 private int wInCmAxisIndex;
31 double pnpValue;
32
29 public DischargeGenerator() { 33 public DischargeGenerator() {
30 } 34 }
31 35
32 @Override 36 @Override
33 public void addDatasets(XYPlot plot) { 37 public void addDatasets(XYPlot plot) {
36 Object pnp = context.getContextValue(PNP); 40 Object pnp = context.getContextValue(PNP);
37 if (!(pnp instanceof Number)) { 41 if (!(pnp instanceof Number)) {
38 return; 42 return;
39 } 43 }
40 44
41 double pnpValue = ((Number)pnp).doubleValue(); 45 pnpValue = ((Number)pnp).doubleValue();
42 46
43 int wAxisIndex = diagramAttributes.getAxisIndex("W"); 47 wAxisIndex = diagramAttributes.getAxisIndex("W");
44 if (wAxisIndex == -1) { 48 if (wAxisIndex == -1) {
45 log.warn("No W axis found."); 49 log.warn("No W axis found.");
46 return; 50 return;
47 } 51 }
48 52
65 69
66 // Do we have an index for W in cm? 70 // Do we have an index for W in cm?
67 NumberAxis wInCmAxis = createWinCMAxis(wAxisIndex); 71 NumberAxis wInCmAxis = createWinCMAxis(wAxisIndex);
68 wInCmAxis.setRange(axisRange); 72 wInCmAxis.setRange(axisRange);
69 73
70 int wInCmAxisIndex = plot.getRangeAxisCount(); 74 wInCmAxisIndex = plot.getRangeAxisCount();
71 plot.setRangeAxis(wInCmAxisIndex, wInCmAxis); 75 plot.setRangeAxis(wInCmAxisIndex, wInCmAxis);
72 combineYBounds(new DoubleBounds(dataRange), wInCmAxisIndex); 76 combineYBounds(new DoubleBounds(dataRange), wInCmAxisIndex);
73 } 77 }
74 78
75 private static Range inCm(Range r, double pnpValue) { 79 private static Range inCm(Range r, double pnpValue) {
98 axis.setLabelFont(labelFont); 102 axis.setLabelFont(labelFont);
99 axis.setTickLabelFont(labelFont); 103 axis.setTickLabelFont(labelFont);
100 104
101 return axis; 105 return axis;
102 } 106 }
107
108 /** We need to override this to keep both axis synced. */
109 @Override
110 protected void autoZoom(XYPlot plot) {
111 super.autoZoom(plot);
112 IdentifiableNumberAxis idA = (IdentifiableNumberAxis) plot.getRangeAxis(wAxisIndex);
113 Range fixedRange = getRangeForAxisFromSettings(idA.getId());
114 if (fixedRange == null) {
115 return;
116 }
117 log.debug("Adjusting helper centimeter axis to fixed range.");
118 Range adjustedRange = inCm(
119 fixedRange,
120 pnpValue
121 );
122 IdentifiableNumberAxis wInCmAxis=
123 (IdentifiableNumberAxis) plot.getRangeAxis(wInCmAxisIndex);
124 wInCmAxis.setRange(adjustedRange);
125 }
103 } 126 }
104 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 127 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org