修复Tooltip在鼠标移出图表外可能绘制异常的问题

This commit is contained in:
monitor1394
2019-09-20 08:55:52 +08:00
parent 5532640c5d
commit 1a3a1d2b03
4 changed files with 26 additions and 10 deletions

View File

@@ -381,9 +381,9 @@ namespace XCharts
{ {
if (!m_Tooltip.show || !m_Tooltip.inited) if (!m_Tooltip.show || !m_Tooltip.inited)
{ {
if (m_Tooltip.dataIndex[0] != 0 || m_Tooltip.dataIndex[1] != 0) if (m_Tooltip.IsActive())
{ {
m_Tooltip.dataIndex[0] = m_Tooltip.dataIndex[1] = -1; m_Tooltip.ClearValue();
m_Tooltip.SetActive(false); m_Tooltip.SetActive(false);
RefreshChart(); RefreshChart();
} }
@@ -399,15 +399,21 @@ namespace XCharts
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
Input.mousePosition, canvas.worldCamera, out local)) Input.mousePosition, canvas.worldCamera, out local))
{ {
if (m_Tooltip.IsActive()) RefreshChart(); if (m_Tooltip.IsActive())
{
m_Tooltip.SetActive(false); m_Tooltip.SetActive(false);
RefreshChart();
}
return; return;
} }
if (local.x < 0 || local.x > chartWidth || if (local.x < 0 || local.x > chartWidth ||
local.y < 0 || local.y > chartHeight) local.y < 0 || local.y > chartHeight)
{ {
if (m_Tooltip.IsActive()) RefreshChart(); if (m_Tooltip.IsActive())
{
m_Tooltip.SetActive(false); m_Tooltip.SetActive(false);
RefreshChart();
}
return; return;
} }
m_Tooltip.pointerPos = local; m_Tooltip.pointerPos = local;

View File

@@ -162,9 +162,10 @@ namespace XCharts
RefreshChart(); RefreshChart();
} }
} }
else else if (m_Tooltip.IsActive())
{ {
m_Tooltip.SetActive(false); m_Tooltip.SetActive(false);
RefreshChart();
} }
} }
@@ -191,8 +192,12 @@ namespace XCharts
tempAxis = m_XAxises[0]; tempAxis = m_XAxises[0];
} }
if (index < 0) if (index < 0)
{
if (m_Tooltip.IsActive())
{ {
m_Tooltip.SetActive(false); m_Tooltip.SetActive(false);
RefreshChart();
}
return; return;
} }

View File

@@ -519,9 +519,10 @@ namespace XCharts
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25)); m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
RefreshTooltip(); RefreshTooltip();
} }
else else if(m_Tooltip.IsActive())
{ {
m_Tooltip.SetActive(false); m_Tooltip.SetActive(false);
RefreshChart();
} }
} }

View File

@@ -471,8 +471,12 @@ namespace XCharts
base.RefreshTooltip(); base.RefreshTooltip();
int serieIndex = m_Tooltip.dataIndex[0]; int serieIndex = m_Tooltip.dataIndex[0];
if (serieIndex < 0) if (serieIndex < 0)
{
if (m_Tooltip.IsActive())
{ {
m_Tooltip.SetActive(false); m_Tooltip.SetActive(false);
RefreshChart();
}
return; return;
} }
m_Tooltip.SetActive(true); m_Tooltip.SetActive(true);