mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-28 03:58:49 +00:00
修复Tooltip在只有一个数据时可能异常的问题
This commit is contained in:
@@ -66,6 +66,7 @@ slug: /changelog
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2023.04.14) 修复`Tooltip`在只有一个数据时可能异常的问题
|
||||||
* (2023.04.14) 增加`BaseChart`的`TriggerTooltip()`接口尝试触发`ToolTip`
|
* (2023.04.14) 增加`BaseChart`的`TriggerTooltip()`接口尝试触发`ToolTip`
|
||||||
* (2023.04.12) 优化`RadarCood`设置`startAngle`时文本也跟随调整位置
|
* (2023.04.12) 优化`RadarCood`设置`startAngle`时文本也跟随调整位置
|
||||||
* (2023.04.12) 增加`Radar`对通配符`{b}`的支持
|
* (2023.04.12) 增加`Radar`对通配符`{b}`的支持
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace XCharts.Runtime
|
|||||||
private void InitTooltip(Tooltip tooltip)
|
private void InitTooltip(Tooltip tooltip)
|
||||||
{
|
{
|
||||||
tooltip.painter = chart.m_PainterUpper;
|
tooltip.painter = chart.m_PainterUpper;
|
||||||
tooltip.refreshComponent = delegate()
|
tooltip.refreshComponent = delegate ()
|
||||||
{
|
{
|
||||||
var objName = ChartCached.GetComponentObjectName(tooltip);
|
var objName = ChartCached.GetComponentObjectName(tooltip);
|
||||||
tooltip.gameObject = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor,
|
tooltip.gameObject = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor,
|
||||||
@@ -193,7 +193,7 @@ namespace XCharts.Runtime
|
|||||||
|
|
||||||
if (axis.IsCategory())
|
if (axis.IsCategory())
|
||||||
{
|
{
|
||||||
var index = (int) axis.context.pointerValue;
|
var index = (int)axis.context.pointerValue;
|
||||||
var category = axis.GetData(index);
|
var category = axis.GetData(index);
|
||||||
label.SetText(axis.indicatorLabel.GetFormatterContent(index, category));
|
label.SetText(axis.indicatorLabel.GetFormatterContent(index, category));
|
||||||
}
|
}
|
||||||
@@ -241,7 +241,7 @@ namespace XCharts.Runtime
|
|||||||
else if (container is PolarCoord)
|
else if (container is PolarCoord)
|
||||||
{
|
{
|
||||||
var m_AngleAxis = ComponentHelper.GetAngleAxis(chart.components, container.index);
|
var m_AngleAxis = ComponentHelper.GetAngleAxis(chart.components, container.index);
|
||||||
tooltip.context.angle = (float) m_AngleAxis.context.pointerValue;
|
tooltip.context.angle = (float)m_AngleAxis.context.pointerValue;
|
||||||
}
|
}
|
||||||
list.Add(serie);
|
list.Add(serie);
|
||||||
if (!isTriggerAxis)
|
if (!isTriggerAxis)
|
||||||
@@ -267,7 +267,7 @@ namespace XCharts.Runtime
|
|||||||
if (isTriggerAxis)
|
if (isTriggerAxis)
|
||||||
{
|
{
|
||||||
serie.context.pointerEnter = true;
|
serie.context.pointerEnter = true;
|
||||||
serie.context.pointerAxisDataIndexs.Add((int) yAxis.context.pointerValue);
|
serie.context.pointerAxisDataIndexs.Add((int)yAxis.context.pointerValue);
|
||||||
yAxis.context.axisTooltipValue = yAxis.context.pointerValue;
|
yAxis.context.axisTooltipValue = yAxis.context.pointerValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,7 +283,7 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
if (isTriggerAxis)
|
if (isTriggerAxis)
|
||||||
{
|
{
|
||||||
var index = serie.context.dataZoomStartIndex + (int) xAxis.context.pointerValue;
|
var index = serie.context.dataZoomStartIndex + (int)xAxis.context.pointerValue;
|
||||||
serie.context.pointerEnter = true;
|
serie.context.pointerEnter = true;
|
||||||
serie.context.pointerAxisDataIndexs.Add(index);
|
serie.context.pointerAxisDataIndexs.Add(index);
|
||||||
serie.context.pointerItemDataIndex = index;
|
serie.context.pointerItemDataIndex = index;
|
||||||
@@ -344,7 +344,7 @@ namespace XCharts.Runtime
|
|||||||
var serieData = serie.data[i];
|
var serieData = serie.data[i];
|
||||||
serie.context.sortedData.Add(serieData);
|
serie.context.sortedData.Add(serieData);
|
||||||
}
|
}
|
||||||
serie.context.sortedData.Sort(delegate(SerieData a, SerieData b)
|
serie.context.sortedData.Sort(delegate (SerieData a, SerieData b)
|
||||||
{
|
{
|
||||||
return a.GetData(dimension).CompareTo(b.GetData(dimension));
|
return a.GetData(dimension).CompareTo(b.GetData(dimension));
|
||||||
});
|
});
|
||||||
@@ -355,7 +355,7 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
var serieData = data[i];
|
var serieData = data[i];
|
||||||
currValue = serieData.GetData(dimension);
|
currValue = serieData.GetData(dimension);
|
||||||
if (i == 0)
|
if (i == 0 && i + 1 < dataCount)
|
||||||
{
|
{
|
||||||
nextValue = data[i + 1].GetData(dimension);
|
nextValue = data[i + 1].GetData(dimension);
|
||||||
if (axisValue <= currValue + (nextValue - currValue) / 2)
|
if (axisValue <= currValue + (nextValue - currValue) / 2)
|
||||||
@@ -372,7 +372,7 @@ namespace XCharts.Runtime
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (i + 1 < dataCount)
|
||||||
{
|
{
|
||||||
nextValue = data[i + 1].GetData(dimension);
|
nextValue = data[i + 1].GetData(dimension);
|
||||||
if (axisValue > (currValue - (currValue - lastValue) / 2) && axisValue <= currValue + (nextValue - currValue) / 2)
|
if (axisValue > (currValue - (currValue - lastValue) / 2) && axisValue <= currValue + (nextValue - currValue) / 2)
|
||||||
@@ -497,7 +497,7 @@ namespace XCharts.Runtime
|
|||||||
var axis = component as Axis;
|
var axis = component as Axis;
|
||||||
if (axis.gridIndex == gridIndex && axis.IsCategory())
|
if (axis.gridIndex == gridIndex && axis.IsCategory())
|
||||||
{
|
{
|
||||||
dataIndex = axis.context.dataZoomStartIndex + (int) axis.context.pointerValue;
|
dataIndex = axis.context.dataZoomStartIndex + (int)axis.context.pointerValue;
|
||||||
category = axis.GetData(dataIndex);
|
category = axis.GetData(dataIndex);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -558,7 +558,7 @@ namespace XCharts.Runtime
|
|||||||
case Tooltip.Type.Line:
|
case Tooltip.Type.Line:
|
||||||
float pX = grid.context.x;
|
float pX = grid.context.x;
|
||||||
pX += xAxis.IsCategory() ?
|
pX += xAxis.IsCategory() ?
|
||||||
(float) (xAxis.context.pointerValue * splitWidth + (xAxis.boundaryGap ? splitWidth / 2 : 0)) :
|
(float)(xAxis.context.pointerValue * splitWidth + (xAxis.boundaryGap ? splitWidth / 2 : 0)) :
|
||||||
xAxis.GetDistance(xAxis.context.axisTooltipValue, grid.context.width);
|
xAxis.GetDistance(xAxis.context.axisTooltipValue, grid.context.width);
|
||||||
if (pX < grid.context.x)
|
if (pX < grid.context.x)
|
||||||
break;
|
break;
|
||||||
@@ -577,15 +577,15 @@ namespace XCharts.Runtime
|
|||||||
if (xAxis.IsCategory() && !double.IsInfinity(xAxis.context.pointerValue))
|
if (xAxis.IsCategory() && !double.IsInfinity(xAxis.context.pointerValue))
|
||||||
{
|
{
|
||||||
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
||||||
pX = (float) (grid.context.x + splitWidth * xAxis.context.pointerValue -
|
pX = (float)(grid.context.x + splitWidth * xAxis.context.pointerValue -
|
||||||
(xAxis.boundaryGap ? 0 : splitWidth / 2));
|
(xAxis.boundaryGap ? 0 : splitWidth / 2));
|
||||||
if (pX < grid.context.x)
|
if (pX < grid.context.x)
|
||||||
break;
|
break;
|
||||||
float pY = grid.context.y + grid.context.height;
|
float pY = grid.context.y + grid.context.height;
|
||||||
Vector3 p1 = chart.ClampInGrid(grid,new Vector3(pX, grid.context.y));
|
Vector3 p1 = chart.ClampInGrid(grid, new Vector3(pX, grid.context.y));
|
||||||
Vector3 p2 = chart.ClampInGrid(grid,new Vector3(pX, pY));
|
Vector3 p2 = chart.ClampInGrid(grid, new Vector3(pX, pY));
|
||||||
Vector3 p3 = chart.ClampInGrid(grid,new Vector3(pX + tooltipSplitWid, pY));
|
Vector3 p3 = chart.ClampInGrid(grid, new Vector3(pX + tooltipSplitWid, pY));
|
||||||
Vector3 p4 = chart.ClampInGrid(grid,new Vector3(pX + tooltipSplitWid, grid.context.y));
|
Vector3 p4 = chart.ClampInGrid(grid, new Vector3(pX + tooltipSplitWid, grid.context.y));
|
||||||
var areaColor = TooltipHelper.GetLineColor(tooltip, chart.theme.tooltip.areaColor);
|
var areaColor = TooltipHelper.GetLineColor(tooltip, chart.theme.tooltip.areaColor);
|
||||||
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, areaColor);
|
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, areaColor);
|
||||||
}
|
}
|
||||||
@@ -622,7 +622,7 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
case Tooltip.Type.Corss:
|
case Tooltip.Type.Corss:
|
||||||
case Tooltip.Type.Line:
|
case Tooltip.Type.Line:
|
||||||
float pY = (float) (grid.context.y + yAxis.context.pointerValue * splitWidth +
|
float pY = (float)(grid.context.y + yAxis.context.pointerValue * splitWidth +
|
||||||
(yAxis.boundaryGap ? splitWidth / 2 : 0));
|
(yAxis.boundaryGap ? splitWidth / 2 : 0));
|
||||||
if (pY < grid.context.y)
|
if (pY < grid.context.y)
|
||||||
break;
|
break;
|
||||||
@@ -642,7 +642,7 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
||||||
float pX = grid.context.x + grid.context.width;
|
float pX = grid.context.x + grid.context.width;
|
||||||
pY = (float) (grid.context.y + splitWidth * yAxis.context.pointerValue -
|
pY = (float)(grid.context.y + splitWidth * yAxis.context.pointerValue -
|
||||||
(yAxis.boundaryGap ? 0 : splitWidth / 2));
|
(yAxis.boundaryGap ? 0 : splitWidth / 2));
|
||||||
if (pY < grid.context.y)
|
if (pY < grid.context.y)
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user