From 83b876e80d3dfc2f184e26487b7f3ffa7eb0b1bd Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Thu, 29 Apr 2021 07:30:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0`Settings`=E7=9A=84`reversePa?= =?UTF-8?q?inter`=E5=8F=AF=E8=AE=BE=E7=BD=AE`Serie`=E7=9A=84=E7=BB=98?= =?UTF-8?q?=E5=88=B6=E6=98=AF=E5=90=A6=E9=80=86=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG-EN.md | 1 + CHANGELOG.md | 1 + Documentation/XCharts配置项手册.md | 2 ++ Documentation/xcharts-configuration-EN.md | 2 ++ Editor/PropertyDrawers/SettingsDrawer.cs | 1 + Runtime/API/BaseGraph_API.cs | 8 ++++++++ Runtime/Component/Main/Settings.cs | 11 +++++++++++ Runtime/Internal/BaseChart.cs | 5 +++-- Runtime/Internal/BaseGraph.cs | 2 ++ Runtime/Internal/Painter.cs | 10 +++++----- 10 files changed, 36 insertions(+), 7 deletions(-) diff --git a/CHANGELOG-EN.md b/CHANGELOG-EN.md index 9e289e29..6e693466 100644 --- a/CHANGELOG-EN.md +++ b/CHANGELOG-EN.md @@ -34,6 +34,7 @@ ## Latest +* (2021.04.29) Added `Settings`'s `reversePainter` to set whether or not `Serie` is drawn in reverse order * (2021.04.28) Fixed bug where `AxisLabel` displayed incorrectly with `DataRoom` (#138) * (2021.04.26) Fixed dynamically creating chart at runtime would be abnormal #137 * (2021.04.26) Added support for `Barchart` to draw gradient borders diff --git a/CHANGELOG.md b/CHANGELOG.md index 56f3c709..b0c88f77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ ## Latest +* (2021.04.29) 增加`Settings`的`reversePainter`可设置`Serie`的绘制是否逆序 * (2021.04.28) 增加`SerieData`的`ignore`可忽略当前数据项 * (2021.04.28) 修复`DataZoom`下`AxisLabel`显示不准确的问题 #138 * (2021.04.26) 修复运行时动态创建图表会异常的问题 #137 diff --git a/Documentation/XCharts配置项手册.md b/Documentation/XCharts配置项手册.md index 7980cd9c..5d10f97a 100644 --- a/Documentation/XCharts配置项手册.md +++ b/Documentation/XCharts配置项手册.md @@ -797,6 +797,8 @@ K线图系列。 全局参数设置组件。一般情况下可使用默认值,当有需要时可进行调整。 +* `reversePainter`:Painter是否逆序。逆序时index大的serie最先绘制。 +* `maxPainter`:默认最大Painter数据,当Serie数量大于maxPainter时会平均分配Painter。 * `lineSmoothStyle`:曲线平滑系数。通过调整平滑系数可以改变曲线的曲率,得到外观稍微有变化的不同曲线。 * `lineSmoothness`:曲线平滑度。值越小曲线越平滑,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。 * `lineSegmentDistance`: 线段的分割距离。普通折线图的线是由很多线段组成,段数由该数值决定。值越小段数越多,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。 diff --git a/Documentation/xcharts-configuration-EN.md b/Documentation/xcharts-configuration-EN.md index 4c541140..2967f747 100644 --- a/Documentation/xcharts-configuration-EN.md +++ b/Documentation/xcharts-configuration-EN.md @@ -690,6 +690,8 @@ K线图系列。 全局参数设置组件。一般情况下可使用默认值,当有需要时可进行调整。 +* `reversePainter`:Painter是否逆序。逆序时index大的serie最先绘制。 +* `maxPainter`:默认最大Painter数据,当Serie数量大于maxPainter时会平均分配Painter。 * `lineSmoothStyle`: 曲线平滑系数。通过调整平滑系数可以改变曲线的曲率,得到外观稍微有变化的不同曲线。 * `lineSmoothness`: 曲线平滑度。值越小曲线越平滑,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。 * `lineSegmentDistance`: 线段的分割距离。普通折线图的线是由很多线段组成,段数由该数值决定。值越小段数越多,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。 diff --git a/Editor/PropertyDrawers/SettingsDrawer.cs b/Editor/PropertyDrawers/SettingsDrawer.cs index 9ff7f66f..2e9bbd9f 100644 --- a/Editor/PropertyDrawers/SettingsDrawer.cs +++ b/Editor/PropertyDrawers/SettingsDrawer.cs @@ -27,6 +27,7 @@ namespace XCharts chart.settings.Reset(); } ++EditorGUI.indentLevel; + PropertyField(prop, "m_ReversePainter"); PropertyField(prop, "m_MaxPainter"); PropertyField(prop, "m_LineSmoothStyle"); PropertyField(prop, "m_LineSmoothness"); diff --git a/Runtime/API/BaseGraph_API.cs b/Runtime/API/BaseGraph_API.cs index 4c99d1ca..d0facd82 100644 --- a/Runtime/API/BaseGraph_API.cs +++ b/Runtime/API/BaseGraph_API.cs @@ -122,6 +122,14 @@ namespace XCharts } } + /// + /// 重新初始化Painter + /// + public void SetPainterDirty() + { + m_PainerDirty = true; + } + /// /// Redraw graph in next frame. /// 在下一帧刷新图形。 diff --git a/Runtime/Component/Main/Settings.cs b/Runtime/Component/Main/Settings.cs index 98e5c6bb..9bff0dc6 100644 --- a/Runtime/Component/Main/Settings.cs +++ b/Runtime/Component/Main/Settings.cs @@ -18,6 +18,7 @@ namespace XCharts public class Settings : MainComponent { [SerializeField] [Range(1, 20)] protected int m_MaxPainter = 10; + [SerializeField] protected bool m_ReversePainter = false; [SerializeField] [Range(1, 10)] protected float m_LineSmoothStyle = 3f; [SerializeField] [Range(1f, 20)] protected float m_LineSmoothness = 2f; [SerializeField] [Range(1f, 20)] protected float m_LineSegmentDistance = 3f; @@ -35,6 +36,14 @@ namespace XCharts set { if (PropertyUtil.SetStruct(ref m_MaxPainter, value < 0 ? 1 : value)) SetVerticesDirty(); } } /// + /// Painter是否逆序。逆序时index大的serie最先绘制。 + /// + public bool reversePainter + { + get { return m_ReversePainter; } + set { if (PropertyUtil.SetStruct(ref m_ReversePainter, value)) SetVerticesDirty(); } + } + /// /// Curve smoothing factor. By adjusting the smoothing coefficient, the curvature of the curve can be changed, /// and different curves with slightly different appearance can be obtained. /// 曲线平滑系数。通过调整平滑系数可以改变曲线的曲率,得到外观稍微有变化的不同曲线。 @@ -99,6 +108,7 @@ namespace XCharts public void Copy(Settings settings) { + m_ReversePainter = settings.reversePainter; m_MaxPainter = settings.maxPainter; m_LineSmoothStyle = settings.lineSmoothStyle; m_LineSmoothness = settings.lineSmoothness; @@ -119,6 +129,7 @@ namespace XCharts { return new Settings() { + m_ReversePainter = false, m_MaxPainter = XChartsSettings.maxPainter, m_LineSmoothStyle = XChartsSettings.lineSmoothStyle, m_LineSmoothness = XChartsSettings.lineSmoothness, diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index 4342f316..e1612d59 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -321,8 +321,9 @@ namespace XCharts var sizeDelta = new Vector2(m_GraphWidth, m_GraphHeight); for (int i = 0; i < settings.maxPainter; i++) { - var painter = ChartHelper.AddPainterObject("painter_" + i, transform, m_GraphMinAnchor, - m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + i); + var index = settings.reversePainter ? settings.maxPainter - 1 - i : i; + var painter = ChartHelper.AddPainterObject("painter_" + index, transform, m_GraphMinAnchor, + m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + index); painter.index = m_PainterList.Count; painter.type = Painter.Type.Serie; painter.onPopulateMesh = OnDrawPainterSerie; diff --git a/Runtime/Internal/BaseGraph.cs b/Runtime/Internal/BaseGraph.cs index 113f3db3..ccf4c79e 100644 --- a/Runtime/Internal/BaseGraph.cs +++ b/Runtime/Internal/BaseGraph.cs @@ -129,6 +129,8 @@ namespace XCharts } } + + private void CheckTextMeshPro() { #if dUI_TextMeshPro diff --git a/Runtime/Internal/Painter.cs b/Runtime/Internal/Painter.cs index c97c6852..28cc4ed6 100644 --- a/Runtime/Internal/Painter.cs +++ b/Runtime/Internal/Painter.cs @@ -46,11 +46,11 @@ namespace XCharts { gameObject.SetActive(flag); } - // var higFlags = !flag || !isDebugMode ? HideFlags.HideInHierarchy : HideFlags.None; - // if (gameObject.hideFlags != higFlags) - // { - // gameObject.hideFlags = hideFlags; - // } + var hideFlags = flag ? HideFlags.None : HideFlags.HideInHierarchy; + if (gameObject.hideFlags != hideFlags) + { + gameObject.hideFlags = hideFlags; + } } protected override void Awake()