graph UI improved (unlock xaxis flag)

This commit is contained in:
Stefan Frederik 2022-01-02 04:42:15 +01:00
parent 2bbf967729
commit 2a3e9ddea4
3 changed files with 298 additions and 279 deletions

View File

@ -164,6 +164,16 @@ void start_wire(double mx, double my)
#define W_Y(y) (cy * (y) + dy)
#define G_X(x) (((x) - dx) / cx)
#define G_Y(y) (((y) - dy) / cy)
/* xctx->graph_flags:
* 1:
* 2: draw x-cursor1
* 4: draw x-cursor2
* 8: dnu, reserved, used in draw_graphs()
* 16: move cursor1
* 32: move cursor2
*/
static int waves_callback(int event, int mx, int my, KeySym key, int button, int aux, int state)
{
int digital = 0;
@ -177,7 +187,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
int divy = 5;
const char *val;
char s[30];
int n, c, i;
int i;
double xx1, xx2, yy1, yy2;
int need_redraw = 0;
double delta_threshold = 0.25;
@ -242,14 +252,6 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
xctx->graph_bottom = 0;
}
xctx->graph_master = i;
if(xctx->lastsel == 1 &&
xctx->sel_array[0].type == xRECT &&
xctx->sel_array[0].col == GRIDLAYER &&
xctx->sel_array[0].n == i ) {
xctx->graph_unlock_x = 1;
} else {
xctx->graph_unlock_x = 0;
}
zoom_m = (xctx->mousex - x1) / (x2 - x1);
/* dragging cursors when mouse is very close */
@ -295,7 +297,6 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
xctx->my_double_save = xctx->mousey_snap;
}
if(!xctx->graph_unlock_x) xctx->graph_flags |= 1;
/* lock x-axis to working graph when moving/zooming multiple graphs */
val = get_tok_value(xctx->rect[GRIDLAYER][xctx->graph_master].prop_ptr,"x1",0);
if(val[0]) wx1 = atof(val);
@ -305,70 +306,68 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
else wx2 = 1e-6;
/* second loop: after having determined the master graph do the others */
for(i=0; i< ((xctx->graph_flags & 1) ? xctx->rects[GRIDLAYER] : xctx->lastsel); i++) {
c = (xctx->graph_flags & 1) ? GRIDLAYER : xctx->sel_array[i].col;
for(i=0; i< xctx->rects[GRIDLAYER]; i++) {
xRect *r;
/* process only graph boxes */
if( (xctx->graph_flags & 1) || (xctx->sel_array[i].type == xRECT && c == GRIDLAYER) ) {
xRect *r;
n = (xctx->graph_flags & 1) ? i : xctx->sel_array[i].n;
r = &xctx->rect[GRIDLAYER][n];
if(r->flags != 1) continue;
val = get_tok_value(r->prop_ptr,"divx",0);
if(val[0]) divx = atoi(val);
else divx = 4;
val = get_tok_value(r->prop_ptr,"divy",0);
if(val[0]) divy = atoi(val);
else divy = 4;
val = get_tok_value(r->prop_ptr,"y1",0);
if(val[0]) wy1 = atof(val);
else wy1 = 0;
val = get_tok_value(r->prop_ptr,"y2",0);
if(val[0]) wy2 = atof(val);
else wy2 = 5;
val = get_tok_value(r->prop_ptr,"dataset",0);
if(val[0]) dataset = atoi(val);
else dataset = 0;
if(dataset >= xctx->graph_datasets) dataset = xctx->graph_datasets - 1;
val = get_tok_value(r->prop_ptr,"digital",0);
if(val[0]) digital = atoi(val);
else digital = 0;
calc_graph_area(GRIDLAYER, n, digital, &x1, &y1, &x2, &y2, &marginx, &marginy);
/* cache coefficients for faster graph coord transformations */
cx = (x2 - x1) / (wx2 - wx1);
dx = x1 - wx1 * cx;
cy = (y1 - y2) / (wy2 - wy1);
dy = y2 - wy1 * cy;
dbg(1, "%g %g %g %g - %d %d\n", wx1, wy1, wx2, wy2, divx, divy);
if( event == KeyPress || event == ButtonPress || event == MotionNotify ) {
/* move cursor1 */
if(event == MotionNotify && (state & Button1Mask) && (xctx->graph_flags & 16 )) {
need_redraw = 1;
}
/* move cursor2 */
else if(event == MotionNotify && (state & Button1Mask) && (xctx->graph_flags & 32 )) {
need_redraw = 1;
}
else
if(event == MotionNotify && (state & Button1Mask) && !xctx->graph_bottom) {
double delta;
if(xctx->graph_left) {
if(n == xctx->graph_master) {
delta = (wy2 - wy1) / divy;
delta_threshold = 0.01;
if(fabs(xctx->my_double_save - xctx->mousey_snap) > fabs(cy * delta) * delta_threshold) {
yy1 = wy1 + (xctx->my_double_save - xctx->mousey_snap) / cy;
yy2 = wy2 + (xctx->my_double_save - xctx->mousey_snap) / cy;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1424, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1425, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
xctx->my_double_save = xctx->mousey_snap;
need_redraw = 1;
}
}
} else {
delta = (wx2 - wx1);
r = &xctx->rect[GRIDLAYER][i];
if( !(r->flags & 1) ) continue;
val = get_tok_value(r->prop_ptr,"divx",0);
if(val[0]) divx = atoi(val);
else divx = 4;
val = get_tok_value(r->prop_ptr,"divy",0);
if(val[0]) divy = atoi(val);
else divy = 4;
val = get_tok_value(r->prop_ptr,"y1",0);
if(val[0]) wy1 = atof(val);
else wy1 = 0;
val = get_tok_value(r->prop_ptr,"y2",0);
if(val[0]) wy2 = atof(val);
else wy2 = 5;
val = get_tok_value(r->prop_ptr,"dataset",0);
if(val[0]) dataset = atoi(val);
else dataset = 0;
if(dataset >= xctx->graph_datasets) dataset = xctx->graph_datasets - 1;
val = get_tok_value(r->prop_ptr,"digital",0);
if(val[0]) digital = atoi(val);
else digital = 0;
calc_graph_area(GRIDLAYER, i, digital, &x1, &y1, &x2, &y2, &marginx, &marginy);
/* cache coefficients for faster graph coord transformations */
cx = (x2 - x1) / (wx2 - wx1);
dx = x1 - wx1 * cx;
cy = (y1 - y2) / (wy2 - wy1);
dy = y2 - wy1 * cy;
dbg(1, "%g %g %g %g - %d %d\n", wx1, wy1, wx2, wy2, divx, divy);
if( event == KeyPress || event == ButtonPress || event == MotionNotify ) {
/* move cursor1 */
if(event == MotionNotify && (state & Button1Mask) && (xctx->graph_flags & 16 )) {
need_redraw = 1;
}
/* move cursor2 */
else if(event == MotionNotify && (state & Button1Mask) && (xctx->graph_flags & 32 )) {
need_redraw = 1;
}
else /* drag waves with mouse */
if(event == MotionNotify && (state & Button1Mask) && !xctx->graph_bottom) {
double delta;
if(xctx->graph_left) {
if(i == xctx->graph_master) {
delta = (wy2 - wy1) / divy;
delta_threshold = 0.01;
if(fabs(xctx->my_double_save - xctx->mousey_snap) > fabs(cy * delta) * delta_threshold) {
yy1 = wy1 + (xctx->my_double_save - xctx->mousey_snap) / cy;
yy2 = wy2 + (xctx->my_double_save - xctx->mousey_snap) / cy;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1424, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1425, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
xctx->my_double_save = xctx->mousey_snap;
need_redraw = 1;
}
}
} else {
delta = (wx2 - wx1);
delta_threshold = 0.01;
if( r->sel || !(r->flags & 2) || i == xctx->graph_master) {
if(fabs(xctx->mx_double_save - xctx->mousex_snap) > fabs(cx * delta) * delta_threshold) {
xx1 = wx1 + (xctx->mx_double_save - xctx->mousex_snap) / cx;
xx2 = wx2 + (xctx->mx_double_save - xctx->mousex_snap) / cx;
@ -376,30 +375,34 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
my_strdup(1410, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s));
my_snprintf(s, S(s), "%g", xx2);
my_strdup(1411, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s));
/* update saved mouse position after processing all graphs */
if(i >= ((xctx->graph_flags & 1) ? xctx->rects[GRIDLAYER] : xctx->lastsel) - 1) {
xctx->mx_double_save = xctx->mousex_snap;
xctx->my_double_save = xctx->mousey_snap;
}
need_redraw = 1;
}
}
}
else if((button == Button5 && !(state & ShiftMask))) {
double delta;
if(xctx->graph_left) {
if(!digital && n == xctx->graph_master) {
delta = (wy2 - wy1) / divy;
delta_threshold = 1.0;
yy1 = wy1 + delta * delta_threshold;
yy2 = wy2 + delta * delta_threshold;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1420, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1421, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
/* update saved mouse position after processing all graphs */
if(fabs(xctx->mx_double_save - xctx->mousex_snap) > fabs(cx * delta) * delta_threshold) {
if(i >= xctx->rects[GRIDLAYER] - 1) {
xctx->mx_double_save = xctx->mousex_snap;
xctx->my_double_save = xctx->mousey_snap;
}
} else {
}
}
}
else if((button == Button5 && !(state & ShiftMask))) {
double delta;
if(xctx->graph_left) {
if(!digital && i == xctx->graph_master) {
delta = (wy2 - wy1) / divy;
delta_threshold = 1.0;
yy1 = wy1 + delta * delta_threshold;
yy2 = wy2 + delta * delta_threshold;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1420, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1421, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
if( r->sel || !(r->flags & 2) || i == xctx->graph_master) {
delta = (wx2 - wx1);
delta_threshold = 0.05;
xx1 = wx1 - delta * delta_threshold;
@ -411,50 +414,52 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
need_redraw = 1;
}
}
else if(key == XK_Left) {
double delta;
if(xctx->graph_left) {
if(!digital && n == xctx->graph_master) {
double m = G_Y(xctx->mousey);
double a = m - wy1;
double b = wy2 -m;
double delta = (wy2 - wy1);
double var = delta * 0.2;
yy2 = wy2 + var * b / delta;
yy1 = wy1 - var * a / delta;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1451, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1448, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
delta = (wx2 - wx1);
delta_threshold = 0.05;
xx1 = wx1 - delta * delta_threshold;
xx2 = wx2 - delta * delta_threshold;
my_snprintf(s, S(s), "%g", xx1);
my_strdup(1395, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s));
my_snprintf(s, S(s), "%g", xx2);
my_strdup(1396, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s));
}
else if(key == XK_Left) {
double delta;
if(xctx->graph_left) {
if(!digital && i == xctx->graph_master) {
double m = G_Y(xctx->mousey);
double a = m - wy1;
double b = wy2 -m;
double delta = (wy2 - wy1);
double var = delta * 0.2;
yy2 = wy2 + var * b / delta;
yy1 = wy1 - var * a / delta;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1451, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1448, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
delta = (wx2 - wx1);
delta_threshold = 0.05;
xx1 = wx1 - delta * delta_threshold;
xx2 = wx2 - delta * delta_threshold;
my_snprintf(s, S(s), "%g", xx1);
my_strdup(1395, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s));
my_snprintf(s, S(s), "%g", xx2);
my_strdup(1396, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s));
need_redraw = 1;
}
else if(button == Button4 && !(state & ShiftMask)) {
double delta;
if(xctx->graph_left) {
if(!digital && n == xctx->graph_master) {
delta = (wy2 - wy1) / divy;
delta_threshold = 1.0;
yy1 = wy1 - delta * delta_threshold;
yy2 = wy2 - delta * delta_threshold;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1416, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1417, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
}
else if(button == Button4 && !(state & ShiftMask)) {
double delta;
if(xctx->graph_left) {
if(!digital && i == xctx->graph_master) {
delta = (wy2 - wy1) / divy;
delta_threshold = 1.0;
yy1 = wy1 - delta * delta_threshold;
yy2 = wy2 - delta * delta_threshold;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1416, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1417, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
delta = (wx2 - wx1);
delta_threshold = 0.05;
xx1 = wx1 + delta * delta_threshold;
@ -466,52 +471,54 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
need_redraw = 1;
}
}
else if(key == XK_Right) {
double delta;
if(xctx->graph_left) {
if(!digital && n == xctx->graph_master) {
double m = G_Y(xctx->mousey);
double a = m - wy1;
double b = wy2 -m;
double delta = (wy2 - wy1);
double var = delta * 0.2;
yy2 = wy2 - var * b / delta;
yy1 = wy1 + var * a / delta;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1433, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1439, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
delta = (wx2 - wx1);
delta_threshold = 0.05;
xx1 = wx1 + delta * delta_threshold;
xx2 = wx2 + delta * delta_threshold;
my_snprintf(s, S(s), "%g", xx1);
my_strdup(1430, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s));
my_snprintf(s, S(s), "%g", xx2);
my_strdup(1431, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s));
}
else if(key == XK_Right) {
double delta;
if(xctx->graph_left) {
if(!digital && i == xctx->graph_master) {
double m = G_Y(xctx->mousey);
double a = m - wy1;
double b = wy2 -m;
double delta = (wy2 - wy1);
double var = delta * 0.2;
yy2 = wy2 - var * b / delta;
yy1 = wy1 + var * a / delta;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1433, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1439, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
delta = (wx2 - wx1);
delta_threshold = 0.05;
xx1 = wx1 + delta * delta_threshold;
xx2 = wx2 + delta * delta_threshold;
my_snprintf(s, S(s), "%g", xx1);
my_strdup(1430, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s));
my_snprintf(s, S(s), "%g", xx2);
my_strdup(1431, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s));
need_redraw = 1;
}
else if(button == Button5 && (state & ShiftMask)) {
if(xctx->graph_left) {
if(!digital && n == xctx->graph_master) {
double m = G_Y(xctx->mousey);
double a = m - wy1;
double b = wy2 -m;
double delta = (wy2 - wy1);
double var = delta * 0.2;
yy2 = wy2 + var * b / delta;
yy1 = wy1 - var * a / delta;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1447, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1436, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
}
else if(button == Button5 && (state & ShiftMask)) {
if(xctx->graph_left) {
if(!digital && i == xctx->graph_master) {
double m = G_Y(xctx->mousey);
double a = m - wy1;
double b = wy2 -m;
double delta = (wy2 - wy1);
double var = delta * 0.2;
yy2 = wy2 + var * b / delta;
yy1 = wy1 - var * a / delta;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1447, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1436, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double var = 0.2 * (wx2 -wx1);
xx2 = wx2 + var * (1 - zoom_m);
xx1 = wx1 - var * zoom_m;
@ -522,21 +529,23 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
need_redraw = 1;
}
}
else if(key == XK_Down) {
double delta;
if(xctx->graph_left) {
if(!digital && n == xctx->graph_master) {
delta = (wy2 - wy1) / divy;
delta_threshold = 1.0;
yy1 = wy1 - delta * delta_threshold;
yy2 = wy2 - delta * delta_threshold;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1434, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1435, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
}
else if(key == XK_Down) {
double delta;
if(xctx->graph_left) {
if(!digital && i == xctx->graph_master) {
delta = (wy2 - wy1) / divy;
delta_threshold = 1.0;
yy1 = wy1 - delta * delta_threshold;
yy2 = wy2 - delta * delta_threshold;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1434, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1435, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double var = 0.2 * (wx2 -wx1);
xx2 = wx2 + var * (1 - zoom_m);
xx1 = wx1 - var * zoom_m;
@ -547,23 +556,25 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
need_redraw = 1;
}
}
else if(button == Button4 && (state & ShiftMask)) {
if(xctx->graph_left) {
if(!digital && n == xctx->graph_master) {
double m = G_Y(xctx->mousey);
double a = m - wy1;
double b = wy2 -m;
double delta = (wy2 - wy1);
double var = delta * 0.2;
yy2 = wy2 - var * b / delta;
yy1 = wy1 + var * a / delta;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1419, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1444, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
}
else if(button == Button4 && (state & ShiftMask)) {
if(xctx->graph_left) {
if(!digital && i == xctx->graph_master) {
double m = G_Y(xctx->mousey);
double a = m - wy1;
double b = wy2 -m;
double delta = (wy2 - wy1);
double var = delta * 0.2;
yy2 = wy2 - var * b / delta;
yy1 = wy1 + var * a / delta;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1419, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1444, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double var = 0.2 * (wx2 - wx1);;
xx2 = wx2 - var * (1 - zoom_m);
xx1 = wx1 + var * zoom_m;
@ -574,22 +585,24 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
need_redraw = 1;
}
}
else if(key == XK_Up) {
double delta;
if(xctx->graph_left) {
if(!digital && n == xctx->graph_master) {
delta = (wy2 - wy1) / divy;
delta_threshold = 1.0;
yy1 = wy1 + delta * delta_threshold;
yy2 = wy2 + delta * delta_threshold;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1437, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1438, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
}
else if(key == XK_Up) {
double delta;
if(xctx->graph_left) {
if(!digital && i == xctx->graph_master) {
delta = (wy2 - wy1) / divy;
delta_threshold = 1.0;
yy1 = wy1 + delta * delta_threshold;
yy2 = wy2 + delta * delta_threshold;
my_snprintf(s, S(s), "%g", yy1);
my_strdup(1437, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", yy2);
my_strdup(1438, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
}
} else {
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double var = 0.2 * (wx2 -wx1);
xx2 = wx2 - var * (1 - zoom_m);
xx1 = wx1 + var * zoom_m;
@ -600,37 +613,39 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
need_redraw = 1;
}
}
else if(key == 'f') {
if(xctx->graph_values) {
if(xctx->graph_left) {
int i, j;
double v;
double min=0.0, max=0.0;
int first = 1;
char *saven, *nptr, *ntok, *node = NULL;;
my_strdup2(1426, &node, get_tok_value(r->prop_ptr,"node",0));
nptr = node;
while( (ntok = my_strtok_r(nptr, "\n\t ", &saven)) ) {
nptr = NULL;
j = get_raw_index(ntok);
if(j >= 0) {
for(i = 0; i < xctx->graph_npoints[dataset]; i++) {
v = get_raw_value(dataset, j, i);
if(first || v < min) {min = v; first = 0;}
if(first || v > max) {max = v; first = 0;}
}
}
}
else if(key == 'f') {
if(xctx->graph_values) {
if(xctx->graph_left) {
int i, j;
double v;
double min=0.0, max=0.0;
int first = 1;
char *saven, *nptr, *ntok, *node = NULL;;
my_strdup2(1426, &node, get_tok_value(r->prop_ptr,"node",0));
nptr = node;
while( (ntok = my_strtok_r(nptr, "\n\t ", &saven)) ) {
nptr = NULL;
j = get_raw_index(ntok);
if(j >= 0) {
for(i = 0; i < xctx->graph_npoints[dataset]; i++) {
v = get_raw_value(dataset, j, i);
if(first || v < min) {min = v; first = 0;}
if(first || v > max) {max = v; first = 0;}
}
}
if(max == min) max += 0.01;
min = floor_to_n_digits(min, 2);
max = ceil_to_n_digits(max, 2);
my_free(1427, &node);
my_snprintf(s, S(s), "%g", min);
my_strdup(1422, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", max);
my_strdup(1423, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
} else {
}
if(max == min) max += 0.01;
min = floor_to_n_digits(min, 2);
max = ceil_to_n_digits(max, 2);
my_free(1427, &node);
my_snprintf(s, S(s), "%g", min);
my_strdup(1422, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s));
my_snprintf(s, S(s), "%g", max);
my_strdup(1423, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s));
need_redraw = 1;
} else {
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
xx1 = get_raw_value(dataset, 0, 0);
xx2 = get_raw_value(dataset, 0, xctx->graph_npoints[dataset] -1);
my_snprintf(s, S(s), "%g", xx1);
@ -641,10 +656,12 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
}
}
}
else if( event == MotionNotify && (state & Button1Mask) && xctx->graph_bottom ) {
double wwx1, wwx2, p, delta, ccx, ddx;
if(xctx->graph_values) {
}
else if( event == MotionNotify && (state & Button1Mask) && xctx->graph_bottom ) {
double wwx1, wwx2, p, delta, ccx, ddx;
if(xctx->graph_values) {
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
delta = wx2 - wx1;
wwx1 = get_raw_value(dataset, 0, 0);
wwx2 = get_raw_value(dataset, 0, xctx->graph_npoints[dataset] - 1);
@ -660,13 +677,15 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
need_redraw = 1;
}
}
} /* if( event == KeyPress || event == ButtonPress || event == MotionNotify ) */
else if( event == ButtonRelease) {
if(button != Button3) {
xctx->ui_state &= ~GRAPHPAN;
xctx->graph_flags &= ~(16 | 32); /* clear move cursor flags */
}
else if(button == Button3) {
}
} /* if( event == KeyPress || event == ButtonPress || event == MotionNotify ) */
else if( event == ButtonRelease) {
if(button != Button3) {
xctx->ui_state &= ~GRAPHPAN;
xctx->graph_flags &= ~(16 | 32); /* clear move cursor flags */
}
else if(button == Button3) {
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double tmp;
xctx->ui_state &= ~GRAPHPAN;
xx1 = G_X(xctx->mx_double_save);
@ -679,12 +698,12 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
my_strdup(1441, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s));
need_redraw = 1;
}
} /* else if( event == ButtonRelease) */
} /* if(xctx->sel_array[i].type == xRECT && c == 2) */
}
} /* else if( event == ButtonRelease) */
if(need_redraw) {
draw_graph(GRIDLAYER, n, 1 + 8 + (xctx->graph_flags & 6) ); /* draw data in each graph box */
draw_graph(GRIDLAYER, i, 1 + 8 + (xctx->graph_flags & 6) ); /* draw data in each graph box */
}
} /* for(i=0; i<xctx->lastsel; i++) */
} /* for(i=0; i< xctx->rects[GRIDLAYER]; i++ */
draw_selection(xctx->gc[SELLAYER], 0);
#if HAS_CAIRO==1
cairo_restore(xctx->cairo_ctx);

View File

@ -1694,15 +1694,15 @@ void calc_graph_area(int c, int i, int digital, double *x1, double *y1,double *x
rw = (rx2 - rx1);
rh = (ry2 - ry1);
/* set margins */
tmp = rw * 0.1;
tmp = rw * 0.14;
*marginx = tmp < 30 ? 30 : tmp;
tmp = rh * 0.09;
tmp = rh * 0.13;
*marginy = tmp < 30 ? 30 : tmp;
/* calculate graph bounding box (container - margin)
* This is the box where plot is done */
*x1 = rx1 + *marginx;
*x2 = rx2 - *marginx / 2.4; /* less space for right margin */
*x2 = rx2 - *marginx / 2.8; /* less space for right margin */
if(digital) *y1 = ry1 + *marginy * 0.4;
else *y1 = ry1 + *marginy;
*y2 = ry2 - *marginy;
@ -1808,7 +1808,7 @@ static void draw_graph_bus_points(const char *ntok, int first, int last,
int n = dig_max_waves;
double s1 = 1.0 / n;
double s2 = s1 * .66;
double c = (wy2 - wy1) * wcnt * s1;
double c = (wy2 - wy1) * (n_nodes - wcnt) * s1;
double x1 = W_X(xctx->graph_values[sweep_idx][first]);
double x2 = W_X(xctx->graph_values[sweep_idx][last-1]);
double ylow = W_Y(c + wy2 * s2); /* swapped as xschem Y coordinates are top-bottom */
@ -1817,9 +1817,9 @@ static void draw_graph_bus_points(const char *ntok, int first, int last,
int n_bits = count_items(ntok, ",") - 1;
int *idx_arr = NULL;
Int_hashentry *entry;
unsigned long val, busval, old_busval;
unsigned long busval, old_busval;
double vth = (wy1 + wy2) / 2.0; /* A to D threshold */
double xval, xval_old;
double val, xval, xval_old;
double ydelta = fabs(yhigh - ylow);
double labsize = 0.015 * ydelta;
double charwidth = labsize * 38.0;
@ -1896,7 +1896,7 @@ static void draw_graph_points(int v, int first, int last, double scy, double sdy
int n = dig_max_waves;
double s1 = 1.0 / n;
double s2 = s1 * .66;
double c = ydelta * wcnt * s1;
double c = ydelta * (n_nodes - wcnt) * s1;
if( !digital || (c >= wy1 && c <= wy2) ) {
for(p = first ; p <= last; p++) {
@ -2192,7 +2192,7 @@ void draw_graph(int c, int i, int flags)
int n = dig_max_waves;
double xt = x1 - 10 * txtsizelab;
double delta_div_n = (wy2 - wy1) / n;
double yt = delta_div_n * (double)wcnt;
double yt = delta_div_n * (double)(n_nodes - wcnt);
if(yt <= wy2 && yt >= wy1) {
draw_string(wave_color, NOW, tmpstr, 2, 0, 0, 0, xt, W_Y(yt), digtxtsizelab, digtxtsizelab);
@ -2406,7 +2406,7 @@ void draw_graph_all(int flags)
if(xctx->draw_single_layer==-1 || c == xctx->draw_single_layer) {
if(xctx->enable_layer[c]) for(i = 0; i < xctx->rects[c]; i++) {
xRect *r = &xctx->rect[c][i];
if(r->flags == 1) {
if(r->flags & 1) {
draw_graph(c, i, flags); /* draw data in each graph box */
}
}

View File

@ -381,7 +381,7 @@ typedef struct
unsigned short sel;
char *prop_ptr;
short dash;
unsigned short flags;
unsigned short flags; /* bit0=1 for graph function, bit1=1 for unlocked x axis */
} xRect;
typedef struct