2019-05-11 04:33:54 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
namespace XCharts
|
|
|
|
|
|
{
|
2019-07-15 00:24:04 +08:00
|
|
|
|
[AddComponentMenu("XCharts/BarChart", 14)]
|
2019-05-11 04:33:54 +08:00
|
|
|
|
[ExecuteInEditMode]
|
|
|
|
|
|
[RequireComponent(typeof(RectTransform))]
|
|
|
|
|
|
[DisallowMultipleComponent]
|
|
|
|
|
|
public class BarChart : CoordinateChart
|
|
|
|
|
|
{
|
2019-05-15 09:44:18 +08:00
|
|
|
|
|
2019-07-15 00:24:04 +08:00
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
protected override void Reset()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Reset();
|
2019-07-15 19:21:22 +08:00
|
|
|
|
m_Title.text = "BarChart";
|
2019-07-18 09:42:36 +08:00
|
|
|
|
m_Tooltip.type = Tooltip.Type.Shadow;
|
2019-07-15 00:24:04 +08:00
|
|
|
|
RemoveData();
|
2019-09-29 09:16:15 +08:00
|
|
|
|
AddSerie(SerieType.Bar, "serie1");
|
2019-07-15 00:24:04 +08:00
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
AddXAxisData("x" + (i + 1));
|
|
|
|
|
|
AddData(0, Random.Range(10, 90));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2019-09-28 16:35:55 +08:00
|
|
|
|
protected HashSet<string> m_SerieNameSet = new HashSet<string>();
|
|
|
|
|
|
protected Dictionary<int, List<Serie>> m_StackSeries = new Dictionary<int, List<Serie>>();
|
|
|
|
|
|
protected List<float> m_SeriesCurrHig = new List<float>();
|
2019-05-11 04:33:54 +08:00
|
|
|
|
protected override void DrawChart(VertexHelper vh)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.DrawChart(vh);
|
2019-09-30 19:05:09 +08:00
|
|
|
|
if (!m_CheckMinMaxValue) return;
|
2019-07-23 21:43:01 +08:00
|
|
|
|
bool yCategory = m_YAxises[0].IsCategory() || m_YAxises[1].IsCategory();
|
2019-08-15 21:44:30 +08:00
|
|
|
|
m_Series.GetStackSeries(ref m_StackSeries);
|
|
|
|
|
|
int seriesCount = m_StackSeries.Count;
|
2019-07-23 21:43:01 +08:00
|
|
|
|
int serieNameCount = -1;
|
2019-08-15 21:44:30 +08:00
|
|
|
|
m_SerieNameSet.Clear();
|
|
|
|
|
|
m_BarLastOffset = 0;
|
2019-07-23 21:43:01 +08:00
|
|
|
|
for (int j = 0; j < seriesCount; j++)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-08-15 21:44:30 +08:00
|
|
|
|
var serieList = m_StackSeries[j];
|
|
|
|
|
|
m_SeriesCurrHig.Clear();
|
2019-07-23 21:43:01 +08:00
|
|
|
|
for (int n = 0; n < serieList.Count; n++)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-07-23 21:43:01 +08:00
|
|
|
|
Serie serie = serieList[n];
|
2019-08-20 08:49:39 +08:00
|
|
|
|
serie.dataPoints.Clear();
|
2019-07-23 21:43:01 +08:00
|
|
|
|
if (string.IsNullOrEmpty(serie.name)) serieNameCount++;
|
2019-08-15 21:44:30 +08:00
|
|
|
|
else if (!m_SerieNameSet.Contains(serie.name))
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-08-15 21:44:30 +08:00
|
|
|
|
m_SerieNameSet.Add(serie.name);
|
2019-07-23 21:43:01 +08:00
|
|
|
|
serieNameCount++;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
2019-09-28 16:35:55 +08:00
|
|
|
|
switch (serie.type)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SerieType.Line:
|
|
|
|
|
|
if (yCategory) DrawYLineSerie(vh, j, serie, ref m_SeriesCurrHig);
|
|
|
|
|
|
else DrawXLineSerie(vh, j, serie, ref m_SeriesCurrHig);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case SerieType.Bar:
|
|
|
|
|
|
if (yCategory) DrawYBarSerie(vh, j, seriesCount, serie, serieNameCount, ref m_SeriesCurrHig);
|
|
|
|
|
|
else DrawXBarSerie(vh, j, seriesCount, serie, serieNameCount, ref m_SeriesCurrHig);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-09-06 09:11:46 +08:00
|
|
|
|
DrawLabelBackground(vh);
|
2019-09-28 16:35:55 +08:00
|
|
|
|
DrawLinePoint(vh);
|
|
|
|
|
|
DrawLineArrow(vh);
|
2019-07-23 21:43:01 +08:00
|
|
|
|
if (yCategory) DrawYTooltipIndicator(vh);
|
|
|
|
|
|
else DrawXTooltipIndicator(vh);
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
2019-08-20 08:49:39 +08:00
|
|
|
|
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|