Lib.elm (1113B)
1 -- miscellaneous functions extracted from Main so 2 -- we can more easily test them 3 4 module Lib exposing (looseLabels) 5 6 7 -- https://github.com/cenfun/nice-ticks/blob/master/docs/Nice-Numbers-for-Graph-Labels.pdf 8 9 niceNumber x round = 10 let expt b ex = b^ toFloat ex 11 exp = floor (logBase 10 x) 12 f = x / expt 10.0 exp 13 nfRound = if f < 1.5 14 then 1 15 else if f < 3 16 then 2 17 else if f < 7 18 then 5 19 else 10 20 nf = if f <= 1 21 then 1 22 else if f <= 2 23 then 2 24 else if f <= 5 25 then 5 26 else 10 27 in 28 if round 29 then 30 nfRound * expt 10 exp 31 else 32 nf * expt 10 exp 33 34 looseLabels ticks min max = 35 let 36 range = niceNumber (max-min) False 37 d = niceNumber (range/(ticks - 1)) True 38 graphmin = toFloat (floor (min/d)) * d 39 graphmax = toFloat (ceiling (max/d)) * d 40 in (graphmin, graphmax, d)