Changes as was requested in CR
This commit is contained in:
parent
cd5680f2dc
commit
649f3e833a
|
@ -1,5 +1,4 @@
|
|||
open Rationale.Function.Infix
|
||||
|
||||
module FloatFloatMap = {
|
||||
module Id = Belt.Id.MakeComparable({
|
||||
type t = float
|
||||
|
@ -87,6 +86,11 @@ module O = {
|
|||
let max = compare(\">")
|
||||
}
|
||||
|
||||
module O2 = {
|
||||
let default = (a, b) => O.default(b, a)
|
||||
let toExn = (a, b) => O.toExn(b, a)
|
||||
}
|
||||
|
||||
/* Functions */
|
||||
module F = {
|
||||
let apply = (a, e) => a |> e
|
||||
|
@ -324,7 +328,7 @@ module A = {
|
|||
| r => Some(r)
|
||||
}
|
||||
)
|
||||
let filter = (o, e) => Js.Array.filter(o, e)
|
||||
let filter = Js.Array.filter
|
||||
let joinWith = Js.Array.joinWith
|
||||
|
||||
module O = {
|
||||
|
@ -438,6 +442,11 @@ module A = {
|
|||
}
|
||||
}
|
||||
|
||||
module A2 = {
|
||||
let fmap = (a, b) => Array.map(b, a)
|
||||
let joinWith = (a, b) => A.joinWith(b, a)
|
||||
}
|
||||
|
||||
module JsArray = {
|
||||
let concatSomes = (optionals: Js.Array.t<option<'a>>): Js.Array.t<'a> =>
|
||||
optionals
|
||||
|
|
|
@ -8,19 +8,19 @@ let ticks = [`▁`, `▂`, `▃`, `▄`, `▅`, `▆`, `▇`, `█`]
|
|||
let _ticksLength = E.A.length(ticks)
|
||||
|
||||
let _heightToTickIndex = (maximum: float, v: float) => {
|
||||
let v = Js.Math.ceil_int(v /. maximum *. Belt.Int.toFloat(_ticksLength)) - 1
|
||||
min(v, 0)
|
||||
let suggestedTickIndex = Js.Math.ceil_int(v /. maximum *. Belt.Int.toFloat(_ticksLength)) - 1
|
||||
max(suggestedTickIndex, 0)
|
||||
}
|
||||
|
||||
let create = (relativeHeights: array<float>, ~maximum=?, ()) => {
|
||||
if E.A.length(relativeHeights) === 0 {
|
||||
""
|
||||
} else {
|
||||
let maximum = maximum |> E.O.default(E.A.max(relativeHeights) |> E.O.toExn(""))
|
||||
let maximum = maximum->E.O2.default(E.A.max(relativeHeights)->E.O2.toExn(""))
|
||||
|
||||
relativeHeights
|
||||
|> E.A.fmap(_heightToTickIndex(maximum))
|
||||
|> E.A.fmap(r => E.A.get(ticks, r) |> E.O.toExn(""))
|
||||
|> E.A.joinWith("")
|
||||
->E.A2.fmap(_heightToTickIndex(maximum))
|
||||
->E.A2.fmap(r => E.A.get(ticks, r)->E.O2.toExn(""))
|
||||
->E.A2.joinWith("")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user