From 541bc421b7ec94f6e9f3a51100c183dc9b02f78a Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Fri, 20 Mar 2020 08:47:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0`AxisTick`=E7=9A=84`width`?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=8F=AF=E5=8D=95=E7=8B=AC=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=9D=90=E6=A0=87=E8=BD=B4=E5=88=BB=E5=BA=A6=E7=9A=84=E5=AE=BD?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/XCharts/CHANGELOG.md | 1 + .../Documentation/XCharts配置项手册.md | 1 + .../Editor/PropertyDrawers/AxisTickDrawer.cs | 5 ++++- .../XCharts/Runtime/Component/Sub/AxisTick.cs | 11 +++++++++++ Assets/XCharts/Runtime/Helper/AxisHelper.cs | 19 +++++++++++++++++++ .../XCharts/Runtime/Helper/AxisHelper.cs.meta | 11 +++++++++++ .../Runtime/Internal/CoordinateChart.cs | 10 +++++----- 7 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 Assets/XCharts/Runtime/Helper/AxisHelper.cs create mode 100644 Assets/XCharts/Runtime/Helper/AxisHelper.cs.meta diff --git a/Assets/XCharts/CHANGELOG.md b/Assets/XCharts/CHANGELOG.md index 92d13204..1b369205 100644 --- a/Assets/XCharts/CHANGELOG.md +++ b/Assets/XCharts/CHANGELOG.md @@ -1,6 +1,7 @@ # 更新日志 +* (2020.03.20) 增加`AxisTick`的`width`参数可单独设置坐标轴刻度的宽度 * (2020.03.20) 增加`Serie`的`radarType`参数设置`多圈`和`单圈`雷达图 * (2020.03.17) 增加`BarChart`可用`ItemStyle`的`backgroundColor`设置数据项背景颜色 * (2020.03.17) 增加`SerieData`的`ItemStyle`和`Emphasis`可单独配置数据项样式的支持 diff --git a/Assets/XCharts/Documentation/XCharts配置项手册.md b/Assets/XCharts/Documentation/XCharts配置项手册.md index cb65cb13..1a7c4c7a 100644 --- a/Assets/XCharts/Documentation/XCharts配置项手册.md +++ b/Assets/XCharts/Documentation/XCharts配置项手册.md @@ -720,6 +720,7 @@ * `alignWithLabel`:类目轴中在 boundaryGap 为 true 的时候有效,可以保证刻度线和标签对齐。 * `inside`:坐标轴刻度是否朝内,默认朝外。 * `length`:坐标轴刻度的长度。 +* `width`:坐标轴刻度的宽度。默认为0时宽度和坐标轴一致。 ## `Emphasis` diff --git a/Assets/XCharts/Editor/PropertyDrawers/AxisTickDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/AxisTickDrawer.cs index b9b40bc5..53bc28b9 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/AxisTickDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/AxisTickDrawer.cs @@ -23,6 +23,7 @@ namespace XCharts SerializedProperty m_AlignWithLabel = prop.FindPropertyRelative("m_AlignWithLabel"); SerializedProperty m_Inside = prop.FindPropertyRelative("m_Inside"); SerializedProperty m_Length = prop.FindPropertyRelative("m_Length"); + SerializedProperty m_Width = prop.FindPropertyRelative("m_Width"); ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisTickToggle, "Axis Tick", show, false); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; @@ -35,6 +36,8 @@ namespace XCharts drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_Length); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_Width); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; --EditorGUI.indentLevel; } } @@ -44,7 +47,7 @@ namespace XCharts float height = 0; if (m_AxisTickToggle) { - height += 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing; + height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing; } return height; } diff --git a/Assets/XCharts/Runtime/Component/Sub/AxisTick.cs b/Assets/XCharts/Runtime/Component/Sub/AxisTick.cs index cf2a273f..e49d68b0 100644 --- a/Assets/XCharts/Runtime/Component/Sub/AxisTick.cs +++ b/Assets/XCharts/Runtime/Component/Sub/AxisTick.cs @@ -21,6 +21,7 @@ namespace XCharts [SerializeField] private bool m_AlignWithLabel; [SerializeField] private bool m_Inside; [SerializeField] private float m_Length; + [SerializeField] private float m_Width; /// /// Set this to false to prevent the axis tick from showing. @@ -58,6 +59,15 @@ namespace XCharts get { return m_Length; } set { if (PropertyUtility.SetStruct(ref m_Length, value)) SetVerticesDirty(); } } + /// + /// The width of the axis tick.Keep the same width with axis line when default 0. + /// 坐标轴刻度的宽度。默认为0时宽度和坐标轴一致。 + /// + public float width + { + get { return m_Width; } + set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); } + } public static AxisTick defaultTick { @@ -68,6 +78,7 @@ namespace XCharts m_Show = true, m_AlignWithLabel = false, m_Inside = false, + m_Width = 0f, m_Length = 5f }; return tick; diff --git a/Assets/XCharts/Runtime/Helper/AxisHelper.cs b/Assets/XCharts/Runtime/Helper/AxisHelper.cs new file mode 100644 index 00000000..bcba90d4 --- /dev/null +++ b/Assets/XCharts/Runtime/Helper/AxisHelper.cs @@ -0,0 +1,19 @@ +/******************************************/ +/* */ +/* Copyright (c) 2018 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/******************************************/ +using UnityEngine; +using UnityEngine.UI; + +namespace XCharts +{ + internal static class AxisHelper + { + public static float GetTickWidth(Axis axis) + { + return axis.axisTick.width != 0 ? axis.axisTick.width : axis.axisLine.width; + } + } +} \ No newline at end of file diff --git a/Assets/XCharts/Runtime/Helper/AxisHelper.cs.meta b/Assets/XCharts/Runtime/Helper/AxisHelper.cs.meta new file mode 100644 index 00000000..b7e057ab --- /dev/null +++ b/Assets/XCharts/Runtime/Helper/AxisHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ada7d0edfc97b432db026ca5eecea8ac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/XCharts/Runtime/Internal/CoordinateChart.cs b/Assets/XCharts/Runtime/Internal/CoordinateChart.cs index ae7d2e12..b48b1937 100644 --- a/Assets/XCharts/Runtime/Internal/CoordinateChart.cs +++ b/Assets/XCharts/Runtime/Internal/CoordinateChart.cs @@ -1027,7 +1027,7 @@ namespace XCharts pX += startX - yAxis.axisTick.length; } ChartDrawer.DrawLine(vh, new Vector3(startX, pY), new Vector3(pX, pY), - yAxis.axisLine.width, m_ThemeInfo.axisLineColor); + AxisHelper.GetTickWidth(yAxis), m_ThemeInfo.axisLineColor); } totalWidth += scaleWidth; } @@ -1117,7 +1117,7 @@ namespace XCharts pY += startY - xAxis.axisTick.length; } ChartDrawer.DrawLine(vh, new Vector3(pX, startY), new Vector3(pX, pY), - xAxis.axisLine.width, m_ThemeInfo.axisLineColor); + AxisHelper.GetTickWidth(xAxis), m_ThemeInfo.axisLineColor); } totalWidth += scaleWidth; } @@ -1430,12 +1430,12 @@ namespace XCharts for (int j = 0; j < serie.data.Count; j++) { var serieData = serie.data[j]; - var serieLabel = SerieHelper.GetSerieLabel(serie,serieData,serieData.highlighted); + var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.highlighted); serieData.index = j; if ((serieLabel.show || serieData.iconStyle.show)) { var pos = serie.dataPoints[j]; - + var isIngore = ChartHelper.IsIngore(pos); if (isIngore) { @@ -1519,7 +1519,7 @@ namespace XCharts dimension = m_VisualMap.enable && m_VisualMap.dimension > 0 ? m_VisualMap.dimension - 1 : serieData.data.Count - 1; } - + SerieLabelHelper.ResetLabel(serieData, serieLabel, themeInfo, i); value = serieData.data[dimension];