修复TooltipCross在开启DataZoom时指示位置不准确的问题

This commit is contained in:
monitor1394
2024-06-09 22:13:26 +08:00
parent 8617475808
commit a12c98b1a5
4 changed files with 42 additions and 3 deletions

View File

@@ -73,6 +73,7 @@ slug: /changelog
## master
* (2024.06.09) 修复`Tooltip``Cross``Axis`是类目轴并且开启`DataZoom`的情况下指示位置不准确的问题
* (2024.06.06) 修复`Serie``Clone`时动画异常问题 (#320)
* (2024.06.04) 修复`Serie``state`在代码动态设置时不刷新的问题
* (2024.05.29) 调整`XCharts``Hierarchy`视图下的右键菜单到`UI/XCharts`

View File

@@ -935,5 +935,43 @@ namespace XCharts.Runtime
(float)(Math.Abs(context.minValue) * (axisLength / (Math.Abs(context.minValue) + Math.Abs(context.maxValue))))
);
}
public Vector3 GetCategoryPosition(int categoryIndex, int dataCount = 0)
{
if (dataCount <= 0)
{
dataCount = data.Count;
}
if (IsCategory() && dataCount > 0)
{
Vector3 pos;
if (boundaryGap)
{
var each = context.length / dataCount;
pos = context.start + context.dire * (each * (categoryIndex + 0.5f));
}
else
{
var each = context.length / (dataCount - 1);
pos = context.start + context.dire * (each * categoryIndex);
}
if (axisLabel.distance != 0)
{
if (this is YAxis)
{
pos.x = GetLabelObjectPosition(0).x;
}
else
{
pos.y = GetLabelObjectPosition(0).y;
}
}
return pos;
}
else
{
return Vector3.zero;
}
}
}
}

View File

@@ -58,7 +58,7 @@ namespace XCharts
(!axis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
{
axis.context.pointerValue = j;
axis.context.pointerLabelPosition = axis.GetLabelObjectPosition(j);
axis.context.pointerLabelPosition = axis.GetCategoryPosition(j, dataCount);
if (j != lastPointerValue)
{
if (chart.onAxisPointerValueChanged != null)
@@ -78,7 +78,7 @@ namespace XCharts
(!axis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
{
axis.context.pointerValue = j;
axis.context.pointerLabelPosition = axis.GetLabelObjectPosition(j);
axis.context.pointerLabelPosition = axis.GetCategoryPosition(j, dataCount);
if (j != lastPointerValue)
{
if (chart.onAxisPointerValueChanged != null)

View File

@@ -701,7 +701,7 @@ namespace XCharts.Runtime
case Tooltip.Type.Line:
float pX = grid.context.x;
pX += xAxis.IsCategory() ?
(float)(xAxis.context.axisTooltipValue * splitWidth + (xAxis.boundaryGap ? splitWidth / 2 : 0)) :
(float)(xAxis.context.pointerValue * splitWidth + (xAxis.boundaryGap ? splitWidth / 2 : 0)) :
xAxis.GetDistance(xAxis.context.axisTooltipValue, grid.context.width);
if (pX < grid.context.x)
break;