mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-20 07:20:08 +00:00
修复Tooltip的Cross在开启DataZoom时指示位置不准确的问题
This commit is contained in:
@@ -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`下
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user