1 ## Copyright (C) 2008-2012 David Bateman
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} refreshdata ()
21 ## @deftypefnx {Function File} {} refreshdata (@var{h})
22 ## @deftypefnx {Function File} {} refreshdata (@var{h}, @var{workspace})
23 ## Evaluate any @samp{datasource} properties of the current figure and update
24 ## the plot if the corresponding data has changed. If called with one or more
25 ## arguments @var{h} is a scalar or array of figure handles to refresh. The
26 ## optional second argument @var{workspace} can take the following values.
30 ## Evaluate the datasource properties in the base workspace. (default).
33 ## Evaluate the datasource properties in the workspace of the function
34 ## that called @code{refreshdata}.
37 ## An example of the use of @code{refreshdata} is:
43 ## plot (x, y, "ydatasource", "y");
46 ## y = sin (x + 0.1*i);
53 function refreshdata (h, workspace)
62 if (!all (ishandle (h)) || !all (strcmp (get (h, "type"), "figure")))
63 error ("refreshdata: expecting a list of figure handles");
68 if ( !ischar (workspace)
69 || !(strcmpi (workspace, "base")
70 || strcmpi (workspace, "caller")))
71 error ("refreshdata: expecting WORKSPACE to be \"base\" or ""caller\"");
73 workspace = tolower (workspace);
84 fldnames = fieldnames (obj);
85 m = regexpi (fieldnames(obj), '^.+datasource$', "match");
86 idx = ! cellfun ("isempty", m);
89 props = [props; {vertcat(tmp{:})}];
94 for i = 1 : length (objs)
95 for j = 1 : length (props {i})
96 expr = get (objs(i), props{i}{j});
98 val = evalin (workspace, expr);
99 prop = props{i}{j}(1:end-6);
100 if (! isequal (get (objs(i), prop), val))
101 set (objs(i), props{i}{j}(1:end-6), val);
112 %! plot (x, y, "ydatasource", "y");
115 %! y = sin (x + 0.1 * i);
116 %! refreshdata(gcf(), "caller");