2018-09-21 22:30:48 +08:00
|
|
|
|
using UnityEngine;
|
2018-09-15 06:52:42 +08:00
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
namespace xcharts
|
|
|
|
|
|
{
|
2018-09-18 08:12:16 +08:00
|
|
|
|
[System.Serializable]
|
2018-09-23 08:18:26 +08:00
|
|
|
|
public class BarInfo
|
2018-09-18 08:12:16 +08:00
|
|
|
|
{
|
|
|
|
|
|
public float barWid = 0.7f;
|
|
|
|
|
|
public float space;
|
|
|
|
|
|
}
|
2018-09-15 06:52:42 +08:00
|
|
|
|
|
2018-09-28 06:34:19 +08:00
|
|
|
|
public class BarChart : BaseAxesChart
|
2018-09-15 06:52:42 +08:00
|
|
|
|
{
|
2018-09-18 08:12:16 +08:00
|
|
|
|
[SerializeField]
|
2018-10-01 17:00:15 +08:00
|
|
|
|
private BarInfo barInfo = new BarInfo();
|
2018-09-18 08:12:16 +08:00
|
|
|
|
|
2018-09-18 06:56:41 +08:00
|
|
|
|
protected override void Awake()
|
2018-09-15 06:52:42 +08:00
|
|
|
|
{
|
2018-09-18 06:56:41 +08:00
|
|
|
|
base.Awake();
|
2018-09-15 06:52:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-18 06:56:41 +08:00
|
|
|
|
protected override void Update()
|
2018-09-15 06:52:42 +08:00
|
|
|
|
{
|
2018-09-18 06:56:41 +08:00
|
|
|
|
base.Update();
|
2018-09-15 06:52:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-12 08:10:25 +08:00
|
|
|
|
protected override void DrawChart(VertexHelper vh)
|
2018-09-15 06:52:42 +08:00
|
|
|
|
{
|
2019-03-12 08:10:25 +08:00
|
|
|
|
base.DrawChart(vh);
|
2019-03-16 07:49:36 +08:00
|
|
|
|
if (yAxis.type == AxisType.category)
|
2018-09-15 06:52:42 +08:00
|
|
|
|
{
|
2018-09-19 07:51:33 +08:00
|
|
|
|
int seriesCount = seriesList.Count;
|
2019-03-31 09:11:35 +08:00
|
|
|
|
float scaleWid = yAxis.GetSplitWidth(coordinateHig);
|
2018-09-23 08:18:26 +08:00
|
|
|
|
float barWid = barInfo.barWid > 1 ? barInfo.barWid : scaleWid * barInfo.barWid;
|
|
|
|
|
|
float offset = (scaleWid - barWid * seriesCount - barInfo.space * (seriesCount - 1)) / 2;
|
2018-09-19 07:12:27 +08:00
|
|
|
|
float max = GetMaxValue();
|
2019-03-12 08:10:25 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
2018-09-19 07:12:27 +08:00
|
|
|
|
for (int j = 0; j < seriesCount; j++)
|
2018-09-18 06:56:41 +08:00
|
|
|
|
{
|
2018-09-19 07:12:27 +08:00
|
|
|
|
if (!legend.IsShowSeries(j)) continue;
|
|
|
|
|
|
Series series = seriesList[j];
|
2018-10-01 17:00:15 +08:00
|
|
|
|
Color color = themeInfo.GetColor(j);
|
2018-09-21 22:43:21 +08:00
|
|
|
|
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++)
|
2018-09-19 07:12:27 +08:00
|
|
|
|
{
|
2019-03-16 07:24:21 +08:00
|
|
|
|
float data = series.dataList[i];
|
2018-09-19 07:12:27 +08:00
|
|
|
|
float pX = zeroX + coordinate.tickness;
|
2019-03-31 09:11:35 +08:00
|
|
|
|
float pY = zeroY + i * scaleWid;
|
2018-09-20 09:09:12 +08:00
|
|
|
|
if (!yAxis.boundaryGap) pY -= scaleWid / 2;
|
2019-03-16 07:24:21 +08:00
|
|
|
|
float barHig = data / max * coordinateWid;
|
2018-09-23 08:18:26 +08:00
|
|
|
|
float space = offset + j * (barWid + barInfo.space);
|
2018-09-19 07:12:27 +08:00
|
|
|
|
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
|
|
|
|
|
|
{
|
2018-09-19 07:51:33 +08:00
|
|
|
|
int seriesCount = seriesList.Count;
|
2019-03-31 09:11:35 +08:00
|
|
|
|
float scaleWid = xAxis.GetDataWidth(coordinateWid);
|
2018-09-23 08:18:26 +08:00
|
|
|
|
float barWid = barInfo.barWid > 1 ? barInfo.barWid : scaleWid * barInfo.barWid;
|
|
|
|
|
|
float offset = (scaleWid - barWid * seriesCount - barInfo.space * (seriesCount - 1)) / 2;
|
2018-09-19 07:12:27 +08:00
|
|
|
|
float max = GetMaxValue();
|
2019-03-12 08:10:25 +08:00
|
|
|
|
if (tooltip.show && tooltip.DataIndex > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
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 + scaleWid, pY);
|
|
|
|
|
|
Vector3 p4 = new Vector3(pX + scaleWid, zeroY);
|
|
|
|
|
|
ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, themeInfo.tooltipFlagAreaColor);
|
|
|
|
|
|
}
|
2018-09-19 07:12:27 +08:00
|
|
|
|
for (int j = 0; j < seriesCount; j++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!legend.IsShowSeries(j)) continue;
|
|
|
|
|
|
Series series = seriesList[j];
|
2018-10-01 17:00:15 +08:00
|
|
|
|
Color color = themeInfo.GetColor(j);
|
2018-09-21 22:43:21 +08:00
|
|
|
|
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++)
|
2018-09-19 07:12:27 +08:00
|
|
|
|
{
|
2019-03-16 07:24:21 +08:00
|
|
|
|
float data = series.dataList[i];
|
2019-03-31 09:11:35 +08:00
|
|
|
|
float pX = zeroX + i * scaleWid;
|
2018-09-20 09:09:12 +08:00
|
|
|
|
if (!xAxis.boundaryGap) pX -= scaleWid / 2;
|
2018-09-19 07:12:27 +08:00
|
|
|
|
float pY = zeroY + coordinate.tickness;
|
2019-03-16 07:24:21 +08:00
|
|
|
|
float barHig = data / max * coordinateHig;
|
2018-09-23 08:18:26 +08:00
|
|
|
|
float space = offset + j * (barWid + barInfo.space);
|
2018-09-19 07:12:27 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
2018-09-18 06:56:41 +08:00
|
|
|
|
}
|
2018-09-15 06:52:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|