增加AxisLabelonZero参数可将Label显示在0刻度上

This commit is contained in:
monitor1394
2020-04-19 22:08:40 +08:00
parent c64653cab8
commit 839e1fe9d1
6 changed files with 20 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
# 更新日志
* (2020.04.19) 增加`AxisLabel``onZero`参数可将`Label`显示在`0`刻度上
* (2020.04.19) 增加`Serie``AxisLabel``showAsPositiveNumber`参数将负数数值显示为正数
* (2020.04.18) 增加`Covert XY Axis`互换XY轴配置
* (2020.04.17) 增加`Axis`可通过`inverse`参数设置坐标轴反转

View File

@@ -685,6 +685,7 @@
* `formatter`:图例内容字符串模版格式器。支持用 \n 换行。模板变量为图例名称 {value},支持{value:f0}{value:f1}{value:f2}。
* `forceENotation`是否强制使用科学计数法格式化显示数值。默认为false当小数精度大于3时才采用科学计数法。
* `showAsPositiveNumber`:将负数数值显示为正数。一般和`Serie``showAsPositiveNumber`配合使用。
* `onZero`刻度标签显示在0刻度上。
* `textLimit`:文本自适应 [TextLimit](#TextLimit)。只在类目轴中有效。
## `AxisLine`

View File

@@ -31,6 +31,7 @@ namespace XCharts
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
SerializedProperty m_ForceENotation = prop.FindPropertyRelative("m_ForceENotation");
SerializedProperty m_ShowAsPositiveNumber = prop.FindPropertyRelative("m_ShowAsPositiveNumber");
SerializedProperty m_OnZero = prop.FindPropertyRelative("m_OnZero");
SerializedProperty m_TextLimit = prop.FindPropertyRelative("m_TextLimit");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisLabelToggle, prop, "Axis Label", show, false);
@@ -38,6 +39,8 @@ namespace XCharts
if (ChartEditorHelper.IsToggle(m_AxisLabelToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_OnZero);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Inside);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Interval);
@@ -69,7 +72,7 @@ namespace XCharts
float height = 0;
if (ChartEditorHelper.IsToggle(m_AxisLabelToggle, prop))
{
height += 11 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
height += 12 * EditorGUIUtility.singleLineHeight + 11 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextLimit"));
}
return height;

View File

@@ -66,7 +66,8 @@ namespace XCharts
float height = 0;
if (ChartEditorHelper.IsToggle(m_AxisNameToggle, prop))
{
height += 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset"));
}
return height;
}

View File

@@ -29,6 +29,7 @@ namespace XCharts
[SerializeField] private FontStyle m_FontStyle;
[SerializeField] private bool m_ForceENotation = false;
[SerializeField] private bool m_ShowAsPositiveNumber = false;
[SerializeField] private bool m_OnZero = false;
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
/// <summary>
@@ -131,6 +132,15 @@ namespace XCharts
set { if (PropertyUtility.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); }
}
/// <summary>
/// 刻度标签显示在0刻度上。
/// </summary>
public bool onZero
{
get { return m_OnZero; }
set { if (PropertyUtility.SetStruct(ref m_OnZero, value)) SetComponentDirty(); }
}
/// <summary>
/// 文本限制。
/// </summary>

View File

@@ -757,7 +757,8 @@ namespace XCharts
private Vector3 GetLabelXPosition(float scaleWid, int i, int xAxisIndex, XAxis xAxis)
{
var startY = xAxisIndex == 0 ? coordinateY : coordinateY + coordinateHeight;
var startY = coordinateY + (xAxis.axisLabel.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0);
if (xAxisIndex > 0) startY += coordinateHeight;
var posY = 0f;
var inside = xAxis.axisLabel.inside;
if ((inside && xAxisIndex == 0) || (!inside && xAxisIndex == 1))