## Copyright (C) 2011 Konstantinos Poulios ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} __sync_subplots__ (@address@hidden) ## Undocumented internal function. ## @end deftypefn ## Author: Konstantinos Poulios ## Created: 2011-03-03 function __sync_subplots__ (h, d, fig) ref_axes = h; ref_outbox = get (ref_axes, "outerposition"); ref_outbox(3) = ref_outbox(1) + ref_outbox(3); ref_outbox(4) = ref_outbox(2) + ref_outbox(4); ref_box = [0 0 1 1]; l_align = [ref_axes]; r_align = [ref_axes]; b_align = [ref_axes]; t_align = [ref_axes]; involved = [ref_axes]; figureunits = get (fig, "units"); unwind_protect set (fig, "units", "pixels"); kids = get (fig, "children"); for child = reshape (kids, 1, numel (kids)) if (child == ref_axes) continue; endif if (strcmp (get (child, "type"), "axes")) ## Skip legend and colorbar objects. if (strcmp (get (child, "tag"), "legend") || strcmp (get (child, "tag"), "colorbar")) continue; endif outpos = get (child, "outerposition"); l_involved = false; b_involved = false; r_involved = false; t_involved = false; if (abs(outpos(1)-ref_outbox(1)) < 1e-5) l_align(end+1) = child; l_involved = true; endif if (abs(outpos(2)-ref_outbox(2)) < 1e-5) b_align(end+1) = child; b_involved = true; endif if (abs(outpos(1)+outpos(3)-ref_outbox(3)) < 1e-5) r_align(end+1) = child; r_involved = true; endif if (abs(outpos(2)+outpos(4)-ref_outbox(4)) < 1e-5) t_align(end+1) = child; t_involved = true; endif if (l_involved || b_involved || r_involved || t_involved) involved(end+1) = child; dellistener (child, "tightinset", "persistent") ref_box = subplot_box (child, ref_box, l_involved, ... b_involved, r_involved, t_involved); endif endif endfor l_involved = (length(l_align) > 1); b_involved = (length(b_align) > 1); r_involved = (length(r_align) > 1); t_involved = (length(t_align) > 1); if length(involved) > 1 dellistener (ref_axes, "tightinset", "persistent") ref_box = subplot_box (ref_axes, ref_box, l_involved, ... b_involved, r_involved, t_involved); endif if (l_involved) for ax = l_align outpos = get (ax, "outerposition"); lins = get (ax, "looseinset"); lins(1) = (ref_box(1)-outpos(1))/outpos(3); set (ax, "looseinset", lins) endfor endif if (b_involved) for ax = b_align outpos = get (ax, "outerposition"); lins = get (ax, "looseinset"); lins(2) = (ref_box(2)-outpos(2))/outpos(4); set (ax, "looseinset", lins) endfor endif if (r_involved) for ax = r_align outpos = get (ax, "outerposition"); lins = get (ax, "looseinset"); lins(3) = (outpos(1)+outpos(3)-ref_box(3))/outpos(3); set (ax, "looseinset", lins) endfor endif if (t_involved) for ax = t_align outpos = get (ax, "outerposition"); lins = get (ax, "looseinset"); lins(4) = (outpos(2)+outpos(4)-ref_box(4))/outpos(4); set (ax, "looseinset", lins) endfor endif if length(involved) > 1 addlistener (ref_axes, "tightinset", address@hidden, fig}, "persistent") for ax = involved addlistener (ax, "tightinset", address@hidden, fig}, "persistent") endfor endif unwind_protect_cleanup set (fig, "units", figureunits); end_unwind_protect endfunction function box = subplot_box (ax, box0, left, bottom, right, top) lins = get (ax, "looseinset"); if (left) lins(1) = 0.; endif if (bottom) lins(2) = 0.; endif if (right) lins(3) = 0.; endif if (top) lins(4) = 0.; endif set (ax, "looseinset", lins); pos = get (ax, "position"); if (left) box0(1) = max(box0(1), pos(1)); endif if (bottom) box0(2) = max(box0(2), pos(2)); endif if (right) box0(3) = min(box0(3), pos(1)+pos(3)); endif if (top) box0(4) = min(box0(4), pos(2)+pos(4)); endif box = box0; endfunction