Bug in R2021a with current Point of UIAxes

21 views (last 30 days)
Hi,
I was using R2019b and made a GUI-Programm. Everything worked fine. Now i updated to R2021a and have a bug with the current Point of UIAxes.
There is a UIAxes in my GUI and I ask for the current point, if i press a Button and save the current Point in a global variable. If i click on another button I check, if the saved current Point is equal to the actual current point. The result is false in every case. I dont know why the current point is changing, it worked in R2019a, so there cant be a logic mistake.
UPDATE: I found out that in R2021a the current point is not the last point clicked in the UIAxes, it is the last point clicked in the GUI, what is absolutly without any sense!
Does anybody know how to get the last point clciked in the UIAxes and not in general?
Thanks!

Accepted Answer

Benjamin Kraus
Benjamin Kraus on 17 Nov 2021
The CurrentPoint property on UIAxes will always reflect the last click detected anywhere in the figure. That is how CurrentPoint has worked on regular axes for a long time, and how it has worked on UIAxes for as long as CurrentPoint has been supported on UIAxes. I just tested in a simple figure in R2019b and R2021a and that is the behavior I am seeing in both versions.
There was a limitation in R2019b that if you clicked within a panel (but not on a UIAxes) and on some other UI components, that click was not being detected, and therefore the CurrentPoint was not updated. If you clicked on the figure directly (not inside a panel or another container or component), those clicks would be detected and the CurrentPoint would be updated. This limitation was removed in R2020b, and I suspect that is why you are seeing this change in behavior in your app.
For example, in the picture below:
  • If you click the green dot you should see the current point reflect [0.5 0.5]. This is what you were expecting.
  • If you click the red dot you should see the current point reflect [0.1 -0.05]. Even though that dot is outside the axes, the current point will show you the place you clicked relative to the data values in the plot.
  • If you click the blue dot you should see the current point reflect [1.2 0.5], for the same reason as the red dot.
  • In R2019b, if you click anywhere in the yellow region, CurrentPoint will not be updated. This was a limitation in R2019b that has since been removed. In R2020b and later, if you click anywhere in the yellow region, CurrentPoint will be updated.
  • In R2019b, R2021a, or any other release, clicking on the figure itself (the outer region outside the yellow region), CurrentPoint will be updated.
If your goal is to record the last point clicked, then you have a few options:
  1. Use the ButtonDownFcn on the axes (or UIAxes) itself. Starting in R2020b you can use the ButtonDownFcn on UIAxes (it did not work in R2020a or earlier releases). This callback will only fire when you click on the uiaxes/axes. To use this effectively, you may need to disable HitTest on objects in the axes. See Capturing Mouse Clicks for more details.
  2. Add a WindowButtonDownFcn to the figure, and when the callback fires (a) read the CurrentPoint property on the uiaxes/axes, (b) check if the CurrentPoint is within the axes limits, and if so (c) store the CurrentPoint somewhere for use later. Unlike ButtonDownFcn on the uaixes/axes, WindowButtonDownFcn on the figure will fire even if there are other objects in the axes that get in the way.
f = uifigure;
p1 = uipanel(f,'Position',[10 10 525 400],'BackgroundColor','yellow');
p2 = uipanel(p1,'Position',[25 25 475 350]);
u = uiaxes(p2);
f.WindowButtonDownFcn = @(~,~) disp(u.CurrentPoint(1,1:2));
s = scatter(u,[0.1 0.5 1.2],[-0.05 0.5 0.5],[],eye(3),'filled');
axis(u,[0 1 0 1])
s.Clipping = 'off';
legend(u,'Location','NEO')
  2 Comments
Arne T
Arne T on 17 Nov 2021
Hi Benjamin!
Thanks for your answer, I fully get your explanation! I dont get, why this change was made, cause I cant see any advantage in this behavior, but this doesn't matter here. I like the solution with the button down function, so thank you, I will do it this way.
Benjamin Kraus
Benjamin Kraus on 17 Nov 2021
Edited: Benjamin Kraus on 9 Jan 2023
The reason for this behavior is that CurrentPoint does double-duty for both clicks (the WindowButtonDownFcn and ButtonDownFcn) and motion events (WindowButtonMotionFcn). There is a note in the documentation that says this: "The two points indicate the location of the last mouse click. However, if the figure has a WindowButtonMotionFcn callback defined, then the points indicate the last location of the mouse pointer."
The fact that CurrentPoint can reflect points outside the axes is much more useful for things like click-and-drag (which leverage the WindowButtonMotionFcn). To give a concrete example, when you are panning on an axes, you click the axes and start dragging. During the drag, the CurrentPoint continues to be updated wherever the cursor is, allowing you to keep panning even though the cursor is outside the axes.

