Disable Datatips on click

42 views (last 30 days)
Nick Donatelli
Nick Donatelli on 16 Jun 2020
Commented: Tommy on 17 Jun 2020
I've run into some difficulty deleting Datatips on a GUI I'm building using geoaxes and geoplot.
My Scenario: (R2019b)
My GUI has a geoaxes which is plotting multiple lines using a timer function; the geoaxes is updating every 1 second. For the lines being plotted I've set a ButtonDownFcn callback to a function that changes the color of all lines; one color for the selected line, and another color for the rest of the lines. There are more callbacks that this queues as well, but the baseline is I need to update when a specific line is selected.
All of this works correctly, and as it should, but when I click on a line I have a datatip appear, and it follows the clicked line as its data points update. I don't want this to happen, I haven't found any resources that can successfully disable datatips.
Solutions I've found have included disableDefaultInteractivity, delete(findall(gcf, 'type', 'hggroup')), toying with datacursormode; None of them work.
disableDefaultInteractivity doesn't work for two reasons:
1) I get an error trying to use this on my geoaxes handle, the error says the object is not of type axes so it won't work
2) even if I did get this default interactivity to work, I would lose my ability to click and drag around the geoaxes as my lines are plotting. (this is more relevant for R2020a+ because the interactivity of a geoaxes needs to be turned on using enableDefaultInteractivity per R2020a release notes)
delete(findall(gcf, 'type', 'hggroup') works, but doesn't fully do the job:
calling this within the 'buttondownfcn' callback works in deleting previous datatips (originally multiple datatips were being generated), but there seems to be no reference available to the new datatip until after the buttondownfcn callback returns. I can verify this by using the same command in the timer function; the current datatip disappears once the timer function is called.
datacursor and UpdateFcn gives mixed results:
While I'm able to use this to get access to the handle for the current datatip and delete it I get numerous errors because I'm deleting the obj the callback is referencing.
Bottom line:
Is there any way to turn off data tips from the get-go? It seems like this should be controllable on initialization but I can't find anything.

Accepted Answer

Tommy
Tommy on 17 Jun 2020
Not the greatest solution, but you could make the datatips invisible until your timer deletes them:
dcm = datacursormode;
dcm.Enable = 'off';
dcm.UpdateFcn = @makeDataTipInvisible;
function txt = makeDataTipInvisible(pdt, ~)
pdt.Visible = 'off';
txt = '';
end
I am using R2019a, but the documentation for UpdateFcn implies that the UpdateFcn stopped accepting a reference to the data tip sometime between R2019a and now, I'd guess in R2020a as you are using R2019b. If you want your GUI to work for the latest release(s), you should keep in mind that the above approach seems to stop working at a certain point. For R2020a+, does
ax = geoaxes;
ax.Interactions = [panInteraction zoomInteraction];
not do the trick? I'm not sure what you're referring to when you say
"because the interactivity of a geoaxes needs to be turned on using enableDefaultInteractivity per R2020a release notes"
A potentially irrelevant note:
I disabled the data cursor mode in my example above because this mode (the same mode obtained by clicking the corresponding axes toolbar button) disables the default interactions, including pan and zoom. However, disabling this mode then enables the default interactions, including the 'data tip interaction' which, as far as I can tell, is different from the aforementioned data cursor mode. One difference is that hovering over graphics objects creates data tips, whereas you need to actually click a graphics object in data cursor mode to create a data tip. The effect is that UpdateFcn is called even when the user hovers over a graphics object, so this function better return before the user moves the mouse away (thereby deleting the data tip which had been previously created) or else you'll see the same warning you got when you tried to delete the data tip within the UpdateFcn. This is illustrated by the following:
ax = geoaxes;
latSeattle = 47.62;
lonSeattle = -122.33;
latAnchorage = 61.20;
lonAnchorage = -149.9;
geoplot(ax,[latSeattle latAnchorage],[lonSeattle lonAnchorage],'g-*')
% (^ example from geoaxes reference page)
dcm = datacursormode;
dcm.Enable = 'off';
dcm.UpdateFcn = @waitThenDataTip;
function txt = waitThenDataTip(pdt, ~)
pause(1);
txt = '';
end
You can probably get by without worrying about this, but I figured I'd mention it anyway.
  3 Comments
Nick Donatelli
Nick Donatelli on 17 Jun 2020
As a follow-up I did test modifying the Interactions in R2020a, this does work and will disable the datatips without disabling the other interactivity using the same code format where I have nested geoaxes in a figure. I don't receive the same error as I did in R2019b.
The 'Visible' property is still available to modify in R2020a in the UpdateFcn also, maybe that plan to remove the reference is set for R2020b (although I could definitely see some utility in this for future development so I hope they don't change it)
I was able to achieve both of these methods using R2020a, thank you for your input
Tommy
Tommy on 17 Jun 2020
Glad you got it to work, and happy to help!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!