plots: implement remaining vertical grid types #136

This commit is contained in:
nick black 2020-04-03 07:47:36 -04:00 committed by Nick Black
parent 5f3eb3dc24
commit 68b4ba1706
5 changed files with 30 additions and 33 deletions

View File

@ -4,29 +4,37 @@
# NAME
notcurses_plot - high level widget for selecting from a set
notcurses_plot - high level widget for plotting
# SYNOPSIS
**#include <notcurses.h>**
```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

View File

@ -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'.

View File

@ -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);

View File

@ -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<struct ncplot*, 3> plots;
std::array<struct ncplot*, 5> plots;
for(auto i = 0u ; i < plots.size() ; ++i){
popts.gridtype = static_cast<ncgridgeom_e>(i);
plots[i] = ncplot_create(planes[i], &popts);

View File

@ -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){