Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ scripts that can output in that format.
spark 0 30 55 80 33 150
▁▂▃▅▂▇

Spark also supports output on multiple rows:

spark -r 3 1,2,3,4,5,6,2,3
▃█
▂▆██ ▂
▁▅████▅█

Invoke help with `spark -h`.

## cooler usage
Expand Down
44 changes: 39 additions & 5 deletions spark
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
# spark 0 30 55 80 33 150
# # => ▁▂▃▅▂▇
#
# spark -r 3 1,2,3,4,5,6,2,3
# # => ▃█
# ▂▆██ ▂
# ▁▅████▅█
#
# spark -h
# # => Prints the spark help text.

Expand Down Expand Up @@ -61,14 +66,32 @@ spark()
# use a high tick if data is constant
(( min == max )) && ticks=(▅ ▆)

local f=$(( (($max-$min)<<8)/(${#ticks[@]}-1) ))
local nticks=$((${#ticks[@]}))
local range=$((($max-$min)<<8))
local srange=$(($range/$rows))
local f=$(( (${srange}/(${nticks}-1)) ))
(( f < 1 )) && f=1

for n in $numbers
local row=$rows
while [ $row -ne 0 ]
do
_echo -n ${ticks[$(( ((($n-$min)<<8)/$f) ))]}
for n in $numbers
do
local val=$((($n-$min)<<8))
if [ $val -ge $((($srange * $row))) ]; then
#full tick
_echo -n ${ticks[$(($nticks - 1))]}
elif [ $val -lt $((($srange * ($row - 1)))) ]; then
#empty tick
_echo -n " "
else
#partial tick
_echo -n ${ticks[$(( ((($val-($srange * ($row - 1))))/$f) ))]}
fi
done
row=$(($row - 1))
_echo
done
_echo
}

# If we're being sourced, don't worry about such things
Expand All @@ -80,13 +103,17 @@ if [ "$BASH_SOURCE" == "$0" ]; then
cat <<EOF

USAGE:
$spark [-h|--help] VALUE,...
$spark [-h|--help] [-r|--rows] <ROWS> VALUE,...

EXAMPLES:
$spark 1 5 22 13 53
▁▁▃▂█
$spark 0,30,55,80,33,150
▁▂▃▄▂█
$spark -r 3 1,2,3,4,5,6,2,3
▃█
▂▆██ ▂
▁▅████▅█
echo 9 13 5 17 1 | $spark
▄▆▂█▁
EOF
Expand All @@ -98,6 +125,13 @@ EOF
help
exit 0
fi
if [ "$1" == '-r' ] || [ "$1" == '--rows' ]
then
rows="$2"
shift 2
else
rows=1
fi

spark ${@:-`cat`}
fi