'''Sparkline''' is a term Edward Tufte invented with for "small, high resolution graphics embedded in a context of words, numbers, images". On the Internet, however, the term has come to often mean rough text charts made with block characters, like this: `▁▂▃▅▂▇`. [dbohdan] 2014-12-29: This particular implementation was inspired by using [https://github.com/holman/spark/%|%one for Bash] (sadly, incompatible with POSIX `sh`). It works in both Tcl 8.4+ and [Jim Tcl]. ====== # spark.tcl namespace eval sparklines { namespace export create variable version 0.0.4 variable ticks [list ▁ ▂ ▃ ▄ ▅ ▆ ▇ █] variable tickMax [expr {[llength $ticks] - 1}] proc create data { variable ticks variable tickMax set sorted [lsort -real $data] set min [lindex $sorted 0] set max [lindex $sorted end] if {$min == $max} { # All data points are the same. return [string repeat \ [lindex $ticks [expr {int($tickMax / 2)}]] \ [llength $data]] } else { set result {} foreach x $data { set xNormalized [expr { int($tickMax * ($x - $min) / ($max - $min)) }] append result [lindex $ticks $xNormalized] } return $result } } } # The following code allows you to use this script from the command line much like # the Bash version mentioned above. proc main-script? {} { # From http://wiki.tcl.tk/40097. global argv0 if {[info exists argv0] && [file exists [info script]] && [file exists $argv0]} { file stat $argv0 argv0Info file stat [info script] scriptInfo expr {$argv0Info(dev) == $scriptInfo(dev) && $argv0Info(ino) == $scriptInfo(ino)} } else { return 0 } } if {[main-script?]} { puts [sparklines::create $argv] } ====== **See also** * [7-segment ASCII graphics] * [ASCII animation] - how to make an text progress bar <>Plotting | Unicode