From f23347a86eb28b0fc17287fe4a267a79772622ef Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sun, 17 May 2020 20:36:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Examples/Runtime/Example02_ChartEvent.cs | 1 - Runtime/Component/Main/Axis.cs | 278 +--------- Runtime/Component/Main/Serie.cs | 22 - Runtime/Component/Main/Series.cs | 479 +----------------- Runtime/Helper/AxisHelper.cs | 19 - Runtime/Helper/CheckHelper.cs | 13 +- Runtime/Internal/BaseChart.cs | 156 +----- Runtime/Internal/CoordinateChart.cs | 96 ++-- Runtime/Internal/CoordinateChart_DrawBar.cs | 12 +- Runtime/Internal/CoordinateChart_DrawLine.cs | 14 +- Runtime/Internal/Helper.meta | 8 + Runtime/Internal/Helper/AxisHelper.cs | 275 ++++++++++ .../{ => Internal}/Helper/AxisHelper.cs.meta | 2 +- .../{ => Internal}/Helper/ItemStyleHelper.cs | 0 .../Helper/ItemStyleHelper.cs.meta | 2 +- Runtime/{ => Internal}/Helper/LegendHelper.cs | 51 ++ .../Helper/LegendHelper.cs.meta | 2 +- .../{ => Internal}/Helper/SerieDataHelper.cs | 0 .../Helper/SerieDataHelper.cs.meta | 2 +- Runtime/{ => Internal}/Helper/SerieHelper.cs | 0 .../{ => Internal}/Helper/SerieHelper.cs.meta | 2 +- .../{ => Internal}/Helper/SerieLabelHelper.cs | 0 .../Helper/SerieLabelHelper.cs.meta | 2 +- Runtime/Internal/Helper/SeriesHelper.cs | 447 ++++++++++++++++ Runtime/Internal/Helper/SeriesHelper.cs.meta | 11 + Runtime/{ => Internal}/Helper/TitleHelper.cs | 0 .../{ => Internal}/Helper/TitleHelper.cs.meta | 2 +- .../{ => Internal}/Helper/TitleStyleHelper.cs | 0 .../Helper/TitleStyleHelper.cs.meta | 2 +- .../{ => Internal}/Helper/TooltipHelper.cs | 0 .../Helper/TooltipHelper.cs.meta | 2 +- .../{ => Internal}/Helper/VisualMapHelper.cs | 0 .../Helper/VisualMapHelper.cs.meta | 2 +- Runtime/{ => Internal}/Interface.meta | 4 +- Runtime/{ => Internal}/Interface/IJsonData.cs | 0 .../Interface/IJsonData.cs.meta | 0 .../Interface/IPropertyChanged.cs | 0 .../Interface/IPropertyChanged.cs.meta | 0 Runtime/{ => Internal}/Object.meta | 2 +- Runtime/{ => Internal}/Object/ChartObject.cs | 0 .../{ => Internal}/Object/ChartObject.cs.meta | 0 Runtime/{ => Internal}/Object/LabelObject.cs | 0 .../{ => Internal}/Object/LabelObject.cs.meta | 0 Runtime/Internal/{ => Object}/LegendItem.cs | 0 .../Internal/{ => Object}/LegendItem.cs.meta | 2 +- Runtime/Internal/Pools.meta | 8 + Runtime/Internal/{ => Pools}/AxisPool.cs | 0 Runtime/Internal/{ => Pools}/AxisPool.cs.meta | 2 +- Runtime/Internal/{ => Pools}/ListPool.cs | 0 Runtime/Internal/{ => Pools}/ListPool.cs.meta | 2 +- Runtime/Internal/{ => Pools}/ObjectPool.cs | 0 .../Internal/{ => Pools}/ObjectPool.cs.meta | 2 +- Runtime/Internal/{ => Pools}/SerieDataPool.cs | 0 .../{ => Pools}/SerieDataPool.cs.meta | 2 +- .../Internal/{ => Pools}/SerieLabelPool.cs | 0 .../{ => Pools}/SerieLabelPool.cs.meta | 2 +- Runtime/PieChart.cs | 6 +- Runtime/RadarChart.cs | 18 +- Runtime/RingChart.cs | 6 +- Runtime/Utility/ChartDrawer.cs | 91 ++++ .../{Internal => Utility}/PropertyUtility.cs | 0 .../PropertyUtility.cs.meta | 2 +- 62 files changed, 1021 insertions(+), 1030 deletions(-) delete mode 100644 Runtime/Helper/AxisHelper.cs create mode 100644 Runtime/Internal/Helper.meta create mode 100644 Runtime/Internal/Helper/AxisHelper.cs rename Runtime/{ => Internal}/Helper/AxisHelper.cs.meta (83%) rename Runtime/{ => Internal}/Helper/ItemStyleHelper.cs (100%) rename Runtime/{ => Internal}/Helper/ItemStyleHelper.cs.meta (83%) rename Runtime/{ => Internal}/Helper/LegendHelper.cs (86%) rename Runtime/{ => Internal}/Helper/LegendHelper.cs.meta (83%) rename Runtime/{ => Internal}/Helper/SerieDataHelper.cs (100%) rename Runtime/{ => Internal}/Helper/SerieDataHelper.cs.meta (83%) rename Runtime/{ => Internal}/Helper/SerieHelper.cs (100%) rename Runtime/{ => Internal}/Helper/SerieHelper.cs.meta (83%) rename Runtime/{ => Internal}/Helper/SerieLabelHelper.cs (100%) rename Runtime/{ => Internal}/Helper/SerieLabelHelper.cs.meta (83%) create mode 100644 Runtime/Internal/Helper/SeriesHelper.cs create mode 100644 Runtime/Internal/Helper/SeriesHelper.cs.meta rename Runtime/{ => Internal}/Helper/TitleHelper.cs (100%) rename Runtime/{ => Internal}/Helper/TitleHelper.cs.meta (83%) rename Runtime/{ => Internal}/Helper/TitleStyleHelper.cs (100%) rename Runtime/{ => Internal}/Helper/TitleStyleHelper.cs.meta (83%) rename Runtime/{ => Internal}/Helper/TooltipHelper.cs (100%) rename Runtime/{ => Internal}/Helper/TooltipHelper.cs.meta (83%) rename Runtime/{ => Internal}/Helper/VisualMapHelper.cs (100%) rename Runtime/{ => Internal}/Helper/VisualMapHelper.cs.meta (83%) rename Runtime/{ => Internal}/Interface.meta (62%) rename Runtime/{ => Internal}/Interface/IJsonData.cs (100%) rename Runtime/{ => Internal}/Interface/IJsonData.cs.meta (100%) rename Runtime/{ => Internal}/Interface/IPropertyChanged.cs (100%) rename Runtime/{ => Internal}/Interface/IPropertyChanged.cs.meta (100%) rename Runtime/{ => Internal}/Object.meta (77%) rename Runtime/{ => Internal}/Object/ChartObject.cs (100%) rename Runtime/{ => Internal}/Object/ChartObject.cs.meta (100%) rename Runtime/{ => Internal}/Object/LabelObject.cs (100%) rename Runtime/{ => Internal}/Object/LabelObject.cs.meta (100%) rename Runtime/Internal/{ => Object}/LegendItem.cs (100%) rename Runtime/Internal/{ => Object}/LegendItem.cs.meta (83%) create mode 100644 Runtime/Internal/Pools.meta rename Runtime/Internal/{ => Pools}/AxisPool.cs (100%) rename Runtime/Internal/{ => Pools}/AxisPool.cs.meta (83%) rename Runtime/Internal/{ => Pools}/ListPool.cs (100%) rename Runtime/Internal/{ => Pools}/ListPool.cs.meta (83%) rename Runtime/Internal/{ => Pools}/ObjectPool.cs (100%) rename Runtime/Internal/{ => Pools}/ObjectPool.cs.meta (83%) rename Runtime/Internal/{ => Pools}/SerieDataPool.cs (100%) rename Runtime/Internal/{ => Pools}/SerieDataPool.cs.meta (83%) rename Runtime/Internal/{ => Pools}/SerieLabelPool.cs (100%) rename Runtime/Internal/{ => Pools}/SerieLabelPool.cs.meta (83%) rename Runtime/{Internal => Utility}/PropertyUtility.cs (100%) rename Runtime/{Internal => Utility}/PropertyUtility.cs.meta (83%) diff --git a/Examples/Runtime/Example02_ChartEvent.cs b/Examples/Runtime/Example02_ChartEvent.cs index dd98e25e..3686a14d 100644 --- a/Examples/Runtime/Example02_ChartEvent.cs +++ b/Examples/Runtime/Example02_ChartEvent.cs @@ -14,7 +14,6 @@ namespace XCharts.Examples [ExecuteInEditMode] public class Example02_ChartEvent : MonoBehaviour { - private float updateTime = 0; BaseChart chart; void Awake() diff --git a/Runtime/Component/Main/Axis.cs b/Runtime/Component/Main/Axis.cs index 7414fa81..26b9eeaa 100644 --- a/Runtime/Component/Main/Axis.cs +++ b/Runtime/Component/Main/Axis.cs @@ -86,7 +86,7 @@ namespace XCharts [SerializeField] protected AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine; [SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea; - [NonSerialized] private float m_ValueRange; + [NonSerialized] private float m_MinMaxValueRange; [NonSerialized] private bool m_NeedUpdateFilterData; /// @@ -339,6 +339,7 @@ namespace XCharts public int runtimeMinLogIndex { get { return logBaseE ? (int)Mathf.Log(runtimeMinValue) : (int)Mathf.Log(runtimeMinValue, logBase); } } public int runtimeMaxLogIndex { get { return logBaseE ? (int)Mathf.Log(runtimeMaxValue) : (int)Mathf.Log(runtimeMaxValue, logBase); } } internal bool runtimeLastCheckInverse { get; set; } + internal float runtimeMinMaxRange { get { return m_MinMaxValueRange; } set { m_MinMaxValueRange = value; } } private int filterStart; private int filterEnd; private int filterMinShow; @@ -461,13 +462,26 @@ namespace XCharts SetAllDirty(); } + /// + /// 获得指定索引的类目数据 + /// + /// + /// + public string GetData(int index) + { + if (index >= 0 && index < m_Data.Count) + return m_Data[index]; + else + return null; + } + /// /// 获得在dataZoom范围内指定索引的类目数据 /// /// 类目数据索引 /// 区域缩放 /// - internal string GetData(int index, DataZoom dataZoom) + public string GetData(int index, DataZoom dataZoom) { var showData = GetDataList(dataZoom); if (index >= 0 && index < showData.Count) @@ -539,55 +553,6 @@ namespace XCharts } } - /// - /// 获得分割段数 - /// - /// - /// - internal int GetSplitNumber(float coordinateWid, DataZoom dataZoom) - { - if (type == AxisType.Value) - { - if (m_Interval > 0) - { - if (coordinateWid <= 0) return 0; - int num = Mathf.CeilToInt(m_ValueRange / m_Interval) + 1; - int maxNum = Mathf.CeilToInt(coordinateWid / 15); - if (num > maxNum) - { - m_Interval *= 2; - num = Mathf.CeilToInt(m_ValueRange / m_Interval) + 1; - } - return num; - } - else return m_SplitNumber; - } - else if (type == AxisType.Log) - { - return m_SplitNumber; - } - int dataCount = GetDataList(dataZoom).Count; - if (m_SplitNumber <= 0) return dataCount; - if (dataCount > 2 * m_SplitNumber || dataCount <= 0) - return m_SplitNumber; - else - return dataCount; - } - - /// - /// 获得分割段的宽度 - /// - /// - /// - /// - internal float GetSplitWidth(float coordinateWidth, DataZoom dataZoom) - { - int split = GetSplitNumber(coordinateWidth, dataZoom); - int segment = (m_BoundaryGap ? split : split - 1); - segment = segment <= 0 ? 1 : segment; - return coordinateWidth / segment; - } - /// /// 获得类目数据个数 /// @@ -598,133 +563,6 @@ namespace XCharts return GetDataList(dataZoom).Count; } - /// - /// 获得一个类目数据在坐标系中代表的宽度 - /// - /// - /// - /// - internal float GetDataWidth(float coordinateWidth, int dataCount, DataZoom dataZoom) - { - if (dataCount < 1) dataCount = 1; - var categoryCount = GetDataNumber(dataZoom); - int segment = (m_BoundaryGap ? categoryCount : categoryCount - 1); - segment = segment <= 0 ? dataCount : segment; - return coordinateWidth / segment; - } - - /// - /// 获得标签显示的名称 - /// - /// - /// - /// - /// - /// - internal string GetLabelName(float coordinateWidth, int index, float minValue, float maxValue, - DataZoom dataZoom, bool forcePercent) - { - int split = GetSplitNumber(coordinateWidth, dataZoom); - if (m_Type == AxisType.Value) - { - if (minValue == 0 && maxValue == 0) return string.Empty; - float value = 0; - if (forcePercent) maxValue = 100; - if (m_Interval > 0) - { - if (index == split - 1) value = maxValue; - else value = minValue + index * m_Interval; - } - else - { - value = (minValue + (maxValue - minValue) * index / (split - 1)); - } - if (inverse) - { - value = -value; - minValue = -minValue; - maxValue = -maxValue; - } - if (forcePercent) return string.Format("{0}%", (int)value); - else return m_AxisLabel.GetFormatterContent(value, minValue, maxValue); - } - else if (m_Type == AxisType.Log) - { - float value = m_LogBaseE ? Mathf.Exp(runtimeMinLogIndex + index) : - Mathf.Pow(m_LogBase, runtimeMinLogIndex + index); - if (inverse) - { - value = -value; - minValue = -minValue; - maxValue = -maxValue; - } - return m_AxisLabel.GetFormatterContent(value, minValue, maxValue, true); - } - var showData = GetDataList(dataZoom); - int dataCount = showData.Count; - if (dataCount <= 0) return ""; - - if (index == split - 1 && !m_BoundaryGap) - { - return m_AxisLabel.GetFormatterContent(showData[dataCount - 1]); - } - else - { - float rate = dataCount / split; - if (rate < 1) rate = 1; - int offset = m_BoundaryGap ? (int)(rate / 2) : 0; - int newIndex = (int)(index * rate >= dataCount - 1 ? - dataCount - 1 : offset + index * rate); - return m_AxisLabel.GetFormatterContent(showData[newIndex]); - } - } - - /// - /// 获得分割线条数 - /// - /// - /// - internal int GetScaleNumber(float coordinateWidth, DataZoom dataZoom) - { - if (type == AxisType.Value || type == AxisType.Log) - { - int splitNum = GetSplitNumber(coordinateWidth, dataZoom); - return m_BoundaryGap ? splitNum + 1 : splitNum; - } - else - { - var showData = GetDataList(dataZoom); - int dataCount = showData.Count; - if (m_SplitNumber <= 0) return m_BoundaryGap ? dataCount + 1 : dataCount; - if (dataCount > 2 * splitNumber || dataCount <= 0) - return m_BoundaryGap ? m_SplitNumber + 1 : m_SplitNumber; - else - return m_BoundaryGap ? dataCount + 1 : dataCount; - } - } - - /// - /// 获得分割段宽度 - /// - /// - /// - /// - internal float GetScaleWidth(float coordinateWidth, int index, DataZoom dataZoom) - { - int num = GetScaleNumber(coordinateWidth, dataZoom) - 1; - if (num <= 0) num = 1; - if (type == AxisType.Value && m_Interval > 0) - { - if (index == num - 1) return coordinateWidth - (num - 1) * m_Interval * coordinateWidth / m_ValueRange; - else return m_Interval * coordinateWidth / m_ValueRange; - } - else - { - return coordinateWidth / num; - } - - } - /// /// 更新刻度标签文字 /// @@ -737,7 +575,8 @@ namespace XCharts { if (axisLabelTextList[i] != null) { - axisLabelTextList[i].text = GetLabelName(coordinateWidth, i, minValue, maxValue, dataZoom, forcePercent); + var text = AxisHelper.GetLabelName(this, coordinateWidth, i, minValue, maxValue, dataZoom, forcePercent); + axisLabelTextList[i].text = text; } } } @@ -782,87 +621,6 @@ namespace XCharts } } - internal bool NeedShowSplit() - { - if (!show) return false; - if (IsCategory() && data.Count <= 0) return false; - else if (IsValue() && m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return false; - else return true; - } - - /// - /// 调整最大最小值 - /// - /// - /// - internal void AdjustMinMaxValue(ref float minValue, ref float maxValue, bool needFormat) - { - if (m_Type == AxisType.Log) - { - int minSplit = 0; - int maxSplit = 0; - maxValue = ChartHelper.GetMaxLogValue(maxValue, m_LogBase, m_LogBaseE, out maxSplit); - minValue = ChartHelper.GetMinLogValue(minValue, m_LogBase, m_LogBaseE, out minSplit); - splitNumber = (minSplit > 0 && maxSplit > 0) ? (maxSplit + minSplit - 1) : (maxSplit + minSplit); - return; - } - if (minMaxType == Axis.AxisMinMaxType.Custom) - { - if (min != 0 || max != 0) - { - if (inverse) - { - minValue = -max; - maxValue = -min; - } - else - { - minValue = min; - maxValue = max; - } - } - } - else - { - switch (minMaxType) - { - case Axis.AxisMinMaxType.Default: - if (minValue == 0 && maxValue == 0) - { - } - else if (minValue > 0 && maxValue > 0) - { - minValue = 0; - maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, m_CeilRate) : maxValue; - } - else if (minValue < 0 && maxValue < 0) - { - minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, m_CeilRate) : minValue; - maxValue = 0; - } - else - { - minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, m_CeilRate) : minValue; - maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, m_CeilRate) : maxValue; - } - break; - case Axis.AxisMinMaxType.MinMax: - minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, m_CeilRate) : minValue; - maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, m_CeilRate) : maxValue; - break; - } - } - var tempRange = maxValue - minValue; - if (m_ValueRange != tempRange) - { - m_ValueRange = tempRange; - if (type == AxisType.Value && m_Interval > 0) - { - SetComponentDirty(); - } - } - } - internal void UpdateMinValue(float value, bool check) { if (value != m_RuntimeMaxValue) diff --git a/Runtime/Component/Main/Serie.cs b/Runtime/Component/Main/Serie.cs index 6421aba9..00dcb40f 100644 --- a/Runtime/Component/Main/Serie.cs +++ b/Runtime/Component/Main/Serie.cs @@ -1270,24 +1270,6 @@ namespace XCharts return null; } - /// - /// 获得指定索引的数据项的Label - /// - /// - /// - /// - public SerieLabel GetSerieLabel(int index, DataZoom dataZoom = null) - { - var data = GetDataList(dataZoom); - if (index >= 0 && index <= data.Count - 1) - { - var serieData = data[index]; - if (serieData.enableLabel) return serieData.label; - else return label; - } - return null; - } - /// /// 获得指定索引的维度X和维度Y的数据 /// @@ -1506,10 +1488,6 @@ namespace XCharts } } - - - - internal float GetBarWidth(float categoryWidth) { if (m_BarWidth > 1) return m_BarWidth; diff --git a/Runtime/Component/Main/Series.cs b/Runtime/Component/Main/Series.cs index 61664a55..43ca797e 100644 --- a/Runtime/Component/Main/Series.cs +++ b/Runtime/Component/Main/Series.cs @@ -35,6 +35,7 @@ namespace XCharts /// 系列个数。 /// public int Count { get { return m_Series.Count; } } + public bool labelDirty { get { return m_LabelDirty; } set { m_LabelDirty = value; } } public static Series defaultSeries { @@ -65,32 +66,6 @@ namespace XCharts } } - public bool labelDirty - { - get - { - if (m_LabelDirty) return true; - foreach (var serie in m_Series) - { - if (serie.label.componentDirty) return true; - } - return false; - } - } - - public bool labelUpdate - { - get - { - foreach (var serie in m_Series) - { - if (serie.label.vertsDirty) return true; - } - return false; - } - } - - public void SetLabelDirty() { m_LabelDirty = true; @@ -225,78 +200,6 @@ namespace XCharts return null; } - /// - /// 获得上一个同堆叠且显示的serie。 - /// - /// - /// - internal Serie GetLastStackSerie(int index) - { - var serie = GetSerie(index); - return GetLastStackSerie(serie); - } - - /// - /// 同堆叠的serie是否有渐变色的。 - /// - /// - /// - internal bool IsAnyGradientSerie(string stack) - { - if (string.IsNullOrEmpty(stack)) return false; - foreach (var serie in m_Series) - { - if (serie.show && serie.areaStyle.show && stack.Equals(serie.stack)) - { - if (serie.areaStyle.color != serie.areaStyle.toColor - && !ChartHelper.IsClearColor(serie.areaStyle.toColor)) - return true; - } - } - return false; - } - - /// - /// 是否有需裁剪的serie。 - /// - /// - internal bool IsAnyClipSerie() - { - foreach (var serie in m_Series) - { - if (serie.clip) return true; - } - return false; - } - - internal bool IsAnyUpdateAnimationSerie() - { - foreach (var serie in m_Series) - { - if (serie.animation.enable && serie.animation.dataChangeEnable) - { - return true; - } - } - return false; - } - - /// - /// 获得上一个同堆叠且显示的serie。 - /// - /// - /// - internal Serie GetLastStackSerie(Serie serie) - { - if (serie == null || string.IsNullOrEmpty(serie.stack)) return null; - for (int i = serie.index - 1; i >= 0; i--) - { - var temp = m_Series[i]; - if (temp.show && serie.stack.Equals(temp.stack)) return temp; - } - return null; - } - /// /// 是否包含指定名字的系列 /// @@ -698,20 +601,6 @@ namespace XCharts } } - /// - /// 是否由系列在用指定索引的axis - /// - /// - /// - internal bool IsUsedAxisIndex(int axisIndex) - { - foreach (var serie in list) - { - if (serie.axisIndex == axisIndex) return true; - } - return false; - } - /// /// 指定系列是否处于高亮选中状态 /// @@ -724,362 +613,6 @@ namespace XCharts else return false; } - /// - /// 获得维度X的最大最小值 - /// - /// - /// - /// - /// - internal void GetXMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis, bool inverse, - out float minVaule, out float maxValue) - { - GetMinMaxValue(dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue); - } - - /// - /// 获得维度Y的最大最小值 - /// - /// - /// - /// - /// - internal void GetYMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis, bool inverse, - out float minVaule, out float maxValue) - { - GetMinMaxValue(dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue); - } - - private Dictionary> _stackSeriesForMinMax = new Dictionary>(); - private Dictionary _serieTotalValueForMinMax = new Dictionary(); - internal void GetMinMaxValue(DataZoom dataZoom, int axisIndex, bool isValueAxis, bool inverse, bool yValue, - out float minVaule, out float maxValue) - { - float min = int.MaxValue; - float max = int.MinValue; - var isPercentStack = IsPercentStack(SerieType.Bar); - if (!IsStack() || (isValueAxis && !yValue)) - { - for (int i = 0; i < m_Series.Count; i++) - { - var serie = m_Series[i]; - if (serie.axisIndex != axisIndex) continue; - - if (IsActive(i)) - { - if (isPercentStack && IsPercentStack(serie.name, SerieType.Bar)) - { - if (100 > max) max = 100; - if (0 < min) min = 0; - } - else - { - var showData = m_Series[i].GetDataList(dataZoom); - foreach (var data in showData) - { - var currData = data.GetData(yValue ? 1 : 0, inverse); - if (currData > max) max = currData; - if (currData < min) min = currData; - } - } - } - } - } - else - { - GetStackSeries(ref _stackSeriesForMinMax); - foreach (var ss in _stackSeriesForMinMax) - { - _serieTotalValueForMinMax.Clear(); - for (int i = 0; i < ss.Value.Count; i++) - { - var serie = ss.Value[i]; - if (serie.axisIndex != axisIndex || !IsActive(i)) continue; - var showData = serie.GetDataList(dataZoom); - if (IsPercentStack(serie.stack, SerieType.Bar)) - { - for (int j = 0; j < showData.Count; j++) - { - _serieTotalValueForMinMax[j] = 100; - } - } - else - { - for (int j = 0; j < showData.Count; j++) - { - if (!_serieTotalValueForMinMax.ContainsKey(j)) - _serieTotalValueForMinMax[j] = 0; - var currData = (yValue ? showData[j].GetData(1) : showData[j].GetData(0)); - if (inverse) currData = -currData; - _serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData; - } - } - } - float tmax = int.MinValue; - float tmin = int.MaxValue; - foreach (var tt in _serieTotalValueForMinMax) - { - if (tt.Value > tmax) tmax = tt.Value; - if (tt.Value < tmin) tmin = tt.Value; - } - if (tmax > max) max = tmax; - if (tmin < min) min = tmin; - } - } - if (max == int.MinValue && min == int.MaxValue) - { - minVaule = 0; - maxValue = 0; - } - else - { - minVaule = min > 1 ? Mathf.FloorToInt(min) : min; - maxValue = max > 1 ? Mathf.CeilToInt(max) : max; - } - } - - private HashSet _setForStack = new HashSet(); - /// - /// 是否由数据堆叠 - /// - /// - internal bool IsStack() - { - _setForStack.Clear(); - foreach (var serie in m_Series) - { - if (string.IsNullOrEmpty(serie.stack)) continue; - if (_setForStack.Contains(serie.stack)) return true; - else - { - _setForStack.Add(serie.stack); - } - } - return false; - } - - /// - /// 是否堆叠 - /// - /// - /// - /// - internal bool IsStack(string stackName, SerieType type) - { - if (string.IsNullOrEmpty(stackName)) return false; - int count = 0; - foreach (var serie in m_Series) - { - if (serie.show && serie.type == type) - { - if (stackName.Equals(serie.stack)) count++; - if (count >= 2) return true; - } - } - return false; - } - - /// - /// 是否时百分比堆叠 - /// - /// - /// - internal bool IsPercentStack(SerieType type) - { - int count = 0; - bool isPercentStack = false; - foreach (var serie in m_Series) - { - if (serie.show && serie.type == type) - { - if (!string.IsNullOrEmpty(serie.stack)) - { - count++; - if (serie.barPercentStack) isPercentStack = true; - } - if (count >= 2 && isPercentStack) return true; - } - } - return false; - } - - /// - /// 是否时百分比堆叠 - /// - /// - /// - /// - internal bool IsPercentStack(string stackName, SerieType type) - { - if (string.IsNullOrEmpty(stackName)) return false; - int count = 0; - bool isPercentStack = false; - foreach (var serie in m_Series) - { - if (serie.show && serie.type == type) - { - if (stackName.Equals(serie.stack)) - { - count++; - if (serie.barPercentStack) isPercentStack = true; - } - if (count >= 2 && isPercentStack) return true; - } - } - return false; - } - - /// - /// 获得堆叠系列列表 - /// - /// - internal Dictionary> GetStackSeries() - { - int count = 0; - Dictionary sets = new Dictionary(); - Dictionary> stackSeries = new Dictionary>(); - for (int i = 0; i < m_Series.Count; i++) - { - var serie = m_Series[i]; - serie.index = i; - if (string.IsNullOrEmpty(serie.stack)) - { - stackSeries[count] = new List(); - stackSeries[count].Add(serie); - count++; - } - else - { - if (!sets.ContainsKey(serie.stack)) - { - sets.Add(serie.stack, count); - stackSeries[count] = new List(); - stackSeries[count].Add(serie); - count++; - } - else - { - int stackIndex = sets[serie.stack]; - stackSeries[stackIndex].Add(serie); - } - } - } - return stackSeries; - } - - private Dictionary sets = new Dictionary(); - /// - /// 获得堆叠系列列表 - /// - /// - /// - internal void GetStackSeries(ref Dictionary> stackSeries) - { - int count = 0; - sets.Clear(); - if (stackSeries == null) - { - stackSeries = new Dictionary>(m_Series.Count); - } - else - { - foreach (var kv in stackSeries) - { - kv.Value.Clear(); - } - } - for (int i = 0; i < m_Series.Count; i++) - { - var serie = m_Series[i]; - serie.index = i; - if (string.IsNullOrEmpty(serie.stack)) - { - if (!stackSeries.ContainsKey(count)) - stackSeries[count] = new List(m_Series.Count); - stackSeries[count].Add(serie); - count++; - } - else - { - if (!sets.ContainsKey(serie.stack)) - { - sets.Add(serie.stack, count); - if (!stackSeries.ContainsKey(count)) - stackSeries[count] = new List(m_Series.Count); - stackSeries[count].Add(serie); - count++; - } - else - { - int stackIndex = sets[serie.stack]; - stackSeries[stackIndex].Add(serie); - } - } - } - } - - private List serieNameList = new List(); - /// - /// 获得所有系列名,不包含空名字。 - /// - /// - internal List GetSerieNameList() - { - serieNameList.Clear(); - for (int n = 0; n < m_Series.Count; n++) - { - var serie = m_Series[n]; - switch (serie.type) - { - case SerieType.Pie: - case SerieType.Radar: - case SerieType.Ring: - for (int i = 0; i < serie.data.Count; i++) - { - if (string.IsNullOrEmpty(serie.data[i].name)) - serieNameList.Add(ChartCached.IntToStr(i)); - else if (!serieNameList.Contains(serie.data[i].name)) - serieNameList.Add(serie.data[i].name); - } - break; - default: - if (string.IsNullOrEmpty(serie.name)) - serieNameList.Add(ChartCached.IntToStr(n)); - else if (!serieNameList.Contains(serie.name)) - serieNameList.Add(serie.name); - break; - } - } - return serieNameList; - } - - internal List GetLegalSerieNameList() - { - var list = new List(); - for (int n = 0; n < m_Series.Count; n++) - { - var serie = m_Series[n]; - switch (serie.type) - { - case SerieType.Pie: - case SerieType.Radar: - case SerieType.Ring: - for (int i = 0; i < serie.data.Count; i++) - { - var dataName = serie.data[i].name; - if (!string.IsNullOrEmpty(dataName) && IsLegalLegendName(dataName) && !list.Contains(dataName)) - list.Add(dataName); - } - break; - default: - if (!string.IsNullOrEmpty(serie.name) && !list.Contains(serie.name) && IsLegalLegendName(serie.name)) - list.Add(serie.name); - break; - } - } - return list; - } - /// /// 设置获得标志图形大小的回调 /// @@ -1163,16 +696,6 @@ namespace XCharts } } - public bool IsLegalLegendName(string name) - { - int numName = -1; - if (int.TryParse(name, out numName)) - { - if (numName >= 0 && numName < 100) return false; - } - return true; - } - /// /// 从json中解析数据 /// diff --git a/Runtime/Helper/AxisHelper.cs b/Runtime/Helper/AxisHelper.cs deleted file mode 100644 index bcba90d4..00000000 --- a/Runtime/Helper/AxisHelper.cs +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************/ -/* */ -/* 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/Runtime/Helper/CheckHelper.cs b/Runtime/Helper/CheckHelper.cs index 095311c0..37d36a3e 100644 --- a/Runtime/Helper/CheckHelper.cs +++ b/Runtime/Helper/CheckHelper.cs @@ -9,7 +9,7 @@ using UnityEngine; namespace XCharts { - internal static class CheckHelper + public static class CheckHelper { private static bool IsColorAlphaZero(Color color) { @@ -19,7 +19,6 @@ namespace XCharts { var sb = ChartHelper.sb; sb.Length = 0; - //sb.AppendFormat("version:{0}_{1}\n", XChartsMgr.version, XChartsMgr.date); CheckSize(chart, sb); CheckTheme(chart, sb); CheckTitle(chart, sb); @@ -48,9 +47,9 @@ namespace XCharts var title = chart.title; if (!title.show) return; if (string.IsNullOrEmpty(title.text)) sb.Append("warning:title->text is null\n"); - if(IsColorAlphaZero(title.textStyle.color)) + if (IsColorAlphaZero(title.textStyle.color)) sb.Append("warning:title->textStyle->color alpha is 0\n"); - if(IsColorAlphaZero(title.subTextStyle.color)) + if (IsColorAlphaZero(title.subTextStyle.color)) sb.Append("warning:title->subTextStyle->color alpha is 0\n"); } @@ -58,9 +57,9 @@ namespace XCharts { var legend = chart.legend; if (!legend.show) return; - if(IsColorAlphaZero(legend.textStyle.color)) + if (IsColorAlphaZero(legend.textStyle.color)) sb.Append("warning:legend->textStyle->color alpha is 0\n"); - var serieNameList = chart.series.GetLegalSerieNameList(); + var serieNameList = SeriesHelper.GetLegalSerieNameList(chart.series); if (serieNameList.Count == 0) sb.Append("warning:legend need serie.name or serieData.name not empty\n"); foreach (var category in legend.data) { @@ -106,7 +105,7 @@ namespace XCharts sb.AppendFormat("warning:serie {0} lineStyle->width is 0\n", serie.index); if (serie.lineStyle.opacity == 0) sb.AppendFormat("warning:serie {0} lineStyle->opacity is 0\n", serie.index); - if(IsColorAlphaZero(serie.lineStyle.color)) + if (IsColorAlphaZero(serie.lineStyle.color)) sb.AppendFormat("warning:serie {0} lineStyle->color alpha is 0\n", serie.index); break; case SerieType.Bar: diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index ea9c7ceb..bc6930b1 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -175,8 +175,8 @@ namespace XCharts if (m_Series.anyDirty) { if (m_Series.vertsDirty) RefreshChart(); - if (m_Series.labelDirty) m_ReinitLabel = true; - if (m_Series.labelUpdate && !m_RefreshChart) m_RefreshLabel = true; + if (SeriesHelper.IsLabelDirty(m_Series)) m_ReinitLabel = true; + if (SeriesHelper.IsNeedLabelUpdate(m_Series) && !m_RefreshChart) m_RefreshLabel = true; foreach (var serie in m_Series.list) { if (serie.titleStyle.componentDirty) m_ReinitTitle = true; @@ -285,8 +285,7 @@ namespace XCharts var legendObject = ChartHelper.AddObject(s_LegendObjectName, transform, anchorMin, anchorMax, pivot, new Vector2(chartWidth, chartHeight)); legendObject.transform.localPosition = GetLegendPosition(); - - m_LegendRealShowName = m_Series.GetSerieNameList(); + SeriesHelper.UpdateSerieNameList(m_Series, ref m_LegendRealShowName); List datas; if (m_Legend.show && m_Legend.data.Count > 0) { @@ -303,7 +302,7 @@ namespace XCharts int totalLegend = 0; for (int i = 0; i < datas.Count; i++) { - if (!m_Series.IsLegalLegendName(datas[i])) continue; + if (!SeriesHelper.IsLegalLegendName(datas[i])) continue; totalLegend++; } m_Legend.RemoveButton(); @@ -311,7 +310,7 @@ namespace XCharts if (!m_Legend.show) return; for (int i = 0; i < datas.Count; i++) { - if (!m_Series.IsLegalLegendName(datas[i])) continue; + if (!SeriesHelper.IsLegalLegendName(datas[i])) continue; string legendName = m_Legend.GetFormatterContent(datas[i]); var readIndex = m_LegendRealShowName.IndexOf(datas[i]); var active = IsActiveByLegend(datas[i]); @@ -621,7 +620,7 @@ namespace XCharts if (m_ReinitLabel) { m_ReinitLabel = false; - m_LegendRealShowName = m_Series.GetSerieNameList(); + SeriesHelper.UpdateSerieNameList(m_Series, ref m_LegendRealShowName); InitSerieLabel(); } if (m_ReinitTitle) @@ -690,57 +689,6 @@ namespace XCharts RefreshChart(); } - protected bool CheckDataShow(string legendName, bool show) - { - bool needShow = false; - foreach (var serie in m_Series.list) - { - if (legendName.Equals(serie.name)) - { - serie.show = show; - serie.highlighted = false; - if (serie.show) needShow = true; - } - else - { - foreach (var data in serie.data) - { - if (legendName.Equals(data.name)) - { - data.show = show; - data.highlighted = false; - if (data.show) needShow = true; - } - } - } - } - return needShow; - } - - protected bool CheckDataHighlighted(string legendName, bool heighlight) - { - bool show = false; - foreach (var serie in m_Series.list) - { - if (legendName.Equals(serie.name)) - { - serie.highlighted = heighlight; - } - else - { - foreach (var data in serie.data) - { - if (legendName.Equals(data.name)) - { - data.highlighted = heighlight; - if (data.highlighted) show = true; - } - } - } - } - return show; - } - protected virtual void UpdateTooltip() { } @@ -775,100 +723,18 @@ namespace XCharts ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.backgroundColor); } - protected void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, - float tickness, Vector3 pos, Color color, Color toColor, float gap, float[] cornerRadius) + public void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, + float tickness, Vector3 pos, Color color, Color toColor, float gap, float[] cornerRadius) { var backgroundColor = m_ThemeInfo.backgroundColor; var smoothness = m_Settings.cicleSmoothness; - switch (type) - { - case SerieSymbolType.None: - break; - case SerieSymbolType.Circle: - if (gap > 0) - { - ChartDrawer.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, color, toColor, smoothness); - } - else - { - ChartDrawer.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness); - } - break; - case SerieSymbolType.EmptyCircle: - if (gap > 0) - { - ChartDrawer.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness); - ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, toColor, backgroundColor, smoothness); - } - else - { - ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, toColor, backgroundColor, smoothness); - } - break; - case SerieSymbolType.Rect: - if (gap > 0) - { - ChartDrawer.DrawPolygon(vh, pos, symbolSize + gap, backgroundColor); - ChartDrawer.DrawPolygon(vh, pos, symbolSize, color, toColor); - } - else - { - //ChartDrawer.DrawPolygon(vh, pos, symbolSize, color, toColor); - ChartDrawer.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, 0, cornerRadius); - } - break; - case SerieSymbolType.Triangle: - if (gap > 0) - { - ChartDrawer.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor); - ChartDrawer.DrawTriangle(vh, pos, symbolSize, color, toColor); - } - else - { - ChartDrawer.DrawTriangle(vh, pos, symbolSize, color, toColor); - } - break; - case SerieSymbolType.Diamond: - if (gap > 0) - { - ChartDrawer.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor); - ChartDrawer.DrawDiamond(vh, pos, symbolSize, color, toColor); - } - else - { - ChartDrawer.DrawDiamond(vh, pos, symbolSize, color, toColor); - } - break; - } - } - - protected void DrawLineStyle(VertexHelper vh, LineStyle lineStyle, - Vector3 startPos, Vector3 endPos, Color color) - { - var type = lineStyle.type; - var width = lineStyle.width; - switch (type) - { - case LineStyle.Type.Dashed: - ChartDrawer.DrawDashLine(vh, startPos, endPos, width, color); - break; - case LineStyle.Type.Dotted: - ChartDrawer.DrawDotLine(vh, startPos, endPos, width, color); - break; - case LineStyle.Type.Solid: - ChartDrawer.DrawLine(vh, startPos, endPos, width, color); - break; - case LineStyle.Type.DashDot: - ChartDrawer.DrawDashDotLine(vh, startPos, endPos, width, color); - break; - case LineStyle.Type.DashDotDot: - ChartDrawer.DrawDashDotDotLine(vh, startPos, endPos, width, color); - break; - } + ChartDrawer.DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, gap, + cornerRadius, backgroundColor, smoothness); } protected void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData) { + if (serieData == null || serieData.labelObject == null) return; var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); if (!serieLabel.show) return; var invert = serie.type == SerieType.Line diff --git a/Runtime/Internal/CoordinateChart.cs b/Runtime/Internal/CoordinateChart.cs index 463f45f3..0e6d01f4 100644 --- a/Runtime/Internal/CoordinateChart.cs +++ b/Runtime/Internal/CoordinateChart.cs @@ -144,7 +144,7 @@ namespace XCharts protected override void DrawBackground(VertexHelper vh) { - if (m_Series.IsAnyClipSerie()) + if (SeriesHelper.IsAnyClipSerie(m_Series)) { var xLineDiff = xAxis0.axisLine.width; var yLineDiff = yAxis0.axisLine.width; @@ -167,7 +167,7 @@ namespace XCharts protected void DrawClip(VertexHelper vh) { - if (!m_Series.IsAnyClipSerie()) return; + if (!SeriesHelper.IsAnyClipSerie(m_Series)) return; var xLineDiff = xAxis0.axisLine.width; var yLineDiff = yAxis0.axisLine.width; var xSplitDiff = xAxis0.splitLine.lineStyle.width; @@ -200,7 +200,7 @@ namespace XCharts if (!m_CheckMinMaxValue) return; m_IsPlayingAnimation = false; bool yCategory = m_YAxises[0].IsCategory() || m_YAxises[1].IsCategory(); - m_Series.GetStackSeries(ref m_StackSeries); + SeriesHelper.GetStackSeries(m_Series, ref m_StackSeries); int seriesCount = m_StackSeries.Count; m_BarLastOffset = 0; for (int j = 0; j < seriesCount; j++) @@ -300,7 +300,7 @@ namespace XCharts for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++) { - float splitWid = xAxis.GetDataWidth(m_CoordinateWidth, dataCount, m_DataZoom); + float splitWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom); float pX = m_CoordinateX + j * splitWid; if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) || (!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2))) @@ -312,7 +312,7 @@ namespace XCharts } for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++) { - float splitWid = yAxis.GetDataWidth(m_CoordinateHeight, dataCount, m_DataZoom); + float splitWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom); float pY = m_CoordinateY + j * splitWid; if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) || (!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2))) @@ -329,7 +329,7 @@ namespace XCharts m_Tooltip.runtimeYValues[i] = value; for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++) { - float splitWid = xAxis.GetDataWidth(m_CoordinateWidth, dataCount, m_DataZoom); + float splitWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom); float pX = m_CoordinateX + j * splitWid; if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) || (!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2))) @@ -347,7 +347,7 @@ namespace XCharts m_Tooltip.runtimeXValues[i] = value; for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++) { - float splitWid = yAxis.GetDataWidth(m_CoordinateHeight, dataCount, m_DataZoom); + float splitWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom); float pY = m_CoordinateY + j * splitWid; if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) || (!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2))) @@ -443,7 +443,7 @@ namespace XCharts else { labelText = axis.GetData((int)m_Tooltip.runtimeXValues[axisIndex], m_DataZoom); - float splitWidth = axis.GetSplitWidth(m_CoordinateWidth, m_DataZoom); + float splitWidth = AxisHelper.GetSplitWidth(axis, m_CoordinateWidth, m_DataZoom); int index = (int)m_Tooltip.runtimeXValues[axisIndex]; float px = m_CoordinateX + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0) + 0.5f; labelPos = new Vector2(px, posY - diff); @@ -461,7 +461,7 @@ namespace XCharts else { labelText = axis.GetData((int)m_Tooltip.runtimeYValues[axisIndex], m_DataZoom); - float splitWidth = axis.GetSplitWidth(m_CoordinateHeight, m_DataZoom); + float splitWidth = AxisHelper.GetSplitWidth(axis, m_CoordinateHeight, m_DataZoom); int index = (int)m_Tooltip.runtimeYValues[axisIndex]; float py = m_CoordinateY + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0); labelPos = new Vector2(posX - diff, py); @@ -525,7 +525,7 @@ namespace XCharts var labelColor = ChartHelper.IsClearColor(yAxis.axisLabel.color) ? (Color)m_ThemeInfo.axisTextColor : yAxis.axisLabel.color; - int splitNumber = yAxis.GetSplitNumber(m_CoordinateHeight, m_DataZoom); + int splitNumber = AxisHelper.GetSplitNumber(yAxis, m_CoordinateHeight, m_DataZoom); float totalWidth = 0; for (int i = 0; i < splitNumber; i++) { @@ -546,12 +546,12 @@ namespace XCharts yAxis.axisLabel.fontSize, yAxis.axisLabel.rotate, yAxis.axisLabel.fontStyle); } - float labelWidth = yAxis.GetScaleWidth(m_CoordinateHeight, i, m_DataZoom); + float labelWidth = AxisHelper.GetScaleWidth(yAxis, m_CoordinateHeight, i, m_DataZoom); if (i == 0) yAxis.axisLabel.SetRelatedText(txt, labelWidth); txt.transform.localPosition = GetLabelYPosition(totalWidth + (yAxis.boundaryGap ? labelWidth / 2 : 0), i, yAxisIndex, yAxis); - var isPercentStack = m_Series.IsPercentStack(SerieType.Bar); - txt.text = yAxis.GetLabelName(m_CoordinateHeight, i, yAxis.runtimeMinValue, yAxis.runtimeMaxValue, m_DataZoom, isPercentStack); + var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); + txt.text = AxisHelper.GetLabelName(yAxis, m_CoordinateHeight, i, yAxis.runtimeMinValue, yAxis.runtimeMaxValue, m_DataZoom, isPercentStack); txt.gameObject.SetActive(yAxis.show && (yAxis.axisLabel.interval == 0 || i % (yAxis.axisLabel.interval + 1) == 0)); yAxis.axisLabelTextList.Add(txt); @@ -630,11 +630,11 @@ namespace XCharts var labelColor = ChartHelper.IsClearColor(xAxis.axisLabel.color) ? (Color)m_ThemeInfo.axisTextColor : xAxis.axisLabel.color; - int splitNumber = xAxis.GetSplitNumber(m_CoordinateWidth, m_DataZoom); + int splitNumber = AxisHelper.GetSplitNumber(xAxis, m_CoordinateWidth, m_DataZoom); float totalWidth = 0; for (int i = 0; i < splitNumber; i++) { - float labelWidth = xAxis.GetScaleWidth(m_CoordinateWidth, i, m_DataZoom); + float labelWidth = AxisHelper.GetScaleWidth(xAxis, m_CoordinateWidth, i, m_DataZoom); bool inside = xAxis.axisLabel.inside; Text txt = ChartHelper.AddTextObject(ChartCached.GetXAxisName(xAxisIndex, i), axisObj.transform, m_ThemeInfo.font, labelColor, TextAnchor.MiddleCenter, new Vector2(0, 1), @@ -644,8 +644,8 @@ namespace XCharts txt.transform.localPosition = GetLabelXPosition(totalWidth + (xAxis.boundaryGap ? labelWidth : labelWidth / 2), i, xAxisIndex, xAxis); totalWidth += labelWidth; - var isPercentStack = m_Series.IsPercentStack(SerieType.Bar); - txt.text = xAxis.GetLabelName(m_CoordinateWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, m_DataZoom, + var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); + txt.text = AxisHelper.GetLabelName(xAxis, m_CoordinateWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, m_DataZoom, isPercentStack); txt.gameObject.SetActive(xAxis.show && (xAxis.axisLabel.interval == 0 || i % (xAxis.axisLabel.interval + 1) == 0)); @@ -790,18 +790,18 @@ namespace XCharts { if (axis is XAxis) { - m_Series.GetXMinMaxValue(null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue); + SeriesHelper.GetXMinMaxValue(m_Series, null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue); } else { - m_Series.GetYMinMaxValue(null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue); + SeriesHelper.GetYMinMaxValue(m_Series, null, axisIndex, true, axis.inverse, out tempMinValue, out tempMaxValue); } } else { - m_Series.GetYMinMaxValue(null, axisIndex, false, axis.inverse, out tempMinValue, out tempMaxValue); + SeriesHelper.GetYMinMaxValue(m_Series, null, axisIndex, false, axis.inverse, out tempMinValue, out tempMaxValue); } - axis.AdjustMinMaxValue(ref tempMinValue, ref tempMaxValue, true); + AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true); if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue) { m_CheckMinMaxValue = true; @@ -843,7 +843,7 @@ namespace XCharts protected void UpdateAxisLabelText(Axis axis) { float m_CoordinateWidth = axis is XAxis ? this.m_CoordinateWidth : m_CoordinateHeight; - var isPercentStack = m_Series.IsPercentStack(SerieType.Bar); + var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); axis.UpdateLabelText(m_CoordinateWidth, m_DataZoom, isPercentStack, 500); } @@ -907,15 +907,15 @@ namespace XCharts private void DrawYAxisSplit(VertexHelper vh, int yAxisIndex, YAxis yAxis) { - if (yAxis.NeedShowSplit()) + if (AxisHelper.NeedShowSplit(yAxis)) { - var size = yAxis.GetScaleNumber(m_CoordinateWidth, m_DataZoom); + var size = AxisHelper.GetScaleNumber(yAxis, m_CoordinateWidth, m_DataZoom); var totalWidth = m_CoordinateY; var xAxis = m_XAxises[yAxisIndex]; var zeroPos = new Vector3(m_CoordinateX + xAxis.runtimeZeroXOffset, m_CoordinateY + yAxis.runtimeZeroYOffset); for (int i = 0; i < size; i++) { - var scaleWidth = yAxis.GetScaleWidth(m_CoordinateHeight, i, m_DataZoom); + var scaleWidth = AxisHelper.GetScaleWidth(yAxis, m_CoordinateHeight, i, m_DataZoom); float pY = totalWidth; if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel) { @@ -935,7 +935,7 @@ namespace XCharts { if (yAxis.splitLine.NeedShow(i)) { - DrawLineStyle(vh, yAxis.splitLine.lineStyle, new Vector3(m_CoordinateX, pY), + ChartDrawer.DrawLineStyle(vh, yAxis.splitLine.lineStyle, new Vector3(m_CoordinateX, pY), new Vector3(m_CoordinateX + m_CoordinateWidth, pY), yAxis.splitLine.GetColor(m_ThemeInfo)); } } @@ -947,14 +947,14 @@ namespace XCharts private void DrawYAxisTick(VertexHelper vh, int yAxisIndex, YAxis yAxis) { - if (yAxis.NeedShowSplit()) + if (AxisHelper.NeedShowSplit(yAxis)) { - var size = yAxis.GetScaleNumber(m_CoordinateWidth, m_DataZoom); + var size = AxisHelper.GetScaleNumber(yAxis, m_CoordinateWidth, m_DataZoom); var totalWidth = m_CoordinateY; var xAxis = m_XAxises[yAxisIndex]; for (int i = 0; i < size; i++) { - var scaleWidth = yAxis.GetScaleWidth(m_CoordinateHeight, i, m_DataZoom); + var scaleWidth = AxisHelper.GetScaleWidth(yAxis, m_CoordinateHeight, i, m_DataZoom); float pX = 0; float pY = totalWidth; if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel) @@ -997,15 +997,15 @@ namespace XCharts private void DrawXAxisSplit(VertexHelper vh, int xAxisIndex, XAxis xAxis) { - if (xAxis.NeedShowSplit()) + if (AxisHelper.NeedShowSplit(xAxis)) { - var size = xAxis.GetScaleNumber(m_CoordinateWidth, m_DataZoom); + var size = AxisHelper.GetScaleNumber(xAxis, m_CoordinateWidth, m_DataZoom); var totalWidth = m_CoordinateX; var yAxis = m_YAxises[xAxisIndex]; var zeroPos = new Vector3(m_CoordinateX, m_CoordinateY + yAxis.runtimeZeroYOffset); for (int i = 0; i < size; i++) { - var scaleWidth = xAxis.GetScaleWidth(m_CoordinateWidth, i, m_DataZoom); + var scaleWidth = AxisHelper.GetScaleWidth(xAxis, m_CoordinateWidth, i, m_DataZoom); float pX = totalWidth; if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel) { @@ -1025,7 +1025,7 @@ namespace XCharts { if (xAxis.splitLine.NeedShow(i)) { - DrawLineStyle(vh, xAxis.splitLine.lineStyle, new Vector3(pX, m_CoordinateY), + ChartDrawer.DrawLineStyle(vh, xAxis.splitLine.lineStyle, new Vector3(pX, m_CoordinateY), new Vector3(pX, m_CoordinateY + m_CoordinateHeight), xAxis.splitLine.GetColor(m_ThemeInfo)); } } @@ -1037,14 +1037,14 @@ namespace XCharts private void DrawXAxisTick(VertexHelper vh, int xAxisIndex, XAxis xAxis) { - if (xAxis.NeedShowSplit()) + if (AxisHelper.NeedShowSplit(xAxis)) { - var size = xAxis.GetScaleNumber(m_CoordinateWidth, m_DataZoom); + var size = AxisHelper.GetScaleNumber(xAxis, m_CoordinateWidth, m_DataZoom); var totalWidth = m_CoordinateX; var yAxis = m_YAxises[xAxisIndex]; for (int i = 0; i < size; i++) { - var scaleWidth = xAxis.GetScaleWidth(m_CoordinateWidth, i, m_DataZoom); + var scaleWidth = AxisHelper.GetScaleWidth(xAxis, m_CoordinateWidth, i, m_DataZoom); float pX = totalWidth; float pY = 0; if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel) @@ -1132,8 +1132,8 @@ namespace XCharts Vector3 np = Vector3.zero; float minValue = 0; float maxValue = 0; - m_Series.GetYMinMaxValue(null, 0, IsValue(), axis.inverse, out minValue, out maxValue); - axis.AdjustMinMaxValue(ref minValue, ref maxValue, true); + SeriesHelper.GetYMinMaxValue(m_Series, null, 0, IsValue(), axis.inverse, out minValue, out maxValue); + AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true); int rate = 1; var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist; @@ -1148,8 +1148,6 @@ namespace XCharts float value = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i, serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis.inverse); float pX = m_CoordinateX + i * scaleWid; - // float dataHig = (axis.runtimeMaxValue - axis.runtimeMinValue) == 0 ? 0 : - // (value - axis.runtimeMinValue) / (axis.runtimeMaxValue - axis.runtimeMinValue) * hig; float dataHig = (maxValue - minValue) == 0 ? 0 : (value - minValue) / (maxValue - minValue) * hig; np = new Vector3(pX, m_ChartY + m_DataZoom.bottom + dataHig); @@ -1197,7 +1195,7 @@ namespace XCharts var xAxis = m_XAxises[i]; var yAxis = m_YAxises[i]; if (!xAxis.show) continue; - float splitWidth = xAxis.GetDataWidth(m_CoordinateWidth, dataCount, m_DataZoom); + float splitWidth = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom); switch (m_Tooltip.type) { case Tooltip.Type.Corss: @@ -1208,12 +1206,12 @@ namespace XCharts Vector2 sp = new Vector2(pX, m_CoordinateY); Vector2 ep = new Vector2(pX, m_CoordinateY + m_CoordinateHeight); var lineColor = TooltipHelper.GetLineColor(tooltip, m_ThemeInfo); - DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); + ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); if (m_Tooltip.type == Tooltip.Type.Corss) { sp = new Vector2(m_CoordinateX, m_Tooltip.runtimePointerPos.y); ep = new Vector2(m_CoordinateX + m_CoordinateWidth, m_Tooltip.runtimePointerPos.y); - DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); + ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); } break; case Tooltip.Type.Shadow: @@ -1242,7 +1240,7 @@ namespace XCharts var yAxis = m_YAxises[i]; var xAxis = m_XAxises[i]; if (!yAxis.show) continue; - float splitWidth = yAxis.GetDataWidth(m_CoordinateHeight, dataCount, m_DataZoom); + float splitWidth = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom); switch (m_Tooltip.type) { case Tooltip.Type.Corss: @@ -1251,12 +1249,12 @@ namespace XCharts Vector2 sp = new Vector2(m_CoordinateX, pY); Vector2 ep = new Vector2(m_CoordinateX + m_CoordinateWidth, pY); var lineColor = TooltipHelper.GetLineColor(tooltip, m_ThemeInfo); - DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); + ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); if (m_Tooltip.type == Tooltip.Type.Corss) { sp = new Vector2(m_CoordinateX, m_Tooltip.runtimePointerPos.y); ep = new Vector2(m_CoordinateX + m_CoordinateWidth, m_Tooltip.runtimePointerPos.y); - DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); + ChartDrawer.DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor); } break; case Tooltip.Type.Shadow: @@ -1403,7 +1401,7 @@ namespace XCharts break; case SerieType.Bar: var zeroPos = Vector3.zero; - var lastStackSerie = m_Series.GetLastStackSerie(n); + var lastStackSerie = SeriesHelper.GetLastStackSerie(m_Series, n); if (serie.type == SerieType.Bar) { if (serieLabel.position == SerieLabel.Position.Bottom || serieLabel.position == SerieLabel.Position.Center) @@ -1449,13 +1447,13 @@ namespace XCharts protected override void OnRefreshLabel() { - var anyPercentStack = m_Series.IsPercentStack(SerieType.Bar); + var anyPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); for (int i = 0; i < m_Series.Count; i++) { var serie = m_Series.GetSerie(i); if (serie.IsPerformanceMode()) continue; var total = serie.yTotal; - var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar); + var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar); for (int j = 0; j < serie.data.Count; j++) { if (j >= serie.dataPoints.Count) break; diff --git a/Runtime/Internal/CoordinateChart_DrawBar.cs b/Runtime/Internal/CoordinateChart_DrawBar.cs index f2383d83..04a77116 100644 --- a/Runtime/Internal/CoordinateChart_DrawBar.cs +++ b/Runtime/Internal/CoordinateChart_DrawBar.cs @@ -24,7 +24,7 @@ namespace XCharts if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count]; var showData = serie.GetDataList(m_DataZoom); - float categoryWidth = yAxis.GetDataWidth(m_CoordinateHeight, showData.Count, m_DataZoom); + float categoryWidth = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, showData.Count, m_DataZoom); float barGap = GetBarGap(); float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap); float barWidth = serie.GetBarWidth(categoryWidth); @@ -43,7 +43,7 @@ namespace XCharts seriesHig.Add(0); } } - var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar); + var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar); bool dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration); @@ -135,7 +135,7 @@ namespace XCharts } } } - if (!m_Series.IsStack(serie.stack, SerieType.Bar)) + if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar)) { m_BarLastOffset += barGapWidth; } @@ -165,7 +165,7 @@ namespace XCharts var xAxis = m_XAxises[serie.axisIndex]; if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count]; - float categoryWidth = xAxis.GetDataWidth(m_CoordinateWidth, showData.Count, m_DataZoom); + float categoryWidth = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, showData.Count, m_DataZoom); float barGap = GetBarGap(); float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap); float barWidth = serie.GetBarWidth(categoryWidth); @@ -184,7 +184,7 @@ namespace XCharts } } - var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar); + var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar); bool dataChanging = false; float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration); @@ -279,7 +279,7 @@ namespace XCharts { RefreshChart(); } - if (!m_Series.IsStack(serie.stack, SerieType.Bar)) + if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar)) { m_BarLastOffset += barGapWidth; } diff --git a/Runtime/Internal/CoordinateChart_DrawLine.cs b/Runtime/Internal/CoordinateChart_DrawLine.cs index 633995a9..f64de8e8 100644 --- a/Runtime/Internal/CoordinateChart_DrawLine.cs +++ b/Runtime/Internal/CoordinateChart_DrawLine.cs @@ -17,7 +17,7 @@ namespace XCharts { protected void DrawLinePoint(VertexHelper vh) { - var clip = m_Series.IsAnyClipSerie(); + var clip = SeriesHelper.IsAnyClipSerie(m_Series); for (int n = 0; n < m_Series.Count; n++) { var serie = m_Series.GetSerie(n); @@ -98,9 +98,9 @@ namespace XCharts var yAxis = m_YAxises[serie.axisIndex]; var xAxis = m_XAxises[serie.axisIndex]; var zeroPos = new Vector3(m_CoordinateX, m_CoordinateY + yAxis.runtimeZeroYOffset); - var isStack = m_Series.IsStack(serie.stack, SerieType.Line); + var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Line); if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count]; - float scaleWid = xAxis.GetDataWidth(m_CoordinateWidth, showData.Count, m_DataZoom); + float scaleWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, showData.Count, m_DataZoom); float startX = m_CoordinateX + (xAxis.boundaryGap ? scaleWid / 2 : 0); int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) @@ -486,9 +486,9 @@ namespace XCharts var xAxis = m_XAxises[serie.axisIndex]; var yAxis = m_YAxises[serie.axisIndex]; var zeroPos = new Vector3(m_CoordinateX + xAxis.runtimeZeroXOffset, m_CoordinateY); - var isStack = m_Series.IsStack(serie.stack, SerieType.Line); + var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Line); if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count]; - float scaleWid = yAxis.GetDataWidth(m_CoordinateHeight, showData.Count, m_DataZoom); + float scaleWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, showData.Count, m_DataZoom); float startY = m_CoordinateY + (yAxis.boundaryGap ? scaleWid / 2 : 0); int maxCount = serie.maxShow > 0 ? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) @@ -653,7 +653,7 @@ namespace XCharts return true; } - var lastSerie = m_Series.GetLastStackSerie(serie); + var lastSerie = SeriesHelper.GetLastStackSerie(m_Series, serie); Vector3 dnPos, upPos1, upPos2, dir1v, dir2v; bool isDown; var dir1 = (np - lp).normalized; @@ -1192,7 +1192,7 @@ namespace XCharts if (serie.areaStyle.show) { - var lastSerie = m_Series.GetLastStackSerie(serie); + var lastSerie = SeriesHelper.GetLastStackSerie(m_Series, serie); if (lastSerie != null) { var lastSmoothPoints = lastSerie.GetUpSmoothList(dataIndex); diff --git a/Runtime/Internal/Helper.meta b/Runtime/Internal/Helper.meta new file mode 100644 index 00000000..82842c5f --- /dev/null +++ b/Runtime/Internal/Helper.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b3dbff4f83d24491da3a8a88e3e3ace4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/Helper/AxisHelper.cs b/Runtime/Internal/Helper/AxisHelper.cs new file mode 100644 index 00000000..6ee9e445 --- /dev/null +++ b/Runtime/Internal/Helper/AxisHelper.cs @@ -0,0 +1,275 @@ +/******************************************/ +/* */ +/* Copyright (c) 2018 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/******************************************/ +using System.Text; +using UnityEngine; + +namespace XCharts +{ + public static class AxisHelper + { + public static float GetTickWidth(Axis axis) + { + return axis.axisTick.width != 0 ? axis.axisTick.width : axis.axisLine.width; + } + + /// + /// 获得分割段数 + /// + /// + /// + public static int GetSplitNumber(Axis axis, float coordinateWid, DataZoom dataZoom) + { + if (axis.type == Axis.AxisType.Value) + { + if (axis.interval > 0) + { + if (coordinateWid <= 0) return 0; + int num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval) + 1; + int maxNum = Mathf.CeilToInt(coordinateWid / 15); + if (num > maxNum) + { + axis.interval *= 2; + num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval) + 1; + } + return num; + } + else return axis.splitNumber; + } + else if (axis.type == Axis.AxisType.Log) + { + return axis.splitNumber; + } + int dataCount = axis.GetDataList(dataZoom).Count; + if (axis.splitNumber <= 0) return dataCount; + if (dataCount > 2 * axis.splitNumber || dataCount <= 0) + return axis.splitNumber; + else + return dataCount; + } + + /// + /// 获得分割段的宽度 + /// + /// + /// + /// + public static float GetSplitWidth(Axis axis, float coordinateWidth, DataZoom dataZoom) + { + int split = GetSplitNumber(axis, coordinateWidth, dataZoom); + int segment = (axis.boundaryGap ? split : split - 1); + segment = segment <= 0 ? 1 : segment; + return coordinateWidth / segment; + } + + /// + /// 获得一个类目数据在坐标系中代表的宽度 + /// + /// + /// + /// + public static float GetDataWidth(Axis axis, float coordinateWidth, int dataCount, DataZoom dataZoom) + { + if (dataCount < 1) dataCount = 1; + var categoryCount = axis.GetDataNumber(dataZoom); + int segment = (axis.boundaryGap ? categoryCount : categoryCount - 1); + segment = segment <= 0 ? dataCount : segment; + return coordinateWidth / segment; + } + + /// + /// 获得标签显示的名称 + /// + /// + /// + /// + /// + /// + internal static string GetLabelName(Axis axis, float coordinateWidth, int index, float minValue, float maxValue, + DataZoom dataZoom, bool forcePercent) + { + int split = GetSplitNumber(axis, coordinateWidth, dataZoom); + if (axis.type == Axis.AxisType.Value) + { + if (minValue == 0 && maxValue == 0) return string.Empty; + float value = 0; + if (forcePercent) maxValue = 100; + if (axis.interval > 0) + { + if (index == split - 1) value = maxValue; + else value = minValue + index * axis.interval; + } + else + { + value = (minValue + (maxValue - minValue) * index / (split - 1)); + } + if (axis.inverse) + { + value = -value; + minValue = -minValue; + maxValue = -maxValue; + } + if (forcePercent) return string.Format("{0}%", (int)value); + else return axis.axisLabel.GetFormatterContent(value, minValue, maxValue); + } + else if (axis.type == Axis.AxisType.Log) + { + float value = axis.logBaseE ? Mathf.Exp(axis.runtimeMinLogIndex + index) : + Mathf.Pow(axis.logBase, axis.runtimeMinLogIndex + index); + if (axis.inverse) + { + value = -value; + minValue = -minValue; + maxValue = -maxValue; + } + return axis.axisLabel.GetFormatterContent(value, minValue, maxValue, true); + } + var showData = axis.GetDataList(dataZoom); + int dataCount = showData.Count; + if (dataCount <= 0) return ""; + + if (index == split - 1 && !axis.boundaryGap) + { + return axis.axisLabel.GetFormatterContent(showData[dataCount - 1]); + } + else + { + float rate = dataCount / split; + if (rate < 1) rate = 1; + int offset = axis.boundaryGap ? (int)(rate / 2) : 0; + int newIndex = (int)(index * rate >= dataCount - 1 ? + dataCount - 1 : offset + index * rate); + return axis.axisLabel.GetFormatterContent(showData[newIndex]); + } + } + + /// + /// 获得分割线条数 + /// + /// + /// + internal static int GetScaleNumber(Axis axis, float coordinateWidth, DataZoom dataZoom) + { + if (axis.type == Axis.AxisType.Value || axis.type == Axis.AxisType.Log) + { + int splitNum = GetSplitNumber(axis, coordinateWidth, dataZoom); + return axis.boundaryGap ? splitNum + 1 : splitNum; + } + else + { + var showData = axis.GetDataList(dataZoom); + int dataCount = showData.Count; + if (axis.splitNumber <= 0) return axis.boundaryGap ? dataCount + 1 : dataCount; + if (dataCount > 2 * axis.splitNumber || dataCount <= 0) + return axis.boundaryGap ? axis.splitNumber + 1 : axis.splitNumber; + else + return axis.boundaryGap ? dataCount + 1 : dataCount; + } + } + + /// + /// 获得分割段宽度 + /// + /// + /// + /// + internal static float GetScaleWidth(Axis axis, float coordinateWidth, int index, DataZoom dataZoom) + { + int num = GetScaleNumber(axis, coordinateWidth, dataZoom) - 1; + if (num <= 0) num = 1; + if (axis.type == Axis.AxisType.Value && axis.interval > 0) + { + if (index == num - 1) return coordinateWidth - (num - 1) * axis.interval * coordinateWidth / axis.runtimeMinMaxRange; + else return axis.interval * coordinateWidth / axis.runtimeMinMaxRange; + } + else + { + return coordinateWidth / num; + } + } + + /// + /// 调整最大最小值 + /// + /// + /// + internal static void AdjustMinMaxValue(Axis axis, ref float minValue, ref float maxValue, bool needFormat) + { + if (axis.type == Axis.AxisType.Log) + { + int minSplit = 0; + int maxSplit = 0; + maxValue = ChartHelper.GetMaxLogValue(maxValue, axis.logBase, axis.logBaseE, out maxSplit); + minValue = ChartHelper.GetMinLogValue(minValue, axis.logBase, axis.logBaseE, out minSplit); + axis.splitNumber = (minSplit > 0 && maxSplit > 0) ? (maxSplit + minSplit - 1) : (maxSplit + minSplit); + return; + } + if (axis.minMaxType == Axis.AxisMinMaxType.Custom) + { + if (axis.min != 0 || axis.max != 0) + { + if (axis.inverse) + { + minValue = -axis.max; + maxValue = -axis.min; + } + else + { + minValue = axis.min; + maxValue = axis.max; + } + } + } + else + { + switch (axis.minMaxType) + { + case Axis.AxisMinMaxType.Default: + if (minValue == 0 && maxValue == 0) + { + } + else if (minValue > 0 && maxValue > 0) + { + minValue = 0; + maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, axis.ceilRate) : maxValue; + } + else if (minValue < 0 && maxValue < 0) + { + minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, axis.ceilRate) : minValue; + maxValue = 0; + } + else + { + minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, axis.ceilRate) : minValue; + maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, axis.ceilRate) : maxValue; + } + break; + case Axis.AxisMinMaxType.MinMax: + minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, axis.ceilRate) : minValue; + maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, axis.ceilRate) : maxValue; + break; + } + } + var tempRange = maxValue - minValue; + if (axis.runtimeMinMaxRange != tempRange) + { + axis.runtimeMinMaxRange = tempRange; + if (axis.type == Axis.AxisType.Value && axis.interval > 0) + { + axis.SetComponentDirty(); + } + } + } + + internal static bool NeedShowSplit(Axis axis) + { + if (!axis.show) return false; + if (axis.IsCategory() && axis.data.Count <= 0) return false; + else if (axis.IsValue() && axis.runtimeMinValue == 0 && axis.runtimeMaxValue == 0) return false; + else return true; + } + } +} \ No newline at end of file diff --git a/Runtime/Helper/AxisHelper.cs.meta b/Runtime/Internal/Helper/AxisHelper.cs.meta similarity index 83% rename from Runtime/Helper/AxisHelper.cs.meta rename to Runtime/Internal/Helper/AxisHelper.cs.meta index b7e057ab..c911707b 100644 --- a/Runtime/Helper/AxisHelper.cs.meta +++ b/Runtime/Internal/Helper/AxisHelper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ada7d0edfc97b432db026ca5eecea8ac +guid: 502c2be6d197b40f59ae65d9c659700f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Helper/ItemStyleHelper.cs b/Runtime/Internal/Helper/ItemStyleHelper.cs similarity index 100% rename from Runtime/Helper/ItemStyleHelper.cs rename to Runtime/Internal/Helper/ItemStyleHelper.cs diff --git a/Runtime/Helper/ItemStyleHelper.cs.meta b/Runtime/Internal/Helper/ItemStyleHelper.cs.meta similarity index 83% rename from Runtime/Helper/ItemStyleHelper.cs.meta rename to Runtime/Internal/Helper/ItemStyleHelper.cs.meta index 7bc5f0a3..31a149f1 100644 --- a/Runtime/Helper/ItemStyleHelper.cs.meta +++ b/Runtime/Internal/Helper/ItemStyleHelper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ce94468fab72e4b39b53f6cf8b647d6b +guid: 14c20b85c2c6d44b08f57c928307080d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Helper/LegendHelper.cs b/Runtime/Internal/Helper/LegendHelper.cs similarity index 86% rename from Runtime/Helper/LegendHelper.cs rename to Runtime/Internal/Helper/LegendHelper.cs index aa50a8a8..3a9d9b3c 100644 --- a/Runtime/Helper/LegendHelper.cs +++ b/Runtime/Internal/Helper/LegendHelper.cs @@ -213,5 +213,56 @@ namespace XCharts break; } } + + public static bool CheckDataShow(Series series, string legendName, bool show) + { + bool needShow = false; + foreach (var serie in series.list) + { + if (legendName.Equals(serie.name)) + { + serie.show = show; + serie.highlighted = false; + if (serie.show) needShow = true; + } + else + { + foreach (var data in serie.data) + { + if (legendName.Equals(data.name)) + { + data.show = show; + data.highlighted = false; + if (data.show) needShow = true; + } + } + } + } + return needShow; + } + + public static bool CheckDataHighlighted(Series series, string legendName, bool heighlight) + { + bool show = false; + foreach (var serie in series.list) + { + if (legendName.Equals(serie.name)) + { + serie.highlighted = heighlight; + } + else + { + foreach (var data in serie.data) + { + if (legendName.Equals(data.name)) + { + data.highlighted = heighlight; + if (data.highlighted) show = true; + } + } + } + } + return show; + } } } \ No newline at end of file diff --git a/Runtime/Helper/LegendHelper.cs.meta b/Runtime/Internal/Helper/LegendHelper.cs.meta similarity index 83% rename from Runtime/Helper/LegendHelper.cs.meta rename to Runtime/Internal/Helper/LegendHelper.cs.meta index 5f67fbd3..8d21df83 100644 --- a/Runtime/Helper/LegendHelper.cs.meta +++ b/Runtime/Internal/Helper/LegendHelper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 928a0ea2a67c74bdcad4f252830a7592 +guid: d03ce7a11ecde41b6930883612bf8f05 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Helper/SerieDataHelper.cs b/Runtime/Internal/Helper/SerieDataHelper.cs similarity index 100% rename from Runtime/Helper/SerieDataHelper.cs rename to Runtime/Internal/Helper/SerieDataHelper.cs diff --git a/Runtime/Helper/SerieDataHelper.cs.meta b/Runtime/Internal/Helper/SerieDataHelper.cs.meta similarity index 83% rename from Runtime/Helper/SerieDataHelper.cs.meta rename to Runtime/Internal/Helper/SerieDataHelper.cs.meta index 463728ec..b497cb52 100644 --- a/Runtime/Helper/SerieDataHelper.cs.meta +++ b/Runtime/Internal/Helper/SerieDataHelper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 0de4f692b6e2d4cdd9ef1946bffa895f +guid: e78d1b28fc61d4b1b995a1eca16cf3b6 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Helper/SerieHelper.cs b/Runtime/Internal/Helper/SerieHelper.cs similarity index 100% rename from Runtime/Helper/SerieHelper.cs rename to Runtime/Internal/Helper/SerieHelper.cs diff --git a/Runtime/Helper/SerieHelper.cs.meta b/Runtime/Internal/Helper/SerieHelper.cs.meta similarity index 83% rename from Runtime/Helper/SerieHelper.cs.meta rename to Runtime/Internal/Helper/SerieHelper.cs.meta index 39d6749c..1cd082c4 100644 --- a/Runtime/Helper/SerieHelper.cs.meta +++ b/Runtime/Internal/Helper/SerieHelper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f69933c37061c417d9cadd9e486e6785 +guid: e5c421b17fb6f45a283f4f57efce686f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Helper/SerieLabelHelper.cs b/Runtime/Internal/Helper/SerieLabelHelper.cs similarity index 100% rename from Runtime/Helper/SerieLabelHelper.cs rename to Runtime/Internal/Helper/SerieLabelHelper.cs diff --git a/Runtime/Helper/SerieLabelHelper.cs.meta b/Runtime/Internal/Helper/SerieLabelHelper.cs.meta similarity index 83% rename from Runtime/Helper/SerieLabelHelper.cs.meta rename to Runtime/Internal/Helper/SerieLabelHelper.cs.meta index 0cc0269d..a2e2a477 100644 --- a/Runtime/Helper/SerieLabelHelper.cs.meta +++ b/Runtime/Internal/Helper/SerieLabelHelper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d74ec0ba2845e409ca2e1c85a3814939 +guid: bbd57df98f6f145f299cf942b04229a4 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Internal/Helper/SeriesHelper.cs b/Runtime/Internal/Helper/SeriesHelper.cs new file mode 100644 index 00000000..cc8e9353 --- /dev/null +++ b/Runtime/Internal/Helper/SeriesHelper.cs @@ -0,0 +1,447 @@ +/******************************************/ +/* */ +/* Copyright (c) 2018 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/******************************************/ + +using System.Collections.Generic; +using UnityEngine; + +namespace XCharts +{ + internal static class SeriesHelper + { + public static bool IsNeedLabelUpdate(Series series) + { + foreach (var serie in series.list) + { + if (serie.label.vertsDirty) return true; + } + return false; + } + + public static bool IsLabelDirty(Series series) + { + if (series.labelDirty) return true; + foreach (var serie in series.list) + { + if (serie.label.componentDirty) return true; + } + return false; + } + + public static bool IsLegalLegendName(string name) + { + int numName = -1; + if (int.TryParse(name, out numName)) + { + if (numName >= 0 && numName < 100) return false; + } + return true; + } + + public static List GetLegalSerieNameList(Series series) + { + var list = new List(); + for (int n = 0; n < series.list.Count; n++) + { + var serie = series.GetSerie(n); + switch (serie.type) + { + case SerieType.Pie: + case SerieType.Radar: + case SerieType.Ring: + for (int i = 0; i < serie.data.Count; i++) + { + var dataName = serie.data[i].name; + if (!string.IsNullOrEmpty(dataName) && IsLegalLegendName(dataName) && !list.Contains(dataName)) + list.Add(dataName); + } + break; + default: + if (!string.IsNullOrEmpty(serie.name) && !list.Contains(serie.name) && IsLegalLegendName(serie.name)) + list.Add(serie.name); + break; + } + } + return list; + } + + /// + /// 获得所有系列名,不包含空名字。 + /// + /// + internal static void UpdateSerieNameList(Series series, ref List serieNameList) + { + serieNameList.Clear(); + for (int n = 0; n < series.list.Count; n++) + { + var serie = series.GetSerie(n); + switch (serie.type) + { + case SerieType.Pie: + case SerieType.Radar: + case SerieType.Ring: + for (int i = 0; i < serie.data.Count; i++) + { + if (string.IsNullOrEmpty(serie.data[i].name)) + serieNameList.Add(ChartCached.IntToStr(i)); + else if (!serieNameList.Contains(serie.data[i].name)) + serieNameList.Add(serie.data[i].name); + } + break; + default: + if (string.IsNullOrEmpty(serie.name)) + serieNameList.Add(ChartCached.IntToStr(n)); + else if (!serieNameList.Contains(serie.name)) + serieNameList.Add(serie.name); + break; + } + } + } + + /// + /// 同堆叠的serie是否有渐变色的。 + /// + /// + /// + internal static bool IsAnyGradientSerie(Series series, string stack) + { + if (string.IsNullOrEmpty(stack)) return false; + foreach (var serie in series.list) + { + if (serie.show && serie.areaStyle.show && stack.Equals(serie.stack)) + { + if (serie.areaStyle.color != serie.areaStyle.toColor + && !ChartHelper.IsClearColor(serie.areaStyle.toColor)) + return true; + } + } + return false; + } + + /// + /// 是否有需裁剪的serie。 + /// + /// + internal static bool IsAnyClipSerie(Series series) + { + foreach (var serie in series.list) + { + if (serie.clip) return true; + } + return false; + } + + internal static bool IsAnyUpdateAnimationSerie(Series series) + { + foreach (var serie in series.list) + { + if (serie.animation.enable && serie.animation.dataChangeEnable) + { + return true; + } + } + return false; + } + + /// + /// 获得上一个同堆叠且显示的serie。 + /// + /// + /// + internal static Serie GetLastStackSerie(Series series, Serie serie) + { + if (serie == null || string.IsNullOrEmpty(serie.stack)) return null; + for (int i = serie.index - 1; i >= 0; i--) + { + var temp = series.list[i]; + if (temp.show && serie.stack.Equals(temp.stack)) return temp; + } + return null; + } + + /// + /// 获得上一个同堆叠且显示的serie。 + /// + /// + /// + internal static Serie GetLastStackSerie(Series series, int index) + { + var serie = series.GetSerie(index); + return GetLastStackSerie(series, serie); + } + + /// + /// 是否由系列在用指定索引的axis + /// + /// + /// + internal static bool IsUsedAxisIndex(Series series, int axisIndex) + { + foreach (var serie in series.list) + { + if (serie.axisIndex == axisIndex) return true; + } + return false; + } + + private static HashSet _setForStack = new HashSet(); + /// + /// 是否由数据堆叠 + /// + /// + internal static bool IsStack(Series series) + { + _setForStack.Clear(); + foreach (var serie in series.list) + { + if (string.IsNullOrEmpty(serie.stack)) continue; + if (_setForStack.Contains(serie.stack)) return true; + else + { + _setForStack.Add(serie.stack); + } + } + return false; + } + + /// + /// 是否堆叠 + /// + /// + /// + /// + internal static bool IsStack(Series series, string stackName, SerieType type) + { + if (string.IsNullOrEmpty(stackName)) return false; + int count = 0; + foreach (var serie in series.list) + { + if (serie.show && serie.type == type) + { + if (stackName.Equals(serie.stack)) count++; + if (count >= 2) return true; + } + } + return false; + } + + /// + /// 是否时百分比堆叠 + /// + /// + /// + internal static bool IsPercentStack(Series series, SerieType type) + { + int count = 0; + bool isPercentStack = false; + foreach (var serie in series.list) + { + if (serie.show && serie.type == type) + { + if (!string.IsNullOrEmpty(serie.stack)) + { + count++; + if (serie.barPercentStack) isPercentStack = true; + } + if (count >= 2 && isPercentStack) return true; + } + } + return false; + } + + /// + /// 是否时百分比堆叠 + /// + /// + /// + /// + internal static bool IsPercentStack(Series series, string stackName, SerieType type) + { + if (string.IsNullOrEmpty(stackName)) return false; + int count = 0; + bool isPercentStack = false; + foreach (var serie in series.list) + { + if (serie.show && serie.type == type) + { + if (stackName.Equals(serie.stack)) + { + count++; + if (serie.barPercentStack) isPercentStack = true; + } + if (count >= 2 && isPercentStack) return true; + } + } + return false; + } + + private static Dictionary sets = new Dictionary(); + /// + /// 获得堆叠系列列表 + /// + /// + /// + internal static void GetStackSeries(Series series, ref Dictionary> stackSeries) + { + int count = 0; + var serieCount = series.list.Count; + sets.Clear(); + if (stackSeries == null) + { + stackSeries = new Dictionary>(serieCount); + } + else + { + foreach (var kv in stackSeries) + { + kv.Value.Clear(); + } + } + for (int i = 0; i < serieCount; i++) + { + var serie = series.GetSerie(i); + serie.index = i; + if (string.IsNullOrEmpty(serie.stack)) + { + if (!stackSeries.ContainsKey(count)) + stackSeries[count] = new List(serieCount); + stackSeries[count].Add(serie); + count++; + } + else + { + if (!sets.ContainsKey(serie.stack)) + { + sets.Add(serie.stack, count); + if (!stackSeries.ContainsKey(count)) + stackSeries[count] = new List(serieCount); + stackSeries[count].Add(serie); + count++; + } + else + { + int stackIndex = sets[serie.stack]; + stackSeries[stackIndex].Add(serie); + } + } + } + } + + /// + /// 获得维度X的最大最小值 + /// + /// + /// + /// + /// + internal static void GetXMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis, + bool inverse, out float minVaule, out float maxValue) + { + GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue); + } + + /// + /// 获得维度Y的最大最小值 + /// + /// + /// + /// + /// + internal static void GetYMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis, + bool inverse, out float minVaule, out float maxValue) + { + GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue); + } + + private static Dictionary> _stackSeriesForMinMax = new Dictionary>(); + private static Dictionary _serieTotalValueForMinMax = new Dictionary(); + internal static void GetMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis, + bool inverse, bool yValue, out float minVaule, out float maxValue) + { + float min = int.MaxValue; + float max = int.MinValue; + var isPercentStack = SeriesHelper.IsPercentStack(series, SerieType.Bar); + if (!SeriesHelper.IsStack(series) || (isValueAxis && !yValue)) + { + for (int i = 0; i < series.list.Count; i++) + { + var serie = series.GetSerie(i); + if (serie.axisIndex != axisIndex) continue; + + if (series.IsActive(i)) + { + if (isPercentStack && SeriesHelper.IsPercentStack(series, serie.name, SerieType.Bar)) + { + if (100 > max) max = 100; + if (0 < min) min = 0; + } + else + { + var showData = serie.GetDataList(dataZoom); + foreach (var data in showData) + { + var currData = data.GetData(yValue ? 1 : 0, inverse); + if (currData > max) max = currData; + if (currData < min) min = currData; + } + } + } + } + } + else + { + SeriesHelper.GetStackSeries(series, ref _stackSeriesForMinMax); + foreach (var ss in _stackSeriesForMinMax) + { + _serieTotalValueForMinMax.Clear(); + for (int i = 0; i < ss.Value.Count; i++) + { + var serie = ss.Value[i]; + if (serie.axisIndex != axisIndex || !series.IsActive(i)) continue; + var showData = serie.GetDataList(dataZoom); + if (SeriesHelper.IsPercentStack(series, serie.stack, SerieType.Bar)) + { + for (int j = 0; j < showData.Count; j++) + { + _serieTotalValueForMinMax[j] = 100; + } + } + else + { + for (int j = 0; j < showData.Count; j++) + { + if (!_serieTotalValueForMinMax.ContainsKey(j)) + _serieTotalValueForMinMax[j] = 0; + var currData = (yValue ? showData[j].GetData(1) : showData[j].GetData(0)); + if (inverse) currData = -currData; + _serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData; + } + } + } + float tmax = int.MinValue; + float tmin = int.MaxValue; + foreach (var tt in _serieTotalValueForMinMax) + { + if (tt.Value > tmax) tmax = tt.Value; + if (tt.Value < tmin) tmin = tt.Value; + } + if (tmax > max) max = tmax; + if (tmin < min) min = tmin; + } + } + if (max == int.MinValue && min == int.MaxValue) + { + minVaule = 0; + maxValue = 0; + } + else + { + minVaule = min > 1 ? Mathf.FloorToInt(min) : min; + maxValue = max > 1 ? Mathf.CeilToInt(max) : max; + } + } + } +} \ No newline at end of file diff --git a/Runtime/Internal/Helper/SeriesHelper.cs.meta b/Runtime/Internal/Helper/SeriesHelper.cs.meta new file mode 100644 index 00000000..5ad2501f --- /dev/null +++ b/Runtime/Internal/Helper/SeriesHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e7411a13172764cf89b10e643089c832 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Helper/TitleHelper.cs b/Runtime/Internal/Helper/TitleHelper.cs similarity index 100% rename from Runtime/Helper/TitleHelper.cs rename to Runtime/Internal/Helper/TitleHelper.cs diff --git a/Runtime/Helper/TitleHelper.cs.meta b/Runtime/Internal/Helper/TitleHelper.cs.meta similarity index 83% rename from Runtime/Helper/TitleHelper.cs.meta rename to Runtime/Internal/Helper/TitleHelper.cs.meta index 8328b249..67f3117c 100644 --- a/Runtime/Helper/TitleHelper.cs.meta +++ b/Runtime/Internal/Helper/TitleHelper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8c96205317b864d6c8c08ec45c27933c +guid: e22859d8021f6491f8ee08339b71e577 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Helper/TitleStyleHelper.cs b/Runtime/Internal/Helper/TitleStyleHelper.cs similarity index 100% rename from Runtime/Helper/TitleStyleHelper.cs rename to Runtime/Internal/Helper/TitleStyleHelper.cs diff --git a/Runtime/Helper/TitleStyleHelper.cs.meta b/Runtime/Internal/Helper/TitleStyleHelper.cs.meta similarity index 83% rename from Runtime/Helper/TitleStyleHelper.cs.meta rename to Runtime/Internal/Helper/TitleStyleHelper.cs.meta index afee7009..5b0e40c0 100644 --- a/Runtime/Helper/TitleStyleHelper.cs.meta +++ b/Runtime/Internal/Helper/TitleStyleHelper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 76af3a33fe0b643e4ac6e875864233c0 +guid: 35fa58aecc0f4414e8a2f03195b66175 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Helper/TooltipHelper.cs b/Runtime/Internal/Helper/TooltipHelper.cs similarity index 100% rename from Runtime/Helper/TooltipHelper.cs rename to Runtime/Internal/Helper/TooltipHelper.cs diff --git a/Runtime/Helper/TooltipHelper.cs.meta b/Runtime/Internal/Helper/TooltipHelper.cs.meta similarity index 83% rename from Runtime/Helper/TooltipHelper.cs.meta rename to Runtime/Internal/Helper/TooltipHelper.cs.meta index bb7eab8b..ca8bc73d 100644 --- a/Runtime/Helper/TooltipHelper.cs.meta +++ b/Runtime/Internal/Helper/TooltipHelper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: de1595793312142b4bbe2d1081eecf68 +guid: f0fa1b19683a8424bb335802de5c9726 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Helper/VisualMapHelper.cs b/Runtime/Internal/Helper/VisualMapHelper.cs similarity index 100% rename from Runtime/Helper/VisualMapHelper.cs rename to Runtime/Internal/Helper/VisualMapHelper.cs diff --git a/Runtime/Helper/VisualMapHelper.cs.meta b/Runtime/Internal/Helper/VisualMapHelper.cs.meta similarity index 83% rename from Runtime/Helper/VisualMapHelper.cs.meta rename to Runtime/Internal/Helper/VisualMapHelper.cs.meta index 8ed26396..2183dfde 100644 --- a/Runtime/Helper/VisualMapHelper.cs.meta +++ b/Runtime/Internal/Helper/VisualMapHelper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 947fc87a63dec45f8b27ade5f0d050c4 +guid: 15e5106bd46f5484596429d512f6af5d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Interface.meta b/Runtime/Internal/Interface.meta similarity index 62% rename from Runtime/Interface.meta rename to Runtime/Internal/Interface.meta index b3e492a1..1c107351 100644 --- a/Runtime/Interface.meta +++ b/Runtime/Internal/Interface.meta @@ -1,8 +1,6 @@ fileFormatVersion: 2 -guid: 253203a243755c744880211dbbc988a2 +guid: 4e4276d289bef4136b22e6cc8b207d99 folderAsset: yes -timeCreated: 1554979427 -licenseType: Free DefaultImporter: externalObjects: {} userData: diff --git a/Runtime/Interface/IJsonData.cs b/Runtime/Internal/Interface/IJsonData.cs similarity index 100% rename from Runtime/Interface/IJsonData.cs rename to Runtime/Internal/Interface/IJsonData.cs diff --git a/Runtime/Interface/IJsonData.cs.meta b/Runtime/Internal/Interface/IJsonData.cs.meta similarity index 100% rename from Runtime/Interface/IJsonData.cs.meta rename to Runtime/Internal/Interface/IJsonData.cs.meta diff --git a/Runtime/Interface/IPropertyChanged.cs b/Runtime/Internal/Interface/IPropertyChanged.cs similarity index 100% rename from Runtime/Interface/IPropertyChanged.cs rename to Runtime/Internal/Interface/IPropertyChanged.cs diff --git a/Runtime/Interface/IPropertyChanged.cs.meta b/Runtime/Internal/Interface/IPropertyChanged.cs.meta similarity index 100% rename from Runtime/Interface/IPropertyChanged.cs.meta rename to Runtime/Internal/Interface/IPropertyChanged.cs.meta diff --git a/Runtime/Object.meta b/Runtime/Internal/Object.meta similarity index 77% rename from Runtime/Object.meta rename to Runtime/Internal/Object.meta index c0b6ac80..011588c7 100644 --- a/Runtime/Object.meta +++ b/Runtime/Internal/Object.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 05690857746244b0ebec49f0b58b0f23 +guid: 3d225ec4fe992405d91714722649cc93 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Object/ChartObject.cs b/Runtime/Internal/Object/ChartObject.cs similarity index 100% rename from Runtime/Object/ChartObject.cs rename to Runtime/Internal/Object/ChartObject.cs diff --git a/Runtime/Object/ChartObject.cs.meta b/Runtime/Internal/Object/ChartObject.cs.meta similarity index 100% rename from Runtime/Object/ChartObject.cs.meta rename to Runtime/Internal/Object/ChartObject.cs.meta diff --git a/Runtime/Object/LabelObject.cs b/Runtime/Internal/Object/LabelObject.cs similarity index 100% rename from Runtime/Object/LabelObject.cs rename to Runtime/Internal/Object/LabelObject.cs diff --git a/Runtime/Object/LabelObject.cs.meta b/Runtime/Internal/Object/LabelObject.cs.meta similarity index 100% rename from Runtime/Object/LabelObject.cs.meta rename to Runtime/Internal/Object/LabelObject.cs.meta diff --git a/Runtime/Internal/LegendItem.cs b/Runtime/Internal/Object/LegendItem.cs similarity index 100% rename from Runtime/Internal/LegendItem.cs rename to Runtime/Internal/Object/LegendItem.cs diff --git a/Runtime/Internal/LegendItem.cs.meta b/Runtime/Internal/Object/LegendItem.cs.meta similarity index 83% rename from Runtime/Internal/LegendItem.cs.meta rename to Runtime/Internal/Object/LegendItem.cs.meta index 483d22bd..e7a52043 100644 --- a/Runtime/Internal/LegendItem.cs.meta +++ b/Runtime/Internal/Object/LegendItem.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3452002928282423f988cd5c5ecf318a +guid: 3e5abcb8f339f41f5b3680ecdab67509 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Internal/Pools.meta b/Runtime/Internal/Pools.meta new file mode 100644 index 00000000..49e7df6a --- /dev/null +++ b/Runtime/Internal/Pools.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 576ce681815d348d0a2abbbadf3dd9f7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/AxisPool.cs b/Runtime/Internal/Pools/AxisPool.cs similarity index 100% rename from Runtime/Internal/AxisPool.cs rename to Runtime/Internal/Pools/AxisPool.cs diff --git a/Runtime/Internal/AxisPool.cs.meta b/Runtime/Internal/Pools/AxisPool.cs.meta similarity index 83% rename from Runtime/Internal/AxisPool.cs.meta rename to Runtime/Internal/Pools/AxisPool.cs.meta index 5514a341..1128203d 100644 --- a/Runtime/Internal/AxisPool.cs.meta +++ b/Runtime/Internal/Pools/AxisPool.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6d6006e13d2c640b9909e4d4121c01ea +guid: 3a709ca44e9a445bd86bde1bbfae80de MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Internal/ListPool.cs b/Runtime/Internal/Pools/ListPool.cs similarity index 100% rename from Runtime/Internal/ListPool.cs rename to Runtime/Internal/Pools/ListPool.cs diff --git a/Runtime/Internal/ListPool.cs.meta b/Runtime/Internal/Pools/ListPool.cs.meta similarity index 83% rename from Runtime/Internal/ListPool.cs.meta rename to Runtime/Internal/Pools/ListPool.cs.meta index 13562c64..7807cc92 100644 --- a/Runtime/Internal/ListPool.cs.meta +++ b/Runtime/Internal/Pools/ListPool.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 359b8b077c5954701a132fe69eb8ba9c +guid: 02c30457469c746dc96f00f24cb6e1c6 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Internal/ObjectPool.cs b/Runtime/Internal/Pools/ObjectPool.cs similarity index 100% rename from Runtime/Internal/ObjectPool.cs rename to Runtime/Internal/Pools/ObjectPool.cs diff --git a/Runtime/Internal/ObjectPool.cs.meta b/Runtime/Internal/Pools/ObjectPool.cs.meta similarity index 83% rename from Runtime/Internal/ObjectPool.cs.meta rename to Runtime/Internal/Pools/ObjectPool.cs.meta index b99ea825..58927caf 100644 --- a/Runtime/Internal/ObjectPool.cs.meta +++ b/Runtime/Internal/Pools/ObjectPool.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a543f22be703f4d58b47fa6d343581c8 +guid: 09e67988253cb4f568b82d52b4113797 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Internal/SerieDataPool.cs b/Runtime/Internal/Pools/SerieDataPool.cs similarity index 100% rename from Runtime/Internal/SerieDataPool.cs rename to Runtime/Internal/Pools/SerieDataPool.cs diff --git a/Runtime/Internal/SerieDataPool.cs.meta b/Runtime/Internal/Pools/SerieDataPool.cs.meta similarity index 83% rename from Runtime/Internal/SerieDataPool.cs.meta rename to Runtime/Internal/Pools/SerieDataPool.cs.meta index 3e569777..5bd47406 100644 --- a/Runtime/Internal/SerieDataPool.cs.meta +++ b/Runtime/Internal/Pools/SerieDataPool.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6bd0d723595ba485dbe696491cf978f3 +guid: faf4da15b01d74648bd13f73125e27bd MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Internal/SerieLabelPool.cs b/Runtime/Internal/Pools/SerieLabelPool.cs similarity index 100% rename from Runtime/Internal/SerieLabelPool.cs rename to Runtime/Internal/Pools/SerieLabelPool.cs diff --git a/Runtime/Internal/SerieLabelPool.cs.meta b/Runtime/Internal/Pools/SerieLabelPool.cs.meta similarity index 83% rename from Runtime/Internal/SerieLabelPool.cs.meta rename to Runtime/Internal/Pools/SerieLabelPool.cs.meta index 2e35ce5e..8d5c7528 100644 --- a/Runtime/Internal/SerieLabelPool.cs.meta +++ b/Runtime/Internal/Pools/SerieLabelPool.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 340f267fa46e74d0bbbb0b75a20bd708 +guid: e960aeb14c09844e3bdcdc4138af0761 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/PieChart.cs b/Runtime/PieChart.cs index 9049559b..94fdabda 100644 --- a/Runtime/PieChart.cs +++ b/Runtime/PieChart.cs @@ -476,7 +476,7 @@ namespace XCharts protected override void OnLegendButtonClick(int index, string legendName, bool show) { - CheckDataShow(legendName, show); + LegendHelper.CheckDataShow(m_Series, legendName, show); UpdateLegendColor(legendName, show); RefreshChart(); } @@ -484,14 +484,14 @@ namespace XCharts protected override void OnLegendButtonEnter(int index, string legendName) { m_IsEnterLegendButtom = true; - CheckDataHighlighted(legendName, true); + LegendHelper.CheckDataHighlighted(m_Series, legendName, true); RefreshChart(); } protected override void OnLegendButtonExit(int index, string legendName) { m_IsEnterLegendButtom = false; - CheckDataHighlighted(legendName, false); + LegendHelper.CheckDataHighlighted(m_Series, legendName, false); RefreshChart(); } diff --git a/Runtime/RadarChart.cs b/Runtime/RadarChart.cs index 58ae8486..c7d1fab2 100644 --- a/Runtime/RadarChart.cs +++ b/Runtime/RadarChart.cs @@ -25,7 +25,7 @@ namespace XCharts protected override void OnLegendButtonClick(int index, string legendName, bool show) { - CheckDataShow(legendName, show); + LegendHelper.CheckDataShow(m_Series, legendName, show); UpdateLegendColor(legendName, show); RefreshChart(); } @@ -33,14 +33,14 @@ namespace XCharts protected override void OnLegendButtonEnter(int index, string legendName) { m_IsEnterLegendButtom = true; - CheckDataHighlighted(legendName, true); + LegendHelper.CheckDataHighlighted(m_Series, legendName, true); RefreshChart(); } protected override void OnLegendButtonExit(int index, string legendName) { m_IsEnterLegendButtom = false; - CheckDataHighlighted(legendName, false); + LegendHelper.CheckDataHighlighted(m_Series, legendName, false); RefreshChart(); } @@ -320,7 +320,7 @@ namespace XCharts } if (serie.lineStyle.show) { - DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor); + ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor); } startPoint = toPoint; } @@ -332,7 +332,7 @@ namespace XCharts } if (serie.lineStyle.show) { - DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor); + ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor); } if (serie.symbol.type != SerieSymbolType.None) { @@ -453,7 +453,7 @@ namespace XCharts } if (serie.lineStyle.show) { - DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor); + ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor); } startPoint = toPoint; } @@ -466,7 +466,7 @@ namespace XCharts } if (serie.lineStyle.show && j == endIndex) { - DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor); + ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor); } } if (serie.symbol.type != SerieSymbolType.None) @@ -565,7 +565,7 @@ namespace XCharts } if (radar.splitLine.NeedShow(i)) { - DrawLineStyle(vh, radar.splitLine.lineStyle, p2, p3, lineColor); + ChartDrawer.DrawLineStyle(vh, radar.splitLine.lineStyle, p2, p3, lineColor); } p1 = p4; p2 = p3; @@ -579,7 +579,7 @@ namespace XCharts p.y + outsideRadius * Mathf.Cos(currAngle)); if (radar.splitLine.show) { - DrawLineStyle(vh, radar.splitLine.lineStyle, p, p3, lineColor); + ChartDrawer.DrawLineStyle(vh, radar.splitLine.lineStyle, p, p3, lineColor); } } } diff --git a/Runtime/RingChart.cs b/Runtime/RingChart.cs index 8a5f2339..92500915 100644 --- a/Runtime/RingChart.cs +++ b/Runtime/RingChart.cs @@ -238,7 +238,7 @@ namespace XCharts protected override void OnLegendButtonClick(int index, string legendName, bool show) { - CheckDataShow(legendName, show); + LegendHelper.CheckDataShow(m_Series, legendName, show); UpdateLegendColor(legendName, show); RefreshChart(); } @@ -246,14 +246,14 @@ namespace XCharts protected override void OnLegendButtonEnter(int index, string legendName) { m_IsEnterLegendButtom = true; - CheckDataHighlighted(legendName, true); + LegendHelper.CheckDataHighlighted(m_Series, legendName, true); RefreshChart(); } protected override void OnLegendButtonExit(int index, string legendName) { m_IsEnterLegendButtom = false; - CheckDataHighlighted(legendName, false); + LegendHelper.CheckDataHighlighted(m_Series, legendName, false); RefreshChart(); } diff --git a/Runtime/Utility/ChartDrawer.cs b/Runtime/Utility/ChartDrawer.cs index adc16c0f..0b04f638 100644 --- a/Runtime/Utility/ChartDrawer.cs +++ b/Runtime/Utility/ChartDrawer.cs @@ -1038,5 +1038,96 @@ namespace XCharts } } } + + public static void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, + float tickness, Vector3 pos, Color color, Color toColor, float gap, float[] cornerRadius, + Color backgroundColor, float smoothness) + { + switch (type) + { + case SerieSymbolType.None: + break; + case SerieSymbolType.Circle: + if (gap > 0) + { + ChartDrawer.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, color, toColor, smoothness); + } + else + { + ChartDrawer.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness); + } + break; + case SerieSymbolType.EmptyCircle: + if (gap > 0) + { + ChartDrawer.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness); + ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, toColor, backgroundColor, smoothness); + } + else + { + ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, toColor, backgroundColor, smoothness); + } + break; + case SerieSymbolType.Rect: + if (gap > 0) + { + ChartDrawer.DrawPolygon(vh, pos, symbolSize + gap, backgroundColor); + ChartDrawer.DrawPolygon(vh, pos, symbolSize, color, toColor); + } + else + { + //ChartDrawer.DrawPolygon(vh, pos, symbolSize, color, toColor); + ChartDrawer.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, 0, cornerRadius); + } + break; + case SerieSymbolType.Triangle: + if (gap > 0) + { + ChartDrawer.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor); + ChartDrawer.DrawTriangle(vh, pos, symbolSize, color, toColor); + } + else + { + ChartDrawer.DrawTriangle(vh, pos, symbolSize, color, toColor); + } + break; + case SerieSymbolType.Diamond: + if (gap > 0) + { + ChartDrawer.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor); + ChartDrawer.DrawDiamond(vh, pos, symbolSize, color, toColor); + } + else + { + ChartDrawer.DrawDiamond(vh, pos, symbolSize, color, toColor); + } + break; + } + } + + public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle, + Vector3 startPos, Vector3 endPos, Color color) + { + var type = lineStyle.type; + var width = lineStyle.width; + switch (type) + { + case LineStyle.Type.Dashed: + ChartDrawer.DrawDashLine(vh, startPos, endPos, width, color); + break; + case LineStyle.Type.Dotted: + ChartDrawer.DrawDotLine(vh, startPos, endPos, width, color); + break; + case LineStyle.Type.Solid: + ChartDrawer.DrawLine(vh, startPos, endPos, width, color); + break; + case LineStyle.Type.DashDot: + ChartDrawer.DrawDashDotLine(vh, startPos, endPos, width, color); + break; + case LineStyle.Type.DashDotDot: + ChartDrawer.DrawDashDotDotLine(vh, startPos, endPos, width, color); + break; + } + } } } \ No newline at end of file diff --git a/Runtime/Internal/PropertyUtility.cs b/Runtime/Utility/PropertyUtility.cs similarity index 100% rename from Runtime/Internal/PropertyUtility.cs rename to Runtime/Utility/PropertyUtility.cs diff --git a/Runtime/Internal/PropertyUtility.cs.meta b/Runtime/Utility/PropertyUtility.cs.meta similarity index 83% rename from Runtime/Internal/PropertyUtility.cs.meta rename to Runtime/Utility/PropertyUtility.cs.meta index 737fe86e..8b1ef5db 100644 --- a/Runtime/Internal/PropertyUtility.cs.meta +++ b/Runtime/Utility/PropertyUtility.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 820c154b7b7d848cdaf52e68c369dd86 +guid: deeae684afb4a40cea4b11461d9692e8 MonoImporter: externalObjects: {} serializedVersion: 2