This repository has been archived by the owner on Dec 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
select_llegend.m
138 lines (125 loc) · 5.15 KB
/
select_llegend.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
%% select_llegend
% graphical user interface for setting legend for line plots
%%
function legend = select_llegend(legend)
% created 2017/04/20 by Bas Kooijman
%% Syntax
% legend = <../select_llegend.m *select_llegend*> (legend)
%% Description
% Select or edit a legend for line plots; the active item is indicated and can be changed with button #.
% Edit line specs with button line and taxon name with button taxon.
% Edit the sequence with buttons v and ^, insert with >, remove with x.
% The sequence matters if lines will be plotted on top of each other.
%
% Input:
%
% * legend: optional (n,2)-matrix with lines (3-vector of cells) and taxa (string)
%
% Output:
%
% * legend: (m,2)-matrix with lines (3-vector of cells) and taxa (string)
%% Remarks
% Press any key when done.
% Calls <../../lib/misc/html/select_line.html *select_line*> to edit lines.
%% Example of use
% legend = select_llegend;
global legend_local i_legend Hlegend
if ~exist('legend', 'var')
legend_local = { ...
{'-'; 2; [0 0 1]}, 'Protostomata'; ...
{'-'; 2; [1 0 0]}, 'Chordata'; ...
{'-'; 2; [0 0 0]}, 'Animalia'; ...
};
else
legend_local = legend;
end
i_legend = size(legend_local,1); % default index of active item
x = 30; y = 10; % lower-left corner of button block
dx = 60; % width of button
HFig_legend = figure('Position', [500, 400, 8*dx, dx]); % initiate fig with buttons
% Component
Hnr = uicontrol('Style','pushbutton',...
'String', '#',...
'Position',[x,y,.9*dx,.5*dx], ...
'Callback', @nr_Callback);
Hline = uicontrol('Style','pushbutton',...
'String', 'line',...
'Position',[x+dx,y,.9*dx,.5*dx], ...
'Callback', @line_Callback);
Htaxon = uicontrol('Style','pushbutton',...
'String', 'taxon', ...
'Position',[x+2*dx,y, .9*dx,.5*dx], ...
'Callback', @taxon_Callback);
Hup = uicontrol('Style','pushbutton',...
'String', '^', ...
'Position',[x+3*dx,y,.9*dx,.5*dx], ...
'Callback', @up_Callback);
Hdown = uicontrol('Style','pushbutton', ...
'String','v',...
'Position',[x+4*dx,y,.9*dx,.5*dx], ...
'Callback', @down_Callback);
Hinsert = uicontrol('Style','pushbutton', ...
'String','<',...
'Position',[x+5*dx,y,.9*dx,.5*dx], ...
'Callback', @insert_Callback);
Hremove = uicontrol('Style','pushbutton', ...
'String','x',...
'Position',[x+6*dx,y,.9*dx,.5*dx], ...
'Callback', @remove_Callback);
% OK = uicontrol('Style','pushbutton', ...
% 'String','OK',...
% 'Position',[x+7*dx,y,.9*dx,.5*dx], ...
% 'Callback', 'uiresume(gcbf)');
Hlegend = shllegend(legend_local,[],[],'',i_legend);
%uiwait(gcf)
pause
close (HFig_legend); close(Hlegend);
legend = legend_local; % export to output
end
% %%% subfunctions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function C = nr_Callback(source, eventdata)
global legend_local i_legend Hlegend
list = {num2str((1:size(legend_local,1))')};
i_legend = listdlg('PromptString', 'Select #', 'ListString', list, 'Selectionmode', 'single', 'InitialValue', i_legend);
close(Hlegend); Hlegend = shllegend(legend_local,[],[],'',i_legend);
end
function C = line_Callback(source, eventdata)
global legend_local i_legend Hlegend
legend_local(i_legend,1) = {select_line(legend_local{i_legend,1})};
close(Hlegend); Hlegend = shllegend(legend_local,[],[],'',i_legend);
end
function C = taxon_Callback(source, eventdata)
global legend_local i_legend Hlegend
legend_local(i_legend,2) = {select_taxon};
close(Hlegend); Hlegend = shllegend(legend_local,[],[],'',i_legend);
end
function C = up_Callback(source, eventdata)
global legend_local i_legend Hlegend
if i_legend > 1
legend_local([i_legend-1, i_legend],:) = legend_local([i_legend, i_legend-1],:);
i_legend = i_legend - 1;
end
close(Hlegend); Hlegend = shllegend(legend_local,[],[],'',i_legend);
end
function C = down_Callback(source, eventdata)
global legend_local i_legend Hlegend
if i_legend < size(legend_local,1)
legend_local([i_legend, i_legend+1],:) = legend_local([i_legend+1, i_legend],:);
i_legend = i_legend + 1;
end
close(Hlegend); Hlegend = shllegend(legend_local,[],[],'',i_legend);
end
function C = insert_Callback(source, eventdata)
global legend_local i_legend Hlegend
N = (1:size(legend_local,1))'; % index-vector of legend items
item = {{'-', 2, [0 0 0]}, 'Animalia'}; % default marker, taxon
legend_local = [legend_local(N<i_legend,:); item; legend_local(N>=i_legend,:)];
close(Hlegend); Hlegend = shllegend(legend_local,[],[],'',i_legend);
end
function C = remove_Callback(source, eventdata)
global legend_local i_legend Hlegend
n = size(legend_local,1); N = (1:n)';
legend_local = legend_local(~(N==i_legend),:);
i_legend = max(1, i_legend - 1);
close(Hlegend); Hlegend = shllegend(legend_local,[],[],'',i_legend);
end