Skip to content

Commit

Permalink
update legend callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
iChunyu committed Jun 23, 2024
1 parent f2b034e commit e4a8003
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions content/posts/matlab/legend-callback/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,18 @@ function my_legend_callback(hSrc,eventData)
% mid click to show only the selected object or show all
if strcmp(eventData.SelectionType, 'extend') && strcmp(eventData.Region, 'icon')
% get all graphic objects displayed in legend
% results may contain 'group' object create by 'bode', ignore their children
go = findobj(eventData.Peer.Parent, '-property', 'DisplayName');
K = length(go);
idx = true(K,1);
for k = 1:K
if isprop(go(k), 'Children')
if isprop(go(k).Children, 'Visible')
idx(go == go(k).Children) = false;
end
end
end
go = go(idx);
go_visible = [go.Visible];
if sum(go_visible) == 1 && isequal(go(go_visible), eventData.Peer)
for k = 1:length(go)
Expand Down
11 changes: 11 additions & 0 deletions content/posts/matlab/legend-callback/test_demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ function my_legend_callback(hSrc,eventData)
% mid click to show only the selected object or show all
if strcmp(eventData.SelectionType, 'extend') && strcmp(eventData.Region, 'icon')
% get all graphic objects displayed in legend
% results may contain 'group' object create by 'bode', ignore their children
go = findobj(eventData.Peer.Parent, '-property', 'DisplayName');
K = length(go);
idx = true(K,1);
for k = 1:K
if isprop(go(k), 'Children')
if isprop(go(k).Children, 'Visible')
idx(go == go(k).Children) = false;
end
end
end
go = go(idx);
go_visible = [go.Visible];
if sum(go_visible) == 1 && isequal(go(go_visible), eventData.Peer)
for k = 1:length(go)
Expand Down

0 comments on commit e4a8003

Please sign in to comment.