Skip to content

Commit 1f28b92

Browse files
committed
Allow deleting plots in exported plot figures
1 parent 5eefe2e commit 1f28b92

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

UI/TDVFigureWindow.m

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
properties (Constant)
44

5-
figureTag = 'twomdv-plot';
5+
figureTag = 'twomdv-plot';
6+
plotContextMenuTag = 'twomdv-plot-cm';
67

78
end
89

@@ -11,9 +12,7 @@
1112
methods (Static)
1213

1314
function addData(h, fd)
14-
if ~TDVFigureWindow.isValidFigureWindow(h)
15-
error('Invalid TWOMDV Figure Window handle');
16-
end
15+
TDVFigureWindow.checkValidFigureWindow(h);
1716

1817
figure(h);
1918

@@ -24,21 +23,42 @@ function addData(h, fd)
2423
if isa(fd, 'FdDataCollection')
2524
for i = 1:fd.length
2625
figFdc.add(fd.items{i});
27-
plot(fd.items{i}.d, fd.items{i}.f);
26+
hPlot = plot(fd.items{i}.d, fd.items{i}.f);
27+
set(hPlot ...
28+
, 'UserData', fd.items{i} ...
29+
, 'UIContextMenu', TDVFigureWindow.getContextMenu(h) ...
30+
);
2831
end
2932
else
3033
error('Invalid argument "fd".');
3134
end
3235
end
3336

34-
function [h] = create()
35-
h = figure(...
37+
function [hFig] = create()
38+
hFig = figure(...
3639
'Tag', TDVFigureWindow.figureTag ...
3740
, 'UserData', FdDataCollection() ...
3841
);
3942
xlabel('Distance (um)');
4043
ylabel('Force (pN)');
4144
hold('on');
45+
46+
% Context menu for plots
47+
hMenu = uicontextmenu(hFig, 'Tag', TDVFigureWindow.plotContextMenuTag);
48+
uimenu(hMenu ...
49+
, 'Label', 'Delete This Plot' ...
50+
, 'Callback', @(h,e) TDVFigureWindow.deleteSelectedData(hFig) ...
51+
);
52+
end
53+
54+
function deleteSelectedData(h)
55+
TDVFigureWindow.checkValidFigureWindow(h);
56+
fd = get(gco(h), 'UserData');
57+
if strcmp(get(gco(h), 'Type'), 'line') && isa(fd, 'FdData')
58+
fdc = get(h, 'UserData');
59+
fdc.remove(fd);
60+
delete(gco(h));
61+
end
4262
end
4363

4464
function [h] = findAll()
@@ -58,5 +78,23 @@ function addData(h, fd)
5878

5979
end
6080

81+
% ------------------------------------------------------------------------
82+
83+
methods (Static, Access=private)
84+
85+
function checkValidFigureWindow(h)
86+
if ~TDVFigureWindow.isValidFigureWindow(h)
87+
error('Invalid TWOMDV Figure Window handle');
88+
end
89+
end
90+
91+
function [hMenu] = getContextMenu(h)
92+
TDVFigureWindow.checkValidFigureWindow(h);
93+
hMenu = findobj(h, 'Type', 'uicontextmenu', ...
94+
'Tag', TDVFigureWindow.plotContextMenuTag);
95+
end
96+
97+
end
98+
6199
end
62100

0 commit comments

Comments
 (0)