diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index a24a6f714f1e53b5b07a87d0f22fa5ad1f7ff6ca..c9caafb9da4d6f105f7c0b71c0a527c54542888c 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -3491,7 +3491,7 @@ function gui_scalar_draw_select_rect(cid, tag, state, x1, y1, x2, y2, basex, bas }); } -function gui_scalar_draw_group(cid, tag, parent_tag, type, attr_array) { +function gui_scalar_draw_group(cid, tag, parent_tag, type, plot_style, attr_array) { gui(cid).get_elem(parent_tag) .append(function(frag) { if (!attr_array) { @@ -3499,6 +3499,10 @@ function gui_scalar_draw_group(cid, tag, parent_tag, type, attr_array) { } attr_array.push("id", tag); var group = create_item(cid, type, attr_array); + if (plot_style == 3) + { + group.style.setProperty("transform", "translateX(0.2px)"); + } frag.appendChild(group); return frag; }); diff --git a/pd/src/g_array.c b/pd/src/g_array.c index cd605e15e901452cf3e03619431937b14895aeb0..fac752ac05ea46382a875a9482539b5ee66e88bc 100644 --- a/pd/src/g_array.c +++ b/pd/src/g_array.c @@ -1553,10 +1553,10 @@ void garray_redraw(t_garray *x) */ sys_queuegui(&x->x_gobj, x->x_glist, garray_doredraw); - /* 1-24-2015 Ico: this however causes painfully slow and inefficient red - when we use tabwrite which writes one point per array and requests - redraw after each point is changed. Thus it is deprecated in favor of - of the approach above */ + /* 1-24-2015 Ico: the approach below, however causes painfully slow and + inefficient redraw when we use tabwrite which writes one point per + array and requests redraw after each point is changed. Thus it is + deprecated in favor of the approach above */ //garray_doredraw(&x->x_gobj, x->x_glist); } @@ -1950,6 +1950,12 @@ static void garray_print(t_garray *x) x->x_realname->s_name, array->a_templatesym->s_name, array->a_n); } +/* ico@vt.edu: used for scalar to detect type and thereby adjust visual offset */ +int garray_get_style(t_garray *x) +{ + return(x->x_style); +} + void g_array_setup(void) { garray_class = class_new(gensym("array"), 0, (t_method)garray_free, diff --git a/pd/src/g_graph.c b/pd/src/g_graph.c index dfbf6739ccdca2cbbbbcda8843f715ca114beb4c..b4a37cb9be3f4e958ff76475389025f261f722da 100644 --- a/pd/src/g_graph.c +++ b/pd/src/g_graph.c @@ -722,6 +722,10 @@ t_float glist_pixelstoy(t_glist *x, t_float ypix) } } +/* ico@vt.edu: used by the scalar_vis to adjust visual offset + based on the graph drawing style, affects bar graph */ +extern int garray_get_style(t_garray *x); + /* convert an x coordinate value to an x pixel location in window */ t_float glist_xtopixels(t_glist *x, t_float xval) { @@ -732,11 +736,21 @@ t_float glist_xtopixels(t_glist *x, t_float xval) (xval - x->gl_x1) / (x->gl_x2 - x->gl_x1); else { + /* ico@vt.edu: some really stupid code to compensate for the fact + that the svg stroke featue adds unaccounted width to the bars */ + t_float plot_offset = 0; + t_gobj *g = x->gl_list; + if (g != NULL && g->g_pd == garray_class) + { + t_garray *g_a = (t_garray *)g; + if (garray_get_style(g_a) == PLOTSTYLE_BARS) + plot_offset = 2; + } int x1, y1, x2, y2; if (!x->gl_owner) bug("glist_pixelstox"); graph_graphrect(&x->gl_gobj, x->gl_owner, &x1, &y1, &x2, &y2); - return (x1 + (x2 - x1) * (xval - x->gl_x1) / (x->gl_x2 - x->gl_x1)); + return (x1 + (x2 - x1 - plot_offset) * (xval - x->gl_x1) / (x->gl_x2 - x->gl_x1)); } } @@ -749,11 +763,22 @@ t_float glist_ytopixels(t_glist *x, t_float yval) (yval - x->gl_y1) / (x->gl_y2 - x->gl_y1); else { + /* ico@vt.edu: some really stupid code to compensate for the fact + that the poly and bezier tend to overlap the GOP edges */ + t_float plot_offset = 0; + t_gobj *g = x->gl_list; + if (g != NULL && g->g_pd == garray_class) + { + t_garray *g_a = (t_garray *)g; + if (garray_get_style(g_a) == PLOTSTYLE_POLY || + garray_get_style(g_a) == PLOTSTYLE_BEZ) + plot_offset = 2; + } int x1, y1, x2, y2; if (!x->gl_owner) bug("glist_pixelstoy"); graph_graphrect(&x->gl_gobj, x->gl_owner, &x1, &y1, &x2, &y2); - return (y1 + (y2 - y1) * (yval - x->gl_y1) / (x->gl_y2 - x->gl_y1)); + return (y1 + (y2 - y1 - plot_offset) * (yval - x->gl_y1) / (x->gl_y2 - x->gl_y1)); } } diff --git a/pd/src/g_scalar.c b/pd/src/g_scalar.c index 984accf40c4d82eeeb45a4253d3def5e9d2bf26d..a1f778fe710130da9f1e46fa7f4e60be4eef8355 100644 --- a/pd/src/g_scalar.c +++ b/pd/src/g_scalar.c @@ -22,6 +22,10 @@ extern t_symbol *canvas_field_templatesym; /* for "canvas" data type */ extern t_word *canvas_field_vec; /* for "canvas" data type */ extern t_gpointer *canvas_field_gp; /* parent for "canvas" data type */ +/* ico@vt.edu: used by the scalar_vis to adjust visual offset + based on the graph drawing style, affects bar graph */ +extern int garray_get_style(t_garray *x); + void word_init(t_word *data, t_template *template, t_gpointer *gp) { int i, nitems = template->t_n; @@ -925,15 +929,28 @@ static void scalar_groupvis(t_scalar *x, t_glist *owner, t_template *template, t_gobj *y; if (vis) { + /* ico@vt.edu check for the plot style if available, + so that we can adjust visual offset, as needed. + This may have to be refactored later, since there + is another identical implementation below + */ + int plot_style = -1; + t_gobj *g = owner->gl_list; + if (g != NULL && g->g_pd == garray_class) + { + t_garray *g_a = (t_garray *)g; + plot_style = garray_get_style(g_a); + } + char tagbuf[MAXPDSTRING]; sprintf(tagbuf, "dgroup%lx.%lx", (long unsigned int)gl, (long unsigned int)x->sc_vec); char parentbuf[MAXPDSTRING]; sprintf(parentbuf, "dgroup%lx.%lx", (long unsigned int)parent, (long unsigned int)x->sc_vec); - gui_start_vmess("gui_scalar_draw_group", "xsss", + gui_start_vmess("gui_scalar_draw_group", "xsssi", glist_getcanvas(owner), tagbuf, parentbuf, - group_gettype(gl)->s_name); + group_gettype(gl)->s_name, plot_style); svg_grouptogui(gl, template, x->sc_vec); gui_end_vmess(); @@ -1026,27 +1043,56 @@ static void scalar_vis(t_gobj *z, t_glist *owner, int vis) if (vis) { - t_float xscale = glist_xtopixels(owner, 1) - glist_xtopixels(owner, 0); + /* ico@vt.edu: + Check if we are a bar graph and add to it a bit of left padding. + This is done inside pdgui.js gui_scalar_new */ + int plot_style = -1; + t_gobj *g = owner->gl_list; + + if (g != NULL && g->g_pd == garray_class) + { + t_garray *g_a = (t_garray *)g; + plot_style = garray_get_style(g_a); + } + t_float xscale = ((glist_xtopixels(owner, 1) - glist_xtopixels(owner, 0))); t_float yscale = glist_ytopixels(owner, 1) - glist_ytopixels(owner, 0); + t_float nw_yoffset = 0; + switch (plot_style) + { + case 0: + nw_yoffset = -0.5; + yscale += 1; + break; + case 1: + nw_yoffset = 1.5; + break; + case 2: + nw_yoffset = 1.5; + break; + case 3: + nw_yoffset = 0.5; + yscale += 1; + break; + } /* we translate the .scalar%lx group to displace it on the tk side. This is the outermost group for the scalar, something like a poor man's viewport. Also: * the default stroke is supposed to be "none" * default fill is supposed to be black. - * stroke-linejoin should be "miter", not "round" + * stroke-linejoin should be "miter", not "round" To fix these, we set the correct fill/stroke/strokelinjoin options here on the .scalar%lx group. (Notice also that tkpath doesn't understand "None"-- instead we must send an empty symbol.) */ char tagbuf[MAXPDSTRING]; sprintf(tagbuf, "scalar%lx", (long unsigned int)x->sc_vec); - gui_vmess("gui_scalar_new", "xsiffffiii", - glist_getcanvas(owner), + gui_vmess("gui_scalar_new", "xsiffffffi", + glist_getcanvas(owner), tagbuf, glist_isselected(owner, &x->sc_gobj), xscale, 0.0, 0.0, yscale, - (int)glist_xtopixels(owner, basex), - (int)glist_ytopixels(owner, basey), + glist_xtopixels(owner, basex) + (plot_style == 3 ? 0.5 : 0), + glist_ytopixels(owner, basey) + nw_yoffset, glist_istoplevel(owner)); char groupbuf[MAXPDSTRING]; // Quick hack to make gui_scalar_draw_group more general (so we @@ -1054,8 +1100,8 @@ static void scalar_vis(t_gobj *z, t_glist *owner, int vis) sprintf(tagbuf, "scalar%lxgobj", (long unsigned int)x->sc_vec); sprintf(groupbuf, "dgroup%lx.%lx", (long unsigned int)templatecanvas, (long unsigned int)x->sc_vec); - gui_vmess("gui_scalar_draw_group", "xsss", - glist_getcanvas(owner), groupbuf, tagbuf, "g"); + gui_vmess("gui_scalar_draw_group", "xsssi", + glist_getcanvas(owner), groupbuf, tagbuf, "g", plot_style); pd_bind(&x->sc_gobj.g_pd, gensym(buf)); }