9 using System.Collections.Generic;
84 [SerializeField]
protected bool m_Show =
true;
85 [SerializeField]
protected AxisType m_Type;
87 [SerializeField]
protected int m_GridIndex;
88 [SerializeField]
protected int m_PolarIndex;
90 [SerializeField]
protected float m_Offset;
91 [SerializeField]
protected float m_Min;
92 [SerializeField]
protected float m_Max;
93 [SerializeField]
protected int m_SplitNumber = 5;
94 [SerializeField]
protected float m_Interval = 0;
95 [SerializeField]
protected bool m_BoundaryGap =
true;
96 [SerializeField]
protected int m_MaxCache = 0;
97 [SerializeField]
protected float m_LogBase = 10;
98 [SerializeField]
protected bool m_LogBaseE =
false;
99 [SerializeField]
protected int m_CeilRate = 0;
100 [SerializeField]
protected bool m_Inverse =
false;
101 [SerializeField]
private bool m_Clockwise =
true;
102 [SerializeField]
private bool m_InsertDataToHead;
104 [SerializeField]
protected List<Sprite> m_Icons =
new List<Sprite>();
105 [SerializeField]
protected List<string> m_Data =
new List<string>();
113 [NonSerialized]
private double m_MinMaxValueRange;
114 [NonSerialized]
private bool m_NeedUpdateFilterData;
122 get {
return m_Show; }
123 set {
if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
131 get {
return m_Type; }
132 set {
if (PropertyUtil.SetStruct(ref m_Type, value)) SetAllDirty(); }
140 get {
return m_MinMaxType; }
141 set {
if (PropertyUtil.SetStruct(ref m_MinMaxType, value)) SetAllDirty(); }
149 get {
return m_GridIndex; }
150 set {
if (PropertyUtil.SetStruct(ref m_GridIndex, value)) SetAllDirty(); }
158 get {
return m_PolarIndex; }
159 set {
if (PropertyUtil.SetStruct(ref m_PolarIndex, value)) SetAllDirty(); }
167 get {
return m_Position; }
168 set {
if (PropertyUtil.SetStruct(ref m_Position, value)) SetAllDirty(); }
176 get {
return m_Offset; }
177 set {
if (PropertyUtil.SetStruct(ref m_Offset, value)) SetAllDirty(); }
185 get {
return m_Min; }
186 set {
if (PropertyUtil.SetStruct(ref m_Min, value)) SetAllDirty(); }
194 get {
return m_Max; }
195 set {
if (PropertyUtil.SetStruct(ref m_Max, value)) SetAllDirty(); }
203 get {
return m_SplitNumber; }
204 set {
if (PropertyUtil.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); }
212 get {
return m_Interval; }
213 set {
if (PropertyUtil.SetStruct(ref m_Interval, value)) SetAllDirty(); }
221 get {
return IsCategory() ? m_BoundaryGap :
false; }
222 set {
if (PropertyUtil.SetStruct(ref m_BoundaryGap, value)) SetAllDirty(); }
230 get {
return m_LogBase; }
233 if (value <= 0 || value == 1) value = 10;
234 if (PropertyUtil.SetStruct(ref m_LogBase, value)) SetAllDirty();
243 get {
return m_LogBaseE; }
244 set {
if (PropertyUtil.SetStruct(ref m_LogBaseE, value)) SetAllDirty(); }
253 get {
return m_MaxCache; }
254 set {
if (PropertyUtil.SetStruct(ref m_MaxCache, value < 0 ? 0 : value)) SetAllDirty(); }
262 get {
return m_CeilRate; }
263 set {
if (PropertyUtil.SetStruct(ref m_CeilRate, value < 0 ? 0 : value)) SetAllDirty(); }
271 get {
return m_Inverse; }
272 set {
if (m_Type ==
AxisType.Value && PropertyUtil.SetStruct(ref m_Inverse, value)) SetAllDirty(); }
280 get {
return m_Clockwise; }
281 set {
if (PropertyUtil.SetStruct(ref m_Clockwise, value)) SetAllDirty(); }
287 public List<string>
data
289 get {
return m_Data; }
290 set {
if (value !=
null) { m_Data = value; SetAllDirty(); } }
295 public List<Sprite>
icons
297 get {
return m_Icons; }
298 set {
if (value !=
null) { m_Icons = value; SetAllDirty(); } }
306 get {
return m_AxisLine; }
307 set {
if (value !=
null) { m_AxisLine = value; SetVerticesDirty(); } }
315 get {
return m_AxisName; }
316 set {
if (value !=
null) { m_AxisName = value; SetComponentDirty(); } }
324 get {
return m_AxisTick; }
325 set {
if (value !=
null) { m_AxisTick = value; SetVerticesDirty(); } }
333 get {
return m_AxisLabel; }
334 set {
if (value !=
null) { m_AxisLabel = value; SetComponentDirty(); } }
342 get {
return m_SplitLine; }
343 set {
if (value !=
null) { m_SplitLine = value; SetVerticesDirty(); } }
351 get {
return m_SplitArea; }
352 set {
if (value !=
null) { m_SplitArea = value; SetVerticesDirty(); } }
360 get {
return m_InsertDataToHead; }
361 set {
if (PropertyUtil.SetStruct(ref m_InsertDataToHead, value)) SetAllDirty(); }
368 get {
return m_IconStyle; }
369 set {
if (PropertyUtil.SetClass(ref m_IconStyle, value)) SetAllDirty(); }
371 public override bool vertsDirty
375 public override bool componentDirty
379 public override void ClearComponentDirty()
381 base.ClearComponentDirty();
386 public override void ClearVerticesDirty()
388 base.ClearVerticesDirty();
394 public int index {
get;
internal set; }
395 public List<ChartLabel> runtimeAxisLabelList {
get {
return m_AxisLabelList; }
set { m_AxisLabelList = value; } }
402 get {
return m_RuntimeMinValue; }
405 m_RuntimeMinValue = value;
406 m_RuntimeLastMinValue = value;
407 m_RuntimeMinValueUpdateTime = Time.time;
408 m_RuntimeMinValueChanged =
true;
417 get {
return m_RuntimeMaxValue; }
420 m_RuntimeMaxValue = value;
421 m_RuntimeLastMaxValue = value;
422 m_RuntimeMaxValueUpdateTime = Time.time;
423 m_RuntimeMaxValueChanged =
false;
438 public bool runtimeLastCheckInverse {
get;
set; }
439 public double runtimeMinMaxRange {
get {
return m_MinMaxValueRange; }
set { m_MinMaxValueRange = value; } }
440 public List<string> runtimeData {
get {
return m_RuntimeData; } }
441 public float runtimeScaleWidth {
get;
internal set; }
442 private int filterStart;
443 private int filterEnd;
444 private int filterMinShow;
445 private List<string> filterData;
446 private List<ChartLabel> m_AxisLabelList =
new List<ChartLabel>();
447 private GameObject m_TooltipLabel;
448 private ChartText m_TooltipLabelText;
449 private RectTransform m_TooltipLabelRect;
450 private double m_RuntimeMinValue;
451 private double m_RuntimeLastMinValue;
452 private bool m_RuntimeMinValueChanged;
453 private float m_RuntimeMinValueUpdateTime;
454 private double m_RuntimeMaxValue;
455 private double m_RuntimeLastMaxValue;
456 private bool m_RuntimeMaxValueChanged;
457 private float m_RuntimeMaxValueUpdateTime;
458 private bool m_RuntimeMinValueFirstChanged =
true;
459 private bool m_RuntimeMaxValueFirstChanged =
true;
460 protected List<string> m_RuntimeData =
new List<string>();
464 var axis =
new Axis();
486 axis.icons =
new List<Sprite>();
487 axis.data =
new List<string>();
488 ChartHelper.CopyList(axis.data,
data);
492 public override void SetComponentDirty()
494 m_NeedUpdateFilterData =
true;
495 base.SetComponentDirty();
498 public void Copy(Axis axis)
521 ChartHelper.CopyList(
data, axis.data);
522 ChartHelper.CopyList<Sprite>(
icons, axis.icons);
532 m_RuntimeData.Clear();
571 public void SetNeedUpdateFilterData()
573 m_NeedUpdateFilterData =
true;
586 m_NeedUpdateFilterData =
true;
587 m_Data.RemoveAt(m_InsertDataToHead ? m_Data.Count - 1 : 0);
590 if (m_InsertDataToHead) m_Data.Insert(0, category);
591 else m_Data.Add(category);
602 if (index >= 0 && index < m_Data.Count)
604 m_Data[index] = category;
619 m_Icons.RemoveAt(m_InsertDataToHead ? m_Icons.Count - 1 : 0);
622 if (m_InsertDataToHead) m_Icons.Insert(0, icon);
623 else m_Icons.Add(icon);
634 if (index >= 0 && index < m_Icons.Count)
636 m_Icons[index] = icon;
648 if (index >= 0 && index < m_Data.Count)
649 return m_Data[index];
662 var showData = GetDataList(dataZoom);
663 if (index >= 0 && index < showData.Count)
664 return showData[index];
669 public Sprite GetIcon(
int index)
671 if (index >= 0 && index < m_Icons.Count)
672 return m_Icons[index];
682 internal List<string> GetDataList(DataZoom dataZoom)
684 if (dataZoom !=
null && dataZoom.enable && dataZoom.IsContainsAxis(
this))
686 UpdateFilterData(dataZoom);
691 return m_Data.Count > 0 ? m_Data : m_RuntimeData;
695 internal List<string> GetDataList()
697 return m_Data.Count > 0 ? m_Data : m_RuntimeData;
700 private List<string> emptyFliter =
new List<string>();
705 internal void UpdateFilterData(DataZoom dataZoom)
707 if (dataZoom !=
null && dataZoom.enable && dataZoom.IsContainsAxis(
this))
709 var
data = GetDataList();
710 var range = Mathf.RoundToInt(
data.Count * (dataZoom.end - dataZoom.start) / 100);
711 if (range <= 0) range = 1;
712 int start = 0, end = 0;
713 if (dataZoom.runtimeInvert)
715 end = Mathf.CeilToInt(
data.Count * dataZoom.end / 100);
717 if (start < 0) start = 0;
721 start = Mathf.FloorToInt(
data.Count * dataZoom.start / 100);
723 if (end >
data.Count) end =
data.Count;
725 if (start != filterStart || end != filterEnd || dataZoom.minShowNum != filterMinShow || m_NeedUpdateFilterData)
729 filterMinShow = dataZoom.minShowNum;
730 m_NeedUpdateFilterData =
false;
733 if (range < dataZoom.minShowNum)
735 if (dataZoom.minShowNum >
data.Count) range =
data.Count;
736 else range = dataZoom.minShowNum;
738 filterData =
data.GetRange(start, range);
747 filterData = emptyFliter;
757 internal int GetDataNumber(DataZoom dataZoom)
759 return GetDataList(dataZoom).Count;
766 internal void UpdateLabelText(
float coordinateWidth, DataZoom dataZoom,
bool forcePercent,
float duration)
768 var minValue = GetCurrMinValue(duration);
769 var maxValue = GetCurrMaxValue(duration);
770 for (
int i = 0; i < runtimeAxisLabelList.Count; i++)
772 if (runtimeAxisLabelList[i] !=
null)
774 var text = AxisHelper.GetLabelName(
this, coordinateWidth, i, minValue, maxValue, dataZoom, forcePercent);
775 runtimeAxisLabelList[i].SetText(text);
780 internal void SetTooltipLabel(GameObject label)
782 m_TooltipLabel = label;
783 m_TooltipLabelRect = label.GetComponent<RectTransform>();
784 m_TooltipLabelText =
new ChartText(label);
785 ChartHelper.SetActive(m_TooltipLabel,
true);
788 internal void SetTooltipLabelColor(Color bgColor, Color textColor)
790 m_TooltipLabel.GetComponent<Image>().color = bgColor;
791 m_TooltipLabelText.SetColor(textColor);
794 internal void SetTooltipLabelActive(
bool flag)
796 if (m_TooltipLabel ==
null)
return;
797 ChartHelper.SetActive(m_TooltipLabel, flag);
800 internal void UpdateTooptipLabelText(
string text)
802 if (m_TooltipLabelText !=
null)
804 m_TooltipLabelText.SetText(text);
805 m_TooltipLabelRect.sizeDelta =
new Vector2(m_TooltipLabelText.GetPreferredWidth() + 8,
806 m_TooltipLabelText.GetPreferredHeight() + 8);
810 internal void UpdateTooltipLabelPos(Vector2 pos)
814 m_TooltipLabel.transform.localPosition = pos;
818 internal void UpdateMinValue(
double value,
bool check)
820 if (value != m_RuntimeMaxValue)
822 if (check && Application.isPlaying)
824 if (m_RuntimeMinValueFirstChanged)
826 m_RuntimeMinValueFirstChanged =
false;
830 m_RuntimeLastMinValue = m_RuntimeMinValue;
831 m_RuntimeMinValueChanged =
true;
832 m_RuntimeMinValueUpdateTime = Time.time;
834 m_RuntimeMinValue = value;
838 m_RuntimeMinValue = value;
839 m_RuntimeLastMinValue = value;
840 m_RuntimeMinValueUpdateTime = Time.time;
841 m_RuntimeMinValueChanged =
true;
846 internal void UpdateMaxValue(
double value,
bool check)
848 if (value != m_RuntimeMaxValue)
850 if (check && Application.isPlaying)
852 if (m_RuntimeMaxValueFirstChanged)
854 m_RuntimeMaxValueFirstChanged =
false;
858 m_RuntimeLastMaxValue = m_RuntimeMaxValue;
859 m_RuntimeMaxValueChanged =
true;
860 m_RuntimeMaxValueUpdateTime = Time.time;
862 m_RuntimeMaxValue = value;
866 m_RuntimeMaxValue = value;
867 m_RuntimeLastMaxValue = value;
868 m_RuntimeMaxValueUpdateTime = Time.time;
869 m_RuntimeMaxValueChanged =
false;
874 public double GetCurrMinValue(
float duration)
876 if (!Application.isPlaying)
return m_RuntimeMinValue;
877 if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0)
return 0;
878 if (!m_RuntimeMinValueChanged)
return m_RuntimeMinValue;
879 var time = Time.time - m_RuntimeMinValueUpdateTime;
880 if (time == 0)
return m_RuntimeMinValue;
881 var total = duration / 1000;
882 if (duration > 0 && time <= total)
884 var curr = MathUtil.Lerp(m_RuntimeLastMinValue, m_RuntimeMinValue, time / total);
889 m_RuntimeMinValueChanged =
false;
890 return m_RuntimeMinValue;
894 public double GetCurrMaxValue(
float duration)
896 if (!Application.isPlaying)
return m_RuntimeMaxValue;
897 if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0)
return 0;
898 if (!m_RuntimeMaxValueChanged)
return m_RuntimeMaxValue;
899 var time = Time.time - m_RuntimeMaxValueUpdateTime;
900 if (time == 0)
return m_RuntimeMaxValue;
901 var total = duration / 1000;
902 if (duration > 0 && time < total)
904 var curr = MathUtil.Lerp(m_RuntimeLastMaxValue, m_RuntimeMaxValue, time / total);
909 m_RuntimeMaxValueChanged =
false;
910 return m_RuntimeMaxValue;
914 public bool IsValueChanging(
float duration)
916 if (!Application.isPlaying)
return false;
917 if (GetCurrMinValue(duration) != m_RuntimeMinValue || GetCurrMaxValue(duration) != m_RuntimeMaxValue)
927 public float GetLogValue(
double value)
929 if (value <= 0 || value == 1)
return 0;
930 return logBaseE ? (float)Math.Log(value) : (float)Math.Log(value,
logBase);
938 public bool IsRight()
948 public bool IsBottom()
959 [System.Serializable]
962 public static XAxis defaultXAxis
973 m_BoundaryGap =
true,
976 m_Data =
new List<string>()
978 "x1",
"x2",
"x3",
"x4",
"x5"
980 m_Icons =
new List<Sprite>(5),
984 axis.axisLabel.textLimit.enable =
true;
995 [System.Serializable]
998 public static YAxis defaultYAxis
1002 var axis =
new YAxis
1009 m_BoundaryGap =
false,
1011 m_Data =
new List<string>(5),
1016 axis.axisLabel.textLimit.enable =
false;
1026 [System.Serializable]
1040 m_BoundaryGap =
false,
1041 m_Data =
new List<string>(5),
1045 axis.axisLabel.textLimit.enable =
false;
1055 [System.Serializable]
1058 [SerializeField]
private float m_StartAngle = 90;
1066 get {
return m_StartAngle; }
1067 set {
if (PropertyUtil.SetStruct(ref m_StartAngle, value)) SetAllDirty(); }
1070 public float runtimeStartAngle {
get;
set; }
1072 public static AngleAxis defaultAngleAxis
1076 var axis =
new AngleAxis
1081 m_BoundaryGap =
false,
1082 m_Data =
new List<string>(12),
1084 axis.splitLine.show =
true;
1085 axis.splitLine.lineStyle.type = LineStyle.Type.Solid;
1086 axis.axisLabel.textLimit.enable =
false;