mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
ncplot: support legend styling
This commit is contained in:
parent
4a48baf50b
commit
5c533c9f1a
3
NEWS.md
3
NEWS.md
@ -19,6 +19,9 @@ rearrangements of Notcurses.
|
||||
RGB in a channel (they were originally in the attrword).
|
||||
* Added `ncdirect_flush()`, mainly for the benefit of FFI that might not
|
||||
have a native interface to `fflush(3)`.
|
||||
* The `ncplot_options` struct has a new field, `legendstyle`. If the
|
||||
dependent variable is being labeled, this style will be applied to the
|
||||
legend. Without NCPLOT_OPTION_LABELTICKSD, this value is ignored.
|
||||
|
||||
* 1.6.15 (2020-08-16)
|
||||
* Styles now work properly with `ncdirect`, which apparently has never
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 315 KiB After Width: | Height: | Size: 131 KiB |
@ -11,15 +11,19 @@ notcurses_plot - high level widget for plotting
|
||||
**#include <notcurses/notcurses.h>**
|
||||
|
||||
```c
|
||||
#define NCPLOT_OPTION_LABELTICKSD 0x0001
|
||||
#define NCPLOT_OPTION_EXPONENTIALD 0x0002
|
||||
#define NCPLOT_OPTION_VERTICALI 0x0004
|
||||
#define NCPLOT_OPTION_LABELTICKSD 0x0001u
|
||||
#define NCPLOT_OPTION_EXPONENTIALD 0x0002u
|
||||
#define NCPLOT_OPTION_VERTICALI 0x0004u
|
||||
#define NCPLOT_OPTION_NODEGRADE 0x0008u
|
||||
#define NCPLOT_OPTION_DETECTMAXONLY 0x0010u
|
||||
|
||||
typedef struct ncplot_options {
|
||||
// channels for the maximum and minimum levels.
|
||||
// lerp across the domain between these two.
|
||||
uint64_t maxchannel;
|
||||
uint64_t minchannel;
|
||||
// styling used for labels (NCPLOT_OPTION_LABELTICKSD)
|
||||
uint16_t legendstyle;
|
||||
// number of "pixels" per row x column
|
||||
ncblitter_e gridtype;
|
||||
// independent variable is a contiguous range
|
||||
@ -81,9 +85,14 @@ 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:
|
||||
|
||||
* **NCPLOT_OPTION_LABELTICKSD**: Label dependent axis ticks.
|
||||
* **NCPLOT_OPTION_EXPONENTIALD**: Use an exponential dependent axis.
|
||||
* **NCPLOT_OPTION_VERTICALI**: Vertical independent axis.
|
||||
* **NCPLOT_OPTION_LABELTICKSD**: Label dependent axis ticks
|
||||
* **NCPLOT_OPTION_EXPONENTIALD**: Use an exponential dependent axis
|
||||
* **NCPLOT_OPTION_VERTICALI**: Vertical independent axis
|
||||
* **NCPLOT_OPTION_NODEGRADE**: Fail rather than degrade blitter
|
||||
* **NCPLOT_OPTION_DETECTMAXONLY**: Detect only max domain, not min
|
||||
|
||||
If **NCPLOT_OPTION_LABELTICKSD** is supplied, the **legendstyle** field will be
|
||||
used to style the labels. It is otherwise ignored.
|
||||
|
||||
# NOTES
|
||||
|
||||
|
@ -2868,17 +2868,19 @@ API int ncmenu_destroy(struct ncmenu* n);
|
||||
//
|
||||
// This options structure works for both the ncuplot (uint64_t) and ncdplot
|
||||
// (double) types.
|
||||
#define NCPLOT_OPTION_LABELTICKSD 0x0001ull // show labels for dependent axis
|
||||
#define NCPLOT_OPTION_EXPONENTIALD 0x0002ull // exponential dependent axis
|
||||
#define NCPLOT_OPTION_VERTICALI 0x0004ull // independent axis is vertical
|
||||
#define NCPLOT_OPTION_NODEGRADE 0x0008ull // fail rather than degrade blitter
|
||||
#define NCPLOT_OPTION_DETECTMAXONLY 0x0010ull // use domain detection only for max
|
||||
#define NCPLOT_OPTION_LABELTICKSD 0x0001u // show labels for dependent axis
|
||||
#define NCPLOT_OPTION_EXPONENTIALD 0x0002u // exponential dependent axis
|
||||
#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
|
||||
|
||||
typedef struct ncplot_options {
|
||||
// channels for the maximum and minimum levels. linear or exponential
|
||||
// interpolation will be applied across the domain between these two.
|
||||
uint64_t maxchannel;
|
||||
uint64_t minchannel;
|
||||
// styling used for the legend, if NCPLOT_OPTION_LABELTICKSD is set
|
||||
uint16_t legendstyle;
|
||||
// if you don't care, pass NCBLIT_DEFAULT and get NCBLIT_8x1 (assuming
|
||||
// UTF8) or NCBLIT_1x1 (in an ASCII environment)
|
||||
ncblitter_e gridtype; // number of "pixels" per row x column
|
||||
|
@ -350,6 +350,7 @@ bool ncplane_translate_abs(const struct ncplane* n, int* y, int* x);
|
||||
typedef struct ncplot_options {
|
||||
uint64_t maxchannel;
|
||||
uint64_t minchannel;
|
||||
uint16_t legendstyle;
|
||||
ncblitter_e gridtype;
|
||||
uint64_t rangex;
|
||||
unsigned flags;
|
||||
|
@ -64,6 +64,7 @@ class ncppplot {
|
||||
if(dimx < ncpp->rangex){
|
||||
ncpp->slotcount = scaleddim;
|
||||
}
|
||||
ncpp->legendstyle = opts->legendstyle;
|
||||
if( (ncpp->labelaxisd = opts->flags & NCPLOT_OPTION_LABELTICKSD) ){
|
||||
if(ncpp->slotcount + scaledprefixlen > scaleddim){
|
||||
if(scaleddim > scaledprefixlen){
|
||||
@ -128,6 +129,7 @@ class ncppplot {
|
||||
const int finalx = (slotcount < scaleddim - 1 - (startx * scale) ? startx + (slotcount / scale) - 1 : dimx - 1);
|
||||
if(labelaxisd){
|
||||
// show the *top* of each interval range
|
||||
ncplane_set_attr(ncp, legendstyle);
|
||||
for(int y = 0 ; y < dimy ; ++y){
|
||||
uint64_t channels = 0;
|
||||
calc_gradient_channels(&channels, maxchannel, maxchannel,
|
||||
@ -145,6 +147,7 @@ class ncppplot {
|
||||
}
|
||||
ncplane_printf_yx(ncp, dimy - y - 1, PREFIXCOLUMNS - strlen(buf), "%s", buf);
|
||||
}
|
||||
ncplane_set_attr(ncp, NCSTYLE_NONE);
|
||||
}
|
||||
if(finalx < startx){ // exit on pathologically narrow planes
|
||||
return 0;
|
||||
@ -362,6 +365,7 @@ class ncppplot {
|
||||
|
||||
uint64_t maxchannel;
|
||||
uint64_t minchannel;
|
||||
uint16_t legendstyle;
|
||||
bool vertical_indep; // not yet implemented FIXME
|
||||
const struct blitset* bset;
|
||||
// requested number of slots. 0 for automatically setting the number of slots
|
||||
|
@ -6,6 +6,7 @@ using namespace ncpp;
|
||||
ncplot_options PlotD::default_options = {
|
||||
0, // maxchannel
|
||||
0, // minchannel
|
||||
0, // legendstyle
|
||||
ncblitter_e::NCBLIT_1x1, // ncblitter_e
|
||||
0, // rangex
|
||||
0, // flags
|
||||
@ -14,6 +15,7 @@ ncplot_options PlotD::default_options = {
|
||||
ncplot_options PlotU::default_options = {
|
||||
0, // maxchannel
|
||||
0, // minchannel
|
||||
0, // legendstyle
|
||||
ncblitter_e::NCBLIT_1x1, // ncblitter_e
|
||||
0, // rangex
|
||||
0, // flags
|
||||
|
Loading…
x
Reference in New Issue
Block a user