## 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];
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")
lins = get (child, "looseinset");
if (l_involved)
lins(1) = 0.;
endif
if (b_involved)
lins(2) = 0.;
endif
if (r_involved)
lins(3) = 0.;
endif
if (t_involved)
lins(4) = 0.;
endif
set (child, "looseinset", lins);
pos = get (child, "position");
if (l_involved)
ref_box(1) = max(ref_box(1), pos(1));
endif
if (b_involved)
ref_box(2) = max(ref_box(2), pos(2));
endif
if (r_involved)
ref_box(3) = min(ref_box(3), pos(1)+pos(3));
endif
if (t_involved)
ref_box(4) = min(ref_box(4), pos(2)+pos(4));
endif
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')
lins = get (ref_axes, "looseinset");
if (l_involved)
lins(1) = 0.;
endif
if (b_involved)
lins(2) = 0.;
endif
if (r_involved)
lins(3) = 0.;
endif
if (t_involved)
lins(4) = 0.;
endif
set (ref_axes, "looseinset", lins);
pos = get (ref_axes, "position");
if (l_involved)
ref_box(1) = max(ref_box(1), pos(1));
endif
if (b_involved)
ref_box(2) = max(ref_box(2), pos(2));
endif
if (r_involved)
ref_box(3) = min(ref_box(3), pos(1)+pos(3));
endif
if (t_involved)
ref_box(4) = min(ref_box(4), pos(2)+pos(4));
endif
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})
for ax = involved
addlistener (ax, 'tightinset', address@hidden, fig})
endfor
endif
endfunction