Permalink
Browse files

-z option puts spark baseline at 0 instead of at min

  • Loading branch information...
1 parent 0cde7d0 commit 810265ae8571548a094346606cf0a9ef5bd682d2 @mjdominus committed Nov 15, 2011
Showing with 22 additions and 4 deletions.
  1. +12 −4 spark
  2. +10 −0 spark-test.sh
View
16 spark
@@ -25,6 +25,7 @@
# # => Prints the spark help text.
set -e
debug='false'
+zero_baseline='false'
# Prints the help text for spark.
#
@@ -66,8 +67,13 @@ setup_array() {
sorted=($sorted)
to_rational ${sorted[0]}
- min_n=$n
- min_d=$d
+ if $zero_baseline ; then
+ min_n=0
+ min_d=1
+ else
+ min_n=$n
+ min_d=$d
+ fi
to_rational ${sorted[${#sorted[@]} - 1]}
max_n=$n
@@ -108,6 +114,7 @@ print_tick()
# does integer calculations and because shelling out to bc or dc is
# slow and nonportable
to_rational $1
+
tick_index_d=$(( range_n * d * min_d ))
tick_index_n=$(( ( n * min_d - min_n * d ) * number_of_tiers * range_d ))
@@ -137,11 +144,12 @@ print_ticks()
echo
}
-while getopts ":hd" option; do
+while getopts ":hdz" option; do
case "$option" in
h) help && exit ;;
# [?]) echo "$OPTARG";;
- d) debug='true'; fudge='0'; shift $((OPTIND-1)) ;;
+ d) debug='true'; shift $((OPTIND-1)) ;;
+ z) zero_baseline='true'; shift $((OPTIND-1)) ;;
esac
done
View
@@ -54,3 +54,13 @@ it_charts_sequence() {
data="12,22,32,42,52,62,72"
test $(echo $data | $spark) = $res
}
+
+it_zero_baseline() {
+ data='100,101,102,103,104,105,106'
+ test $(echo $data | $spark) = '▁▂▃▄▅▆▇'
+ test $(echo $data | $spark -z) = '▇▇▇▇▇▇▇'
+
+ data='5,6,7'
+ test $(echo $data | $spark) = '▁▄▇'
+ test $(echo $data | $spark -z) = '▅▆▇'
+}

0 comments on commit 810265a

Please sign in to comment.