- When switching from custom-callback => default, there is a seeminly random peroid of time where it takes a while for the default behavoir to come back.
- When switching from default => custom-callback, there is about a 3 seconds time window where it works as desired (custom callback works along with default pan/zoom).
App Designer: Setting a callback on a plot line in uiaxes disables interactivity
8 ビュー (過去 30 日間)
古いコメントを表示
OK I've lost way too many hours on this one.
Using MATLAB 2018b.
Trying to make a multi-line plot using uiaxes in app designer, and then to add callbacks to the lines.
When I create the plot without callbacks, the plot has the nice default zoom-and-pan interactivity of uiaxes (which is different than the old legacy zoom() and pan()).
When I add the callbacks, the plot becomes non-interactive, no zoom or pan, although the lines are selectable and the callback is launched. That sucks.
Example:
plot(app.UIAxesMainPlot, sampleNumberVector, tgtDataTable{:,:});
% No problem, multi-line plot is populated and zoom/pan interactivity is OK.
Now add a callback to (for example) the last line on the plot:
app.UIAxesMainPlot.Children(end).ButtonDownFcn = createCallbackFcn(app, @lineSelected, true)
% Line objects are stored as ~.Children of the uiaxes object so I set the
% callback there.
% Clicking on the plot line launches the callback. OK. Looks good so far.
% However, plot is now 'static' and does not pan/zoom.
% Calling the legacy
pan(app.UIAxesMainPlot,'on') % or
zoom(app.UIAxesMainPlot,'on')
% does not resolve the problem, and also those are not the same as the default
% interactivity for uiaxes.
% I can hold(app.UIAxesMainPlot,'on'), plot the lines one by one, and add the
% callbacks to specific lines as I go, but I get the same result.
What am I missing here?
Is the way I'm applying the line callback somehow interfering with the callback hierarchy of the uiaxes object and wrecking the zoom/pan interactivity?
I've crawled through all the object properties and can't seem to isolate the issue.
1 件のコメント
Kent Schonert
2020 年 12 月 1 日
編集済み: Kent Schonert
2020 年 12 月 2 日
I am vexed by this issue as well.
Within the callback I wish something like was possible (maybe it is?):
function chartClick(app, hitEvent)
if hitEvent.Button ~= 1
"***process default events***
return;
end
I ended up putting a manual toggle in the UI so the user can toggle between the two behavoirs:
function MouseModeSwitch_2ValueChanged(app, event)
value = app.MouseModeSwitch_2.Value;
if value == "Pan/Zoom"
%have to replot and reset to reliably get the default pan/zoom behavior back
plot(app.UIAxes, app.DG, 'NodeLabel',table2cell(app.DG.Nodes),'Interpreter', 'none');
app.UIAxes.reset;
app.UIAxes.Children(end).PickableParts = 'none'; %dont want datatips in my digraph
else
app.UIAxes.Children(end).ButtonDownFcn = createCallbackFcn(app, @chartClick, true);
app.UIAxes.Children(end).PickableParts = 'visible';
delete(findall(app.UIAxes,'Type','hggroup')); %delete datatips
end
end
It is far from perfect.
回答 (1 件)
yu-hung lin
2019 年 4 月 15 日
I don't know the exact reason why the pan or zoom didn't work either after the callback was added , but i guessed that when we added the customized function to the buttomdownfcn it just replace the function of pan or zoom somewhere inside the matlab.
So i put the pan inside the customized function and assign it to the mouse left-click.
function lineSelected(app, event)
if strcmp(app.UIFigure.SelectionType,'normal')
pan(app.UIAxesMainPlot,'on');
end
end
It works for me. Hope that helps you.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Specifying Target for Graphics Output についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!