Is there an even better way to initialize the DataTipTemplate field for polygon objects?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
This question is a combination of the following questions:
- https://www.mathworks.com/matlabcentral/answers/1468891-add-data-tips-to-polyshape-plots
- https://www.mathworks.com/matlabcentral/answers/1590114-is-there-a-better-way-to-initialize-the-datatiptemplate-field-in-primitive-objects
In Matlab 2022b, as in the answer to the first link above, polygon objects do not have the DataTipTemplate property by default. The property appears, and can be changed, after creating a dataTip as described in the answer to the first link above. In the second link above, this method is used to initialize the field for a single graphics object and @adam.danz states that creating and deleting the dataTip is "fast". Fast is relative, so I tried it out on 100 polyshapes with the following code:
>> clf;tic;for j=1:100;qqq=plot(polyshape([15,20,30,-15,-25],[30,42,15,-20,-5]));end;toc
Elapsed time is 0.578942 seconds.
>> clf;tic;for j=1:100;qqq=plot(polyshape([15,20,30,-15,-25],[30,42,15,-20,-5]));tmp=datatip(qqq,15,30,'Visible','off');delete(tmp);end;toc
Elapsed time is 6.173269 seconds.
Creating, and deleting the dataTip increases the run time by a factor of TEN.
This is clearly not acceptable for a large number (hundreds or thousands) of polyshapes (e.g., for mapping applications).
So is there an even better way to initialize DataTipTemplate for polygon objects?
An alternate approach is to create a custom ButtonDownFcn for the polygon objects, but this breaks all the normal interactive axis behaviors (see also https://www.mathworks.com/matlabcentral/answers/485964-restore-standard-interactive-axes-behavior-callback-when-using-custom-buttondownfcn).
2 Commenti
Matt J
il 14 Nov 2023
polygon objects do not have the DataTipTemplate property by default.
Do you mean polyshape objects?
Risposte (1)
Shivam
il 8 Feb 2024
Hi,
From the gathered information, it seems that you are exploring a better approach to use the 'DataTipTemplate' field of the polygon object. In your shared code, you are generating custom datatips, making the 'DataTipTemplate' property available, and this method of creating custom datatips results in longer execution times.
As indicated in the 'Polygon Properties' documentation, a polygon is one of the primitive objects that contains a dynamic property 'DataTipTemplate,' and this property applies to polygons only when you explicitly pin a datatip in the polygon. It is done to avoid any performance issues since this primitive object is used as a building block of other charting objects.
The current workflow you are following is the correct one where you are creating a datatip for each polygon object.
You can refer to the following documentation to know more about Polygon properties and DataTipTemplate property:
I hope this explanation addresses your query.
Thanks
0 Commenti
Vedere anche
Categorie
Scopri di più su Elementary Polygons in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!