mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 10:20:10 +00:00
修复Tooltip在对数轴时指示不准确的问题
This commit is contained in:
@@ -78,11 +78,12 @@ slug: /changelog
|
|||||||
* 增加`Axis`的对数轴子刻度的支持
|
* 增加`Axis`的对数轴子刻度的支持
|
||||||
* 增加`MarkLine`的`onTop`设置是否显示在最上层
|
* 增加`MarkLine`的`onTop`设置是否显示在最上层
|
||||||
* 增加`UITable`表格组件的轮播功能,重构`UITable`
|
* 增加`UITable`表格组件的轮播功能,重构`UITable`
|
||||||
* 完善注释和文档
|
* 完善代码注释和手册文档
|
||||||
* 修复若干问题
|
* 修复若干问题
|
||||||
|
|
||||||
日志详情:
|
日志详情:
|
||||||
|
|
||||||
|
* (2023.11.28) 修复`Tooltip`在对数轴时指示不准确的问题
|
||||||
* (2023.11.24) 修复`Chart`的`UpdateData()`接口返回值不准确的问题
|
* (2023.11.24) 修复`Chart`的`UpdateData()`接口返回值不准确的问题
|
||||||
* (2023.11.24) 修复`Axis`的更新数据时效果不顺畅的问题
|
* (2023.11.24) 修复`Axis`的更新数据时效果不顺畅的问题
|
||||||
* (2023.11.23) 增加`Axis`的`Animation`支持动画效果
|
* (2023.11.23) 增加`Axis`的`Animation`支持动画效果
|
||||||
|
|||||||
@@ -727,6 +727,13 @@ namespace XCharts.Runtime
|
|||||||
var each = axisLength / data.Count;
|
var each = axisLength / data.Count;
|
||||||
return (float)(each * (value + 0.5f));
|
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
|
else
|
||||||
{
|
{
|
||||||
return axisLength * (float)((value - context.minValue) / context.minMaxRange);
|
return axisLength * (float)((value - context.minValue) / context.minMaxRange);
|
||||||
|
|||||||
@@ -109,11 +109,23 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var xRate = axis.context.minMaxRange / grid.context.width;
|
double xValue;
|
||||||
var xValue = xRate * (chart.pointerPos.x - grid.context.x - axis.context.offset);
|
if (axis.IsLog())
|
||||||
if (axis.context.minValue > 0)
|
{
|
||||||
xValue += axis.context.minValue;
|
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;
|
var labelY = axis.GetLabelObjectPosition(0).y;
|
||||||
axis.context.pointerValue = xValue;
|
axis.context.pointerValue = xValue;
|
||||||
axis.context.pointerLabelPosition = new Vector3(chart.pointerPos.x, labelY);
|
axis.context.pointerLabelPosition = new Vector3(chart.pointerPos.x, labelY);
|
||||||
@@ -898,7 +910,7 @@ namespace XCharts
|
|||||||
if (isLogAxis)
|
if (isLogAxis)
|
||||||
{
|
{
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var logRange = (axis.logBase - 1f);
|
var logRange = axis.logBase - 1f;
|
||||||
minorTickDistance = scaleWidth * axis.GetLogValue(1 + (count + 1) * logRange / minorTickSplitNumber);
|
minorTickDistance = scaleWidth * axis.GetLogValue(1 + (count + 1) * logRange / minorTickSplitNumber);
|
||||||
var tickTotal = lastSplitX + minorTickDistance;
|
var tickTotal = lastSplitX + minorTickDistance;
|
||||||
while (tickTotal < current && count < minorTickSplitNumber - 1)
|
while (tickTotal < current && count < minorTickSplitNumber - 1)
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ namespace XCharts.Runtime
|
|||||||
InitTooltip(component);
|
InitTooltip(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void BeforceSerieUpdate()
|
||||||
|
{
|
||||||
|
UpdateTooltipData(component);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
UpdateTooltip(component);
|
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 (tooltip.trigger == Tooltip.Trigger.None) return;
|
||||||
if (!chart.isPointerInChart || !tooltip.show)
|
if (!chart.isPointerInChart || !tooltip.show)
|
||||||
{
|
{
|
||||||
@@ -98,7 +104,28 @@ namespace XCharts.Runtime
|
|||||||
}
|
}
|
||||||
return;
|
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--)
|
for (int i = chart.series.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
var serie = chart.series[i];
|
var serie = chart.series[i];
|
||||||
@@ -106,20 +133,19 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
if (SetSerieTooltip(tooltip, serie))
|
if (SetSerieTooltip(tooltip, serie))
|
||||||
{
|
{
|
||||||
showTooltip = true;
|
|
||||||
chart.RefreshTopPainter();
|
chart.RefreshTopPainter();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var containerSeries = ListPool<Serie>.Get();
|
if (containerSeries != null)
|
||||||
UpdatePointerContainerAndSeriesAndTooltip(tooltip, ref containerSeries);
|
|
||||||
if (containerSeries.Count > 0)
|
|
||||||
{
|
{
|
||||||
if (SetSerieTooltip(tooltip, containerSeries))
|
if (!SetSerieTooltip(tooltip, containerSeries))
|
||||||
showTooltip = true;
|
{
|
||||||
|
showTooltip = false;
|
||||||
|
}
|
||||||
|
ListPool<Serie>.Release(containerSeries);
|
||||||
}
|
}
|
||||||
ListPool<Serie>.Release(containerSeries);
|
|
||||||
if (!showTooltip)
|
if (!showTooltip)
|
||||||
{
|
{
|
||||||
if (tooltip.context.type == Tooltip.Type.Corss && m_PointerContainer != null && m_PointerContainer.IsPointerEnter())
|
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)
|
private void UpdateTooltipIndicatorLabelText(Tooltip tooltip)
|
||||||
{
|
{
|
||||||
if (!tooltip.show) return;
|
if (!tooltip.show) return;
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ namespace XCharts.Runtime
|
|||||||
CheckRefreshChart();
|
CheckRefreshChart();
|
||||||
Internal_CheckAnimation();
|
Internal_CheckAnimation();
|
||||||
foreach (var handler in m_SerieHandlers) handler.BeforeUpdate();
|
foreach (var handler in m_SerieHandlers) handler.BeforeUpdate();
|
||||||
|
foreach (var handler in m_ComponentHandlers) handler.BeforceSerieUpdate();
|
||||||
foreach (var handler in m_SerieHandlers) handler.Update();
|
foreach (var handler in m_SerieHandlers) handler.Update();
|
||||||
foreach (var handler in m_ComponentHandlers) handler.Update();
|
foreach (var handler in m_ComponentHandlers) handler.Update();
|
||||||
foreach (var handler in m_SerieHandlers) handler.AfterUpdate();
|
foreach (var handler in m_SerieHandlers) handler.AfterUpdate();
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ namespace XCharts.Runtime
|
|||||||
public virtual void InitComponent() { }
|
public virtual void InitComponent() { }
|
||||||
public virtual void RemoveComponent() { }
|
public virtual void RemoveComponent() { }
|
||||||
public virtual void CheckComponent(StringBuilder sb) { }
|
public virtual void CheckComponent(StringBuilder sb) { }
|
||||||
|
public virtual void BeforceSerieUpdate() { }
|
||||||
public virtual void Update() { }
|
public virtual void Update() { }
|
||||||
public virtual void DrawBase(VertexHelper vh) { }
|
public virtual void DrawBase(VertexHelper vh) { }
|
||||||
public virtual void DrawUpper(VertexHelper vh) { }
|
public virtual void DrawUpper(VertexHelper vh) { }
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace XCharts.Runtime
|
|||||||
|
|
||||||
private static Dictionary<double, Dictionary<string, string>> s_NumberToStr = new Dictionary<double, Dictionary<string, string>>();
|
private static Dictionary<double, Dictionary<string, string>> s_NumberToStr = new Dictionary<double, Dictionary<string, string>>();
|
||||||
private static Dictionary<int, Dictionary<string, string>> s_PrecisionToStr = new Dictionary<int, Dictionary<string, string>>();
|
private static Dictionary<int, Dictionary<string, string>> s_PrecisionToStr = new Dictionary<int, Dictionary<string, string>>();
|
||||||
|
private static Dictionary<string, Dictionary<int, string>> s_StringIntDict = new Dictionary<string, Dictionary<int, string>>();
|
||||||
|
|
||||||
public static string FloatToStr(double value, string numericFormatter = "F", int precision = 0)
|
public static string FloatToStr(double value, string numericFormatter = "F", int precision = 0)
|
||||||
{
|
{
|
||||||
@@ -113,6 +114,19 @@ namespace XCharts.Runtime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetString(string prefix, int suffix)
|
||||||
|
{
|
||||||
|
if (!s_StringIntDict.ContainsKey(prefix))
|
||||||
|
{
|
||||||
|
s_StringIntDict[prefix] = new Dictionary<int, string>();
|
||||||
|
}
|
||||||
|
if (!s_StringIntDict[prefix].ContainsKey(suffix))
|
||||||
|
{
|
||||||
|
s_StringIntDict[prefix][suffix] = prefix + suffix;
|
||||||
|
}
|
||||||
|
return s_StringIntDict[prefix][suffix];
|
||||||
|
}
|
||||||
|
|
||||||
internal static string GetComponentObjectName(MainComponent component)
|
internal static string GetComponentObjectName(MainComponent component)
|
||||||
{
|
{
|
||||||
Dictionary<int, string> dict;
|
Dictionary<int, string> dict;
|
||||||
|
|||||||
@@ -438,7 +438,8 @@ namespace XCharts.Runtime
|
|||||||
label.color = (!labelStyle.background.autoColor || autoColor == Color.clear) ?
|
label.color = (!labelStyle.background.autoColor || autoColor == Color.clear) ?
|
||||||
labelStyle.background.color : autoColor;
|
labelStyle.background.color : autoColor;
|
||||||
label.sprite = labelStyle.background.sprite;
|
label.sprite = labelStyle.background.sprite;
|
||||||
label.type = labelStyle.background.type;
|
if(label.type != labelStyle.background.type)
|
||||||
|
label.type = labelStyle.background.type;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user