[feature][axis] support AxisName.onZero (#207)

This commit is contained in:
monitor1394
2022-07-03 10:02:22 +08:00
parent 9b263c883b
commit 33fd4aa9f3
4 changed files with 17 additions and 3 deletions

View File

@@ -54,6 +54,7 @@
## master
* (2022.07.05) 增加`AxisName``onZero`参数支持设置坐标轴名称位置是否和Y轴0刻度一致 (#207)
* (2022.07.02) 修复`PieChart`用代码动态创建时`Legend`不正常的问题 (#206)
* (2022.07.02) 修复`YAxis``AxisLabel`设置`onZero`不生效的问题
* (2022.07.02) 修复`AxisLabel`代码设置`distance`属性后一直刷新的问题

View File

@@ -181,6 +181,7 @@ namespace XCharts.Editor
{
++EditorGUI.indentLevel;
PropertyField(prop, "m_Name");
PropertyField(prop, "m_OnZero");
PropertyField(prop, "m_LabelStyle");
--EditorGUI.indentLevel;
}

View File

@@ -424,7 +424,8 @@ namespace XCharts
var autoColor = axis.axisLine.GetColor(chart.theme.axis.lineColor);
if (orient == Orient.Horizonal)
{
var posY = GetAxisLineXOrY() + offset.y;
var grid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
var posY = !axis.axisName.onZero && grid != null? grid.context.y : GetAxisLineXOrY() + offset.y;
switch (axis.axisName.labelStyle.position)
{
case LabelStyle.Position.Start:
@@ -460,7 +461,8 @@ namespace XCharts
}
else
{
var posX = GetAxisLineXOrY() + offset.x;
var grid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
var posX = !axis.axisName.onZero && grid != null? grid.context.x : GetAxisLineXOrY() + offset.x;
switch (axis.axisName.labelStyle.position)
{
case LabelStyle.Position.Start:

View File

@@ -12,11 +12,12 @@ namespace XCharts.Runtime
{
[SerializeField] private bool m_Show;
[SerializeField] private string m_Name;
[SerializeField][Since("v3.1.0")] private bool m_OnZero;
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
/// <summary>
/// Whether to show axis name.
/// |是否显示坐标名称。
/// |是否显示坐标名称。
/// </summary>
public bool show
{
@@ -33,6 +34,15 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetClass(ref m_Name, value)) SetComponentDirty(); }
}
/// <summary>
/// Whether the axis name position are the same with 0 position of YAxis.
/// |坐标轴名称的位置是否保持和Y轴0刻度一致。
/// </summary>
public bool onZero
{
get { return m_OnZero; }
set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetComponentDirty(); }
}
/// <summary>
/// The text style of axis name.
/// |文本样式。
/// </summary>