support multiple plot per xy_plot
This commit is contained in:
@@ -55,7 +55,7 @@ static void *input_signal_plotter(void *_)
|
|||||||
iqbuf[2*i+1]*iqbuf[2*i+1]));
|
iqbuf[2*i+1]*iqbuf[2*i+1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
xy_plot_set_points(eNB_data.g, eNB_data.input_signal,
|
xy_plot_set_points(eNB_data.g, eNB_data.input_signal, 0,
|
||||||
length, x, y);
|
length, x, y);
|
||||||
|
|
||||||
if (pthread_mutex_unlock(&eNB_data.input_signal_lock)) abort();
|
if (pthread_mutex_unlock(&eNB_data.input_signal_lock)) abort();
|
||||||
@@ -70,6 +70,7 @@ void t_gui_start(void)
|
|||||||
widget *plot = new_xy_plot(g, 512, 100, "eNB 0 input signal", 20);
|
widget *plot = new_xy_plot(g, 512, 100, "eNB 0 input signal", 20);
|
||||||
widget_add_child(g, win, plot, -1);
|
widget_add_child(g, win, plot, -1);
|
||||||
xy_plot_set_range(g, plot, 0, 76800, 30, 70);
|
xy_plot_set_range(g, plot, 0, 76800, 30, 70);
|
||||||
|
xy_plot_new_plot(g, plot, FOREGROUND_COLOR);
|
||||||
|
|
||||||
eNB_data.input_signal = plot;
|
eNB_data.input_signal = plot;
|
||||||
eNB_data.input_signal_length = 76800 * 4;
|
eNB_data.input_signal_length = 76800 * 4;
|
||||||
|
|||||||
@@ -32,10 +32,11 @@ void label_set_clickable(gui *gui, widget *label, int clickable);
|
|||||||
void container_set_child_growable(gui *_gui, widget *_this,
|
void container_set_child_growable(gui *_gui, widget *_this,
|
||||||
widget *child, int growable);
|
widget *child, int growable);
|
||||||
|
|
||||||
|
int xy_plot_new_plot(gui *gui, widget *this, int color);
|
||||||
void xy_plot_set_range(gui *gui, widget *this,
|
void xy_plot_set_range(gui *gui, widget *this,
|
||||||
float xmin, float xmax, float ymin, float ymax);
|
float xmin, float xmax, float ymin, float ymax);
|
||||||
void xy_plot_set_points(gui *gui, widget *this,
|
void xy_plot_set_points(gui *gui, widget *this,
|
||||||
int npoints, float *x, float *y);
|
int plot, int npoints, float *x, float *y);
|
||||||
|
|
||||||
void textlist_add(gui *gui, widget *this, const char *text, int position,
|
void textlist_add(gui *gui, widget *this, const char *text, int position,
|
||||||
int color);
|
int color);
|
||||||
|
|||||||
@@ -95,11 +95,15 @@ struct textlist_widget {
|
|||||||
int background_color;
|
int background_color;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct xy_plot_widget {
|
struct xy_plot_plot {
|
||||||
struct widget common;
|
|
||||||
float *x;
|
float *x;
|
||||||
float *y;
|
float *y;
|
||||||
int npoints;
|
int npoints;
|
||||||
|
int color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct xy_plot_widget {
|
||||||
|
struct widget common;
|
||||||
char *label;
|
char *label;
|
||||||
int label_width;
|
int label_width;
|
||||||
int label_height;
|
int label_height;
|
||||||
@@ -109,6 +113,8 @@ struct xy_plot_widget {
|
|||||||
float ymin, ymax;
|
float ymin, ymax;
|
||||||
int wanted_width;
|
int wanted_width;
|
||||||
int wanted_height;
|
int wanted_height;
|
||||||
|
struct xy_plot_plot *plots;
|
||||||
|
int nplots;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct button_widget {
|
struct button_widget {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ static void paint(gui *_gui, widget *_this)
|
|||||||
float allocated_ymin, allocated_ymax;
|
float allocated_ymin, allocated_ymax;
|
||||||
float center;
|
float center;
|
||||||
int i;
|
int i;
|
||||||
|
int n;
|
||||||
|
|
||||||
# define FLIP(v) (-(v) + allocated_plot_height-1)
|
# define FLIP(v) (-(v) + allocated_plot_height-1)
|
||||||
|
|
||||||
@@ -134,23 +135,25 @@ static void paint(gui *_gui, widget *_this)
|
|||||||
+ this->label_baseline,
|
+ this->label_baseline,
|
||||||
this->label);
|
this->label);
|
||||||
|
|
||||||
/* points */
|
for (n = 0; n < this->nplots; n++) {
|
||||||
float ax, bx, ay, by;
|
/* points */
|
||||||
ax = (allocated_plot_width-1) / (allocated_xmax - allocated_xmin);
|
float ax, bx, ay, by;
|
||||||
bx = -ax * allocated_xmin;
|
ax = (allocated_plot_width-1) / (allocated_xmax - allocated_xmin);
|
||||||
ay = (allocated_plot_height-1) / (allocated_ymax - allocated_ymin);
|
bx = -ax * allocated_xmin;
|
||||||
by = -ay * allocated_ymin;
|
ay = (allocated_plot_height-1) / (allocated_ymax - allocated_ymin);
|
||||||
for (i = 0; i < this->npoints; i++) {
|
by = -ay * allocated_ymin;
|
||||||
int x, y;
|
for (i = 0; i < this->plots[n].npoints; i++) {
|
||||||
x = ax * this->x[i] + bx;
|
int x, y;
|
||||||
y = ay * this->y[i] + by;
|
x = ax * this->plots[n].x[i] + bx;
|
||||||
if (x >= 0 && x < allocated_plot_width &&
|
y = ay * this->plots[n].y[i] + by;
|
||||||
y >= 0 && y < allocated_plot_height)
|
if (x >= 0 && x < allocated_plot_width &&
|
||||||
x_add_point(g->x,
|
y >= 0 && y < allocated_plot_height)
|
||||||
this->common.x + this->vrule_width + x,
|
x_add_point(g->x,
|
||||||
this->common.y + FLIP(y));
|
this->common.x + this->vrule_width + x,
|
||||||
|
this->common.y + FLIP(y));
|
||||||
|
}
|
||||||
|
x_plot_points(g->x, g->xwin, this->plots[n].color);
|
||||||
}
|
}
|
||||||
x_plot_points(g->x, g->xwin, FOREGROUND_COLOR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hints(gui *_gui, widget *_w, int *width, int *height)
|
static void hints(gui *_gui, widget *_w, int *width, int *height)
|
||||||
@@ -186,6 +189,8 @@ widget *new_xy_plot(gui *_gui, int width, int height, char *label,
|
|||||||
w->xmax = 1;
|
w->xmax = 1;
|
||||||
w->ymin = -1;
|
w->ymin = -1;
|
||||||
w->ymax = 1;
|
w->ymax = 1;
|
||||||
|
w->plots = NULL;
|
||||||
|
w->nplots = 0;
|
||||||
|
|
||||||
w->common.paint = paint;
|
w->common.paint = paint;
|
||||||
w->common.hints = hints;
|
w->common.hints = hints;
|
||||||
@@ -199,6 +204,31 @@ widget *new_xy_plot(gui *_gui, int width, int height, char *label,
|
|||||||
/* public functions */
|
/* public functions */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
|
int xy_plot_new_plot(gui *_gui, widget *_this, int color)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
struct gui *g = _gui;
|
||||||
|
struct xy_plot_widget *this = _this;
|
||||||
|
|
||||||
|
glock(g);
|
||||||
|
|
||||||
|
ret = this->nplots;
|
||||||
|
|
||||||
|
this->nplots++;
|
||||||
|
this->plots = realloc(this->plots,
|
||||||
|
this->nplots * sizeof(struct xy_plot_plot));
|
||||||
|
if (this->plots == NULL) abort();
|
||||||
|
|
||||||
|
this->plots[ret].x = NULL;
|
||||||
|
this->plots[ret].y = NULL;
|
||||||
|
this->plots[ret].npoints = 0;
|
||||||
|
this->plots[ret].color = color;
|
||||||
|
|
||||||
|
gunlock(g);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void xy_plot_set_range(gui *_gui, widget *_this,
|
void xy_plot_set_range(gui *_gui, widget *_this,
|
||||||
float xmin, float xmax, float ymin, float ymax)
|
float xmin, float xmax, float ymin, float ymax)
|
||||||
{
|
{
|
||||||
@@ -217,7 +247,7 @@ void xy_plot_set_range(gui *_gui, widget *_this,
|
|||||||
gunlock(g);
|
gunlock(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
void xy_plot_set_points(gui *_gui, widget *_this,
|
void xy_plot_set_points(gui *_gui, widget *_this, int plot,
|
||||||
int npoints, float *x, float *y)
|
int npoints, float *x, float *y)
|
||||||
{
|
{
|
||||||
struct gui *g = _gui;
|
struct gui *g = _gui;
|
||||||
@@ -225,16 +255,16 @@ void xy_plot_set_points(gui *_gui, widget *_this,
|
|||||||
|
|
||||||
glock(g);
|
glock(g);
|
||||||
|
|
||||||
if (npoints != this->npoints) {
|
if (npoints != this->plots[plot].npoints) {
|
||||||
free(this->x);
|
free(this->plots[plot].x);
|
||||||
free(this->y);
|
free(this->plots[plot].y);
|
||||||
this->x = calloc(sizeof(float), npoints);
|
this->plots[plot].x = calloc(sizeof(float), npoints);
|
||||||
this->y = calloc(sizeof(float), npoints);
|
this->plots[plot].y = calloc(sizeof(float), npoints);
|
||||||
this->npoints = npoints;
|
this->plots[plot].npoints = npoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(this->x, x, npoints * sizeof(float));
|
memcpy(this->plots[plot].x, x, npoints * sizeof(float));
|
||||||
memcpy(this->y, y, npoints * sizeof(float));
|
memcpy(this->plots[plot].y, y, npoints * sizeof(float));
|
||||||
|
|
||||||
send_event(g, DIRTY, this->common.id);
|
send_event(g, DIRTY, this->common.id);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user