Sparkline in unicode: Difference between revisions
Content added Content deleted
(Add NetRexx implementation) |
|||
Line 237: | Line 237: | ||
▂▁▄▃▆▅█▇ |
▂▁▄▃▆▅█▇ |
||
</pre> |
|||
=={{header|NetRexx}}== |
|||
<lang NetRexx>/* NetRexx */ |
|||
options replace format comments java crossref symbols nobinary |
|||
runSample(arg) |
|||
return |
|||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|||
method sparkline(spark) private static |
|||
bars = '\u2581 \u2582 \u2583 \u2584 \u2585 \u2586 \u2587 \u2588' |
|||
barK = bars.words() |
|||
nmin = spark.word(1) |
|||
nmax = nmin |
|||
-- get min & max values |
|||
loop iw = 1 to spark.words() |
|||
nval = spark.word(iw) |
|||
nmin = nval.min(nmin) |
|||
nmax = nval.max(nmax) |
|||
end iw |
|||
range = nmax - nmin + 1 |
|||
slope = '' |
|||
loop iw = 1 to spark.words() |
|||
point = Math.ceil((spark.word(iw) - nmin) / range * barK) + 1 |
|||
slope = slope || bars.word(point) |
|||
end iw |
|||
return slope nmin nmax range |
|||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|||
method runSample(arg) private static |
|||
-- sample data setup |
|||
parse arg vals |
|||
sparks = 0 |
|||
sparks[0] = 0 |
|||
if vals = '' then do |
|||
si = sparks[0] + 1; sparks[0] = si; sparks[si] = 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 |
|||
si = sparks[0] + 1; sparks[0] = si; sparks[si] = 1.5 0.5 3.5 2.5 5.5 4.5 7.5 6.5 |
|||
end |
|||
else do |
|||
loop until vals = '' |
|||
parse vals lst ',' vals |
|||
si = sparks[0] + 1; sparks[0] = si; sparks[si] = lst |
|||
end |
|||
end |
|||
-- run the samples |
|||
loop si = 1 to sparks[0] |
|||
parse sparkline(sparks[si]) slope . |
|||
say 'Input: ' sparks[si].space() |
|||
say 'Sparkline: ' slope |
|||
end si |
|||
return |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
Input: 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 |
|||
Sparkline: ▁▂▃▄▅▆▇█▇▆▅▄▃▂▁ |
|||
Input: 1.5 0.5 3.5 2.5 5.5 4.5 7.5 6.5 |
|||
Sparkline: ▂▁▄▃▆▅█▇ |
|||
</pre> |
</pre> |
||