Skip to content

Commit

Permalink
LinePlotReducer/DeletePlot as Nested Function
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Frisch committed Aug 29, 2017
1 parent 00aea55 commit be3252f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions LinePlotReducer.m
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,21 @@

% Listen for changes on the figure itself.
o.figure_listener = addlistener(o.h_figure, size_cb{:}, ...
@(~,~) o.RefreshData);
@(~,~) o.RefreshData);

% Define DeletePlot as Nested Function, so the figure can be deleted
% even if LinePlotReducer.m is not on Matlab's search path anymore.
function DeletePlot(o,k)
o.deleted_plots(k) = true;
if all(o.deleted_plots)
delete(o.figure_listener);
end
end

% When all of our managed plots are deleted, we need to erase
% ourselves, so we'll keep track when each is deleted.
for k = 1:length(o.h_plot)
set(o.h_plot(k), 'DeleteFcn', @(~,~) o.DeletePlot(k));
set(o.h_plot(k), 'DeleteFcn', @(~,~) DeletePlot(o,k));
end
o.deleted_plots = false(1, length(o.h_plot));

Expand All @@ -484,13 +493,6 @@

methods

function DeletePlot(o, k)
o.deleted_plots(k) = true;
if all(o.deleted_plots)
delete(o.figure_listener);
end
end

% Redraw all of the data.
function RefreshData(o)

Expand Down

0 comments on commit be3252f

Please sign in to comment.