diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5f3c238b..c5a4c13e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -59,6 +59,7 @@
## master
+* (2022.10.30) 增加`Axis`的`indicatorLabel`,移除`Tooltip`的`indicatorLabelStyle` (#226)
* (2022.10.29) 增加`Serie`的`markColor`可设置标识颜色用于`Legend`和`Tooltip`的展示 (#229)
* (2022.10.26) 增加`RadarCoord`的`startAngle`可设置`Radar`起始角度
* (2022.10.21) 修复`Chart`在受`Layout`控制时`Label`显示不正常的问题 (#231)
diff --git a/Documentation/XChartsAPI-EN.md b/Documentation/XChartsAPI-EN.md
index 784b050e..69173ea6 100644
--- a/Documentation/XChartsAPI-EN.md
+++ b/Documentation/XChartsAPI-EN.md
@@ -204,6 +204,7 @@ Inherits or Implemented: [BaseGraph](#BaseGraph),[ISerializationCallbackReceiver
| GetItemColor() |public Color32 GetItemColor(Serie serie, SerieData serieData, int colorIndex)|
| GetLegendRealShowNameColor() |public Color32 GetLegendRealShowNameColor(string name)|
| GetLegendRealShowNameIndex() |public int GetLegendRealShowNameIndex(string name)|
+| GetMarkColor() |public Color32 GetMarkColor(Serie serie, SerieData serieData)
获得Serie的标识颜色。 |
| GetOrAddChartComponent<T>() |public T GetOrAddChartComponent<T>() where T : MainComponent|
| GetPainter() |public Painter GetPainter(int index)|
| GetSerie() |public Serie GetSerie(int serieIndex)|
diff --git a/Documentation/XChartsAPI-ZH.md b/Documentation/XChartsAPI-ZH.md
index b8f9350e..0843044c 100644
--- a/Documentation/XChartsAPI-ZH.md
+++ b/Documentation/XChartsAPI-ZH.md
@@ -204,6 +204,7 @@ Inherits or Implemented: [BaseGraph](#BaseGraph),[ISerializationCallbackReceiver
| GetItemColor() |public Color32 GetItemColor(Serie serie, SerieData serieData, int colorIndex)|
| GetLegendRealShowNameColor() |public Color32 GetLegendRealShowNameColor(string name)|
| GetLegendRealShowNameIndex() |public int GetLegendRealShowNameIndex(string name)|
+| GetMarkColor() |public Color32 GetMarkColor(Serie serie, SerieData serieData)
获得Serie的标识颜色。 |
| GetOrAddChartComponent<T>() |public T GetOrAddChartComponent<T>() where T : MainComponent|
| GetPainter() |public Painter GetPainter(int index)|
| GetSerie() |public Serie GetSerie(int serieIndex)|
diff --git a/Documentation/XChartsConfiguration-EN.md b/Documentation/XChartsConfiguration-EN.md
index c745f3bd..3c3393fc 100644
--- a/Documentation/XChartsConfiguration-EN.md
+++ b/Documentation/XChartsConfiguration-EN.md
@@ -268,6 +268,7 @@ The axis in rectangular coordinate.
|splitArea|||axis split area. [AxisSplitArea](#AxisSplitArea)|
|minorTick||v3.2.0|axis minor tick. [AxisMinorTick](#AxisMinorTick)|
|minorSplitLine||v3.2.0|axis minor split line. [AxisMinorSplitLine](#AxisMinorSplitLine)|
+|indicatorLabel||v3.4.0|Style of axis tooltip indicator label. [LabelStyle](#LabelStyle)|
## AxisLabel
@@ -1080,6 +1081,7 @@ Inherits or Implemented: [BaseSerie](#BaseSerie),[IComparable](#IComparable)
|serieName|||Series name used for displaying in tooltip and filtering with legend.
|state||v3.2.0|The default state of a serie.
`SerieState`:
- `Normal`: Normal state.
- `Emphasis`: Emphasis state.
- `Blur`: Blur state.
- `Select`: Select state.
- `Auto`: Auto state.
|
|colorBy||v3.2.0|The policy to take color from theme.
`SerieColorBy`:
- `Default`: Select state.
- `Serie`: assigns the colors in the palette by serie, so that all data in the same series are in the same color;.
- `Data`: assigns colors in the palette according to data items, with each data item using a different color..
|
+|markColor||v3.4.0|Serie's mark color. It is only used to display Legend and Tooltip, and does not affect the drawing color. The default value is clear.
|stack|||If stack the value. On the same category axis, the series with the same stack name would be put on top of each other.
|xAxisIndex|0||the index of XAxis.
|yAxisIndex|0||the index of YAxis.
@@ -1458,7 +1460,6 @@ Tooltip component.
|itemHeight|25f||height of content text.
|borderColor|Color32(230, 230, 230, 255)||the color of tooltip border.
|lineStyle|||the line style of indicator line. [LineStyle](#LineStyle)|
-|indicatorLabelStyle|||the label style of tooltip axis indicator label. [LabelStyle](#LabelStyle)|
|titleLabelStyle|||the textstyle of title. [LabelStyle](#LabelStyle)|
|contentLabelStyles|||the textstyle list of content.
diff --git a/Documentation/XChartsConfiguration-ZH.md b/Documentation/XChartsConfiguration-ZH.md
index 1f6fdc68..5e3d4c17 100644
--- a/Documentation/XChartsConfiguration-ZH.md
+++ b/Documentation/XChartsConfiguration-ZH.md
@@ -268,6 +268,7 @@ Inherits or Implemented: [MainComponent](#MainComponent)
|splitArea|||坐标轴分割区域。 [AxisSplitArea](#AxisSplitArea)|
|minorTick||v3.2.0|坐标轴次刻度。 [AxisMinorTick](#AxisMinorTick)|
|minorSplitLine||v3.2.0|坐标轴次分割线。 [AxisMinorSplitLine](#AxisMinorSplitLine)|
+|indicatorLabel||v3.4.0|指示器文本的样式。Tooltip为Cross时使用。 [LabelStyle](#LabelStyle)|
## AxisLabel
@@ -1080,6 +1081,7 @@ Inherits or Implemented: [BaseSerie](#BaseSerie),[IComparable](#IComparable)
|serieName|||系列名称,用于 tooltip 的显示,legend 的图例筛选。
|state||v3.2.0|系列的默认状态。
`SerieState`:
- `Normal`: 正常状态。
- `Emphasis`: 高亮状态。
- `Blur`: 淡出状态。
- `Select`: 选中状态。
- `Auto`: 自动保持和父节点一致。一般用在SerieData。
|
|colorBy||v3.2.0|从主题中取色的策略。
`SerieColorBy`:
- `Default`: 默认策略。每种Serie都有自己的默认的取颜色策略。比如Line默认是Series策略,Pie默认是Data策略
- `Serie`: 按照系列分配调色盘中的颜色,同一系列中的所有数据都是用相同的颜色。
- `Data`: 按照数据项分配调色盘中的颜色,每个数据项都使用不同的颜色。
|
+|markColor||v3.4.0|Serie的标识颜色。仅用于Legend和Tooltip的展示,不影响绘制颜色,默认为clear。
|stack|||数据堆叠,同个类目轴上系列配置相同的stack值后,后一个系列的值会在前一个系列的值上相加。
|xAxisIndex|0||使用X轴的index。
|yAxisIndex|0||使用Y轴的index。
@@ -1458,7 +1460,6 @@ Inherits or Implemented: [MainComponent](#MainComponent)
|itemHeight|25f||数据项文本的高。
|borderColor|Color32(230, 230, 230, 255)||边框颜色。
|lineStyle|||指示线样式。 [LineStyle](#LineStyle)|
-|indicatorLabelStyle|||提示框的坐标轴指示器文本的样式。 [LabelStyle](#LabelStyle)|
|titleLabelStyle|||标题的文本样式。 [LabelStyle](#LabelStyle)|
|contentLabelStyles|||内容部分的文本样式列表。和列一一对应。
diff --git a/Editor/MainComponents/AxisEditor.cs b/Editor/MainComponents/AxisEditor.cs
index 46e1bac4..2e2d9224 100644
--- a/Editor/MainComponents/AxisEditor.cs
+++ b/Editor/MainComponents/AxisEditor.cs
@@ -78,6 +78,7 @@ namespace XCharts.Editor
PropertyField("m_AxisLabel");
PropertyField("m_SplitLine");
PropertyField("m_SplitArea");
+ PropertyField("m_IndicatorLabel");
if (type != Axis.AxisType.Category)
{
PropertyField("m_MinorTick");
diff --git a/Editor/MainComponents/TooltipEditor.cs b/Editor/MainComponents/TooltipEditor.cs
index c657d8fe..179048e5 100644
--- a/Editor/MainComponents/TooltipEditor.cs
+++ b/Editor/MainComponents/TooltipEditor.cs
@@ -39,7 +39,6 @@ namespace XCharts.Editor
PropertyField("m_IgnoreDataDefaultContent");
});
PropertyField("m_LineStyle");
- PropertyField("m_IndicatorLabelStyle");
PropertyField("m_TitleLabelStyle");
PropertyListField("m_ContentLabelStyles");
--EditorGUI.indentLevel;
diff --git a/Runtime/Component/Axis/Axis.cs b/Runtime/Component/Axis/Axis.cs
index 1a988b1f..d9664c2f 100644
--- a/Runtime/Component/Axis/Axis.cs
+++ b/Runtime/Component/Axis/Axis.cs
@@ -103,6 +103,7 @@ namespace XCharts.Runtime
[SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
[SerializeField][Since("v3.2.0")] protected AxisMinorTick m_MinorTick = AxisMinorTick.defaultMinorTick;
[SerializeField][Since("v3.2.0")] protected AxisMinorSplitLine m_MinorSplitLine = AxisMinorSplitLine.defaultMinorSplitLine;
+ [SerializeField][Since("v3.4.0")] protected LabelStyle m_IndicatorLabel = new LabelStyle();
public AxisContext context = new AxisContext();
@@ -372,6 +373,15 @@ namespace XCharts.Runtime
set { if (value != null) { m_MinorSplitLine = value; SetVerticesDirty(); } }
}
///
+ /// Style of axis tooltip indicator label.
+ /// |指示器文本的样式。Tooltip为Cross时使用。
+ ///
+ public LabelStyle indicatorLabel
+ {
+ get { return m_IndicatorLabel; }
+ set { if (value != null) { m_IndicatorLabel = value; SetComponentDirty(); } }
+ }
+ ///
/// Whether to add new data at the head or at the end of the list.
/// |添加新数据时是在列表的头部还是尾部加入。
///
@@ -401,7 +411,8 @@ namespace XCharts.Runtime
{
return m_ComponentDirty ||
axisName.anyDirty ||
- axisLabel.anyDirty;
+ axisLabel.anyDirty ||
+ indicatorLabel.anyDirty;
}
}
@@ -410,6 +421,7 @@ namespace XCharts.Runtime
base.ClearComponentDirty();
axisName.ClearComponentDirty();
axisLabel.ClearComponentDirty();
+ indicatorLabel.ClearComponentDirty();
}
public override void ClearVerticesDirty()
@@ -422,6 +434,7 @@ namespace XCharts.Runtime
splitArea.ClearVerticesDirty();
minorTick.ClearVerticesDirty();
minorSplitLine.ClearVerticesDirty();
+ indicatorLabel.ClearComponentDirty();
}
public override void SetComponentDirty()
@@ -455,6 +468,7 @@ namespace XCharts.Runtime
axis.splitArea = splitArea.Clone();
axis.minorTick = minorTick.Clone();
axis.minorSplitLine = minorSplitLine.Clone();
+ axis.indicatorLabel = indicatorLabel.Clone();
axis.icons = new List();
axis.data = new List();
ChartHelper.CopyList(axis.data, data);
@@ -485,6 +499,7 @@ namespace XCharts.Runtime
splitArea.Copy(axis.splitArea);
minorTick.Copy(axis.minorTick);
minorSplitLine.Copy(axis.minorSplitLine);
+ indicatorLabel.Copy(axis.indicatorLabel);
ChartHelper.CopyList(data, axis.data);
ChartHelper.CopyList(icons, axis.icons);
}
@@ -719,8 +734,6 @@ namespace XCharts.Runtime
}
}
-
-
///
/// 获得指定区域缩放的类目数据列表
///
diff --git a/Runtime/Component/Axis/AxisContext.cs b/Runtime/Component/Axis/AxisContext.cs
index fcc5a768..89e0296f 100644
--- a/Runtime/Component/Axis/AxisContext.cs
+++ b/Runtime/Component/Axis/AxisContext.cs
@@ -56,6 +56,7 @@ namespace XCharts.Runtime
public double pointerValue;
public Vector3 pointerLabelPosition;
public double axisTooltipValue;
+ public TextAnchor aligment;
public List runtimeData { get { return m_RuntimeData; } }
public List labelValueList { get { return m_LabelValueList; } }
public List labelObjectList { get { return m_AxisLabelList; } }
diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs
index a5034a8f..c419eb6b 100644
--- a/Runtime/Component/Axis/AxisHandler.cs
+++ b/Runtime/Component/Axis/AxisHandler.cs
@@ -373,6 +373,7 @@ namespace XCharts
TextAnchor.MiddleRight);
if (axis.IsCategory() && axis.boundaryGap)
splitNumber -= 1;
+ axis.context.aligment = defaultAlignment;
for (int i = 0; i < splitNumber; i++)
{
var labelWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom);
diff --git a/Runtime/Component/Axis/AxisLabel.cs b/Runtime/Component/Axis/AxisLabel.cs
index 4d6a081c..934f5e0d 100644
--- a/Runtime/Component/Axis/AxisLabel.cs
+++ b/Runtime/Component/Axis/AxisLabel.cs
@@ -143,7 +143,7 @@ namespace XCharts.Runtime
m_TextLimit.SetRelatedText(txt, labelWidth);
}
- public string GetFormatterContent(int labelIndex, string category)
+ public override string GetFormatterContent(int labelIndex, string category)
{
if (string.IsNullOrEmpty(category))
return GetFormatterFunctionContent(labelIndex, category, category);
@@ -160,71 +160,13 @@ namespace XCharts.Runtime
}
}
- public string GetFormatterContent(int labelIndex, double value, double minValue, double maxValue, bool isLog = false)
+ public override string GetFormatterContent(int labelIndex, double value, double minValue, double maxValue, bool isLog = false)
{
if (showAsPositiveNumber && value < 0)
{
value = Math.Abs(value);
}
- if (string.IsNullOrEmpty(m_Formatter))
- {
- if (isLog)
- {
- return GetFormatterFunctionContent(labelIndex, value, ChartCached.NumberToStr(value, numericFormatter));
- }
- if (minValue >= -1 && minValue <= 1 && maxValue >= -1 && maxValue <= 1)
- {
- int minAcc = ChartHelper.GetFloatAccuracy(minValue);
- int maxAcc = ChartHelper.GetFloatAccuracy(maxValue);
- int curAcc = ChartHelper.GetFloatAccuracy(value);
- int acc = Mathf.Max(Mathf.Max(minAcc, maxAcc), curAcc);
- return GetFormatterFunctionContent(labelIndex, value, ChartCached.FloatToStr(value, numericFormatter, acc));
- }
- return GetFormatterFunctionContent(labelIndex, value, ChartCached.NumberToStr(value, numericFormatter));
- }
- else
- {
- var content = m_Formatter;
- FormatterHelper.ReplaceAxisLabelContent(ref content, numericFormatter, value);
- return GetFormatterFunctionContent(labelIndex, value, content);
- }
- }
-
- public string GetFormatterDateTime(int labelIndex, double value, double minValue, double maxValue)
- {
- var timestamp = (int) value;
- var dateTime = DateTimeUtil.GetDateTime(timestamp);
- var dateString = string.Empty;
- if (string.IsNullOrEmpty(numericFormatter))
- {
- dateString = DateTimeUtil.GetDateTimeFormatString(dateTime, maxValue - minValue);
- }
- else
- {
- dateString = dateTime.ToString(numericFormatter);
- }
- if (!string.IsNullOrEmpty(m_Formatter))
- {
- var content = m_Formatter;
- FormatterHelper.ReplaceAxisLabelContent(ref content, dateString);
- return GetFormatterFunctionContent(labelIndex, value, m_TextLimit.GetLimitContent(content));
- }
- else
- {
- return GetFormatterFunctionContent(labelIndex, value, m_TextLimit.GetLimitContent(dateString));
- }
- }
-
- private string GetFormatterFunctionContent(int labelIndex, string category, string currentContent)
- {
- return m_FormatterFunction == null ? currentContent :
- m_FormatterFunction(labelIndex, labelIndex, category, currentContent);
- }
-
- private string GetFormatterFunctionContent(int labelIndex, double value, string currentContent)
- {
- return m_FormatterFunction == null ? currentContent :
- m_FormatterFunction(labelIndex, labelIndex, null, currentContent);
+ return base.GetFormatterContent(labelIndex, value, minValue, maxValue, isLog);
}
}
}
\ No newline at end of file
diff --git a/Runtime/Component/Label/LabelStyle.cs b/Runtime/Component/Label/LabelStyle.cs
index 2aa4f187..3130a443 100644
--- a/Runtime/Component/Label/LabelStyle.cs
+++ b/Runtime/Component/Label/LabelStyle.cs
@@ -1,3 +1,4 @@
+using System;
using UnityEngine;
namespace XCharts.Runtime
@@ -315,5 +316,85 @@ namespace XCharts.Runtime
m_TextPadding = label.m_TextPadding;
m_TextStyle.Copy(label.m_TextStyle);
}
+
+ public virtual string GetFormatterContent(int labelIndex, string category)
+ {
+ if (string.IsNullOrEmpty(category))
+ return GetFormatterFunctionContent(labelIndex, category, category);
+
+ if (string.IsNullOrEmpty(m_Formatter))
+ {
+ return GetFormatterFunctionContent(labelIndex, category, category);
+ }
+ else
+ {
+ var content = m_Formatter;
+ FormatterHelper.ReplaceAxisLabelContent(ref content, category);
+ return GetFormatterFunctionContent(labelIndex, category, category);
+ }
+ }
+
+ public virtual string GetFormatterContent(int labelIndex, double value, double minValue, double maxValue, bool isLog = false)
+ {
+ if (string.IsNullOrEmpty(m_Formatter))
+ {
+ if (isLog)
+ {
+ return GetFormatterFunctionContent(labelIndex, value, ChartCached.NumberToStr(value, numericFormatter));
+ }
+ if (minValue >= -1 && minValue <= 1 && maxValue >= -1 && maxValue <= 1)
+ {
+ int minAcc = ChartHelper.GetFloatAccuracy(minValue);
+ int maxAcc = ChartHelper.GetFloatAccuracy(maxValue);
+ int curAcc = ChartHelper.GetFloatAccuracy(value);
+ int acc = Mathf.Max(Mathf.Max(minAcc, maxAcc), curAcc);
+ return GetFormatterFunctionContent(labelIndex, value, ChartCached.FloatToStr(value, numericFormatter, acc));
+ }
+ return GetFormatterFunctionContent(labelIndex, value, ChartCached.NumberToStr(value, numericFormatter));
+ }
+ else
+ {
+ var content = m_Formatter;
+ FormatterHelper.ReplaceAxisLabelContent(ref content, numericFormatter, value);
+ return GetFormatterFunctionContent(labelIndex, value, content);
+ }
+ }
+
+ public string GetFormatterDateTime(int labelIndex, double value, double minValue, double maxValue)
+ {
+ var timestamp = (int) value;
+ var dateTime = DateTimeUtil.GetDateTime(timestamp);
+ var dateString = string.Empty;
+ if (string.IsNullOrEmpty(numericFormatter))
+ {
+ dateString = DateTimeUtil.GetDateTimeFormatString(dateTime, maxValue - minValue);
+ }
+ else
+ {
+ dateString = dateTime.ToString(numericFormatter);
+ }
+ if (!string.IsNullOrEmpty(m_Formatter))
+ {
+ var content = m_Formatter;
+ FormatterHelper.ReplaceAxisLabelContent(ref content, dateString);
+ return GetFormatterFunctionContent(labelIndex, value, content);
+ }
+ else
+ {
+ return GetFormatterFunctionContent(labelIndex, value, dateString);
+ }
+ }
+
+ protected string GetFormatterFunctionContent(int labelIndex, string category, string currentContent)
+ {
+ return m_FormatterFunction == null ? currentContent :
+ m_FormatterFunction(labelIndex, labelIndex, category, currentContent);
+ }
+
+ protected string GetFormatterFunctionContent(int labelIndex, double value, string currentContent)
+ {
+ return m_FormatterFunction == null ? currentContent :
+ m_FormatterFunction(labelIndex, labelIndex, null, currentContent);
+ }
}
}
\ No newline at end of file
diff --git a/Runtime/Component/Tooltip/Tooltip.cs b/Runtime/Component/Tooltip/Tooltip.cs
index b6a9b9b9..08a0b423 100644
--- a/Runtime/Component/Tooltip/Tooltip.cs
+++ b/Runtime/Component/Tooltip/Tooltip.cs
@@ -120,7 +120,6 @@ namespace XCharts.Runtime
[SerializeField] private float m_ItemHeight = 25f;
[SerializeField] private Color32 m_BorderColor = new Color32(230, 230, 230, 255);
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.None);
- [SerializeField] private LabelStyle m_IndicatorLabelStyle = new LabelStyle();
[SerializeField]
private LabelStyle m_TitleLabelStyle = new LabelStyle()
{
@@ -378,15 +377,6 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); }
}
///
- /// the label style of tooltip axis indicator label.
- /// |提示框的坐标轴指示器文本的样式。
- ///
- public LabelStyle indicatorLabelStyle
- {
- get { return m_IndicatorLabelStyle; }
- set { if (value != null) { m_IndicatorLabelStyle = value; SetComponentDirty(); } }
- }
- ///
/// the textstyle of title.
/// |标题的文本样式。
///
@@ -420,14 +410,13 @@ namespace XCharts.Runtime
///
public override bool componentDirty
{
- get { return m_ComponentDirty || lineStyle.componentDirty || indicatorLabelStyle.componentDirty; }
+ get { return m_ComponentDirty || lineStyle.componentDirty; }
}
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
lineStyle.ClearComponentDirty();
- indicatorLabelStyle.ClearComponentDirty();
}
///
/// 当前提示框所指示的Serie索引(目前只对散点图有效)。
diff --git a/Runtime/Component/Tooltip/TooltipHandler.cs b/Runtime/Component/Tooltip/TooltipHandler.cs
index 75023b60..bfdd627b 100644
--- a/Runtime/Component/Tooltip/TooltipHandler.cs
+++ b/Runtime/Component/Tooltip/TooltipHandler.cs
@@ -9,7 +9,7 @@ namespace XCharts.Runtime
[UnityEngine.Scripting.Preserve]
internal sealed class TooltipHandler : MainComponentHandler
{
- private List m_IndicatorLabels = new List();
+ private Dictionary m_IndicatorLabels = new Dictionary();
private GameObject m_LabelRoot;
private ISerieContainer m_PointerContainer;
@@ -52,28 +52,35 @@ namespace XCharts.Runtime
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
ChartHelper.HideAllObject(m_LabelRoot);
m_IndicatorLabels.Clear();
- for (int i = 0; i < 2; i++)
+ foreach (var com in chart.components)
{
- var labelName = "label_" + i;
- var item = ChartHelper.AddTooltipIndicatorLabel(component, labelName, m_LabelRoot.transform,
- chart.theme, TextAnchor.MiddleCenter);
- item.SetActive(false);
- m_IndicatorLabels.Add(item);
+ if (com is Axis)
+ {
+ var axis = com as Axis;
+ var labelName = ChartCached.GetComponentObjectName(axis);
+ var item = ChartHelper.AddTooltipIndicatorLabel(component, labelName, m_LabelRoot.transform,
+ chart.theme, axis.context.aligment, axis.indicatorLabel);
+ item.SetActive(false);
+ m_IndicatorLabels[labelName] = item;
+ }
}
};
tooltip.refreshComponent();
}
- private ChartLabel GetIndicatorLabel(int index)
+ private ChartLabel GetIndicatorLabel(Axis axis)
{
if (m_LabelRoot == null) return null;
- if (index < m_IndicatorLabels.Count) return m_IndicatorLabels[index];
+ var key = ChartCached.GetComponentObjectName(axis);
+ if (m_IndicatorLabels.ContainsKey(key))
+ {
+ return m_IndicatorLabels[key];
+ }
else
{
- var labelName = "label_" + index;
- var item = ChartHelper.AddTooltipIndicatorLabel(component, labelName, m_LabelRoot.transform,
- chart.theme, TextAnchor.MiddleCenter);
- m_IndicatorLabels.Add(item);
+ var item = ChartHelper.AddTooltipIndicatorLabel(component, key, m_LabelRoot.transform,
+ chart.theme, TextAnchor.MiddleCenter, axis.indicatorLabel);
+ m_IndicatorLabels[key] = item;
return item;
}
}
@@ -138,7 +145,6 @@ namespace XCharts.Runtime
{
if (tooltip.type == Tooltip.Type.Corss)
{
- var labelCount = 0;
if (m_PointerContainer is GridCoord)
{
var grid = m_PointerContainer as GridCoord;
@@ -150,7 +156,7 @@ namespace XCharts.Runtime
var axis = component as Axis;
if (axis.gridIndex == grid.index)
{
- var label = GetIndicatorLabel(labelCount++);
+ var label = GetIndicatorLabel(axis);
SetTooltipIndicatorLabel(tooltip, axis, label);
}
}
@@ -167,7 +173,7 @@ namespace XCharts.Runtime
var axis = component as Axis;
if (axis.polarIndex == polar.index)
{
- var label = GetIndicatorLabel(labelCount++);
+ var label = GetIndicatorLabel(axis);
SetTooltipIndicatorLabel(tooltip, axis, label);
}
}
@@ -183,16 +189,27 @@ namespace XCharts.Runtime
if (double.IsNaN(axis.context.pointerValue)) return;
label.SetActive(true);
label.SetTextActive(true);
- label.SetPosition(axis.context.pointerLabelPosition);
+ label.SetPosition(axis.context.pointerLabelPosition + axis.indicatorLabel.offset);
+
if (axis.IsCategory())
- label.SetText(axis.GetData((int) axis.context.pointerValue));
+ {
+ var index = (int) axis.context.pointerValue;
+ var category = axis.GetData(index);
+ label.SetText(axis.indicatorLabel.GetFormatterContent(index, category));
+ }
+ else if (axis.IsTime())
+ {
+ label.SetText(axis.indicatorLabel.GetFormatterDateTime(0, axis.context.pointerValue, axis.context.minValue, axis.context.maxValue));
+ }
else
- label.SetText(axis.context.pointerValue.ToString("f2"));
+ {
+ label.SetText(axis.indicatorLabel.GetFormatterContent(0, axis.context.pointerValue, axis.context.minValue, axis.context.maxValue, axis.IsLog()));
+ }
var textColor = axis.axisLabel.textStyle.GetColor(chart.theme.axis.textColor);
- if (ChartHelper.IsClearColor(tooltip.indicatorLabelStyle.background.color))
+ if (ChartHelper.IsClearColor(axis.indicatorLabel.background.color))
label.color = textColor;
else
- label.color = tooltip.indicatorLabelStyle.background.color;
+ label.color = axis.indicatorLabel.background.color;
label.SetTextColor(Color.white);
}
diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs
index 8a2fee39..6d600da7 100644
--- a/Runtime/Internal/Utilities/ChartHelper.cs
+++ b/Runtime/Internal/Utilities/ChartHelper.cs
@@ -440,11 +440,11 @@ namespace XCharts.Runtime
}
internal static ChartLabel AddTooltipIndicatorLabel(Tooltip tooltip, string name, Transform parent,
- ThemeStyle theme, TextAnchor alignment)
+ ThemeStyle theme, TextAnchor alignment, LabelStyle labelStyle)
{
- var label = ChartHelper.AddChartLabel(name, parent, tooltip.indicatorLabelStyle, theme.tooltip,
+ var label = ChartHelper.AddChartLabel(name, parent, labelStyle, theme.tooltip,
"", Color.clear, alignment);
- label.SetActive(tooltip.show && tooltip.indicatorLabelStyle.show);
+ label.SetActive(tooltip.show && labelStyle.show);
return label;
}