Mercurial > hg > octave-nkf
changeset 16911:5ea6a6d2b83f
Fix contour() listeners.
scripts/plot/contour.m: Add tests.
scripts/plot/private/__contour__.m: Modify update_data() to set the mode
for levellist and levelstep. When levelstep is manually changed, set
the corrsponding levellist, but keep the levellistmode set to "auto".
Fix recursion.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Sat, 06 Jul 2013 14:17:30 -0400 |
parents | 8a4e53cf79c9 |
children | 6bd74153c3ae |
files | scripts/plot/contour.m scripts/plot/private/__contour__.m |
diffstat | 2 files changed, 55 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/contour.m +++ b/scripts/plot/contour.m @@ -94,3 +94,33 @@ %! contourf (x, y, z, [0.4, 0.4]); %! title ('The hole should be filled with the background color'); +%!test +%! hf = figure ("visible", "off"); +%! clf (hf); +%! unwind_protect +%! [x, y, z] = peaks (); +%! [c, h] = contour (x, y, z); +%! levellist = (-6):6; +%! set (h, "levellist", levellist); +%! assert (get (h, "levellist"), levellist) +%! assert (get (h, "levellistmode"), "manual") +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +%!test +%! hf = figure ("visible", "off"); +%! clf (hf); +%! unwind_protect +%! [x, y, z] = peaks (); +%! [c, h] = contour (x, y, z); +%! levelstep = 3; +%! set (h, "levelstep", levelstep); +%! assert (get (h, "levelstep"), levelstep) +%! assert (get (h, "levelstepmode"), "manual") +%! assert (get (h, "levellist"), (-6):levelstep:6) +%! assert (get (h, "levellistmode"), "auto") +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect +
--- a/scripts/plot/private/__contour__.m +++ b/scripts/plot/private/__contour__.m @@ -92,7 +92,7 @@ error ("__contour__: z argument must be a matrix"); endif if (length (varargin) == 4 || length (varargin) == 6) - vn = varargin {end}; + vn = varargin{end}; vnauto = false; else vnauto = true; @@ -100,6 +100,7 @@ endif if (isscalar (vn)) + ## FIXME - the levels should be determined similarly to {x,y,z}ticks lvl = linspace (min (z1(!isinf (z1))), max (z1(!isinf (z1))), vn + 2)(1:end-1); else @@ -191,8 +192,8 @@ addlistener (hg, "zlevelmode", @update_zlevel); addlistener (hg, "zlevel", @update_zlevel); - addlistener (hg, "levellist", @update_data); - addlistener (hg, "levelstep", @update_data); + addlistener (hg, "levellist", {@update_data, "levellist"}); + addlistener (hg, "levelstep", {@update_data, "levelstep"}); addlistener (hg, "levellistmode", @update_data); addlistener (hg, "levelstepmode", @update_data); @@ -435,7 +436,7 @@ "linewidth", get (h, "linewidth"), "linestyle", get (h, "linestyle")); endfunction -function update_data (h, d) +function update_data (h, d, prop = "") persistent recursive = false; if (!recursive) @@ -443,11 +444,28 @@ delete (get (h, "children")); - if (strcmpi (get (h, "levellistmode"), "manual")) + switch prop + case "levellist" + set (h, "levellistmode", "manual") + case "levelstep" + set (h, "levelstepmode", "manual") + endswitch + + if (strcmpi (get (h, "levellistmode"), "manual") + && ! strcmp (prop, "levelstep")) lvl = get (h, "levellist"); elseif (strcmpi (get (h, "levelstepmode"), "manual")) z = get (h, "zdata"); - lvl = ceil ((max(z(:)) - min (z(:)) ./ get (h, "levelstep"))); + lvs = get (h, "levelstep"); + lvl(1) = ceil (min (z(:)) / lvs) * lvs; + lvl(2) = floor (max (z(:)) / lvs) * lvs; + if (lvl(1) >= lvl(2)) + lvl = median (z(:)); + else + lvl = lvl(1) : lvs : lvl(2); + endif + set (h, "levellist", lvl); + set (h, "levellistmode", "auto"); else lvl = 10; endif @@ -488,9 +506,9 @@ add_patch_children (h); update_text (h, d); + recursive = false; endif - recursive = false; endfunction function update_text (h, d)