Mercurial > hg > octave-terminal
changeset 13216:434e227b100b
Improvements to plotyy.
* scripts/plot/plotyy.m: Don't use "tag" or "userdata" manage plotyy axes.
* scripts/plot/legend.m: Ditto.
* scripts/plot/private/__go_draw_axes__.m: Ditto.
* src/gl-render.cc: Ditto.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Sun, 25 Sep 2011 13:48:09 -0400 |
parents | cb8fd692b600 |
children | 08ba694723f5 |
files | scripts/plot/legend.m scripts/plot/plotyy.m scripts/plot/private/__go_draw_axes__.m src/gl-render.cc |
diffstat | 4 files changed, 34 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/legend.m +++ b/scripts/plot/legend.m @@ -119,13 +119,20 @@ ca = gca (); endif - if (strcmp (get (ca, "tag"), "plotyy")) - plty = get(ca, "userdata"); - if (isscalar (plty)) + if (ishandle (ca) && isprop (ca, "__plotyy_axes__")) + plty = get (ca, "__plotyy_axes__"); + if (isscalar (plty) && ishandle (plty)) ca = [ca, plty]; - else + elseif (iscell (plty)) ca = [ca, plty{:}]; + elseif (all (ishandle (plty))) + ca = [ca, plty(:).']; + else + error ("legend.m: This should not happen. File a bug report.") endif + ## Remove duplicates while preserving order + [~, n] = unique (ca); + ca = ca (sort (n)); endif if (nargin > 0 && all (ishandle (varargin{1})))
--- a/scripts/plot/plotyy.m +++ b/scripts/plot/plotyy.m @@ -79,7 +79,7 @@ ca = get (f, "currentaxes"); if (isempty (ca)) ax = []; - elseif (strcmp (get (ca, "tag"), "plotyy")) + elseif (ishandle (ca) && isprop (ca, "__plotyy_axes__")) ax = get (ca, "__plotyy_axes__"); else ax = ca; @@ -209,25 +209,21 @@ addlistener (ax(1), "plotboxaspectratiomode", {@update_position, ax(2)}); addlistener (ax(2), "plotboxaspectratiomode", {@update_position, ax(1)}); - ## Tag the plotyy axes, so we can use that information - ## not to mirror the y axis tick marks - set (ax, "tag", "plotyy"); - - ## Cross-reference one axis to the other in the userdata - set (ax(1), "userdata", ax(2)); - set (ax(2), "userdata", ax(1)); - ## Store the axes handles for the sister axes. - try + if (ishandle (ax(1)) && ! isprop (ax(1), "__plotyy_axes__")) addproperty ("__plotyy_axes__", ax(1), "data", ax); - catch + elseif (ishandle (ax(1))) set (ax(1), "__plotyy_axes__", ax); - end_try_catch - try + else + error ("plotyy.m: This shouldn't happen. File a bug report.") + endif + if (ishandle (ax(2)) && ! isprop (ax(2), "__plotyy_axes__")) addproperty ("__plotyy_axes__", ax(2), "data", ax); - catch + elseif (ishandle (ax(2))) set (ax(2), "__plotyy_axes__", ax); - end_try_catch + else + error ("plotyy.m: This shouldn't happen. File a bug report.") + endif endfunction %!demo
--- a/scripts/plot/private/__go_draw_axes__.m +++ b/scripts/plot/private/__go_draw_axes__.m @@ -40,10 +40,16 @@ gnuplot_term = __gnuplot_get_var__ (axis_obj.parent, "GPVAL_TERM"); ## Set to false for plotyy axes. - if (strcmp (axis_obj.tag, "plotyy")) - ymirror = false; - else - ymirror = true; + ymirror = true; + if (isfield (axis_obj, "__plotyy_axes__")) + if (all (ishandle (axis_obj.__plotyy_axes__))) + ymirror = false; + else + h = axis_obj.__plotyy_axes__; + h = h(ishandle (h)); + h = h(isprop (h, "__ploty_axes__")); + rmappdata (h, "__plotyy_axes__") + endif endif nd = __calc_dimensions__ (h);
--- a/src/gl-render.cc +++ b/src/gl-render.cc @@ -849,7 +849,7 @@ double ypTickN = props.get_ypTickN (); double zpTickN = props.get_zpTickN (); - bool plotyy = (props.get_tag () == "plotyy"); + bool plotyy = (props.has_property ("__plotyy_axes__")); // Axes box @@ -1074,7 +1074,7 @@ int wmax = 0, hmax = 0; bool tick_along_z = nearhoriz || xisinf (fx); bool mirror = props.is_box () && ystate != AXE_ANY_DIR - && (props.get_tag () != "plotyy"); + && (! props.has_property ("__plotyy_axes__")); set_color (props.get_ycolor_rgb ());