mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 16:00:24 +00:00
[feature] 增加Axis的indicatorLabel,移除Tooltip的indicatorLabelStyle (#226)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)<br/>获得Serie的标识颜色。 |
|
||||
| GetOrAddChartComponent<T>() |public T GetOrAddChartComponent<T>() where T : MainComponent|
|
||||
| GetPainter() |public Painter GetPainter(int index)|
|
||||
| GetSerie() |public Serie GetSerie(int serieIndex)|
|
||||
|
||||
@@ -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)<br/>获得Serie的标识颜色。 |
|
||||
| GetOrAddChartComponent<T>() |public T GetOrAddChartComponent<T>() where T : MainComponent|
|
||||
| GetPainter() |public Painter GetPainter(int index)|
|
||||
| GetSerie() |public Serie GetSerie(int serieIndex)|
|
||||
|
||||
@@ -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.<br/>`SerieState`:<br/>- `Normal`: Normal state.<br/>- `Emphasis`: Emphasis state.<br/>- `Blur`: Blur state.<br/>- `Select`: Select state.<br/>- `Auto`: Auto state.<br/>|
|
||||
|colorBy||v3.2.0|The policy to take color from theme.<br/>`SerieColorBy`:<br/>- `Default`: Select state.<br/>- `Serie`: assigns the colors in the palette by serie, so that all data in the same series are in the same color;.<br/>- `Data`: assigns colors in the palette according to data items, with each data item using a different color..<br/>|
|
||||
|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.
|
||||
|
||||
|
||||
@@ -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|系列的默认状态。<br/>`SerieState`:<br/>- `Normal`: 正常状态。<br/>- `Emphasis`: 高亮状态。<br/>- `Blur`: 淡出状态。<br/>- `Select`: 选中状态。<br/>- `Auto`: 自动保持和父节点一致。一般用在SerieData。<br/>|
|
||||
|colorBy||v3.2.0|从主题中取色的策略。<br/>`SerieColorBy`:<br/>- `Default`: 默认策略。每种Serie都有自己的默认的取颜色策略。比如Line默认是Series策略,Pie默认是Data策略<br/>- `Serie`: 按照系列分配调色盘中的颜色,同一系列中的所有数据都是用相同的颜色。<br/>- `Data`: 按照数据项分配调色盘中的颜色,每个数据项都使用不同的颜色。<br/>|
|
||||
|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|||内容部分的文本样式列表。和列一一对应。
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -39,7 +39,6 @@ namespace XCharts.Editor
|
||||
PropertyField("m_IgnoreDataDefaultContent");
|
||||
});
|
||||
PropertyField("m_LineStyle");
|
||||
PropertyField("m_IndicatorLabelStyle");
|
||||
PropertyField("m_TitleLabelStyle");
|
||||
PropertyListField("m_ContentLabelStyles");
|
||||
--EditorGUI.indentLevel;
|
||||
|
||||
@@ -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(); } }
|
||||
}
|
||||
/// <summary>
|
||||
/// Style of axis tooltip indicator label.
|
||||
/// |指示器文本的样式。Tooltip为Cross时使用。
|
||||
/// </summary>
|
||||
public LabelStyle indicatorLabel
|
||||
{
|
||||
get { return m_IndicatorLabel; }
|
||||
set { if (value != null) { m_IndicatorLabel = value; SetComponentDirty(); } }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether to add new data at the head or at the end of the list.
|
||||
/// |添加新数据时是在列表的头部还是尾部加入。
|
||||
/// </summary>
|
||||
@@ -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<Sprite>();
|
||||
axis.data = new List<string>();
|
||||
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<Sprite>(icons, axis.icons);
|
||||
}
|
||||
@@ -719,8 +734,6 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获得指定区域缩放的类目数据列表
|
||||
/// </summary>
|
||||
|
||||
@@ -56,6 +56,7 @@ namespace XCharts.Runtime
|
||||
public double pointerValue;
|
||||
public Vector3 pointerLabelPosition;
|
||||
public double axisTooltipValue;
|
||||
public TextAnchor aligment;
|
||||
public List<string> runtimeData { get { return m_RuntimeData; } }
|
||||
public List<double> labelValueList { get { return m_LabelValueList; } }
|
||||
public List<ChartLabel> labelObjectList { get { return m_AxisLabelList; } }
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the label style of tooltip axis indicator label.
|
||||
/// |提示框的坐标轴指示器文本的样式。
|
||||
/// </summary>
|
||||
public LabelStyle indicatorLabelStyle
|
||||
{
|
||||
get { return m_IndicatorLabelStyle; }
|
||||
set { if (value != null) { m_IndicatorLabelStyle = value; SetComponentDirty(); } }
|
||||
}
|
||||
/// <summary>
|
||||
/// the textstyle of title.
|
||||
/// |标题的文本样式。
|
||||
/// </summary>
|
||||
@@ -420,14 +410,13 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前提示框所指示的Serie索引(目前只对散点图有效)。
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace XCharts.Runtime
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class TooltipHandler : MainComponentHandler<Tooltip>
|
||||
{
|
||||
private List<ChartLabel> m_IndicatorLabels = new List<ChartLabel>();
|
||||
private Dictionary<string, ChartLabel> m_IndicatorLabels = new Dictionary<string, ChartLabel>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user