代码重构

This commit is contained in:
monitor1394
2019-06-17 04:29:19 +08:00
parent 100f25fc1b
commit b118081deb
15 changed files with 217 additions and 8565 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: a142bb574d9f48c4fa8f0375629732e8
timeCreated: 1539696983
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -26,16 +26,6 @@ namespace XCharts
public Bar bar { get { return m_Bar; } } public Bar bar { get { return m_Bar; } }
protected override void Awake()
{
base.Awake();
}
protected override void Update()
{
base.Update();
}
protected override void DrawChart(VertexHelper vh) protected override void DrawChart(VertexHelper vh)
{ {
base.DrawChart(vh); base.DrawChart(vh);

View File

@@ -254,12 +254,26 @@ namespace XCharts
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Axis)) return false; if (ReferenceEquals(null, obj))
return Equals((Axis)obj); {
return false;
}
else if (obj is Axis)
{
return Equals((Axis)obj);
}
else
{
return false;
}
} }
public bool Equals(Axis other) public bool Equals(Axis other)
{ {
if (ReferenceEquals(null, other))
{
return false;
}
return show == other.show && return show == other.show &&
type == other.type && type == other.type &&
min == other.min && min == other.min &&
@@ -272,14 +286,22 @@ namespace XCharts
ChartHelper.IsValueEqualsList<string>(m_Data, other.data); ChartHelper.IsValueEqualsList<string>(m_Data, other.data);
} }
public static bool operator ==(Axis point1, Axis point2) public static bool operator ==(Axis left, Axis right)
{ {
return point1.Equals(point2); if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
} }
public static bool operator !=(Axis point1, Axis point2) public static bool operator !=(Axis left, Axis right)
{ {
return !point1.Equals(point2); return !(left == right);
} }
public override int GetHashCode() public override int GetHashCode()

View File