Sign in to comment.

More Answers (1)

Sven-Olof Enfors
Sven-Olof Enfors on 8 Jan 2023
The CurrentPoint error appears only in axes drawn in a uitab (not in a figure) and only after application of savefig/openfig of the fin´bure with the uitab. Ant it is only the y- and z coordinates that are corrupted.Please run the 'cperrordemo' code below for proofs of this.
I hope this bug will be corrected in coming updates.
enfors@kth.se
function cperrordemo
%Demonstrates a bug that corrupts CurrentPoint y- & z-coordinates
% of axes in a uitab, after the figure has been saved and re-opened
% with the commands savefig/openfig.
% If the axes is drawn directly in the figure, no such error appears
% Demonstrated in MATLAB R2022b / enfors@kth.se
f1=figure;
f1.Name='Axes i FIGURE BEFORE savefig';
plotaxis=axes(f1); % Create a plotaxis in the figure
plotaxis.Box='on';
hold on
plotaxis.Tag='plotaxis';
txt='Press mouse in the axes to see the CurrentPoint';
t=plotaxis.Title;
t.String=txt;
waitforbuttonpress
disp('CurrentPoint of plotaxies in FIGURE BEFORE savefig: ')
cp1=plotaxis.CurrentPoint % Get cursor position
savefig('f1') % Save and re-open the figure
%close(f1)
f2=openfig('f1');
f2.Name='Axes i FIGURE AFTER savefig/openfig';
a2=findobj(f2,'tag','plotaxis');
axes(a2)
%msgbox(txt)
waitforbuttonpress
disp('CurrentPoint of plotaxis drawn in FIGURE AFTER savefig: ')
cp2=a2.CurrentPoint % Get coordinate for the same cursor position
%Draw the plotaxies in a uitab
%close('f2')
f3=figure;
f3.Name='Axes i UITAB BEFORE savefig';
tabgrp = uitabgroup(f3);
tabgrp.Units='normalized';
tabgrp.Position=[0 0 1 1];
tabgrp.Tag='tabgroup';
tab = uitab(tabgrp); % The graph tab
tab.Title='Plotaxis in uitab';
tab.Units='normalized';
tab.Tag='tab';
%tabgrp.SelectedTab=tab;
plotaxis2=axes(tab); % Create a plotaxis in Graph tab
plotaxis2.Box='on';
hold on
plotaxis2.Tag='plotaxis2';
t2=plotaxis2.Title;
t2.String=txt;
%msgbox(txt)
waitforbuttonpress
disp('CurrentPoint of plotaxis drawn in TAB BEFORE savefig: ')
cp3=plotaxis2.CurrentPoint % Get cursor position
savefig('f3') % Save and re-open the figure
%close(f3)
f4=openfig('f3');
f4.Name='Axes in UITAB AFTER savefig/openfig';
a2=findobj(f4,'tag','plotaxis2');
axes(a2)
%msgbox(txt)
waitforbuttonpress
disp('CurrentPoint of plotaxis drawn in TAB AFTER openfig: ')
cp4=a2.CurrentPoint % Get coordinate for the same cursor position
  1 Comment
Benjamin Kraus
Benjamin Kraus on 9 Jan 2023
Your comment starts off with "The CurrentPoint error appears only in axes drawn in a uitab (not in a figure) and only after application of savefig/openfig of the fin´bure with the uitab." There is no mention of any error messages in this question or answer, so it seems like maybe you meant this as an answer to a different question, and posted it here by mistake?
However, the rest of the post goes on to describe what look like reproduction steps and criteria to encounter an unstated error message, which makes me think maybe you meant this to be a report of an issue you are encountering and want help from the community. If you meant this as a request for help resolving an error message, my recommendation would be to create a new post, as not many people will look back at an old and already answered question.
I also suggest you reformat your question, which is written entirely in monospaced font, with no differentiation between code and your question. I also suggest including the text of any error messages you experiencing.
The end of your post says: "I hope this bug will be corrected in coming updates." I'd like to remind you that, while many MathWorks developers read this forum, it is a community forum. If you want to report bugs with MATLAB, please contact technical support.

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!