整理代码

This commit is contained in:
monitor1394
2019-06-21 09:34:33 +08:00
parent 3dab004731
commit fc95338274
34 changed files with 64 additions and 94 deletions

View File

@@ -1,7 +1,4 @@
using UnityEngine;
using System.Collections;
namespace XCharts
namespace XCharts
{
public interface IJsonData
{

View File

@@ -1,7 +1,4 @@
using UnityEngine;
using System.Collections;
namespace XCharts
namespace XCharts
{
public interface IPropertyChanged
{

View File

@@ -118,7 +118,7 @@ namespace XCharts
m_Data.Add(category);
}
public string GetData(int index,DataZoom dataZoom)
public string GetData(int index, DataZoom dataZoom)
{
var showData = GetData(dataZoom);
if (index >= 0 && index < showData.Count)
@@ -131,10 +131,10 @@ namespace XCharts
{
if (dataZoom != null && dataZoom.show)
{
var startIndex = (int)((data.Count-1) * dataZoom.start / 100);
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
if(filterData == null || filterData.Count != count)
if (filterData == null || filterData.Count != count)
{
UpdateFilterData(dataZoom);
}
@@ -152,7 +152,7 @@ namespace XCharts
{
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
if(startIndex != filterStart || endIndex != filterEnd)
if (startIndex != filterStart || endIndex != filterEnd)
{
filterStart = startIndex;
filterEnd = endIndex;
@@ -166,7 +166,7 @@ namespace XCharts
filterData = m_Data;
}
}
else if(endIndex == 0)
else if (endIndex == 0)
{
filterData = new List<string>();
}
@@ -183,7 +183,7 @@ namespace XCharts
return dataCount;
}
public float GetSplitWidth(float coordinateWidth,DataZoom dataZoom)
public float GetSplitWidth(float coordinateWidth, DataZoom dataZoom)
{
return coordinateWidth / (m_BoundaryGap ? GetSplitNumber(dataZoom) : GetSplitNumber(dataZoom) - 1);
}
@@ -245,7 +245,7 @@ namespace XCharts
}
}
public float GetScaleWidth(float coordinateWidth,DataZoom dataZoom)
public float GetScaleWidth(float coordinateWidth, DataZoom dataZoom)
{
int num = GetScaleNumber(dataZoom) - 1;
if (num <= 0) num = 1;

View File

@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{

View File

@@ -2,7 +2,6 @@
using UnityEngine.UI;
using System.Collections.Generic;
using System.Text;
using System;
using UnityEngine.EventSystems;
namespace XCharts
@@ -162,7 +161,6 @@ namespace XCharts
m_Tooltip.SetActive(false);
return;
}
m_Tooltip.SetActive(true);
if (m_Series.Count == 1)
{
float value = m_Series.GetData(0, index);
@@ -221,6 +219,7 @@ namespace XCharts
pos.y = m_Tooltip.height;
}
m_Tooltip.UpdateContentPos(pos);
m_Tooltip.SetActive(true);
}
protected override void OnThemeChanged()

View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
@@ -84,7 +82,7 @@ namespace XCharts
rangeMode = RangeMode.Percent,
start = 30,
end = 70,
m_ScrollSensitivity=10,
m_ScrollSensitivity = 10,
};
}
}
@@ -119,7 +117,7 @@ namespace XCharts
public void SetLabelActive(bool flag)
{
if(startLabel && startLabel.gameObject.activeInHierarchy!=flag)
if (startLabel && startLabel.gameObject.activeInHierarchy != flag)
{
startLabel.gameObject.SetActive(flag);
}

View File

@@ -3,7 +3,7 @@ using System;
namespace XCharts
{
public class JsonDataSupport: IJsonData,ISerializationCallbackReceiver
public class JsonDataSupport : IJsonData, ISerializationCallbackReceiver
{
[SerializeField] protected string m_JsonData;
[SerializeField] protected bool m_DataFromJson;

View File

@@ -72,7 +72,7 @@ namespace XCharts
public override bool Equals(object obj)
{
if(ReferenceEquals(null, obj))
if (ReferenceEquals(null, obj))
{
return false;
}
@@ -128,7 +128,7 @@ namespace XCharts
public bool IsActive(string name)
{
if (string.IsNullOrEmpty(name)) return true;
for(int i = 0; i < data.Count; i++)
for (int i = 0; i < data.Count; i++)
{
if (data[i].Equals(name)) return m_DataActiveList[i];
}
@@ -204,7 +204,7 @@ namespace XCharts
btn.GetComponentInChildren<Text>().text = data[index];
}
public void UpdateButtonColor(int index,Color ableColor,Color unableColor)
public void UpdateButtonColor(int index, Color ableColor, Color unableColor)
{
if (IsActive(index))
{

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
@@ -94,7 +93,7 @@ namespace XCharts
m_Data.Add(value);
}
public float GetData(int index,DataZoom dataZoom = null)
public float GetData(int index, DataZoom dataZoom = null)
{
var showData = GetData(dataZoom);
if (index >= 0 && index <= showData.Count - 1)
@@ -133,7 +132,7 @@ namespace XCharts
{
filterStart = startIndex;
filterEnd = endIndex;
if(m_Data.Count > 0)
if (m_Data.Count > 0)
{
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
filterData = m_Data.GetRange(startIndex, count);

View File

@@ -211,10 +211,10 @@ namespace XCharts
{
if (IsActive(i))
{
if(dataZoom != null && dataZoom.show)
if (dataZoom != null && dataZoom.show)
{
var showData = m_Series[i].GetData(dataZoom);
foreach(var data in showData)
foreach (var data in showData)
{
if (data > max) max = data;
if (data < min) min = data;

View File

@@ -1,11 +1,10 @@
using UnityEngine;
using System.Collections;
using System;
namespace XCharts
{
[Serializable]
public class Title: IPropertyChanged,IEquatable<Title>
public class Title : IPropertyChanged, IEquatable<Title>
{
[SerializeField] private bool m_Show;
[SerializeField] private string m_Text;
@@ -17,7 +16,7 @@ namespace XCharts
public bool show { get { return m_Show; } set { m_Show = value; } }
public string text { get { return m_Text; } set { m_Text = value; } }
public int textFontSize { get { return m_TextFontSize; }set { m_TextFontSize = value; } }
public int textFontSize { get { return m_TextFontSize; } set { m_TextFontSize = value; } }
public string subText { get { return m_SubText; } set { m_Text = value; } }
public int subTextFontSize { get { return m_SubTextFontSize; } set { m_SubTextFontSize = value; } }
public float itemGap { get { return m_ItemGap; } set { m_ItemGap = value; } }

View File

@@ -21,7 +21,7 @@ namespace XCharts
[NonSerialized] private RectTransform m_LabelRectX;
[NonSerialized] private RectTransform m_LabelRectY;
public bool show { get { return m_Show; }set { m_Show = value; SetActive(value); } }
public bool show { get { return m_Show; } set { m_Show = value; SetActive(value); } }
public bool crossLabel { get { return m_CrossLabel; } set { m_CrossLabel = value; } }
public int dataIndex { get; set; }
@@ -47,6 +47,7 @@ namespace XCharts
public void SetObj(GameObject obj)
{
m_GameObject = obj;
m_GameObject.SetActive(false);
}
public void SetContentObj(GameObject content)
@@ -56,7 +57,7 @@ namespace XCharts
m_ContentText = m_Content.GetComponentInChildren<Text>();
}
public void SetLabelObj(GameObject labelX,GameObject labelY)
public void SetLabelObj(GameObject labelX, GameObject labelY)
{
m_LabelX = labelX;
m_LabelRectX = labelX.GetComponent<RectTransform>();
@@ -64,6 +65,8 @@ namespace XCharts
m_LabelY = labelY;
m_LabelRectY = labelY.GetComponent<RectTransform>();
m_LabelTextY = labelY.GetComponentInChildren<Text>();
m_LabelX.SetActive(false);
m_LabelY.SetActive(false);
}
public void SetContentBackgroundColor(Color color)
@@ -96,17 +99,17 @@ namespace XCharts
if (m_ContentText)
{
m_ContentText.text = txt;
m_ContentRect.sizeDelta = new Vector2(m_ContentText.preferredWidth + 8,
m_ContentRect.sizeDelta = new Vector2(m_ContentText.preferredWidth + 8,
m_ContentText.preferredHeight + 8);
}
}
public void UpdateLabelText(string labelX,string labelY)
public void UpdateLabelText(string labelX, string labelY)
{
if (m_LabelTextX)
{
m_LabelTextX.text = labelX;
m_LabelRectX.sizeDelta = new Vector2(m_LabelTextX.preferredWidth + 8,
m_LabelRectX.sizeDelta = new Vector2(m_LabelTextX.preferredWidth + 8,
m_LabelTextX.preferredHeight + 8);
}
if (m_LabelTextY)
@@ -132,11 +135,11 @@ namespace XCharts
public void UpdateContentPos(Vector2 pos)
{
if(m_Content)
if (m_Content)
m_Content.transform.localPosition = pos;
}
public void UpdateLabelPos(Vector2 xLabelPos,Vector2 yLabelPos)
public void UpdateLabelPos(Vector2 xLabelPos, Vector2 yLabelPos)
{
if (m_LabelX)
{

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
@@ -20,7 +19,7 @@ namespace XCharts
public override void AddData(string legend, float value)
{
m_Legend.AddData(legend);
var serie = m_Series.AddData(legend,value);
var serie = m_Series.AddData(legend, value);
if (serie != null)
{
serie.ClearData();
@@ -56,7 +55,7 @@ namespace XCharts
continue;
}
var data = m_Series.series[i].data;
if(data.Count <= 0)
if (data.Count <= 0)
{
m_AngleList.Add(0);
continue;