mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 00:20:18 +00:00
修复Tooltip在对数轴时指示不准确的问题
This commit is contained in:
@@ -727,6 +727,13 @@ namespace XCharts.Runtime
|
||||
var each = axisLength / data.Count;
|
||||
return (float)(each * (value + 0.5f));
|
||||
}
|
||||
else if (IsLog())
|
||||
{
|
||||
var logValue = GetLogValue(value);
|
||||
var logMin = GetLogValue(context.minValue);
|
||||
var logMax = GetLogValue(context.maxValue);
|
||||
return axisLength * (float)((logValue - logMin) / (logMax - logMin));
|
||||
}
|
||||
else
|
||||
{
|
||||
return axisLength * (float)((value - context.minValue) / context.minMaxRange);
|
||||
|
||||
@@ -109,11 +109,23 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var xRate = axis.context.minMaxRange / grid.context.width;
|
||||
var xValue = xRate * (chart.pointerPos.x - grid.context.x - axis.context.offset);
|
||||
if (axis.context.minValue > 0)
|
||||
xValue += axis.context.minValue;
|
||||
|
||||
double xValue;
|
||||
if (axis.IsLog())
|
||||
{
|
||||
var logBase = axis.logBase;
|
||||
var minLog = Math.Log(axis.context.minValue, logBase);
|
||||
var maxLog = Math.Log(axis.context.maxValue, logBase);
|
||||
var logRange = maxLog - minLog;
|
||||
var pointerLog = minLog + logRange * (chart.pointerPos.x - grid.context.x - axis.context.offset) / grid.context.width;
|
||||
xValue = Math.Pow(logBase, pointerLog);
|
||||
}
|
||||
else
|
||||
{
|
||||
var xRate = axis.context.minMaxRange / grid.context.width;
|
||||
xValue = xRate * (chart.pointerPos.x - grid.context.x - axis.context.offset);
|
||||
if (axis.context.minValue > 0)
|
||||
xValue += axis.context.minValue;
|
||||
}
|
||||
var labelY = axis.GetLabelObjectPosition(0).y;
|
||||
axis.context.pointerValue = xValue;
|
||||
axis.context.pointerLabelPosition = new Vector3(chart.pointerPos.x, labelY);
|
||||
@@ -153,7 +165,7 @@ namespace XCharts
|
||||
else
|
||||
dataZoom.SetYAxisIndexValueInfo(axisIndex, ref tempMinValue, ref tempMaxValue);
|
||||
}
|
||||
|
||||
|
||||
if (tempMinValue != axis.context.destMinValue ||
|
||||
tempMaxValue != axis.context.destMaxValue ||
|
||||
m_LastInterval != axis.interval ||
|
||||
@@ -898,7 +910,7 @@ namespace XCharts
|
||||
if (isLogAxis)
|
||||
{
|
||||
var count = 0;
|
||||
var logRange = (axis.logBase - 1f);
|
||||
var logRange = axis.logBase - 1f;
|
||||
minorTickDistance = scaleWidth * axis.GetLogValue(1 + (count + 1) * logRange / minorTickSplitNumber);
|
||||
var tickTotal = lastSplitX + minorTickDistance;
|
||||
while (tickTotal < current && count < minorTickSplitNumber - 1)
|
||||
|
||||
@@ -18,6 +18,11 @@ namespace XCharts.Runtime
|
||||
InitTooltip(component);
|
||||
}
|
||||
|
||||
public override void BeforceSerieUpdate()
|
||||
{
|
||||
UpdateTooltipData(component);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
UpdateTooltip(component);
|
||||
@@ -86,8 +91,9 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTooltip(Tooltip tooltip)
|
||||
private void UpdateTooltipData(Tooltip tooltip)
|
||||
{
|
||||
showTooltip = false;
|
||||
if (tooltip.trigger == Tooltip.Trigger.None) return;
|
||||
if (!chart.isPointerInChart || !tooltip.show)
|
||||
{
|
||||
@@ -98,7 +104,28 @@ namespace XCharts.Runtime
|
||||
}
|
||||
return;
|
||||
}
|
||||
var showTooltip = false;
|
||||
for (int i = chart.series.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var serie = chart.series[i];
|
||||
if (!(serie is INeedSerieContainer))
|
||||
{
|
||||
showTooltip = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
containerSeries = ListPool<Serie>.Get();
|
||||
UpdatePointerContainerAndSeriesAndTooltip(tooltip, ref containerSeries);
|
||||
if (containerSeries.Count > 0)
|
||||
{
|
||||
showTooltip = true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool showTooltip;
|
||||
private List<Serie> containerSeries;
|
||||
private void UpdateTooltip(Tooltip tooltip)
|
||||
{
|
||||
if (!showTooltip) return;
|
||||
for (int i = chart.series.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var serie = chart.series[i];
|
||||
@@ -106,20 +133,19 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (SetSerieTooltip(tooltip, serie))
|
||||
{
|
||||
showTooltip = true;
|
||||
chart.RefreshTopPainter();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
var containerSeries = ListPool<Serie>.Get();
|
||||
UpdatePointerContainerAndSeriesAndTooltip(tooltip, ref containerSeries);
|
||||
if (containerSeries.Count > 0)
|
||||
if (containerSeries != null)
|
||||
{
|
||||
if (SetSerieTooltip(tooltip, containerSeries))
|
||||
showTooltip = true;
|
||||
if (!SetSerieTooltip(tooltip, containerSeries))
|
||||
{
|
||||
showTooltip = false;
|
||||
}
|
||||
ListPool<Serie>.Release(containerSeries);
|
||||
}
|
||||
ListPool<Serie>.Release(containerSeries);
|
||||
if (!showTooltip)
|
||||
{
|
||||
if (tooltip.context.type == Tooltip.Type.Corss && m_PointerContainer != null && m_PointerContainer.IsPointerEnter())
|
||||
@@ -138,10 +164,6 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTooltipTypeAndTrigger(Tooltip tootip)
|
||||
{
|
||||
}
|
||||
|
||||
private void UpdateTooltipIndicatorLabelText(Tooltip tooltip)
|
||||
{
|
||||
if (!tooltip.show) return;
|
||||
|
||||
Reference in New Issue
Block a user