make plotting work without scales - ploot - simple plotting tools | |
git clone git://bitreich.org/ploot git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
LICENSE | |
--- | |
commit 329e7cc8a47b33e9e4efb0f8bdcfb396e89bbb21 | |
parent 6d206dec470107adc7708b518bff521d8974f8a7 | |
Author: Josuah Demangeon <[email protected]> | |
Date: Mon, 7 May 2018 02:06:55 +0200 | |
make plotting work without scales | |
Plotting works with some essential features missing and not much | |
testing. | |
Diffstat: | |
M ffdraw.c | 1 + | |
M ploot.c | 2 -- | |
M ploot.h | 3 --- | |
M plootxt.c | 63 +++++++++++++++--------------… | |
M test.csv | 143 ++++++++++++++++++++++++-----… | |
M util.h | 4 ++++ | |
6 files changed, 149 insertions(+), 67 deletions(-) | |
--- | |
diff --git a/ffdraw.c b/ffdraw.c | |
@@ -13,6 +13,7 @@ | |
#include <stdlib.h> | |
#include <stdio.h> | |
+#include "util.h" | |
#include "ploot.h" | |
/* | |
diff --git a/ploot.c b/ploot.c | |
@@ -11,8 +11,6 @@ | |
#include "util.h" | |
#include "config.h" /* after ploot.h for type definitions */ | |
-#define LEN(x) (sizeof(x) / sizeof(*x)) | |
- | |
char *argv0; | |
char *tflag = ""; | |
char *uflag = ""; | |
diff --git a/ploot.h b/ploot.h | |
@@ -1,9 +1,6 @@ | |
#include <time.h> | |
#include <stdint.h> | |
-#define MIN(x, y) ((x) < (y) ? (x) : (y)) | |
-#define MAX(x, y) ((x) > (y) ? (x) : (y)) | |
- | |
typedef uint16_t Color[4]; | |
typedef struct { | |
diff --git a/plootxt.c b/plootxt.c | |
@@ -15,6 +15,7 @@ | |
#define BRAILLE_START 10240 | |
int wflag = 80; | |
+int width; | |
char *argv0; | |
@@ -35,12 +36,13 @@ plot_dot(long *out, int row, int col) | |
} | |
static void | |
-plot_val(long *out, double val, double max, int row, int width) | |
+plot_val(long *out, double val, double max, int row) | |
{ | |
int col; | |
- col = (int)((double)(val * width * 2) / max); | |
- for (; col > 0; out++, col--) | |
+ val = MIN(max, val); | |
+ col = (int)(val * (double)(width - 1) / max * 2); | |
+ for (; col > 0; col--) | |
plot_dot(out + col / 2, row, col % 2); | |
} | |
@@ -49,7 +51,7 @@ plot_val(long *out, double val, double max, int row, int widt… | |
* values line. | |
*/ | |
static time_t | |
-plot_row(long *out, char *line, double *max, int nrow, int ncol, int width) | |
+plot_row(long *out, char *line, double *max, int nrow, int ncol) | |
{ | |
time_t epoch; | |
double val; | |
@@ -64,7 +66,7 @@ plot_row(long *out, char *line, double *max, int nrow, int nc… | |
if (n >= ncol) | |
fputs("too many values\n", stderr), exit(1); | |
val = eatof(tok); | |
- plot_val(out + n * width, max[n - 1], nrow, val, width); | |
+ plot_val(out + n * width, val, max[n], nrow); | |
} | |
if (n < ncol) | |
fputs("not enough values\n", stderr), exit(1); | |
@@ -76,7 +78,7 @@ plot_row(long *out, char *line, double *max, int nrow, int nc… | |
* Read enough input in order to print one line and plot it into 'out'. | |
*/ | |
static time_t | |
-plot_line(long *out, double *max, int ncol, int width) | |
+plot_line(long *out, double *max, int ncol) | |
{ | |
time_t epoch; | |
int n, nrow; | |
@@ -89,7 +91,7 @@ plot_line(long *out, double *max, int ncol, int width) | |
for (nrow = 0; nrow < 4; nrow++) { | |
if ((esfgets(line, LINE_MAX, stdin)) == NULL) | |
exit(0); | |
- epoch = plot_row(out, line, max, nrow, ncol, width); | |
+ epoch = plot_row(out, line, max, nrow, ncol); | |
} | |
return epoch; | |
@@ -130,7 +132,6 @@ put_line(long *out) | |
{ | |
for (; *out != '\0'; out++) | |
print_utf8_3bytes(*out); | |
- putchar('|'); | |
putchar('\n'); | |
} | |
@@ -139,16 +140,15 @@ plot(char labels[LINE_MAX], double *max, int ncol) | |
{ | |
time_t epoch, last_epoch; | |
long out[WIDTH_MAX + 1]; | |
- int n, width; | |
+ int n; | |
- width = (wflag - sizeof("XXxXXxXX _|")) / ncol - sizeof("|"); | |
last_epoch = epoch = 0; | |
- for (n = 0;; n = n == 20 ? 0 : n + 1) { | |
+ for (n = 0;; n = n == 25 ? 0 : n + 1) { | |
if (n == 0) | |
put_time(0, 0, 2), puts(labels); | |
- epoch = plot_line(out, max, ncol, width); | |
+ epoch = plot_line(out, max, ncol); | |
put_time(epoch, last_epoch, n); | |
last_epoch = epoch; | |
put_line(out); | |
@@ -157,25 +157,15 @@ plot(char labels[LINE_MAX], double *max, int ncol) | |
} | |
} | |
-static void | |
-fmt_labels(char out[LINE_MAX], int ncol, char *labels[LINE_MAX / 2]) | |
-{ | |
- int i, w; | |
- | |
- w = wflag / ncol; | |
- for (i = 0; i < ncol; labels++, i++) | |
- out += snprintf(out, w - 1, " %.*s", w - 1, *labels); | |
-} | |
- | |
/* | |
* Label must be able to store all pointers to token buf has to | |
* offer: sizeof(*buf / 2). | |
*/ | |
static int | |
-read_labels(char out[LINE_MAX]) | |
+read_labels(char *labv[LINE_MAX]) | |
{ | |
int ncol; | |
- char *l, line[LINE_MAX], **lab, *labels[LINE_MAX / 2], *tok; | |
+ char *l, line[LINE_MAX], *tok; | |
if ((l = esfgets(line, LINE_MAX, stdin)) == NULL) | |
fputs("missing label line\n", stderr), exit(1); | |
@@ -183,20 +173,27 @@ read_labels(char out[LINE_MAX]) | |
if (strcmp(strsep(&l, ","), "epoch") != 0) | |
fputs("first label must be \"epoch\"\n", stderr), exit(1); | |
- lab = labels; | |
- for (ncol = 0; (tok = strsep(&l, ",")) != NULL; ncol++, lab++) | |
- *lab = tok; | |
- *lab = NULL; | |
+ for (ncol = 0; (tok = strsep(&l, ",")) != NULL; ncol++, labv++) | |
+ *labv = tok; | |
+ *labv = NULL; | |
if (ncol < 1) | |
fputs("no label found\n", stderr), exit(1); | |
- fmt_labels(out, ncol, labels); | |
- | |
return ncol; | |
} | |
static void | |
+fmt_labels(char out[LINE_MAX], int ncol, char *labels[LINE_MAX / 2]) | |
+{ | |
+ int i; | |
+ | |
+ printf("%d\n", width); | |
+ for (i = 0; i < ncol; labels++, i++) | |
+ out += snprintf(out, width + 3, " %-*s |", width - 3, *labels); | |
+} | |
+ | |
+static void | |
usage(void) | |
{ | |
fprintf(stderr, "usage: %s maxval... <csv\n", argv0); | |
@@ -225,10 +222,12 @@ main(int argc, char **argv) | |
{ | |
double max[LINE_MAX / 2]; | |
int ncol, nmax; | |
- char labels[LINE_MAX]; | |
+ char *labv[LINE_MAX / 2], labels[LINE_MAX]; | |
nmax = parse_args(argc, argv, max); | |
- ncol = read_labels(labels); | |
+ ncol = read_labels(labv); | |
+ width = (wflag - sizeof("XXxXXxXX _|")) / ncol - sizeof("|"); | |
+ fmt_labels(labels, ncol, labv); | |
if (ncol != nmax) | |
fputs("not as many labels and arguments\n", stderr), exit(1); | |
plot(labels, max, ncol); | |
diff --git a/test.csv b/test.csv | |
@@ -1,30 +1,113 @@ | |
-epoch,value | |
-1525186140,34.691934 | |
-1525187040,34.405857 | |
-1525187940,32.498299 | |
-1525188840,27.619718 | |
-1525189740,30.942743 | |
-1525190640,32.813887 | |
-1525191540,32.230595 | |
-1525192440,30.917799 | |
-1525193340,31.829373 | |
-1525194240,30.912565 | |
-1525195140,32.899966 | |
-1525196040,31.234834 | |
-1525196940,31.196973 | |
-1525197840,30.626265 | |
-1525198740,30.734170 | |
-1525199640,29.900881 | |
-1525200540,28.375837 | |
-1525201440,28.976500 | |
-1525202340,27.949893 | |
-1525203240,26.158816 | |
-1525204140,23.383114 | |
-1525205040,26.615605 | |
-1525205940,30.636621 | |
-1525206840,28.831401 | |
-1525207740,29.878943 | |
-1525208640,22.641583 | |
-1525209540,30.158785 | |
-1525210440,30.718469 | |
-1525211340,30.369028 | |
+epoch,shortterm,midterm,longterm | |
+1525186140,0.023804,0.056885,0.049561 | |
+1525187040,0.035767,0.047485,0.043701 | |
+1525187940,0.057861,0.050293,0.042480 | |
+1525188840,0.098267,0.099609,0.072266 | |
+1525189740,0.083618,0.091187,0.079468 | |
+1525190640,0.055298,0.063843,0.063354 | |
+1525191540,0.046875,0.056152,0.058960 | |
+1525192440,0.091187,0.062622,0.058716 | |
+1525193340,0.067871,0.060303,0.059937 | |
+1525194240,0.085571,0.056763,0.052612 | |
+1525195140,0.020874,0.054810,0.055176 | |
+1525196040,0.125122,0.062500,0.048096 | |
+1525196940,0.040649,0.041870,0.040649 | |
+1525197840,0.032471,0.049194,0.042114 | |
+1525198740,0.073853,0.088501,0.071045 | |
+1525199640,0.119995,0.072998,0.064697 | |
+1525200540,0.030518,0.043335,0.046265 | |
+1525201440,0.037842,0.042969,0.040894 | |
+1525202340,0.054810,0.049927,0.042358 | |
+1525203240,0.120728,0.077271,0.053589 | |
+1525204140,0.068970,0.086670,0.074585 | |
+1525205040,0.071289,0.083496,0.079834 | |
+1525205940,0.046265,0.059326,0.068848 | |
+1525206840,0.064209,0.083374,0.069214 | |
+1525207740,0.055054,0.046753,0.051758 | |
+1525208640,0.170410,0.088867,0.064575 | |
+1525209540,0.067627,0.092407,0.092163 | |
+1525210440,0.078003,0.087646,0.083130 | |
+1525211340,0.032959,0.043457,0.059204 | |
+1525212240,0.036377,0.054810,0.057861 | |
+1525213140,0.054565,0.078369,0.071655 | |
+1525214040,0.026611,0.041138,0.051514 | |
+1525214940,0.065186,0.067505,0.061768 | |
+1525215840,0.071411,0.055298,0.055176 | |
+1525229081,0.041260,0.045044,0.045654 | |
+1525229081,0.041260,0.045044,0.045654 | |
+1525229981,0.059692,0.102051,0.105835 | |
+1525230881,0.077148,0.067017,0.073730 | |
+1525231781,0.080200,0.074341,0.064575 | |
+1525232681,0.122437,0.099487,0.075806 | |
+1525233581,0.085815,0.076050,0.073486 | |
+1525234481,0.074585,0.064087,0.062012 | |
+1525235381,0.024902,0.047241,0.053345 | |
+1525236281,0.107910,0.081543,0.065918 | |
+1525237181,0.038696,0.075684,0.080688 | |
+1525238081,0.204834,0.181152,0.130737 | |
+1525238981,0.231445,0.158325,0.137695 | |
+1525239881,0.067505,0.089355,0.109497 | |
+1525240781,0.047852,0.088745,0.107910 | |
+1525241681,0.094360,0.085693,0.083618 | |
+1525242581,0.047363,0.043335,0.052856 | |
+1525243481,0.047363,0.031982,0.036621 | |
+1525244381,0.055054,0.042236,0.040039 | |
+1525245281,0.034668,0.041626,0.040039 | |
+1525246181,0.088867,0.065918,0.048706 | |
+1525247081,0.049072,0.051880,0.042236 | |
+1525247981,0.045166,0.048828,0.041382 | |
+1525248881,0.067261,0.061768,0.047852 | |
+1525249781,0.039917,0.056519,0.045654 | |
+1525250681,0.017822,0.030273,0.033081 | |
+1525251581,0.034668,0.033691,0.034546 | |
+1525252481,0.053223,0.051880,0.045166 | |
+1525253381,0.028687,0.050049,0.050659 | |
+1525254281,0.021118,0.042358,0.040649 | |
+1525255181,0.059204,0.047974,0.041870 | |
+1525256081,0.206421,0.141968,0.086670 | |
+1525256981,0.105713,0.087158,0.073486 | |
+1525257881,0.048950,0.060913,0.068359 | |
+1525258781,0.024414,0.036621,0.046753 | |
+1525259681,0.245239,0.109619,0.071045 | |
+1525260581,0.042236,0.063965,0.069092 | |
+1525261481,0.016724,0.054077,0.059692 | |
+1525262381,0.018433,0.078003,0.076660 | |
+1525263281,0.042480,0.057617,0.061890 | |
+1525264181,0.040161,0.041138,0.044189 | |
+1525265081,0.059082,0.090698,0.064575 | |
+1525265981,0.129272,0.080811,0.073486 | |
+1525266881,0.228516,0.164551,0.112915 | |
+1525267781,0.083130,0.058594,0.067627 | |
+1525268681,0.062378,0.063965,0.061523 | |
+1525269581,0.066895,0.069702,0.062500 | |
+1525270481,0.061768,0.080322,0.065674 | |
+1525271381,0.123657,0.089478,0.072021 | |
+1525272281,0.056885,0.045532,0.051514 | |
+1525273181,0.108887,0.056519,0.046387 | |
+1525274081,0.072266,0.119629,0.080078 | |
+1525274981,0.033447,0.058350,0.070190 | |
+1525275881,0.028198,0.050781,0.058105 | |
+1525276781,0.067261,0.059937,0.057495 | |
+1525277681,0.024780,0.028809,0.038452 | |
+1525278581,0.053955,0.049561,0.041748 | |
+1525279481,0.086304,0.065308,0.048096 | |
+1525281698,0.019165,0.047485,0.041870 | |
+1525281698,0.019165,0.047485,0.041870 | |
+1525282598,0.039551,0.034302,0.038086 | |
+1525283498,0.017700,0.022827,0.026367 | |
+1525284398,0.023560,0.034790,0.024292 | |
+1525285298,0.093506,0.078857,0.053101 | |
+1525286198,0.051025,0.066162,0.069458 | |
+1525287098,0.054077,0.057861,0.059082 | |
+1525287998,0.080200,0.071655,0.062744 | |
+1525288898,0.478638,0.375122,0.247192 | |
+1525289798,0.393066,0.390991,0.347046 | |
+1525290698,0.368164,0.383545,0.365723 | |
+1525291598,0.459229,0.463867,0.432129 | |
+1525292498,0.286865,0.354980,0.381958 | |
+1525293398,0.180786,0.178833,0.232910 | |
+1525294298,0.278198,0.260864,0.242920 | |
+1525295198,0.192505,0.183716,0.200806 | |
+1525296098,0.109375,0.185669,0.207153 | |
+1525296998,0.137085,0.126221,0.138184 | |
+1525297898,0.077881,0.092529,0.109619 | |
diff --git a/util.h b/util.h | |
@@ -1,3 +1,7 @@ | |
+#define MIN(x, y) ((x) < (y) ? (x) : (y)) | |
+#define MAX(x, y) ((x) > (y) ? (x) : (y)) | |
+#define LEN(x) (sizeof(x) / sizeof(*x)) | |
+ | |
/* util.c */ | |
char *strsep (char **, const char *); | |
void estriplf (char *); |