MATLAB Answers

0

App Designer: Setting a callback on a plot line in uiaxes disables interactivity

Asked by Christopher Couch on 12 Jan 2019
Latest activity Answered by yu-hung lin on 15 Apr 2019
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.

  0 Comments

Sign in to comment.

1 Answer

Answer by yu-hung lin on 15 Apr 2019

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 Comments

Sign in to comment.