From 839e1fe9d12840fd0b4793ba735120024aca8d0d Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sun, 19 Apr 2020 22:08:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0`AxisLabel`=E7=9A=84`onZero`?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=8F=AF=E5=B0=86`Label`=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=9C=A8`0`=E5=88=BB=E5=BA=A6=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/XCharts/CHANGELOG.md | 1 + Assets/XCharts/Documentation/XCharts配置项手册.md | 1 + .../XCharts/Editor/PropertyDrawers/AxisLabelDrawer.cs | 5 ++++- .../XCharts/Editor/PropertyDrawers/AxisNameDrawer.cs | 3 ++- Assets/XCharts/Runtime/Component/Sub/AxisLabel.cs | 10 ++++++++++ Assets/XCharts/Runtime/Internal/CoordinateChart.cs | 3 ++- 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Assets/XCharts/CHANGELOG.md b/Assets/XCharts/CHANGELOG.md index 38de1e55..3c479c59 100644 --- a/Assets/XCharts/CHANGELOG.md +++ b/Assets/XCharts/CHANGELOG.md @@ -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`参数设置坐标轴反转 diff --git a/Assets/XCharts/Documentation/XCharts配置项手册.md b/Assets/XCharts/Documentation/XCharts配置项手册.md index 346d39f9..52731fa3 100644 --- a/Assets/XCharts/Documentation/XCharts配置项手册.md +++ b/Assets/XCharts/Documentation/XCharts配置项手册.md @@ -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` diff --git a/Assets/XCharts/Editor/PropertyDrawers/AxisLabelDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/AxisLabelDrawer.cs index fccd7dd5..f1745f16 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/AxisLabelDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/AxisLabelDrawer.cs @@ -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; diff --git a/Assets/XCharts/Editor/PropertyDrawers/AxisNameDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/AxisNameDrawer.cs index ff689afd..de1f5d6f 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/AxisNameDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/AxisNameDrawer.cs @@ -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; } diff --git a/Assets/XCharts/Runtime/Component/Sub/AxisLabel.cs b/Assets/XCharts/Runtime/Component/Sub/AxisLabel.cs index be95c128..e96a7888 100644 --- a/Assets/XCharts/Runtime/Component/Sub/AxisLabel.cs +++ b/Assets/XCharts/Runtime/Component/Sub/AxisLabel.cs @@ -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(); /// @@ -131,6 +132,15 @@ namespace XCharts set { if (PropertyUtility.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); } } + /// + /// 刻度标签显示在0刻度上。 + /// + public bool onZero + { + get { return m_OnZero; } + set { if (PropertyUtility.SetStruct(ref m_OnZero, value)) SetComponentDirty(); } + } + /// /// 文本限制。 /// diff --git a/Assets/XCharts/Runtime/Internal/CoordinateChart.cs b/Assets/XCharts/Runtime/Internal/CoordinateChart.cs index 8a306e96..40b7e8d8 100644 --- a/Assets/XCharts/Runtime/Internal/CoordinateChart.cs +++ b/Assets/XCharts/Runtime/Internal/CoordinateChart.cs @@ -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))