[feature][axis] support Settings.axisMaxSplitNumber

This commit is contained in:
monitor1394
2022-07-04 13:37:16 +08:00
parent 2248b61d03
commit 4d5e2481b0
5 changed files with 17 additions and 3 deletions

View File

@@ -56,6 +56,7 @@
## master ## master
* (2022.07.04) 增加`Settings``axisMaxSplitNumber`参数设置`Axis`的最大分隔段数
* (2022.07.04) 修复`Axis`在设置`offset``Tick`绘制位置异常的问题 (#209) * (2022.07.04) 修复`Axis`在设置`offset``Tick`绘制位置异常的问题 (#209)
* (2022.07.03) 优化`AxisLabel``formatterFunction`自定义委托 * (2022.07.03) 优化`AxisLabel``formatterFunction`自定义委托
* (2022.07.03) 增加`AxisName``onZero`参数支持设置坐标轴名称位置是否和Y轴0刻度一致 (#207) * (2022.07.03) 增加`AxisName``onZero`参数支持设置坐标轴名称位置是否和Y轴0刻度一致 (#207)

View File

@@ -28,6 +28,7 @@ namespace XCharts.Editor
PropertyField(prop, "m_LineSmoothness"); PropertyField(prop, "m_LineSmoothness");
PropertyField(prop, "m_LineSegmentDistance"); PropertyField(prop, "m_LineSegmentDistance");
PropertyField(prop, "m_CicleSmoothness"); PropertyField(prop, "m_CicleSmoothness");
PropertyField(prop, "m_AxisMaxSplitNumber");
PropertyField(prop, "m_LegendIconLineWidth"); PropertyField(prop, "m_LegendIconLineWidth");
PropertyListField(prop, "m_LegendIconCornerRadius", true); PropertyListField(prop, "m_LegendIconCornerRadius", true);
--EditorGUI.indentLevel; --EditorGUI.indentLevel;

View File

@@ -218,7 +218,7 @@ namespace XCharts
axis.UpdateLabelText(runtimeWidth, dataZoom, isPercentStack); axis.UpdateLabelText(runtimeWidth, dataZoom, isPercentStack);
} }
internal static void UpdateAxisTickValueList(Axis axis) internal void UpdateAxisTickValueList(Axis axis)
{ {
if (axis.IsTime()) if (axis.IsTime())
{ {
@@ -267,12 +267,13 @@ namespace XCharts
list.Add(axis.context.minValue); list.Add(axis.context.minValue);
value = Math.Ceiling(axis.context.minValue / tick) * tick; value = Math.Ceiling(axis.context.minValue / tick) * tick;
} }
var maxSplitNumber = chart.settings.axisMaxSplitNumber;
while (value <= axis.context.maxValue) while (value <= axis.context.maxValue)
{ {
list.Add(value); list.Add(value);
value += tick; value += tick;
if (list.Count > 100) if (maxSplitNumber > 0 && list.Count > maxSplitNumber)
break; break;
} }
if (!ChartHelper.IsEquals(axis.context.maxValue, list[list.Count - 1])) if (!ChartHelper.IsEquals(axis.context.maxValue, list[list.Count - 1]))

View File

@@ -23,6 +23,7 @@ namespace XCharts.Runtime
[SerializeField][Range(1, 10)] protected float m_CicleSmoothness = 2f; [SerializeField][Range(1, 10)] protected float m_CicleSmoothness = 2f;
[SerializeField] protected float m_LegendIconLineWidth = 2; [SerializeField] protected float m_LegendIconLineWidth = 2;
[SerializeField] private float[] m_LegendIconCornerRadius = new float[] { 0.25f, 0.25f, 0.25f, 0.25f }; [SerializeField] private float[] m_LegendIconCornerRadius = new float[] { 0.25f, 0.25f, 0.25f, 0.25f };
[SerializeField][Since("v3.1.0")] protected float m_AxisMaxSplitNumber = 20;
public bool show { get { return m_Show; } } public bool show { get { return m_Show; } }
/// <summary> /// <summary>
@@ -137,6 +138,16 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetClass(ref m_LegendIconCornerRadius, value, true)) SetVerticesDirty(); } set { if (PropertyUtil.SetClass(ref m_LegendIconCornerRadius, value, true)) SetVerticesDirty(); }
} }
/// <summary>
/// the max splitnumber of axis.
/// |坐标轴最大分隔段数。段数过大时可能会生成较多的label节点。
/// </summary>
public float axisMaxSplitNumber
{
get { return m_AxisMaxSplitNumber; }
set { if (PropertyUtil.SetStruct(ref m_AxisMaxSplitNumber, value)) SetVerticesDirty(); }
}
public void Copy(Settings settings) public void Copy(Settings settings)
{ {
m_ReversePainter = settings.reversePainter; m_ReversePainter = settings.reversePainter;

View File

@@ -165,7 +165,7 @@ namespace XCharts.Runtime
axis.context.offset = 0; axis.context.offset = 0;
axis.context.lastCheckInverse = axis.inverse; axis.context.lastCheckInverse = axis.inverse;
AxisHandler<ParallelAxis>.UpdateAxisTickValueList(axis); (axis.handler as ParallelAxisHander).UpdateAxisTickValueList(axis);
(axis.handler as ParallelAxisHander).UpdateAxisLabelText(axis); (axis.handler as ParallelAxisHander).UpdateAxisLabelText(axis);
chart.RefreshChart(); chart.RefreshChart();
} }