debugged sparklines implementation
This commit is contained in:
parent
03318ee2e1
commit
669fb95479
|
@ -14,9 +14,9 @@ let normalParams3: SymbolicDistTypes.normal = {mean: 20.0, stdev: 2.0}
|
||||||
let range20 = [0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0]
|
let range20 = [0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0]
|
||||||
let forSparkline = (thisPdf, inps) => map(thisPdf, inps)
|
let forSparkline = (thisPdf, inps) => map(thisPdf, inps)
|
||||||
|
|
||||||
describe("normal combine", () => {
|
describe("Sparklines", () => {
|
||||||
let pdf1 = x => Normal.pdf(x, normalParams1)
|
let pdf1 = x => Normal.pdf(x, normalParams1)
|
||||||
let forSparkline1 = forSparkline(pdf1, range20)
|
let forSparkline1 = forSparkline(pdf1, range20)
|
||||||
let x = forSparkline1 -> toString -> Sparklines.sparkly -> Js.Console.log
|
Js.Console.log(Sparklines.sparkly(forSparkline1, ~options={minimum: None, maximum: None}))
|
||||||
makeTest("Spark1", 1, 0)
|
makeTest("Spark1", 1, 0)
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,19 +8,19 @@ type sparklyConfig = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let sparkly = (
|
let sparkly = (
|
||||||
numbers: list<float>,
|
numbers: array<float>,
|
||||||
~options = {minimum: None, maximum: None}
|
~options = {minimum: None, maximum: None}
|
||||||
) => {
|
) => {
|
||||||
// if not numbers is not an array, throw typeerror "Expected an array"
|
// if not numbers is not an array, throw typeerror "Expected an array"
|
||||||
|
|
||||||
// Unlike reference impl, we assume that all numbers are finite, i.e. no NaN.
|
// Unlike reference impl, we assume that all numbers are finite, i.e. no NaN.
|
||||||
let ticks = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"]
|
let ticks = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"]// ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"]
|
||||||
let minimum = switch options.minimum {
|
let minimum = switch options.minimum {
|
||||||
| None => Js.Math.minimum(numbers)
|
| None => Js.Math.minMany_float(numbers)
|
||||||
| Some(x) => x
|
| Some(x) => x
|
||||||
}
|
}
|
||||||
let maximum = switch options.maximum {
|
let maximum = switch options.maximum {
|
||||||
| None => Js.Math.maximum(numbers)
|
| None => Js.Math.maxMany_float(numbers)
|
||||||
| Some(x) => x
|
| Some(x) => x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,11 +31,9 @@ let sparkly = (
|
||||||
ticks
|
ticks
|
||||||
}
|
}
|
||||||
|
|
||||||
let toMapWith = number => {
|
let toMapWith = (number: float) => {
|
||||||
let ret = if (! Js.Number.isFinite(number)) {
|
let ret = {
|
||||||
" "
|
let tickIndex = Js.Math.ceil_int((number /. maximum) *. Belt.Int.toFloat(Belt.Array.length(ticks))) - 1
|
||||||
} else {
|
|
||||||
let tickIndex = Js.Math.ceil((number / maximum) * ticks.length) - 1
|
|
||||||
|
|
||||||
let tickIndex = if maximum == 0.0 || tickIndex < 0 {
|
let tickIndex = if maximum == 0.0 || tickIndex < 0 {
|
||||||
0
|
0
|
||||||
|
@ -46,6 +44,7 @@ let sparkly = (
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
let ret = map(toMapWith, numbers)
|
let ret = Belt.Array.map(numbers, toMapWith)
|
||||||
|
// Belt.Array.reduce(ret, "", (x, y) => x ++ y)
|
||||||
Js.Array.joinWith("", ret)
|
Js.Array.joinWith("", ret)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user