Mercurial > octave
changeset 24472:19d63669d174
Don't use "userdata" property internally for legend private data.
* legend.m: Replace struct stored in "userdata" with setappdata/getappdata.
Use "handle" appdata property to store handle of graphic object referenced
by legend or by line listener objects. Use "nocallbacks" appdata property to
stop recursion in legend callbacks.
* __getlegenddata__.m, __errplot__.m, __plt__.m, axes.m,
__gnuplot_draw_axes__.m, __gnuplot_draw_figure__.m: Replace occurrences
of 'get (h, "userdata")' with 'getappdata (h, "handle")'.
* struct2hdl.m: Remove "__appdata__" property from list of properties
to restore.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 26 Dec 2017 15:23:43 -0800 |
parents | a94a1d742938 |
children | 42d099b841aa |
files | scripts/plot/appearance/__getlegenddata__.m scripts/plot/appearance/legend.m scripts/plot/draw/private/__errplot__.m scripts/plot/draw/private/__plt__.m scripts/plot/util/axes.m scripts/plot/util/private/__gnuplot_draw_axes__.m scripts/plot/util/private/__gnuplot_draw_figure__.m scripts/plot/util/struct2hdl.m |
diffstat | 8 files changed, 56 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/appearance/__getlegenddata__.m Tue Dec 26 13:32:03 2017 -0800 +++ b/scripts/plot/appearance/__getlegenddata__.m Tue Dec 26 15:23:43 2017 -0800 @@ -25,7 +25,7 @@ hplots = []; text_strings = {}; - ca = getfield (get (hlegend, "userdata"), "handle"); + ca = getappdata (hlegend, "handle"); if (numel (ca) == 1) kids = get (ca, "children"); else
--- a/scripts/plot/appearance/legend.m Tue Dec 26 13:32:03 2017 -0800 +++ b/scripts/plot/appearance/legend.m Tue Dec 26 15:23:43 2017 -0800 @@ -190,8 +190,8 @@ for i = 1 : numel (fkids) if ( strcmp (get (fkids(i), "type"), "axes") && strcmp (get (fkids(i), "tag"), "legend")) - udata = get (fkids(i), "userdata"); - if (any (ismember (udata.handle, ca))) + handle = getappdata (fkids(i), "handle"); + if (any (ismember (handle, ca))) hlegend = fkids(i); break; endif @@ -404,9 +404,7 @@ if (! isempty (hlegend)) ## Disable callbacks while modifying an existing legend - legdata = get (hlegend, "userdata"); - legdata.nocallbacks = true; - set (hlegend, "userdata", legdata); + setappdata (hlegend, "nocallbacks", true); endif if (have_labels) @@ -601,11 +599,12 @@ if (isempty (hlegend)) ## Create a legend object (axes + new properties) addprops = true; - hlegend = axes ("tag", "legend", "userdata", struct ("handle", ud), + hlegend = axes ("tag", "legend", "box", box, "xtick", [], "ytick", [], "xlim", [0, 1], "ylim", [0, 1], "activepositionproperty", "position"); + setappdata (hlegend, "handle", ud); ## Inherit fontsize from current axis ## "fontunits" should be first because it affects interpretation ## of "fontsize" property. @@ -667,8 +666,8 @@ texthandle(k) = text (0, 0, text_strings{k}, "units", "points", "horizontalalignment", halign, - txtprops{:}, - "userdata", hplots(k)); + txtprops{:}); + setappdata (texthandle(k), "handle", hplots(k)); extents = get (texthandle(k), "extent"); maxwidth = max (maxwidth, extents(3)); maxheight = max (maxheight, extents(4)); @@ -880,8 +879,8 @@ l1 = line ("xdata", ([xoffset, xoffset + linelength] + xk * xstep) / lpos(3), "ydata", [1, 1] .* (lpos(4) - yoffset - yk * ystep) / lpos(4), "color", color, "linestyle", style, "linewidth", lwidth, - "marker", "none", - "userdata", hplt); + "marker", "none"); + setappdata (l1, "handle", hplt); hobjects(end+1) = l1; endif marker = get (hplt, "marker"); @@ -892,8 +891,8 @@ "marker", marker, "markeredgecolor", get (hplt, "markeredgecolor"), "markerfacecolor", get (hplt, "markerfacecolor"), - "markersize", min (get (hplt, "markersize"),10), - "userdata", hplt); + "markersize", min (get (hplt, "markersize"),10)); + setappdata (l1, "handle", hplt); hobjects(end+1) = l1; endif @@ -927,7 +926,8 @@ "ydata", (lpos(4) - yoffset - [yk-0.3, yk-0.3, yk+0.3, yk+0.3] .* ystep) / lpos(4), "facecolor", facecolor, "edgecolor", edgecolor, - "cdata", cdata, "userdata", hplt); + "cdata", cdata); + setappdata (p1, "handle", hplt); else ## non-standard patch only making use of marker styles ## such as scatter plot. @@ -937,7 +937,8 @@ "markeredgecolor",get (hplt,"markeredgecolor"), "markerfacecolor",get (hplt,"markerfacecolor"), "markersize", min (get (hplt,"markersize"),10), - "cdata", cdata, "userdata", hplt); + "cdata", cdata); + setappdata (p1, "handle", hplt); endif hobjects(end+1) = p1; ## Copy clim from axes so that colors work out. @@ -956,7 +957,8 @@ "ydata", (lpos(4) - yoffset - [yk-0.3, yk-0.3, yk+0.3, yk+0.3] .* ystep) / lpos(4), "facecolor", facecolor, "edgecolor", edgecolor, - "cdata", cdata, "userdata", hplt); + "cdata", cdata); + setappdata (p1, "handle", hplt); hobjects(end+1) = p1; endif ## FIXME: Need listeners, as for line objects. @@ -1103,9 +1105,7 @@ endif ## Restore operation of callbacks - legdata = get (hlegend, "userdata"); - legdata.nocallbacks = false; - set (hlegend, "userdata", legdata); + setappdata (hlegend, "nocallbacks", false); if (nargout > 0) hleg = hlegend; @@ -1123,7 +1123,7 @@ if (! recursive) recursive = true; unwind_protect - hax = getfield (get (hleg, "userdata"), "handle"); + hax = getappdata (hleg, "handle"); ## Hack. Maybe store this somewhere else such as appdata. hplots = [ get(hleg, "deletefcn"){6:end} ]; text_strings = get (hleg, "string"); @@ -1261,7 +1261,7 @@ function cb_line_listener (h, ~, hlegend, linelength, update_name) ## Don't execute callbacks when legend is under construction - legdata = get (hlegend, "userdata"); + legdata = getappdata (hlegend); if (legdata.nocallbacks) return; endif @@ -1276,7 +1276,7 @@ endif else kids = get (hlegend, "children"); - kids = kids([get(kids, "userdata"){:}] == h); + kids = kids([getappdata(kids, "handle"){:}] == h); kids = kids(strcmp (get (kids, "type"), "line")); idx = strcmp (get (kids, "marker"), "none"); ll = kids (idx); @@ -1301,20 +1301,22 @@ endif if (! strcmp (linestyle, "none")) - line ("xdata", xpos1, "ydata", ypos1, "color", get (h, "color"), - "linestyle", get (h, "linestyle"), - "linewidth", min (get (h, "linewidth"), 5), - "marker", "none", - "userdata", h, "parent", hlegend); + hl = line ("xdata", xpos1, "ydata", ypos1, "color", get (h, "color"), + "linestyle", get (h, "linestyle"), + "linewidth", min (get (h, "linewidth"), 5), + "marker", "none", + "parent", hlegend); + setappdata (hl, "handle", h); endif if (! strcmp (marker, "none")) - line ("xdata", xpos2, "ydata", ypos2, "color", get (h, "color"), - "marker", marker, "markeredgecolor", get (h, "markeredgecolor"), - "markerfacecolor", get (h, "markerfacecolor"), - "markersize", min (get (h, "markersize"), 10), - "linestyle", "none", - "linewidth", min (get (h, "linewidth"), 5), - "userdata", h, "parent", hlegend); + hl = line ("xdata", xpos2, "ydata", ypos2, "color", get (h, "color"), + "marker", marker, "markeredgecolor", get (h, "markeredgecolor"), + "markerfacecolor", get (h, "markerfacecolor"), + "markersize", min (get (h, "markersize"), 10), + "linestyle", "none", + "linewidth", min (get (h, "linewidth"), 5), + "parent", hlegend); + setappdata (hl, "handle", h); endif endif @@ -1744,10 +1746,10 @@ %! hax2 = subplot (1,2,2); %! plot (1:10); %! hleg1 = legend (hax1, "foo"); -%! assert (get (hleg1, "userdata").handle, hax1); +%! assert (getappdata (hleg1, "handle"), hax1); %! assert (gca (), hax2); %! hleg2 = legend ("bar"); -%! assert (get (hleg2, "userdata").handle, gca ()); +%! assert (getappdata (hleg2, "handle"), gca ()); %! unwind_protect_cleanup %! close (h); %! end_unwind_protect
--- a/scripts/plot/draw/private/__errplot__.m Tue Dec 26 13:32:03 2017 -0800 +++ b/scripts/plot/draw/private/__errplot__.m Tue Dec 26 15:23:43 2017 -0800 @@ -257,8 +257,8 @@ for i = 1 : numel (fkids) if ( strcmp (get (fkids(i), "type"), "axes") && strcmp (get (fkids(i), "tag"), "legend")) - udata = get (fkids(i), "userdata"); - if (! isempty (intersect (udata.handle, gca ()))) + leghandle = getappdata (fkids(i), "handle"); + if (! isempty (intersect (leghandle, gca ()))) hlegend = fkids(i); break; endif
--- a/scripts/plot/draw/private/__plt__.m Tue Dec 26 13:32:03 2017 -0800 +++ b/scripts/plot/draw/private/__plt__.m Tue Dec 26 15:23:43 2017 -0800 @@ -42,8 +42,8 @@ for i = 1 : numel (fkids) if ( strcmp (get (fkids(i), "type"), "axes") && strcmp (get (fkids(i), "tag"), "legend")) - udata = get (fkids(i), "userdata"); - if (! isempty (intersect (udata.handle, gca ()))) + leghandle = getappdata (fkids(i), "handle"); + if (! isempty (intersect (leghandle, gca ()))) hlegend = fkids(i); break; endif
--- a/scripts/plot/util/axes.m Tue Dec 26 13:32:03 2017 -0800 +++ b/scripts/plot/util/axes.m Tue Dec 26 15:23:43 2017 -0800 @@ -106,11 +106,11 @@ ## Stack the legend associated with this axes on top of the axes itself hleg = hax(strcmp (get (hax, "tag"), "legend")); if (any (hleg)) - ## Get field "handle" from structure stored in "userdata" property + ## Get axes handles associated with legend if (isscalar (hleg)) - hlegaxes = get (hleg, "userdata").handle; + hlegaxes = getappdata (hleg, "handle"); else - hlegaxes = [[get(hleg, "userdata"){:}].handle](:); + hlegaxes = [getappdata(hleg, "handle"){:}](:); endif hleg = hleg(hlegaxes == h); h = [hleg; h];
--- a/scripts/plot/util/private/__gnuplot_draw_axes__.m Tue Dec 26 13:32:03 2017 -0800 +++ b/scripts/plot/util/private/__gnuplot_draw_axes__.m Tue Dec 26 15:23:43 2017 -0800 @@ -1544,7 +1544,7 @@ if (! isempty (hlgnd) && strcmp (hlgnd.visible, "on") && ! isempty (hlgnd.children) - && any (strcmp (get ([get(hlgnd.children, "userdata"){:}], "visible"), + && any (strcmp (get ([getappdata(hlgnd.children, "handle"){:}], "visible"), "on"))) if (strcmp (hlgnd.box, "on"))
--- a/scripts/plot/util/private/__gnuplot_draw_figure__.m Tue Dec 26 13:32:03 2017 -0800 +++ b/scripts/plot/util/private/__gnuplot_draw_figure__.m Tue Dec 26 15:23:43 2017 -0800 @@ -53,10 +53,10 @@ ## This is so ugly. If there was a way of getting ## gnuplot to give us the text extents of strings ## then we could get rid of this mess. - lh = getfield (get (kids(i), "userdata"), "handle"); + lh = getappdata (kids(i), "handle"); if (isscalar (lh)) ## We have a legend with a single parent. It'll be handled - ## below as a gnuplot key to the axis it corresponds to + ## below as a gnuplot key to the axis it corresponds to. continue; else ca = lh(1); @@ -91,8 +91,8 @@ if (! strcmp (get (hobj(k), "type"), "line")) continue; endif - if (get (hobj(j), "userdata") - != get (hobj(k), "userdata")) + if (getappdata (hobj(j), "handle") + != getappdata (hobj(k), "handle")) continue; endif if (! strcmp (get (hobj(k), "linestyle"), "none")) @@ -161,16 +161,15 @@ if (ishghandle (fkids (j)) && strcmp (get (fkids (j), "type"), "axes") && (strcmp (get (fkids (j), "tag"), "legend"))) - udata = get (fkids (j), "userdata"); - if (isscalar (udata.handle) - && ! isempty (intersect (udata.handle, kids (i)))) - hlegend = get (fkids (j)); + leghandle = getappdata (fkids(j), "handle"); + if (! isempty (intersect (leghandle, kids(i)))) + hlegend = get (fkids(j)); break; endif endif endfor __gnuplot_draw_axes__ (kids(i), plot_stream, enhanced, - bg_is_set, fg_is_set, hlegend); + bg_is_set, fg_is_set, hlegend); unwind_protect_cleanup ## Return axes "units" and "position" back to ## their original values.
--- a/scripts/plot/util/struct2hdl.m Tue Dec 26 13:32:03 2017 -0800 +++ b/scripts/plot/util/struct2hdl.m Tue Dec 26 15:23:43 2017 -0800 @@ -261,7 +261,7 @@ ## remove all properties such as "textposition" that redefine ## the entire legend. Also remove chidren. s.properties = rmfield (s.properties, ... - {"userdata", "xlabel",... + {"__appdata__", "xlabel",... "ylabel", "zlabel", "location", ... "title", "string","orientation", ... "visible", "textposition"}); @@ -276,7 +276,7 @@ location = s.properties.location; h = colorbar ("peer", ax, location); s.properties = rmfield (s.properties, ... - {"userdata", "xlabel" ... + {"__appdata__", "xlabel" ... "ylabel", "zlabel", ... "title", "axes"}); s.children= [];