dot

packages and services management
Log | Files | Refs | README

commit 20be1e86494ec937a7a950c5d1b238b255ebd5f1
parent 088ce686ba791367750cd403c9f7eec673c7fddc
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Wed, 26 Jul 2017 00:47:50 +0200

bin/plot: version supporting scaling

Diffstat:
Mbin/plot | 46+++++++++++++++++++++++++++++++++-------------
1 file changed, 33 insertions(+), 13 deletions(-)

diff --git a/bin/plot b/bin/plot @@ -1,21 +1,41 @@ awk ' + +BEGIN { + stepx = stepy = 1 + + for (i = 1; i < ARGC; i++) { + if (ARGV[i] == "-x" && i + 1 < ARGC) stepx = ARGV[++i] + else if (ARGV[i] == "-y" && i + 1 < ARGC) stepy = ARGV[++i] + else { + print "Usage: plot [-x step] [-y step]" + exit 1 + } + } + + ARGC = 0 +} + { - maxcol = split($0, dots) - maxrow = 0 + printf "." + maxx = split($0, dots) + maxy = 0 - # find the max - for (col = 0; col < maxcol; col++) - if (maxrow < dots[col + 1]) - maxrow = dots[col + 1] + # scale the values and find the max + for (x = 1; x <= maxx; x++) { + dots[x] = int(dots[x] / stepy) + if (maxy < dots[x]) maxy = dots[x] + } - for (col = 0; col < maxcol; col++) - for (row = maxrow + maxrow % 2; row > 0; row--) - grid[row "-" col] = dots[col + 1] < row ? 0 : 1 + # fill the grid + for (x = 1; x <= maxx; x++) + for (y = maxy + maxy % 2; y >= 1; y--) + grid[y "-" x] = dots[x] < y ? 0 : 1 - for (r = maxrow + maxrow % 2; r > 0; r -= 2) { - for (c = 0; c < col; c++) - printf grid[r "-" c] && grid[r + 1 "-" c] ? ":" : \ - grid[r "-" c] && !grid[r + 1 "-" c] ? "." : " " + # draw the grid + for (y = maxy + maxy % 2 + 1; y >= 1; y -= 2) { + for (x = 1; x <= maxx; x++) + printf grid[y "-" x] && grid[y + 1 "-" x] ? ":" : \ + grid[y "-" x] && !grid[y + 1 "-" x] ? "." : " " print "" } }