Sparkline in unicode: Difference between revisions
Content added Content deleted
No edit summary |
(Add SenseTalk implementation) |
||
Line 2,408: | Line 2,408: | ||
▂▁▄▃▆▅█▇ |
▂▁▄▃▆▅█▇ |
||
Numbers separated by anything: |
Numbers separated by anything: |
||
</pre> |
|||
=={{header|SenseTalk}}== |
|||
This solution makes use of SenseTalk's "word" chunks, in this case delimited by any number of spaces and/or commas, to simplify parsing the input string. Also note the use of the <code>but no more than</code> operator to handle the edge case where a number equal to the top value would otherwise refer to the 9th symbol, which doesn't exist. |
|||
<lang sensetalk>put sparklineGraph of "1 2 3 4 5 6 7 8 7 6 5 4 3 2 1" |
|||
put sparklineGraph of "1.5, 0.5 3.5, 2.5 5.5, 4.5 7.5, 6.5" |
|||
put sparklineGraph of "0, 1, 19, 20" |
|||
put sparklineGraph of "0, 999, 4000, 4999, 7000, 7999" |
|||
to handle sparklineGraph of input |
|||
put each word delimited by " ," of input into numbers |
|||
put the lowestValue of numbers into bottom |
|||
put the highestValue of numbers into top |
|||
put top - bottom into range -- total range of values |
|||
put range/8 into step -- the size of each incremental step in the graph |
|||
repeat with each number in numbers |
|||
put (trunc((number - bottom) / step) + 1) but no more than 8 into symbolNum |
|||
put character symbolNum of "▁▂▃▄▅▆▇█" after graph |
|||
end repeat |
|||
put !" (range: [[bottom]] to [[top]])" after graph |
|||
return graph |
|||
end sparklineGraph |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
▁▂▃▄▅▆▇█▇▆▅▄▃▂▁ (range: 1 to 8) |
|||
▂▁▄▃▆▅█▇ (range: 0.5 to 7.5) |
|||
▁▁██ (range: 0 to 20) |
|||
▁▁▅▅██ (range: 0 to 7999) |
|||
</pre> |
</pre> |
||