增加AxisLabelshowZeroLabel设置是否显示0刻度

This commit is contained in:
monitor1394
2025-04-15 22:51:59 +08:00
parent ccf815c853
commit 21ffcba0c0
10 changed files with 46 additions and 14 deletions

View File

@@ -915,7 +915,7 @@ public bool IsLog()
### Axis.IsNeedShowLabel
public bool IsNeedShowLabel(int index, int total = 0)
public bool IsNeedShowLabel(int index, int total = 0, string content = null)
### Axis.IsRight
@@ -1219,7 +1219,7 @@ public override string GetFormatterContent(int labelIndex, int totalIndex, doubl
### AxisLabel.IsNeedShowLabel
public bool IsNeedShowLabel(int index, int total)
public bool IsNeedShowLabel(int index, int total, string content = null)
### AxisLabel.SetRelatedText

View File

@@ -804,6 +804,12 @@ Whether to display the last label.
Whether to display the first label.
### AxisLabel.showZeroLabel
`bool` `true` `v3.15.0`
Whether to display the zero label.
### AxisLabel.textLimit
[TextLimit](#textlimit)

View File

@@ -915,7 +915,7 @@ public bool IsLog()
### Axis.IsNeedShowLabel
public bool IsNeedShowLabel(int index, int total = 0)
public bool IsNeedShowLabel(int index, int total = 0, string content = null)
### Axis.IsRight
@@ -1219,7 +1219,7 @@ public override string GetFormatterContent(int labelIndex, int totalIndex, doubl
### AxisLabel.IsNeedShowLabel
public bool IsNeedShowLabel(int index, int total)
public bool IsNeedShowLabel(int index, int total, string content = null)
### AxisLabel.SetRelatedText

View File

@@ -80,6 +80,8 @@ slug: /changelog
## master
* (2025.04.15) 增加`AxisLabel``showZeroLabel`设置是否显示0刻度
* (2025.04.08) 增加`UIStatistic``desc`描述文本设置支持
* (2025.04.07) 修复`Gantt`甘特图在有多维数据时计算的时间区间不准确的问题
* (2025.04.07) 优化`Axis``Time`时间轴支持设置Custom和ceilRate
* (2025.04.07) 修复`GridCoord`在设置背景色且Serie开启Clip时会覆盖图表的问题

View File

@@ -804,6 +804,12 @@ class in XCharts.Runtime / 继承自: [LabelStyle](#labelstyle)
是否显示第一个文本。
### AxisLabel.showZeroLabel
`bool` `true` `v3.15.0`
是否显示0刻度文本。
### AxisLabel.textLimit
[TextLimit](#textlimit)

View File

@@ -164,6 +164,7 @@ namespace XCharts.Editor
PropertyField(prop, "m_ShowAsPositiveNumber");
PropertyField(prop, "m_OnZero");
PropertyField(prop, "m_ShowZeroLabel");
PropertyField(prop, "m_ShowStartLabel");
PropertyField(prop, "m_ShowEndLabel");

View File

@@ -616,13 +616,13 @@ namespace XCharts.Runtime
return m_Position == AxisPosition.Bottom;
}
public bool IsNeedShowLabel(int index, int total = 0)
public bool IsNeedShowLabel(int index, int total = 0, string content = null)
{
if (total == 0)
{
total = context.labelValueList.Count;
}
return axisLabel.IsNeedShowLabel(index, total);
return axisLabel.IsNeedShowLabel(index, total, content);
}
public void SetNeedUpdateFilterData()

View File

@@ -447,13 +447,17 @@ namespace XCharts
return Math.Pow(10, n);
}
internal void CheckValueLabelActive(Axis axis, int i, ChartLabel label, Vector3 pos)
internal void CheckValueLabelActive(Axis axis, int i, ChartLabel label, Vector3 pos, string content = null)
{
if (!axis.show || !axis.axisLabel.show)
{
label.SetTextActive(false);
return;
}
if(content == null)
{
content = label.text.text.text;
}
if (axis.IsValue())
{
if (orient == Orient.Horizonal)
@@ -461,12 +465,12 @@ namespace XCharts
if (i == 0)
{
var dist = GetLabelPosition(0, 1).x - pos.x;
label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredWidth());
label.SetTextActive(axis.IsNeedShowLabel(i,0,content) && dist > label.text.GetPreferredWidth());
}
else if (i == axis.context.labelValueList.Count - 1)
{
var dist = pos.x - GetLabelPosition(0, i - 1).x;
label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredWidth());
label.SetTextActive(axis.IsNeedShowLabel(i,0,content) && dist > label.text.GetPreferredWidth());
}
}
else
@@ -474,12 +478,12 @@ namespace XCharts
if (i == 0)
{
var dist = GetLabelPosition(0, 1).y - pos.y;
label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredHeight());
label.SetTextActive(axis.IsNeedShowLabel(i,0,content) && dist > label.text.GetPreferredHeight());
}
else if (i == axis.context.labelValueList.Count - 1)
{
var dist = pos.y - GetLabelPosition(0, i - 1).y;
label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredHeight());
label.SetTextActive(axis.IsNeedShowLabel(i,0,content) && dist > label.text.GetPreferredHeight());
}
}
}
@@ -683,7 +687,7 @@ namespace XCharts
var pos = GetLabelPosition(totalWidth + gapWidth, i);
label.SetPosition(pos);
CheckValueLabelActive(axis, i, label, pos);
CheckValueLabelActive(axis, i, label, pos, labelName);
axis.context.labelObjectList.Add(label);

