diff --git a/packages/squiggle-lang/__tests__/Symbolic_test.res b/packages/squiggle-lang/__tests__/Symbolic_test.res index 8f9f88cd..f45e3374 100644 --- a/packages/squiggle-lang/__tests__/Symbolic_test.res +++ b/packages/squiggle-lang/__tests__/Symbolic_test.res @@ -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 forSparkline = (thisPdf, inps) => map(thisPdf, inps) -describe("normal combine", () => { +describe("Sparklines", () => { let pdf1 = x => Normal.pdf(x, normalParams1) 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) }) diff --git a/packages/squiggle-lang/src/rescript/utility/Sparklines.res b/packages/squiggle-lang/src/rescript/utility/Sparklines.res index 97b25127..9f2f780c 100644 --- a/packages/squiggle-lang/src/rescript/utility/Sparklines.res +++ b/packages/squiggle-lang/src/rescript/utility/Sparklines.res @@ -8,19 +8,19 @@ type sparklyConfig = { } let sparkly = ( - numbers: list, + numbers: array, ~options = {minimum: None, maximum: None} ) => { // 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. - let ticks = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"] + let ticks = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"]// ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"] let minimum = switch options.minimum { - | None => Js.Math.minimum(numbers) + | None => Js.Math.minMany_float(numbers) | Some(x) => x } let maximum = switch options.maximum { - | None => Js.Math.maximum(numbers) + | None => Js.Math.maxMany_float(numbers) | Some(x) => x } @@ -31,11 +31,9 @@ let sparkly = ( ticks } - let toMapWith = number => { - let ret = if (! Js.Number.isFinite(number)) { - " " - } else { - let tickIndex = Js.Math.ceil((number / maximum) * ticks.length) - 1 + let toMapWith = (number: float) => { + let ret = { + let tickIndex = Js.Math.ceil_int((number /. maximum) *. Belt.Int.toFloat(Belt.Array.length(ticks))) - 1 let tickIndex = if maximum == 0.0 || tickIndex < 0 { 0 @@ -46,6 +44,7 @@ let sparkly = ( } 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) }