mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 08:50:10 +00:00
[feature] 增加Axis的indicatorLabel,移除Tooltip的indicatorLabelStyle (#226)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user