mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-20 15:30:09 +00:00
0.2版本,重构代码,增加Editor
This commit is contained in:
@@ -1,120 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class BarInfo
|
||||
{
|
||||
public float barWid = 0.7f;
|
||||
public float space;
|
||||
}
|
||||
|
||||
public class BarChart : BaseAxesChart
|
||||
{
|
||||
[SerializeField]
|
||||
private BarInfo barInfo = new BarInfo();
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
if (yAxis.type == AxisType.category)
|
||||
{
|
||||
int seriesCount = seriesList.Count;
|
||||
float scaleWid = yAxis.GetSplitWidth(coordinateHig);
|
||||
float barWid = barInfo.barWid > 1 ? barInfo.barWid : scaleWid * barInfo.barWid;
|
||||
float offset = (scaleWid - barWid * seriesCount - barInfo.space * (seriesCount - 1)) / 2;
|
||||
float max = GetMaxValue();
|
||||
if (tooltip.show && tooltip.DataIndex > 0)
|
||||
{
|
||||
float pX = zeroX + coordinateWid;
|
||||
float pY = zeroY + scaleWid * (tooltip.DataIndex - 1);
|
||||
Vector3 p1 = new Vector3(zeroX, pY);
|
||||
Vector3 p2 = new Vector3(zeroX, pY + scaleWid);
|
||||
Vector3 p3 = new Vector3(pX, pY + scaleWid);
|
||||
Vector3 p4 = new Vector3(pX, pY);
|
||||
ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, themeInfo.tooltipFlagAreaColor);
|
||||
}
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
if (!legend.IsShowSeries(j)) continue;
|
||||
Series series = seriesList[j];
|
||||
Color color = themeInfo.GetColor(j);
|
||||
int startIndex = 0;
|
||||
if (series.showDataNumber > 0 && series.DataList.Count > series.showDataNumber)
|
||||
{
|
||||
startIndex = series.DataList.Count - series.showDataNumber;
|
||||
}
|
||||
for (int i = startIndex; i < series.DataList.Count; i++)
|
||||
{
|
||||
float data = series.DataList[i];
|
||||
float pX = zeroX + coordinate.tickness;
|
||||
float pY = zeroY + i * scaleWid;
|
||||
if (!yAxis.boundaryGap) pY -= scaleWid / 2;
|
||||
float barHig = data / max * coordinateWid;
|
||||
float space = offset + j * (barWid + barInfo.space);
|
||||
Vector3 p1 = new Vector3(pX, pY + space + barWid);
|
||||
Vector3 p2 = new Vector3(pX + barHig, pY + space + barWid);
|
||||
Vector3 p3 = new Vector3(pX + barHig, pY + space);
|
||||
Vector3 p4 = new Vector3(pX, pY + space);
|
||||
ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int seriesCount = seriesList.Count;
|
||||
float scaleWid = xAxis.GetDataWidth(coordinateWid);
|
||||
float barWid = barInfo.barWid > 1 ? barInfo.barWid : scaleWid * barInfo.barWid;
|
||||
float offset = (scaleWid - barWid * seriesCount - barInfo.space * (seriesCount - 1)) / 2;
|
||||
float max = GetMaxValue();
|
||||
if (tooltip.show && tooltip.DataIndex > 0)
|
||||
{
|
||||
float tooltipSplitWid = scaleWid < 1 ? 1 : scaleWid;
|
||||
float pX = zeroX + scaleWid * (tooltip.DataIndex - 1);
|
||||
float pY = zeroY + coordinateHig;
|
||||
Vector3 p1 = new Vector3(pX, zeroY);
|
||||
Vector3 p2 = new Vector3(pX, pY);
|
||||
Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY);
|
||||
Vector3 p4 = new Vector3(pX + tooltipSplitWid, zeroY);
|
||||
ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, themeInfo.tooltipFlagAreaColor);
|
||||
}
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
if (!legend.IsShowSeries(j)) continue;
|
||||
Series series = seriesList[j];
|
||||
Color color = themeInfo.GetColor(j);
|
||||
int startIndex = 0;
|
||||
if (series.showDataNumber > 0 && series.DataList.Count > series.showDataNumber)
|
||||
{
|
||||
startIndex = series.DataList.Count - series.showDataNumber;
|
||||
}
|
||||
for (int i = startIndex; i < series.DataList.Count; i++)
|
||||
{
|
||||
float data = series.DataList[i];
|
||||
float pX = zeroX + i * scaleWid;
|
||||
if (!xAxis.boundaryGap) pX -= scaleWid / 2;
|
||||
float pY = zeroY + coordinate.tickness;
|
||||
float barHig = data / max * coordinateHig;
|
||||
float space = offset + j * (barWid + barInfo.space);
|
||||
Vector3 p1 = new Vector3(pX + space, pY);
|
||||
Vector3 p2 = new Vector3(pX + space, pY + barHig);
|
||||
Vector3 p3 = new Vector3(pX + space + barWid, pY + barHig);
|
||||
Vector3 p4 = new Vector3(pX + space + barWid, pY);
|
||||
ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,600 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
|
||||
[System.Serializable]
|
||||
public class Coordinate
|
||||
{
|
||||
public bool show = true;
|
||||
public float left = 40f;
|
||||
public float right = 30f;
|
||||
public float top = 40;
|
||||
public float bottom = 25f;
|
||||
public float tickness = 0.6f;
|
||||
public float splitWidth = 5.0f;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public enum AxisType
|
||||
{
|
||||
value,
|
||||
category,
|
||||
time,
|
||||
log
|
||||
}
|
||||
|
||||
public enum SplitLineType
|
||||
{
|
||||
solid,
|
||||
dashed,
|
||||
dotted
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Axis
|
||||
{
|
||||
public AxisType type;
|
||||
public int splitNumber = 5;
|
||||
public int maxSplitNumber = 5;
|
||||
public bool showSplitLine = true;
|
||||
public SplitLineType splitLineType = SplitLineType.dashed;
|
||||
public bool boundaryGap = true;
|
||||
[SerializeField]
|
||||
private List<string> data;
|
||||
|
||||
private List<string> Data { get { return data; } }
|
||||
|
||||
public void AddData(string category)
|
||||
{
|
||||
if (data.Count >= maxSplitNumber && maxSplitNumber != 0)
|
||||
{
|
||||
data.RemoveAt(0);
|
||||
}
|
||||
data.Add(category);
|
||||
}
|
||||
|
||||
public string GetData(int index)
|
||||
{
|
||||
return Data[index];
|
||||
}
|
||||
|
||||
public int GetSplitNumber()
|
||||
{
|
||||
if (Data.Count > 2 * splitNumber || Data.Count <= 0)
|
||||
return splitNumber;
|
||||
else
|
||||
return Data.Count;
|
||||
}
|
||||
|
||||
public float GetSplitWidth(float coordinateWidth)
|
||||
{
|
||||
return coordinateWidth / (boundaryGap ? GetSplitNumber(): GetSplitNumber() - 1);
|
||||
}
|
||||
|
||||
public int GetDataNumber()
|
||||
{
|
||||
return Data.Count;
|
||||
}
|
||||
|
||||
public float GetDataWidth(float coordinateWidth)
|
||||
{
|
||||
return coordinateWidth / (boundaryGap ? Data.Count : Data.Count - 1);
|
||||
}
|
||||
|
||||
public string GetScaleName(int index, float maxData = 0)
|
||||
{
|
||||
if (type == AxisType.value)
|
||||
{
|
||||
return ((int)(maxData * index / GetSplitNumber())).ToString();
|
||||
}
|
||||
int dataCount = Data.Count;
|
||||
if (dataCount <= 0) return "";
|
||||
float rate = dataCount / GetScaleNumber();
|
||||
if (rate < 1) rate = 1;
|
||||
int newIndex = (int)(index * rate >= dataCount - 1 ? dataCount - 1 : index * rate);
|
||||
return Data[newIndex];
|
||||
}
|
||||
|
||||
public int GetScaleNumber()
|
||||
{
|
||||
if (Data.Count > 2 * splitNumber || Data.Count <= 0)
|
||||
return boundaryGap ? splitNumber + 1 : splitNumber;
|
||||
else
|
||||
return boundaryGap ? Data.Count + 1 : Data.Count;
|
||||
}
|
||||
|
||||
public float GetScaleWidth(float coordinateWidth)
|
||||
{
|
||||
int num = GetScaleNumber() - 1;
|
||||
if (num <= 0) num = 1;
|
||||
return coordinateWidth / num;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class XAxis : Axis
|
||||
{
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class YAxis : Axis
|
||||
{
|
||||
}
|
||||
|
||||
public class BaseAxesChart : BaseChart
|
||||
{
|
||||
private const int DEFAULT_YSACLE_NUM = 5;
|
||||
private const string YSCALE_TEXT_PREFIX = "yScale";
|
||||
private const string XSCALE_TEXT_PREFIX = "xScale";
|
||||
|
||||
[SerializeField]
|
||||
protected Coordinate coordinate = new Coordinate();
|
||||
[SerializeField]
|
||||
protected XAxis xAxis = new XAxis();
|
||||
[SerializeField]
|
||||
protected YAxis yAxis = new YAxis();
|
||||
|
||||
private float lastXMaxValue;
|
||||
private float lastYMaxValue;
|
||||
private float lastCoordinateWid;
|
||||
private float lastCoordinateHig;
|
||||
private float lastCoordinateScaleLen;
|
||||
|
||||
private XAxis checkXAxis = new XAxis();
|
||||
private YAxis checkYAxis = new YAxis();
|
||||
private Coordinate checkCoordinate = new Coordinate();
|
||||
|
||||
protected List<Text> yScaleTextList = new List<Text>();
|
||||
protected List<Text> xScaleTextList = new List<Text>();
|
||||
protected float zeroX { get { return coordinate.left; } }
|
||||
protected float zeroY { get { return coordinate.bottom; } }
|
||||
protected float coordinateWid { get { return chartWid - coordinate.left - coordinate.right; } }
|
||||
protected float coordinateHig { get { return chartHig - coordinate.top - coordinate.bottom; } }
|
||||
|
||||
public Axis XAxis { get { return xAxis; } }
|
||||
public Axis YAxis { get { return yAxis; } }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
lastCoordinateHig = chartHig;
|
||||
lastCoordinateWid = chartWid;
|
||||
lastCoordinateScaleLen = coordinate.splitWidth;
|
||||
checkXAxis = xAxis;
|
||||
checkYAxis = yAxis;
|
||||
InitXScale();
|
||||
InitYScale();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
CheckYAxisType();
|
||||
CheckXAxisType();
|
||||
CheckMaxValue();
|
||||
CheckCoordinate();
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
DrawCoordinate(vh);
|
||||
}
|
||||
|
||||
protected override void CheckTootipArea(Vector2 local)
|
||||
{
|
||||
if (local.x < zeroX || local.x > zeroX + coordinateWid ||
|
||||
local.y < zeroY || local.y > zeroY + coordinateHig)
|
||||
{
|
||||
tooltip.DataIndex = 0;
|
||||
RefreshTooltip();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xAxis.type == AxisType.value)
|
||||
{
|
||||
float splitWid =yAxis.GetDataWidth(coordinateHig);
|
||||
for (int i = 0; i < yAxis.GetDataNumber(); i++)
|
||||
{
|
||||
float pY = zeroY + i * splitWid;
|
||||
if (yAxis.boundaryGap)
|
||||
{
|
||||
if (local.y > pY && local.y <= pY + splitWid)
|
||||
{
|
||||
tooltip.DataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)
|
||||
{
|
||||
tooltip.DataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float splitWid =xAxis.GetDataWidth(coordinateWid);
|
||||
for (int i = 0; i < xAxis.GetDataNumber(); i++)
|
||||
{
|
||||
float pX = zeroX + i * splitWid;
|
||||
if (xAxis.boundaryGap)
|
||||
{
|
||||
if (local.x > pX && local.x <= pX + splitWid)
|
||||
{
|
||||
tooltip.DataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)
|
||||
{
|
||||
tooltip.DataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tooltip.DataIndex > 0)
|
||||
{
|
||||
tooltip.UpdatePos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
if (tooltip.LastDataIndex != tooltip.DataIndex)
|
||||
{
|
||||
RefreshChart();
|
||||
}
|
||||
tooltip.LastDataIndex = tooltip.DataIndex;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RefreshTooltip()
|
||||
{
|
||||
base.RefreshTooltip();
|
||||
int index = tooltip.DataIndex - 1;
|
||||
Axis tempAxis = xAxis.type == AxisType.value ? (Axis)yAxis : (Axis)xAxis;
|
||||
if (index < 0)
|
||||
{
|
||||
tooltip.SetActive(false);
|
||||
return;
|
||||
}
|
||||
tooltip.SetActive(true);
|
||||
if (seriesList.Count == 1)
|
||||
{
|
||||
string txt = tempAxis.GetData(index) + ": " + seriesList[0].DataList[index];
|
||||
tooltip.UpdateTooltipText(txt);
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(tempAxis.GetData(index));
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
string strColor = ColorUtility.ToHtmlStringRGBA(themeInfo.GetColor(i));
|
||||
string key = seriesList[i].name;
|
||||
float value = seriesList[i].DataList[index];
|
||||
sb.Append("\n");
|
||||
sb.AppendFormat("<color=#{0}>● </color>", strColor);
|
||||
sb.AppendFormat("{0}: {1}", key, value);
|
||||
}
|
||||
tooltip.UpdateTooltipText(sb.ToString());
|
||||
}
|
||||
var pos = tooltip.GetPos();
|
||||
if (pos.x + tooltip.Width > chartWid)
|
||||
{
|
||||
pos.x = chartWid - tooltip.Width;
|
||||
}
|
||||
if (pos.y - tooltip.Height < 0)
|
||||
{
|
||||
pos.y = tooltip.Height;
|
||||
}
|
||||
tooltip.UpdatePos(pos);
|
||||
}
|
||||
|
||||
TextGenerationSettings GetTextSetting()
|
||||
{
|
||||
var setting = new TextGenerationSettings();
|
||||
var fontdata = FontData.defaultFontData;
|
||||
|
||||
//setting.generationExtents = rectTransform.rect.size;
|
||||
setting.generationExtents = new Vector2(200.0F, 50.0F);
|
||||
setting.fontSize = 14;
|
||||
setting.textAnchor = TextAnchor.MiddleCenter;
|
||||
setting.scaleFactor = 1f;
|
||||
setting.color = Color.red;
|
||||
setting.font = themeInfo.font;
|
||||
setting.pivot = new Vector2(0.5f, 0.5f);
|
||||
setting.richText = false;
|
||||
setting.lineSpacing = 0;
|
||||
setting.fontStyle = FontStyle.Normal;
|
||||
setting.resizeTextForBestFit = false;
|
||||
setting.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
setting.verticalOverflow = VerticalWrapMode.Overflow;
|
||||
|
||||
return setting;
|
||||
|
||||
}
|
||||
|
||||
protected override void OnThemeChanged()
|
||||
{
|
||||
base.OnThemeChanged();
|
||||
InitXScale();
|
||||
InitYScale();
|
||||
}
|
||||
|
||||
public void AddXAxisCategory(string category)
|
||||
{
|
||||
xAxis.AddData(category);
|
||||
OnXAxisChanged();
|
||||
}
|
||||
|
||||
public void AddYAxisCategory(string category)
|
||||
{
|
||||
yAxis.AddData(category);
|
||||
OnYAxisChanged();
|
||||
}
|
||||
|
||||
private void InitYScale()
|
||||
{
|
||||
yScaleTextList.Clear();
|
||||
float max = GetMaxValue();
|
||||
float scaleWid = yAxis.GetScaleWidth(coordinateHig);
|
||||
for (int i = 0; i < yAxis.GetSplitNumber(); i++)
|
||||
{
|
||||
Text txt = ChartUtils.AddTextObject(YSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
|
||||
themeInfo.textColor, TextAnchor.MiddleRight, Vector2.zero, Vector2.zero,
|
||||
new Vector2(1, 0.5f),
|
||||
new Vector2(coordinate.left, 20));
|
||||
txt.transform.localPosition = GetYScalePosition(scaleWid, i);
|
||||
txt.text = yAxis.GetScaleName(i, max);
|
||||
txt.gameObject.SetActive(coordinate.show);
|
||||
yScaleTextList.Add(txt);
|
||||
}
|
||||
}
|
||||
|
||||
public void InitXScale()
|
||||
{
|
||||
xScaleTextList.Clear();
|
||||
float max = GetMaxValue();
|
||||
float scaleWid = xAxis.GetScaleWidth(coordinateWid);
|
||||
for (int i = 0; i < xAxis.GetSplitNumber(); i++)
|
||||
{
|
||||
Text txt = ChartUtils.AddTextObject(XSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
|
||||
themeInfo.textColor, TextAnchor.MiddleCenter, Vector2.zero, Vector2.zero,
|
||||
new Vector2(1, 0.5f),
|
||||
new Vector2(scaleWid, 20));
|
||||
txt.transform.localPosition = GetXScalePosition(scaleWid, i);
|
||||
|
||||
txt.text = xAxis.GetScaleName(i, max);
|
||||
txt.gameObject.SetActive(coordinate.show);
|
||||
xScaleTextList.Add(txt);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 GetYScalePosition(float scaleWid,int i)
|
||||
{
|
||||
if (yAxis.boundaryGap)
|
||||
{
|
||||
return new Vector3(zeroX - coordinate.splitWidth - 2f,
|
||||
zeroY + (i + 0.5f) * scaleWid, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector3(zeroX - coordinate.splitWidth - 2f,
|
||||
zeroY + i * scaleWid, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 GetXScalePosition(float scaleWid,int i)
|
||||
{
|
||||
if (xAxis.boundaryGap)
|
||||
{
|
||||
return new Vector3(zeroX + (i + 1) * scaleWid, zeroY - coordinate.splitWidth - 5, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector3(zeroX + (i + 1 - 0.5f) * scaleWid,
|
||||
zeroY - coordinate.splitWidth - 10, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckCoordinate()
|
||||
{
|
||||
if (lastCoordinateHig != coordinateHig
|
||||
|| lastCoordinateWid != coordinateWid
|
||||
|| lastCoordinateScaleLen != coordinate.splitWidth)
|
||||
{
|
||||
lastCoordinateWid = coordinateWid;
|
||||
lastCoordinateHig = coordinateHig;
|
||||
lastCoordinateScaleLen = coordinate.splitWidth;
|
||||
OnCoordinateSize();
|
||||
}
|
||||
if (checkCoordinate.show != coordinate.show)
|
||||
{
|
||||
checkCoordinate.show = coordinate.show;
|
||||
OnXAxisChanged();
|
||||
OnYAxisChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckYAxisType()
|
||||
{
|
||||
if (checkYAxis.type != yAxis.type ||
|
||||
checkYAxis.boundaryGap != yAxis.boundaryGap ||
|
||||
checkYAxis.showSplitLine != yAxis.showSplitLine ||
|
||||
checkYAxis.splitNumber != yAxis.splitNumber)
|
||||
{
|
||||
checkYAxis.type = yAxis.type;
|
||||
checkYAxis.boundaryGap = yAxis.boundaryGap;
|
||||
checkYAxis.showSplitLine = yAxis.showSplitLine;
|
||||
checkYAxis.splitNumber = yAxis.splitNumber;
|
||||
OnYAxisChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckXAxisType()
|
||||
{
|
||||
if (checkXAxis.type != xAxis.type ||
|
||||
checkXAxis.boundaryGap != xAxis.boundaryGap ||
|
||||
checkXAxis.showSplitLine != xAxis.showSplitLine ||
|
||||
checkXAxis.splitNumber != xAxis.splitNumber)
|
||||
{
|
||||
checkXAxis.type = xAxis.type;
|
||||
checkXAxis.boundaryGap = xAxis.boundaryGap;
|
||||
checkXAxis.showSplitLine = xAxis.showSplitLine;
|
||||
checkXAxis.splitNumber = xAxis.splitNumber;
|
||||
OnXAxisChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckMaxValue()
|
||||
{
|
||||
if (xAxis.type == AxisType.value)
|
||||
{
|
||||
float max = GetMaxValue();
|
||||
if (lastXMaxValue != max)
|
||||
{
|
||||
lastXMaxValue = max;
|
||||
OnXMaxValueChanged();
|
||||
}
|
||||
}
|
||||
else if (yAxis.type == AxisType.value)
|
||||
{
|
||||
|
||||
float max = GetMaxValue();
|
||||
if (lastYMaxValue != max)
|
||||
{
|
||||
lastYMaxValue = max;
|
||||
OnYMaxValueChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnCoordinateSize()
|
||||
{
|
||||
InitXScale();
|
||||
InitYScale();
|
||||
}
|
||||
|
||||
protected virtual void OnYAxisChanged()
|
||||
{
|
||||
HideChild(YSCALE_TEXT_PREFIX);
|
||||
InitYScale();
|
||||
}
|
||||
|
||||
protected virtual void OnXAxisChanged()
|
||||
{
|
||||
HideChild(XSCALE_TEXT_PREFIX);
|
||||
InitXScale();
|
||||
}
|
||||
|
||||
protected virtual void OnXMaxValueChanged()
|
||||
{
|
||||
float max = GetMaxValue();
|
||||
for (int i = 0; i < xScaleTextList.Count; i++)
|
||||
{
|
||||
xScaleTextList[i].text = ((int)(max * i / xScaleTextList.Count)).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnSizeChanged()
|
||||
{
|
||||
base.OnSizeChanged();
|
||||
InitXScale();
|
||||
InitYScale();
|
||||
}
|
||||
|
||||
protected override void OnYMaxValueChanged()
|
||||
{
|
||||
float max = GetMaxValue();
|
||||
for (int i = 0; i < yScaleTextList.Count; i++)
|
||||
{
|
||||
yScaleTextList[i].text = ((int)(max * i / (yScaleTextList.Count - 1))).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCoordinate(VertexHelper vh)
|
||||
{
|
||||
if (!coordinate.show) return;
|
||||
// draw splitline
|
||||
for (int i = 1; i < yAxis.GetScaleNumber(); i++)
|
||||
{
|
||||
float pX = zeroX - coordinate.splitWidth;
|
||||
float pY = zeroY + i * coordinateHig / (yAxis.GetScaleNumber() - 1);
|
||||
ChartUtils.DrawLine(vh, new Vector3(pX, pY), new Vector3(zeroX, pY), coordinate.tickness,
|
||||
themeInfo.axisLineColor);
|
||||
if (yAxis.showSplitLine)
|
||||
{
|
||||
DrawSplitLine(vh, true, yAxis.splitLineType, new Vector3(zeroX, pY),
|
||||
new Vector3(zeroX + coordinateWid, pY));
|
||||
}
|
||||
}
|
||||
for (int i = 1; i < xAxis.GetScaleNumber(); i++)
|
||||
{
|
||||
float pX = zeroX + i * coordinateWid / (xAxis.GetScaleNumber() - 1);
|
||||
float pY = zeroY - coordinate.splitWidth - 2;
|
||||
ChartUtils.DrawLine(vh, new Vector3(pX, zeroY), new Vector3(pX, pY), coordinate.tickness,
|
||||
themeInfo.axisLineColor);
|
||||
if (xAxis.showSplitLine)
|
||||
{
|
||||
DrawSplitLine(vh, false, xAxis.splitLineType, new Vector3(pX, zeroY),
|
||||
new Vector3(pX, zeroY + coordinateHig));
|
||||
}
|
||||
}
|
||||
//draw x,y axis
|
||||
ChartUtils.DrawLine(vh, new Vector3(zeroX, zeroY - coordinate.splitWidth),
|
||||
new Vector3(zeroX, zeroY + coordinateHig + 2), coordinate.tickness,
|
||||
themeInfo.axisLineColor);
|
||||
ChartUtils.DrawLine(vh, new Vector3(zeroX - coordinate.splitWidth, zeroY),
|
||||
new Vector3(zeroX + coordinateWid + 2, zeroY), coordinate.tickness,
|
||||
themeInfo.axisLineColor);
|
||||
}
|
||||
|
||||
private void DrawSplitLine(VertexHelper vh, bool isYAxis, SplitLineType type, Vector3 startPos,
|
||||
Vector3 endPos)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SplitLineType.dashed:
|
||||
case SplitLineType.dotted:
|
||||
var startX = startPos.x;
|
||||
var startY = startPos.y;
|
||||
var dashLen = type == SplitLineType.dashed ? 6 : 2.5f;
|
||||
var count = isYAxis ? (endPos.x - startPos.x) / (dashLen * 2) :
|
||||
(endPos.y - startPos.y) / (dashLen * 2);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (isYAxis)
|
||||
{
|
||||
var toX = startX + dashLen;
|
||||
ChartUtils.DrawLine(vh, new Vector3(startX, startY), new Vector3(toX, startY),
|
||||
coordinate.tickness, themeInfo.axisSplitLineColor);
|
||||
startX += dashLen * 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
var toY = startY + dashLen;
|
||||
ChartUtils.DrawLine(vh, new Vector3(startX, startY), new Vector3(startX, toY),
|
||||
coordinate.tickness, themeInfo.axisSplitLineColor);
|
||||
startY += dashLen * 2;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case SplitLineType.solid:
|
||||
ChartUtils.DrawLine(vh, startPos, endPos, coordinate.tickness,
|
||||
themeInfo.axisSplitLineColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,673 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public enum ChartType
|
||||
{
|
||||
line,
|
||||
bar
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Title
|
||||
{
|
||||
public bool show = true;
|
||||
public string text = "Chart Title";
|
||||
public string subText = "";
|
||||
public Align align = Align.center;
|
||||
public float left;
|
||||
public float right;
|
||||
public float top = 5;
|
||||
public float bottom;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public enum Align
|
||||
{
|
||||
left, //左对齐
|
||||
right, //右对齐
|
||||
center //居中对齐
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public enum Location
|
||||
{
|
||||
left,
|
||||
right,
|
||||
top,
|
||||
bottom,
|
||||
start,
|
||||
middle,
|
||||
center,
|
||||
end,
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Legend
|
||||
{
|
||||
public bool show = true;
|
||||
public Location location = Location.right;
|
||||
public float itemWidth = 50.0f;
|
||||
public float itemHeight = 20.0f;
|
||||
public float itemGap = 5;
|
||||
public float left;
|
||||
public float right = 5;
|
||||
public float top;
|
||||
public float bottom;
|
||||
public List<string> dataList = new List<string>();
|
||||
public int checkDataListCount { get; set; }
|
||||
|
||||
private List<bool> dataShowList = new List<bool>();
|
||||
private List<Button> dataBtnList = new List<Button>();
|
||||
|
||||
public bool IsShowSeries(int seriesIndex)
|
||||
{
|
||||
if (seriesIndex < 0 || seriesIndex > dataList.Count - 1) seriesIndex = 0;
|
||||
if (seriesIndex >= dataList.Count) return false;
|
||||
if (seriesIndex < 0 || seriesIndex > dataShowList.Count - 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return dataShowList[seriesIndex];
|
||||
}
|
||||
}
|
||||
|
||||
public void SetShowData(int index, bool flag)
|
||||
{
|
||||
dataShowList[index] = flag;
|
||||
}
|
||||
|
||||
public void SetDataButton(int index, Button btn)
|
||||
{
|
||||
if (index < 0 || index > dataBtnList.Count - 1)
|
||||
{
|
||||
dataBtnList.Add(btn);
|
||||
dataShowList.Add(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataBtnList[index] = btn;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetShowData(string name, bool flag)
|
||||
{
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
if (dataList[i].Equals(name))
|
||||
{
|
||||
dataShowList[i] = flag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Button GetButton(int index)
|
||||
{
|
||||
return dataBtnList[index];
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Tooltip
|
||||
{
|
||||
public bool show;
|
||||
|
||||
public int DataIndex { get; set; }
|
||||
public int LastDataIndex { get; set; }
|
||||
public float Width { get { return bgRect.sizeDelta.x; } }
|
||||
public float Height { get { return bgRect.sizeDelta.y; } }
|
||||
|
||||
|
||||
private GameObject gameObject;
|
||||
private Text text;
|
||||
private RectTransform bgRect;
|
||||
|
||||
public void SetObj(GameObject obj)
|
||||
{
|
||||
gameObject = obj;
|
||||
bgRect = gameObject.GetComponent<RectTransform>();
|
||||
text = gameObject.GetComponentInChildren<Text>();
|
||||
}
|
||||
|
||||
public void SetBackgroundColor(Color color)
|
||||
{
|
||||
gameObject.GetComponent<Image>().color = color;
|
||||
}
|
||||
|
||||
public void SetTextColor(Color color)
|
||||
{
|
||||
text.color = color;
|
||||
}
|
||||
|
||||
public void UpdateTooltipText(string txt)
|
||||
{
|
||||
text.text = txt;
|
||||
bgRect.sizeDelta = new Vector2(text.preferredWidth + 8, text.preferredHeight + 8);
|
||||
}
|
||||
|
||||
public void SetActive(bool flag)
|
||||
{
|
||||
gameObject.SetActive(flag);
|
||||
}
|
||||
|
||||
public void UpdatePos(Vector2 pos)
|
||||
{
|
||||
gameObject.transform.localPosition = pos;
|
||||
}
|
||||
|
||||
public Vector3 GetPos()
|
||||
{
|
||||
return gameObject.transform.localPosition;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Series
|
||||
{
|
||||
public string name;
|
||||
public int showDataNumber = 0;
|
||||
[SerializeField]
|
||||
private List<float> dataList = new List<float>();
|
||||
|
||||
public List<float> DataList
|
||||
{
|
||||
get { return dataList; }
|
||||
}
|
||||
|
||||
public float Max
|
||||
{
|
||||
get
|
||||
{
|
||||
float max = 0;
|
||||
foreach (var data in DataList)
|
||||
{
|
||||
if (data > max)
|
||||
{
|
||||
max = data;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
public float Total
|
||||
{
|
||||
get
|
||||
{
|
||||
float total = 0;
|
||||
foreach (var data in DataList)
|
||||
{
|
||||
total += data;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddData(float value)
|
||||
{
|
||||
if (dataList.Count >= showDataNumber && showDataNumber != 0)
|
||||
{
|
||||
dataList.RemoveAt(0);
|
||||
}
|
||||
dataList.Add(value);
|
||||
}
|
||||
|
||||
public float GetData(int index)
|
||||
{
|
||||
if (index >= 0 && index <= DataList.Count - 1)
|
||||
{
|
||||
return DataList[index];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void UpdateData(int index, float value)
|
||||
{
|
||||
if (index >= 0 && index <= dataList.Count - 1)
|
||||
{
|
||||
dataList[index] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class BaseChart : MaskableGraphic
|
||||
{
|
||||
private const string TILTE_TEXT = "title";
|
||||
private const string SUB_TILTE_TEXT = "sub_title";
|
||||
private const string LEGEND_TEXT = "legend";
|
||||
|
||||
[SerializeField] protected Theme theme = Theme.Dark;
|
||||
[SerializeField] protected ThemeInfo themeInfo = new ThemeInfo();
|
||||
[SerializeField] protected Title title = new Title();
|
||||
[SerializeField] protected Legend legend = new Legend();
|
||||
[SerializeField] protected Tooltip tooltip = new Tooltip();
|
||||
[SerializeField] protected List<Series> seriesList = new List<Series>();
|
||||
|
||||
private Theme checkTheme = 0;
|
||||
private Title checkTitle = new Title();
|
||||
private Legend checkLegend = new Legend();
|
||||
private float checkWid = 0;
|
||||
private float checkHig = 0;
|
||||
|
||||
protected List<Text> legendTextList = new List<Text>();
|
||||
protected float chartWid { get { return rectTransform.sizeDelta.x; } }
|
||||
protected float chartHig { get { return rectTransform.sizeDelta.y; } }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
themeInfo = ThemeInfo.Dark;
|
||||
rectTransform.anchorMax = Vector2.zero;
|
||||
rectTransform.anchorMin = Vector2.zero;
|
||||
rectTransform.pivot = Vector2.zero;
|
||||
checkWid = chartWid;
|
||||
checkHig = chartHig;
|
||||
checkTheme = theme;
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
InitTooltip();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
CheckSize();
|
||||
CheckTheme();
|
||||
CheckTile();
|
||||
CheckLegend();
|
||||
CheckTooltip();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
for (int i = transform.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
DestroyImmediate(transform.GetChild(i).gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddData(string legend, float value)
|
||||
{
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (seriesList[i].name.Equals(legend))
|
||||
{
|
||||
seriesList[i].AddData(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void AddData(int legend,float value)
|
||||
{
|
||||
seriesList[legend].AddData(value);
|
||||
}
|
||||
|
||||
public void UpdateData(string legend, float value, int dataIndex = 0)
|
||||
{
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (seriesList[i].name.Equals(legend))
|
||||
{
|
||||
seriesList[i].UpdateData(dataIndex, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void UpdateData(int legendIndex, float value, int dataIndex = 0)
|
||||
{
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (i == legendIndex)
|
||||
{
|
||||
seriesList[i].UpdateData(dataIndex, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void UpdateTheme(Theme theme)
|
||||
{
|
||||
this.theme = theme;
|
||||
OnThemeChanged();
|
||||
SetAllDirty();
|
||||
}
|
||||
|
||||
protected void HideChild(string match = null)
|
||||
{
|
||||
for (int i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
if (match == null)
|
||||
transform.GetChild(i).gameObject.SetActive(false);
|
||||
else
|
||||
{
|
||||
var go = transform.GetChild(i);
|
||||
if (go.name.StartsWith(match))
|
||||
{
|
||||
go.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitTitle()
|
||||
{
|
||||
TextAnchor anchor = TextAnchor.MiddleCenter;
|
||||
Vector2 anchorMin = new Vector2(0, 0);
|
||||
Vector2 anchorMax = new Vector2(0, 0);
|
||||
Vector3 titlePosition;
|
||||
float titleWid = 200;
|
||||
float titleHig = 20;
|
||||
switch (title.align)
|
||||
{
|
||||
case Align.left:
|
||||
anchor = TextAnchor.MiddleLeft;
|
||||
titlePosition = new Vector3(title.left, chartHig - title.top, 0);
|
||||
break;
|
||||
case Align.right:
|
||||
anchor = TextAnchor.MiddleRight;
|
||||
titlePosition = new Vector3(chartWid - title.right - titleWid,
|
||||
chartHig - title.top, 0);
|
||||
break;
|
||||
case Align.center:
|
||||
anchor = TextAnchor.MiddleCenter;
|
||||
titlePosition = new Vector3(chartWid / 2 - titleWid / 2, chartHig - title.top, 0);
|
||||
break;
|
||||
default:
|
||||
anchor = TextAnchor.MiddleCenter;
|
||||
titlePosition = new Vector3(0, -title.top, 0);
|
||||
break;
|
||||
}
|
||||
Text titleText = ChartUtils.AddTextObject(TILTE_TEXT, transform, themeInfo.font,
|
||||
themeInfo.textColor, anchor, anchorMin, anchorMax, new Vector2(0, 1),
|
||||
new Vector2(titleWid, titleHig), 16);
|
||||
titleText.alignment = anchor;
|
||||
titleText.gameObject.SetActive(title.show);
|
||||
titleText.transform.localPosition = titlePosition;
|
||||
titleText.text = title.text;
|
||||
|
||||
Text subText = ChartUtils.AddTextObject(SUB_TILTE_TEXT, transform, themeInfo.font,
|
||||
themeInfo.textColor, anchor, anchorMin, anchorMax, new Vector2(0, 1),
|
||||
new Vector2(titleWid, titleHig), 14);
|
||||
subText.alignment = anchor;
|
||||
subText.gameObject.SetActive(title.show && !string.IsNullOrEmpty(title.subText));
|
||||
subText.transform.localPosition = titlePosition - new Vector3(0,15,0);
|
||||
subText.text = title.subText;
|
||||
}
|
||||
|
||||
private void InitLegend()
|
||||
{
|
||||
for (int i = 0; i < legend.dataList.Count; i++)
|
||||
{
|
||||
//LegendData data = legend.dataList[i];
|
||||
Button btn = ChartUtils.AddButtonObject(LEGEND_TEXT +"_"+ i, transform, themeInfo.font,
|
||||
themeInfo.textColor, Vector2.zero, Vector2.zero, Vector2.zero,
|
||||
new Vector2(legend.itemWidth, legend.itemHeight));
|
||||
legend.SetDataButton(i, btn);
|
||||
Color bcolor = themeInfo.GetColor(i);
|
||||
btn.gameObject.SetActive(legend.show);
|
||||
btn.transform.localPosition = GetLegendPosition(i);
|
||||
btn.GetComponent<Image>().color = bcolor;
|
||||
btn.GetComponentInChildren<Text>().text = legend.dataList[i];
|
||||
btn.onClick.AddListener(delegate ()
|
||||
{
|
||||
int index = int.Parse(btn.name.Split('_')[1]);
|
||||
legend.SetShowData(index, !legend.IsShowSeries(index));
|
||||
btn.GetComponent<Image>().color = legend.IsShowSeries(index) ?
|
||||
themeInfo.GetColor(index) : themeInfo.unableColor;
|
||||
OnYMaxValueChanged();
|
||||
OnLegendButtonClicked();
|
||||
RefreshChart();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void InitTooltip()
|
||||
{
|
||||
GameObject obj = ChartUtils.AddTooltipObject("tooltip", transform, themeInfo.font);
|
||||
tooltip.SetObj(obj);
|
||||
tooltip.SetBackgroundColor(themeInfo.tooltipBackgroundColor);
|
||||
tooltip.SetTextColor(themeInfo.tooltipTextColor);
|
||||
tooltip.SetActive(false);
|
||||
}
|
||||
|
||||
private Vector3 GetLegendPosition(int i)
|
||||
{
|
||||
int legendCount = legend.dataList.Count;
|
||||
switch (legend.location)
|
||||
{
|
||||
case Location.bottom:
|
||||
case Location.top:
|
||||
float startX = legend.left;
|
||||
if (startX <= 0)
|
||||
{
|
||||
startX = (chartWid - (legendCount * legend.itemWidth -
|
||||
(legendCount - 1) * legend.itemGap)) / 2;
|
||||
}
|
||||
float posY = legend.location == Location.bottom ?
|
||||
legend.bottom : chartHig - legend.top - legend.itemHeight;
|
||||
return new Vector3(startX + i * (legend.itemWidth + legend.itemGap), posY, 0);
|
||||
case Location.left:
|
||||
case Location.right:
|
||||
float startY = 0;
|
||||
if (legend.top > 0)
|
||||
{
|
||||
startY = chartHig - legend.top - legend.itemHeight;
|
||||
}
|
||||
else if (startY <= 0)
|
||||
{
|
||||
float legendHig = legendCount * legend.itemHeight - (legendCount - 1) * legend.itemGap;
|
||||
float offset = (chartHig - legendHig) / 2;
|
||||
startY = chartHig - offset - legend.itemHeight;
|
||||
}
|
||||
float posX = legend.location == Location.left ?
|
||||
legend.left :
|
||||
chartWid - legend.right - legend.itemWidth;
|
||||
return new Vector3(posX, startY - i * (legend.itemHeight + legend.itemGap), 0);
|
||||
default: break;
|
||||
}
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
protected float GetMaxValue()
|
||||
{
|
||||
float max = 0;
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (legend.IsShowSeries(i) && seriesList[i].Max > max) max = seriesList[i].Max;
|
||||
}
|
||||
int bigger = (int)(max * 1.3f);
|
||||
return bigger < 10 ? bigger : bigger - bigger % 10;
|
||||
}
|
||||
|
||||
private void CheckSize()
|
||||
{
|
||||
if(checkWid != chartWid || checkHig != chartHig)
|
||||
{
|
||||
checkWid = chartWid;
|
||||
checkHig = chartHig;
|
||||
OnSizeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckTheme()
|
||||
{
|
||||
if (checkTheme != theme)
|
||||
{
|
||||
checkTheme = theme;
|
||||
OnThemeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckTile()
|
||||
{
|
||||
if (checkTitle == null || title == null) return;
|
||||
if (checkTitle.align != title.align ||
|
||||
checkTitle.left != title.left ||
|
||||
checkTitle.right != title.right ||
|
||||
checkTitle.top != title.top)
|
||||
{
|
||||
checkTitle.align = title.align;
|
||||
checkTitle.left = title.left;
|
||||
checkTitle.right = title.right;
|
||||
checkTitle.top = title.top;
|
||||
OnTitleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckLegend()
|
||||
{
|
||||
if (checkLegend.checkDataListCount != legend.dataList.Count)
|
||||
{
|
||||
checkLegend.checkDataListCount = legend.dataList.Count;
|
||||
OnLegendDataListChanged();
|
||||
}
|
||||
|
||||
if (checkLegend.itemWidth != legend.itemWidth ||
|
||||
checkLegend.itemHeight != legend.itemHeight ||
|
||||
checkLegend.itemGap != legend.itemGap ||
|
||||
checkLegend.left != legend.left ||
|
||||
checkLegend.right != legend.right ||
|
||||
checkLegend.bottom != legend.bottom ||
|
||||
checkLegend.top != legend.top ||
|
||||
checkLegend.location != legend.location ||
|
||||
checkLegend.show != legend.show)
|
||||
{
|
||||
checkLegend.itemWidth = legend.itemWidth;
|
||||
checkLegend.itemHeight = legend.itemHeight;
|
||||
checkLegend.itemGap = legend.itemGap;
|
||||
checkLegend.left = legend.left;
|
||||
checkLegend.right = legend.right;
|
||||
checkLegend.bottom = legend.bottom;
|
||||
checkLegend.top = legend.top;
|
||||
checkLegend.location = legend.location;
|
||||
checkLegend.show = legend.show;
|
||||
OnLegendChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckTooltip()
|
||||
{
|
||||
if (!tooltip.show) return;
|
||||
tooltip.DataIndex = 0;
|
||||
Vector2 local;
|
||||
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||
Input.mousePosition, null, out local))
|
||||
return;
|
||||
|
||||
if (local.x < 0 || local.x > chartWid ||
|
||||
local.y < 0 || local.y > chartHig)
|
||||
return;
|
||||
|
||||
CheckTootipArea(local);
|
||||
}
|
||||
|
||||
protected virtual void CheckTootipArea(Vector2 localPostion)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnSizeChanged()
|
||||
{
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
}
|
||||
|
||||
protected virtual void OnThemeChanged()
|
||||
{
|
||||
switch (theme)
|
||||
{
|
||||
case Theme.Dark:
|
||||
themeInfo.Copy(ThemeInfo.Dark);
|
||||
break;
|
||||
case Theme.Default:
|
||||
themeInfo.Copy(ThemeInfo.Default);
|
||||
break;
|
||||
case Theme.Light:
|
||||
themeInfo.Copy(ThemeInfo.Light);
|
||||
break;
|
||||
}
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
}
|
||||
|
||||
protected virtual void OnTitleChanged()
|
||||
{
|
||||
InitTitle();
|
||||
}
|
||||
|
||||
protected virtual void OnLegendChanged()
|
||||
{
|
||||
for (int i = 0; i < legend.dataList.Count; i++)
|
||||
{
|
||||
Button btn = legend.GetButton(i);
|
||||
btn.GetComponent<RectTransform>().sizeDelta =
|
||||
new Vector2(legend.itemWidth, legend.itemHeight);
|
||||
Text txt = btn.GetComponentInChildren<Text>();
|
||||
txt.transform.GetComponent<RectTransform>().sizeDelta =
|
||||
new Vector2(legend.itemWidth, legend.itemHeight);
|
||||
txt.transform.localPosition = Vector3.zero;
|
||||
btn.transform.localPosition = GetLegendPosition(i);
|
||||
btn.gameObject.SetActive(legend.show);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnLegendDataListChanged()
|
||||
{
|
||||
InitLegend();
|
||||
}
|
||||
|
||||
protected virtual void OnYMaxValueChanged()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnLegendButtonClicked()
|
||||
{
|
||||
}
|
||||
|
||||
public void RefreshChart()
|
||||
{
|
||||
int tempWid = (int)chartWid;
|
||||
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid - 1);
|
||||
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid);
|
||||
}
|
||||
|
||||
protected virtual void RefreshTooltip()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
vh.Clear();
|
||||
DrawBackground(vh);
|
||||
DrawChart(vh);
|
||||
DrawTooltip(vh);
|
||||
}
|
||||
|
||||
protected virtual void DrawChart(VertexHelper vh)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void DrawTooltip(VertexHelper vh)
|
||||
{
|
||||
}
|
||||
|
||||
private void DrawBackground(VertexHelper vh)
|
||||
{
|
||||
// draw bg
|
||||
Vector3 p1 = new Vector3(0, chartHig);
|
||||
Vector3 p2 = new Vector3(chartWid, chartHig);
|
||||
Vector3 p3 = new Vector3(chartWid, 0);
|
||||
Vector3 p4 = new Vector3(0, 0);
|
||||
ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, themeInfo.backgroundColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public enum Theme
|
||||
{
|
||||
Default = 1,
|
||||
Light,
|
||||
Dark
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class ThemeInfo
|
||||
{
|
||||
public Font font;
|
||||
public Color32 backgroundColor;
|
||||
public Color32 contrastColor;
|
||||
public Color32 textColor;
|
||||
public Color32 subTextColor;
|
||||
public Color32 unableColor;
|
||||
|
||||
public Color32 axisLineColor;
|
||||
public Color32 axisSplitLineColor;
|
||||
|
||||
public Color32 tooltipBackgroundColor;
|
||||
public Color32 tooltipFlagAreaColor;
|
||||
public Color32 tooltipTextColor;
|
||||
|
||||
public Color32[] colorPalette;
|
||||
|
||||
public Color32 GetColor(int index)
|
||||
{
|
||||
if(index < 0)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
index = index % colorPalette.Length;
|
||||
return colorPalette[index];
|
||||
}
|
||||
|
||||
public void Copy(ThemeInfo theme)
|
||||
{
|
||||
font = theme.font;
|
||||
backgroundColor = theme.backgroundColor;
|
||||
contrastColor = theme.contrastColor;
|
||||
unableColor = theme.unableColor;
|
||||
textColor = theme.textColor;
|
||||
subTextColor = theme.subTextColor;
|
||||
axisLineColor = theme.axisLineColor;
|
||||
axisSplitLineColor = theme.axisSplitLineColor;
|
||||
tooltipBackgroundColor = theme.tooltipBackgroundColor;
|
||||
tooltipTextColor = theme.tooltipTextColor;
|
||||
colorPalette = new Color32[theme.colorPalette.Length];
|
||||
for(int i = 0; i < theme.colorPalette.Length; i++)
|
||||
{
|
||||
colorPalette[i] = theme.colorPalette[i];
|
||||
}
|
||||
}
|
||||
|
||||
public static ThemeInfo Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ThemeInfo()
|
||||
{
|
||||
font = Resources.GetBuiltinResource<Font>("Arial.ttf"),
|
||||
backgroundColor = new Color32(255, 255, 255, 255),
|
||||
contrastColor = GetColor("#514D4D"),
|
||||
unableColor = GetColor("#cccccc"),
|
||||
textColor = GetColor("#514D4D"),
|
||||
subTextColor = GetColor("#514D4D"),
|
||||
axisLineColor = GetColor("#514D4D"),
|
||||
axisSplitLineColor = GetColor("#AB9999"),
|
||||
tooltipBackgroundColor = GetColor("#515151B5"),
|
||||
tooltipTextColor = GetColor("#FFFFFFFF"),
|
||||
tooltipFlagAreaColor = GetColor("#51515120"),
|
||||
colorPalette = new Color32[]
|
||||
{
|
||||
new Color32(194, 53, 49, 255),
|
||||
new Color32(47, 69, 84, 255),
|
||||
new Color32(97, 160, 168, 255),
|
||||
new Color32(212, 130, 101, 255),
|
||||
new Color32(145, 199, 174, 255),
|
||||
new Color32(116, 159, 131, 255),
|
||||
new Color32(202, 134, 34, 255),
|
||||
new Color32(189, 162, 154, 255),
|
||||
new Color32(110, 112, 116, 255),
|
||||
new Color32(84, 101, 112, 255),
|
||||
new Color32(196, 204, 211, 255)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static ThemeInfo Light
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ThemeInfo()
|
||||
{
|
||||
font = Resources.GetBuiltinResource<Font>("Arial.ttf"),
|
||||
backgroundColor = new Color32(255, 255, 255, 255),
|
||||
contrastColor = GetColor("#514D4D"),
|
||||
unableColor = GetColor("#cccccc"),
|
||||
textColor = GetColor("#514D4D"),
|
||||
subTextColor = GetColor("#514D4D"),
|
||||
axisLineColor = GetColor("#514D4D"),
|
||||
axisSplitLineColor = GetColor("#AB9999"),
|
||||
tooltipBackgroundColor = GetColor("#515151B5"),
|
||||
tooltipTextColor = GetColor("#FFFFFFFF"),
|
||||
tooltipFlagAreaColor = GetColor("#51515120"),
|
||||
colorPalette = new Color32[]
|
||||
{
|
||||
new Color32(55, 162, 218, 255),
|
||||
new Color32(255, 159, 127, 255),
|
||||
new Color32(50, 197, 233, 255),
|
||||
new Color32(251, 114, 147, 255),
|
||||
new Color32(103, 224, 227, 255),
|
||||
new Color32(224, 98, 174, 255),
|
||||
new Color32(159, 230, 184, 255),
|
||||
new Color32(230, 144, 209, 255),
|
||||
new Color32(255, 219, 92, 255),
|
||||
new Color32(230, 188, 243, 255),
|
||||
new Color32(157, 150, 245, 255),
|
||||
new Color32(131, 120, 234, 255),
|
||||
new Color32(150, 191, 255, 255)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static ThemeInfo Dark
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ThemeInfo()
|
||||
{
|
||||
font = Resources.GetBuiltinResource<Font>("Arial.ttf"),
|
||||
unableColor = GetColor("#cccccc"),
|
||||
backgroundColor = new Color32(34, 34, 34, 255),
|
||||
contrastColor = GetColor("#eee"),
|
||||
textColor = GetColor("#eee"),
|
||||
subTextColor = GetColor("#eee"),
|
||||
axisLineColor = GetColor("#eee"),
|
||||
axisSplitLineColor = GetColor("#aaa"),
|
||||
tooltipBackgroundColor = GetColor("#515151B5"),
|
||||
tooltipTextColor = GetColor("#FFFFFFFF"),
|
||||
tooltipFlagAreaColor = GetColor("#51515120"),
|
||||
colorPalette = new Color32[]
|
||||
{
|
||||
new Color32(221, 107, 102, 255),
|
||||
new Color32(117, 154, 160, 255),
|
||||
new Color32(230, 157, 135, 255),
|
||||
new Color32(141, 193, 169, 255),
|
||||
new Color32(234, 126, 83, 255),
|
||||
new Color32(238, 221, 120, 255),
|
||||
new Color32(115, 163, 115, 255),
|
||||
new Color32(115, 185, 188, 255),
|
||||
new Color32(114, 137, 171, 255),
|
||||
new Color32(145, 202, 140, 255),
|
||||
new Color32(244, 159, 66, 255)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static Color32 GetColor(string hexColorStr)
|
||||
{
|
||||
Color color;
|
||||
ColorUtility.TryParseHtmlString(hexColorStr,out color);
|
||||
return (Color32)color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
Scripts/Editor.meta
Normal file
10
Scripts/Editor.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ed45d2c9978fbf4aac0915d767f8853
|
||||
folderAsset: yes
|
||||
timeCreated: 1554216875
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Scripts/Editor/BarChartEditor.cs
Normal file
31
Scripts/Editor/BarChartEditor.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Editor class used to edit UI BarChart.
|
||||
/// </summary>
|
||||
|
||||
[CustomEditor(typeof(BarChart), false)]
|
||||
public class BarChartEditor : CoordinateChartEditor
|
||||
{
|
||||
protected SerializedProperty m_Bar;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
m_Target = (BarChart)target;
|
||||
m_Bar = serializedObject.FindProperty("m_Bar");
|
||||
}
|
||||
|
||||
protected override void OnEndInspectorGUI()
|
||||
{
|
||||
base.OnEndInspectorGUI();
|
||||
if (m_Target == null && target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
EditorGUILayout.PropertyField(m_Bar, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c6931b54797f3f46b892afcfb70c79d
|
||||
timeCreated: 1538089241
|
||||
guid: 5acea6fd06c0e9c498c434f941e4cba9
|
||||
timeCreated: 1554219116
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
115
Scripts/Editor/BaseChartEditor.cs
Normal file
115
Scripts/Editor/BaseChartEditor.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Editor class used to edit UI BaseChart.
|
||||
/// </summary>
|
||||
|
||||
[CustomEditor(typeof(BaseChart), false)]
|
||||
public class BaseChartEditor : Editor
|
||||
{
|
||||
protected BaseChart m_Target;
|
||||
protected SerializedProperty m_Script;
|
||||
protected SerializedProperty m_Theme;
|
||||
protected SerializedProperty m_ThemeInfo;
|
||||
protected SerializedProperty m_Title;
|
||||
protected SerializedProperty m_Legend;
|
||||
protected SerializedProperty m_Tooltip;
|
||||
protected SerializedProperty m_Series;
|
||||
|
||||
protected SerializedProperty m_Large;
|
||||
protected SerializedProperty m_MinShowDataNumber;
|
||||
protected SerializedProperty m_MaxShowDataNumber;
|
||||
protected SerializedProperty m_MaxCacheDataNumber;
|
||||
|
||||
protected float m_DefaultLabelWidth;
|
||||
protected float m_DefaultFieldWidth;
|
||||
|
||||
private int m_SeriesSize;
|
||||
|
||||
|
||||
private bool m_ThemeModuleToggle = false;
|
||||
private bool m_BaseModuleToggle = false;
|
||||
|
||||
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
m_Target = (BaseChart)target;
|
||||
m_Script = serializedObject.FindProperty("m_Script");
|
||||
m_Theme = serializedObject.FindProperty("m_Theme");
|
||||
m_ThemeInfo = serializedObject.FindProperty("m_ThemeInfo");
|
||||
m_Title = serializedObject.FindProperty("m_Title");
|
||||
m_Legend = serializedObject.FindProperty("m_Legend");
|
||||
m_Tooltip = serializedObject.FindProperty("m_Tooltip");
|
||||
m_Series = serializedObject.FindProperty("m_Series");
|
||||
|
||||
m_Large = serializedObject.FindProperty("m_Large");
|
||||
m_MinShowDataNumber = serializedObject.FindProperty("m_MinShowDataNumber");
|
||||
m_MaxShowDataNumber = serializedObject.FindProperty("m_MaxShowDataNumber");
|
||||
m_MaxCacheDataNumber = serializedObject.FindProperty("m_MaxCacheDataNumber");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (m_Target == null && target == null)
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
return;
|
||||
}
|
||||
serializedObject.Update();
|
||||
m_DefaultLabelWidth = EditorGUIUtility.labelWidth;
|
||||
m_DefaultFieldWidth = EditorGUIUtility.fieldWidth;
|
||||
|
||||
OnStartInspectorGUI();
|
||||
OnMiddleInspectorGUI();
|
||||
OnEndInspectorGUI();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
protected virtual void OnStartInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_Script);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUIUtility.fieldWidth = EditorGUIUtility.labelWidth -5;
|
||||
m_ThemeModuleToggle = EditorGUILayout.Foldout(m_ThemeModuleToggle, "Theme", ChartEditorHelper.foldoutStyle);
|
||||
EditorGUILayout.PropertyField(m_Theme, GUIContent.none);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUIUtility.labelWidth = m_DefaultLabelWidth;
|
||||
EditorGUIUtility.fieldWidth = m_DefaultFieldWidth;
|
||||
if (m_ThemeModuleToggle)
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_ThemeInfo, true);
|
||||
}
|
||||
EditorGUILayout.PropertyField(m_Title, true);
|
||||
EditorGUILayout.PropertyField(m_Legend, true);
|
||||
EditorGUILayout.PropertyField(m_Tooltip, true);
|
||||
}
|
||||
|
||||
protected virtual void OnMiddleInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_Series,true);
|
||||
m_BaseModuleToggle = EditorGUILayout.Foldout(m_BaseModuleToggle, "Base", ChartEditorHelper.foldoutStyle);
|
||||
if (m_BaseModuleToggle)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(m_Large, true);
|
||||
EditorGUILayout.PropertyField(m_MinShowDataNumber, true);
|
||||
EditorGUILayout.PropertyField(m_MaxShowDataNumber, true);
|
||||
EditorGUILayout.PropertyField(m_MaxCacheDataNumber, true);
|
||||
if (m_MinShowDataNumber.intValue < 0) m_MinShowDataNumber.intValue = 0;
|
||||
if (m_MaxShowDataNumber.intValue < 0) m_MaxShowDataNumber.intValue = 0;
|
||||
if (m_MaxCacheDataNumber.intValue < 0) m_MaxCacheDataNumber.intValue = 0;
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnEndInspectorGUI()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/BaseChartEditor.cs.meta
Normal file
13
Scripts/Editor/BaseChartEditor.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7f1cff1e5bae244a872040086b1cfa8
|
||||
timeCreated: 1554217495
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Scripts/Editor/CoordinateChartEditor.cs
Normal file
33
Scripts/Editor/CoordinateChartEditor.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Editor class used to edit UI BarChart.
|
||||
/// </summary>
|
||||
|
||||
[CustomEditor(typeof(CoordinateChart), false)]
|
||||
public class CoordinateChartEditor : BaseChartEditor
|
||||
{
|
||||
protected SerializedProperty m_Coordinate;
|
||||
protected SerializedProperty m_XAxis;
|
||||
protected SerializedProperty m_YAxis;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
m_Target = (CoordinateChart)target;
|
||||
m_Coordinate = serializedObject.FindProperty("m_Coordinate");
|
||||
m_XAxis = serializedObject.FindProperty("m_XAxis");
|
||||
m_YAxis = serializedObject.FindProperty("m_YAxis");
|
||||
}
|
||||
|
||||
protected override void OnStartInspectorGUI()
|
||||
{
|
||||
base.OnStartInspectorGUI();
|
||||
EditorGUILayout.PropertyField(m_Coordinate);
|
||||
EditorGUILayout.PropertyField(m_XAxis);
|
||||
EditorGUILayout.PropertyField(m_YAxis);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/CoordinateChartEditor.cs.meta
Normal file
13
Scripts/Editor/CoordinateChartEditor.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1dd7acd8b13f3f14e9891af4e8dd0b0b
|
||||
timeCreated: 1554475249
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Scripts/Editor/LineChartEditor.cs
Normal file
27
Scripts/Editor/LineChartEditor.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Editor class used to edit UI LineChart.
|
||||
/// </summary>
|
||||
|
||||
[CustomEditor(typeof(LineChart), false)]
|
||||
public class LineChartEditor : CoordinateChartEditor
|
||||
{
|
||||
protected SerializedProperty m_Line;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
m_Target = (LineChart)target;
|
||||
m_Line = serializedObject.FindProperty("m_Line");
|
||||
}
|
||||
|
||||
protected override void OnEndInspectorGUI()
|
||||
{
|
||||
base.OnEndInspectorGUI();
|
||||
EditorGUILayout.PropertyField(m_Line, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/LineChartEditor.cs.meta
Normal file
13
Scripts/Editor/LineChartEditor.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bd1a238bc5b407408b8f902aa3db9fd
|
||||
timeCreated: 1554539035
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Scripts/Editor/PieChartEditor.cs
Normal file
27
Scripts/Editor/PieChartEditor.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Editor class used to edit UI PieChart.
|
||||
/// </summary>
|
||||
|
||||
[CustomEditor(typeof(PieChart), false)]
|
||||
public class PieChartEditor : BaseChartEditor
|
||||
{
|
||||
protected SerializedProperty m_Pie;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
m_Target = (PieChart)target;
|
||||
m_Pie = serializedObject.FindProperty("m_Pie");
|
||||
}
|
||||
|
||||
protected override void OnEndInspectorGUI()
|
||||
{
|
||||
base.OnEndInspectorGUI();
|
||||
EditorGUILayout.PropertyField(m_Pie, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PieChartEditor.cs.meta
Normal file
13
Scripts/Editor/PieChartEditor.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28de30021bed0f945af09633584fcb44
|
||||
timeCreated: 1554768152
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Scripts/Editor/PropertyDrawers.meta
Normal file
10
Scripts/Editor/PropertyDrawers.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ad1e8940e4805b49a18ea7a2cbd4bce
|
||||
folderAsset: yes
|
||||
timeCreated: 1554304641
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
139
Scripts/Editor/PropertyDrawers/AxisDrawer.cs
Normal file
139
Scripts/Editor/PropertyDrawers/AxisDrawer.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Axis), true)]
|
||||
public class AxisDrawer : PropertyDrawer
|
||||
{
|
||||
private ReorderableList m_DataList;
|
||||
private bool m_DataFoldout = false;
|
||||
private int m_DataSize = 0;
|
||||
private bool m_ShowJsonDataArea = false;
|
||||
private string m_JsonDataAreaText;
|
||||
private bool m_AxisModuleToggle = false;
|
||||
|
||||
private void InitReorderableList(SerializedProperty prop)
|
||||
{
|
||||
if (m_DataList == null)
|
||||
{
|
||||
SerializedProperty data = prop.FindPropertyRelative("m_Data");
|
||||
m_DataList = new ReorderableList(data.serializedObject, data, false, false, true, true);
|
||||
m_DataList.elementHeight = EditorGUIUtility.singleLineHeight;
|
||||
m_DataList.drawHeaderCallback += delegate (Rect rect)
|
||||
{
|
||||
EditorGUI.LabelField(rect, data.displayName);
|
||||
};
|
||||
|
||||
m_DataList.drawElementCallback = delegate (Rect rect, int index, bool isActive, bool isFocused)
|
||||
{
|
||||
EditorGUI.PropertyField(rect, data.GetArrayElementAtIndex(index), true);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
SerializedProperty m_Show = prop.FindPropertyRelative("m_Show");
|
||||
SerializedProperty m_Type = prop.FindPropertyRelative("m_Type");
|
||||
SerializedProperty m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber");
|
||||
SerializedProperty m_TextRotation = prop.FindPropertyRelative("m_TextRotation");
|
||||
SerializedProperty m_ShowSplitLine = prop.FindPropertyRelative("m_ShowSplitLine");
|
||||
SerializedProperty m_SplitLineType = prop.FindPropertyRelative("m_SplitLineType");
|
||||
SerializedProperty m_BoundaryGap = prop.FindPropertyRelative("m_BoundaryGap");
|
||||
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
||||
SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick");
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisModuleToggle, prop.displayName, m_Show);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_AxisModuleToggle)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUI.PropertyField(drawRect, m_Type);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_SplitNumber);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_TextRotation);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_ShowSplitLine.boolValue)
|
||||
{
|
||||
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
||||
EditorGUI.PropertyField(drawRect, m_ShowSplitLine);
|
||||
//drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.x = EditorGUIUtility.labelWidth + 35;
|
||||
drawRect.width = EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - 55;
|
||||
EditorGUI.PropertyField(drawRect, m_SplitLineType, GUIContent.none);
|
||||
drawRect.x = pos.x;
|
||||
drawRect.width = pos.width;
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.PropertyField(drawRect, m_ShowSplitLine);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
EditorGUI.PropertyField(drawRect, m_BoundaryGap);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_AxisTick);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisTick);
|
||||
Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex;
|
||||
if (type == Axis.AxisType.Category)
|
||||
{
|
||||
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
||||
m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Data");
|
||||
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop);
|
||||
drawRect.width = pos.width;
|
||||
if (m_DataFoldout)
|
||||
{
|
||||
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Data);
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
if (!m_AxisModuleToggle)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
SerializedProperty m_Type = prop.FindPropertyRelative("m_Type");
|
||||
SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick");
|
||||
float height = 0;
|
||||
height += 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
|
||||
Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex;
|
||||
if (type == Axis.AxisType.Category)
|
||||
{
|
||||
if (m_DataFoldout)
|
||||
{
|
||||
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
||||
int num = m_Data.arraySize + 2;
|
||||
if (num > 50) num = 13;
|
||||
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
|
||||
height += EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
if (m_ShowJsonDataArea)
|
||||
{
|
||||
height += EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
height += EditorGUI.GetPropertyHeight(m_AxisTick);
|
||||
return height;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/AxisDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/AxisDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0544f1db7f17644bb3cbe7c85da84d5
|
||||
timeCreated: 1554507809
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Scripts/Editor/PropertyDrawers/AxisTickDrawer.cs
Normal file
46
Scripts/Editor/PropertyDrawers/AxisTickDrawer.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Axis.AxisTick), true)]
|
||||
public class AxisTickDrawer : PropertyDrawer
|
||||
{
|
||||
private bool m_AxisTickToggle = false;
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
SerializedProperty show = prop.FindPropertyRelative("m_Show");
|
||||
SerializedProperty m_AlignWithLabel = prop.FindPropertyRelative("m_AlignWithLabel");
|
||||
SerializedProperty m_Inside = prop.FindPropertyRelative("m_Inside");
|
||||
SerializedProperty m_Length = prop.FindPropertyRelative("m_Length");
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisTickToggle, "Axis Tick", show, false);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_AxisTickToggle)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_AlignWithLabel);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Inside);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Length);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
float height = 0;
|
||||
if (m_AxisTickToggle)
|
||||
{
|
||||
height += 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/AxisTickDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/AxisTickDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c7d45bc59dedc140b08f6e9d26ccd9d
|
||||
timeCreated: 1555890921
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
48
Scripts/Editor/PropertyDrawers/BarDrawer.cs
Normal file
48
Scripts/Editor/PropertyDrawers/BarDrawer.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(BarChart.Bar), true)]
|
||||
public class BarDrawer : PropertyDrawer
|
||||
{
|
||||
SerializedProperty m_BarWidth;
|
||||
SerializedProperty m_Space;
|
||||
bool m_BarModuleToggle = true;
|
||||
|
||||
private void InitProperty(SerializedProperty prop)
|
||||
{
|
||||
m_BarWidth = prop.FindPropertyRelative("m_BarWidth");
|
||||
m_Space = prop.FindPropertyRelative("m_Space");
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
InitProperty(prop);
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_BarModuleToggle, "Bar");
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
if (m_BarModuleToggle)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_BarWidth);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Space);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
if (m_BarModuleToggle)
|
||||
return 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
|
||||
else
|
||||
return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/BarDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/BarDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a443d39bebe073645a240a745feb9fc5
|
||||
timeCreated: 1554768582
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
54
Scripts/Editor/PropertyDrawers/CoordinateDrawer.cs
Normal file
54
Scripts/Editor/PropertyDrawers/CoordinateDrawer.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Coordinate), true)]
|
||||
public class CoordinateDrawer : PropertyDrawer
|
||||
{
|
||||
private bool m_CoordinateModuleToggle = false;
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
SerializedProperty m_Left = prop.FindPropertyRelative("m_Left");
|
||||
SerializedProperty m_Right = prop.FindPropertyRelative("m_Right");
|
||||
SerializedProperty m_Top = prop.FindPropertyRelative("m_Top");
|
||||
SerializedProperty m_Bottom = prop.FindPropertyRelative("m_Bottom");
|
||||
SerializedProperty m_Tickness = prop.FindPropertyRelative("m_Tickness");
|
||||
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_CoordinateModuleToggle, "Coordinate");
|
||||
EditorGUI.LabelField(drawRect, "Coordinate",EditorStyles.boldLabel);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_CoordinateModuleToggle)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_Left);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Right);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Top);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Bottom);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Tickness);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_FontSize);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
if (m_CoordinateModuleToggle)
|
||||
return 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
|
||||
else
|
||||
return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/CoordinateDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/CoordinateDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38e8e72dd7107db429232ccab308e27c
|
||||
timeCreated: 1554506762
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
83
Scripts/Editor/PropertyDrawers/LegendDrawer.cs
Normal file
83
Scripts/Editor/PropertyDrawers/LegendDrawer.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Legend), true)]
|
||||
public class LegendDrawer : PropertyDrawer
|
||||
{
|
||||
private bool m_DataFoldout = false;
|
||||
private int m_DataSize = 0;
|
||||
private bool m_ShowJsonDataArea = false;
|
||||
private string m_JsonDataAreaText;
|
||||
private bool m_LegendModuleToggle = false;
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
SerializedProperty show = prop.FindPropertyRelative("m_Show");
|
||||
SerializedProperty orient = prop.FindPropertyRelative("m_Orient");
|
||||
SerializedProperty location = prop.FindPropertyRelative("m_Location");
|
||||
SerializedProperty itemWidth = prop.FindPropertyRelative("m_ItemWidth");
|
||||
SerializedProperty itemHeight = prop.FindPropertyRelative("m_ItemHeight");
|
||||
SerializedProperty itemGap = prop.FindPropertyRelative("m_ItemGap");
|
||||
SerializedProperty itemFontSize = prop.FindPropertyRelative("m_ItemFontSize");
|
||||
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_LegendModuleToggle, "Legend", show);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_LegendModuleToggle)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, itemWidth);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, itemHeight);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, itemGap);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, itemFontSize);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, orient);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, location);
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(location);
|
||||
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
||||
m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Data");
|
||||
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop);
|
||||
drawRect.width = pos.width;
|
||||
if (m_DataFoldout)
|
||||
{
|
||||
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Data);
|
||||
}
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
float height = 0;
|
||||
if (m_LegendModuleToggle)
|
||||
{
|
||||
SerializedProperty location = prop.FindPropertyRelative("m_Location");
|
||||
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
|
||||
height += EditorGUI.GetPropertyHeight(location);
|
||||
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_DataFoldout)
|
||||
{
|
||||
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
||||
int num = m_Data.arraySize + 1;
|
||||
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
|
||||
height += EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
if (m_ShowJsonDataArea)
|
||||
{
|
||||
height += EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/LegendDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/LegendDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b96d10541649a23468168ba0bf1c0bc5
|
||||
timeCreated: 1554395454
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
93
Scripts/Editor/PropertyDrawers/LineDrawer.cs
Normal file
93
Scripts/Editor/PropertyDrawers/LineDrawer.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Line), true)]
|
||||
public class LineDrawer : PropertyDrawer
|
||||
{
|
||||
SerializedProperty m_Tickness;
|
||||
SerializedProperty m_Point;
|
||||
SerializedProperty m_PointWidth;
|
||||
SerializedProperty m_Smooth;
|
||||
SerializedProperty m_SmoothStyle;
|
||||
SerializedProperty m_Area;
|
||||
|
||||
private bool m_LineModuleToggle = false;
|
||||
|
||||
private void InitProperty(SerializedProperty prop)
|
||||
{
|
||||
m_Tickness = prop.FindPropertyRelative("m_Tickness");
|
||||
m_Point = prop.FindPropertyRelative("m_Point");
|
||||
m_PointWidth = prop.FindPropertyRelative("m_PointWidth");
|
||||
m_Smooth = prop.FindPropertyRelative("m_Smooth");
|
||||
m_SmoothStyle = prop.FindPropertyRelative("m_SmoothStyle");
|
||||
m_Area = prop.FindPropertyRelative("m_Area");
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
InitProperty(prop);
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_LineModuleToggle, "Line");
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_LineModuleToggle)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_Tickness);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
||||
EditorGUI.PropertyField(drawRect, m_Point);
|
||||
if (m_Point.boolValue)
|
||||
{
|
||||
drawRect.x = EditorGUIUtility.labelWidth + 15;
|
||||
EditorGUI.LabelField(drawRect,"Width");
|
||||
drawRect.x = EditorGUIUtility.labelWidth + 65;
|
||||
float tempWidth = EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - 70;
|
||||
if (tempWidth < 20) tempWidth = 20;
|
||||
drawRect.width = tempWidth;
|
||||
EditorGUI.PropertyField(drawRect, m_PointWidth, GUIContent.none);
|
||||
drawRect.x = pos.x;
|
||||
drawRect.width = pos.width;
|
||||
}
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
||||
EditorGUI.PropertyField(drawRect, m_Smooth);
|
||||
if (m_Smooth.boolValue)
|
||||
{
|
||||
drawRect.x = EditorGUIUtility.labelWidth + 15;
|
||||
EditorGUI.LabelField(drawRect, "Style");
|
||||
drawRect.x = EditorGUIUtility.labelWidth + 65;
|
||||
float tempWidth = EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - 70;
|
||||
if (tempWidth < 20) tempWidth = 20;
|
||||
drawRect.width = tempWidth;
|
||||
EditorGUI.PropertyField(drawRect, m_SmoothStyle, GUIContent.none);
|
||||
drawRect.x = pos.x;
|
||||
drawRect.width = pos.width;
|
||||
}
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
EditorGUI.PropertyField(drawRect, m_Area);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
if (m_LineModuleToggle)
|
||||
{
|
||||
return 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/LineDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/LineDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0eeb8c12e86239b4e93a6c75d766cb15
|
||||
timeCreated: 1554720052
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
87
Scripts/Editor/PropertyDrawers/LocationDrawer.cs
Normal file
87
Scripts/Editor/PropertyDrawers/LocationDrawer.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Location), true)]
|
||||
public class LocationDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
SerializedProperty align = prop.FindPropertyRelative("m_Align");
|
||||
SerializedProperty left = prop.FindPropertyRelative("m_Left");
|
||||
SerializedProperty right = prop.FindPropertyRelative("m_Right");
|
||||
SerializedProperty top = prop.FindPropertyRelative("m_Top");
|
||||
SerializedProperty bottom = prop.FindPropertyRelative("m_Bottom");
|
||||
EditorGUI.PropertyField(drawRect, align, new GUIContent("Location"));
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
++EditorGUI.indentLevel;
|
||||
switch ((Location.Align)align.enumValueIndex)
|
||||
{
|
||||
case Location.Align.TopCenter:
|
||||
EditorGUI.PropertyField(drawRect, top);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
break;
|
||||
case Location.Align.TopLeft:
|
||||
EditorGUI.PropertyField(drawRect, top);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, left);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
break;
|
||||
case Location.Align.TopRight:
|
||||
EditorGUI.PropertyField(drawRect, top);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, right);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
break;
|
||||
case Location.Align.BottomCenter:
|
||||
EditorGUI.PropertyField(drawRect, bottom);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
break;
|
||||
case Location.Align.BottomLeft:
|
||||
EditorGUI.PropertyField(drawRect, bottom);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, left);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
break;
|
||||
case Location.Align.BottomRight:
|
||||
EditorGUI.PropertyField(drawRect, bottom);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, right);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
break;
|
||||
case Location.Align.Center:
|
||||
break;
|
||||
case Location.Align.CenterLeft:
|
||||
EditorGUI.PropertyField(drawRect, left);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
break;
|
||||
case Location.Align.CenterRight:
|
||||
EditorGUI.PropertyField(drawRect, right);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
break;
|
||||
}
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
SerializedProperty align = prop.FindPropertyRelative("m_Align");
|
||||
switch ((Location.Align)align.enumValueIndex)
|
||||
{
|
||||
case Location.Align.Center:
|
||||
return 1 * EditorGUIUtility.singleLineHeight + 0 * EditorGUIUtility.standardVerticalSpacing;
|
||||
case Location.Align.TopCenter:
|
||||
case Location.Align.BottomCenter:
|
||||
case Location.Align.CenterLeft:
|
||||
case Location.Align.CenterRight:
|
||||
return 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||
default:
|
||||
return 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/LocationDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/LocationDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34092595791508d4b94b074a8788c388
|
||||
timeCreated: 1554307767
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
79
Scripts/Editor/PropertyDrawers/PieDrawer.cs
Normal file
79
Scripts/Editor/PropertyDrawers/PieDrawer.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Pie), true)]
|
||||
public class PieInfoDrawer : PropertyDrawer
|
||||
{
|
||||
SerializedProperty m_Name;
|
||||
SerializedProperty m_InsideRadius;
|
||||
SerializedProperty m_OutsideRadius;
|
||||
SerializedProperty m_TooltipExtraRadius;
|
||||
SerializedProperty m_Rose;
|
||||
SerializedProperty m_Space;
|
||||
SerializedProperty m_Left;
|
||||
SerializedProperty m_Right;
|
||||
SerializedProperty m_Top;
|
||||
SerializedProperty m_Bottom;
|
||||
bool m_PieModuleToggle = true;
|
||||
|
||||
private void InitProperty(SerializedProperty prop)
|
||||
{
|
||||
m_Name = prop.FindPropertyRelative("m_Name");
|
||||
m_InsideRadius = prop.FindPropertyRelative("m_InsideRadius");
|
||||
m_OutsideRadius = prop.FindPropertyRelative("m_OutsideRadius");
|
||||
m_TooltipExtraRadius = prop.FindPropertyRelative("m_TooltipExtraRadius");
|
||||
m_Rose = prop.FindPropertyRelative("m_Rose");
|
||||
m_Space = prop.FindPropertyRelative("m_Space");
|
||||
m_Left = prop.FindPropertyRelative("m_Left");
|
||||
m_Right = prop.FindPropertyRelative("m_Right");
|
||||
m_Top = prop.FindPropertyRelative("m_Top");
|
||||
m_Bottom = prop.FindPropertyRelative("m_Bottom");
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
InitProperty(prop);
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_PieModuleToggle, "Pie");
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_PieModuleToggle)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_Name);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_InsideRadius);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_OutsideRadius);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_TooltipExtraRadius);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Rose);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Space);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Left);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Right);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Top);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Bottom);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
if (m_PieModuleToggle)
|
||||
return 11 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
|
||||
else
|
||||
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/PieDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/PieDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 019eadbd43e952945925f357ae8ef74b
|
||||
timeCreated: 1554773154
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
158
Scripts/Editor/PropertyDrawers/RadarDrawer.cs
Normal file
158
Scripts/Editor/PropertyDrawers/RadarDrawer.cs
Normal file
@@ -0,0 +1,158 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Radar), true)]
|
||||
public class RadarDrawer : PropertyDrawer
|
||||
{
|
||||
SerializedProperty m_Cricle;
|
||||
SerializedProperty m_Area;
|
||||
SerializedProperty m_Radius;
|
||||
SerializedProperty m_SplitNumber;
|
||||
SerializedProperty m_Left;
|
||||
SerializedProperty m_Right;
|
||||
SerializedProperty m_Top;
|
||||
SerializedProperty m_Bottom;
|
||||
SerializedProperty m_LineTickness;
|
||||
SerializedProperty m_LinePointSize;
|
||||
SerializedProperty m_LineColor;
|
||||
SerializedProperty m_BackgroundColorList;
|
||||
SerializedProperty m_Indicator;
|
||||
SerializedProperty m_IndicatorList;
|
||||
|
||||
private bool m_RadarModuleToggle = false;
|
||||
private bool m_IndicatorToggle = false;
|
||||
private bool m_IndicatorJsonAreaToggle = false;
|
||||
private string m_IndicatorJsonAreaText;
|
||||
private int m_IndicatorSize;
|
||||
private bool m_BackgroundColorToggle = false;
|
||||
private int m_BackgroundColorSize;
|
||||
|
||||
private void InitProperty(SerializedProperty prop)
|
||||
{
|
||||
m_Cricle = prop.FindPropertyRelative("m_Cricle");
|
||||
m_Area = prop.FindPropertyRelative("m_Area");
|
||||
m_Radius = prop.FindPropertyRelative("m_Radius");
|
||||
m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber");
|
||||
m_Left = prop.FindPropertyRelative("m_Left");
|
||||
m_Right = prop.FindPropertyRelative("m_Right");
|
||||
m_Top = prop.FindPropertyRelative("m_Top");
|
||||
m_Bottom = prop.FindPropertyRelative("m_Bottom");
|
||||
m_LineTickness = prop.FindPropertyRelative("m_LineTickness");
|
||||
m_LinePointSize = prop.FindPropertyRelative("m_LinePointSize");
|
||||
m_LineColor = prop.FindPropertyRelative("m_LineColor");
|
||||
m_BackgroundColorList = prop.FindPropertyRelative("m_BackgroundColorList");
|
||||
m_Indicator = prop.FindPropertyRelative("m_Indicator");
|
||||
m_IndicatorList = prop.FindPropertyRelative("m_IndicatorList");
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
InitProperty(prop);
|
||||
Rect drawRect = pos;
|
||||
float defaultLabelWidth = EditorGUIUtility.labelWidth;
|
||||
float defaultFieldWidth = EditorGUIUtility.fieldWidth;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_RadarModuleToggle, "Radar");
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_RadarModuleToggle)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
|
||||
EditorGUIUtility.fieldWidth = 10;
|
||||
|
||||
EditorGUIUtility.labelWidth = 50;
|
||||
drawRect.width = 60;
|
||||
EditorGUI.PropertyField(drawRect, m_Cricle);
|
||||
|
||||
EditorGUIUtility.labelWidth = 45;
|
||||
drawRect.x += 60;
|
||||
EditorGUI.PropertyField(drawRect, m_Area);
|
||||
|
||||
EditorGUIUtility.labelWidth = 70;
|
||||
drawRect.x += 55;
|
||||
drawRect.width = 80;
|
||||
EditorGUI.PropertyField(drawRect, m_Indicator);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.x = pos.x;
|
||||
drawRect.width = pos.width;
|
||||
EditorGUIUtility.labelWidth = defaultLabelWidth;
|
||||
EditorGUIUtility.fieldWidth = defaultFieldWidth;
|
||||
EditorGUI.PropertyField(drawRect, m_Radius);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_SplitNumber);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Left);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Right);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Top);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Bottom);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_LineTickness);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_LinePointSize);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_LineColor);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
m_BackgroundColorToggle = EditorGUI.Foldout(drawRect, m_BackgroundColorToggle, "BackgroundColors");
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.width = pos.width;
|
||||
if (m_BackgroundColorToggle)
|
||||
{
|
||||
ChartEditorHelper.MakeList(ref drawRect, ref m_BackgroundColorSize, m_BackgroundColorList);
|
||||
}
|
||||
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
||||
m_IndicatorToggle = EditorGUI.Foldout(drawRect, m_IndicatorToggle, "Indicators");
|
||||
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_IndicatorJsonAreaToggle, ref m_IndicatorJsonAreaText, prop);
|
||||
drawRect.width = pos.width;
|
||||
if (m_IndicatorToggle)
|
||||
{
|
||||
ChartEditorHelper.MakeList(ref drawRect, ref m_IndicatorSize, m_IndicatorList);
|
||||
}
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
int propNum = 1;
|
||||
if (m_RadarModuleToggle)
|
||||
{
|
||||
propNum += 12;
|
||||
|
||||
if (m_BackgroundColorToggle)
|
||||
{
|
||||
m_BackgroundColorList = prop.FindPropertyRelative("m_BackgroundColorList");
|
||||
propNum += 2;
|
||||
propNum += m_BackgroundColorList.arraySize;
|
||||
}
|
||||
if (m_IndicatorJsonAreaToggle) propNum += 4;
|
||||
|
||||
|
||||
float height = propNum * EditorGUIUtility.singleLineHeight + (propNum -1) * EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
if (m_IndicatorToggle)
|
||||
{
|
||||
m_IndicatorList = prop.FindPropertyRelative("m_IndicatorList");
|
||||
height += EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
for(int i = 0; i < m_IndicatorSize; i++)
|
||||
{
|
||||
height += EditorGUI.GetPropertyHeight(m_IndicatorList.GetArrayElementAtIndex(i));
|
||||
}
|
||||
}
|
||||
return height;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/RadarDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/RadarDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09bf71ecf64f321468ac28af28bec878
|
||||
timeCreated: 1555563898
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
58
Scripts/Editor/PropertyDrawers/RadarIndicatorDrawer.cs
Normal file
58
Scripts/Editor/PropertyDrawers/RadarIndicatorDrawer.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Radar.Indicator), true)]
|
||||
public class RadarIndicatorDrawer : PropertyDrawer
|
||||
{
|
||||
SerializedProperty m_Name;
|
||||
SerializedProperty m_Max;
|
||||
|
||||
private bool m_RadarModuleToggle = false;
|
||||
|
||||
private void InitProperty(SerializedProperty prop)
|
||||
{
|
||||
m_Name = prop.FindPropertyRelative("m_Name");
|
||||
m_Max = prop.FindPropertyRelative("m_Max");
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
InitProperty(prop);
|
||||
Rect drawRect = pos;
|
||||
float defaultLabelWidth = EditorGUIUtility.labelWidth;
|
||||
float defaultFieldWidth = EditorGUIUtility.fieldWidth;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
m_RadarModuleToggle = EditorGUI.Foldout(drawRect, m_RadarModuleToggle, "Indicator");
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_RadarModuleToggle)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
|
||||
EditorGUI.PropertyField(drawRect, m_Name);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Max);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
int propNum = 1;
|
||||
if (m_RadarModuleToggle)
|
||||
{
|
||||
propNum += 2;
|
||||
return propNum * EditorGUIUtility.singleLineHeight + (propNum -1) * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/RadarIndicatorDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/RadarIndicatorDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fb5d2a98871919459956dc252632435
|
||||
timeCreated: 1556220585
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
77
Scripts/Editor/PropertyDrawers/SerieDrawer.cs
Normal file
77
Scripts/Editor/PropertyDrawers/SerieDrawer.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Serie), true)]
|
||||
public class SerieDrawer : PropertyDrawer
|
||||
{
|
||||
private bool m_DataFoldout = false;
|
||||
private int m_DataSize = 0;
|
||||
private bool m_ShowJsonDataArea = false;
|
||||
private string m_JsonDataAreaText;
|
||||
private bool m_SerieModuleToggle = false;
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
SerializedProperty show = prop.FindPropertyRelative("m_Show");
|
||||
//SerializedProperty type = prop.FindPropertyRelative("m_Type");
|
||||
SerializedProperty name = prop.FindPropertyRelative("m_Name");
|
||||
SerializedProperty stack = prop.FindPropertyRelative("m_Stack");
|
||||
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
||||
|
||||
string moduleName = "Serie " + prop.displayName.Split(' ')[1];
|
||||
if (!string.IsNullOrEmpty(name.stringValue))
|
||||
moduleName += ":" + name.stringValue;
|
||||
m_SerieModuleToggle = EditorGUI.Foldout(drawRect, m_SerieModuleToggle, "Serie");
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_SerieModuleToggle)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, show);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, name);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, stack);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
||||
m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Data");
|
||||
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop);
|
||||
drawRect.width = pos.width;
|
||||
if (m_DataFoldout)
|
||||
{
|
||||
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Data);
|
||||
}
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
float height = 0;
|
||||
if (!m_SerieModuleToggle)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_DataFoldout)
|
||||
{
|
||||
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
||||
int num = m_Data.arraySize + 1;
|
||||
if (num > 50) num = 13;
|
||||
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
if (m_ShowJsonDataArea)
|
||||
{
|
||||
height += EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/SerieDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/SerieDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c30d9496b99e39944a6987e390bed91f
|
||||
timeCreated: 1555200849
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Scripts/Editor/PropertyDrawers/SeriesDrawer.cs
Normal file
53
Scripts/Editor/PropertyDrawers/SeriesDrawer.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Series), true)]
|
||||
public class SeriesDrawer : PropertyDrawer
|
||||
{
|
||||
private int m_DataSize = 0;
|
||||
private bool m_ShowJsonDataArea = false;
|
||||
private string m_JsonDataAreaText;
|
||||
private bool m_SeriesModuleToggle = false;
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
SerializedProperty m_Series = prop.FindPropertyRelative("m_Series");
|
||||
|
||||
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SeriesModuleToggle, "Series");
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
//ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop);
|
||||
drawRect.width = pos.width;
|
||||
if (m_SeriesModuleToggle)
|
||||
{
|
||||
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Series);
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
float height = 0;
|
||||
if (m_SeriesModuleToggle)
|
||||
{
|
||||
SerializedProperty m_Data = prop.FindPropertyRelative("m_Series");
|
||||
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||
for (int i = 0; i < m_Data.arraySize; i++)
|
||||
{
|
||||
height += EditorGUI.GetPropertyHeight(m_Data.GetArrayElementAtIndex(i));
|
||||
}
|
||||
}
|
||||
if (m_ShowJsonDataArea)
|
||||
{
|
||||
height += EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/SeriesDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/SeriesDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c2458b1901047547b1a59d097786816
|
||||
timeCreated: 1556016849
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
111
Scripts/Editor/PropertyDrawers/ThemeInfoDrawer.cs
Normal file
111
Scripts/Editor/PropertyDrawers/ThemeInfoDrawer.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(ThemeInfo), true)]
|
||||
public class ThemeInfoDrawer : PropertyDrawer
|
||||
{
|
||||
ReorderableList m_ColorPaletteList;
|
||||
bool m_ColorPaletteFoldout;
|
||||
|
||||
private void InitReorderableList(SerializedProperty prop)
|
||||
{
|
||||
if (m_ColorPaletteList == null)
|
||||
{
|
||||
SerializedProperty colorPalette = prop.FindPropertyRelative("m_ColorPalette");
|
||||
m_ColorPaletteList = new ReorderableList(colorPalette.serializedObject, colorPalette, false, false, true, true);
|
||||
m_ColorPaletteList.elementHeight = EditorGUIUtility.singleLineHeight;
|
||||
m_ColorPaletteList.drawHeaderCallback += delegate (Rect rect)
|
||||
{
|
||||
EditorGUI.LabelField(rect, colorPalette.displayName);
|
||||
};
|
||||
|
||||
m_ColorPaletteList.drawElementCallback = delegate (Rect rect, int index, bool isActive, bool isFocused)
|
||||
{
|
||||
EditorGUI.PropertyField(rect, colorPalette.GetArrayElementAtIndex(index), true);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
SerializedProperty m_Font = prop.FindPropertyRelative("m_Font");
|
||||
SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor");
|
||||
SerializedProperty m_ContrastColor = prop.FindPropertyRelative("m_ContrastColor");
|
||||
SerializedProperty m_TextColor = prop.FindPropertyRelative("m_TextColor");
|
||||
SerializedProperty m_SubTextColor = prop.FindPropertyRelative("m_SubTextColor");
|
||||
SerializedProperty m_LegendTextColor = prop.FindPropertyRelative("m_LegendTextColor");
|
||||
SerializedProperty m_UnableColor = prop.FindPropertyRelative("m_UnableColor");
|
||||
SerializedProperty m_AxisLineColor = prop.FindPropertyRelative("m_AxisLineColor");
|
||||
SerializedProperty m_AxisSplitLineColor = prop.FindPropertyRelative("m_AxisSplitLineColor");
|
||||
SerializedProperty m_TooltipBackgroundColor = prop.FindPropertyRelative("m_TooltipBackgroundColor");
|
||||
SerializedProperty m_TooltipFlagAreaColor = prop.FindPropertyRelative("m_TooltipFlagAreaColor");
|
||||
SerializedProperty m_TooltipTextColor = prop.FindPropertyRelative("m_TooltipTextColor");
|
||||
SerializedProperty m_ColorPalette = prop.FindPropertyRelative("m_ColorPalette");
|
||||
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_Font);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_BackgroundColor);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_ContrastColor);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_TextColor);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_SubTextColor);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_LegendTextColor);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_UnableColor);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_AxisLineColor);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_AxisSplitLineColor);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_TooltipBackgroundColor);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_TooltipFlagAreaColor);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_TooltipTextColor);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
m_ColorPaletteFoldout = EditorGUI.Foldout(drawRect, m_ColorPaletteFoldout, "ColorPalette");
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_ColorPaletteFoldout)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
for (int i = 0; i < m_ColorPalette.arraySize; i++)
|
||||
{
|
||||
SerializedProperty element = m_ColorPalette.GetArrayElementAtIndex(i);
|
||||
EditorGUI.PropertyField(drawRect, element);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
float height = 0;
|
||||
int propertyCount = 12;
|
||||
if (m_ColorPaletteFoldout)
|
||||
{
|
||||
SerializedProperty m_ColorPalette = prop.FindPropertyRelative("m_ColorPalette");
|
||||
propertyCount += m_ColorPalette.arraySize + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyCount += 1;
|
||||
}
|
||||
height += propertyCount * EditorGUIUtility.singleLineHeight + (propertyCount - 1) * EditorGUIUtility.standardVerticalSpacing;
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/ThemeInfoDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/ThemeInfoDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcac1baa719179549b24d7056f7e0cb5
|
||||
timeCreated: 1554541305
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
61
Scripts/Editor/PropertyDrawers/TitleDrawer.cs
Normal file
61
Scripts/Editor/PropertyDrawers/TitleDrawer.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Title), true)]
|
||||
public class TitleDrawer : PropertyDrawer
|
||||
{
|
||||
private bool m_TitleModuleToggle = false;
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
SerializedProperty show = prop.FindPropertyRelative("m_Show");
|
||||
SerializedProperty text = prop.FindPropertyRelative("m_Text");
|
||||
SerializedProperty m_TextFontSize = prop.FindPropertyRelative("m_TextFontSize");
|
||||
SerializedProperty subText = prop.FindPropertyRelative("m_SubText");
|
||||
SerializedProperty m_SubTextFontSize = prop.FindPropertyRelative("m_SubTextFontSize");
|
||||
SerializedProperty m_ItemGap = prop.FindPropertyRelative("m_ItemGap");
|
||||
SerializedProperty location = prop.FindPropertyRelative("m_Location");
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TitleModuleToggle, "Title", show);
|
||||
++EditorGUI.indentLevel;
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_TitleModuleToggle)
|
||||
{
|
||||
EditorGUI.PropertyField(drawRect, text);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_TextFontSize, new GUIContent("Font Size"));
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
--EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, subText);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_SubTextFontSize, new GUIContent("Font Size"));
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_ItemGap, new GUIContent("Item Gap"));
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
--EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, location);
|
||||
}
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
float height = 0;
|
||||
if (m_TitleModuleToggle)
|
||||
{
|
||||
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
|
||||
SerializedProperty location = prop.FindPropertyRelative("m_Location");
|
||||
height += EditorGUI.GetPropertyHeight(location);
|
||||
}
|
||||
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/TitleDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/TitleDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22ae7ec778f27c1409cb9151ce7b9aba
|
||||
timeCreated: 1554304641
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
26
Scripts/Editor/PropertyDrawers/TooltipDrawer.cs
Normal file
26
Scripts/Editor/PropertyDrawers/TooltipDrawer.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Tooltip), true)]
|
||||
public class TooltipDrawer : PropertyDrawer
|
||||
{
|
||||
private bool m_TooltipModuleToggle = false;
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
SerializedProperty show = prop.FindPropertyRelative("m_Show");
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TooltipModuleToggle, "Tooltip", show);
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
return 1 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/PropertyDrawers/TooltipDrawer.cs.meta
Normal file
13
Scripts/Editor/PropertyDrawers/TooltipDrawer.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5600b7009bc024a49800448cece012e2
|
||||
timeCreated: 1554419729
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
Scripts/Editor/RadarChartEditor.cs
Normal file
28
Scripts/Editor/RadarChartEditor.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Editor class used to edit UI RadarChart.
|
||||
/// </summary>
|
||||
|
||||
[CustomEditor(typeof(RadarChart), false)]
|
||||
public class RadarChartEditor : BaseChartEditor
|
||||
{
|
||||
protected SerializedProperty m_Radar;
|
||||
protected bool m_RadarModuleToggle = false;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
m_Target = (RadarChart)target;
|
||||
m_Radar = serializedObject.FindProperty("m_Radar");
|
||||
}
|
||||
|
||||
protected override void OnEndInspectorGUI()
|
||||
{
|
||||
base.OnEndInspectorGUI();
|
||||
EditorGUILayout.PropertyField(m_Radar, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/RadarChartEditor.cs.meta
Normal file
13
Scripts/Editor/RadarChartEditor.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ea6609b1e1634241947b4ef14c38849
|
||||
timeCreated: 1555512890
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Scripts/Editor/Utility.meta
Normal file
10
Scripts/Editor/Utility.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb0b30c9bc2c84f46a99514a69d7e462
|
||||
folderAsset: yes
|
||||
timeCreated: 1555303340
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
113
Scripts/Editor/Utility/ChartEditorHelper.cs
Normal file
113
Scripts/Editor/Utility/ChartEditorHelper.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
public class ChartEditorHelper
|
||||
{
|
||||
public static GUIStyle headerStyle = EditorStyles.boldLabel;
|
||||
public static GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout)
|
||||
{
|
||||
font = headerStyle.font,
|
||||
fontStyle = headerStyle.fontStyle,
|
||||
};
|
||||
|
||||
public static void SecondField(Rect drawRect, SerializedProperty prop)
|
||||
{
|
||||
RectOffset offset = new RectOffset(-(int)EditorGUIUtility.labelWidth, 0, 0, 0);
|
||||
drawRect = offset.Add(drawRect);
|
||||
EditorGUI.PropertyField(drawRect, prop, GUIContent.none);
|
||||
drawRect = offset.Remove(drawRect);
|
||||
}
|
||||
|
||||
public static void MakeJsonData(ref Rect drawRect, ref bool showTextArea, ref string inputString,
|
||||
SerializedProperty prop)
|
||||
{
|
||||
SerializedProperty stringDataProp = prop.FindPropertyRelative("m_JsonData");
|
||||
SerializedProperty needParseProp = prop.FindPropertyRelative("m_DataFromJson");
|
||||
float defalutX = drawRect.x;
|
||||
drawRect.x = EditorGUIUtility.labelWidth + 40;
|
||||
drawRect.width = EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - 60;
|
||||
if (GUI.Button(drawRect, new GUIContent("Parse Json", "Parse data from input json")))
|
||||
{
|
||||
showTextArea = !showTextArea;
|
||||
bool needParse = !showTextArea;
|
||||
if (needParse)
|
||||
{
|
||||
stringDataProp.stringValue = inputString;
|
||||
needParseProp.boolValue = true;
|
||||
}
|
||||
}
|
||||
drawRect.x = defalutX;
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (showTextArea)
|
||||
{
|
||||
drawRect.width = EditorGUIUtility.currentViewWidth - drawRect.x - 20;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight * 3;
|
||||
inputString = EditorGUI.TextArea(drawRect, inputString);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MakeFoldout(ref Rect drawRect, ref bool moduleToggle, string content,
|
||||
SerializedProperty prop = null, bool bold = true)
|
||||
{
|
||||
float defaultWidth = drawRect.width;
|
||||
float defaultX = drawRect.x;
|
||||
drawRect.width = EditorGUIUtility.labelWidth;
|
||||
moduleToggle = EditorGUI.Foldout(drawRect, moduleToggle, content, bold ? foldoutStyle : EditorStyles.foldout);
|
||||
drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2;
|
||||
drawRect.width = EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - 70;
|
||||
if (prop != null)
|
||||
{
|
||||
EditorGUI.PropertyField(drawRect, prop, GUIContent.none);
|
||||
}
|
||||
drawRect.width = defaultWidth;
|
||||
drawRect.x = defaultX;
|
||||
}
|
||||
|
||||
public static void MakeList(ref Rect drawRect, ref int listSize, SerializedProperty listProp, SerializedProperty large = null)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
listSize = listProp.arraySize;
|
||||
listSize = EditorGUI.IntField(drawRect, "Size", listSize);
|
||||
if (listSize < 0) listSize = 0;
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
if (listSize != listProp.arraySize)
|
||||
{
|
||||
while (listSize > listProp.arraySize)
|
||||
listProp.InsertArrayElementAtIndex(listProp.arraySize);
|
||||
while (listSize < listProp.arraySize)
|
||||
listProp.DeleteArrayElementAtIndex(listProp.arraySize - 1);
|
||||
}
|
||||
if (listSize > 50)
|
||||
{
|
||||
SerializedProperty element;
|
||||
int num = listSize > 10 ? 10 : listSize;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
element = listProp.GetArrayElementAtIndex(i);
|
||||
EditorGUI.PropertyField(drawRect, element);
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
if (num >= 10)
|
||||
{
|
||||
EditorGUI.LabelField(drawRect, "...");
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
element = listProp.GetArrayElementAtIndex(listSize - 1);
|
||||
EditorGUI.PropertyField(drawRect, element);
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < listProp.arraySize; i++)
|
||||
{
|
||||
SerializedProperty element = listProp.GetArrayElementAtIndex(i);
|
||||
EditorGUI.PropertyField(drawRect, element);
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
13
Scripts/Editor/Utility/ChartEditorHelper.cs.meta
Normal file
13
Scripts/Editor/Utility/ChartEditorHelper.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd22466b776d93c4cb0b252ee510cc7a
|
||||
timeCreated: 1555303340
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,133 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class LineInfo
|
||||
{
|
||||
public float tickness = 0.8f;
|
||||
|
||||
[Header("Point")]
|
||||
public bool showPoint = true;
|
||||
public float pointWid = 2.5f;
|
||||
|
||||
[Header("Smooth")]
|
||||
public bool smooth = false;
|
||||
|
||||
[Range(1f, 10f)]
|
||||
public float smoothStyle = 2f;
|
||||
|
||||
[Header("Area")]
|
||||
public bool area = false;
|
||||
public Color areaColor;
|
||||
}
|
||||
|
||||
public class LineChart : BaseAxesChart
|
||||
{
|
||||
[SerializeField]
|
||||
private LineInfo lineInfo;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
int seriesCount = seriesList.Count;
|
||||
float max = GetMaxValue();
|
||||
float scaleWid = xAxis.GetSplitWidth(coordinateWid);
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
if (!legend.IsShowSeries(j)) continue;
|
||||
Series series = seriesList[j];
|
||||
Color32 color = themeInfo.GetColor(j);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
float startX = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int showDataNumber = series.showDataNumber;
|
||||
int startIndex = 0;
|
||||
if (series.showDataNumber > 0 && series.DataList.Count > series.showDataNumber)
|
||||
{
|
||||
startIndex = series.DataList.Count - series.showDataNumber;
|
||||
}
|
||||
for (int i = startIndex; i < series.DataList.Count; i++)
|
||||
{
|
||||
float value = series.DataList[i];
|
||||
|
||||
np = new Vector3(startX + i * scaleWid, zeroY + value * coordinateHig / max);
|
||||
if (i > 0)
|
||||
{
|
||||
if (lineInfo.smooth)
|
||||
{
|
||||
var list = ChartUtils.GetBezierList(lp, np, lineInfo.smoothStyle);
|
||||
Vector3 start, to;
|
||||
start = list[0];
|
||||
for (int k = 1; k < list.Length; k++)
|
||||
{
|
||||
to = list[k];
|
||||
ChartUtils.DrawLine(vh, start, to, lineInfo.tickness, color);
|
||||
start = to;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartUtils.DrawLine(vh, lp, np, lineInfo.tickness, color);
|
||||
if (lineInfo.area)
|
||||
{
|
||||
ChartUtils.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY),
|
||||
new Vector3(lp.x, zeroY), color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
lp = np;
|
||||
}
|
||||
// draw point
|
||||
if (lineInfo.showPoint)
|
||||
{
|
||||
for (int i = 0; i < series.DataList.Count; i++)
|
||||
{
|
||||
float value = series.DataList[i];
|
||||
|
||||
Vector3 p = new Vector3(startX + i * scaleWid,
|
||||
zeroY + value * coordinateHig / max);
|
||||
float pointWid = lineInfo.pointWid;
|
||||
if (tooltip.show && i == tooltip.DataIndex - 1)
|
||||
{
|
||||
pointWid = pointWid * 1.8f;
|
||||
}
|
||||
if (theme == Theme.Dark)
|
||||
{
|
||||
|
||||
ChartUtils.DrawCricle(vh, p, pointWid, color,
|
||||
(int)lineInfo.pointWid * 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartUtils.DrawCricle(vh, p, pointWid, Color.white);
|
||||
ChartUtils.DrawDoughnut(vh, p, pointWid - lineInfo.tickness,
|
||||
pointWid, 0, 360, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//draw tooltip line
|
||||
if (tooltip.show && tooltip.DataIndex > 0)
|
||||
{
|
||||
float splitWid = coordinateWid / (xAxis.GetSplitNumber() - 1);
|
||||
float px = zeroX + (tooltip.DataIndex - 1) * splitWid + (xAxis.boundaryGap ? splitWid / 2 : 0);
|
||||
Vector2 sp = new Vector2(px, zeroY);
|
||||
Vector2 ep = new Vector2(px, zeroY + coordinateHig);
|
||||
ChartUtils.DrawLine(vh, sp, ep, coordinate.tickness, themeInfo.tooltipFlagAreaColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,218 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class PieInfo
|
||||
{
|
||||
public string name;
|
||||
public float insideRadius = 0f;
|
||||
public float outsideRadius = 80f;
|
||||
public float tooltipExtraRadius = 10f;
|
||||
public bool outsideRadiusDynamic = false;
|
||||
public float space;
|
||||
public float left;
|
||||
public float right;
|
||||
public float top;
|
||||
public float bottom;
|
||||
}
|
||||
|
||||
public class PieChart : BaseChart
|
||||
{
|
||||
[SerializeField]
|
||||
private PieInfo pieInfo = new PieInfo();
|
||||
|
||||
private float pieCenterX = 0f;
|
||||
private float pieCenterY = 0f;
|
||||
private float pieRadius = 0;
|
||||
private Vector2 pieCenter;
|
||||
private List<float> angleList = new List<float>();
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
UpdatePieCenter();
|
||||
float totalDegree = 360;
|
||||
float startDegree = 0;
|
||||
float dataTotal = GetDataTotal();
|
||||
float dataMax = GetDataMax();
|
||||
angleList.Clear();
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (!legend.IsShowSeries(i))
|
||||
{
|
||||
angleList.Add(0);
|
||||
continue;
|
||||
}
|
||||
float value = seriesList[i].DataList[0];
|
||||
float degree = totalDegree * value / dataTotal;
|
||||
float toDegree = startDegree + degree;
|
||||
|
||||
float outSideRadius = pieInfo.outsideRadiusDynamic ?
|
||||
pieInfo.insideRadius + (pieRadius - pieInfo.insideRadius) * value / dataMax :
|
||||
pieRadius;
|
||||
if (tooltip.show && tooltip.DataIndex == i + 1)
|
||||
{
|
||||
outSideRadius += pieInfo.tooltipExtraRadius;
|
||||
}
|
||||
ChartUtils.DrawDoughnut(vh, pieCenter, pieInfo.insideRadius,
|
||||
outSideRadius, startDegree, toDegree, themeInfo.GetColor(i));
|
||||
angleList.Add(toDegree);
|
||||
startDegree = toDegree;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLegendButtonClicked()
|
||||
{
|
||||
base.OnLegendButtonClicked();
|
||||
|
||||
}
|
||||
|
||||
private float GetDataTotal()
|
||||
{
|
||||
float total = 0;
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (legend.IsShowSeries(i))
|
||||
{
|
||||
total += seriesList[i].GetData(0);
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
private float GetDataMax()
|
||||
{
|
||||
float max = 0;
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (legend.IsShowSeries(i) && seriesList[i].GetData(0) > max)
|
||||
{
|
||||
max = seriesList[i].GetData(0);
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
private void UpdatePieCenter()
|
||||
{
|
||||
float diffX = chartWid - pieInfo.left - pieInfo.right;
|
||||
float diffY = chartHig - pieInfo.top - pieInfo.bottom;
|
||||
float diff = Mathf.Min(diffX, diffY);
|
||||
if (pieInfo.outsideRadius <= 0)
|
||||
{
|
||||
pieRadius = diff / 3 * 2;
|
||||
pieCenterX = pieInfo.left + pieRadius;
|
||||
pieCenterY = pieInfo.bottom + pieRadius;
|
||||
}
|
||||
else
|
||||
{
|
||||
pieRadius = pieInfo.outsideRadius;
|
||||
pieCenterX = chartWid / 2;
|
||||
pieCenterY = chartHig / 2;
|
||||
if (pieInfo.left > 0) pieCenterX = pieInfo.left + pieRadius;
|
||||
if (pieInfo.right > 0) pieCenterX = chartWid - pieInfo.right - pieRadius;
|
||||
if (pieInfo.top > 0) pieCenterY = chartHig - pieInfo.top - pieRadius;
|
||||
if (pieInfo.bottom > 0) pieCenterY = pieInfo.bottom + pieRadius;
|
||||
}
|
||||
pieCenter = new Vector2(pieCenterX, pieCenterY);
|
||||
}
|
||||
|
||||
protected override void CheckTootipArea(Vector2 local)
|
||||
{
|
||||
|
||||
float dist = Vector2.Distance(local, pieCenter);
|
||||
if (dist > pieRadius)
|
||||
{
|
||||
tooltip.DataIndex = 0;
|
||||
tooltip.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 dir = local - pieCenter;
|
||||
float angle = VectorAngle(Vector2.up, dir);
|
||||
tooltip.DataIndex = 0;
|
||||
for (int i = angleList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (i == 0 && angle < angleList[i])
|
||||
{
|
||||
tooltip.DataIndex = 1;
|
||||
break;
|
||||
}
|
||||
else if (angle < angleList[i] && angle > angleList[i - 1])
|
||||
{
|
||||
tooltip.DataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tooltip.DataIndex > 0)
|
||||
{
|
||||
tooltip.UpdatePos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
if (tooltip.LastDataIndex != tooltip.DataIndex)
|
||||
{
|
||||
RefreshChart();
|
||||
}
|
||||
tooltip.LastDataIndex = tooltip.DataIndex;
|
||||
}
|
||||
}
|
||||
|
||||
float VectorAngle(Vector2 from, Vector2 to)
|
||||
{
|
||||
float angle;
|
||||
|
||||
Vector3 cross = Vector3.Cross(from, to);
|
||||
angle = Vector2.Angle(from, to);
|
||||
angle = cross.z > 0 ? -angle : angle;
|
||||
angle = (angle + 360) % 360;
|
||||
return angle;
|
||||
}
|
||||
|
||||
protected override void RefreshTooltip()
|
||||
{
|
||||
base.RefreshTooltip();
|
||||
int index = tooltip.DataIndex - 1;
|
||||
if (index < 0)
|
||||
{
|
||||
tooltip.SetActive(false);
|
||||
return;
|
||||
}
|
||||
tooltip.SetActive(true);
|
||||
string strColor = ColorUtility.ToHtmlStringRGBA(themeInfo.GetColor(index));
|
||||
string key = legend.dataList[index];
|
||||
float value = seriesList[index].DataList[0];
|
||||
string txt = "";
|
||||
if (!string.IsNullOrEmpty(pieInfo.name))
|
||||
{
|
||||
txt += pieInfo.name + "\n";
|
||||
}
|
||||
txt += string.Format("<color=#{0}>● </color>{1}: {2}", strColor, key, value);
|
||||
tooltip.UpdateTooltipText(txt);
|
||||
|
||||
var pos = tooltip.GetPos();
|
||||
if (pos.x + tooltip.Width > chartWid)
|
||||
{
|
||||
pos.x = chartWid - tooltip.Width;
|
||||
}
|
||||
if (pos.y - tooltip.Height < 0)
|
||||
{
|
||||
pos.y = tooltip.Height;
|
||||
}
|
||||
tooltip.UpdatePos(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,390 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class RadarIndicator
|
||||
{
|
||||
public string name;
|
||||
public float max;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class RadarInfo
|
||||
{
|
||||
public bool cricle;
|
||||
public bool area;
|
||||
|
||||
public float radius = 100;
|
||||
public int splitNumber = 5;
|
||||
|
||||
public float left;
|
||||
public float right;
|
||||
public float top;
|
||||
public float bottom;
|
||||
|
||||
public float lineTickness = 1f;
|
||||
public float linePointSize = 5f;
|
||||
public Color lineColor = Color.grey;
|
||||
public List<Color> backgroundColorList = new List<Color>();
|
||||
public bool showIndicator = true;
|
||||
public List<RadarIndicator> indicatorList = new List<RadarIndicator>();
|
||||
|
||||
public int checkIndicatorCount { get; set; }
|
||||
}
|
||||
|
||||
public class RadarChart : BaseChart
|
||||
{
|
||||
private const string INDICATOR_TEXT = "indicator";
|
||||
|
||||
[SerializeField]
|
||||
private RadarInfo radarInfo = new RadarInfo();
|
||||
|
||||
private RadarInfo checkRadarInfo = new RadarInfo();
|
||||
private float radarCenterX = 0f;
|
||||
private float radarCenterY = 0f;
|
||||
private float radarRadius = 0;
|
||||
private List<Text> indicatorTextList = new List<Text>();
|
||||
private List<List<Vector3>> dataPosList = new List<List<Vector3>>();
|
||||
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
UpdateRadarCenter();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
CheckRadarInfoChanged();
|
||||
}
|
||||
|
||||
private void InitIndicator()
|
||||
{
|
||||
indicatorTextList.Clear();
|
||||
HideChild(INDICATOR_TEXT);
|
||||
int indicatorNum = radarInfo.indicatorList.Count;
|
||||
float txtWid = 100;
|
||||
float txtHig = 20;
|
||||
for (int i = 0; i < indicatorNum; i++)
|
||||
{
|
||||
var pos = GetIndicatorPosition(i);
|
||||
TextAnchor anchor = TextAnchor.MiddleCenter;
|
||||
var diff = pos.x - radarCenterX;
|
||||
if (diff < -1f)
|
||||
{
|
||||
pos = new Vector3(pos.x - 5, pos.y);
|
||||
anchor = TextAnchor.MiddleRight;
|
||||
}
|
||||
else if (diff > 1f)
|
||||
{
|
||||
anchor = TextAnchor.MiddleLeft;
|
||||
pos = new Vector3(pos.x + txtWid + 5, pos.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
anchor = TextAnchor.MiddleCenter;
|
||||
float y = pos.y > radarCenterY ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
|
||||
pos = new Vector3(pos.x + txtWid / 2, y);
|
||||
}
|
||||
Text txt = ChartUtils.AddTextObject(INDICATOR_TEXT + i, transform, themeInfo.font,
|
||||
themeInfo.textColor, anchor, Vector2.zero, Vector2.zero, new Vector2(1, 0.5f),
|
||||
new Vector2(txtWid, txtHig));
|
||||
txt.transform.localPosition = pos;
|
||||
txt.text = radarInfo.indicatorList[i].name;
|
||||
txt.gameObject.SetActive(radarInfo.showIndicator);
|
||||
indicatorTextList.Add(txt);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckRadarInfoChanged()
|
||||
{
|
||||
if (checkRadarInfo.radius != radarInfo.radius ||
|
||||
checkRadarInfo.left != radarInfo.left ||
|
||||
checkRadarInfo.right != radarInfo.right ||
|
||||
checkRadarInfo.top != radarInfo.top ||
|
||||
checkRadarInfo.bottom != radarInfo.bottom ||
|
||||
checkRadarInfo.checkIndicatorCount != radarInfo.indicatorList.Count ||
|
||||
checkRadarInfo.showIndicator != radarInfo.showIndicator)
|
||||
{
|
||||
checkRadarInfo.radius = radarInfo.radius;
|
||||
checkRadarInfo.left = radarInfo.left;
|
||||
checkRadarInfo.right = radarInfo.right;
|
||||
checkRadarInfo.top = radarInfo.top;
|
||||
checkRadarInfo.bottom = radarInfo.bottom;
|
||||
checkRadarInfo.showIndicator = radarInfo.showIndicator;
|
||||
checkRadarInfo.checkIndicatorCount = radarInfo.indicatorList.Count;
|
||||
OnRadarChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRadarChanged()
|
||||
{
|
||||
UpdateRadarCenter();
|
||||
InitIndicator();
|
||||
}
|
||||
|
||||
private Vector3 GetIndicatorPosition(int i)
|
||||
{
|
||||
int indicatorNum = radarInfo.indicatorList.Count;
|
||||
var angle = 2 * Mathf.PI / indicatorNum * i;
|
||||
var x = radarCenterX + radarInfo.radius * Mathf.Sin(angle);
|
||||
var y = radarCenterY + radarInfo.radius * Mathf.Cos(angle);
|
||||
|
||||
return new Vector3(x, y);
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
UpdateRadarCenter();
|
||||
if (radarInfo.cricle)
|
||||
DrawCricleRadar(vh);
|
||||
else
|
||||
DrawRadar(vh);
|
||||
DrawData(vh);
|
||||
}
|
||||
|
||||
protected override void OnLegendButtonClicked()
|
||||
{
|
||||
base.OnLegendButtonClicked();
|
||||
}
|
||||
|
||||
protected override void OnThemeChanged()
|
||||
{
|
||||
base.OnThemeChanged();
|
||||
radarInfo.backgroundColorList.Clear();
|
||||
switch (theme)
|
||||
{
|
||||
case Theme.Dark:
|
||||
radarInfo.backgroundColorList.Add(ThemeInfo.GetColor("#6f6f6f"));
|
||||
radarInfo.backgroundColorList.Add(ThemeInfo.GetColor("#606060"));
|
||||
break;
|
||||
case Theme.Default:
|
||||
radarInfo.backgroundColorList.Add(ThemeInfo.GetColor("#f6f6f6"));
|
||||
radarInfo.backgroundColorList.Add(ThemeInfo.GetColor("#e7e7e7"));
|
||||
break;
|
||||
case Theme.Light:
|
||||
radarInfo.backgroundColorList.Add(ThemeInfo.GetColor("#f6f6f6"));
|
||||
radarInfo.backgroundColorList.Add(ThemeInfo.GetColor("#e7e7e7"));
|
||||
break;
|
||||
}
|
||||
InitIndicator();
|
||||
}
|
||||
|
||||
private void DrawData(VertexHelper vh)
|
||||
{
|
||||
int indicatorNum = radarInfo.indicatorList.Count;
|
||||
var angle = 2 * Mathf.PI / indicatorNum;
|
||||
var p = new Vector3(radarCenterX, radarCenterY);
|
||||
Vector3 startPoint = Vector3.zero;
|
||||
Vector3 toPoint = Vector3.zero;
|
||||
Vector3 firstPoint = Vector3.zero;
|
||||
dataPosList.Clear();
|
||||
dataPosList.Capacity = seriesList.Count;
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (!legend.IsShowSeries(i))
|
||||
{
|
||||
dataPosList.Add(new List<Vector3>());
|
||||
continue;
|
||||
}
|
||||
var dataList = seriesList[i].DataList;
|
||||
var color = themeInfo.GetColor(i);
|
||||
var areaColor = new Color(color.r, color.g, color.b, color.a * 0.7f);
|
||||
var max = radarInfo.indicatorList[i].max > 0 ?
|
||||
radarInfo.indicatorList[i].max :
|
||||
GetMaxValue();
|
||||
List<Vector3> pointList = new List<Vector3>(dataList.Count);
|
||||
dataPosList.Add(pointList);
|
||||
for (int j = 0; j < dataList.Count; j++)
|
||||
{
|
||||
var radius = radarInfo.radius * dataList[j] / max;
|
||||
var currAngle = j * angle;
|
||||
if (j == 0)
|
||||
{
|
||||
startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
||||
p.y + radius * Mathf.Cos(currAngle));
|
||||
firstPoint = startPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
||||
p.y + radius * Mathf.Cos(currAngle));
|
||||
if (radarInfo.area)
|
||||
{
|
||||
ChartUtils.DrawTriangle(vh, p, startPoint, toPoint, areaColor);
|
||||
}
|
||||
ChartUtils.DrawLine(vh, startPoint, toPoint, radarInfo.lineTickness, color);
|
||||
startPoint = toPoint;
|
||||
}
|
||||
pointList.Add(startPoint);
|
||||
}
|
||||
if (radarInfo.area) ChartUtils.DrawTriangle(vh, p, startPoint, firstPoint, areaColor);
|
||||
ChartUtils.DrawLine(vh, startPoint, firstPoint, radarInfo.lineTickness, color);
|
||||
foreach (var point in pointList)
|
||||
{
|
||||
float radius = radarInfo.linePointSize - radarInfo.lineTickness * 2;
|
||||
|
||||
ChartUtils.DrawCricle(vh, point, radius, Color.white);
|
||||
ChartUtils.DrawDoughnut(vh, point, radius, radarInfo.linePointSize, 0, 360, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawRadar(VertexHelper vh)
|
||||
{
|
||||
float insideRadius = 0, outsideRadius = 0;
|
||||
float block = radarInfo.radius / radarInfo.splitNumber;
|
||||
int indicatorNum = radarInfo.indicatorList.Count;
|
||||
Vector3 p1, p2, p3, p4;
|
||||
Vector3 p = new Vector3(radarCenterX, radarCenterY);
|
||||
float angle = 2 * Mathf.PI / indicatorNum;
|
||||
for (int i = 0; i < radarInfo.splitNumber; i++)
|
||||
{
|
||||
Color color = radarInfo.backgroundColorList[i % radarInfo.backgroundColorList.Count];
|
||||
outsideRadius = insideRadius + block;
|
||||
p1 = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0));
|
||||
p2 = new Vector3(p.x + outsideRadius * Mathf.Sin(0), p.y + outsideRadius * Mathf.Cos(0));
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
{
|
||||
float currAngle = j * angle;
|
||||
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle),
|
||||
p.y + insideRadius * Mathf.Cos(currAngle));
|
||||
|
||||
ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
ChartUtils.DrawLine(vh, p2, p3, radarInfo.lineTickness, radarInfo.lineColor);
|
||||
p1 = p4;
|
||||
p2 = p3;
|
||||
}
|
||||
insideRadius = outsideRadius;
|
||||
}
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
{
|
||||
float currAngle = j * angle;
|
||||
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
ChartUtils.DrawLine(vh, p, p3, radarInfo.lineTickness / 2, radarInfo.lineColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCricleRadar(VertexHelper vh)
|
||||
{
|
||||
float insideRadius = 0, outsideRadius = 0;
|
||||
float block = radarInfo.radius / radarInfo.splitNumber;
|
||||
int indicatorNum = radarInfo.indicatorList.Count;
|
||||
Vector3 p = new Vector3(radarCenterX, radarCenterY);
|
||||
Vector3 p1;
|
||||
float angle = 2 * Mathf.PI / indicatorNum;
|
||||
for (int i = 0; i < radarInfo.splitNumber; i++)
|
||||
{
|
||||
Color color = radarInfo.backgroundColorList[i % radarInfo.backgroundColorList.Count];
|
||||
outsideRadius = insideRadius + block;
|
||||
ChartUtils.DrawDoughnut(vh, p, insideRadius, outsideRadius, 0, 360, color);
|
||||
ChartUtils.DrawCicleNotFill(vh, p, outsideRadius, radarInfo.lineTickness,
|
||||
radarInfo.lineColor);
|
||||
insideRadius = outsideRadius;
|
||||
}
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
{
|
||||
float currAngle = j * angle;
|
||||
p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
ChartUtils.DrawLine(vh, p, p1, radarInfo.lineTickness / 2, radarInfo.lineColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRadarCenter()
|
||||
{
|
||||
float diffX = chartWid - radarInfo.left - radarInfo.right;
|
||||
float diffY = chartHig - radarInfo.top - radarInfo.bottom;
|
||||
float diff = Mathf.Min(diffX, diffY);
|
||||
if (radarInfo.radius <= 0)
|
||||
{
|
||||
radarRadius = diff / 3 * 2;
|
||||
radarCenterX = radarInfo.left + radarRadius;
|
||||
radarCenterY = radarInfo.bottom + radarRadius;
|
||||
}
|
||||
else
|
||||
{
|
||||
radarRadius = radarInfo.radius;
|
||||
radarCenterX = chartWid / 2;
|
||||
radarCenterY = chartHig / 2;
|
||||
if (radarInfo.left > 0) radarCenterX = radarInfo.left + radarRadius;
|
||||
if (radarInfo.right > 0) radarCenterX = chartWid - radarInfo.right - radarRadius;
|
||||
if (radarInfo.top > 0) radarCenterY = chartHig - radarInfo.top - radarRadius;
|
||||
if (radarInfo.bottom > 0) radarCenterY = radarInfo.bottom + radarRadius;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CheckTootipArea(Vector2 local)
|
||||
{
|
||||
if (dataPosList.Count <= 0) return;
|
||||
tooltip.DataIndex = 0;
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (!legend.IsShowSeries(i)) continue;
|
||||
for (int j = 0; j < dataPosList[i].Count; j++)
|
||||
{
|
||||
if (Vector3.Distance(local, dataPosList[i][j]) <= radarInfo.linePointSize * 1.2f)
|
||||
{
|
||||
tooltip.DataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tooltip.DataIndex > 0)
|
||||
{
|
||||
tooltip.UpdatePos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
if (tooltip.LastDataIndex != tooltip.DataIndex)
|
||||
{
|
||||
RefreshChart();
|
||||
}
|
||||
tooltip.LastDataIndex = tooltip.DataIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
tooltip.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RefreshTooltip()
|
||||
{
|
||||
base.RefreshTooltip();
|
||||
int index = tooltip.DataIndex - 1;
|
||||
if (index < 0)
|
||||
{
|
||||
tooltip.SetActive(false);
|
||||
return;
|
||||
}
|
||||
tooltip.SetActive(true);
|
||||
StringBuilder sb = new StringBuilder(legend.dataList[index]);
|
||||
for (int i = 0; i < radarInfo.indicatorList.Count; i++)
|
||||
{
|
||||
string key = radarInfo.indicatorList[i].name;
|
||||
float value = seriesList[index].DataList[i];
|
||||
sb.Append("\n");
|
||||
sb.AppendFormat("{0}: {1}", key, value);
|
||||
}
|
||||
tooltip.UpdateTooltipText(sb.ToString());
|
||||
|
||||
var pos = tooltip.GetPos();
|
||||
if (pos.x + tooltip.Width > chartWid)
|
||||
{
|
||||
pos.x = chartWid - tooltip.Width;
|
||||
}
|
||||
if (pos.y - tooltip.Height < 0)
|
||||
{
|
||||
pos.y = tooltip.Height;
|
||||
}
|
||||
tooltip.UpdatePos(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Scripts/UI.meta
Normal file
10
Scripts/UI.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3f125a3accd30240b3ca251090f11b4
|
||||
folderAsset: yes
|
||||
timeCreated: 1554216875
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
164
Scripts/UI/BarChart.cs
Normal file
164
Scripts/UI/BarChart.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
|
||||
|
||||
[AddComponentMenu("XCharts/BarChart", 13)]
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[DisallowMultipleComponent]
|
||||
public class BarChart : CoordinateChart
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Bar
|
||||
{
|
||||
[SerializeField] private float m_BarWidth = 0.7f;
|
||||
[SerializeField] private float m_Space;
|
||||
|
||||
public float barWidth { get { return m_BarWidth; } set { m_BarWidth = value; } }
|
||||
public float space { get { return m_Space; } set { m_Space = value; } }
|
||||
}
|
||||
|
||||
[SerializeField] private Bar m_Bar = new Bar();
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
if (m_YAxis.type == Axis.AxisType.Category)
|
||||
{
|
||||
var stackSeries = m_Series.GetStackSeries();
|
||||
int seriesCount = stackSeries.Count;
|
||||
float scaleWid = m_YAxis.GetDataWidth(coordinateHig);
|
||||
float barWid = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
|
||||
float offset = (scaleWid - barWid * seriesCount - m_Bar.space * (seriesCount - 1)) / 2;
|
||||
float max = GetMaxValue();
|
||||
int serieCount = 0;
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
var seriesCurrHig = new Dictionary<int, float>();
|
||||
var serieList = stackSeries[j];
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
Serie serie = serieList[n];
|
||||
if (!m_Legend.IsShowSeries(serie.name)) continue;
|
||||
Color color = m_ThemeInfo.GetColor(serieCount);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
|
||||
: serie.data.Count;
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
{
|
||||
if (!seriesCurrHig.ContainsKey(i))
|
||||
{
|
||||
seriesCurrHig[i] = 0;
|
||||
}
|
||||
float data = serie.data[i];
|
||||
float pX = seriesCurrHig[i] + zeroX + m_Coordinate.tickness;
|
||||
float pY = zeroY + i * scaleWid;
|
||||
if (!m_YAxis.boundaryGap) pY -= scaleWid / 2;
|
||||
float barHig = data / max * coordinateWid;
|
||||
float space = offset + j * (barWid + m_Bar.space);
|
||||
seriesCurrHig[i] += barHig;
|
||||
Vector3 p1 = new Vector3(pX, pY + space + barWid);
|
||||
Vector3 p2 = new Vector3(pX + barHig, pY + space + barWid);
|
||||
Vector3 p3 = new Vector3(pX + barHig, pY + space);
|
||||
Vector3 p4 = new Vector3(pX, pY + space);
|
||||
if (serie.show)
|
||||
{
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
}
|
||||
}
|
||||
if (serie.show)
|
||||
{
|
||||
serieCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
float tooltipSplitWid = scaleWid < 1 ? 1 : scaleWid;
|
||||
float pX = zeroX + coordinateWid;
|
||||
float pY = zeroY + scaleWid * (m_Tooltip.dataIndex - 1) - (m_YAxis.boundaryGap ? 0 : scaleWid / 2);
|
||||
Vector3 p1 = new Vector3(zeroX, pY);
|
||||
Vector3 p2 = new Vector3(zeroX, pY + tooltipSplitWid);
|
||||
Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid);
|
||||
Vector3 p4 = new Vector3(pX, pY);
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var stackSeries = m_Series.GetStackSeries();
|
||||
int seriesCount = stackSeries.Count;
|
||||
float scaleWid = m_XAxis.GetDataWidth(coordinateWid);
|
||||
float barWid = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
|
||||
float offset = (scaleWid - barWid * seriesCount - m_Bar.space * (seriesCount - 1)) / 2;
|
||||
float max = GetMaxValue();
|
||||
int serieCount = 0;
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
var seriesCurrHig = new Dictionary<int, float>();
|
||||
var serieList = stackSeries[j];
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
Serie serie = serieList[n];
|
||||
if (!m_Legend.IsShowSeries(serie.name)) continue;
|
||||
Color color = m_ThemeInfo.GetColor(serieCount);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
|
||||
: serie.data.Count;
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
{
|
||||
if (!seriesCurrHig.ContainsKey(i))
|
||||
{
|
||||
seriesCurrHig[i] = 0;
|
||||
}
|
||||
float data = serie.data[i];
|
||||
float pX = zeroX + i * scaleWid;
|
||||
if (!m_XAxis.boundaryGap) pX -= scaleWid / 2;
|
||||
float pY = seriesCurrHig[i] + zeroY + m_Coordinate.tickness;
|
||||
float barHig = data / max * coordinateHig;
|
||||
seriesCurrHig[i] += barHig;
|
||||
float space = offset + j * (barWid + m_Bar.space);
|
||||
Vector3 p1 = new Vector3(pX + space, pY);
|
||||
Vector3 p2 = new Vector3(pX + space, pY + barHig);
|
||||
Vector3 p3 = new Vector3(pX + space + barWid, pY + barHig);
|
||||
Vector3 p4 = new Vector3(pX + space + barWid, pY);
|
||||
if (serie.show)
|
||||
{
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
}
|
||||
}
|
||||
if (serie.show)
|
||||
{
|
||||
serieCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
float tooltipSplitWid = scaleWid < 1 ? 1 : scaleWid;
|
||||
float pX = zeroX + scaleWid * (m_Tooltip.dataIndex - 1) - (m_XAxis.boundaryGap?0:scaleWid/2);
|
||||
float pY = zeroY + coordinateHig;
|
||||
Vector3 p1 = new Vector3(pX, zeroY);
|
||||
Vector3 p2 = new Vector3(pX, pY);
|
||||
Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY);
|
||||
Vector3 p4 = new Vector3(pX + tooltipSplitWid, zeroY);
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Scripts/UI/Interface.meta
Normal file
10
Scripts/UI/Interface.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 253203a243755c744880211dbbc988a2
|
||||
folderAsset: yes
|
||||
timeCreated: 1554979427
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Scripts/UI/Interface/IJsonData.cs
Normal file
10
Scripts/UI/Interface/IJsonData.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public interface IJsonData
|
||||
{
|
||||
void ParseJsonData(string json);
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Interface/IJsonData.cs.meta
Normal file
13
Scripts/UI/Interface/IJsonData.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9132f4c137015247b44450c2cb23606
|
||||
timeCreated: 1555379601
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Scripts/UI/Interface/IPropertyChanged.cs
Normal file
11
Scripts/UI/Interface/IPropertyChanged.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public interface IPropertyChanged
|
||||
{
|
||||
void OnChanged();
|
||||
}
|
||||
}
|
||||
|
||||
13
Scripts/UI/Interface/IPropertyChanged.cs.meta
Normal file
13
Scripts/UI/Interface/IPropertyChanged.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24f32e2d632f08245ae885545f14a2a3
|
||||
timeCreated: 1554979427
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Scripts/UI/Internal.meta
Normal file
10
Scripts/UI/Internal.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 750348e0c6842d74e872391f6ea942da
|
||||
folderAsset: yes
|
||||
timeCreated: 1554221587
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
259
Scripts/UI/Internal/Axis.cs
Normal file
259
Scripts/UI/Internal/Axis.cs
Normal file
@@ -0,0 +1,259 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Axis : JsonDataSupport,IEquatable<Axis>
|
||||
{
|
||||
public enum AxisType
|
||||
{
|
||||
Value,
|
||||
Category,
|
||||
Time,
|
||||
Log
|
||||
}
|
||||
|
||||
public enum SplitLineType
|
||||
{
|
||||
None,
|
||||
Solid,
|
||||
Dashed,
|
||||
Dotted
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class AxisTick
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private bool m_AlignWithLabel;
|
||||
[SerializeField] private bool m_Inside;
|
||||
[SerializeField] private float m_Length;
|
||||
|
||||
public bool show { get { return m_Show; }set { m_Show = value; } }
|
||||
public bool alignWithLabel { get { return m_AlignWithLabel; } set { m_AlignWithLabel = value; } }
|
||||
public bool inside { get { return m_Inside; }set { m_Inside = value; } }
|
||||
public float length { get { return m_Length; }set { m_Length = value; } }
|
||||
|
||||
public static AxisTick defaultTick
|
||||
{
|
||||
get
|
||||
{
|
||||
var tick = new AxisTick
|
||||
{
|
||||
m_Show = true,
|
||||
m_AlignWithLabel = false,
|
||||
m_Inside = false,
|
||||
m_Length = 5f
|
||||
};
|
||||
return tick;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] protected bool m_Show = true;
|
||||
[SerializeField] protected AxisType m_Type;
|
||||
[SerializeField] protected int m_SplitNumber = 5;
|
||||
[SerializeField] protected int m_TextRotation = 0;
|
||||
[SerializeField] protected bool m_ShowSplitLine = false;
|
||||
[SerializeField] protected SplitLineType m_SplitLineType = SplitLineType.Dashed;
|
||||
[SerializeField] protected bool m_BoundaryGap = true;
|
||||
[SerializeField] protected List<string> m_Data = new List<string>();
|
||||
[SerializeField] protected AxisTick m_AxisTick = AxisTick.defaultTick;
|
||||
|
||||
public bool show { get { return m_Show; }set { m_Show = value; } }
|
||||
public AxisType type { get { return m_Type; } set { m_Type = value; } }
|
||||
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
|
||||
public int textRotation { get { return m_TextRotation; } set { m_TextRotation = value; } }
|
||||
public bool showSplitLine { get { return m_ShowSplitLine; } set { m_ShowSplitLine = value; } }
|
||||
public SplitLineType splitLineType { get { return m_SplitLineType; } set { m_SplitLineType = value; } }
|
||||
public bool boundaryGap { get { return m_BoundaryGap; } set { m_BoundaryGap = value; } }
|
||||
public List<string> data { get { return m_Data; } }
|
||||
public AxisTick axisTick { get { return m_AxisTick; }set { m_AxisTick = value; } }
|
||||
|
||||
public void Copy(Axis other)
|
||||
{
|
||||
m_Show = other.show;
|
||||
m_Type = other.type;
|
||||
m_SplitNumber = other.splitNumber;
|
||||
m_TextRotation = other.textRotation;
|
||||
m_ShowSplitLine = other.showSplitLine;
|
||||
m_SplitLineType = other.splitLineType;
|
||||
m_BoundaryGap = other.boundaryGap;
|
||||
m_Data.Clear();
|
||||
foreach (var d in other.data) m_Data.Add(d);
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
m_Data.Clear();
|
||||
}
|
||||
|
||||
public void AddData(string category,int maxDataNumber)
|
||||
{
|
||||
if (maxDataNumber > 0)
|
||||
{
|
||||
while (m_Data.Count > maxDataNumber) m_Data.RemoveAt(0);
|
||||
}
|
||||
m_Data.Add(category);
|
||||
}
|
||||
|
||||
public string GetData(int index)
|
||||
{
|
||||
if (index >= 0 && index < data.Count)
|
||||
return data[index];
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
public int GetSplitNumber()
|
||||
{
|
||||
if (data.Count > 2 * m_SplitNumber || data.Count <= 0)
|
||||
return m_SplitNumber;
|
||||
else
|
||||
return data.Count;
|
||||
}
|
||||
|
||||
public float GetSplitWidth(float coordinateWidth)
|
||||
{
|
||||
return coordinateWidth / (m_BoundaryGap ? GetSplitNumber() : GetSplitNumber() - 1);
|
||||
}
|
||||
|
||||
public int GetDataNumber()
|
||||
{
|
||||
return data.Count;
|
||||
}
|
||||
|
||||
public float GetDataWidth(float coordinateWidth)
|
||||
{
|
||||
return coordinateWidth / (m_BoundaryGap ? data.Count : data.Count - 1);
|
||||
}
|
||||
|
||||
public string GetScaleName(int index, float maxData = 0)
|
||||
{
|
||||
if (m_Type == AxisType.Value)
|
||||
{
|
||||
return ((int)(maxData * index / (GetSplitNumber() -1))).ToString();
|
||||
}
|
||||
int dataCount = data.Count;
|
||||
if (dataCount <= 0) return "";
|
||||
|
||||
if(index == GetSplitNumber() - 1 && !m_BoundaryGap)
|
||||
{
|
||||
return data[data.Count-1];
|
||||
}
|
||||
else
|
||||
{
|
||||
float rate = dataCount / GetSplitNumber();
|
||||
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 data[newIndex];
|
||||
}
|
||||
}
|
||||
|
||||
public int GetScaleNumber()
|
||||
{
|
||||
if (data.Count > 2 * splitNumber || data.Count <= 0)
|
||||
return m_BoundaryGap ? m_SplitNumber + 1 : m_SplitNumber;
|
||||
else
|
||||
return m_BoundaryGap ? data.Count + 1 : data.Count;
|
||||
}
|
||||
|
||||
public float GetScaleWidth(float coordinateWidth)
|
||||
{
|
||||
int num = GetScaleNumber() - 1;
|
||||
if (num <= 0) num = 1;
|
||||
return coordinateWidth / num;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Axis)) return false;
|
||||
return Equals((Axis)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Axis other)
|
||||
{
|
||||
return show == other.show &&
|
||||
type == other.type &&
|
||||
splitNumber == other.splitNumber &&
|
||||
showSplitLine == other.showSplitLine &&
|
||||
textRotation == other.textRotation &&
|
||||
splitLineType == other.splitLineType &&
|
||||
boundaryGap == other.boundaryGap &&
|
||||
ChartHelper.IsValueEqualsList<string>(m_Data, other.data);
|
||||
}
|
||||
|
||||
public static bool operator ==(Axis point1, Axis point2)
|
||||
{
|
||||
return point1.Equals(point2);
|
||||
}
|
||||
|
||||
public static bool operator !=(Axis point1, Axis point2)
|
||||
{
|
||||
return !point1.Equals(point2);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public override void ParseJsonData(string jsonData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
||||
m_Data = ChartHelper.ParseStringFromString(jsonData);
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class XAxis : Axis
|
||||
{
|
||||
public static XAxis defaultXAxis
|
||||
{
|
||||
get
|
||||
{
|
||||
var axis = new XAxis
|
||||
{
|
||||
m_Show = true,
|
||||
m_Type = AxisType.Category,
|
||||
m_SplitNumber = 5,
|
||||
m_TextRotation = 0,
|
||||
m_ShowSplitLine = false,
|
||||
m_SplitLineType = SplitLineType.Dashed,
|
||||
m_BoundaryGap = true,
|
||||
m_Data = new List<string>()
|
||||
{
|
||||
"x1","x2","x3","x4","x5"
|
||||
}
|
||||
};
|
||||
return axis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class YAxis : Axis
|
||||
{
|
||||
public static YAxis defaultYAxis
|
||||
{
|
||||
get
|
||||
{
|
||||
var axis = new YAxis
|
||||
{
|
||||
m_Show = true,
|
||||
m_Type = AxisType.Value,
|
||||
m_SplitNumber = 5,
|
||||
m_TextRotation = 0,
|
||||
m_ShowSplitLine = false,
|
||||
m_SplitLineType = SplitLineType.Dashed,
|
||||
m_BoundaryGap = false,
|
||||
m_Data = new List<string>(5),
|
||||
};
|
||||
return axis;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/Axis.cs.meta
Normal file
13
Scripts/UI/Internal/Axis.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84f640465300fb34facae554552063b9
|
||||
timeCreated: 1554422468
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
367
Scripts/UI/Internal/BaseChart.cs
Normal file
367
Scripts/UI/Internal/BaseChart.cs
Normal file
@@ -0,0 +1,367 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class BaseChart : MaskableGraphic
|
||||
{
|
||||
private static readonly string s_TitleObjectName = "title";
|
||||
private static readonly string s_LegendObjectName = "legend";
|
||||
|
||||
[SerializeField] protected Theme m_Theme = Theme.Default;
|
||||
[SerializeField] protected ThemeInfo m_ThemeInfo;
|
||||
[SerializeField] protected Title m_Title = Title.defaultTitle;
|
||||
[SerializeField] protected Legend m_Legend = Legend.defaultLegend;
|
||||
[SerializeField] protected Tooltip m_Tooltip = Tooltip.defaultTooltip;
|
||||
[SerializeField] protected Series m_Series;
|
||||
|
||||
[SerializeField] protected bool m_Large;
|
||||
[SerializeField] protected int m_MinShowDataNumber;
|
||||
[SerializeField] protected int m_MaxShowDataNumber;
|
||||
[SerializeField] protected int m_MaxCacheDataNumber;
|
||||
|
||||
[NonSerialized] private Theme m_CheckTheme = 0;
|
||||
[NonSerialized] private Title m_CheckTitle = Title.defaultTitle;
|
||||
[NonSerialized] private Legend m_CheckLegend = Legend.defaultLegend;
|
||||
[NonSerialized] private float m_CheckWidth = 0;
|
||||
[NonSerialized] private float m_CheckHeight = 0;
|
||||
[NonSerialized] protected List<Text> m_LegendTextList = new List<Text>();
|
||||
|
||||
protected float chartWidth { get { return rectTransform.sizeDelta.x; } }
|
||||
protected float chartHeight { get { return rectTransform.sizeDelta.y; } }
|
||||
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
|
||||
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
|
||||
protected Vector2 chartPivot { get { return rectTransform.pivot; } }
|
||||
|
||||
public Title title { get { return m_Title; } }
|
||||
public Legend legend { get { return m_Legend; } }
|
||||
public Tooltip tooltip { get { return m_Tooltip; } }
|
||||
public Series series { get { return m_Series; } }
|
||||
|
||||
public bool large { get { return m_Large; } set { m_Large = value; } }
|
||||
public int minShowDataNumber
|
||||
{
|
||||
get { return m_MinShowDataNumber; }
|
||||
set { m_MinShowDataNumber = value; if (m_MinShowDataNumber < 0) m_MinShowDataNumber = 0; }
|
||||
}
|
||||
public int maxShowDataNumber
|
||||
{
|
||||
get { return m_MaxShowDataNumber; }
|
||||
set { m_MaxShowDataNumber = value; if (m_MaxShowDataNumber < 0) m_MaxShowDataNumber = 0; }
|
||||
}
|
||||
public int maxCacheDataNumber
|
||||
{
|
||||
get { return m_MaxCacheDataNumber; }
|
||||
set { m_MaxCacheDataNumber = value; if (m_MaxCacheDataNumber < 0) m_MaxCacheDataNumber = 0; }
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
m_ThemeInfo = ThemeInfo.Default;
|
||||
rectTransform.anchorMax = Vector2.zero;
|
||||
rectTransform.anchorMin = Vector2.zero;
|
||||
rectTransform.pivot = Vector2.zero;
|
||||
m_CheckWidth = chartWidth;
|
||||
m_CheckHeight = chartHeight;
|
||||
m_CheckTheme = m_Theme;
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
InitTooltip();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
CheckSize();
|
||||
CheckTheme();
|
||||
CheckTile();
|
||||
CheckLegend();
|
||||
CheckTooltip();
|
||||
}
|
||||
|
||||
protected override void Reset()
|
||||
{
|
||||
ChartHelper.DestoryAllChilds(transform);
|
||||
m_ThemeInfo = ThemeInfo.Dark;
|
||||
m_Title = Title.defaultTitle;
|
||||
m_Legend = Legend.defaultLegend;
|
||||
m_Tooltip = Tooltip.defaultTooltip;
|
||||
m_Series = Series.defaultSeries;
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
InitTooltip();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
for (int i = transform.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
DestroyImmediate(transform.GetChild(i).gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddData(string legend, float value)
|
||||
{
|
||||
m_Series.AddData(legend, value, m_MaxCacheDataNumber);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void AddData(int legend, float value)
|
||||
{
|
||||
m_Series.AddData(legend, value, m_MaxCacheDataNumber);
|
||||
}
|
||||
|
||||
public void UpdateData(string legend, float value, int dataIndex = 0)
|
||||
{
|
||||
m_Series.UpdateData(legend, value, dataIndex);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void UpdateData(int legendIndex, float value, int dataIndex = 0)
|
||||
{
|
||||
m_Series.UpdateData(legendIndex, value, dataIndex);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void UpdateTheme(Theme theme)
|
||||
{
|
||||
this.m_Theme = theme;
|
||||
OnThemeChanged();
|
||||
SetAllDirty();
|
||||
}
|
||||
|
||||
private void InitTitle()
|
||||
{
|
||||
m_Title.OnChanged();
|
||||
TextAnchor anchor = m_Title.location.textAnchor;
|
||||
Vector2 anchorMin = m_Title.location.anchorMin;
|
||||
Vector2 anchorMax = m_Title.location.anchorMax;
|
||||
Vector2 pivot = m_Title.location.pivot;
|
||||
Vector3 titlePosition = m_Title.location.GetPosition(chartWidth, chartHeight);
|
||||
Vector3 subTitlePosition = -new Vector3(0, m_Title.textFontSize + m_Title.itemGap, 0);
|
||||
float titleWid = chartWidth;
|
||||
|
||||
var titleObject = ChartHelper.AddObject(s_TitleObjectName, transform, anchorMin, anchorMax,
|
||||
pivot, new Vector2(chartWidth, chartHeight));
|
||||
titleObject.transform.localPosition = titlePosition;
|
||||
ChartHelper.HideAllObject(titleObject, s_TitleObjectName);
|
||||
|
||||
Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.textColor, anchor, anchorMin, anchorMax, pivot,
|
||||
new Vector2(titleWid, m_Title.textFontSize), m_Title.textFontSize);
|
||||
|
||||
titleText.alignment = anchor;
|
||||
titleText.gameObject.SetActive(m_Title.show);
|
||||
titleText.transform.localPosition = Vector2.zero;
|
||||
titleText.text = m_Title.text;
|
||||
|
||||
Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.textColor, anchor, anchorMin, anchorMax, pivot,
|
||||
new Vector2(titleWid, m_Title.subTextFontSize), m_Title.subTextFontSize);
|
||||
|
||||
subText.alignment = anchor;
|
||||
subText.gameObject.SetActive(m_Title.show && !string.IsNullOrEmpty(m_Title.subText));
|
||||
subText.transform.localPosition = subTitlePosition;
|
||||
subText.text = m_Title.subText;
|
||||
}
|
||||
|
||||
private void InitLegend()
|
||||
{
|
||||
m_Legend.OnChanged();
|
||||
ChartHelper.HideAllObject(transform, s_LegendObjectName);
|
||||
TextAnchor anchor = m_Legend.location.textAnchor;
|
||||
Vector2 anchorMin = m_Legend.location.anchorMin;
|
||||
Vector2 anchorMax = m_Legend.location.anchorMax;
|
||||
Vector2 pivot = m_Legend.location.pivot;
|
||||
|
||||
var legendObject = ChartHelper.AddObject(s_LegendObjectName, transform, anchorMin, anchorMax,
|
||||
pivot, new Vector2(chartWidth, chartHeight));
|
||||
legendObject.transform.localPosition = m_Legend.location.GetPosition(chartWidth, chartHeight);
|
||||
ChartHelper.HideAllObject(legendObject, s_LegendObjectName);
|
||||
|
||||
for (int i = 0; i < m_Legend.data.Count; i++)
|
||||
{
|
||||
Button btn = ChartHelper.AddButtonObject(s_LegendObjectName + "_" + i, legendObject.transform,
|
||||
m_ThemeInfo.font, m_Legend.itemFontSize, m_ThemeInfo.legendTextColor, anchor,
|
||||
anchorMin, anchorMax, pivot, new Vector2(m_Legend.itemWidth, m_Legend.itemHeight));
|
||||
|
||||
m_Legend.SetButton(i, btn);
|
||||
m_Legend.UpdateButtonColor(i, m_ThemeInfo.GetColor(i), m_ThemeInfo.unableColor);
|
||||
btn.GetComponentInChildren<Text>().text = m_Legend.data[i];
|
||||
btn.onClick.AddListener(delegate ()
|
||||
{
|
||||
int index = int.Parse(btn.name.Split('_')[1]);
|
||||
m_Legend.SetShowData(index, !m_Legend.IsShowSeries(index));
|
||||
m_Legend.UpdateButtonColor(index, m_ThemeInfo.GetColor(index), m_ThemeInfo.unableColor);
|
||||
OnYMaxValueChanged();
|
||||
OnLegendButtonClicked();
|
||||
RefreshChart();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void InitTooltip()
|
||||
{
|
||||
GameObject obj = ChartHelper.AddTooltipObject("tooltip", transform, m_ThemeInfo.font);
|
||||
m_Tooltip.SetObj(obj);
|
||||
m_Tooltip.SetBackgroundColor(m_ThemeInfo.tooltipBackgroundColor);
|
||||
m_Tooltip.SetTextColor(m_ThemeInfo.tooltipTextColor);
|
||||
m_Tooltip.SetActive(false);
|
||||
}
|
||||
|
||||
private Vector3 GetLegendPosition(int i)
|
||||
{
|
||||
return m_Legend.location.GetPosition(chartWidth, chartHeight);
|
||||
}
|
||||
|
||||
protected float GetMaxValue()
|
||||
{
|
||||
if (m_Series == null) return 100;
|
||||
else return m_Series.GetMaxValue(m_Legend);
|
||||
}
|
||||
|
||||
protected float GetMaxValue(int index)
|
||||
{
|
||||
if (m_Series == null) return 100;
|
||||
else return m_Series.GetMaxValue(index);
|
||||
}
|
||||
|
||||
private void CheckSize()
|
||||
{
|
||||
if (m_CheckWidth != chartWidth || m_CheckHeight != chartHeight)
|
||||
{
|
||||
m_CheckWidth = chartWidth;
|
||||
m_CheckHeight = chartHeight;
|
||||
OnSizeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckTheme()
|
||||
{
|
||||
if (m_CheckTheme != m_Theme)
|
||||
{
|
||||
m_CheckTheme = m_Theme;
|
||||
OnThemeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckTile()
|
||||
{
|
||||
if (!m_CheckTitle.Equals(m_Title))
|
||||
{
|
||||
m_CheckTitle.Copy(m_Title);
|
||||
OnTitleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckLegend()
|
||||
{
|
||||
if (m_CheckLegend != m_Legend)
|
||||
{
|
||||
m_CheckLegend.Copy(m_Legend);
|
||||
OnLegendChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckTooltip()
|
||||
{
|
||||
if (!m_Tooltip.show) return;
|
||||
m_Tooltip.dataIndex = 0;
|
||||
Vector2 local;
|
||||
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||
Input.mousePosition, null, out local))
|
||||
return;
|
||||
|
||||
if (local.x < 0 || local.x > chartWidth ||
|
||||
local.y < 0 || local.y > chartHeight)
|
||||
return;
|
||||
|
||||
CheckTootipArea(local);
|
||||
}
|
||||
|
||||
protected virtual void CheckTootipArea(Vector2 localPostion)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnSizeChanged()
|
||||
{
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
}
|
||||
|
||||
protected virtual void OnThemeChanged()
|
||||
{
|
||||
switch (m_Theme)
|
||||
{
|
||||
case Theme.Dark:
|
||||
m_ThemeInfo.Copy(ThemeInfo.Dark);
|
||||
break;
|
||||
case Theme.Default:
|
||||
m_ThemeInfo.Copy(ThemeInfo.Default);
|
||||
break;
|
||||
case Theme.Light:
|
||||
m_ThemeInfo.Copy(ThemeInfo.Light);
|
||||
break;
|
||||
}
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
}
|
||||
|
||||
protected virtual void OnTitleChanged()
|
||||
{
|
||||
InitTitle();
|
||||
}
|
||||
|
||||
protected virtual void OnLegendChanged()
|
||||
{
|
||||
InitLegend();
|
||||
}
|
||||
|
||||
protected virtual void OnYMaxValueChanged()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnLegendButtonClicked()
|
||||
{
|
||||
}
|
||||
|
||||
public void RefreshChart()
|
||||
{
|
||||
int tempWid = (int)chartWidth;
|
||||
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid - 1);
|
||||
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid);
|
||||
}
|
||||
|
||||
protected virtual void RefreshTooltip()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
vh.Clear();
|
||||
DrawBackground(vh);
|
||||
DrawChart(vh);
|
||||
DrawTooltip(vh);
|
||||
}
|
||||
|
||||
protected virtual void DrawChart(VertexHelper vh)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void DrawTooltip(VertexHelper vh)
|
||||
{
|
||||
}
|
||||
|
||||
private void DrawBackground(VertexHelper vh)
|
||||
{
|
||||
// draw bg
|
||||
Vector3 p1 = new Vector3(0, chartHeight);
|
||||
Vector3 p2 = new Vector3(chartWidth, chartHeight);
|
||||
Vector3 p3 = new Vector3(chartWidth, 0);
|
||||
Vector3 p4 = new Vector3(0, 0);
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.backgroundColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
81
Scripts/UI/Internal/Coordinate.cs
Normal file
81
Scripts/UI/Internal/Coordinate.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[Serializable]
|
||||
public class Coordinate : IEquatable<Coordinate>
|
||||
{
|
||||
[SerializeField] private float m_Left;
|
||||
[SerializeField] private float m_Right;
|
||||
[SerializeField] private float m_Top;
|
||||
[SerializeField] private float m_Bottom;
|
||||
[SerializeField] private float m_Tickness;
|
||||
[SerializeField] private int m_FontSize;
|
||||
|
||||
public float left { get { return m_Left; } set { m_Left = value; } }
|
||||
public float right { get { return m_Right; } set { m_Right = value; } }
|
||||
public float top { get { return m_Top; } set { m_Top = value; } }
|
||||
public float bottom { get { return m_Bottom; } set { m_Bottom = value; } }
|
||||
public float tickness { get { return m_Tickness; } set { m_Tickness = value; } }
|
||||
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
|
||||
|
||||
public static Coordinate defaultCoordinate
|
||||
{
|
||||
get
|
||||
{
|
||||
var coordinate = new Coordinate
|
||||
{
|
||||
m_Left = 40f,
|
||||
m_Right = 80f,
|
||||
m_Top = 40f,
|
||||
m_Bottom = 25f,
|
||||
m_Tickness = 0.6f,
|
||||
m_FontSize = 16,
|
||||
};
|
||||
return coordinate;
|
||||
}
|
||||
}
|
||||
public void Copy(Coordinate other)
|
||||
{
|
||||
m_Left = other.left;
|
||||
m_Right = other.right;
|
||||
m_Top = other.top;
|
||||
m_Bottom = other.bottom;
|
||||
m_Tickness = other.tickness;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Coordinate)) return false;
|
||||
return Equals((Coordinate)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Coordinate other)
|
||||
{
|
||||
return m_Left == other.left &&
|
||||
m_Right == other.right &&
|
||||
m_Top == other.top &&
|
||||
m_Bottom == other.bottom &&
|
||||
m_Tickness == other.tickness &&
|
||||
m_FontSize == other.fontSize;
|
||||
}
|
||||
|
||||
public static bool operator ==(Coordinate point1, Coordinate point2)
|
||||
{
|
||||
return point1.Equals(point2);
|
||||
}
|
||||
|
||||
public static bool operator !=(Coordinate point1, Coordinate point2)
|
||||
{
|
||||
return !point1.Equals(point2);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/Coordinate.cs.meta
Normal file
13
Scripts/UI/Internal/Coordinate.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7dea6e12aeb93945888247ea97dbd13
|
||||
timeCreated: 1554422468
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
497
Scripts/UI/Internal/CoordinateChart.cs
Normal file
497
Scripts/UI/Internal/CoordinateChart.cs
Normal file
@@ -0,0 +1,497 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class CoordinateChart : BaseChart
|
||||
{
|
||||
private static readonly string s_DefaultSplitNameY = "split_y";
|
||||
private static readonly string s_DefaultSplitNameX = "split_x";
|
||||
|
||||
[SerializeField] protected Coordinate m_Coordinate = Coordinate.defaultCoordinate;
|
||||
[SerializeField] protected XAxis m_XAxis = XAxis.defaultXAxis;
|
||||
[SerializeField] protected YAxis m_YAxis = YAxis.defaultYAxis;
|
||||
|
||||
[NonSerialized] private float m_LastXMaxValue;
|
||||
[NonSerialized] private float m_LastYMaxValue;
|
||||
[NonSerialized] private XAxis m_CheckXAxis = XAxis.defaultXAxis;
|
||||
[NonSerialized] private YAxis m_CheckYAxis = YAxis.defaultYAxis;
|
||||
[NonSerialized] private Coordinate m_CheckCoordinate = Coordinate.defaultCoordinate;
|
||||
|
||||
protected List<Text> m_SplitYTextList = new List<Text>();
|
||||
protected List<Text> m_SplitXTextList = new List<Text>();
|
||||
|
||||
public float zeroX { get { return m_Coordinate.left; } }
|
||||
public float zeroY { get { return m_Coordinate.bottom; } }
|
||||
public float coordinateWid { get { return chartWidth - m_Coordinate.left - m_Coordinate.right; } }
|
||||
public float coordinateHig { get { return chartHeight - m_Coordinate.top - m_Coordinate.bottom; } }
|
||||
public Axis xAxis { get { return m_XAxis; } }
|
||||
public Axis yAxis { get { return m_YAxis; } }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
InitSplitX();
|
||||
InitSplitY();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
CheckYAxis();
|
||||
CheckXAxis();
|
||||
CheckMaxValue();
|
||||
CheckCoordinate();
|
||||
}
|
||||
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
m_Coordinate = Coordinate.defaultCoordinate;
|
||||
m_XAxis = XAxis.defaultXAxis;
|
||||
m_YAxis = YAxis.defaultYAxis;
|
||||
InitSplitX();
|
||||
InitSplitY();
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
DrawCoordinate(vh);
|
||||
}
|
||||
|
||||
protected override void CheckTootipArea(Vector2 local)
|
||||
{
|
||||
if (local.x < zeroX || local.x > zeroX + coordinateWid ||
|
||||
local.y < zeroY || local.y > zeroY + coordinateHig)
|
||||
{
|
||||
m_Tooltip.dataIndex = 0;
|
||||
RefreshTooltip();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_XAxis.type == Axis.AxisType.Value)
|
||||
{
|
||||
float splitWid = m_YAxis.GetDataWidth(coordinateHig);
|
||||
for (int i = 0; i < m_YAxis.GetDataNumber(); i++)
|
||||
{
|
||||
float pY = zeroY + i * splitWid;
|
||||
if (m_YAxis.boundaryGap)
|
||||
{
|
||||
if (local.y > pY && local.y <= pY + splitWid)
|
||||
{
|
||||
m_Tooltip.dataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)
|
||||
{
|
||||
m_Tooltip.dataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float splitWid = m_XAxis.GetDataWidth(coordinateWid);
|
||||
for (int i = 0; i < m_XAxis.GetDataNumber(); i++)
|
||||
{
|
||||
float pX = zeroX + i * splitWid;
|
||||
if (m_XAxis.boundaryGap)
|
||||
{
|
||||
if (local.x > pX && local.x <= pX + splitWid)
|
||||
{
|
||||
m_Tooltip.dataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)
|
||||
{
|
||||
m_Tooltip.dataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
m_Tooltip.UpdatePos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
if (m_Tooltip.lastDataIndex != m_Tooltip.dataIndex)
|
||||
{
|
||||
RefreshChart();
|
||||
}
|
||||
m_Tooltip.lastDataIndex = m_Tooltip.dataIndex;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RefreshTooltip()
|
||||
{
|
||||
base.RefreshTooltip();
|
||||
int index = m_Tooltip.dataIndex - 1;
|
||||
Axis tempAxis = m_XAxis.type == Axis.AxisType.Value ? (Axis)m_YAxis : (Axis)m_XAxis;
|
||||
if (index < 0)
|
||||
{
|
||||
m_Tooltip.SetActive(false);
|
||||
return;
|
||||
}
|
||||
m_Tooltip.SetActive(true);
|
||||
if (m_Series.Count == 1)
|
||||
{
|
||||
string txt = tempAxis.GetData(index) + ": " + m_Series.GetData(0,index);
|
||||
m_Tooltip.UpdateTooltipText(txt);
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(tempAxis.GetData(index));
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (m_Series.series[i].show)
|
||||
{
|
||||
string strColor = ColorUtility.ToHtmlStringRGBA(m_ThemeInfo.GetColor(i));
|
||||
string key = m_Series.series[i].name;
|
||||
float value = m_Series.series[i].data[index];
|
||||
sb.Append("\n");
|
||||
sb.AppendFormat("<color=#{0}>● </color>", strColor);
|
||||
sb.AppendFormat("{0}: {1}", key, value);
|
||||
}
|
||||
|
||||
}
|
||||
m_Tooltip.UpdateTooltipText(sb.ToString());
|
||||
}
|
||||
var pos = m_Tooltip.GetPos();
|
||||
if (pos.x + m_Tooltip.width > chartWidth)
|
||||
{
|
||||
pos.x = chartWidth - m_Tooltip.width;
|
||||
}
|
||||
if (pos.y - m_Tooltip.height < 0)
|
||||
{
|
||||
pos.y = m_Tooltip.height;
|
||||
}
|
||||
m_Tooltip.UpdatePos(pos);
|
||||
}
|
||||
|
||||
TextGenerationSettings GetTextSetting()
|
||||
{
|
||||
var setting = new TextGenerationSettings();
|
||||
var fontdata = FontData.defaultFontData;
|
||||
|
||||
//setting.generationExtents = rectTransform.rect.size;
|
||||
setting.generationExtents = new Vector2(200.0F, 50.0F);
|
||||
setting.fontSize = 14;
|
||||
setting.textAnchor = TextAnchor.MiddleCenter;
|
||||
setting.scaleFactor = 1f;
|
||||
setting.color = Color.red;
|
||||
setting.font = m_ThemeInfo.font;
|
||||
setting.pivot = new Vector2(0.5f, 0.5f);
|
||||
setting.richText = false;
|
||||
setting.lineSpacing = 0;
|
||||
setting.fontStyle = FontStyle.Normal;
|
||||
setting.resizeTextForBestFit = false;
|
||||
setting.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
setting.verticalOverflow = VerticalWrapMode.Overflow;
|
||||
|
||||
return setting;
|
||||
|
||||
}
|
||||
|
||||
protected override void OnThemeChanged()
|
||||
{
|
||||
base.OnThemeChanged();
|
||||
InitSplitX();
|
||||
InitSplitY();
|
||||
}
|
||||
|
||||
public void AddXAxisData(string category)
|
||||
{
|
||||
m_XAxis.AddData(category,m_MaxCacheDataNumber);
|
||||
OnXAxisChanged();
|
||||
}
|
||||
|
||||
public void AddYAxisData(string category)
|
||||
{
|
||||
m_YAxis.AddData(category, m_MaxCacheDataNumber);
|
||||
OnYAxisChanged();
|
||||
}
|
||||
|
||||
private void InitSplitY()
|
||||
{
|
||||
m_SplitYTextList.Clear();
|
||||
float max = GetMaxValue();
|
||||
float splitWidth = m_YAxis.GetScaleWidth(coordinateHig);
|
||||
|
||||
var titleObject = ChartHelper.AddObject(s_DefaultSplitNameY, transform, chartAnchorMin,
|
||||
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
|
||||
titleObject.transform.localPosition = Vector3.zero;
|
||||
ChartHelper.HideAllObject(titleObject, s_DefaultSplitNameY);
|
||||
|
||||
for (int i = 0; i < m_YAxis.splitNumber; i++)
|
||||
{
|
||||
Text txt = ChartHelper.AddTextObject(s_DefaultSplitNameY + i, titleObject.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.textColor, TextAnchor.MiddleRight, Vector2.zero,
|
||||
Vector2.zero, new Vector2(1, 0.5f), new Vector2(m_Coordinate.left, 20),
|
||||
m_Coordinate.fontSize, m_XAxis.textRotation);
|
||||
txt.transform.localPosition = GetSplitYPosition(splitWidth, i);
|
||||
txt.text = m_YAxis.GetScaleName(i, max);
|
||||
txt.gameObject.SetActive(m_YAxis.show);
|
||||
m_SplitYTextList.Add(txt);
|
||||
}
|
||||
}
|
||||
|
||||
public void InitSplitX()
|
||||
{
|
||||
m_SplitXTextList.Clear();
|
||||
float max = GetMaxValue();
|
||||
float splitWidth = m_XAxis.GetScaleWidth(coordinateWid);
|
||||
|
||||
var titleObject = ChartHelper.AddObject(s_DefaultSplitNameX, transform, chartAnchorMin,
|
||||
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
|
||||
titleObject.transform.localPosition = Vector3.zero;
|
||||
ChartHelper.HideAllObject(titleObject, s_DefaultSplitNameX);
|
||||
|
||||
for (int i = 0; i < m_XAxis.splitNumber; i++)
|
||||
{
|
||||
Text txt = ChartHelper.AddTextObject(s_DefaultSplitNameX + i, titleObject.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.textColor, TextAnchor.MiddleCenter, Vector2.zero,
|
||||
Vector2.zero, new Vector2(1, 0.5f), new Vector2(splitWidth, 20),
|
||||
m_Coordinate.fontSize, m_XAxis.textRotation);
|
||||
|
||||
txt.transform.localPosition = GetSplitXPosition(splitWidth, i);
|
||||
txt.text = m_XAxis.GetScaleName(i, max);
|
||||
txt.gameObject.SetActive(m_XAxis.show);
|
||||
m_SplitXTextList.Add(txt);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 GetSplitYPosition(float scaleWid, int i)
|
||||
{
|
||||
if (m_YAxis.boundaryGap)
|
||||
{
|
||||
return new Vector3(zeroX - m_YAxis.axisTick.length - 2f,
|
||||
zeroY + (i + 0.5f) * scaleWid, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector3(zeroX - m_YAxis.axisTick.length - 2f,
|
||||
zeroY + i * scaleWid, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 GetSplitXPosition(float scaleWid, int i)
|
||||
{
|
||||
if (m_XAxis.boundaryGap)
|
||||
{
|
||||
return new Vector3(zeroX + (i + 1) * scaleWid, zeroY - m_XAxis.axisTick.length - 5, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector3(zeroX + (i + 1 - 0.5f) * scaleWid,
|
||||
zeroY - m_XAxis.axisTick.length - 10, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckCoordinate()
|
||||
{
|
||||
if (m_CheckCoordinate != m_Coordinate)
|
||||
{
|
||||
m_CheckCoordinate.Copy(m_Coordinate);
|
||||
OnCoordinateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckYAxis()
|
||||
{
|
||||
if (m_CheckYAxis != m_YAxis)
|
||||
{
|
||||
m_CheckYAxis.Copy(m_YAxis);
|
||||
OnYAxisChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckXAxis()
|
||||
{
|
||||
if (!m_CheckXAxis.Equals(m_XAxis))
|
||||
{
|
||||
m_CheckXAxis.Copy(m_XAxis);
|
||||
OnXAxisChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckMaxValue()
|
||||
{
|
||||
if (m_XAxis.type == Axis.AxisType.Value)
|
||||
{
|
||||
float max = GetMaxValue();
|
||||
if (m_LastXMaxValue != max)
|
||||
{
|
||||
m_LastXMaxValue = max;
|
||||
OnXMaxValueChanged();
|
||||
}
|
||||
}
|
||||
else if (m_YAxis.type == Axis.AxisType.Value)
|
||||
{
|
||||
|
||||
float max = GetMaxValue();
|
||||
|
||||
if (m_LastYMaxValue != max)
|
||||
{
|
||||
m_LastYMaxValue = max;
|
||||
OnYMaxValueChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnCoordinateChanged()
|
||||
{
|
||||
InitSplitX();
|
||||
InitSplitY();
|
||||
}
|
||||
|
||||
protected virtual void OnYAxisChanged()
|
||||
{
|
||||
InitSplitY();
|
||||
}
|
||||
|
||||
protected virtual void OnXAxisChanged()
|
||||
{
|
||||
InitSplitX();
|
||||
}
|
||||
|
||||
protected virtual void OnXMaxValueChanged()
|
||||
{
|
||||
float max = GetMaxValue();
|
||||
for (int i = 0; i < m_SplitXTextList.Count; i++)
|
||||
{
|
||||
m_SplitXTextList[i].text = m_XAxis.GetScaleName(i, max);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnSizeChanged()
|
||||
{
|
||||
base.OnSizeChanged();
|
||||
InitSplitX();
|
||||
InitSplitY();
|
||||
}
|
||||
|
||||
protected override void OnYMaxValueChanged()
|
||||
{
|
||||
float max = GetMaxValue();
|
||||
for (int i = 0; i < m_SplitYTextList.Count; i++)
|
||||
{
|
||||
m_SplitYTextList[i].text = m_YAxis.GetScaleName(i, max);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCoordinate(VertexHelper vh)
|
||||
{
|
||||
#region draw tick and splitline
|
||||
if (m_YAxis.show)
|
||||
{
|
||||
for (int i = 1; i < m_YAxis.GetScaleNumber(); i++)
|
||||
{
|
||||
float pX = zeroX - m_YAxis.axisTick.length;
|
||||
float pY = zeroY + i * m_YAxis.GetScaleWidth(coordinateHig);
|
||||
if (m_YAxis.boundaryGap && m_YAxis.axisTick.alignWithLabel)
|
||||
{
|
||||
pY -= m_YAxis.GetScaleWidth(coordinateHig) / 2;
|
||||
}
|
||||
if (m_YAxis.axisTick.show)
|
||||
{
|
||||
ChartHelper.DrawLine(vh, new Vector3(pX, pY), new Vector3(zeroX, pY),
|
||||
m_Coordinate.tickness, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
if (m_YAxis.showSplitLine)
|
||||
{
|
||||
DrawSplitLine(vh, true, m_YAxis.splitLineType, new Vector3(zeroX, pY),
|
||||
new Vector3(zeroX + coordinateWid, pY));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_XAxis.show)
|
||||
{
|
||||
for (int i = 1; i < m_XAxis.GetScaleNumber(); i++)
|
||||
{
|
||||
float pX = zeroX + i * m_XAxis.GetScaleWidth(coordinateWid);
|
||||
float pY = zeroY - m_XAxis.axisTick.length - 2;
|
||||
if (m_XAxis.boundaryGap && m_XAxis.axisTick.alignWithLabel)
|
||||
{
|
||||
pX -= m_XAxis.GetScaleWidth(coordinateWid) / 2;
|
||||
}
|
||||
if (m_XAxis.axisTick.show)
|
||||
{
|
||||
ChartHelper.DrawLine(vh, new Vector3(pX, zeroY), new Vector3(pX, pY), m_Coordinate.tickness,
|
||||
m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
if (m_XAxis.showSplitLine)
|
||||
{
|
||||
DrawSplitLine(vh, false, m_XAxis.splitLineType, new Vector3(pX, zeroY),
|
||||
new Vector3(pX, zeroY + coordinateHig));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
//draw x,y axis
|
||||
if (m_YAxis.show)
|
||||
{
|
||||
ChartHelper.DrawLine(vh, new Vector3(zeroX, zeroY - m_YAxis.axisTick.length),
|
||||
new Vector3(zeroX, zeroY + coordinateHig + 2), m_Coordinate.tickness,
|
||||
m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
if (m_XAxis.show)
|
||||
{
|
||||
ChartHelper.DrawLine(vh, new Vector3(zeroX - m_XAxis.axisTick.length, zeroY),
|
||||
new Vector3(zeroX + coordinateWid + 2, zeroY), m_Coordinate.tickness,
|
||||
m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSplitLine(VertexHelper vh, bool isYAxis, Axis.SplitLineType type, Vector3 startPos,
|
||||
Vector3 endPos)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case Axis.SplitLineType.Dashed:
|
||||
case Axis.SplitLineType.Dotted:
|
||||
var startX = startPos.x;
|
||||
var startY = startPos.y;
|
||||
var dashLen = type == Axis.SplitLineType.Dashed ? 6 : 2.5f;
|
||||
var count = isYAxis ? (endPos.x - startPos.x) / (dashLen * 2) :
|
||||
(endPos.y - startPos.y) / (dashLen * 2);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (isYAxis)
|
||||
{
|
||||
var toX = startX + dashLen;
|
||||
ChartHelper.DrawLine(vh, new Vector3(startX, startY), new Vector3(toX, startY),
|
||||
m_Coordinate.tickness, m_ThemeInfo.axisSplitLineColor);
|
||||
startX += dashLen * 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
var toY = startY + dashLen;
|
||||
ChartHelper.DrawLine(vh, new Vector3(startX, startY), new Vector3(startX, toY),
|
||||
m_Coordinate.tickness, m_ThemeInfo.axisSplitLineColor);
|
||||
startY += dashLen * 2;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case Axis.SplitLineType.Solid:
|
||||
ChartHelper.DrawLine(vh, startPos, endPos, m_Coordinate.tickness,
|
||||
m_ThemeInfo.axisSplitLineColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
32
Scripts/UI/Internal/JsonDataSupport.cs
Normal file
32
Scripts/UI/Internal/JsonDataSupport.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class JsonDataSupport: IJsonData,ISerializationCallbackReceiver
|
||||
{
|
||||
[SerializeField] protected string m_JsonData;
|
||||
[SerializeField] protected bool m_DataFromJson;
|
||||
|
||||
public string jsonData { get { return m_JsonData; } set { m_JsonData = value; ParseJsonData(value); } }
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
if (m_DataFromJson)
|
||||
{
|
||||
ParseJsonData(m_JsonData);
|
||||
m_DataFromJson = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void ParseJsonData(string json)
|
||||
{
|
||||
throw new Exception("no support yet");
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/JsonDataSupport.cs.meta
Normal file
13
Scripts/UI/Internal/JsonDataSupport.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73e326ed8a76f90408bfa9feb1797433
|
||||
timeCreated: 1555379601
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
243
Scripts/UI/Internal/Legend.cs
Normal file
243
Scripts/UI/Internal/Legend.cs
Normal file
@@ -0,0 +1,243 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Legend : JsonDataSupport, IPropertyChanged, IEquatable<Legend>
|
||||
{
|
||||
public enum Orient
|
||||
{
|
||||
Horizonal,
|
||||
Vertical
|
||||
}
|
||||
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private Orient m_Orient = Orient.Horizonal;
|
||||
[SerializeField] private Location m_Location = Location.defaultRight;
|
||||
[SerializeField] private float m_ItemWidth = 50.0f;
|
||||
[SerializeField] private float m_ItemHeight = 20.0f;
|
||||
[SerializeField] private float m_ItemGap = 5;
|
||||
[SerializeField] private int m_ItemFontSize = 18;
|
||||
[SerializeField] private List<string> m_Data = new List<string>();
|
||||
|
||||
[NonSerialized] private List<bool> m_DataShowList = new List<bool>();
|
||||
[NonSerialized] private List<Button> m_DataBtnList = new List<Button>();
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
|
||||
public Orient orient { get { return m_Orient; } set { m_Orient = value; } }
|
||||
|
||||
public Location location { get { return m_Location; } set { m_Location = value; } }
|
||||
|
||||
public float itemWidth { get { return m_ItemWidth; } set { m_ItemWidth = value; } }
|
||||
|
||||
public float itemHeight { get { return m_ItemHeight; } set { m_ItemHeight = value; } }
|
||||
|
||||
public float itemGap { get { return m_ItemGap; } set { m_ItemGap = value; } }
|
||||
|
||||
public int itemFontSize { get { return m_ItemFontSize; } set { m_ItemFontSize = value; } }
|
||||
|
||||
public List<string> data { get { return m_Data; } }
|
||||
|
||||
public static Legend defaultLegend
|
||||
{
|
||||
get
|
||||
{
|
||||
var legend = new Legend
|
||||
{
|
||||
m_Show = true,
|
||||
m_Orient = Orient.Horizonal,
|
||||
m_Location = Location.defaultRight,
|
||||
m_ItemWidth = 60.0f,
|
||||
m_ItemHeight = 20.0f,
|
||||
m_ItemGap = 5,
|
||||
m_ItemFontSize = 16,
|
||||
m_Data = new List<string>()
|
||||
{
|
||||
"Legend"
|
||||
}
|
||||
};
|
||||
return legend;
|
||||
}
|
||||
}
|
||||
public void Copy(Legend legend)
|
||||
{
|
||||
m_Show = legend.show;
|
||||
m_Orient = legend.orient;
|
||||
m_Location.Copy(legend.location);
|
||||
m_ItemWidth = legend.itemWidth;
|
||||
m_ItemHeight = legend.itemHeight;
|
||||
m_ItemGap = legend.itemGap;
|
||||
m_ItemFontSize = legend.itemFontSize;
|
||||
m_Data.Clear();
|
||||
foreach (var d in legend.data) m_Data.Add(d);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Legend)) return false;
|
||||
return Equals((Legend)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Legend other)
|
||||
{
|
||||
return show == other.show &&
|
||||
orient == other.orient &&
|
||||
location == other.location &&
|
||||
itemWidth == other.itemWidth &&
|
||||
itemHeight == other.itemHeight &&
|
||||
itemGap == other.itemGap &&
|
||||
itemFontSize == other.itemFontSize &&
|
||||
ChartHelper.IsValueEqualsList<string>(m_Data, other.data);
|
||||
}
|
||||
|
||||
public static bool operator ==(Legend point1, Legend point2)
|
||||
{
|
||||
return point1.Equals(point2);
|
||||
}
|
||||
|
||||
public static bool operator !=(Legend point1, Legend point2)
|
||||
{
|
||||
return !point1.Equals(point2);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public bool IsShowSeries(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return true;
|
||||
for(int i = 0; i < data.Count; i++)
|
||||
{
|
||||
if (name.Equals(data[i])) return m_DataShowList[i];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsShowSeries(int seriesIndex)
|
||||
{
|
||||
if (seriesIndex < 0 || seriesIndex > data.Count - 1) seriesIndex = 0;
|
||||
if (seriesIndex >= data.Count) return false;
|
||||
if (seriesIndex < 0 || seriesIndex > m_DataShowList.Count - 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_DataShowList[seriesIndex];
|
||||
}
|
||||
}
|
||||
|
||||
public void SetShowData(int index, bool flag)
|
||||
{
|
||||
m_DataShowList[index] = flag;
|
||||
}
|
||||
|
||||
public void SetButton(int index, Button btn)
|
||||
{
|
||||
btn.transform.localPosition = GetButtonLocationPosition(index);
|
||||
if (index < 0 || index > m_DataBtnList.Count - 1)
|
||||
{
|
||||
m_DataBtnList.Add(btn);
|
||||
m_DataShowList.Add(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_DataBtnList[index] = btn;
|
||||
}
|
||||
btn.gameObject.SetActive(show);
|
||||
btn.GetComponentInChildren<Text>().text = data[index];
|
||||
}
|
||||
|
||||
public void UpdateButtonColor(int index,Color ableColor,Color unableColor)
|
||||
{
|
||||
if (IsShowSeries(index))
|
||||
{
|
||||
m_DataBtnList[index].GetComponent<Image>().color = ableColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_DataBtnList[index].GetComponent<Image>().color = unableColor;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetShowData(string name, bool flag)
|
||||
{
|
||||
for (int i = 0; i < data.Count; i++)
|
||||
{
|
||||
if (data[i].Equals(name))
|
||||
{
|
||||
m_DataShowList[i] = flag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnChanged()
|
||||
{
|
||||
m_Location.OnChanged();
|
||||
}
|
||||
|
||||
private Vector2 GetButtonLocationPosition(int index)
|
||||
{
|
||||
int size = m_Data.Count;
|
||||
switch (m_Orient)
|
||||
{
|
||||
case Orient.Vertical:
|
||||
switch (m_Location.align)
|
||||
{
|
||||
case Location.Align.TopCenter:
|
||||
case Location.Align.TopLeft:
|
||||
case Location.Align.TopRight:
|
||||
return new Vector2(0, -index * (itemHeight + itemGap));
|
||||
|
||||
case Location.Align.Center:
|
||||
case Location.Align.CenterLeft:
|
||||
case Location.Align.CenterRight:
|
||||
float totalHeight = size * itemHeight + (size - 1) * itemGap;
|
||||
float startY = totalHeight / 2;
|
||||
return new Vector2(0, startY - index * (itemHeight + itemGap));
|
||||
|
||||
case Location.Align.BottomCenter:
|
||||
case Location.Align.BottomLeft:
|
||||
case Location.Align.BottomRight:
|
||||
return new Vector2(0, (size - index - 1) * (itemHeight + itemGap));
|
||||
}
|
||||
return Vector2.zero;
|
||||
|
||||
case Orient.Horizonal:
|
||||
switch (m_Location.align)
|
||||
{
|
||||
case Location.Align.TopLeft:
|
||||
case Location.Align.CenterLeft:
|
||||
case Location.Align.BottomLeft:
|
||||
return new Vector2(index * (itemWidth + itemGap), 0);
|
||||
|
||||
case Location.Align.TopCenter:
|
||||
case Location.Align.Center:
|
||||
case Location.Align.BottomCenter:
|
||||
float totalWidth = size * itemWidth + (size - 1) * itemGap;
|
||||
float startX = totalWidth / 2;
|
||||
return new Vector2(-startX + itemWidth / 2 + index * (itemWidth + itemGap), 0);
|
||||
case Location.Align.TopRight:
|
||||
case Location.Align.CenterRight:
|
||||
case Location.Align.BottomRight:
|
||||
return new Vector2(-(size - index - 1) * (itemWidth + itemGap), 0);
|
||||
}
|
||||
return Vector2.zero;
|
||||
}
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
public override void ParseJsonData(string jsonData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
||||
m_Data = ChartHelper.ParseStringFromString(jsonData);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/Legend.cs.meta
Normal file
13
Scripts/UI/Internal/Legend.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3fba76b49d7dd644cb3953355d6caae4
|
||||
timeCreated: 1554222818
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
Scripts/UI/Internal/Line.cs
Normal file
41
Scripts/UI/Internal/Line.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Line
|
||||
{
|
||||
[SerializeField] private float m_Tickness;
|
||||
[SerializeField] private bool m_Point;
|
||||
[SerializeField] private float m_PointWidth;
|
||||
[SerializeField] private bool m_Smooth;
|
||||
[SerializeField] [Range(1f, 10f)] private float m_SmoothStyle;
|
||||
[SerializeField] private bool m_Area;
|
||||
[SerializeField] private Color m_AreaColor;
|
||||
|
||||
public float tickness { get { return m_Tickness; } set { m_Tickness = value; } }
|
||||
public bool point { get { return m_Point; } set { m_Point = value; } }
|
||||
public float pointWidth { get { return m_PointWidth; } set { m_PointWidth = value; } }
|
||||
public bool smooth { get { return m_Smooth; } set { m_Smooth = value; } }
|
||||
public float smoothStyle { get { return m_SmoothStyle; } set { m_SmoothStyle = value; } }
|
||||
public bool area { get { return m_Area; } set { m_Area = value; } }
|
||||
public Color areaColor { get { return m_AreaColor; } set { m_AreaColor = value; } }
|
||||
|
||||
public static Line defaultLine
|
||||
{
|
||||
get
|
||||
{
|
||||
var line = new Line
|
||||
{
|
||||
m_Tickness = 0.8f,
|
||||
m_Point = true,
|
||||
m_PointWidth = 2.5f,
|
||||
m_Smooth = false,
|
||||
m_SmoothStyle = 2f,
|
||||
m_Area = false
|
||||
};
|
||||
return line;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/Line.cs.meta
Normal file
13
Scripts/UI/Internal/Line.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86acdbfd671c43949bf0cc4880a4ccb7
|
||||
timeCreated: 1555671450
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
240
Scripts/UI/Internal/Location.cs
Normal file
240
Scripts/UI/Internal/Location.cs
Normal file
@@ -0,0 +1,240 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[Serializable]
|
||||
public class Location : IPropertyChanged, IEquatable<Location>
|
||||
{
|
||||
public enum Align
|
||||
{
|
||||
TopLeft,
|
||||
TopRight,
|
||||
TopCenter,
|
||||
BottomLeft,
|
||||
BottomRight,
|
||||
BottomCenter,
|
||||
Center,
|
||||
CenterLeft,
|
||||
CenterRight
|
||||
}
|
||||
|
||||
[SerializeField] private Align m_Align = Align.TopCenter;
|
||||
[SerializeField] private float m_Left;
|
||||
[SerializeField] private float m_Right;
|
||||
[SerializeField] private float m_Top;
|
||||
[SerializeField] private float m_Bottom;
|
||||
|
||||
private TextAnchor m_TextAnchor;
|
||||
private Vector2 m_AnchorMin;
|
||||
private Vector2 m_AnchorMax;
|
||||
private Vector2 m_Pivot;
|
||||
|
||||
public Align align { get { return m_Align; } set { m_Align = value; UpdateAlign(); } }
|
||||
public float left { get { return m_Left; } set { m_Left = value; UpdateAlign(); } }
|
||||
public float right { get { return m_Right; } set { m_Right = value; UpdateAlign(); } }
|
||||
public float top { get { return m_Top; } set { m_Top = value; UpdateAlign(); } }
|
||||
public float bottom { get { return m_Bottom; } set { m_Bottom = value; UpdateAlign(); } }
|
||||
|
||||
public TextAnchor textAnchor { get { return m_TextAnchor; } }
|
||||
public Vector2 anchorMin { get { return m_AnchorMin; } }
|
||||
public Vector2 anchorMax { get { return m_AnchorMax; } }
|
||||
public Vector2 pivot { get { return m_Pivot; } }
|
||||
|
||||
public static Location defaultLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Location()
|
||||
{
|
||||
align = Align.CenterRight,
|
||||
left = 5,
|
||||
right = 0,
|
||||
top = 0,
|
||||
bottom = 0
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static Location defaultRight
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Location()
|
||||
{
|
||||
align = Align.CenterRight,
|
||||
left = 0,
|
||||
right = 5,
|
||||
top = 0,
|
||||
bottom = 0
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static Location defaultTop
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Location()
|
||||
{
|
||||
align = Align.TopCenter,
|
||||
left = 0,
|
||||
right = 0,
|
||||
top = 5,
|
||||
bottom = 0
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static Location defaultBottom
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Location()
|
||||
{
|
||||
align = Align.BottomCenter,
|
||||
left = 0,
|
||||
right = 0,
|
||||
top = 0,
|
||||
bottom = 5
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAlign()
|
||||
{
|
||||
switch (m_Align)
|
||||
{
|
||||
case Align.BottomCenter:
|
||||
m_TextAnchor = TextAnchor.LowerCenter;
|
||||
m_AnchorMin = new Vector2(0.5f, 0);
|
||||
m_AnchorMax = new Vector2(0.5f, 0);
|
||||
m_Pivot = new Vector2(0.5f, 0);
|
||||
break;
|
||||
case Align.BottomLeft:
|
||||
m_TextAnchor = TextAnchor.LowerLeft;
|
||||
m_AnchorMin = new Vector2(0, 0);
|
||||
m_AnchorMax = new Vector2(0, 0);
|
||||
m_Pivot = new Vector2(0, 0);
|
||||
break;
|
||||
case Align.BottomRight:
|
||||
m_TextAnchor = TextAnchor.LowerRight;
|
||||
m_AnchorMin = new Vector2(1, 0);
|
||||
m_AnchorMax = new Vector2(1, 0);
|
||||
m_Pivot = new Vector2(1, 0);
|
||||
break;
|
||||
case Align.Center:
|
||||
m_TextAnchor = TextAnchor.MiddleCenter;
|
||||
m_AnchorMin = new Vector2(0.5f, 0.5f);
|
||||
m_AnchorMax = new Vector2(0.5f, 0.5f);
|
||||
m_Pivot = new Vector2(0.5f, 0.5f);
|
||||
break;
|
||||
case Align.CenterLeft:
|
||||
m_TextAnchor = TextAnchor.MiddleLeft;
|
||||
m_AnchorMin = new Vector2(0, 0.5f);
|
||||
m_AnchorMax = new Vector2(0, 0.5f);
|
||||
m_Pivot = new Vector2(0, 0.5f);
|
||||
break;
|
||||
case Align.CenterRight:
|
||||
m_TextAnchor = TextAnchor.MiddleRight;
|
||||
m_AnchorMin = new Vector2(1, 0.5f);
|
||||
m_AnchorMax = new Vector2(1, 0.5f);
|
||||
m_Pivot = new Vector2(1, 0.5f);
|
||||
break;
|
||||
case Align.TopCenter:
|
||||
m_TextAnchor = TextAnchor.UpperCenter;
|
||||
m_AnchorMin = new Vector2(0.5f, 1);
|
||||
m_AnchorMax = new Vector2(0.5f, 1);
|
||||
m_Pivot = new Vector2(0.5f, 1);
|
||||
break;
|
||||
case Align.TopLeft:
|
||||
m_TextAnchor = TextAnchor.UpperLeft;
|
||||
m_AnchorMin = new Vector2(0, 1);
|
||||
m_AnchorMax = new Vector2(0, 1);
|
||||
m_Pivot = new Vector2(0, 1);
|
||||
break;
|
||||
case Align.TopRight:
|
||||
m_TextAnchor = TextAnchor.UpperRight;
|
||||
m_AnchorMin = new Vector2(1, 1);
|
||||
m_AnchorMax = new Vector2(1, 1);
|
||||
m_Pivot = new Vector2(1, 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 GetPosition(float chartWidht, float chartHeight)
|
||||
{
|
||||
switch (align)
|
||||
{
|
||||
case Align.BottomCenter:
|
||||
return new Vector2(chartWidht / 2, bottom);
|
||||
case Align.BottomLeft:
|
||||
return new Vector2(left, bottom);
|
||||
case Align.BottomRight:
|
||||
return new Vector2(chartWidht - right, bottom);
|
||||
case Align.Center:
|
||||
return new Vector2(chartWidht / 2, chartHeight / 2);
|
||||
case Align.CenterLeft:
|
||||
return new Vector2(left, chartHeight / 2);
|
||||
case Align.CenterRight:
|
||||
return new Vector2(chartWidht - right, chartHeight / 2);
|
||||
case Align.TopCenter:
|
||||
return new Vector2(chartWidht / 2, chartHeight - top);
|
||||
case Align.TopLeft:
|
||||
return new Vector2(left, chartHeight - top);
|
||||
case Align.TopRight:
|
||||
return new Vector2(chartWidht - right, chartHeight - top);
|
||||
default:
|
||||
return Vector2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
public void Copy(Location location)
|
||||
{
|
||||
m_Align = location.align;
|
||||
m_Left = location.left;
|
||||
m_Right = location.right;
|
||||
m_Top = location.top;
|
||||
m_Bottom = location.bottom;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Location))
|
||||
return false;
|
||||
|
||||
return Equals((Location)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Location other)
|
||||
{
|
||||
return align == other.align &&
|
||||
left == other.left &&
|
||||
right == other.right &&
|
||||
top == other.top &&
|
||||
bottom == other.bottom;
|
||||
}
|
||||
|
||||
public static bool operator ==(Location point1, Location point2)
|
||||
{
|
||||
return point1.Equals(point2);
|
||||
}
|
||||
|
||||
public static bool operator !=(Location point1, Location point2)
|
||||
{
|
||||
return !point1.Equals(point2);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public void OnChanged()
|
||||
{
|
||||
UpdateAlign();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/Location.cs.meta
Normal file
13
Scripts/UI/Internal/Location.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 453c586e78719f046a387172174edb36
|
||||
timeCreated: 1554306777
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Scripts/UI/Internal/Pie.cs
Normal file
46
Scripts/UI/Internal/Pie.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Pie
|
||||
{
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private float m_InsideRadius;
|
||||
[SerializeField] private float m_OutsideRadius;
|
||||
[SerializeField] private float m_TooltipExtraRadius;
|
||||
[SerializeField] private bool m_Rose;
|
||||
[SerializeField] private float m_Space;
|
||||
[SerializeField] private float m_Left;
|
||||
[SerializeField] private float m_Right;
|
||||
[SerializeField] private float m_Top;
|
||||
[SerializeField] private float m_Bottom;
|
||||
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
public float insideRadius { get { return m_InsideRadius; } set { m_InsideRadius = value; } }
|
||||
public float outsideRadius { get { return m_OutsideRadius; } set { m_OutsideRadius = value; } }
|
||||
public float tooltipExtraRadius { get { return m_TooltipExtraRadius; } set { m_TooltipExtraRadius = value; } }
|
||||
public bool rose { get { return m_Rose; } set { m_Rose = value; } }
|
||||
public float space { get { return m_Space; } set { m_Space = value; } }
|
||||
public float left { get { return m_Left; } set { m_Left = value; } }
|
||||
public float right { get { return m_Right; } set { m_Right = value; } }
|
||||
public float top { get { return m_Top; } set { m_Top = value; } }
|
||||
public float bottom { get { return m_Bottom; } set { m_Bottom = value; } }
|
||||
|
||||
public static Pie defaultPie
|
||||
{
|
||||
get
|
||||
{
|
||||
var pie = new Pie
|
||||
{
|
||||
m_Name = "Pie",
|
||||
m_InsideRadius = 0f,
|
||||
m_OutsideRadius = 80f,
|
||||
m_TooltipExtraRadius = 10f,
|
||||
m_Rose = false
|
||||
};
|
||||
return pie;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/Pie.cs.meta
Normal file
13
Scripts/UI/Internal/Pie.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f38ef4633bae5247a8c382a4d20fc39
|
||||
timeCreated: 1555671161
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
189
Scripts/UI/Internal/Radar.cs
Normal file
189
Scripts/UI/Internal/Radar.cs
Normal file
@@ -0,0 +1,189 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Radar : JsonDataSupport, IEquatable<Radar>
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Indicator: IEquatable<Indicator>
|
||||
{
|
||||
public string m_Name;
|
||||
public float m_Max;
|
||||
|
||||
public string name { get { return m_Name; }set { m_Name = value; } }
|
||||
public float max { get { return m_Max; }set { m_Max = value; } }
|
||||
|
||||
public Indicator Clone()
|
||||
{
|
||||
return new Indicator()
|
||||
{
|
||||
name = name,
|
||||
max = max
|
||||
};
|
||||
}
|
||||
|
||||
public bool Equals(Indicator other)
|
||||
{
|
||||
return name.Equals(other.name);
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] private bool m_Cricle;
|
||||
[SerializeField] private bool m_Area;
|
||||
|
||||
[SerializeField] private float m_Radius = 100;
|
||||
[SerializeField] private int m_SplitNumber = 5;
|
||||
|
||||
[SerializeField] private float m_Left;
|
||||
[SerializeField] private float m_Right;
|
||||
[SerializeField] private float m_Top;
|
||||
[SerializeField] private float m_Bottom;
|
||||
|
||||
[SerializeField] private float m_LineTickness = 1f;
|
||||
[SerializeField] private float m_LinePointSize = 5f;
|
||||
[SerializeField] private Color m_LineColor = Color.grey;
|
||||
|
||||
[SerializeField] private List<Color> m_BackgroundColorList = new List<Color>();
|
||||
[SerializeField] private bool m_Indicator = true;
|
||||
[SerializeField] private List<Indicator> m_IndicatorList = new List<Indicator>();
|
||||
|
||||
public bool cricle { get { return m_Cricle; } set { m_Cricle = value; } }
|
||||
public bool area { get { return m_Area; } set { m_Area = value; } }
|
||||
|
||||
public float radius { get { return m_Radius; } set { m_Radius = value; } }
|
||||
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
|
||||
|
||||
public float left { get { return m_Left; } set { m_Left = value; } }
|
||||
public float right { get { return m_Right; } set { m_Right = value; } }
|
||||
public float top { get { return m_Top; } set { m_Top = value; } }
|
||||
public float bottom { get { return m_Bottom; } set { m_Bottom = value; } }
|
||||
|
||||
public float lineTickness { get { return m_LineTickness; } set { m_LineTickness = value; } }
|
||||
public float linePointSize { get { return m_LinePointSize; } set { m_LinePointSize = value; } }
|
||||
public Color lineColor { get { return m_LineColor; } set { m_LineColor = value; } }
|
||||
public List<Color> backgroundColorList { get { return m_BackgroundColorList; } }
|
||||
public bool indicator { get { return m_Indicator; } set { m_Indicator = value; } }
|
||||
public List<Indicator> indicatorList { get { return m_IndicatorList; } }
|
||||
|
||||
public static Radar defaultRadar
|
||||
{
|
||||
get {
|
||||
var radar = new Radar
|
||||
{
|
||||
m_Cricle = false,
|
||||
m_Area = false,
|
||||
m_Radius = 100,
|
||||
m_SplitNumber = 5,
|
||||
m_Left = 0,
|
||||
m_Right = 0,
|
||||
m_Top = 0,
|
||||
m_Bottom = 0,
|
||||
m_LineTickness = 1f,
|
||||
m_LinePointSize = 5f,
|
||||
m_LineColor = Color.grey,
|
||||
m_Indicator = true,
|
||||
m_BackgroundColorList = new List<Color> {
|
||||
new Color32(194, 53, 49, 255),
|
||||
new Color32(47, 69, 84, 255)
|
||||
},
|
||||
m_IndicatorList = new List<Indicator>(5)
|
||||
};
|
||||
return radar;
|
||||
}
|
||||
}
|
||||
|
||||
public void Copy(Radar other)
|
||||
{
|
||||
m_Radius = other.radius;
|
||||
m_SplitNumber = other.splitNumber;
|
||||
m_Left = other.left;
|
||||
m_Right = other.right;
|
||||
m_Top = other.top;
|
||||
m_Bottom = other.bottom;
|
||||
m_Indicator = other.indicator;
|
||||
indicatorList.Clear();
|
||||
foreach (var d in other.indicatorList) indicatorList.Add(d.Clone());
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Radar)) return false;
|
||||
return Equals((Radar)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Radar other)
|
||||
{
|
||||
return radius == other.radius &&
|
||||
splitNumber == other.splitNumber &&
|
||||
left == other.left &&
|
||||
right == other.right &&
|
||||
top == other.top &&
|
||||
bottom == other.bottom &&
|
||||
indicator == other.indicator &&
|
||||
IsEqualsIndicatorList(indicatorList, other.indicatorList);
|
||||
}
|
||||
|
||||
private bool IsEqualsIndicatorList(List<Indicator> indicators1,List<Indicator> indicators2)
|
||||
{
|
||||
if (indicators1.Count != indicators2.Count) return false;
|
||||
for(int i = 0; i < indicators1.Count; i++)
|
||||
{
|
||||
var indicator1 = indicators1[i];
|
||||
var indicator2 = indicators2[i];
|
||||
if (!indicator1.Equals(indicator2)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool operator ==(Radar point1, Radar point2)
|
||||
{
|
||||
return point1.Equals(point2);
|
||||
}
|
||||
|
||||
public static bool operator !=(Radar point1, Radar point2)
|
||||
{
|
||||
return !point1.Equals(point2);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public override void ParseJsonData(string jsonData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
||||
string pattern = "[\"|'](.*?)[\"|']";
|
||||
if (Regex.IsMatch(jsonData, pattern))
|
||||
{
|
||||
m_IndicatorList.Clear();
|
||||
MatchCollection m = Regex.Matches(jsonData, pattern);
|
||||
foreach (Match match in m)
|
||||
{
|
||||
m_IndicatorList.Add(new Indicator() {
|
||||
name = match.Groups[1].Value
|
||||
});
|
||||
}
|
||||
}
|
||||
pattern = "(\\d+)";
|
||||
if (Regex.IsMatch(jsonData, pattern))
|
||||
{
|
||||
MatchCollection m = Regex.Matches(jsonData, pattern);
|
||||
int index = 0;
|
||||
foreach (Match match in m)
|
||||
{
|
||||
if (m_IndicatorList[index]!=null)
|
||||
{
|
||||
m_IndicatorList[index].max = int.Parse(match.Groups[1].Value);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/Radar.cs.meta
Normal file
13
Scripts/UI/Internal/Radar.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3a368484f9598e4eb9dfce2471d34da
|
||||
timeCreated: 1555562622
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
100
Scripts/UI/Internal/Serie.cs
Normal file
100
Scripts/UI/Internal/Serie.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Serie : JsonDataSupport
|
||||
{
|
||||
public enum SerieType
|
||||
{
|
||||
Line,
|
||||
Bar
|
||||
}
|
||||
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private SerieType m_Type;
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private string m_Stack;
|
||||
[SerializeField] private List<float> m_Data = new List<float>();
|
||||
[SerializeField] private bool m_Flodout;
|
||||
|
||||
public bool show { get { return m_Show; }set { m_Show = value; } }
|
||||
public SerieType type { get { return m_Type; } set { m_Type = value; } }
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
public string stack { get { return m_Stack; } set { m_Stack = value; } }
|
||||
public List<float> data { get { return m_Data; } }
|
||||
|
||||
public float Max
|
||||
{
|
||||
get
|
||||
{
|
||||
float max = int.MinValue;
|
||||
foreach (var data in data)
|
||||
{
|
||||
if (data > max)
|
||||
{
|
||||
max = data;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
public float Total
|
||||
{
|
||||
get
|
||||
{
|
||||
float total = 0;
|
||||
foreach (var data in data)
|
||||
{
|
||||
total += data;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
m_Data.Clear();
|
||||
}
|
||||
|
||||
public void RemoveData(int index)
|
||||
{
|
||||
m_Data.RemoveAt(index);
|
||||
}
|
||||
|
||||
public void AddData(float value, int maxDataNumber)
|
||||
{
|
||||
if (maxDataNumber > 0)
|
||||
{
|
||||
while (m_Data.Count > maxDataNumber) m_Data.RemoveAt(0);
|
||||
}
|
||||
m_Data.Add(value);
|
||||
}
|
||||
|
||||
public float GetData(int index)
|
||||
{
|
||||
if (index >= 0 && index <= data.Count - 1)
|
||||
{
|
||||
return data[index];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void UpdateData(int index, float value)
|
||||
{
|
||||
if (index >= 0 && index <= m_Data.Count - 1)
|
||||
{
|
||||
m_Data[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ParseJsonData(string jsonData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
||||
m_Data = ChartHelper.ParseFloatFromString(jsonData);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/Serie.cs.meta
Normal file
13
Scripts/UI/Internal/Serie.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bde61eb0785bad4d91d84d5511514ba
|
||||
timeCreated: 1554222818
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
221
Scripts/UI/Internal/Series.cs
Normal file
221
Scripts/UI/Internal/Series.cs
Normal file
@@ -0,0 +1,221 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Series : JsonDataSupport
|
||||
{
|
||||
[SerializeField] protected List<Serie> m_Series;
|
||||
|
||||
public List<Serie> series { get { return m_Series; } }
|
||||
|
||||
public int Count { get { return m_Series.Count; } }
|
||||
|
||||
public static Series defaultSeries
|
||||
{
|
||||
get
|
||||
{
|
||||
var series = new Series
|
||||
{
|
||||
m_Series = new List<Serie>()
|
||||
};
|
||||
return series;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
foreach(var serie in m_Series)
|
||||
{
|
||||
serie.ClearData();
|
||||
}
|
||||
}
|
||||
|
||||
public float GetData(int serieIndex,int dataIndex)
|
||||
{
|
||||
if(serieIndex >= 0 && serieIndex < Count)
|
||||
{
|
||||
return m_Series[serieIndex].GetData(dataIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddData(string legend, float value, int maxDataNumber = 0)
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (m_Series[i].name.Equals(legend))
|
||||
{
|
||||
m_Series[i].AddData(value, maxDataNumber);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddData(int legend, float value, int maxDataNumber = 0)
|
||||
{
|
||||
if (legend >= 0 && legend < Count)
|
||||
{
|
||||
m_Series[legend].AddData(value, maxDataNumber);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateData(string legend, float value, int dataIndex = 0)
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (m_Series[i].name.Equals(legend))
|
||||
{
|
||||
m_Series[i].UpdateData(dataIndex, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateData(int legendIndex, float value, int dataIndex = 0)
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (i == legendIndex)
|
||||
{
|
||||
m_Series[i].UpdateData(dataIndex, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float GetMaxValue(Legend legend)
|
||||
{
|
||||
float max = int.MinValue;
|
||||
if (IsStack())
|
||||
{
|
||||
var stackSeries = GetStackSeries();
|
||||
foreach (var ss in stackSeries)
|
||||
{
|
||||
var seriesTotalValue = new Dictionary<int, float>();
|
||||
for (int i = 0; i < ss.Value.Count; i++)
|
||||
{
|
||||
var serie = ss.Value[i];
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
if (!seriesTotalValue.ContainsKey(j))
|
||||
seriesTotalValue[j] = 0;
|
||||
seriesTotalValue[j] = seriesTotalValue[j] + serie.data[j];
|
||||
}
|
||||
}
|
||||
float tmax = 0;
|
||||
foreach (var tt in seriesTotalValue)
|
||||
{
|
||||
if (tt.Value > tmax) tmax = tt.Value;
|
||||
}
|
||||
if (tmax > max) max = tmax;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (legend.IsShowSeries(i) && m_Series[i].Max > max) max = m_Series[i].Max;
|
||||
}
|
||||
}
|
||||
if (max == int.MinValue) return 100;
|
||||
if (max < 1 && max > -1) return max;
|
||||
int bigger = (int)Mathf.Abs(max);
|
||||
int n = 1;
|
||||
while (bigger / (Mathf.Pow(10, n)) > 10)
|
||||
{
|
||||
n++;
|
||||
}
|
||||
float mm = bigger < 10 ? bigger : ((bigger - bigger % (Mathf.Pow(10, n))) + Mathf.Pow(10, n));
|
||||
if (max < 0) return -mm;
|
||||
else return mm;
|
||||
}
|
||||
|
||||
public float GetMaxValue(int index,int splitNumber = 0)
|
||||
{
|
||||
float max = int.MinValue;
|
||||
float min = int.MaxValue;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (m_Series[i].data[index] > max)
|
||||
{
|
||||
max = Mathf.Ceil(m_Series[i].data[index]);
|
||||
}
|
||||
if (m_Series[i].data[index] < min)
|
||||
{
|
||||
min = Mathf.Ceil(m_Series[i].data[index]);
|
||||
}
|
||||
}
|
||||
if (max < 1 && max > -1) return max;
|
||||
if (max < 0 && min < 0) max = min;
|
||||
int bigger = (int)Mathf.Abs(max);
|
||||
int n = 1;
|
||||
while (bigger / (Mathf.Pow(10, n)) > 10)
|
||||
{
|
||||
n++;
|
||||
}
|
||||
float mm = bigger < 10 ? bigger : ((bigger - bigger % (Mathf.Pow(10, n))) + Mathf.Pow(10, n));
|
||||
if (max < 1 && max > -1) return max;
|
||||
else if (max < 0) return -mm;
|
||||
else return mm;
|
||||
}
|
||||
|
||||
public bool IsStack()
|
||||
{
|
||||
HashSet<string> sets = new HashSet<string>();
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
if (string.IsNullOrEmpty(serie.stack)) continue;
|
||||
if (sets.Contains(serie.stack)) return true;
|
||||
else
|
||||
{
|
||||
sets.Add(serie.stack);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Dictionary<int, List<Serie>> GetStackSeries()
|
||||
{
|
||||
int count = 0;
|
||||
Dictionary<string, int> sets = new Dictionary<string, int>();
|
||||
Dictionary<int, List<Serie>> stackSeries = new Dictionary<int, List<Serie>>();
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
if (string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
stackSeries[count] = new List<Serie>();
|
||||
stackSeries[count].Add(serie);
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!sets.ContainsKey(serie.stack))
|
||||
{
|
||||
sets.Add(serie.stack, count);
|
||||
stackSeries[count] = new List<Serie>();
|
||||
stackSeries[count].Add(serie);
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
int stackIndex = sets[serie.stack];
|
||||
stackSeries[stackIndex].Add(serie);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stackSeries;
|
||||
}
|
||||
|
||||
public override void ParseJsonData(string jsonData)
|
||||
{
|
||||
//TODO:
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/Series.cs.meta
Normal file
13
Scripts/UI/Internal/Series.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 137f78d348f866943a9fb8c1c8eaceef
|
||||
timeCreated: 1556016849
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
232
Scripts/UI/Internal/Theme.cs
Normal file
232
Scripts/UI/Internal/Theme.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public enum Theme
|
||||
{
|
||||
Default = 1,
|
||||
Light,
|
||||
Dark
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ThemeInfo : IEquatable<ThemeInfo>
|
||||
{
|
||||
[SerializeField] private Font m_Font;
|
||||
[SerializeField] private Color32 m_BackgroundColor;
|
||||
[SerializeField] private Color32 m_ContrastColor;
|
||||
[SerializeField] private Color32 m_TextColor;
|
||||
[SerializeField] private Color32 m_SubTextColor;
|
||||
[SerializeField] private Color32 m_LegendTextColor;
|
||||
[SerializeField] private Color32 m_UnableColor;
|
||||
[SerializeField] private Color32 m_AxisLineColor;
|
||||
[SerializeField] private Color32 m_AxisSplitLineColor;
|
||||
[SerializeField] private Color32 m_TooltipBackgroundColor;
|
||||
[SerializeField] private Color32 m_TooltipFlagAreaColor;
|
||||
[SerializeField] private Color32 m_TooltipTextColor;
|
||||
[SerializeField] private Color32[] m_ColorPalette;
|
||||
|
||||
public Font font { get { return m_Font; } set { m_Font = value; } }
|
||||
public Color32 backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
|
||||
public Color32 contrastColor { get { return m_ContrastColor; } set { m_ContrastColor = value; } }
|
||||
public Color32 textColor { get { return m_TextColor; } set { m_TextColor = value; } }
|
||||
public Color32 subTextColor { get { return m_SubTextColor; } set { m_SubTextColor = value; } }
|
||||
public Color32 legendTextColor { get { return m_LegendTextColor; } set { m_LegendTextColor = value; } }
|
||||
public Color32 unableColor { get { return m_UnableColor; } set { m_UnableColor = value; } }
|
||||
public Color32 axisLineColor { get { return m_AxisLineColor; } set { m_AxisLineColor = value; } }
|
||||
public Color32 axisSplitLineColor { get { return m_AxisSplitLineColor; } set { m_AxisSplitLineColor = value; } }
|
||||
public Color32 tooltipBackgroundColor { get { return m_TooltipBackgroundColor; } set { m_TooltipBackgroundColor = value; } }
|
||||
public Color32 tooltipFlagAreaColor { get { return m_TooltipFlagAreaColor; } set { m_TooltipFlagAreaColor = value; } }
|
||||
public Color32 tooltipTextColor { get { return m_TooltipTextColor; } set { m_TooltipTextColor = value; } }
|
||||
public Color32[] colorPalette { get { return m_ColorPalette; } set { m_ColorPalette = value; } }
|
||||
|
||||
public Color32 GetColor(int index)
|
||||
{
|
||||
if (index < 0)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
index = index % m_ColorPalette.Length;
|
||||
return m_ColorPalette[index];
|
||||
}
|
||||
|
||||
public void Copy(ThemeInfo theme)
|
||||
{
|
||||
m_Font = theme.m_Font;
|
||||
m_BackgroundColor = theme.m_BackgroundColor;
|
||||
m_ContrastColor = theme.m_ContrastColor;
|
||||
m_UnableColor = theme.m_UnableColor;
|
||||
m_TextColor = theme.m_TextColor;
|
||||
m_SubTextColor = theme.m_SubTextColor;
|
||||
m_LegendTextColor = theme.m_LegendTextColor;
|
||||
m_AxisLineColor = theme.m_AxisLineColor;
|
||||
m_AxisSplitLineColor = theme.m_AxisSplitLineColor;
|
||||
m_TooltipBackgroundColor = theme.m_TooltipBackgroundColor;
|
||||
m_TooltipTextColor = theme.m_TooltipTextColor;
|
||||
m_ColorPalette = new Color32[theme.m_ColorPalette.Length];
|
||||
for (int i = 0; i < theme.m_ColorPalette.Length; i++)
|
||||
{
|
||||
m_ColorPalette[i] = theme.m_ColorPalette[i];
|
||||
}
|
||||
}
|
||||
|
||||
public static ThemeInfo Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ThemeInfo()
|
||||
{
|
||||
m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"),
|
||||
m_BackgroundColor = new Color32(255, 255, 255, 255),
|
||||
m_ContrastColor = GetColor("#514D4D"),
|
||||
m_UnableColor = GetColor("#cccccc"),
|
||||
m_TextColor = GetColor("#514D4D"),
|
||||
m_SubTextColor = GetColor("#514D4D"),
|
||||
m_LegendTextColor = GetColor("#eee"),
|
||||
m_AxisLineColor = GetColor("#514D4D"),
|
||||
m_AxisSplitLineColor = GetColor("#51515120"),
|
||||
m_TooltipBackgroundColor = GetColor("#515151B5"),
|
||||
m_TooltipTextColor = GetColor("#FFFFFFFF"),
|
||||
m_TooltipFlagAreaColor = GetColor("#51515120"),
|
||||
m_ColorPalette = new Color32[]
|
||||
{
|
||||
new Color32(194, 53, 49, 255),
|
||||
new Color32(47, 69, 84, 255),
|
||||
new Color32(97, 160, 168, 255),
|
||||
new Color32(212, 130, 101, 255),
|
||||
new Color32(145, 199, 174, 255),
|
||||
new Color32(116, 159, 131, 255),
|
||||
new Color32(202, 134, 34, 255),
|
||||
new Color32(189, 162, 154, 255),
|
||||
new Color32(110, 112, 116, 255),
|
||||
new Color32(84, 101, 112, 255),
|
||||
new Color32(196, 204, 211, 255)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static ThemeInfo Light
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ThemeInfo()
|
||||
{
|
||||
m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"),
|
||||
m_BackgroundColor = new Color32(255, 255, 255, 255),
|
||||
m_ContrastColor = GetColor("#514D4D"),
|
||||
m_UnableColor = GetColor("#cccccc"),
|
||||
m_TextColor = GetColor("#514D4D"),
|
||||
m_SubTextColor = GetColor("#514D4D"),
|
||||
m_LegendTextColor = GetColor("#514D4D"),
|
||||
m_AxisLineColor = GetColor("#514D4D"),
|
||||
m_AxisSplitLineColor = GetColor("#51515120"),
|
||||
m_TooltipBackgroundColor = GetColor("#515151B5"),
|
||||
m_TooltipTextColor = GetColor("#FFFFFFFF"),
|
||||
m_TooltipFlagAreaColor = GetColor("#51515120"),
|
||||
m_ColorPalette = new Color32[]
|
||||
{
|
||||
new Color32(55, 162, 218, 255),
|
||||
new Color32(255, 159, 127, 255),
|
||||
new Color32(50, 197, 233, 255),
|
||||
new Color32(251, 114, 147, 255),
|
||||
new Color32(103, 224, 227, 255),
|
||||
new Color32(224, 98, 174, 255),
|
||||
new Color32(159, 230, 184, 255),
|
||||
new Color32(230, 144, 209, 255),
|
||||
new Color32(255, 219, 92, 255),
|
||||
new Color32(230, 188, 243, 255),
|
||||
new Color32(157, 150, 245, 255),
|
||||
new Color32(131, 120, 234, 255),
|
||||
new Color32(150, 191, 255, 255)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static ThemeInfo Dark
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ThemeInfo()
|
||||
{
|
||||
m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"),
|
||||
m_UnableColor = GetColor("#cccccc"),
|
||||
m_BackgroundColor = new Color32(34, 34, 34, 255),
|
||||
m_ContrastColor = GetColor("#eee"),
|
||||
m_TextColor = GetColor("#eee"),
|
||||
m_SubTextColor = GetColor("#eee"),
|
||||
m_LegendTextColor = GetColor("#eee"),
|
||||
m_AxisLineColor = GetColor("#eee"),
|
||||
m_AxisSplitLineColor = GetColor("#aaa"),
|
||||
m_TooltipBackgroundColor = GetColor("#515151B5"),
|
||||
m_TooltipTextColor = GetColor("#FFFFFFFF"),
|
||||
m_TooltipFlagAreaColor = GetColor("#51515120"),
|
||||
m_ColorPalette = new Color32[]
|
||||
{
|
||||
new Color32(221, 107, 102, 255),
|
||||
new Color32(117, 154, 160, 255),
|
||||
new Color32(230, 157, 135, 255),
|
||||
new Color32(141, 193, 169, 255),
|
||||
new Color32(234, 126, 83, 255),
|
||||
new Color32(238, 221, 120, 255),
|
||||
new Color32(115, 163, 115, 255),
|
||||
new Color32(115, 185, 188, 255),
|
||||
new Color32(114, 137, 171, 255),
|
||||
new Color32(145, 202, 140, 255),
|
||||
new Color32(244, 159, 66, 255)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static Color32 GetColor(string hexColorStr)
|
||||
{
|
||||
Color color;
|
||||
ColorUtility.TryParseHtmlString(hexColorStr, out color);
|
||||
return (Color32)color;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is ThemeInfo))
|
||||
return false;
|
||||
|
||||
return Equals((ThemeInfo)obj);
|
||||
}
|
||||
|
||||
public bool Equals(ThemeInfo other)
|
||||
{
|
||||
return m_Font == other.m_Font &&
|
||||
ChartHelper.IsValueEqualsColor(m_UnableColor, other.m_UnableColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_BackgroundColor, other.m_BackgroundColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_ContrastColor, other.m_ContrastColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_TextColor, other.m_TextColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_SubTextColor, other.m_SubTextColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_AxisLineColor, other.m_AxisLineColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_AxisSplitLineColor, other.m_AxisSplitLineColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_TooltipBackgroundColor, other.m_TooltipBackgroundColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_AxisSplitLineColor, other.m_AxisSplitLineColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_TooltipTextColor, other.m_TooltipTextColor) &&
|
||||
ChartHelper.IsValueEqualsColor(m_TooltipFlagAreaColor, other.m_TooltipFlagAreaColor) &&
|
||||
m_ColorPalette.Length == other.m_ColorPalette.Length;
|
||||
}
|
||||
|
||||
public static bool operator ==(ThemeInfo point1, ThemeInfo point2)
|
||||
{
|
||||
return point1.Equals(point2);
|
||||
}
|
||||
|
||||
public static bool operator !=(ThemeInfo point1, ThemeInfo point2)
|
||||
{
|
||||
return !point1.Equals(point2);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/Theme.cs.meta
Normal file
13
Scripts/UI/Internal/Theme.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 337565e835799d44bb794677abf84498
|
||||
timeCreated: 1554221927
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
91
Scripts/UI/Internal/Title.cs
Normal file
91
Scripts/UI/Internal/Title.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[Serializable]
|
||||
public class Title: IPropertyChanged,IEquatable<Title>
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private string m_Text;
|
||||
[SerializeField] private int m_TextFontSize;
|
||||
[SerializeField] private string m_SubText;
|
||||
[SerializeField] private int m_SubTextFontSize;
|
||||
[SerializeField] private float m_ItemGap;
|
||||
[SerializeField] private Location m_Location;
|
||||
|
||||
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 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; } }
|
||||
public Location location { get { return m_Location; } set { m_Location = value; } }
|
||||
|
||||
public static Title defaultTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
var title = new Title
|
||||
{
|
||||
m_Show = true,
|
||||
m_Text = "Chart Title",
|
||||
m_TextFontSize = 16,
|
||||
m_SubText = "",
|
||||
m_SubTextFontSize = 14,
|
||||
m_ItemGap = 14,
|
||||
m_Location = Location.defaultTop
|
||||
};
|
||||
return title;
|
||||
}
|
||||
}
|
||||
public void Copy(Title title)
|
||||
{
|
||||
m_Show = title.show;
|
||||
m_Text = title.text;
|
||||
m_TextFontSize = title.textFontSize;
|
||||
m_SubText = title.subText;
|
||||
m_SubTextFontSize = title.subTextFontSize;
|
||||
m_ItemGap = title.itemGap;
|
||||
m_Location.Copy(title.location);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Title)) return false;
|
||||
return Equals((Title)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Title other)
|
||||
{
|
||||
return m_Show == other.show &&
|
||||
m_Text.Equals(other.text) &&
|
||||
m_TextFontSize == other.textFontSize &&
|
||||
m_SubText.Equals(other.subText) &&
|
||||
m_SubTextFontSize == other.subTextFontSize &&
|
||||
m_ItemGap == other.itemGap &&
|
||||
m_Location.Equals(other.location);
|
||||
}
|
||||
|
||||
public static bool operator == (Title point1, Title point2)
|
||||
{
|
||||
return point1.Equals(point2);
|
||||
}
|
||||
|
||||
public static bool operator != (Title point1, Title point2)
|
||||
{
|
||||
return !point1.Equals(point2);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public void OnChanged()
|
||||
{
|
||||
m_Location.OnChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/Title.cs.meta
Normal file
13
Scripts/UI/Internal/Title.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e41a7f82b5a931408f301257fbc09e2
|
||||
timeCreated: 1554222818
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
74
Scripts/UI/Internal/Tooltip.cs
Normal file
74
Scripts/UI/Internal/Tooltip.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Tooltip
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
|
||||
[NonSerialized] private GameObject m_GameObject;
|
||||
[NonSerialized] private Text m_Text;
|
||||
[NonSerialized] private RectTransform m_BackgroudRect;
|
||||
|
||||
public bool show { get { return m_Show; }set { m_Show = value; } }
|
||||
public int dataIndex { get; set; }
|
||||
public int lastDataIndex { get; set; }
|
||||
public float width { get { return m_BackgroudRect.sizeDelta.x; } }
|
||||
public float height { get { return m_BackgroudRect.sizeDelta.y; } }
|
||||
|
||||
public static Tooltip defaultTooltip
|
||||
{
|
||||
get
|
||||
{
|
||||
var tooltip = new Tooltip
|
||||
{
|
||||
m_Show = true
|
||||
};
|
||||
return tooltip;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetObj(GameObject obj)
|
||||
{
|
||||
m_GameObject = obj;
|
||||
m_BackgroudRect = m_GameObject.GetComponent<RectTransform>();
|
||||
m_Text = m_GameObject.GetComponentInChildren<Text>();
|
||||
}
|
||||
|
||||
public void SetBackgroundColor(Color color)
|
||||
{
|
||||
m_GameObject.GetComponent<Image>().color = color;
|
||||
}
|
||||
|
||||
public void SetTextColor(Color color)
|
||||
{
|
||||
m_Text.color = color;
|
||||
}
|
||||
|
||||
public void UpdateTooltipText(string txt)
|
||||
{
|
||||
m_Text.text = txt;
|
||||
m_BackgroudRect.sizeDelta = new Vector2(m_Text.preferredWidth + 8, m_Text.preferredHeight + 8);
|
||||
}
|
||||
|
||||
public void SetActive(bool flag)
|
||||
{
|
||||
if(m_GameObject)
|
||||
m_GameObject.SetActive(flag);
|
||||
}
|
||||
|
||||
public void UpdatePos(Vector2 pos)
|
||||
{
|
||||
if(m_GameObject)
|
||||
m_GameObject.transform.localPosition = pos;
|
||||
}
|
||||
|
||||
public Vector3 GetPos()
|
||||
{
|
||||
return m_GameObject.transform.localPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/UI/Internal/Tooltip.cs.meta
Normal file
13
Scripts/UI/Internal/Tooltip.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 015f1aafb9c2e8940be9ef79b984b843
|
||||
timeCreated: 1554222818
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
116
Scripts/UI/LineChart.cs
Normal file
116
Scripts/UI/LineChart.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class LineChart : CoordinateChart
|
||||
{
|
||||
[SerializeField] private Line m_Line = Line.defaultLine;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
m_Line = Line.defaultLine;
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
int seriesCount = m_Series.Count;
|
||||
float max = GetMaxValue();
|
||||
float scaleWid = m_XAxis.GetDataWidth(coordinateWid);
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
if (!m_Legend.IsShowSeries(j)) continue;
|
||||
Serie serie = m_Series.series[j];
|
||||
Color32 color = m_ThemeInfo.GetColor(j);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
float startX = zeroX + (m_XAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
|
||||
: serie.data.Count;
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
{
|
||||
float value = serie.data[i];
|
||||
|
||||
np = new Vector3(startX + i * scaleWid, zeroY + value * coordinateHig / max);
|
||||
if (i > 0)
|
||||
{
|
||||
if (m_Line.smooth)
|
||||
{
|
||||
var list = ChartHelper.GetBezierList(lp, np, m_Line.smoothStyle);
|
||||
Vector3 start, to;
|
||||
start = list[0];
|
||||
for (int k = 1; k < list.Length; k++)
|
||||
{
|
||||
to = list[k];
|
||||
ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color);
|
||||
start = to;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
ChartHelper.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY),
|
||||
new Vector3(lp.x, zeroY), color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
lp = np;
|
||||
}
|
||||
// draw point
|
||||
if (m_Line.point)
|
||||
{
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
{
|
||||
float value = serie.data[i];
|
||||
|
||||
Vector3 p = new Vector3(startX + i * scaleWid,
|
||||
zeroY + value * coordinateHig / max);
|
||||
float pointWid = m_Line.pointWidth;
|
||||
if (m_Tooltip.show && i == m_Tooltip.dataIndex - 1)
|
||||
{
|
||||
pointWid = pointWid * 1.8f;
|
||||
}
|
||||
if (m_Theme == Theme.Dark)
|
||||
{
|
||||
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, color,
|
||||
(int)m_Line.pointWidth * 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, Color.white);
|
||||
ChartHelper.DrawDoughnut(vh, p, pointWid - m_Line.tickness,
|
||||
pointWid, 0, 360, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//draw tooltip line
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
float splitWidth = m_XAxis.GetSplitWidth(coordinateWid);
|
||||
float px = zeroX + (m_Tooltip.dataIndex - 1) * splitWidth + (m_XAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
Vector2 sp = new Vector2(px, zeroY);
|
||||
Vector2 ep = new Vector2(px, zeroY + coordinateHig);
|
||||
ChartHelper.DrawLine(vh, sp, ep, m_Coordinate.tickness, m_ThemeInfo.tooltipFlagAreaColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
202
Scripts/UI/PieChart.cs
Normal file
202
Scripts/UI/PieChart.cs
Normal file
@@ -0,0 +1,202 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class PieChart : BaseChart
|
||||
{
|
||||
[SerializeField] private Pie m_Pie = Pie.defaultPie;
|
||||
|
||||
private float m_PieCenterX = 0f;
|
||||
private float m_PieCenterY = 0f;
|
||||
private float m_PieRadius = 0;
|
||||
private Vector2 m_PieCenter;
|
||||
private List<float> m_AngleList = new List<float>();
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
UpdatePieCenter();
|
||||
float totalDegree = 360;
|
||||
float startDegree = 0;
|
||||
float dataTotal = GetDataTotal();
|
||||
float dataMax = GetDataMax();
|
||||
m_AngleList.Clear();
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (!m_Legend.IsShowSeries(i))
|
||||
{
|
||||
m_AngleList.Add(0);
|
||||
continue;
|
||||
}
|
||||
float value = m_Series.series[i].data[0];
|
||||
float degree = totalDegree * value / dataTotal;
|
||||
float toDegree = startDegree + degree;
|
||||
|
||||
float outSideRadius = m_Pie.rose ?
|
||||
m_Pie.insideRadius + (m_PieRadius - m_Pie.insideRadius) * value / dataMax :
|
||||
m_PieRadius;
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex == i + 1)
|
||||
{
|
||||
outSideRadius += m_Pie.tooltipExtraRadius;
|
||||
}
|
||||
ChartHelper.DrawDoughnut(vh, m_PieCenter, m_Pie.insideRadius,
|
||||
outSideRadius, startDegree, toDegree, m_ThemeInfo.GetColor(i));
|
||||
m_AngleList.Add(toDegree);
|
||||
startDegree = toDegree;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLegendButtonClicked()
|
||||
{
|
||||
base.OnLegendButtonClicked();
|
||||
|
||||
}
|
||||
|
||||
private float GetDataTotal()
|
||||
{
|
||||
float total = 0;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (m_Legend.IsShowSeries(i))
|
||||
{
|
||||
total += m_Series.series[i].GetData(0);
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
private float GetDataMax()
|
||||
{
|
||||
float max = 0;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (m_Legend.IsShowSeries(i) && m_Series.series[i].GetData(0) > max)
|
||||
{
|
||||
max = m_Series.series[i].GetData(0);
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
private void UpdatePieCenter()
|
||||
{
|
||||
float diffX = chartWidth - m_Pie.left - m_Pie.right;
|
||||
float diffY = chartHeight - m_Pie.top - m_Pie.bottom;
|
||||
float diff = Mathf.Min(diffX, diffY);
|
||||
if (m_Pie.outsideRadius <= 0)
|
||||
{
|
||||
m_PieRadius = diff / 3 * 2;
|
||||
m_PieCenterX = m_Pie.left + m_PieRadius;
|
||||
m_PieCenterY = m_Pie.bottom + m_PieRadius;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_PieRadius = m_Pie.outsideRadius;
|
||||
m_PieCenterX = chartWidth / 2;
|
||||
m_PieCenterY = chartHeight / 2;
|
||||
if (m_Pie.left > 0) m_PieCenterX = m_Pie.left + m_PieRadius;
|
||||
if (m_Pie.right > 0) m_PieCenterX = chartWidth - m_Pie.right - m_PieRadius;
|
||||
if (m_Pie.top > 0) m_PieCenterY = chartHeight - m_Pie.top - m_PieRadius;
|
||||
if (m_Pie.bottom > 0) m_PieCenterY = m_Pie.bottom + m_PieRadius;
|
||||
}
|
||||
m_PieCenter = new Vector2(m_PieCenterX, m_PieCenterY);
|
||||
}
|
||||
|
||||
protected override void CheckTootipArea(Vector2 local)
|
||||
{
|
||||
|
||||
float dist = Vector2.Distance(local, m_PieCenter);
|
||||
if (dist > m_PieRadius)
|
||||
{
|
||||
m_Tooltip.dataIndex = 0;
|
||||
m_Tooltip.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 dir = local - m_PieCenter;
|
||||
float angle = VectorAngle(Vector2.up, dir);
|
||||
m_Tooltip.dataIndex = 0;
|
||||
for (int i = m_AngleList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (i == 0 && angle < m_AngleList[i])
|
||||
{
|
||||
m_Tooltip.dataIndex = 1;
|
||||
break;
|
||||
}
|
||||
else if (angle < m_AngleList[i] && angle > m_AngleList[i - 1])
|
||||
{
|
||||
m_Tooltip.dataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
m_Tooltip.UpdatePos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
if (m_Tooltip.lastDataIndex != m_Tooltip.dataIndex)
|
||||
{
|
||||
RefreshChart();
|
||||
}
|
||||
m_Tooltip.lastDataIndex = m_Tooltip.dataIndex;
|
||||
}
|
||||
}
|
||||
|
||||
float VectorAngle(Vector2 from, Vector2 to)
|
||||
{
|
||||
float angle;
|
||||
|
||||
Vector3 cross = Vector3.Cross(from, to);
|
||||
angle = Vector2.Angle(from, to);
|
||||
angle = cross.z > 0 ? -angle : angle;
|
||||
angle = (angle + 360) % 360;
|
||||
return angle;
|
||||
}
|
||||
|
||||
protected override void RefreshTooltip()
|
||||
{
|
||||
base.RefreshTooltip();
|
||||
int index = m_Tooltip.dataIndex - 1;
|
||||
if (index < 0)
|
||||
{
|
||||
m_Tooltip.SetActive(false);
|
||||
return;
|
||||
}
|
||||
m_Tooltip.SetActive(true);
|
||||
string strColor = ColorUtility.ToHtmlStringRGBA(m_ThemeInfo.GetColor(index));
|
||||
string key = m_Legend.data[index];
|
||||
float value = m_Series.series[index].data[0];
|
||||
string txt = "";
|
||||
if (!string.IsNullOrEmpty(m_Pie.name))
|
||||
{
|
||||
txt += m_Pie.name + "\n";
|
||||
}
|
||||
txt += string.Format("<color=#{0}>● </color>{1}: {2}", strColor, key, value);
|
||||
m_Tooltip.UpdateTooltipText(txt);
|
||||
|
||||
var pos = m_Tooltip.GetPos();
|
||||
if (pos.x + m_Tooltip.width > chartWidth)
|
||||
{
|
||||
pos.x = chartWidth - m_Tooltip.width;
|
||||
}
|
||||
if (pos.y - m_Tooltip.height < 0)
|
||||
{
|
||||
pos.y = m_Tooltip.height;
|
||||
}
|
||||
m_Tooltip.UpdatePos(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
347
Scripts/UI/RadarChart.cs
Normal file
347
Scripts/UI/RadarChart.cs
Normal file
@@ -0,0 +1,347 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class RadarChart : BaseChart
|
||||
{
|
||||
private const string INDICATOR_TEXT = "indicator";
|
||||
|
||||
[SerializeField]
|
||||
private Radar m_Radar = Radar.defaultRadar;
|
||||
private Radar m_CheckRadar = Radar.defaultRadar;
|
||||
private float m_RadarCenterX = 0f;
|
||||
private float m_RadarCenterY = 0f;
|
||||
private float m_RadarRadius = 0;
|
||||
private List<Text> indicatorTextList = new List<Text>();
|
||||
private List<List<Vector3>> dataPosList = new List<List<Vector3>>();
|
||||
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
UpdateRadarCenter();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
CheckRadarInfoChanged();
|
||||
}
|
||||
|
||||
private void InitIndicator()
|
||||
{
|
||||
indicatorTextList.Clear();
|
||||
ChartHelper.HideAllObject(transform, INDICATOR_TEXT);
|
||||
int indicatorNum = m_Radar.indicatorList.Count;
|
||||
float txtWid = 100;
|
||||
float txtHig = 20;
|
||||
for (int i = 0; i < indicatorNum; i++)
|
||||
{
|
||||
var pos = GetIndicatorPosition(i);
|
||||
TextAnchor anchor = TextAnchor.MiddleCenter;
|
||||
var diff = pos.x - m_RadarCenterX;
|
||||
if (diff < -1f)
|
||||
{
|
||||
pos = new Vector3(pos.x - 5, pos.y);
|
||||
anchor = TextAnchor.MiddleRight;
|
||||
}
|
||||
else if (diff > 1f)
|
||||
{
|
||||
anchor = TextAnchor.MiddleLeft;
|
||||
pos = new Vector3(pos.x + txtWid + 5, pos.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
anchor = TextAnchor.MiddleCenter;
|
||||
float y = pos.y > m_RadarCenterY ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
|
||||
pos = new Vector3(pos.x + txtWid / 2, y);
|
||||
}
|
||||
Text txt = ChartHelper.AddTextObject(INDICATOR_TEXT + i, transform, m_ThemeInfo.font,
|
||||
m_ThemeInfo.textColor, anchor, Vector2.zero, Vector2.zero, new Vector2(1, 0.5f),
|
||||
new Vector2(txtWid, txtHig));
|
||||
txt.transform.localPosition = pos;
|
||||
txt.text = m_Radar.indicatorList[i].name;
|
||||
txt.gameObject.SetActive(m_Radar.indicator);
|
||||
indicatorTextList.Add(txt);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckRadarInfoChanged()
|
||||
{
|
||||
if (!m_CheckRadar.Equals(m_Radar))
|
||||
{
|
||||
m_CheckRadar.Copy(m_Radar);
|
||||
OnRadarChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRadarChanged()
|
||||
{
|
||||
UpdateRadarCenter();
|
||||
InitIndicator();
|
||||
}
|
||||
|
||||
private Vector3 GetIndicatorPosition(int i)
|
||||
{
|
||||
int indicatorNum = m_Radar.indicatorList.Count;
|
||||
var angle = 2 * Mathf.PI / indicatorNum * i;
|
||||
var x = m_RadarCenterX + m_Radar.radius * Mathf.Sin(angle);
|
||||
var y = m_RadarCenterY + m_Radar.radius * Mathf.Cos(angle);
|
||||
|
||||
return new Vector3(x, y);
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
UpdateRadarCenter();
|
||||
if (m_Radar.cricle)
|
||||
DrawCricleRadar(vh);
|
||||
else
|
||||
DrawRadar(vh);
|
||||
DrawData(vh);
|
||||
}
|
||||
|
||||
protected override void OnLegendButtonClicked()
|
||||
{
|
||||
base.OnLegendButtonClicked();
|
||||
}
|
||||
|
||||
protected override void OnThemeChanged()
|
||||
{
|
||||
base.OnThemeChanged();
|
||||
m_Radar.backgroundColorList.Clear();
|
||||
switch (m_Theme)
|
||||
{
|
||||
case Theme.Dark:
|
||||
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#6f6f6f"));
|
||||
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#606060"));
|
||||
break;
|
||||
case Theme.Default:
|
||||
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#f6f6f6"));
|
||||
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#e7e7e7"));
|
||||
break;
|
||||
case Theme.Light:
|
||||
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#f6f6f6"));
|
||||
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#e7e7e7"));
|
||||
break;
|
||||
}
|
||||
InitIndicator();
|
||||
}
|
||||
|
||||
private void DrawData(VertexHelper vh)
|
||||
{
|
||||
int indicatorNum = m_Radar.indicatorList.Count;
|
||||
var angle = 2 * Mathf.PI / indicatorNum;
|
||||
var p = new Vector3(m_RadarCenterX, m_RadarCenterY);
|
||||
Vector3 startPoint = Vector3.zero;
|
||||
Vector3 toPoint = Vector3.zero;
|
||||
Vector3 firstPoint = Vector3.zero;
|
||||
dataPosList.Clear();
|
||||
dataPosList.Capacity = m_Series.Count;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (!m_Legend.IsShowSeries(i))
|
||||
{
|
||||
dataPosList.Add(new List<Vector3>());
|
||||
continue;
|
||||
}
|
||||
var dataList = m_Series.series[i].data;
|
||||
var color = m_ThemeInfo.GetColor(i);
|
||||
var areaColor = new Color(color.r, color.g, color.b, color.a * 0.7f);
|
||||
|
||||
List<Vector3> pointList = new List<Vector3>(dataList.Count);
|
||||
dataPosList.Add(pointList);
|
||||
for (int j = 0; j < dataList.Count; j++)
|
||||
{
|
||||
var max = m_Radar.indicatorList[j].max > 0 ?
|
||||
m_Radar.indicatorList[j].max :
|
||||
GetMaxValue(j);
|
||||
var radius = max<0? m_Radar.radius - m_Radar.radius * dataList[j] / max : m_Radar.radius * dataList[j] / max ;
|
||||
var currAngle = j * angle;
|
||||
if (j == 0)
|
||||
{
|
||||
startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
||||
p.y + radius * Mathf.Cos(currAngle));
|
||||
firstPoint = startPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
||||
p.y + radius * Mathf.Cos(currAngle));
|
||||
if (m_Radar.area)
|
||||
{
|
||||
ChartHelper.DrawTriangle(vh, p, startPoint, toPoint, areaColor);
|
||||
}
|
||||
ChartHelper.DrawLine(vh, startPoint, toPoint, m_Radar.lineTickness, color);
|
||||
startPoint = toPoint;
|
||||
}
|
||||
pointList.Add(startPoint);
|
||||
}
|
||||
if (m_Radar.area) ChartHelper.DrawTriangle(vh, p, startPoint, firstPoint, areaColor);
|
||||
ChartHelper.DrawLine(vh, startPoint, firstPoint, m_Radar.lineTickness, color);
|
||||
foreach (var point in pointList)
|
||||
{
|
||||
float radius = m_Radar.linePointSize - m_Radar.lineTickness * 2;
|
||||
|
||||
ChartHelper.DrawCricle(vh, point, radius, Color.white);
|
||||
ChartHelper.DrawDoughnut(vh, point, radius, m_Radar.linePointSize, 0, 360, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawRadar(VertexHelper vh)
|
||||
{
|
||||
float insideRadius = 0, outsideRadius = 0;
|
||||
float block = m_Radar.radius / m_Radar.splitNumber;
|
||||
int indicatorNum = m_Radar.indicatorList.Count;
|
||||
Vector3 p1, p2, p3, p4;
|
||||
Vector3 p = new Vector3(m_RadarCenterX, m_RadarCenterY);
|
||||
float angle = 2 * Mathf.PI / indicatorNum;
|
||||
for (int i = 0; i < m_Radar.splitNumber; i++)
|
||||
{
|
||||
Color color = m_Radar.backgroundColorList[i % m_Radar.backgroundColorList.Count];
|
||||
outsideRadius = insideRadius + block;
|
||||
p1 = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0));
|
||||
p2 = new Vector3(p.x + outsideRadius * Mathf.Sin(0), p.y + outsideRadius * Mathf.Cos(0));
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
{
|
||||
float currAngle = j * angle;
|
||||
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle),
|
||||
p.y + insideRadius * Mathf.Cos(currAngle));
|
||||
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
ChartHelper.DrawLine(vh, p2, p3, m_Radar.lineTickness, m_Radar.lineColor);
|
||||
p1 = p4;
|
||||
p2 = p3;
|
||||
}
|
||||
insideRadius = outsideRadius;
|
||||
}
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
{
|
||||
float currAngle = j * angle;
|
||||
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
ChartHelper.DrawLine(vh, p, p3, m_Radar.lineTickness / 2, m_Radar.lineColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCricleRadar(VertexHelper vh)
|
||||
{
|
||||
float insideRadius = 0, outsideRadius = 0;
|
||||
float block = m_Radar.radius / m_Radar.splitNumber;
|
||||
int indicatorNum = m_Radar.indicatorList.Count;
|
||||
Vector3 p = new Vector3(m_RadarCenterX, m_RadarCenterY);
|
||||
Vector3 p1;
|
||||
float angle = 2 * Mathf.PI / indicatorNum;
|
||||
for (int i = 0; i < m_Radar.splitNumber; i++)
|
||||
{
|
||||
Color color = m_Radar.backgroundColorList[i % m_Radar.backgroundColorList.Count];
|
||||
outsideRadius = insideRadius + block;
|
||||
ChartHelper.DrawDoughnut(vh, p, insideRadius, outsideRadius, 0, 360, color);
|
||||
ChartHelper.DrawCicleNotFill(vh, p, outsideRadius, m_Radar.lineTickness,
|
||||
m_Radar.lineColor);
|
||||
insideRadius = outsideRadius;
|
||||
}
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
{
|
||||
float currAngle = j * angle;
|
||||
p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
ChartHelper.DrawLine(vh, p, p1, m_Radar.lineTickness / 2, m_Radar.lineColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRadarCenter()
|
||||
{
|
||||
float diffX = chartWidth - m_Radar.left - m_Radar.right;
|
||||
float diffY = chartHeight - m_Radar.top - m_Radar.bottom;
|
||||
float diff = Mathf.Min(diffX, diffY);
|
||||
if (m_Radar.radius <= 0)
|
||||
{
|
||||
m_RadarRadius = diff / 3 * 2;
|
||||
m_RadarCenterX = m_Radar.left + m_RadarRadius;
|
||||
m_RadarCenterY = m_Radar.bottom + m_RadarRadius;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_RadarRadius = m_Radar.radius;
|
||||
m_RadarCenterX = chartWidth / 2;
|
||||
m_RadarCenterY = chartHeight / 2;
|
||||
if (m_Radar.left > 0) m_RadarCenterX = m_Radar.left + m_RadarRadius;
|
||||
if (m_Radar.right > 0) m_RadarCenterX = chartWidth - m_Radar.right - m_RadarRadius;
|
||||
if (m_Radar.top > 0) m_RadarCenterY = chartHeight - m_Radar.top - m_RadarRadius;
|
||||
if (m_Radar.bottom > 0) m_RadarCenterY = m_Radar.bottom + m_RadarRadius;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CheckTootipArea(Vector2 local)
|
||||
{
|
||||
if (dataPosList.Count <= 0) return;
|
||||
m_Tooltip.dataIndex = 0;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (!m_Legend.IsShowSeries(i)) continue;
|
||||
for (int j = 0; j < dataPosList[i].Count; j++)
|
||||
{
|
||||
if (Vector3.Distance(local, dataPosList[i][j]) <= m_Radar.linePointSize * 1.2f)
|
||||
{
|
||||
m_Tooltip.dataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
m_Tooltip.UpdatePos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
if (m_Tooltip.lastDataIndex != m_Tooltip.dataIndex)
|
||||
{
|
||||
RefreshChart();
|
||||
}
|
||||
m_Tooltip.lastDataIndex = m_Tooltip.dataIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Tooltip.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RefreshTooltip()
|
||||
{
|
||||
base.RefreshTooltip();
|
||||
int index = m_Tooltip.dataIndex - 1;
|
||||
if (index < 0)
|
||||
{
|
||||
m_Tooltip.SetActive(false);
|
||||
return;
|
||||
}
|
||||
m_Tooltip.SetActive(true);
|
||||
StringBuilder sb = new StringBuilder(m_Legend.data[index]);
|
||||
for (int i = 0; i < m_Radar.indicatorList.Count; i++)
|
||||
{
|
||||
string key = m_Radar.indicatorList[i].name;
|
||||
float value = m_Series.series[index].data[i];
|
||||
sb.Append("\n");
|
||||
sb.AppendFormat("{0}: {1}", key, value);
|
||||
}
|
||||
m_Tooltip.UpdateTooltipText(sb.ToString());
|
||||
|
||||
var pos = m_Tooltip.GetPos();
|
||||
if (pos.x + m_Tooltip.width > chartWidth)
|
||||
{
|
||||
pos.x = chartWidth - m_Tooltip.width;
|
||||
}
|
||||
if (pos.y - m_Tooltip.height < 0)
|
||||
{
|
||||
pos.y = m_Tooltip.height;
|
||||
}
|
||||
m_Tooltip.UpdatePos(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Scripts/UI/Utility.meta
Normal file
10
Scripts/UI/Utility.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3f97e494bd29fb43a2e17e14bd12b28
|
||||
folderAsset: yes
|
||||
timeCreated: 1554221615
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user