ckplot

Unnamed repository
Log | Files | Refs

commit 5bbd587cf75a40576c7a9c221743f3d0abe24e09
parent ed27ae4dcf7029d20ff0fd507a8a3460249990be
Author: aabacchus <ben@bvnf.space>
Date:   Sun,  3 Oct 2021 01:59:26 +0100

kplot: write axis labels onto graph if read from file

Diffstat:
MMakefile | 2+-
Mkplot.c | 20+++++++++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ .POSIX: -XCFLAGS = $(CFLAGS) -I/usr/local/include -I/usr/include/cairo -Wall -Wextra -Wpedantic +XCFLAGS = $(CFLAGS) -I/usr/local/include -I/usr/include/cairo -Wall -Wextra -Wpedantic -D_XOPEN_SOURCE=600 XLDFLAGS = $(LDFLAGS) -lkplot -L/usr/local/lib -lcsv -lcairo kplot: kplot.c diff --git a/kplot.c b/kplot.c @@ -3,6 +3,7 @@ #include <cairo.h> #include <cairo-pdf.h> #include <csv.h> +#include <errno.h> #include <kplot.h> #include <math.h> #include <string.h> @@ -107,15 +108,32 @@ main(int argc, char **argv) { points1[i].x = c->data[i][0]; points1[i].y = c->data[i][1]; } + + char *xlabel, *ylabel; + if (flag_H) { + xlabel = c->headers[0]; + ylabel = c->headers[1]; + } csv_destroy(c); struct kdata *d1; struct kplot *p; + struct kplotcfg kpcfg; + kplotcfg_defaults(&kpcfg); + if (flag_H) { + errno = 0; + kpcfg.xaxislabel = strdup(xlabel); + kpcfg.yaxislabel = strdup(ylabel); + if (errno != 0) { + perror("strdup"); + return 1; + } + } cairo_surface_t *surf; cairo_t *cr; d1 = kdata_array_alloc(points1, rows); - p = kplot_alloc(NULL); + p = kplot_alloc(&kpcfg); kplot_attach_data(p, d1, KPLOT_POINTS, NULL); kdata_destroy(d1); if (output_type == OUT_PNG)