@@ -69,6 +69,10 @@ namespace XCharts
protected override void Awake() protected override void Awake()
{ {
if (m_ThemeInfo == null)
{
m_ThemeInfo = ThemeInfo.Default;
}
raycastTarget = false; raycastTarget = false;
rectTransform.anchorMax = Vector2.zero; rectTransform.anchorMax = Vector2.zero;
rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMin = Vector2.zero;
@@ -95,14 +99,12 @@ namespace XCharts
protected override void Reset() protected override void Reset()
{ {
ChartHelper.DestoryAllChilds(transform); ChartHelper.DestoryAllChilds(transform);
m_ThemeInfo = ThemeInfo.Dark; m_ThemeInfo = ThemeInfo.Default;
m_Title = Title.defaultTitle; m_Title = Title.defaultTitle;
m_Legend = Legend.defaultLegend; m_Legend = Legend.defaultLegend;
m_Tooltip = Tooltip.defaultTooltip; m_Tooltip = Tooltip.defaultTooltip;
m_Series = Series.defaultSeries; m_Series = Series.defaultSeries;
InitTitle(); Awake();
InitLegend();
InitTooltip();
} }
#endif #endif
@@ -244,7 +246,8 @@ namespace XCharts
int count = (data as PointerEventData).clickCount; int count = (data as PointerEventData).clickCount;
int index = int.Parse(data.selectedObject.name.Split('_')[1]); int index = int.Parse(data.selectedObject.name.Split('_')[1]);
SetActive(index, !m_Legend.IsActive(index)); SetActive(index, !m_Legend.IsActive(index));
m_Legend.UpdateButtonColor(index, m_ThemeInfo.GetColor(index), m_ThemeInfo.legendUnableColor); m_Legend.UpdateButtonColor(index, m_ThemeInfo.GetColor(index),
m_ThemeInfo.legendUnableColor);
OnYMaxValueChanged(); OnYMaxValueChanged();
OnLegendButtonClicked(); OnLegendButtonClicked();
RefreshChart(); RefreshChart();
@@ -258,10 +261,11 @@ namespace XCharts
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
tooltipObject.transform.localPosition = Vector3.zero; tooltipObject.transform.localPosition = Vector3.zero;
DestroyImmediate(tooltipObject.GetComponent<Image>()); DestroyImmediate(tooltipObject.GetComponent<Image>());
var parent = tooltipObject.transform;
ChartHelper.HideAllObject(tooltipObject.transform); ChartHelper.HideAllObject(tooltipObject.transform);
GameObject content = ChartHelper.AddTooltipContent("content", tooltipObject.transform, m_ThemeInfo.font); GameObject content = ChartHelper.AddTooltipContent("content", parent, m_ThemeInfo.font);
GameObject labelX = ChartHelper.AddTooltipLabel("label_x", tooltipObject.transform, m_ThemeInfo.font, new Vector2(0.5f, 1)); GameObject labelX = ChartHelper.AddTooltipLabel("label_x", parent, m_ThemeInfo.font, new Vector2(0.5f, 1));
GameObject labelY = ChartHelper.AddTooltipLabel("label_y", tooltipObject.transform, m_ThemeInfo.font, new Vector2(1, 0.5f)); GameObject labelY = ChartHelper.AddTooltipLabel("label_y", parent, m_ThemeInfo.font, new Vector2(1, 0.5f));
m_Tooltip.SetObj(tooltipObject); m_Tooltip.SetObj(tooltipObject);
m_Tooltip.SetContentObj(content); m_Tooltip.SetContentObj(content);
m_Tooltip.SetLabelObj(labelX, labelY); m_Tooltip.SetLabelObj(labelX, labelY);

View File

@@ -49,12 +49,26 @@ namespace XCharts
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Coordinate)) return false; if (ReferenceEquals(null, obj))
return Equals((Coordinate)obj); {
return false;
}
else if (obj is Coordinate)
{
return Equals((Coordinate)obj);
}
else
{
return false;
}
} }
public bool Equals(Coordinate other) public bool Equals(Coordinate other)
{ {
if (ReferenceEquals(null, other))
{
return false;
}
return m_Left == other.left && return m_Left == other.left &&
m_Right == other.right && m_Right == other.right &&
m_Top == other.top && m_Top == other.top &&
@@ -63,14 +77,22 @@ namespace XCharts
m_FontSize == other.fontSize; m_FontSize == other.fontSize;
} }
public static bool operator ==(Coordinate point1, Coordinate point2) public static bool operator ==(Coordinate left, Coordinate right)
{ {
return point1.Equals(point2); if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
} }
public static bool operator !=(Coordinate point1, Coordinate point2) public static bool operator !=(Coordinate left, Coordinate right)
{ {
return !point1.Equals(point2); return !(left == right);
} }
public override int GetHashCode() public override int GetHashCode()

View File

