diff --git a/Editor/MainComponents/DataZoomEditor.cs b/Editor/MainComponents/DataZoomEditor.cs index fa85d49e..10f0fdba 100644 --- a/Editor/MainComponents/DataZoomEditor.cs +++ b/Editor/MainComponents/DataZoomEditor.cs @@ -29,6 +29,8 @@ namespace XCharts.Editor PropertyField("m_RangeMode"); PropertyField(m_Start); PropertyField(m_End); + PropertyField("m_StartLock"); + PropertyField("m_EndLock"); PropertyField(m_MinShowNum); if (m_Start.floatValue < 0) m_Start.floatValue = 0; if (m_End.floatValue > 100) m_End.floatValue = 100; diff --git a/Runtime/Component/Child/Location.cs b/Runtime/Component/Child/Location.cs index 819e3560..c61de59a 100644 --- a/Runtime/Component/Child/Location.cs +++ b/Runtime/Component/Child/Location.cs @@ -125,10 +125,10 @@ namespace XCharts.Runtime return new Location() { align = Align.CenterLeft, - left = 0.03f, - right = 0, - top = 0, - bottom = 0 + left = 0.03f, + right = 0, + top = 0, + bottom = 0 }; } } @@ -140,10 +140,10 @@ namespace XCharts.Runtime return new Location() { align = Align.CenterRight, - left = 0, - right = 0.03f, - top = 0, - bottom = 0 + left = 0, + right = 0.03f, + top = 0, + bottom = 0 }; } } @@ -155,10 +155,10 @@ namespace XCharts.Runtime return new Location() { align = Align.TopCenter, - left = 0, - right = 0, - top = 0.03f, - bottom = 0 + left = 0, + right = 0, + top = 0.03f, + bottom = 0 }; } } @@ -170,10 +170,10 @@ namespace XCharts.Runtime return new Location() { align = Align.BottomCenter, - left = 0, - right = 0, - top = 0, - bottom = 0.03f + left = 0, + right = 0, + top = 0, + bottom = 0.03f }; } } @@ -268,6 +268,60 @@ namespace XCharts.Runtime } } + public bool IsBottom() + { + switch (m_Align) + { + case Align.BottomCenter: + case Align.BottomLeft: + case Align.BottomRight: +#if dUI_TextMeshPro + case TextAlignmentOptions.Bottom: + case TextAlignmentOptions.BottomLeft: + case TextAlignmentOptions.BottomRight: +#endif + return true; + default: + return false; + } + } + + public bool IsTop() + { + switch (m_Align) + { + case Align.TopCenter: + case Align.TopLeft: + case Align.TopRight: +#if dUI_TextMeshPro + case TextAlignmentOptions.Top: + case TextAlignmentOptions.TopLeft: + case TextAlignmentOptions.TopRight: +#endif + return true; + default: + return false; + } + } + + public bool IsCenter() + { + switch (m_Align) + { + case Align.Center: + case Align.CenterLeft: + case Align.CenterRight: +#if dUI_TextMeshPro + case TextAlignmentOptions.Center: + case TextAlignmentOptions.CenterLeft: + case TextAlignmentOptions.CenterRight: +#endif + return true; + default: + return false; + } + } + public void UpdateRuntimeData(float chartWidth, float chartHeight) { runtimeLeft = left <= 1 ? left * chartWidth : left; diff --git a/Runtime/Component/DataZoom/DataZoom.cs b/Runtime/Component/DataZoom/DataZoom.cs index eb1407c9..27b82507 100644 --- a/Runtime/Component/DataZoom/DataZoom.cs +++ b/Runtime/Component/DataZoom/DataZoom.cs @@ -81,8 +81,6 @@ namespace XCharts.Runtime [SerializeField] private RangeMode m_RangeMode; [SerializeField] private float m_Start; [SerializeField] private float m_End; - //[SerializeField] private float m_StartValue; - //[SerializeField] private float m_EndValue; [SerializeField] private int m_MinShowNum = 1; [Range(1f, 20f)] [SerializeField] private float m_ScrollSensitivity = 1.1f; @@ -91,6 +89,8 @@ namespace XCharts.Runtime [SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid); [SerializeField] private AreaStyle m_AreaStyle = new AreaStyle(); [SerializeField][Since("v3.5.0")] private MarqueeStyle m_MarqueeStyle = new MarqueeStyle(); + [SerializeField][Since("v3.6.0")] private bool m_StartLock; + [SerializeField][Since("v3.6.0")] private bool m_EndLock; public DataZoomContext context = new DataZoomContext(); @@ -305,6 +305,24 @@ namespace XCharts.Runtime set { m_Start = value; if (m_Start < 0) m_Start = 0; if (m_Start > 100) m_Start = 100; SetVerticesDirty(); } } /// + /// Lock start value. + /// |固定起始值,不让改变。 + /// + public bool startLock + { + get { return m_StartLock; } + set { if (PropertyUtil.SetStruct(ref m_StartLock, value)) SetVerticesDirty(); } + } + /// + /// Lock end value. + /// |固定结束值,不让改变。 + /// + public bool endLock + { + get { return m_EndLock; } + set { if (PropertyUtil.SetStruct(ref m_EndLock, value)) SetVerticesDirty(); } + } + /// /// The end percentage of the window out of the data extent, in the range of 0 ~ 100. /// |数据窗口范围的结束百分比。范围是:0 ~ 100。 /// diff --git a/Runtime/Component/DataZoom/DataZoomHandler.cs b/Runtime/Component/DataZoom/DataZoomHandler.cs index 54a88121..fd06635d 100644 --- a/Runtime/Component/DataZoom/DataZoomHandler.cs +++ b/Runtime/Component/DataZoom/DataZoomHandler.cs @@ -22,7 +22,7 @@ namespace XCharts.Runtime { var dataZoom = component; dataZoom.painter = chart.m_PainterUpper; - dataZoom.refreshComponent = delegate() + dataZoom.refreshComponent = delegate () { var dataZoomObject = ChartHelper.AddObject(s_DefaultDataZoom + dataZoom.index, chart.transform, chart.chartMinAnchor, chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta); @@ -398,8 +398,10 @@ namespace XCharts.Runtime if (end < start) end = start; - dataZoom.start = start; - dataZoom.end = end; + if (!dataZoom.startLock) + dataZoom.start = start; + if (!dataZoom.endLock) + dataZoom.end = end; if (dataZoom.realtime) { chart.OnDataZoomRangeChanged(dataZoom); @@ -466,8 +468,8 @@ namespace XCharts.Runtime { m_CheckDataZoomLabel = false; var xAxis = chart.GetChartComponent(dataZoom.xAxisIndexs[0]); - var startIndex = (int) ((xAxis.data.Count - 1) * dataZoom.start / 100); - var endIndex = (int) ((xAxis.data.Count - 1) * dataZoom.end / 100); + var startIndex = (int)((xAxis.data.Count - 1) * dataZoom.start / 100); + var endIndex = (int)((xAxis.data.Count - 1) * dataZoom.end / 100); if (m_DataZoomLastStartIndex != startIndex || m_DataZoomLastEndIndex != endIndex) { @@ -532,7 +534,7 @@ namespace XCharts.Runtime var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist; var maxCount = showData.Count; if (sampleDist > 0) - rate = (int) ((maxCount - serie.minShow) / (dataZoom.context.width / sampleDist)); + rate = (int)((maxCount - serie.minShow) / (dataZoom.context.width / sampleDist)); if (rate < 1) rate = 1; @@ -547,7 +549,7 @@ namespace XCharts.Runtime double value = DataHelper.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i, animationDuration, ref dataChanging, axis, unscaledTime); float pX = dataZoom.context.x + i * scaleWid; - float dataHig = (float) ((maxValue - minValue) == 0 ? 0 : + float dataHig = (float)((maxValue - minValue) == 0 ? 0 : (value - minValue) / (maxValue - minValue) * dataZoom.context.height); np = new Vector3(pX, chart.chartY + dataZoom.bottom + dataHig); if (i > 0) @@ -623,7 +625,7 @@ namespace XCharts.Runtime var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist; var maxCount = showData.Count; if (sampleDist > 0) - rate = (int) ((maxCount - serie.minShow) / (dataZoom.context.height / sampleDist)); + rate = (int)((maxCount - serie.minShow) / (dataZoom.context.height / sampleDist)); if (rate < 1) rate = 1; @@ -639,7 +641,7 @@ namespace XCharts.Runtime animationDuration, ref dataChanging, axis, unscaledTime); float pY = dataZoom.context.y + i * scaleWid; float dataHig = (maxValue - minValue) == 0 ? 0 : - (float) ((value - minValue) / (maxValue - minValue) * dataZoom.context.width); + (float)((value - minValue) / (maxValue - minValue) * dataZoom.context.width); np = new Vector3(chart.chartX + chart.chartWidth - dataZoom.right - dataHig, pY); if (i > 0) {