1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-02 07:07:46 +00:00

port spark

This commit is contained in:
Darren Schroeder 2022-01-15 18:22:42 -06:00
parent 1546634a80
commit 881ba5e7a6

23
engine-q/fun/spark.nu Normal file
View file

@ -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 | get $i)"
} | str collect
}