From 4e4d0bc85dd6b7f81733a40651c139f3166fde8e Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sun, 1 May 2022 10:30:58 +0800 Subject: [PATCH] [optimize][bar] bar support clip and min-max (#196) --- Editor/Series/BarEditor.cs | 3 +-- Editor/Series/LineEditor.cs | 2 +- Editor/Series/SimplifiedBarEditor.cs | 1 + Editor/Series/SimplifiedLineEditor.cs | 1 + Runtime/Component/Axis/AxisContext.cs | 2 ++ Runtime/Component/Axis/AxisHandler.cs | 8 ++++++++ Runtime/Component/Axis/AxisHelper.cs | 8 ++++---- Runtime/Serie/Bar/SimplifiedBarHandler.cs | 2 +- 8 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Editor/Series/BarEditor.cs b/Editor/Series/BarEditor.cs index f98d2f16..c06a04e0 100644 --- a/Editor/Series/BarEditor.cs +++ b/Editor/Series/BarEditor.cs @@ -26,7 +26,7 @@ namespace XCharts.Editor PropertyField("m_BarZebraWidth"); PropertyField("m_BarZebraGap"); } - + PropertyField("m_Clip"); PropertyFiledMore(() => { PropertyFieldLimitMin("m_MinShow", 0); @@ -38,7 +38,6 @@ namespace XCharts.Editor PropertyField("m_ShowAsPositiveNumber"); PropertyField("m_Large"); PropertyField("m_LargeThreshold"); - PropertyField("m_Clip"); PropertyField("m_PlaceHolder"); }); PropertyField("m_ItemStyle"); diff --git a/Editor/Series/LineEditor.cs b/Editor/Series/LineEditor.cs index 8f3df7eb..5d6c2342 100644 --- a/Editor/Series/LineEditor.cs +++ b/Editor/Series/LineEditor.cs @@ -18,6 +18,7 @@ namespace XCharts.Editor PropertyField("m_YAxisIndex"); } PropertyField("m_LineType"); + //PropertyField("m_Clip"); PropertyFiledMore(() => { PropertyFieldLimitMin("m_MinShow", 0); @@ -32,7 +33,6 @@ namespace XCharts.Editor PropertyField("m_ShowAsPositiveNumber"); PropertyField("m_Large"); PropertyField("m_LargeThreshold"); - PropertyField("m_Clip"); }); PropertyField("m_Symbol"); PropertyField("m_LineStyle"); diff --git a/Editor/Series/SimplifiedBarEditor.cs b/Editor/Series/SimplifiedBarEditor.cs index 2a4090f3..fdd9133a 100644 --- a/Editor/Series/SimplifiedBarEditor.cs +++ b/Editor/Series/SimplifiedBarEditor.cs @@ -12,6 +12,7 @@ namespace XCharts.Editor PropertyField("m_YAxisIndex"); PropertyField("m_BarWidth"); PropertyField("m_BarGap"); + PropertyField("m_Clip"); PropertyField("m_ItemStyle"); PropertyField("m_Animation"); } diff --git a/Editor/Series/SimplifiedLineEditor.cs b/Editor/Series/SimplifiedLineEditor.cs index 23377fd5..b5be0c2e 100644 --- a/Editor/Series/SimplifiedLineEditor.cs +++ b/Editor/Series/SimplifiedLineEditor.cs @@ -10,6 +10,7 @@ namespace XCharts.Editor PropertyField("m_XAxisIndex"); PropertyField("m_YAxisIndex"); PropertyField("m_LineType"); + //PropertyField("m_Clip"); PropertyField("m_LineStyle"); PropertyField("m_ItemStyle"); PropertyField("m_Animation"); diff --git a/Runtime/Component/Axis/AxisContext.cs b/Runtime/Component/Axis/AxisContext.cs index 4ff255aa..c42fe217 100644 --- a/Runtime/Component/Axis/AxisContext.cs +++ b/Runtime/Component/Axis/AxisContext.cs @@ -10,6 +10,8 @@ namespace XCharts.Runtime public Orient orient; public float x; public float y; + public float zeroX; + public float zeroY; public float width; public float height; public Vector3 position; diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 4b59206e..4bf963d2 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -166,6 +166,10 @@ namespace XCharts : (float)(Math.Abs(axis.context.minValue) * (grid.context.width / (Math.Abs(axis.context.minValue) + Math.Abs(axis.context.maxValue)))) ); + axis.context.x = grid.context.x; + axis.context.y = grid.context.y; + axis.context.zeroY = grid.context.y; + axis.context.zeroX = grid.context.x - (float)(axis.context.minValue * grid.context.width / axis.context.minMaxRange); } if (grid != null && axis is YAxis && axis.IsValue()) { @@ -176,6 +180,10 @@ namespace XCharts : (float)(Math.Abs(axis.context.minValue) * (grid.context.height / (Math.Abs(axis.context.minValue) + Math.Abs(axis.context.maxValue)))) ); + axis.context.x = grid.context.x; + axis.context.y = grid.context.y; + axis.context.zeroX = grid.context.x; + axis.context.zeroY = grid.context.y - (float)(axis.context.minValue * grid.context.height / axis.context.minMaxRange); } } var dataZoom = chart.GetDataZoomOfAxis(axis); diff --git a/Runtime/Component/Axis/AxisHelper.cs b/Runtime/Component/Axis/AxisHelper.cs index d25d8489..560679a4 100644 --- a/Runtime/Component/Axis/AxisHelper.cs +++ b/Runtime/Component/Axis/AxisHelper.cs @@ -511,7 +511,7 @@ namespace XCharts.Runtime } /// - /// 获得数值value在坐标轴上对于的长度 + /// 获得数值value在坐标轴上对应的长度 /// /// /// @@ -549,10 +549,10 @@ namespace XCharts.Runtime var yDataHig = 0f; if (axis.context.minMaxRange != 0) { - if (!realLength || (realLength && axis.context.minValue > 0)) - yDataHig = (float)((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight); + if (realLength) + yDataHig = (float)(value * gridHeight / axis.context.minMaxRange); else - yDataHig = (float)(value / axis.context.minMaxRange * gridHeight); + yDataHig = (float)((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight); } return includeGridXY ? gridXY + yDataHig diff --git a/Runtime/Serie/Bar/SimplifiedBarHandler.cs b/Runtime/Serie/Bar/SimplifiedBarHandler.cs index 342ed8d8..09b542c6 100644 --- a/Runtime/Serie/Bar/SimplifiedBarHandler.cs +++ b/Runtime/Serie/Bar/SimplifiedBarHandler.cs @@ -190,7 +190,7 @@ namespace XCharts.Runtime var pY = 0f; UpdateXYPosition(m_SerieGrid, isY, axis, relativedAxis, i, categoryWidth, barWidth, value, ref pX, ref pY); - var barHig = AxisHelper.GetAxisValueDistance(m_SerieGrid, relativedAxis, categoryWidth, relativedValue); + var barHig = AxisHelper.GetAxisValueLength(m_SerieGrid, relativedAxis, categoryWidth, relativedValue); var currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig); Vector3 plb, plt, prt, prb, top;