Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for GC Allocations inside TooltipHandler #311

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions Runtime/Component/Tooltip/TooltipHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ private void UpdateTooltipData(Tooltip tooltip)
m_ShowTooltip = false;
if (tooltip.trigger == Tooltip.Trigger.None) return;
chart.isTriggerOnClick = tooltip.triggerOn == Tooltip.TriggerOn.Click;
if (!chart.isPointerInChart || !tooltip.show || (chart.isTriggerOnClick && !chart.isPointerClick))

if ((tooltip.show && chart.isPointerInChart) &&
((tooltip.triggerOn == Tooltip.TriggerOn.Click && chart.isPointerClick) ||
(tooltip.triggerOn == Tooltip.TriggerOn.MouseMove))
)
{
for (int i = chart.series.Count - 1; i >= 0; i--)
{
Expand All @@ -124,34 +128,33 @@ private void UpdateTooltipData(Tooltip tooltip)
if (m_ContainerSeries.Count > 0)
{
m_ShowTooltip = true;
m_ContainerSeries = null;
return;
}
}
m_ContainerSeries = ListPool<Serie>.Get();
UpdatePointerContainerAndSeriesAndTooltip(tooltip, ref m_ContainerSeries);
if (m_ContainerSeries.Count > 0)
{
m_ShowTooltip = true;
}
else

if (!m_ShowTooltip && tooltip.IsActive())
{
m_ShowTooltip = false;
if (tooltip.IsActive())
{
tooltip.ClearValue();
tooltip.SetActive(false);
component.context.xAxisClickIndex = -1;
chart.pointerClickEventData = null;
}
tooltip.ClearValue();
tooltip.SetActive(false);
component.context.xAxisClickIndex = -1;
chart.pointerClickEventData = null;
}
}

private bool m_ShowTooltip;
private List<Serie> m_ContainerSeries;
private void UpdateTooltip(Tooltip tooltip)
{
if (!m_ShowTooltip) return;
if (!m_ShowTooltip)
{
if (m_ContainerSeries != null)
{
ListPool<Serie>.Release(m_ContainerSeries);
m_ContainerSeries = null;
}
return;
}

var anyTrigger = false;
for (int i = chart.series.Count - 1; i >= 0; i--)
{
Expand All @@ -173,6 +176,7 @@ private void UpdateTooltip(Tooltip tooltip)
else
anyTrigger = true;
ListPool<Serie>.Release(m_ContainerSeries);
m_ContainerSeries = null;
}
if (!m_ShowTooltip || !anyTrigger)
{
Expand Down