From a2170a4291417405f29ce8219d81a631f8a6d13e Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 3 Apr 2020 01:05:28 -0400 Subject: [PATCH] ncplot: add_sample(), set_sample() #430 --- doc/man/man3/notcurses_plot.3.md | 20 ++++++++++++++++---- python/src/notcurses/build_notcurses.py | 14 ++++++++++++++ src/lib/internal.h | 5 +++++ src/lib/plot.c | 17 ++++++++++++++++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/doc/man/man3/notcurses_plot.3.md b/doc/man/man3/notcurses_plot.3.md index 00525ccd8..92c733589 100644 --- a/doc/man/man3/notcurses_plot.3.md +++ b/doc/man/man3/notcurses_plot.3.md @@ -12,11 +12,20 @@ notcurses_plot - high level widget for selecting from a set ```c typedef struct ncplot_options { - // styling of the maximum and minimum levels. - // linear interpolation will be applied across - // the domain between these two. + // channels for the maximum and minimum levels. + // lerp across the domain between these two. uint64_t maxchannel; uint64_t minchannel; + // independent variable is vertical, not horizontal + bool vertical_indep; + // number of "pixels" per row x column + ncgridgeom_e gridtype; + // independent variable is a contiguous range + uint64_t rangex; + // y axis min and max. set both equal to 0 + // for autodiscovery of range. + int64_t miny, maxy; + bool exponentialy; // is y-axis exponential? } ncplot_options; ``` @@ -24,7 +33,10 @@ typedef struct ncplot_options { **struct ncplane* ncplot_plane(struct ncplot* n);** -**void ncplot_destroy(struct ncplot* n, char\*\* item);** +**int ncplot_add_sample(struct ncplot* n, uint64_t x, int64_t y);** +**int ncplot_set_sample(struct ncplot* n, uint64_t x, int64_t y);** + +**void ncplot_destroy(struct ncplot* n);** # DESCRIPTION diff --git a/python/src/notcurses/build_notcurses.py b/python/src/notcurses/build_notcurses.py index aa0ea17fc..31c84d90d 100644 --- a/python/src/notcurses/build_notcurses.py +++ b/python/src/notcurses/build_notcurses.py @@ -410,6 +410,20 @@ int ncplane_rotate_cw(struct ncplane* n); int ncplane_rotate_ccw(struct ncplane* n); void ncplane_translate(const struct ncplane* src, const struct ncplane* dst, int* y, int* x); bool ncplane_translate_abs(const struct ncplane* n, int* y, int* x); +typedef struct ncplot_options { + uint64_t maxchannel; + uint64_t minchannel; + bool vertical_indep; + ncgridgeom_e gridtype; + uint64_t rangex; + int64_t miny, maxy; + bool exponentialy; +} ncplot_options; +struct ncplot* ncplot_create(struct ncplane* n, const ncplot_options* opts); +struct ncplane* ncplot_plane(struct ncplot* n); +int ncplot_add_sample(struct ncplot* n, uint64_t x, int64_t y); +int ncplot_set_sample(struct ncplot* n, uint64_t x, int64_t y); +void ncplot_destroy(struct ncplot* n); """) if __name__ == "__main__": diff --git a/src/lib/internal.h b/src/lib/internal.h index 16ab13d1d..621656ed3 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -153,6 +153,11 @@ typedef struct ncplot { ncplane* ncp; uint64_t maxchannel; uint64_t minchannel; + bool vertical_indep; + ncgridgeom_e gridtype; + uint64_t rangex; + int64_t miny, maxy; + bool exponentialy; } ncplot; typedef struct ncmenu { diff --git a/src/lib/plot.c b/src/lib/plot.c index 601322644..4e454d681 100644 --- a/src/lib/plot.c +++ b/src/lib/plot.c @@ -6,7 +6,12 @@ ncplot* ncplot_create(ncplane* n, const ncplot_options* opts){ ret->ncp = n; ret->maxchannel = opts->maxchannel; ret->minchannel = opts->minchannel; - // FIXME + ret->rangex = opts->rangex; + ret->miny = opts->miny; + ret->maxy = opts->maxy; + ret->vertical_indep = opts->vertical_indep; + ret->gridtype = opts->gridtype; + ret->exponentialy = opts->exponentialy; } return ret; } @@ -15,6 +20,16 @@ ncplane* ncplot_plane(ncplot* n){ return n->ncp; } +// Add to or set the value corresponding to this x. If x is beyond the current +// x window, the x window is advanced to include x, and values passing beyond +// the window are lost. The first call will place the initial window. The plot +// will be redrawn, but notcurses_render() is not called. +int ncplot_add_sample(struct ncplot* n, uint64_t x, int64_t y){ +} + +int ncplot_set_sample(struct ncplot* n, uint64_t x, int64_t y){ +} + void ncplot_destroy(ncplot* n){ if(n){ free(n);