add NCPLOT_OPTION_PRINTSAMPLE #1183

dankamongmen/ltr
nick black 4 years ago
parent 5257232f2f
commit 14fa544433
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -9,7 +9,7 @@ and the project is committed to backwards compatibility.
* [Planes](#planes) ([Plane Channels API](#plane-channels-api))
* [Cells](#cells) ([Cell Channels API](#cell-channels-api))
* [Reels](#reels) ([ncreel Examples](#ncreel-examples))
* [Widgets](#widgets) ([Readers](#readers))
* [Widgets](#widgets) ([Plots](#plots)) ([Readers](#readers))
* [Channels](#channels)
* [Visuals](#visuals) ([QR codes](#qrcodes)) ([Multimedia](#multimedia)) ([Pixels](#pixels))
* [Stats](#stats)
@ -2330,6 +2330,10 @@ xxxxxxxxxxxxxxxx│Quit Ctrl+q│xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx╰─────────────╯xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```
### Plots
**FIXME**
### Readers
```c

@ -16,6 +16,7 @@ notcurses_plot - high level widget for plotting
#define NCPLOT_OPTION_VERTICALI 0x0004u
#define NCPLOT_OPTION_NODEGRADE 0x0008u
#define NCPLOT_OPTION_DETECTMAXONLY 0x0010u
#define NCPLOT_OPTION_PRINTSAMPLE 0x0020u
typedef struct ncplot_options {
// channels for the maximum and minimum levels.
@ -83,9 +84,9 @@ contribute to the plot. Supplying an **x** below the current window is an
error, and has no effect.
More granular block glyphs means more resolution in your plots, but they can
be difficult to differentiate at small text sizes. Quadrants and braille allow
be difficult to differentiate at small text sizes. Sextants and Braille allow
for more resolution on the independent variable. It can be difficult to predict
how the braille glyphs will look in a given font.
how the Braille glyphs will look in a given font.
The same **ncplot_options** struct can be used with all ncplot types. The
**flags** field is a bitmask composed of:
@ -95,13 +96,20 @@ The same **ncplot_options** struct can be used with all ncplot types. The
* **NCPLOT_OPTION_VERTICALI**: Vertical independent axis
* **NCPLOT_OPTION_NODEGRADE**: Fail rather than degrade blitter
* **NCPLOT_OPTION_DETECTMAXONLY**: Detect only max domain, not min
* **NCPLOT_OPTION_PRINTSAMPLE**: Print the most recent sample
If **NCPLOT_OPTION_LABELTICKSD** is supplied, the **legendstyle** field will be
used to style the labels. It is otherwise ignored.
If **NCPLOT_OPTION_LABELTICKSD** or **NCPLOT_OPTION_PRINTSAMPLE** is supplied,
the **legendstyle** field will be used to style the labels. It is otherwise
ignored.
The **label** is printed in the upper left, immediately to the right of the
topmost axis tick (if **NCPLOT_OPTION_LABELTICKSD** was used). The most
recent sample is printed diagonally opposite from the label (if
**NCPLOT_OPTION_PRINTSAMPLE** was used).
# NOTES
Neither **exponentially** not **vertical_indep** is yet implemented.
**NCPLOT_OPTION_VERTICALI** is not yet implemented.
# RETURN VALUES

@ -3037,6 +3037,7 @@ API int ncmenu_destroy(struct ncmenu* n);
#define NCPLOT_OPTION_VERTICALI 0x0004u // independent axis is vertical
#define NCPLOT_OPTION_NODEGRADE 0x0008u // fail rather than degrade blitter
#define NCPLOT_OPTION_DETECTMAXONLY 0x0010u // use domain detection only for max
#define NCPLOT_OPTION_PRINTSAMPLE 0x0020u // print the most recent sample
typedef struct ncplot_options {
// channels for the maximum and minimum levels. linear or exponential

@ -634,7 +634,8 @@ int fpsgraph_init(struct notcurses* nc){
ncplane_set_base(newp, "", style, channels);
ncplot_options opts;
memset(&opts, 0, sizeof(opts));
opts.flags = NCPLOT_OPTION_LABELTICKSD | NCPLOT_OPTION_EXPONENTIALD;
opts.flags = NCPLOT_OPTION_LABELTICKSD |
NCPLOT_OPTION_EXPONENTIALD;
opts.gridtype = NCBLIT_BRAILLE;
opts.legendstyle = NCSTYLE_ITALIC | NCSTYLE_BOLD;
opts.title = "frames per decisecond";

@ -209,7 +209,7 @@ int input_demo(ncpp::NotCurses* nc) {
ncpp::Plane pplane{PLOTHEIGHT, dimx, dimy - PLOTHEIGHT, 0, nullptr};
struct ncplot_options popts{};
// FIXME would be nice to switch over to exponential at some level
popts.flags = NCPLOT_OPTION_LABELTICKSD;
popts.flags = NCPLOT_OPTION_LABELTICKSD | NCPLOT_OPTION_PRINTSAMPLE;
popts.minchannels = popts.maxchannels = 0;
channels_set_fg_rgb8(&popts.minchannels, 0x40, 0x50, 0xb0);
channels_set_fg_rgb8(&popts.maxchannels, 0x40, 0xff, 0xd0);

@ -13,25 +13,22 @@ class ncppplot {
public:
// these were all originally plain C, sorry for the non-idiomatic usage FIXME
// ought admit nullptr opts FIXME
// reenable logging once #703 is done
static bool create(ncppplot<T>* ncpp, ncplane* n, const ncplot_options* opts, T miny, T maxy) {
ncplot_options zeroed = {};
if(!opts){
opts = &zeroed;
}
if(opts->flags > NCPLOT_OPTION_DETECTMAXONLY){
if(opts->flags > NCPLOT_OPTION_PRINTSAMPLE){
logwarn(ncplane_notcurses(n), "Provided unsupported flags %016jx\n", (uintmax_t)opts->flags);
}
//struct notcurses* nc = n->nc;
auto nc = ncplane_notcurses(n);
// if miny == maxy (enabling domain detection), they both must be equal to 0
if(miny == maxy && miny){
//logerror(nc, "Supplied non-zero domain detection param %d\n", miny);
ncplane_destroy(n);
return false;
}
if(opts->rangex < 0){
//logerror(nc, "Supplied negative independent range %d\n", opts->rangex);
logerror(nc, "Supplied negative independent range %d\n", opts->rangex);
ncplane_destroy(n);
return false;
}
@ -41,7 +38,7 @@ class ncppplot {
}
// DETECTMAXONLY can't be used without domain detection
if(opts->flags & NCPLOT_OPTION_DETECTMAXONLY && (miny != maxy)){
//logerror(nc, "Supplied DETECTMAXONLY without domain detection");
logerror(nc, "Supplied DETECTMAXONLY without domain detection");
ncplane_destroy(n);
return false;
}
@ -105,6 +102,7 @@ class ncppplot {
ncpp->vertical_indep = opts->flags & NCPLOT_OPTION_VERTICALI;
ncpp->exponentiali = opts->flags & NCPLOT_OPTION_EXPONENTIALD;
ncpp->detectonlymax = opts->flags & NCPLOT_OPTION_DETECTMAXONLY;
ncpp->printsample = opts->flags & NCPLOT_OPTION_PRINTSAMPLE;
if( (ncpp->detectdomain = (miny == maxy)) ){
ncpp->maxy = 0;
ncpp->miny = std::numeric_limits<T>::max();
@ -171,11 +169,11 @@ class ncppplot {
}
}
}else if(!title.empty()){
uint64_t channels = 0;
calc_gradient_channels(&channels, minchannels, minchannels,
maxchannels, maxchannels, dimy - 1, 0, dimy, dimx);
ncplane_set_channels(ncp, channels);
ncplane_printf_yx(ncp, 0, PREFIXCOLUMNS - title.length(), "%s", title.c_str());
uint64_t channels = 0;
calc_gradient_channels(&channels, minchannels, minchannels,
maxchannels, maxchannels, dimy - 1, 0, dimy, dimx);
ncplane_set_channels(ncp, channels);
ncplane_printf_yx(ncp, 0, PREFIXCOLUMNS - title.length(), "%s", title.c_str());
}
ncplane_set_styles(ncp, NCSTYLE_NONE);
if(finalx < startx){ // exit on pathologically narrow planes
@ -209,6 +207,7 @@ class ncppplot {
// we can't draw anything in a given cell.
T intervalbase = miny;
const wchar_t* egc = bset->egcs;
bool done = !bset->fill;
for(int y = 0 ; y < dimy ; ++y){
uint64_t channels = 0;
calc_gradient_channels(&channels, minchannels, minchannels,
@ -218,7 +217,6 @@ class ncppplot {
// if we've got at least one interval's worth on the number of positions
// times the number of intervals per position plus the starting offset,
// we're going to print *something*
bool done = !bset->fill;
for(int i = 0 ; i < scale ; ++i){
sumidx *= states;
if(intervalbase < gvals[i]){
@ -238,13 +236,15 @@ class ncppplot {
}else{
egcidx = 0;
}
//fprintf(stderr, "y: %d i(scale): %d gvals[%d]: %ju egcidx: %zu sumidx: %zu interval: %f intervalbase: %ju\n", y, i, i, gvals[i], egcidx, sumidx, interval, intervalbase);
}
// if we're not UTF8, we can only arrive here via NCBLIT_1x1 (otherwise
// we would have errored out during construction). even then, however,
// we need handle ASCII differently, since it can't print full block.
// in ASCII mode, egcidx != means swap colors and use space.
// in ASCII mode, sumidx != 0 means swap colors and use space. in all
// modes, sumidx == 0 means don't do shit, since we erased earlier.
//if(sumidx)fprintf(stderr, "dimy: %d y: %d x: %d sumidx: %zu egc[%zu]: %lc\n", dimy, y, x, sumidx, sumidx, egc[sumidx]);
if(sumidx){
//fprintf(stderr, "dimy: %d y: %d x: %d sumidx: %zu egc[%zu]: %lc\n", dimy, y, x, sumidx, sumidx, egc[sumidx]);
if(notcurses_canutf8(ncplane_notcurses(ncp))){
char utf8[MB_CUR_MAX + 1];
int bytes = wctomb(utf8, egc[sumidx]);
@ -283,6 +283,8 @@ class ncppplot {
}
}
}
ncplane_set_styles(ncp, legendstyle);
ncplane_printf_aligned(ncp, dimy - 1, NCALIGN_RIGHT, "%ju", (uintmax_t)slots[slotstart]);
ncplane_home(ncp);
return 0;
}
@ -422,6 +424,7 @@ class ncppplot {
bool exponentiali; // exponential independent axis
bool detectdomain; // is domain detection in effect (stretch the domain)?
bool detectonlymax; // domain detection applies only to max, not min
bool printsample; // print the most recent sample
};

Loading…
Cancel
Save