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

a fun script to create sparklines

This commit is contained in:
Darren Schroeder 2021-12-13 19:59:14 -06:00
parent ad6eaa1428
commit 8c1e0ac988

23
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 | nth $i)"
} | str collect
}