Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
67
Task/Sparkline-in-unicode/REXX/sparkline-in-unicode-1.rexx
Normal file
67
Task/Sparkline-in-unicode/REXX/sparkline-in-unicode-1.rexx
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/* Rexx */
|
||||
|
||||
parse arg aaa
|
||||
call runSample aaa
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
sparkline:
|
||||
procedure
|
||||
parse arg spark
|
||||
spark = changestr(',', spark, ' ')
|
||||
bars = '▁ ▂ ▃ ▄ ▅ ▆ ▇ █'
|
||||
barK = words(bars)
|
||||
nmin = word(spark, 1)
|
||||
nmax = nmin
|
||||
-- get min & max values
|
||||
do iw = 1 to words(spark)
|
||||
nval = word(spark, iw)
|
||||
nmin = min(nval, nmin)
|
||||
nmax = max(nval, nmax)
|
||||
end iw
|
||||
range = nmax - nmin + 1
|
||||
slope = ''
|
||||
do iw = 1 to words(spark)
|
||||
point = ceiling((word(spark, iw) - nmin + 1) / range * barK)
|
||||
slope = slope || word(bars, point)
|
||||
end iw
|
||||
return slope nmin nmax range
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
ceiling:
|
||||
procedure
|
||||
parse arg ceil
|
||||
return trunc(ceil) + (ceil > 0) * (ceil \= trunc(ceil))
|
||||
floor:
|
||||
procedure
|
||||
parse arg flor
|
||||
return trunc(flor) - (flor < 0) * (flor \= trunc(flor))
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
runSample:
|
||||
procedure
|
||||
-- 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
|
||||
do until vals = ''
|
||||
-- split input on a ! character
|
||||
parse var vals lst '!' vals
|
||||
si = sparks.0 + 1; sparks.0 = si; sparks.si = lst
|
||||
end
|
||||
end
|
||||
-- run the samples
|
||||
do si = 1 to sparks.0
|
||||
vals = sparks.si
|
||||
parse value sparkline(vals) with slope .
|
||||
say 'Input: ' vals
|
||||
say 'Sparkline: ' slope
|
||||
say
|
||||
end si
|
||||
|
||||
return
|
||||
26
Task/Sparkline-in-unicode/REXX/sparkline-in-unicode-2.rexx
Normal file
26
Task/Sparkline-in-unicode/REXX/sparkline-in-unicode-2.rexx
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*REXX program displays a sparkline (spark graph) for a group of values.*/
|
||||
if arg()==0 then do /*No arguments? Use defaults.*/
|
||||
call sparkGraph 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
|
||||
call sparkGraph '1.5, 0.5 3.5, 2.5 5.5, 4.5 7.5, 6.5'
|
||||
end
|
||||
else call sparkGraph arg(1)
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────CEIL subroutine─────────────────────*/
|
||||
ceil: procedure; parse arg ?; _=trunc(?); return _+(?>0)*(?\=_)
|
||||
/*──────────────────────────────────SPARKGRAPH subroutine───────────────*/
|
||||
sparkGraph: procedure; parse arg x; say ' input: ' x /*echo values*/
|
||||
x=translate(x, ' ', ",") /*remove any superfluous commas. */
|
||||
$='▁▂▃▄▅▆▇█' /*chars to be used for the graph.*/
|
||||
xmin=word(x,1); xmax=xmin /*assume a minimum and a maximum.*/
|
||||
|
||||
do n=2 to words(x); _=word(x,n) /*examine successive words in X.*/
|
||||
xmin=min(_,xmin) /*find the minimum value in X. */
|
||||
xmax=max(_,xmax) /* " " maximum " " " */
|
||||
end /*n*/
|
||||
|
||||
z=; do j=1 for words(x) /*build the output spark graph. */
|
||||
z=z||substr($,ceil((word(x,j)-xmin+1)/(xmax-xmin+1)*length($)),1)
|
||||
end /*j*/
|
||||
|
||||
say 'output: ' z; say /*show the output, + a blank line*/
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue