From 8c1e0ac9880abf1a6f2d9b1324b3199dab60a8ce Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Mon, 13 Dec 2021 19:59:14 -0600 Subject: [PATCH] a fun script to create sparklines --- fun/spark.nu | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 fun/spark.nu diff --git a/fun/spark.nu b/fun/spark.nu new file mode 100644 index 0000000..8678036 --- /dev/null +++ b/fun/spark.nu @@ -0,0 +1,23 @@ +let TICKS = ([(char -u "2581") + (char -u "2582") + (char -u "2583") + (char -u "2584") + (char -u "2585") + (char -u "2586") + (char -u "2587") + (char -u "2588")]) + +# send an array into spark and get a sparkline out +# let v = [2, 250, 670, 890, 2, 430, 11, 908, 123, 57] +# > spark $v +# ▁▂▆▇▁▄▁█▁▁ + +def spark [v: any] { + let min = ($v | math min) + let max = ($v | math max) + let scale = (($max - $min) / 7.) + for e in $v { + let i = (($e - $min) / $scale | into int) + $"($TICKS | nth $i)" + } | str collect +} \ No newline at end of file