From 68b4ba170607be3106fdc482b9f79972d3756e50 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 3 Apr 2020 07:47:36 -0400 Subject: [PATCH] plots: implement remaining vertical grid types #136 --- doc/man/man3/notcurses_plot.3.md | 22 ++++++++++++++++------ include/notcurses/notcurses.h | 11 +++++------ python/src/notcurses/build_notcurses.py | 5 +---- src/input/keyplot.cpp | 4 +++- src/lib/plot.c | 21 +++++---------------- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/doc/man/man3/notcurses_plot.3.md b/doc/man/man3/notcurses_plot.3.md index 1ceff9a8f..038490aee 100644 --- a/doc/man/man3/notcurses_plot.3.md +++ b/doc/man/man3/notcurses_plot.3.md @@ -4,29 +4,37 @@ # NAME -notcurses_plot - high level widget for selecting from a set +notcurses_plot - high level widget for plotting # SYNOPSIS **#include ** ```c +typedef enum { + NCPLOT_1x1, // full block █ + NCPLOT_1x1x4, // shaded full blocks █▓▒░ + NCPLOT_2x1, // full/lower blocks █▄ + NCPLOT_4x1, // four vert levels █▆▄▂ + NCPLOT_8x1, // eight vert levels █▇▆▅▄▃▂▁ +} ncgridgeom_e; + typedef struct ncplot_options { // 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 - // use with range autodiscovery. + // dependent min and max. set both equal to 0 for + // use with domain autodiscovery. int64_t miny, maxy; - bool exponentialy; // is y-axis exponential? bool detectdomain; + bool exponentialy; // is dependent exponential? + // independent variable is vertical, not horizontal + bool vertical_indep; } ncplot_options; ``` @@ -43,6 +51,8 @@ typedef struct ncplot_options { # NOTES +**exponentialy** is not yet implemented, nor is **vertical_indep**. + # RETURN VALUES **ncplot_create** will return an error if **detectdomain** is set, and either diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index f8f7cf230..9b72ff6a9 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -2474,11 +2474,10 @@ typedef enum { NCPLOT_1x1, // full block █ NCPLOT_1x1x4, // shaded full blocks █▓▒░ NCPLOT_2x1, // full/(upper|left) blocks █▀ - NCPLOT_2x1INV,// full/(lower|right) blocks █▄ - NCPLOT_2x2, // quadrants ▖▘▝▗ ▛ ▜ ▟ ▙ ▘▗ ▖▝ + //NCPLOT_2x2, // quadrants ▖▘▝▗ ▛ ▜ ▟ ▙ ▘▗ ▖▝ NCPLOT_4x1, // four vert/horz levels █▆▄▂ / ▎▌▊█ NCPLOT_8x1, // eight vert/horz levels █▇▆▅▄▃▂▁ / ▏▎▍▌▋▊▉█ - NCPLOT_4x2, // 4 rows, 2 cols (braille) ...etc... + //NCPLOT_4x2, // 4 rows, 2 cols (braille) ...etc... } ncgridgeom_e; // Plots. Given a rectilinear area, an ncplot can graph samples along some axis. @@ -2519,8 +2518,6 @@ typedef struct ncplot_options { // applied across the domain between these two. uint64_t maxchannel; uint64_t minchannel; - // independent variable is vertical rather than horizontal - bool vertical_indep; // number of "pixels" per row x column ncgridgeom_e gridtype; // independent variable can either be a contiguous range, or a finite set @@ -2531,8 +2528,10 @@ typedef struct ncplot_options { // y axis min and max. for autodiscovery, these both must be equal to 0, // and detectdomain must be additionally be set. int64_t miny, maxy; - bool exponentialy; // is y-axis exponential? bool detectdomain; // if set, miny must == maxy + bool exponentialy; // is y-axis exponential? (not yet implemented) + // independent variable is vertical rather than horizontal + bool vertical_indep; } ncplot_options; // Use the provided plane 'n' for plotting according to the options 'opts'. diff --git a/python/src/notcurses/build_notcurses.py b/python/src/notcurses/build_notcurses.py index 0be1d85a3..cf5a70039 100644 --- a/python/src/notcurses/build_notcurses.py +++ b/python/src/notcurses/build_notcurses.py @@ -414,21 +414,18 @@ typedef enum { NCPLOT_1x1, // full block █ NCPLOT_1x1x4, // shaded full blocks █▓▒░ NCPLOT_2x1, // full/(upper|left) blocks █▀ - NCPLOT_2x1INV,// full/(lower|right) blocks █▄ - NCPLOT_2x2, // quadrants ▖▘▝▗ ▛ ▜ ▟ ▙ ▘▗ ▖▝ NCPLOT_4x1, // four vert/horz levels █▆▄▂ / ▎▌▊█ NCPLOT_8x1, // eight vert/horz levels █▇▆▅▄▃▂▁ / ▏▎▍▌▋▊▉█ - NCPLOT_4x2, // 4 rows, 2 cols (braille) ...etc... } ncgridgeom_e; 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; bool detectdomain; + bool vertical_indep; } ncplot_options; struct ncplot* ncplot_create(struct ncplane* n, const ncplot_options* opts); struct ncplane* ncplot_plane(struct ncplot* n); diff --git a/src/input/keyplot.cpp b/src/input/keyplot.cpp index 18a6adb6f..48eabc8bf 100644 --- a/src/input/keyplot.cpp +++ b/src/input/keyplot.cpp @@ -29,10 +29,12 @@ int main(void){ planes.emplace_back(6, 70, 1, 1, nullptr); planes.emplace_back(6, 70, 8, 1, nullptr); planes.emplace_back(6, 70, 15, 1, nullptr); + planes.emplace_back(6, 70, 23, 1, nullptr); + planes.emplace_back(6, 70, 31, 1, nullptr); struct ncplot_options popts{}; popts.rangex = 60; popts.detectdomain = true; - std::array plots; + std::array plots; for(auto i = 0u ; i < plots.size() ; ++i){ popts.gridtype = static_cast(i); plots[i] = ncplot_create(planes[i], &popts); diff --git a/src/lib/plot.c b/src/lib/plot.c index 7a3335141..b211f40e6 100644 --- a/src/lib/plot.c +++ b/src/lib/plot.c @@ -4,24 +4,13 @@ static const struct { ncgridgeom_e geom; const wchar_t* egcs; } geomdata[] = { - { .geom = NCPLOT_1x1, .egcs = L"█", }, - { .geom = NCPLOT_1x1x4, .egcs = L"▒░▓█", }, - { .geom = NCPLOT_2x1, .egcs = L"▄█", }, + { .geom = NCPLOT_1x1, .egcs = L"█", }, + { .geom = NCPLOT_1x1x4, .egcs = L"▒░▓█", }, + { .geom = NCPLOT_2x1, .egcs = L"▄█", }, + { .geom = NCPLOT_4x1, .egcs = L"▂▄▆█", }, + { .geom = NCPLOT_8x1, .egcs = L"▁▂▃▄▅▆▇█", }, }; -/* FIXME - NCPLOT_2x1TB, // full/upper blocks █▀ - NCPLOT_2x1BT, // full/lower blocks - NCPLOT_1x2LR, // left/full blocks ▌█ - NCPLOT_1x2RL, // right/full blocks █▐ - NCPLOT_2x2, // quadrants ▖▘▝▗ - NCPLOT_4x1, // four vert levels █▆▄▂ - NCPLOT_1x4, // four horizontal levels ▎▌▊█ - NCPLOT_8x1, // eight vert levels █▇▆▅▄▃▂▁ - NCPLOT_1x8, // eight horizontal levels ▏▎▍▌▋▊▉█ - NCPLOT_4x2, // 4 rows, 2 cols (braille) ...etc... -*/ - ncplot* ncplot_create(ncplane* n, const ncplot_options* opts){ // detectdomain requires that miny == maxy if(opts->detectdomain && opts->miny != opts->maxy){