mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
ncplot uses exclusively non-negative samples #447
This commit is contained in:
parent
85c568b3a4
commit
77dd998b05
@ -30,7 +30,7 @@ typedef struct ncplot_options {
|
||||
uint64_t rangex;
|
||||
// dependent min and max. set both equal to 0 to
|
||||
// use domain autodiscovery.
|
||||
int64_t miny, maxy;
|
||||
uint64_t miny, maxy;
|
||||
bool labelaxisd; // label dependent axis
|
||||
bool exponentialy; // is dependent exponential?
|
||||
bool vertical_indep; // vertical independent variable
|
||||
@ -41,8 +41,8 @@ typedef struct ncplot_options {
|
||||
|
||||
**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);**
|
||||
**int ncplot_add_sample(struct ncplot* n, uint64_t x, uint64_t y);**
|
||||
**int ncplot_set_sample(struct ncplot* n, uint64_t x, uint64_t y);**
|
||||
|
||||
**void ncplot_destroy(struct ncplot* n);**
|
||||
|
||||
|
@ -2558,7 +2558,7 @@ typedef struct ncplot_options {
|
||||
// resolution, the independent variable would be the range [0..3600): 3600.
|
||||
// if rangex is 0, it is dynamically set to the number of columns.
|
||||
uint64_t rangex;
|
||||
int64_t miny, maxy; // y axis min and max. for autodiscovery, set them equal.
|
||||
uint64_t miny, maxy; // y axis min and max. for autodiscovery, set them equal.
|
||||
bool labelaxisd; // generate labels for the dependent axis
|
||||
bool exponentialy; // is y-axis exponential? (not yet implemented)
|
||||
// independent variable is vertical rather than horizontal
|
||||
@ -2576,8 +2576,8 @@ API struct ncplane* ncplot_plane(struct ncplot* n);
|
||||
// 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.
|
||||
API int ncplot_add_sample(struct ncplot* n, uint64_t x, int64_t y);
|
||||
API int ncplot_set_sample(struct ncplot* n, uint64_t x, int64_t y);
|
||||
API int ncplot_add_sample(struct ncplot* n, uint64_t x, uint64_t y);
|
||||
API int ncplot_set_sample(struct ncplot* n, uint64_t x, uint64_t y);
|
||||
|
||||
API void ncplot_destroy(struct ncplot* n);
|
||||
|
||||
|
@ -420,15 +420,15 @@ typedef struct ncplot_options {
|
||||
uint64_t minchannel;
|
||||
ncgridgeom_e gridtype;
|
||||
uint64_t rangex;
|
||||
int64_t miny, maxy;
|
||||
uint64_t miny, maxy;
|
||||
bool labelaxisd;
|
||||
bool exponentialy;
|
||||
bool vertical_indep;
|
||||
} 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);
|
||||
int ncplot_add_sample(struct ncplot* n, uint64_t x, uint64_t y);
|
||||
int ncplot_set_sample(struct ncplot* n, uint64_t x, uint64_t y);
|
||||
void ncplot_destroy(struct ncplot* n);
|
||||
bool ncplane_set_scrolling(struct ncplane* n, bool scrollp);
|
||||
""")
|
||||
|
@ -161,7 +161,7 @@ typedef struct ncplot {
|
||||
// domain minimum and maximum. if detectdomain is true, these are
|
||||
// progressively enlarged/shrunk to fit the sample set. if not, samples
|
||||
// outside these bounds are counted, but the displayed range covers only this.
|
||||
int64_t miny, maxy;
|
||||
uint64_t miny, maxy;
|
||||
// circular buffer, with the oldest element at slotstart, and slotcount
|
||||
// elements. slotcount is max(columns, rangex).
|
||||
int64_t* slots;
|
||||
|
@ -18,7 +18,8 @@ redraw_plot(ncplot* n){
|
||||
ncplane_dim_yx(ncplot_plane(n), &dimy, &dimx);
|
||||
// each transition is worth this much change in value
|
||||
const size_t states = wcslen(geomdata[n->gridtype].egcs);
|
||||
double interval = (n->maxy - n->miny + 1) / ((double)dimy * states); // FIXME
|
||||
// FIXME can we not rid ourselves of this meddlesome double?
|
||||
double interval = (n->maxy - n->miny + 1) / ((double)dimy * states);
|
||||
int idx = n->slotstart;
|
||||
const int startx = n->labelaxisd ? PREFIXSTRLEN : 0;
|
||||
if(n->labelaxisd){
|
||||
@ -28,11 +29,12 @@ redraw_plot(ncplot* n){
|
||||
ncplane_putstr_yx(ncplot_plane(n), dimy - y - 1, PREFIXSTRLEN - strlen(buf), buf);
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "min: %ju max: %ju states: %zu interval: %g\n", n->miny, n->maxy, states, interval);
|
||||
for(uint64_t x = startx ; x < n->slotcount + startx ; ++x){
|
||||
if(x >= (unsigned)dimx){
|
||||
break;
|
||||
}
|
||||
int64_t gval = n->slots[idx]; // clip the value at the limits of the graph
|
||||
uint64_t gval = n->slots[idx]; // clip the value at the limits of the graph
|
||||
if(gval < n->miny){
|
||||
gval = n->miny;
|
||||
}
|
||||
@ -140,7 +142,7 @@ ncplane* ncplot_plane(ncplot* n){
|
||||
// return -1 if the value is outside of that range.
|
||||
static inline int
|
||||
update_domain(ncplot* n, uint64_t x){
|
||||
const int64_t val = n->slots[x % n->slotcount];
|
||||
const uint64_t val = n->slots[x % n->slotcount];
|
||||
if(n->detectdomain){
|
||||
if(val > n->maxy){
|
||||
n->maxy = val;
|
||||
@ -191,8 +193,8 @@ window_slide(ncplot* n, uint64_t x){
|
||||
|
||||
// x must be within n's window
|
||||
static inline void
|
||||
update_sample(ncplot* n, uint64_t x, int64_t y, bool reset){
|
||||
uint64_t idx = x/*(n->slotstart + delta)*/ % n->slotcount;
|
||||
update_sample(ncplot* n, uint64_t x, uint64_t y, bool reset){
|
||||
uint64_t idx = x % n->slotcount;
|
||||
if(reset){
|
||||
n->slots[idx] = y;
|
||||
}else{
|
||||
@ -204,7 +206,7 @@ update_sample(ncplot* n, uint64_t x, int64_t y, bool reset){
|
||||
// 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(ncplot* n, uint64_t x, int64_t y){
|
||||
int ncplot_add_sample(ncplot* n, uint64_t x, uint64_t y){
|
||||
if(window_slide(n, x)){
|
||||
return -1;
|
||||
}
|
||||
@ -215,7 +217,7 @@ int ncplot_add_sample(ncplot* n, uint64_t x, int64_t y){
|
||||
return redraw_plot(n);
|
||||
}
|
||||
|
||||
int ncplot_set_sample(ncplot* n, uint64_t x, int64_t y){
|
||||
int ncplot_set_sample(ncplot* n, uint64_t x, uint64_t y){
|
||||
if(window_slide(n, x)){
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user