View File

@@ -17,6 +17,7 @@ namespace XCharts.Runtime
[SerializeField] private bool m_OnZero = false;
[SerializeField] private bool m_ShowStartLabel = true;
[SerializeField] private bool m_ShowEndLabel = true;
[SerializeField][Since("v3.15.0")] private bool m_ShowZeroLabel = true;
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
/// <summary>
@@ -74,6 +75,15 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_ShowEndLabel, value)) SetComponentDirty(); }
}
/// <summary>
/// Whether to display the zero label.
/// ||是否显示0刻度文本。
/// </summary>
public bool showZeroLabel
{
get { return m_ShowZeroLabel; }
set { if (PropertyUtil.SetStruct(ref m_ShowZeroLabel, value)) SetComponentDirty(); }
}
/// <summary>
/// 文本限制。
/// </summary>
public TextLimit textLimit
@@ -118,6 +128,7 @@ namespace XCharts.Runtime
height = height,
showStartLabel = showStartLabel,
showEndLabel = showEndLabel,
showZeroLabel = showZeroLabel,
textLimit = textLimit.Clone()
};
axisLabel.textStyle.Copy(textStyle);
@@ -136,6 +147,7 @@ namespace XCharts.Runtime
height = axisLabel.height;
showStartLabel = axisLabel.showStartLabel;
showEndLabel = axisLabel.showEndLabel;
showZeroLabel = axisLabel.showZeroLabel;
textLimit.Copy(axisLabel.textLimit);
textStyle.Copy(axisLabel.textStyle);
}
@@ -171,13 +183,14 @@ namespace XCharts.Runtime
return base.GetFormatterContent(labelIndex, totalIndex, value, minValue, maxValue, isLog);
}
public bool IsNeedShowLabel(int index, int total)
public bool IsNeedShowLabel(int index, int total, string content = null)
{
var labelShow = show && (interval == 0 || index % (interval + 1) == 0);
if (labelShow)
{
if (!showStartLabel && index == 0) labelShow = false;
else if (!showEndLabel && index == total - 1) labelShow = false;
if (labelShow && content == "0") labelShow = showZeroLabel;
}
return labelShow;
}

View File

@@ -461,7 +461,7 @@ namespace XCharts.Runtime
{
var textStyle = axis.axisLabel.textStyle;
var label = AddChartLabel(name, parent, axis.axisLabel, theme, content, autoColor, autoAlignment);
var labelShow = axis.IsNeedShowLabel(index, total);
var labelShow = axis.IsNeedShowLabel(index, total, content);
label.UpdateIcon(axis.axisLabel.icon, axis.GetIcon(index), iconDefaultColor);
label.text.SetActive(labelShow);
return label;