Is there an even better way to initialize the DataTipTemplate field for polygon objects?

8 次查看(过去 30 天)
This question is a combination of the following questions:
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 个评论
Chris Schierer
Chris Schierer 2023-11-14
When you use the plot command on a polyshape, the graphics primitive that is created is of type polygon.
FWIW, the polygon does not have a DataTipTemplate property by default, which is why you have to use the hack of creating a datatip first.
>> qqq=plot(polyshape([15,20,30,-15,-25],[30,42,15,-20,-5]));
>> qqq.Type
ans =
'polygon'
>>

请先登录,再进行评论。

回答(1 个)

Shivam
Shivam 2024-2-8
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

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by