## Copyright (C) 2017 Pantxo Diribarne
##
## This program 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.
##
## This program 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 this program. If not, see .
## -*- texinfo -*-
## @deftypefn {} address@hidden =} datacursor_menu (@var{input1}, @var{input2})
##
## @seealso{}
## @end deftypefn
## Author: Pantxo Diribarne
## Created: 2017-02-10
function hm = datacursor_menu (hf = [])
if (isempty (hf))
hf = get (0, "currentfigure");
if (isempty (hf))
error ("datacursor_menu: no current figure figure ");
endif
endif
hm = uimenu ("label", "Data");
htmp = uimenu (hm, "label", "Show data cursor(s)", "callback", @update_show);
htmp = uimenu (hm, "label", "New data cursor", "callback", ...
address@hidden, htmp});
htmp = uimenu (hm, "label", "Get cursor(s) data", "callback", @data_dlg);
endfunction
function update_new (hmenu, e, hshow)
colors = {"k", "b", "r", "g"};
nc = numel (getappdata (gcbf, "__datacursor__"));
h = datacursor (gcbf);
if (nc)
if (nc < 4)
col = colors{nc+1};
else
col = rand (1,3);
endif
set (h, "color", col)
endif
update_show (hshow, [], true);
endfunction
function update_show (hmenu, e, on = [])
hc = getappdata (gcbf, "__datacursor__");
if (! isempty (hc))
if (isempty (on))
on = ifelse (all (strcmp (get (hc, "visible"), "on")), "off", "on");
endif
set (hc, "visible", on)
set (hmenu, "checked", on)
endif
endfunction
function data_dlg (hm, e)
pos = get (gcbf, "position");
hc = getappdata (gcbf, "__datacursor__");
nm = inputdlg ({"Name of the variable:"}, "Export data", 1, {"cursor_data"});
if (! isempty (nm))
for ii = 1:numel (hc)
xy = get (hc(ii), "userdata");
evalin ("base", sprintf ("%s.('%s') = [%16.16f; %16.16f];", ...
nm{1}, ["cursor" num2str(ii)], xy(1), xy(2)));
endfor
endif
endfunction