[feature] 增加AxisindicatorLabel,移除TooltipindicatorLabelStyle (#226)

This commit is contained in:
monitor1394
2022-10-30 10:28:17 +08:00
parent e0974fffbe
commit c9d554d184
15 changed files with 152 additions and 103 deletions

View File

@@ -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>

View File

@@ -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; } }

View File

@@ -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);

View File

@@ -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);
}
}
}