@@ -45,11 +45,11 @@ namespace XCharts
protected override void Awake() protected override void Awake()
{ {
base.Awake();
CheckMinMaxValue(); CheckMinMaxValue();
InitDataZoom(); InitDataZoom();
InitSplitX(); InitSplitX();
InitSplitY(); InitSplitY();
base.Awake();
} }
protected override void Update() protected override void Update()
@@ -302,8 +302,14 @@ namespace XCharts
dataZoomObject.transform, m_ThemeInfo.font, m_ThemeInfo.dataZoomTextColor, TextAnchor.MiddleLeft, dataZoomObject.transform, m_ThemeInfo.font, m_ThemeInfo.dataZoomTextColor, TextAnchor.MiddleLeft,
Vector2.zero, Vector2.zero, new Vector2(0, 0.5f), new Vector2(200, 20)); Vector2.zero, Vector2.zero, new Vector2(0, 0.5f), new Vector2(200, 20));
m_DataZoom.SetLabelActive(false); m_DataZoom.SetLabelActive(false);
m_XAxis.UpdateFilterData(m_DataZoom); if (m_XAxis != null)
m_Series.UpdateFilterData(m_DataZoom); {
m_XAxis.UpdateFilterData(m_DataZoom);
}
if (m_Series != null)
{
m_Series.UpdateFilterData(m_DataZoom);
}
raycastTarget = m_DataZoom.show; raycastTarget = m_DataZoom.show;
} }
@@ -355,7 +361,7 @@ namespace XCharts
private void CheckXAxis() private void CheckXAxis()
{ {
if (!m_CheckXAxis.Equals(m_XAxis)) if (m_CheckXAxis != m_XAxis)
{ {
m_CheckXAxis.Copy(m_XAxis); m_CheckXAxis.Copy(m_XAxis);
OnXAxisChanged(); OnXAxisChanged();

View File

@@ -72,12 +72,26 @@ namespace XCharts
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Legend)) return false; if(ReferenceEquals(null, obj))
return Equals((Legend)obj); {
return false;
}
else if (obj is Legend)
{
return Equals((Legend)obj);
}
else
{
return false;
}
} }
public bool Equals(Legend other) public bool Equals(Legend other)
{ {
if (ReferenceEquals(null, other))
{
return false;
}
return show == other.show && return show == other.show &&
orient == other.orient && orient == other.orient &&
location == other.location && location == other.location &&
@@ -88,14 +102,22 @@ namespace XCharts
ChartHelper.IsValueEqualsList<string>(m_Data, other.data); ChartHelper.IsValueEqualsList<string>(m_Data, other.data);
} }
public static bool operator ==(Legend point1, Legend point2) public static bool operator ==(Legend left, Legend right)
{ {
return point1.Equals(point2); if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
} }
public static bool operator !=(Legend point1, Legend point2) public static bool operator !=(Legend left, Legend right)
{ {
return !point1.Equals(point2); return !(left == right);
} }
public override int GetHashCode() public override int GetHashCode()

View File

@@ -202,14 +202,26 @@ namespace XCharts
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Location)) if (ReferenceEquals(null, obj))
{
return false; return false;
}
return Equals((Location)obj); else if (obj is Location)
{
return Equals((Location)obj);
}
else
{
return false;
}
} }
public bool Equals(Location other) public bool Equals(Location other)
{ {
if (ReferenceEquals(null, other))
{
return false;
}
return align == other.align && return align == other.align &&
left == other.left && left == other.left &&
right == other.right && right == other.right &&
@@ -217,14 +229,22 @@ namespace XCharts
bottom == other.bottom; bottom == other.bottom;
} }
public static bool operator ==(Location point1, Location point2) public static bool operator ==(Location left, Location right)
{ {
return point1.Equals(point2); if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
} }
public static bool operator !=(Location point1, Location point2) public static bool operator !=(Location left, Location right)
{ {
return !point1.Equals(point2); return !(left == right);
} }
public override int GetHashCode() public override int GetHashCode()

View File

@@ -111,12 +111,26 @@ namespace XCharts
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Radar)) return false; if (ReferenceEquals(null, obj))
return Equals((Radar)obj); {
return false;
}
else if (obj is Radar)
{
return Equals((Radar)obj);
}
else
{
return false;
}
} }
public bool Equals(Radar other) public bool Equals(Radar other)
{ {
if (ReferenceEquals(null, other))
{
return false;
}
return radius == other.radius && return radius == other.radius &&
splitNumber == other.splitNumber && splitNumber == other.splitNumber &&
left == other.left && left == other.left &&
@@ -139,14 +153,22 @@ namespace XCharts
return true; return true;
} }
public static bool operator ==(Radar point1, Radar point2) public static bool operator ==(Radar left, Radar right)
{ {
return point1.Equals(point2); if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
} }
public static bool operator !=(Radar point1, Radar point2) public static bool operator !=(Radar left, Radar right)
{ {
return !point1.Equals(point2); return !(left == right);
} }
public override int GetHashCode() public override int GetHashCode()

View File

