commit 54af226e52c22aaf83d125897c65b7435bebf79d
parent 754840d19c329f05e370fe28a7800e5c2339506f
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 17 Nov 2024 15:58:46 +0000
revert looseLabels changes
we went a different route for the time axis and don't need this
Diffstat:
2 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/frontend/src/Lib.elm b/frontend/src/Lib.elm
@@ -14,30 +14,29 @@ maybe default val =
log10 x = logBase 10 x
expt b x = b^(toFloat x)
-
-niceDigitRound f =
- let digits = [1, 2, 5, 10]
- breaks = List.map2 (\ a b -> (a+b)/2) (List.drop 1 digits) digits
- m = List.map2 Tuple.pair digits breaks
- in case List.filter (\ d -> (f < Tuple.second d)) m of
- ((a,_) :: _) -> a
- _ -> 10
-
-niceDigit f =
- let niceDigits = [1, 2, 5]
- in case List.filter ((<) f) niceDigits of
- (a :: _) -> a
- _ -> 10
-
niceNumber x round =
let exp = floor (log10 x)
f = x / (expt 10.0 exp)
+ nfRound = if f < 1.5
+ then 1
+ else if f < 3
+ then 2
+ else if f < 7
+ then 5
+ else 10
+ nf = if f <= 1
+ then 1
+ else if f <= 2
+ then 2
+ else if f <= 5
+ then 5
+ else 10
in
if round
then
- (niceDigitRound f) * expt 10 exp
+ nfRound * expt 10 exp
else
- (niceDigit f) * expt 10 exp
+ nf * expt 10 exp
looseLabels ticks min max =
let
diff --git a/frontend/tests/LibTest.elm b/frontend/tests/LibTest.elm
@@ -16,7 +16,7 @@ specs =
[ runCheck 10 0 100 (0.0, 100.0, 10)
, runCheck 10 2 98 (0.0, 100.0, 10)
, runCheck 10 8 91 (0.0, 100.0, 10)
- , runCheck 8 1 32 (0, 35, 5)
- , runCheck 8 1 36 (0, 40, 5)
+ , runCheck 8 1 32 (0, 40, 10)
+ , runCheck 8 1 36 (0, 40, 10)
, runCheck 10 1 4 (1, 4, 0.5)
]