mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-28 20:28:46 +00:00
增加AxisLabel的showZeroLabel设置是否显示0刻度
This commit is contained in:
@@ -915,7 +915,7 @@ public bool IsLog()
|
|||||||
|
|
||||||
### Axis.IsNeedShowLabel
|
### Axis.IsNeedShowLabel
|
||||||
|
|
||||||
public bool IsNeedShowLabel(int index, int total = 0)
|
public bool IsNeedShowLabel(int index, int total = 0, string content = null)
|
||||||
|
|
||||||
### Axis.IsRight
|
### Axis.IsRight
|
||||||
|
|
||||||
@@ -1219,7 +1219,7 @@ public override string GetFormatterContent(int labelIndex, int totalIndex, doubl
|
|||||||
|
|
||||||
### AxisLabel.IsNeedShowLabel
|
### AxisLabel.IsNeedShowLabel
|
||||||
|
|
||||||
public bool IsNeedShowLabel(int index, int total)
|
public bool IsNeedShowLabel(int index, int total, string content = null)
|
||||||
|
|
||||||
### AxisLabel.SetRelatedText
|
### AxisLabel.SetRelatedText
|
||||||
|
|
||||||
|
|||||||
@@ -804,6 +804,12 @@ Whether to display the last label.
|
|||||||
|
|
||||||
Whether to display the first label.
|
Whether to display the first label.
|
||||||
|
|
||||||
|
### AxisLabel.showZeroLabel
|
||||||
|
|
||||||
|
`bool` `true` `v3.15.0`
|
||||||
|
|
||||||
|
Whether to display the zero label.
|
||||||
|
|
||||||
### AxisLabel.textLimit
|
### AxisLabel.textLimit
|
||||||
|
|
||||||
[TextLimit](#textlimit)
|
[TextLimit](#textlimit)
|
||||||
|
|||||||
@@ -915,7 +915,7 @@ public bool IsLog()
|
|||||||
|
|
||||||
### Axis.IsNeedShowLabel
|
### Axis.IsNeedShowLabel
|
||||||
|
|
||||||
public bool IsNeedShowLabel(int index, int total = 0)
|
public bool IsNeedShowLabel(int index, int total = 0, string content = null)
|
||||||
|
|
||||||
### Axis.IsRight
|
### Axis.IsRight
|
||||||
|
|
||||||
@@ -1219,7 +1219,7 @@ public override string GetFormatterContent(int labelIndex, int totalIndex, doubl
|
|||||||
|
|
||||||
### AxisLabel.IsNeedShowLabel
|
### AxisLabel.IsNeedShowLabel
|
||||||
|
|
||||||
public bool IsNeedShowLabel(int index, int total)
|
public bool IsNeedShowLabel(int index, int total, string content = null)
|
||||||
|
|
||||||
### AxisLabel.SetRelatedText
|
### AxisLabel.SetRelatedText
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ slug: /changelog
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2025.04.15) 增加`AxisLabel`的`showZeroLabel`设置是否显示0刻度
|
||||||
|
* (2025.04.08) 增加`UIStatistic`的`desc`描述文本设置支持
|
||||||
* (2025.04.07) 修复`Gantt`甘特图在有多维数据时计算的时间区间不准确的问题
|
* (2025.04.07) 修复`Gantt`甘特图在有多维数据时计算的时间区间不准确的问题
|
||||||
* (2025.04.07) 优化`Axis`的`Time`时间轴支持设置Custom和ceilRate
|
* (2025.04.07) 优化`Axis`的`Time`时间轴支持设置Custom和ceilRate
|
||||||
* (2025.04.07) 修复`GridCoord`在设置背景色且Serie开启Clip时会覆盖图表的问题
|
* (2025.04.07) 修复`GridCoord`在设置背景色且Serie开启Clip时会覆盖图表的问题
|
||||||
|
|||||||
@@ -804,6 +804,12 @@ class in XCharts.Runtime / 继承自: [LabelStyle](#labelstyle)
|
|||||||
|
|
||||||
是否显示第一个文本。
|
是否显示第一个文本。
|
||||||
|
|
||||||
|
### AxisLabel.showZeroLabel
|
||||||
|
|
||||||
|
`bool` `true` `v3.15.0`
|
||||||
|
|
||||||
|
是否显示0刻度文本。
|
||||||
|
|
||||||
### AxisLabel.textLimit
|
### AxisLabel.textLimit
|
||||||
|
|
||||||
[TextLimit](#textlimit)
|
[TextLimit](#textlimit)
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ namespace XCharts.Editor
|
|||||||
|
|
||||||
PropertyField(prop, "m_ShowAsPositiveNumber");
|
PropertyField(prop, "m_ShowAsPositiveNumber");
|
||||||
PropertyField(prop, "m_OnZero");
|
PropertyField(prop, "m_OnZero");
|
||||||
|
PropertyField(prop, "m_ShowZeroLabel");
|
||||||
PropertyField(prop, "m_ShowStartLabel");
|
PropertyField(prop, "m_ShowStartLabel");
|
||||||
PropertyField(prop, "m_ShowEndLabel");
|
PropertyField(prop, "m_ShowEndLabel");
|
||||||
|
|
||||||
|
|||||||
@@ -616,13 +616,13 @@ namespace XCharts.Runtime
|
|||||||
return m_Position == AxisPosition.Bottom;
|
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)
|
if (total == 0)
|
||||||
{
|
{
|
||||||
total = context.labelValueList.Count;
|
total = context.labelValueList.Count;
|
||||||
}
|
}
|
||||||
return axisLabel.IsNeedShowLabel(index, total);
|
return axisLabel.IsNeedShowLabel(index, total, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetNeedUpdateFilterData()
|
public void SetNeedUpdateFilterData()
|
||||||
|
|||||||
@@ -447,13 +447,17 @@ namespace XCharts
|
|||||||
return Math.Pow(10, n);
|
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)
|
if (!axis.show || !axis.axisLabel.show)
|
||||||
{
|
{
|
||||||
label.SetTextActive(false);
|
label.SetTextActive(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(content == null)
|
||||||
|
{
|
||||||
|
content = label.text.text.text;
|
||||||
|
}
|
||||||
if (axis.IsValue())
|
if (axis.IsValue())
|
||||||
{
|
{
|
||||||
if (orient == Orient.Horizonal)
|
if (orient == Orient.Horizonal)
|
||||||
@@ -461,12 +465,12 @@ namespace XCharts
|
|||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
var dist = GetLabelPosition(0, 1).x - pos.x;
|
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)
|
else if (i == axis.context.labelValueList.Count - 1)
|
||||||
{
|
{
|
||||||
var dist = pos.x - GetLabelPosition(0, i - 1).x;
|
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
|
else
|
||||||
@@ -474,12 +478,12 @@ namespace XCharts
|
|||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
var dist = GetLabelPosition(0, 1).y - pos.y;
|
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)
|
else if (i == axis.context.labelValueList.Count - 1)
|
||||||
{
|
{
|
||||||
var dist = pos.y - GetLabelPosition(0, i - 1).y;
|
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);
|
var pos = GetLabelPosition(totalWidth + gapWidth, i);
|
||||||
label.SetPosition(pos);
|
label.SetPosition(pos);
|
||||||
CheckValueLabelActive(axis, i, label, pos);
|
CheckValueLabelActive(axis, i, label, pos, labelName);
|
||||||
|
|
||||||
axis.context.labelObjectList.Add(label);
|
axis.context.labelObjectList.Add(label);
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ namespace XCharts.Runtime
|
|||||||
[SerializeField] private bool m_OnZero = false;
|
[SerializeField] private bool m_OnZero = false;
|
||||||
[SerializeField] private bool m_ShowStartLabel = true;
|
[SerializeField] private bool m_ShowStartLabel = true;
|
||||||
[SerializeField] private bool m_ShowEndLabel = true;
|
[SerializeField] private bool m_ShowEndLabel = true;
|
||||||
|
[SerializeField][Since("v3.15.0")] private bool m_ShowZeroLabel = true;
|
||||||
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
|
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -74,6 +75,15 @@ namespace XCharts.Runtime
|
|||||||
set { if (PropertyUtil.SetStruct(ref m_ShowEndLabel, value)) SetComponentDirty(); }
|
set { if (PropertyUtil.SetStruct(ref m_ShowEndLabel, value)) SetComponentDirty(); }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public TextLimit textLimit
|
public TextLimit textLimit
|
||||||
@@ -118,6 +128,7 @@ namespace XCharts.Runtime
|
|||||||
height = height,
|
height = height,
|
||||||
showStartLabel = showStartLabel,
|
showStartLabel = showStartLabel,
|
||||||
showEndLabel = showEndLabel,
|
showEndLabel = showEndLabel,
|
||||||
|
showZeroLabel = showZeroLabel,
|
||||||
textLimit = textLimit.Clone()
|
textLimit = textLimit.Clone()
|
||||||
};
|
};
|
||||||
axisLabel.textStyle.Copy(textStyle);
|
axisLabel.textStyle.Copy(textStyle);
|
||||||
@@ -136,6 +147,7 @@ namespace XCharts.Runtime
|
|||||||
height = axisLabel.height;
|
height = axisLabel.height;
|
||||||
showStartLabel = axisLabel.showStartLabel;
|
showStartLabel = axisLabel.showStartLabel;
|
||||||
showEndLabel = axisLabel.showEndLabel;
|
showEndLabel = axisLabel.showEndLabel;
|
||||||
|
showZeroLabel = axisLabel.showZeroLabel;
|
||||||
textLimit.Copy(axisLabel.textLimit);
|
textLimit.Copy(axisLabel.textLimit);
|
||||||
textStyle.Copy(axisLabel.textStyle);
|
textStyle.Copy(axisLabel.textStyle);
|
||||||
}
|
}
|
||||||
@@ -171,13 +183,14 @@ namespace XCharts.Runtime
|
|||||||
return base.GetFormatterContent(labelIndex, totalIndex, value, minValue, maxValue, isLog);
|
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);
|
var labelShow = show && (interval == 0 || index % (interval + 1) == 0);
|
||||||
if (labelShow)
|
if (labelShow)
|
||||||
{
|
{
|
||||||
if (!showStartLabel && index == 0) labelShow = false;
|
if (!showStartLabel && index == 0) labelShow = false;
|
||||||
else if (!showEndLabel && index == total - 1) labelShow = false;
|
else if (!showEndLabel && index == total - 1) labelShow = false;
|
||||||
|
if (labelShow && content == "0") labelShow = showZeroLabel;
|
||||||
}
|
}
|
||||||
return labelShow;
|
return labelShow;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -461,7 +461,7 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
var textStyle = axis.axisLabel.textStyle;
|
var textStyle = axis.axisLabel.textStyle;
|
||||||
var label = AddChartLabel(name, parent, axis.axisLabel, theme, content, autoColor, autoAlignment);
|
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.UpdateIcon(axis.axisLabel.icon, axis.GetIcon(index), iconDefaultColor);
|
||||||
label.text.SetActive(labelShow);
|
label.text.SetActive(labelShow);
|
||||||
return label;
|
return label;
|
||||||
|
|||||||
Reference in New Issue
Block a user