mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 15:17:47 +00:00
port spark
This commit is contained in:
parent
1546634a80
commit
881ba5e7a6
1 changed files with 23 additions and 0 deletions
23
engine-q/fun/spark.nu
Normal file
23
engine-q/fun/spark.nu
Normal 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
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue