Mercurial > dive4elements > river
changeset 2059:522826b41ffa
Compute better step width for W/Q input.
flys-artifacts/trunk@3551 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 28 Dec 2011 08:28:13 +0000 |
parents | f97cf2e350c9 |
children | 3ffb7195173f |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java |
diffstat | 2 files changed, 68 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Tue Dec 27 11:37:23 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Dec 28 08:28:13 2011 +0000 @@ -1,3 +1,12 @@ +2011-12-28 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/states/WQSelect.java: + Compute better step width based on a maximal number of steps = 30. + Results with digits are rounded up. E.g.: + Q range = 9.6 - 1750 + Step width = 58.01 + Rounded result = 60 + 2011-12-27 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/exports/AxisSection.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Tue Dec 27 11:37:23 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Wed Dec 28 08:28:13 2011 +0000 @@ -45,6 +45,9 @@ /** The default step width for Qs. */ public static final String DEFAULT_STEP_W = "30"; + /** The max number of steps for Qs and Ws. */ + public static final int MAX_STEPS = 30; + /** The name of the 'mode' field. */ public static final String WQ_MODE = "wq_mode"; @@ -237,14 +240,68 @@ } else { Element stepW = createItem( - cr, new String[] {"stepW", DEFAULT_STEP_W}); + cr, new String[] { + "stepW", + String.valueOf(getStepsW(minmaxW[0], minmaxW[1]))}); Element stepQ = createItem( - cr, new String[] {"stepQ", DEFAULT_STEP_Q}); + cr, new String[] { + "stepQ", + String.valueOf(getStepsW(minmaxQ[0], minmaxQ[1]))}); return new Element[] { stepW, stepQ }; } } + protected static double getStepsW(double min, double max) { + double diff = min < max ? max - min : min - max; + double step = diff / MAX_STEPS; + + if (step < 1000) { + return getSteps(step, 100); + } + else if (step < 100) { + return getSteps(step, 10); + } + else if (step < 10) { + return getSteps(step, 1); + } + else { + return step; + } + } + + + protected static double getStepsQ(double min, double max) { + double diff = min < max ? max - min : min - max; + double step = diff / MAX_STEPS; + + if (step < 1000) { + return getSteps(step, 100); + } + else if (step < 100) { + return getSteps(step, 10); + } + else if (step < 10) { + return getSteps(step, 1); + } + else { + return step; + } + } + + + protected static double getSteps(double steps, double factor) { + int fac = (int) steps / 10; + double diff = steps - fac * 10; + + if (diff == 0) { + return steps; + } + + return 10d * (fac + 1); + } + + protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { Element item = ProtocolUtils.createArtNode(cr, "item", null, null); Element label = ProtocolUtils.createArtNode(cr, "label", null, null);