@@ -221,14 +221,26 @@ namespace XCharts
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is ThemeInfo)) if (ReferenceEquals(null, obj))
{
return false; return false;
}
return Equals((ThemeInfo)obj); else if (obj is ThemeInfo)
{
return Equals((ThemeInfo)obj);
}
else
{
return false;
}
} }
public bool Equals(ThemeInfo other) public bool Equals(ThemeInfo other)
{ {
if (ReferenceEquals(null, other))
{
return false;
}
return m_Font == other.m_Font && return m_Font == other.m_Font &&
ChartHelper.IsValueEqualsColor(m_LegendUnableColor, other.m_LegendUnableColor) && ChartHelper.IsValueEqualsColor(m_LegendUnableColor, other.m_LegendUnableColor) &&
ChartHelper.IsValueEqualsColor(m_BackgroundColor, other.m_BackgroundColor) && ChartHelper.IsValueEqualsColor(m_BackgroundColor, other.m_BackgroundColor) &&
@@ -247,14 +259,22 @@ namespace XCharts
m_ColorPalette.Length == other.m_ColorPalette.Length; m_ColorPalette.Length == other.m_ColorPalette.Length;
} }
public static bool operator ==(ThemeInfo point1, ThemeInfo point2) public static bool operator ==(ThemeInfo left, ThemeInfo right)
{ {
return point1.Equals(point2); if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
} }
public static bool operator !=(ThemeInfo point1, ThemeInfo point2) public static bool operator !=(ThemeInfo left, ThemeInfo right)
{ {
return !point1.Equals(point2); return !(left == right);
} }
public override int GetHashCode() public override int GetHashCode()

View File

@@ -53,12 +53,26 @@ namespace XCharts
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Title)) return false; if (ReferenceEquals(null, obj))
return Equals((Title)obj); {
return false;
}
else if (obj is Title)
{
return Equals((Title)obj);
}
else
{
return false;
}
} }
public bool Equals(Title other) public bool Equals(Title other)
{ {
if (ReferenceEquals(null, other))
{
return false;
}
return m_Show == other.show && return m_Show == other.show &&
m_Text.Equals(other.text) && m_Text.Equals(other.text) &&
m_TextFontSize == other.textFontSize && m_TextFontSize == other.textFontSize &&
@@ -68,14 +82,22 @@ namespace XCharts
m_Location.Equals(other.location); m_Location.Equals(other.location);
} }
public static bool operator == (Title point1, Title point2) public static bool operator ==(Title left, Title right)
{ {
return point1.Equals(point2); if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
{
return true;
}
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return Equals(left, right);
} }
public static bool operator != (Title point1, Title point2) public static bool operator !=(Title left, Title right)
{ {
return !point1.Equals(point2); return !(left == right);
} }
public override int GetHashCode() public override int GetHashCode()

View File

@@ -10,16 +10,6 @@ namespace XCharts
public Line line { get { return line; } } public Line line { get { return line; } }
protected override void Awake()
{
base.Awake();
}
protected override void Update()
{
base.Update();
}
#if UNITY_EDITOR #if UNITY_EDITOR
protected override void Reset() protected override void Reset()
{ {

View File

@@ -39,16 +39,6 @@ namespace XCharts
} }
} }
protected override void Awake()
{
base.Awake();
}
protected override void Update()
{
base.Update();
}
protected override void DrawChart(VertexHelper vh) protected override void DrawChart(VertexHelper vh)
{ {
base.DrawChart(vh); base.DrawChart(vh);

View File

@@ -72,7 +72,7 @@ namespace XCharts
private void CheckRadarInfoChanged() private void CheckRadarInfoChanged()
{ {
if (!m_CheckRadar.Equals(m_Radar)) if (m_CheckRadar != m_Radar)
{ {
m_CheckRadar.Copy(m_Radar); m_CheckRadar.Copy(m_Radar);
OnRadarChanged(); OnRadarChanged();