mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 06:20:15 +00:00
增加二维数据支持,XY轴都可以设置为数值轴
This commit is contained in:
@@ -26,6 +26,90 @@ namespace XCharts
|
||||
|
||||
public Bar bar { get { return m_Bar; } }
|
||||
|
||||
private void DrawYBarSerie(VertexHelper vh, int serieIndex, int stackCount,
|
||||
Serie serie, Color color, ref Dictionary<int, float> seriesHig)
|
||||
{
|
||||
if (!m_Legend.IsActive(serie.name)) return;
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
|
||||
float barWid = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
|
||||
float offset = m_Bar.inSameBar ?
|
||||
(scaleWid - barWid - m_Bar.space * (stackCount - 1)) / 2 :
|
||||
(scaleWid - barWid * stackCount - m_Bar.space * (stackCount - 1)) / 2;
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.yData.Count ? serie.yData.Count : maxShowDataNumber)
|
||||
: serie.yData.Count;
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
{
|
||||
if (!seriesHig.ContainsKey(i))
|
||||
{
|
||||
seriesHig[i] = 0;
|
||||
}
|
||||
float value = serie.yData[i];
|
||||
float pX = seriesHig[i] + coordinateX + xAxis.zeroXOffset + m_Coordinate.tickness;
|
||||
float pY = coordinateY + +i * scaleWid;
|
||||
if (!yAxis.boundaryGap) pY -= scaleWid / 2;
|
||||
float barHig = (xAxis.minValue > 0 ? value - xAxis.minValue : value)
|
||||
/ (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
||||
float space = m_Bar.inSameBar ? offset :
|
||||
offset + serieIndex * (barWid + m_Bar.space);
|
||||
seriesHig[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawXBarSerie(VertexHelper vh, int serieIndex, int stackCount,
|
||||
Serie serie, Color color, ref Dictionary<int, float> seriesHig)
|
||||
{
|
||||
if (!m_Legend.IsActive(serie.name)) return;
|
||||
List<float> showData = serie.GetYData(m_DataZoom);
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
float scaleWid = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
|
||||
float barWid = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
|
||||
float offset = m_Bar.inSameBar ?
|
||||
(scaleWid - barWid - m_Bar.space * (stackCount - 1)) / 2 :
|
||||
(scaleWid - barWid * stackCount - m_Bar.space * (stackCount - 1)) / 2;
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
|
||||
: showData.Count;
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
{
|
||||
if (!seriesHig.ContainsKey(i))
|
||||
{
|
||||
seriesHig[i] = 0;
|
||||
}
|
||||
float value = showData[i];
|
||||
float pX = zeroX + i * scaleWid;
|
||||
float zeroY = coordinateY + yAxis.zeroYOffset;
|
||||
if (!xAxis.boundaryGap) pX -= scaleWid / 2;
|
||||
float pY = seriesHig[i] + zeroY + m_Coordinate.tickness;
|
||||
float barHig = (yAxis.minValue > 0 ? value - yAxis.minValue : value)
|
||||
/ (yAxis.maxValue - yAxis.minValue) * coordinateHig;
|
||||
seriesHig[i] += barHig;
|
||||
float space = m_Bar.inSameBar ? offset :
|
||||
offset + serieIndex * (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
@@ -36,48 +120,13 @@ namespace XCharts
|
||||
int serieCount = 0;
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
var seriesCurrHig = new Dictionary<int, float>();
|
||||
var seriesHig = new Dictionary<int, float>();
|
||||
var serieList = stackSeries[j];
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
Serie serie = serieList[n];
|
||||
if (!m_Legend.IsActive(serie.name)) continue;
|
||||
Color color = m_ThemeInfo.GetColor(serieCount);
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
|
||||
float barWid = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
|
||||
float offset = m_Bar.inSameBar ?
|
||||
(scaleWid - barWid - m_Bar.space * (seriesCount - 1)) / 2 :
|
||||
(scaleWid - barWid * seriesCount - m_Bar.space * (seriesCount - 1)) / 2;
|
||||
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 value = serie.data[i];
|
||||
float pX = seriesCurrHig[i] + coordinateX + xAxis.zeroXOffset + m_Coordinate.tickness;
|
||||
float pY = coordinateY + +i * scaleWid;
|
||||
if (!yAxis.boundaryGap) pY -= scaleWid / 2;
|
||||
float barHig = (xAxis.minValue > 0 ? value - xAxis.minValue : value)
|
||||
/ (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
||||
float space = m_Bar.inSameBar ? offset :
|
||||
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);
|
||||
}
|
||||
}
|
||||
DrawYBarSerie(vh, j, seriesCount, serie, color, ref seriesHig);
|
||||
if (serie.show)
|
||||
{
|
||||
serieCount++;
|
||||
@@ -130,50 +179,13 @@ namespace XCharts
|
||||
int serieCount = 0;
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
var seriesCurrHig = new Dictionary<int, float>();
|
||||
var seriesHig = new Dictionary<int, float>();
|
||||
var serieList = stackSeries[j];
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
Serie serie = serieList[n];
|
||||
if (!m_Legend.IsActive(serie.name)) continue;
|
||||
Color color = m_ThemeInfo.GetColor(serieCount);
|
||||
List<float> showData = serie.GetData(m_DataZoom);
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
float scaleWid = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
|
||||
float barWid = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
|
||||
float offset = m_Bar.inSameBar ?
|
||||
(scaleWid - barWid - m_Bar.space * (seriesCount - 1)) / 2 :
|
||||
(scaleWid - barWid * seriesCount - m_Bar.space * (seriesCount - 1)) / 2;
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
|
||||
: showData.Count;
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
{
|
||||
if (!seriesCurrHig.ContainsKey(i))
|
||||
{
|
||||
seriesCurrHig[i] = 0;
|
||||
}
|
||||
float value = showData[i];
|
||||
float pX = zeroX + i * scaleWid;
|
||||
float zeroY = coordinateY + yAxis.zeroYOffset;
|
||||
if (!xAxis.boundaryGap) pX -= scaleWid / 2;
|
||||
float pY = seriesCurrHig[i] + zeroY + m_Coordinate.tickness;
|
||||
float barHig = (yAxis.minValue > 0 ? value - yAxis.minValue : value)
|
||||
/ (yAxis.maxValue - yAxis.minValue) * coordinateHig;
|
||||
seriesCurrHig[i] += barHig;
|
||||
float space = m_Bar.inSameBar ? offset :
|
||||
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);
|
||||
}
|
||||
}
|
||||
DrawXBarSerie(vh, j, seriesCount, serie, color, ref seriesHig);
|
||||
if (serie.show)
|
||||
{
|
||||
serieCount++;
|
||||
|
||||
@@ -303,16 +303,14 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void AdjustMinMaxValue(int minValue, int maxValue, out int tempMinValue, out int tempMaxValue)
|
||||
public void AdjustMinMaxValue(ref int minValue, ref int maxValue)
|
||||
{
|
||||
tempMinValue = minValue;
|
||||
tempMaxValue = maxValue;
|
||||
if (minMaxType == Axis.AxisMinMaxType.Custom)
|
||||
{
|
||||
if (min != 0 || max != 0)
|
||||
{
|
||||
tempMinValue = min;
|
||||
tempMaxValue = max;
|
||||
minValue = min;
|
||||
maxValue = max;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -322,23 +320,23 @@ namespace XCharts
|
||||
case Axis.AxisMinMaxType.Default:
|
||||
if (minValue > 0 && maxValue > 0)
|
||||
{
|
||||
tempMinValue = 0;
|
||||
tempMaxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
|
||||
minValue = 0;
|
||||
maxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
|
||||
}
|
||||
else if (minValue < 0 && maxValue < 0)
|
||||
{
|
||||
tempMinValue = ChartHelper.GetMinDivisibleValue(minValue);
|
||||
tempMaxValue = 0;
|
||||
minValue = ChartHelper.GetMinDivisibleValue(minValue);
|
||||
maxValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
tempMinValue = ChartHelper.GetMinDivisibleValue(minValue);
|
||||
tempMaxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
|
||||
minValue = ChartHelper.GetMinDivisibleValue(minValue);
|
||||
maxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
|
||||
}
|
||||
break;
|
||||
case Axis.AxisMinMaxType.MinMax:
|
||||
tempMinValue = ChartHelper.GetMinDivisibleValue(minValue);
|
||||
tempMaxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
|
||||
minValue = ChartHelper.GetMinDivisibleValue(minValue);
|
||||
maxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace XCharts
|
||||
public class AxisLine
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private bool m_OnZero;
|
||||
[SerializeField] private bool m_Symbol;
|
||||
[SerializeField] private float m_SymbolWidth;
|
||||
[SerializeField] private float m_SymbolHeight;
|
||||
@@ -13,6 +14,7 @@ namespace XCharts
|
||||
[SerializeField] private float m_SymbolDent;
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
public bool onZero { get { return m_OnZero; } set { m_OnZero = value; } }
|
||||
public bool symbol { get { return m_Symbol; } set { m_Symbol = value; } }
|
||||
public float symbolWidth { get { return m_SymbolWidth; } set { m_SymbolWidth = value; } }
|
||||
public float symbolHeight { get { return m_SymbolHeight; } set { m_SymbolHeight = value; } }
|
||||
@@ -26,6 +28,7 @@ namespace XCharts
|
||||
var axisLine = new AxisLine
|
||||
{
|
||||
m_Show = true,
|
||||
m_OnZero = true,
|
||||
m_Symbol = false,
|
||||
m_SymbolWidth = 10,
|
||||
m_SymbolHeight = 15,
|
||||
|
||||
@@ -13,9 +13,7 @@ namespace XCharts
|
||||
private static readonly string s_DefaultDataZoom = "datazoom";
|
||||
|
||||
[SerializeField] protected Coordinate m_Coordinate = Coordinate.defaultCoordinate;
|
||||
[SerializeField] protected XAxis m_XAxis = XAxis.defaultXAxis;
|
||||
[SerializeField] protected List<XAxis> m_XAxises = new List<XAxis>();
|
||||
[SerializeField] protected YAxis m_YAxis = YAxis.defaultYAxis;
|
||||
[SerializeField] protected List<YAxis> m_YAxises = new List<YAxis>();
|
||||
[SerializeField] protected DataZoom m_DataZoom = DataZoom.defaultDataZoom;
|
||||
|
||||
@@ -188,7 +186,7 @@ namespace XCharts
|
||||
string strColor = ColorUtility.ToHtmlStringRGBA(m_ThemeInfo.GetColor(i));
|
||||
string key = m_Series.series[i].name;
|
||||
if (string.IsNullOrEmpty(key)) key = m_Legend.GetData(i);
|
||||
float value = m_Series.series[i].GetData(index, m_DataZoom);
|
||||
float value = m_Series.series[i].GetYData(index, m_DataZoom);
|
||||
sb.Append("\n");
|
||||
sb.AppendFormat("<color=#{0}>● </color>", strColor);
|
||||
sb.AppendFormat("{0}: {1}", key, value);
|
||||
@@ -272,7 +270,8 @@ namespace XCharts
|
||||
InitAxisY();
|
||||
}
|
||||
|
||||
public void ClearAxisData(){
|
||||
public void ClearAxisData()
|
||||
{
|
||||
foreach (var item in m_XAxises) item.data.Clear();
|
||||
foreach (var item in m_YAxises) item.data.Clear();
|
||||
}
|
||||
@@ -293,7 +292,7 @@ namespace XCharts
|
||||
if (m_XAxises.Count <= 0)
|
||||
{
|
||||
var axis1 = new XAxis();
|
||||
axis1.Copy(m_XAxis);
|
||||
axis1.Copy(axis1);
|
||||
var axis2 = XAxis.defaultXAxis;
|
||||
axis2.show = false;
|
||||
m_XAxises.Add(axis1);
|
||||
@@ -302,7 +301,7 @@ namespace XCharts
|
||||
if (m_YAxises.Count <= 0)
|
||||
{
|
||||
var axis1 = new YAxis();
|
||||
axis1.Copy(m_YAxis);
|
||||
axis1.Copy(axis1);
|
||||
var axis2 = YAxis.defaultYAxis;
|
||||
axis2.show = false;
|
||||
m_YAxises.Add(axis1);
|
||||
@@ -611,8 +610,22 @@ namespace XCharts
|
||||
|
||||
int tempMinValue = 0;
|
||||
int tempMaxValue = 100;
|
||||
m_Series.GetMinMaxValue(m_DataZoom, axisIndex, out tempMinValue, out tempMaxValue);
|
||||
axis.AdjustMinMaxValue(tempMinValue, tempMaxValue, out tempMinValue, out tempMaxValue);
|
||||
if (m_XAxises[axisIndex].IsValue() && m_YAxises[axisIndex].IsValue())
|
||||
{
|
||||
if (axis is XAxis)
|
||||
{
|
||||
m_Series.GetXMinMaxValue(m_DataZoom, axisIndex, out tempMinValue, out tempMaxValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Series.GetYMinMaxValue(m_DataZoom, axisIndex, out tempMinValue, out tempMaxValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Series.GetYMinMaxValue(m_DataZoom, axisIndex, out tempMinValue, out tempMaxValue);
|
||||
}
|
||||
axis.AdjustMinMaxValue(ref tempMinValue, ref tempMaxValue);
|
||||
if (tempMinValue != axis.minValue || tempMaxValue != axis.maxValue)
|
||||
{
|
||||
axis.minValue = tempMinValue;
|
||||
@@ -625,7 +638,7 @@ namespace XCharts
|
||||
axis.maxValue < 0 ? coordinateWid :
|
||||
Mathf.Abs(axis.minValue) * (coordinateWid / (Mathf.Abs(axis.minValue) + Mathf.Abs(axis.maxValue)));
|
||||
}
|
||||
else if (axis is YAxis && axis.IsValue())
|
||||
if (axis is YAxis && axis.IsValue())
|
||||
{
|
||||
axis.zeroYOffset = axis.minValue > 0 ? 0 :
|
||||
axis.maxValue < 0 ? coordinateHig :
|
||||
@@ -777,7 +790,7 @@ namespace XCharts
|
||||
{
|
||||
if (xAxis.show && xAxis.axisLine.show)
|
||||
{
|
||||
var lineY = coordinateY + m_YAxises[xAxisIndex].zeroYOffset;
|
||||
var lineY = coordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].zeroYOffset : 0);
|
||||
if (xAxis.IsValue() && xAxisIndex > 0) lineY += coordinateHig;
|
||||
var top = new Vector3(coordinateX + coordinateWid + m_Coordinate.tickness, lineY);
|
||||
ChartHelper.DrawLine(vh, new Vector3(coordinateX - m_Coordinate.tickness, lineY),
|
||||
@@ -799,7 +812,7 @@ namespace XCharts
|
||||
{
|
||||
if (yAxis.show && yAxis.axisLine.show)
|
||||
{
|
||||
var lineX = coordinateX + m_XAxises[yAxisIndex].zeroXOffset;
|
||||
var lineX = coordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].zeroXOffset : 0);
|
||||
if (yAxis.IsValue() && yAxisIndex > 0) lineX += coordinateWid;
|
||||
var top = new Vector3(lineX, coordinateY + coordinateHig + m_Coordinate.tickness);
|
||||
ChartHelper.DrawLine(vh, new Vector3(lineX, coordinateY - m_Coordinate.tickness),
|
||||
@@ -832,17 +845,17 @@ namespace XCharts
|
||||
{
|
||||
Serie serie = m_Series.series[0];
|
||||
Axis axis = yAxises[0];
|
||||
float scaleWid = coordinateWid / (serie.data.Count - 1);
|
||||
float scaleWid = coordinateWid / (serie.yData.Count - 1);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
int minValue = 0;
|
||||
int maxValue = 100;
|
||||
m_Series.GetMinMaxValue(null, 0, out minValue, out maxValue);
|
||||
axis.AdjustMinMaxValue(minValue, maxValue, out minValue, out maxValue);
|
||||
m_Series.GetYMinMaxValue(null, 0, out minValue, out maxValue);
|
||||
axis.AdjustMinMaxValue(ref minValue, ref maxValue);
|
||||
if (minValue > 0 && maxValue > 0) minValue = 0;
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
for (int i = 0; i < serie.yData.Count; i++)
|
||||
{
|
||||
float value = serie.data[i];
|
||||
float value = serie.yData[i];
|
||||
float pX = coordinateX + i * scaleWid;
|
||||
float dataHig = value / (maxValue - minValue) * m_DataZoom.height;
|
||||
np = new Vector3(pX, m_DataZoom.bottom + dataHig);
|
||||
|
||||
@@ -1,43 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public enum SerieType
|
||||
{
|
||||
Line,
|
||||
Bar,
|
||||
Pie,
|
||||
Radar
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Serie : JsonDataSupport
|
||||
{
|
||||
public enum SerieType
|
||||
{
|
||||
Line,
|
||||
Bar
|
||||
}
|
||||
|
||||
[SerializeField][DefaultValue("true")] private bool m_Show;
|
||||
[SerializeField] [DefaultValue("true")] private bool m_Show;
|
||||
[SerializeField] private SerieType m_Type;
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private string m_Stack;
|
||||
[SerializeField] private int m_AxisIndex;
|
||||
[SerializeField] private List<float> m_Data = new List<float>();
|
||||
[SerializeField] private bool m_Flodout;
|
||||
[SerializeField] private bool m_TwoDimensionData;
|
||||
[FormerlySerializedAs("m_Data")]
|
||||
[SerializeField] private List<float> m_YData = new List<float>();
|
||||
[SerializeField] private List<float> m_XData = new List<float>();
|
||||
|
||||
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 int axisIndex { get { return m_AxisIndex; } set { m_AxisIndex = value; } }
|
||||
public List<float> data { get { return m_Data; } set { m_Data = value; } }
|
||||
public List<float> yData { get { return m_YData; } set { m_YData = value; } }
|
||||
public List<float> xData { get { return m_XData; } set { m_XData = value; } }
|
||||
|
||||
public int filterStart { get; set; }
|
||||
public int filterEnd { get; set; }
|
||||
public List<float> filterData { get; set; }
|
||||
|
||||
public float Max
|
||||
private List<float> yFilterData { get; set; }
|
||||
private List<float> xFilterData { get; set; }
|
||||
|
||||
public float yMax
|
||||
{
|
||||
get
|
||||
{
|
||||
float max = int.MinValue;
|
||||
foreach (var data in data)
|
||||
foreach (var data in yData)
|
||||
{
|
||||
if (data > max)
|
||||
{
|
||||
@@ -48,12 +56,28 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public float Min
|
||||
public float xMax
|
||||
{
|
||||
get
|
||||
{
|
||||
float max = int.MinValue;
|
||||
foreach (var data in xData)
|
||||
{
|
||||
if (data > max)
|
||||
{
|
||||
max = data;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
public float yMin
|
||||
{
|
||||
get
|
||||
{
|
||||
float min = int.MaxValue;
|
||||
foreach (var data in data)
|
||||
foreach (var data in yData)
|
||||
{
|
||||
if (data < min)
|
||||
{
|
||||
@@ -64,12 +88,41 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public float Total
|
||||
public float xMin
|
||||
{
|
||||
get
|
||||
{
|
||||
float min = int.MaxValue;
|
||||
foreach (var data in xData)
|
||||
{
|
||||
if (data < min)
|
||||
{
|
||||
min = data;
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
}
|
||||
|
||||
public float yTotal
|
||||
{
|
||||
get
|
||||
{
|
||||
float total = 0;
|
||||
foreach (var data in data)
|
||||
foreach (var data in yData)
|
||||
{
|
||||
total += data;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
public float xTotal
|
||||
{
|
||||
get
|
||||
{
|
||||
float total = 0;
|
||||
foreach (var data in xData)
|
||||
{
|
||||
total += data;
|
||||
}
|
||||
@@ -79,26 +132,30 @@ namespace XCharts
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
m_Data.Clear();
|
||||
m_XData.Clear();
|
||||
m_YData.Clear();
|
||||
}
|
||||
|
||||
public void RemoveData(int index)
|
||||
{
|
||||
m_Data.RemoveAt(index);
|
||||
m_XData.RemoveAt(index);
|
||||
m_YData.RemoveAt(index);
|
||||
}
|
||||
|
||||
public void AddData(float value, int maxDataNumber = 0)
|
||||
public void AddYData(float value, int maxDataNumber = 0)
|
||||
{
|
||||
if (maxDataNumber > 0)
|
||||
{
|
||||
while (m_Data.Count > maxDataNumber) m_Data.RemoveAt(0);
|
||||
while (m_XData.Count > maxDataNumber) m_XData.RemoveAt(0);
|
||||
while (m_YData.Count > maxDataNumber) m_YData.RemoveAt(0);
|
||||
}
|
||||
m_Data.Add(value);
|
||||
m_YData.Add(value);
|
||||
m_XData.Add(m_XData.Count);
|
||||
}
|
||||
|
||||
public float GetData(int index, DataZoom dataZoom = null)
|
||||
public float GetYData(int index, DataZoom dataZoom = null)
|
||||
{
|
||||
var showData = GetData(dataZoom);
|
||||
var showData = GetYData(dataZoom);
|
||||
if (index >= 0 && index <= showData.Count - 1)
|
||||
{
|
||||
return showData[index];
|
||||
@@ -106,22 +163,41 @@ namespace XCharts
|
||||
return 0;
|
||||
}
|
||||
|
||||
public List<float> GetData(DataZoom dataZoom)
|
||||
public List<float> GetYData(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||
var startIndex = (int)((yData.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((yData.Count - 1) * dataZoom.end / 100);
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (filterData == null || filterData.Count != count)
|
||||
if (yFilterData == null || yFilterData.Count != count)
|
||||
{
|
||||
UpdateFilterData(dataZoom);
|
||||
}
|
||||
return filterData;
|
||||
return yFilterData;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_Data;
|
||||
return m_YData;
|
||||
}
|
||||
}
|
||||
|
||||
public List<float> GetXData(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
var startIndex = (int)((xData.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((xData.Count - 1) * dataZoom.end / 100);
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (xFilterData == null || xFilterData.Count != count)
|
||||
{
|
||||
UpdateFilterData(dataZoom);
|
||||
}
|
||||
return xFilterData;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_XData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,41 +205,51 @@ namespace XCharts
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||
var startIndex = (int)((yData.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((yData.Count - 1) * dataZoom.end / 100);
|
||||
if (startIndex != filterStart || endIndex != filterEnd)
|
||||
{
|
||||
filterStart = startIndex;
|
||||
filterEnd = endIndex;
|
||||
if (m_Data.Count > 0)
|
||||
if (m_YData.Count > 0)
|
||||
{
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
filterData = m_Data.GetRange(startIndex, count);
|
||||
yFilterData = m_YData.GetRange(startIndex, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
filterData = m_Data;
|
||||
yFilterData = m_YData;
|
||||
}
|
||||
if (m_XData.Count > 0)
|
||||
{
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
xFilterData = m_XData.GetRange(startIndex, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
xFilterData = m_XData;
|
||||
}
|
||||
}
|
||||
else if (endIndex == 0)
|
||||
{
|
||||
filterData = new List<float>();
|
||||
yFilterData = new List<float>();
|
||||
xFilterData = new List<float>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateData(int index, float value)
|
||||
public void UpdateYData(int index, float value)
|
||||
{
|
||||
if (index >= 0 && index <= m_Data.Count - 1)
|
||||
if (index >= 0 && index <= m_YData.Count - 1)
|
||||
{
|
||||
m_Data[index] = value;
|
||||
m_YData[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ParseJsonData(string jsonData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
||||
m_Data = ChartHelper.ParseFloatFromString(jsonData);
|
||||
m_YData = ChartHelper.ParseFloatFromString(jsonData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace XCharts
|
||||
{
|
||||
if (serieIndex >= 0 && serieIndex < Count)
|
||||
{
|
||||
return m_Series[serieIndex].GetData(dataIndex);
|
||||
return m_Series[serieIndex].GetYData(dataIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -99,10 +99,10 @@ namespace XCharts
|
||||
{
|
||||
serie = new Serie();
|
||||
serie.name = name;
|
||||
serie.data = new List<float>();
|
||||
serie.yData = new List<float>();
|
||||
m_Series.Add(serie);
|
||||
}
|
||||
serie.AddData(value, maxDataNumber);
|
||||
serie.AddYData(value, maxDataNumber);
|
||||
return serie;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace XCharts
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddData(value, maxDataNumber);
|
||||
serie.AddYData(value, maxDataNumber);
|
||||
}
|
||||
return serie;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace XCharts
|
||||
var serie = GetSerie(name);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.UpdateData(dataIndex, value);
|
||||
serie.UpdateYData(dataIndex, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace XCharts
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.UpdateData(dataIndex, value);
|
||||
serie.UpdateYData(dataIndex, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +184,17 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
|
||||
public void GetMinMaxValue(DataZoom dataZoom, int axisIndex, out int minVaule, out int maxValue)
|
||||
public void GetXMinMaxValue(DataZoom dataZoom, int axisIndex, out int minVaule, out int maxValue)
|
||||
{
|
||||
GetMinMaxValue(dataZoom,axisIndex,false,out minVaule,out maxValue);
|
||||
}
|
||||
|
||||
public void GetYMinMaxValue(DataZoom dataZoom, int axisIndex, out int minVaule, out int maxValue)
|
||||
{
|
||||
GetMinMaxValue(dataZoom,axisIndex,true,out minVaule,out maxValue);
|
||||
}
|
||||
|
||||
public void GetMinMaxValue(DataZoom dataZoom, int axisIndex, bool yValue, out int minVaule, out int maxValue)
|
||||
{
|
||||
float min = int.MaxValue;
|
||||
float max = int.MinValue;
|
||||
@@ -198,7 +208,7 @@ namespace XCharts
|
||||
{
|
||||
var serie = ss.Value[i];
|
||||
if (serie.axisIndex != axisIndex) continue;
|
||||
var showData = serie.GetData(dataZoom);
|
||||
var showData = yValue ? serie.GetYData(dataZoom) : serie.GetXData(dataZoom);
|
||||
for (int j = 0; j < showData.Count; j++)
|
||||
{
|
||||
if (!seriesTotalValue.ContainsKey(j))
|
||||
@@ -224,7 +234,7 @@ namespace XCharts
|
||||
if (m_Series[i].axisIndex != axisIndex) continue;
|
||||
if (IsActive(i))
|
||||
{
|
||||
var showData = m_Series[i].GetData(dataZoom);
|
||||
var showData = yValue ? m_Series[i].GetYData(dataZoom) : m_Series[i].GetXData(dataZoom);
|
||||
foreach (var data in showData)
|
||||
{
|
||||
if (data > max) max = data;
|
||||
@@ -251,7 +261,7 @@ namespace XCharts
|
||||
float min = int.MaxValue;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var showData = m_Series[i].data;
|
||||
var showData = m_Series[i].yData;
|
||||
if (showData[index] > max)
|
||||
{
|
||||
max = Mathf.Ceil(showData[index]);
|
||||
@@ -272,7 +282,7 @@ namespace XCharts
|
||||
float min = int.MaxValue;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var showData = m_Series[i].data;
|
||||
var showData = m_Series[i].yData;
|
||||
if (showData[index] > max)
|
||||
{
|
||||
max = Mathf.Ceil(showData[index]);
|
||||
|
||||
@@ -21,17 +21,18 @@ namespace XCharts
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
|
||||
if (m_XAxises[0].type == Axis.AxisType.Category)
|
||||
{
|
||||
DrawXCategory(vh);
|
||||
}
|
||||
else
|
||||
if (m_YAxises[0].type == Axis.AxisType.Category
|
||||
|| m_YAxises[1].type == Axis.AxisType.Category)
|
||||
{
|
||||
DrawYCategory(vh);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawXCategory(vh);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void DrawXCategory(VertexHelper vh)
|
||||
{
|
||||
var stackSeries = m_Series.GetStackSeries();
|
||||
@@ -39,7 +40,6 @@ namespace XCharts
|
||||
|
||||
int serieCount = 0;
|
||||
List<Vector3> points = new List<Vector3>();
|
||||
List<Vector3> smoothPoints = new List<Vector3>();
|
||||
List<Color> colorList = new List<Color>();
|
||||
int dataCount = 0;
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
@@ -50,181 +50,7 @@ namespace XCharts
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
Serie serie = serieList[n];
|
||||
if (!IsActive(serie.name)) continue;
|
||||
List<Vector3> lastPoints = new List<Vector3>();
|
||||
List<Vector3> lastSmoothPoints = new List<Vector3>();
|
||||
List<float> serieData = serie.GetData(m_DataZoom);
|
||||
|
||||
Color color = m_ThemeInfo.GetColor(serieCount);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
float scaleWid = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
|
||||
float startX = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serieData.Count ? serieData.Count : maxShowDataNumber)
|
||||
: serieData.Count;
|
||||
dataCount = (maxCount - minShowDataNumber);
|
||||
if (m_Line.area && points.Count > 0)
|
||||
{
|
||||
if (!m_Line.smooth && points.Count > 0)
|
||||
{
|
||||
for (int m = points.Count - dataCount; m < points.Count; m++)
|
||||
{
|
||||
lastPoints.Add(points[m]);
|
||||
}
|
||||
}
|
||||
else if (m_Line.smooth && smoothPoints.Count > 0)
|
||||
{
|
||||
for (int m = 0; m < smoothPoints.Count; m++)
|
||||
{
|
||||
lastSmoothPoints.Add(smoothPoints[m]);
|
||||
}
|
||||
smoothPoints.Clear();
|
||||
}
|
||||
}
|
||||
int smoothPointCount = 1;
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
{
|
||||
if (!seriesCurrHig.ContainsKey(i))
|
||||
{
|
||||
seriesCurrHig[i] = 0;
|
||||
}
|
||||
float value = serieData[i];
|
||||
float pX = startX + i * scaleWid;
|
||||
float pY = seriesCurrHig[i] + coordinateY + m_Coordinate.tickness;
|
||||
float dataHig = (value - yAxis.minValue) / (yAxis.maxValue - yAxis.minValue) * coordinateHig;
|
||||
np = new Vector3(pX, pY + dataHig);
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
if (m_Line.step)
|
||||
{
|
||||
Vector2 middle1, middle2;
|
||||
switch (m_Line.stepTpe)
|
||||
{
|
||||
case Line.StepType.Start:
|
||||
middle1 = new Vector2(lp.x, np.y + m_Line.tickness);
|
||||
middle2 = new Vector2(lp.x - m_Line.tickness, np.y);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(middle1.x, zeroY), middle1, np,
|
||||
new Vector2(np.x, zeroY), areaColor);
|
||||
}
|
||||
break;
|
||||
case Line.StepType.Middle:
|
||||
middle1 = new Vector2((lp.x + np.x) / 2 + m_Line.tickness, lp.y);
|
||||
middle2 = new Vector2((lp.x + np.x) / 2 - m_Line.tickness, np.y);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, new Vector2(middle1.x - m_Line.tickness, middle1.y),
|
||||
new Vector2(middle2.x + m_Line.tickness, middle2.y), m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(lp.x, zeroY), lp, middle1,
|
||||
new Vector2(middle1.x, zeroY), areaColor);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(middle2.x + 2 * m_Line.tickness, zeroY),
|
||||
new Vector2(middle2.x + 2 * m_Line.tickness, middle2.y), np,
|
||||
new Vector2(np.x, zeroY), areaColor);
|
||||
}
|
||||
break;
|
||||
case Line.StepType.End:
|
||||
middle1 = new Vector2(np.x + m_Line.tickness, lp.y);
|
||||
middle2 = new Vector2(np.x, lp.y);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(lp.x, zeroY), lp,
|
||||
new Vector2(middle1.x - m_Line.tickness, middle1.y),
|
||||
new Vector2(middle1.x - m_Line.tickness, zeroY), areaColor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else 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++)
|
||||
{
|
||||
smoothPoints.Add(list[k]);
|
||||
to = list[k];
|
||||
ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color);
|
||||
|
||||
if (m_Line.area)
|
||||
{
|
||||
Vector3 alp = new Vector3(start.x, start.y - m_Line.tickness);
|
||||
Vector3 anp = new Vector3(to.x, to.y - m_Line.tickness);
|
||||
Vector3 tnp = serieCount > 0 ?
|
||||
(smoothPointCount > lastSmoothPoints.Count - 1 ?
|
||||
new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 1].x,
|
||||
lastSmoothPoints[lastSmoothPoints.Count - 1].y + m_Line.tickness) :
|
||||
new Vector3(lastSmoothPoints[smoothPointCount].x,
|
||||
lastSmoothPoints[smoothPointCount].y + m_Line.tickness)) :
|
||||
new Vector3(to.x, zeroY + m_Coordinate.tickness);
|
||||
Vector3 tlp = serieCount > 0 ?
|
||||
(smoothPointCount > lastSmoothPoints.Count - 1 ?
|
||||
new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 2].x,
|
||||
lastSmoothPoints[lastSmoothPoints.Count - 2].y + m_Line.tickness) :
|
||||
new Vector3(lastSmoothPoints[smoothPointCount - 1].x,
|
||||
lastSmoothPoints[smoothPointCount - 1].y + m_Line.tickness)) :
|
||||
new Vector3(start.x, zeroY + m_Coordinate.tickness);
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
smoothPointCount++;
|
||||
start = to;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Vector3 alp = new Vector3(lp.x, lp.y - m_Line.tickness);
|
||||
Vector3 anp = new Vector3(np.x, np.y - m_Line.tickness);
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
var cross = ChartHelper.GetIntersection(lp, np, new Vector3(zeroX, zeroY),
|
||||
new Vector3(zeroX + coordinateWid, zeroY));
|
||||
if (cross == Vector3.zero)
|
||||
{
|
||||
Vector3 tnp = serieCount > 0 ?
|
||||
new Vector3(lastPoints[i].x, lastPoints[i].y + m_Line.tickness) :
|
||||
new Vector3(np.x, zeroY + m_Coordinate.tickness);
|
||||
Vector3 tlp = serieCount > 0 ?
|
||||
new Vector3(lastPoints[i - 1].x, lastPoints[i - 1].y + m_Line.tickness) :
|
||||
new Vector3(lp.x, zeroY + m_Coordinate.tickness);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 cross1 = new Vector3(cross.x, cross.y + (alp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness));
|
||||
Vector3 cross2 = new Vector3(cross.x, cross.y + (anp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness));
|
||||
Vector3 xp1 = new Vector3(alp.x, zeroY + (alp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness));
|
||||
Vector3 xp2 = new Vector3(anp.x, zeroY + (anp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness));
|
||||
ChartHelper.DrawTriangle(vh, alp, cross1, xp1, areaColor);
|
||||
ChartHelper.DrawTriangle(vh, anp, cross2, xp2, areaColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Line.point)
|
||||
{
|
||||
points.Add(np);
|
||||
colorList.Add(color);
|
||||
}
|
||||
seriesCurrHig[i] += dataHig;
|
||||
lp = np;
|
||||
}
|
||||
DrawXLineSerie(vh, serieCount, serie, ref dataCount, ref points, ref colorList, ref seriesCurrHig);
|
||||
if (serie.show)
|
||||
{
|
||||
serieCount++;
|
||||
@@ -286,191 +112,17 @@ namespace XCharts
|
||||
int seriesCount = stackSeries.Count;
|
||||
int serieCount = 0;
|
||||
List<Vector3> points = new List<Vector3>();
|
||||
List<Vector3> smoothPoints = new List<Vector3>();
|
||||
List<Color> colorList = new List<Color>();
|
||||
List<Color> colors = new List<Color>();
|
||||
int dataCount = 0;
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
var seriesCurrHig = new Dictionary<int, float>();
|
||||
var seriesHig = new Dictionary<int, float>();
|
||||
var serieList = stackSeries[j];
|
||||
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
Serie serie = serieList[n];
|
||||
if (!IsActive(serie.name)) continue;
|
||||
List<Vector3> lastPoints = new List<Vector3>();
|
||||
List<Vector3> lastSmoothPoints = new List<Vector3>();
|
||||
|
||||
Color color = m_ThemeInfo.GetColor(serieCount);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
|
||||
float startY = zeroY + (yAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
|
||||
: serie.data.Count;
|
||||
dataCount = (maxCount - minShowDataNumber);
|
||||
if (m_Line.area && points.Count > 0)
|
||||
{
|
||||
if (!m_Line.smooth && points.Count > 0)
|
||||
{
|
||||
for (int m = points.Count - dataCount; m < points.Count; m++)
|
||||
{
|
||||
lastPoints.Add(points[m]);
|
||||
}
|
||||
}
|
||||
else if (m_Line.smooth && smoothPoints.Count > 0)
|
||||
{
|
||||
for (int m = 0; m < smoothPoints.Count; m++)
|
||||
{
|
||||
lastSmoothPoints.Add(smoothPoints[m]);
|
||||
}
|
||||
smoothPoints.Clear();
|
||||
}
|
||||
}
|
||||
int smoothPointCount = 1;
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
{
|
||||
if (!seriesCurrHig.ContainsKey(i))
|
||||
{
|
||||
seriesCurrHig[i] = 0;
|
||||
}
|
||||
float value = serie.data[i];
|
||||
float pY = startY + i * scaleWid;
|
||||
float pX = seriesCurrHig[i] + coordinateX + m_Coordinate.tickness;
|
||||
float dataHig = (value - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
||||
np = new Vector3(pX + dataHig, pY);
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
if (m_Line.step)
|
||||
{
|
||||
Vector2 middle1, middle2;
|
||||
switch (m_Line.stepTpe)
|
||||
{
|
||||
case Line.StepType.Start:
|
||||
middle1 = new Vector2(np.x, lp.y);
|
||||
middle2 = new Vector2(np.x, lp.y - m_Line.tickness);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(zeroX, middle1.y), middle1, np,
|
||||
new Vector2(zeroX, np.y), areaColor);
|
||||
}
|
||||
break;
|
||||
case Line.StepType.Middle:
|
||||
middle1 = new Vector2(lp.x, (lp.y + np.y) / 2 + m_Line.tickness);
|
||||
middle2 = new Vector2(np.x, (lp.y + np.y) / 2 - m_Line.tickness);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, new Vector2(middle1.x, middle1.y - m_Line.tickness),
|
||||
new Vector2(middle2.x, middle2.y + m_Line.tickness), m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(zeroX, lp.y), lp, middle1,
|
||||
new Vector2(zeroX, middle1.y), areaColor);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(zeroX, middle2.y + 2 * m_Line.tickness),
|
||||
new Vector2(middle2.x, middle2.y + 2 * m_Line.tickness), np,
|
||||
new Vector2(zeroX, np.y), areaColor);
|
||||
}
|
||||
break;
|
||||
case Line.StepType.End:
|
||||
middle1 = new Vector2(np.x, lp.y);
|
||||
middle2 = new Vector2(np.x, lp.y - m_Line.tickness);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(zeroX, lp.y), middle1,
|
||||
new Vector2(np.x, np.y),
|
||||
new Vector2(zeroX, np.y), areaColor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (m_Line.smooth)
|
||||
{
|
||||
var list = ChartHelper.GetBezierListVertical(lp, np, m_Line.smoothStyle);
|
||||
Vector3 start, to;
|
||||
start = list[0];
|
||||
for (int k = 1; k < list.Length; k++)
|
||||
{
|
||||
smoothPoints.Add(list[k]);
|
||||
to = list[k];
|
||||
ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color);
|
||||
|
||||
if (m_Line.area)
|
||||
{
|
||||
Vector3 alp = new Vector3(start.x, start.y - m_Line.tickness);
|
||||
Vector3 anp = new Vector3(to.x, to.y - m_Line.tickness);
|
||||
Vector3 tnp = serieCount > 0 ?
|
||||
(smoothPointCount > lastSmoothPoints.Count - 1 ?
|
||||
new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 1].x,
|
||||
lastSmoothPoints[lastSmoothPoints.Count - 1].y + m_Line.tickness) :
|
||||
new Vector3(lastSmoothPoints[smoothPointCount].x,
|
||||
lastSmoothPoints[smoothPointCount].y + m_Line.tickness)) :
|
||||
new Vector3(zeroX + m_Coordinate.tickness, to.y);
|
||||
Vector3 tlp = serieCount > 0 ?
|
||||
(smoothPointCount > lastSmoothPoints.Count - 1 ?
|
||||
new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 2].x,
|
||||
lastSmoothPoints[lastSmoothPoints.Count - 2].y + m_Line.tickness) :
|
||||
new Vector3(lastSmoothPoints[smoothPointCount - 1].x,
|
||||
lastSmoothPoints[smoothPointCount - 1].y + m_Line.tickness)) :
|
||||
new Vector3(zeroX + m_Coordinate.tickness, start.y);
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
smoothPointCount++;
|
||||
start = to;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Vector3 alp = new Vector3(lp.x, lp.y - m_Line.tickness);
|
||||
Vector3 anp = new Vector3(np.x, np.y - m_Line.tickness);
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
var cross = ChartHelper.GetIntersection(lp, np, new Vector3(zeroX, zeroY),
|
||||
new Vector3(zeroX, zeroY + coordinateHig));
|
||||
if (cross == Vector3.zero)
|
||||
{
|
||||
Vector3 tnp = serieCount > 0 ?
|
||||
new Vector3(lastPoints[i].x, lastPoints[i].y + m_Line.tickness) :
|
||||
new Vector3(zeroX + m_Coordinate.tickness, np.y);
|
||||
Vector3 tlp = serieCount > 0 ?
|
||||
new Vector3(lastPoints[i - 1].x, lastPoints[i - 1].y + m_Line.tickness) :
|
||||
new Vector3(zeroX + m_Coordinate.tickness, lp.y);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 cross1 = new Vector3(cross.x + (alp.x > zeroX ? m_Coordinate.tickness : -m_Coordinate.tickness), cross.y);
|
||||
Vector3 cross2 = new Vector3(cross.x + (anp.x > zeroX ? m_Coordinate.tickness : -m_Coordinate.tickness), cross.y);
|
||||
Vector3 xp1 = new Vector3(zeroX + (alp.x > zeroX ? m_Coordinate.tickness : -m_Coordinate.tickness), alp.y);
|
||||
Vector3 xp2 = new Vector3(zeroX + (anp.x > zeroX ? m_Coordinate.tickness : -m_Coordinate.tickness), anp.y);
|
||||
ChartHelper.DrawTriangle(vh, alp, cross1, xp1, areaColor);
|
||||
ChartHelper.DrawTriangle(vh, anp, cross2, xp2, areaColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Line.point)
|
||||
{
|
||||
points.Add(np);
|
||||
colorList.Add(color);
|
||||
}
|
||||
seriesCurrHig[i] += dataHig;
|
||||
lp = np;
|
||||
}
|
||||
DrawYLineSerie(vh, serieCount, serie, ref dataCount, ref points, ref colors, ref seriesHig);
|
||||
if (serie.show)
|
||||
{
|
||||
serieCount++;
|
||||
@@ -489,15 +141,12 @@ namespace XCharts
|
||||
}
|
||||
if (m_Theme == Theme.Dark)
|
||||
{
|
||||
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, colorList[i],
|
||||
(int)m_Line.pointWidth * 5);
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, colors[i], (int)m_Line.pointWidth * 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, Color.white);
|
||||
ChartHelper.DrawDoughnut(vh, p, pointWid - m_Line.tickness,
|
||||
pointWid, 0, 360, colorList[i]);
|
||||
ChartHelper.DrawDoughnut(vh, p, pointWid - m_Line.tickness, pointWid, 0, 360, colors[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -523,5 +172,382 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawXLineSerie(VertexHelper vh, int serieIndex, Serie serie, ref int dataCount,
|
||||
ref List<Vector3> points, ref List<Color> colors, ref Dictionary<int, float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.name)) return;
|
||||
List<Vector3> lastPoints = new List<Vector3>();
|
||||
List<Vector3> lastSmoothPoints = new List<Vector3>();
|
||||
List<Vector3> smoothPoints = new List<Vector3>();
|
||||
List<float> yData = serie.GetYData(m_DataZoom);
|
||||
List<float> xData = serie.GetXData(m_DataZoom);
|
||||
|
||||
Color color = m_ThemeInfo.GetColor(serieIndex);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
float scaleWid = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
|
||||
float startX = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > yData.Count ? yData.Count : maxShowDataNumber)
|
||||
: yData.Count;
|
||||
dataCount = (maxCount - minShowDataNumber);
|
||||
if (m_Line.area && points.Count > 0)
|
||||
{
|
||||
if (!m_Line.smooth && points.Count > 0)
|
||||
{
|
||||
for (int m = points.Count - dataCount; m < points.Count; m++)
|
||||
{
|
||||
lastPoints.Add(points[m]);
|
||||
}
|
||||
}
|
||||
else if (m_Line.smooth && smoothPoints.Count > 0)
|
||||
{
|
||||
for (int m = 0; m < smoothPoints.Count; m++)
|
||||
{
|
||||
lastSmoothPoints.Add(smoothPoints[m]);
|
||||
}
|
||||
smoothPoints.Clear();
|
||||
}
|
||||
}
|
||||
int smoothPointCount = 1;
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
{
|
||||
if (!seriesHig.ContainsKey(i))
|
||||
{
|
||||
seriesHig[i] = 0;
|
||||
}
|
||||
float yValue = yData[i];
|
||||
float yDataHig;
|
||||
if (xAxis.IsValue())
|
||||
{
|
||||
float xValue = i > xData.Count - 1 ? 0 : xData[i];
|
||||
float pX = coordinateX + m_Coordinate.tickness;
|
||||
float pY = seriesHig[i] + coordinateY + m_Coordinate.tickness;
|
||||
float xDataHig = (xValue - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
||||
yDataHig = (yValue - yAxis.minValue) / (yAxis.maxValue - yAxis.minValue) * coordinateHig;
|
||||
np = new Vector3(pX + xDataHig, pY + yDataHig);
|
||||
}
|
||||
else
|
||||
{
|
||||
float pX = startX + i * scaleWid;
|
||||
float pY = seriesHig[i] + coordinateY + m_Coordinate.tickness;
|
||||
yDataHig = (yValue - yAxis.minValue) / (yAxis.maxValue - yAxis.minValue) * coordinateHig;
|
||||
np = new Vector3(pX, pY + yDataHig);
|
||||
}
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
if (m_Line.step)
|
||||
{
|
||||
Vector2 middle1, middle2;
|
||||
switch (m_Line.stepTpe)
|
||||
{
|
||||
case Line.StepType.Start:
|
||||
middle1 = new Vector2(lp.x, np.y + m_Line.tickness);
|
||||
middle2 = new Vector2(lp.x - m_Line.tickness, np.y);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(middle1.x, zeroY), middle1, np,
|
||||
new Vector2(np.x, zeroY), areaColor);
|
||||
}
|
||||
break;
|
||||
case Line.StepType.Middle:
|
||||
middle1 = new Vector2((lp.x + np.x) / 2 + m_Line.tickness, lp.y);
|
||||
middle2 = new Vector2((lp.x + np.x) / 2 - m_Line.tickness, np.y);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, new Vector2(middle1.x - m_Line.tickness, middle1.y),
|
||||
new Vector2(middle2.x + m_Line.tickness, middle2.y), m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(lp.x, zeroY), lp, middle1,
|
||||
new Vector2(middle1.x, zeroY), areaColor);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(middle2.x + 2 * m_Line.tickness, zeroY),
|
||||
new Vector2(middle2.x + 2 * m_Line.tickness, middle2.y), np,
|
||||
new Vector2(np.x, zeroY), areaColor);
|
||||
}
|
||||
break;
|
||||
case Line.StepType.End:
|
||||
middle1 = new Vector2(np.x + m_Line.tickness, lp.y);
|
||||
middle2 = new Vector2(np.x, lp.y);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(lp.x, zeroY), lp,
|
||||
new Vector2(middle1.x - m_Line.tickness, middle1.y),
|
||||
new Vector2(middle1.x - m_Line.tickness, zeroY), areaColor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (m_Line.smooth)
|
||||
{
|
||||
Vector3[] list;
|
||||
if (xAxis.IsValue()) list = ChartHelper.GetBezierListVertical(lp, np, m_Line.smoothStyle);
|
||||
else list = ChartHelper.GetBezierList(lp, np, m_Line.smoothStyle);
|
||||
Vector3 start, to;
|
||||
start = list[0];
|
||||
for (int k = 1; k < list.Length; k++)
|
||||
{
|
||||
smoothPoints.Add(list[k]);
|
||||
to = list[k];
|
||||
ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color);
|
||||
|
||||
if (m_Line.area)
|
||||
{
|
||||
Vector3 alp = new Vector3(start.x, start.y - m_Line.tickness);
|
||||
Vector3 anp = new Vector3(to.x, to.y - m_Line.tickness);
|
||||
Vector3 tnp = serieIndex > 0 ?
|
||||
(smoothPointCount > lastSmoothPoints.Count - 1 ?
|
||||
new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 1].x,
|
||||
lastSmoothPoints[lastSmoothPoints.Count - 1].y + m_Line.tickness) :
|
||||
new Vector3(lastSmoothPoints[smoothPointCount].x,
|
||||
lastSmoothPoints[smoothPointCount].y + m_Line.tickness)) :
|
||||
new Vector3(to.x, zeroY + m_Coordinate.tickness);
|
||||
Vector3 tlp = serieIndex > 0 ?
|
||||
(smoothPointCount > lastSmoothPoints.Count - 1 ?
|
||||
new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 2].x,
|
||||
lastSmoothPoints[lastSmoothPoints.Count - 2].y + m_Line.tickness) :
|
||||
new Vector3(lastSmoothPoints[smoothPointCount - 1].x,
|
||||
lastSmoothPoints[smoothPointCount - 1].y + m_Line.tickness)) :
|
||||
new Vector3(start.x, zeroY + m_Coordinate.tickness);
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
smoothPointCount++;
|
||||
start = to;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Vector3 alp = new Vector3(lp.x, lp.y - m_Line.tickness);
|
||||
Vector3 anp = new Vector3(np.x, np.y - m_Line.tickness);
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
var cross = ChartHelper.GetIntersection(lp, np, new Vector3(zeroX, zeroY),
|
||||
new Vector3(zeroX + coordinateWid, zeroY));
|
||||
if (cross == Vector3.zero)
|
||||
{
|
||||
Vector3 tnp = serieIndex > 0 ?
|
||||
new Vector3(lastPoints[i].x, lastPoints[i].y + m_Line.tickness) :
|
||||
new Vector3(np.x, zeroY + m_Coordinate.tickness);
|
||||
Vector3 tlp = serieIndex > 0 ?
|
||||
new Vector3(lastPoints[i - 1].x, lastPoints[i - 1].y + m_Line.tickness) :
|
||||
new Vector3(lp.x, zeroY + m_Coordinate.tickness);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 cross1 = new Vector3(cross.x, cross.y + (alp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness));
|
||||
Vector3 cross2 = new Vector3(cross.x, cross.y + (anp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness));
|
||||
Vector3 xp1 = new Vector3(alp.x, zeroY + (alp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness));
|
||||
Vector3 xp2 = new Vector3(anp.x, zeroY + (anp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness));
|
||||
ChartHelper.DrawTriangle(vh, alp, cross1, xp1, areaColor);
|
||||
ChartHelper.DrawTriangle(vh, anp, cross2, xp2, areaColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Line.point)
|
||||
{
|
||||
points.Add(np);
|
||||
colors.Add(color);
|
||||
}
|
||||
seriesHig[i] += yDataHig;
|
||||
lp = np;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawYLineSerie(VertexHelper vh, int serieIndex, Serie serie, ref int dataCount,
|
||||
ref List<Vector3> points, ref List<Color> colors, ref Dictionary<int, float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.name)) return;
|
||||
List<Vector3> lastPoints = new List<Vector3>();
|
||||
List<Vector3> lastSmoothPoints = new List<Vector3>();
|
||||
List<Vector3> smoothPoints = new List<Vector3>();
|
||||
|
||||
Color color = m_ThemeInfo.GetColor(serieIndex);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
|
||||
float startY = zeroY + (yAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.yData.Count ? serie.yData.Count : maxShowDataNumber)
|
||||
: serie.yData.Count;
|
||||
dataCount = (maxCount - minShowDataNumber);
|
||||
if (m_Line.area && points.Count > 0)
|
||||
{
|
||||
if (!m_Line.smooth && points.Count > 0)
|
||||
{
|
||||
for (int m = points.Count - dataCount; m < points.Count; m++)
|
||||
{
|
||||
lastPoints.Add(points[m]);
|
||||
}
|
||||
}
|
||||
else if (m_Line.smooth && smoothPoints.Count > 0)
|
||||
{
|
||||
for (int m = 0; m < smoothPoints.Count; m++)
|
||||
{
|
||||
lastSmoothPoints.Add(smoothPoints[m]);
|
||||
}
|
||||
smoothPoints.Clear();
|
||||
}
|
||||
}
|
||||
int smoothPointCount = 1;
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
{
|
||||
if (!seriesHig.ContainsKey(i))
|
||||
{
|
||||
seriesHig[i] = 0;
|
||||
}
|
||||
float value = serie.yData[i];
|
||||
float pY = startY + i * scaleWid;
|
||||
float pX = seriesHig[i] + coordinateX + m_Coordinate.tickness;
|
||||
float dataHig = (value - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
||||
np = new Vector3(pX + dataHig, pY);
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
if (m_Line.step)
|
||||
{
|
||||
Vector2 middle1, middle2;
|
||||
switch (m_Line.stepTpe)
|
||||
{
|
||||
case Line.StepType.Start:
|
||||
middle1 = new Vector2(np.x, lp.y);
|
||||
middle2 = new Vector2(np.x, lp.y - m_Line.tickness);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(zeroX, middle1.y), middle1, np,
|
||||
new Vector2(zeroX, np.y), areaColor);
|
||||
}
|
||||
break;
|
||||
case Line.StepType.Middle:
|
||||
middle1 = new Vector2(lp.x, (lp.y + np.y) / 2 + m_Line.tickness);
|
||||
middle2 = new Vector2(np.x, (lp.y + np.y) / 2 - m_Line.tickness);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, new Vector2(middle1.x, middle1.y - m_Line.tickness),
|
||||
new Vector2(middle2.x, middle2.y + m_Line.tickness), m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(zeroX, lp.y), lp, middle1,
|
||||
new Vector2(zeroX, middle1.y), areaColor);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(zeroX, middle2.y + 2 * m_Line.tickness),
|
||||
new Vector2(middle2.x, middle2.y + 2 * m_Line.tickness), np,
|
||||
new Vector2(zeroX, np.y), areaColor);
|
||||
}
|
||||
break;
|
||||
case Line.StepType.End:
|
||||
middle1 = new Vector2(np.x, lp.y);
|
||||
middle2 = new Vector2(np.x, lp.y - m_Line.tickness);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(zeroX, lp.y), middle1,
|
||||
new Vector2(np.x, np.y),
|
||||
new Vector2(zeroX, np.y), areaColor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (m_Line.smooth)
|
||||
{
|
||||
var list = ChartHelper.GetBezierListVertical(lp, np, m_Line.smoothStyle);
|
||||
Vector3 start, to;
|
||||
start = list[0];
|
||||
for (int k = 1; k < list.Length; k++)
|
||||
{
|
||||
smoothPoints.Add(list[k]);
|
||||
to = list[k];
|
||||
ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color);
|
||||
|
||||
if (m_Line.area)
|
||||
{
|
||||
Vector3 alp = new Vector3(start.x, start.y - m_Line.tickness);
|
||||
Vector3 anp = new Vector3(to.x, to.y - m_Line.tickness);
|
||||
Vector3 tnp = serieIndex > 0 ?
|
||||
(smoothPointCount > lastSmoothPoints.Count - 1 ?
|
||||
new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 1].x,
|
||||
lastSmoothPoints[lastSmoothPoints.Count - 1].y + m_Line.tickness) :
|
||||
new Vector3(lastSmoothPoints[smoothPointCount].x,
|
||||
lastSmoothPoints[smoothPointCount].y + m_Line.tickness)) :
|
||||
new Vector3(zeroX + m_Coordinate.tickness, to.y);
|
||||
Vector3 tlp = serieIndex > 0 ?
|
||||
(smoothPointCount > lastSmoothPoints.Count - 1 ?
|
||||
new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 2].x,
|
||||
lastSmoothPoints[lastSmoothPoints.Count - 2].y + m_Line.tickness) :
|
||||
new Vector3(lastSmoothPoints[smoothPointCount - 1].x,
|
||||
lastSmoothPoints[smoothPointCount - 1].y + m_Line.tickness)) :
|
||||
new Vector3(zeroX + m_Coordinate.tickness, start.y);
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
smoothPointCount++;
|
||||
start = to;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Vector3 alp = new Vector3(lp.x, lp.y - m_Line.tickness);
|
||||
Vector3 anp = new Vector3(np.x, np.y - m_Line.tickness);
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
var cross = ChartHelper.GetIntersection(lp, np, new Vector3(zeroX, zeroY),
|
||||
new Vector3(zeroX, zeroY + coordinateHig));
|
||||
if (cross == Vector3.zero)
|
||||
{
|
||||
Vector3 tnp = serieIndex > 0 ?
|
||||
new Vector3(lastPoints[i].x, lastPoints[i].y + m_Line.tickness) :
|
||||
new Vector3(zeroX + m_Coordinate.tickness, np.y);
|
||||
Vector3 tlp = serieIndex > 0 ?
|
||||
new Vector3(lastPoints[i - 1].x, lastPoints[i - 1].y + m_Line.tickness) :
|
||||
new Vector3(zeroX + m_Coordinate.tickness, lp.y);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 cross1 = new Vector3(cross.x + (alp.x > zeroX ? m_Coordinate.tickness : -m_Coordinate.tickness), cross.y);
|
||||
Vector3 cross2 = new Vector3(cross.x + (anp.x > zeroX ? m_Coordinate.tickness : -m_Coordinate.tickness), cross.y);
|
||||
Vector3 xp1 = new Vector3(zeroX + (alp.x > zeroX ? m_Coordinate.tickness : -m_Coordinate.tickness), alp.y);
|
||||
Vector3 xp2 = new Vector3(zeroX + (anp.x > zeroX ? m_Coordinate.tickness : -m_Coordinate.tickness), anp.y);
|
||||
ChartHelper.DrawTriangle(vh, alp, cross1, xp1, areaColor);
|
||||
ChartHelper.DrawTriangle(vh, anp, cross2, xp2, areaColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Line.point)
|
||||
{
|
||||
points.Add(np);
|
||||
colors.Add(color);
|
||||
}
|
||||
seriesHig[i] += dataHig;
|
||||
lp = np;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace XCharts
|
||||
if (serie != null)
|
||||
{
|
||||
serie.ClearData();
|
||||
serie.AddData(value);
|
||||
serie.AddYData(value);
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ namespace XCharts
|
||||
var serie = m_Series.GetSerie(legend);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.UpdateData(0, value);
|
||||
serie.UpdateYData(0, value);
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ namespace XCharts
|
||||
m_AngleList.Add(0);
|
||||
continue;
|
||||
}
|
||||
var data = m_Series.series[i].data;
|
||||
var data = m_Series.series[i].yData;
|
||||
if (data.Count <= 0)
|
||||
{
|
||||
m_AngleList.Add(0);
|
||||
@@ -123,7 +123,7 @@ namespace XCharts
|
||||
{
|
||||
if (IsActive(i))
|
||||
{
|
||||
total += m_Series.series[i].GetData(0);
|
||||
total += m_Series.series[i].GetYData(0);
|
||||
}
|
||||
}
|
||||
return total;
|
||||
@@ -134,9 +134,9 @@ namespace XCharts
|
||||
float max = 0;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (IsActive(i) && m_Series.series[i].GetData(0) > max)
|
||||
if (IsActive(i) && m_Series.series[i].GetYData(0) > max)
|
||||
{
|
||||
max = m_Series.series[i].GetData(0);
|
||||
max = m_Series.series[i].GetYData(0);
|
||||
}
|
||||
}
|
||||
return max;
|
||||
@@ -232,7 +232,7 @@ namespace XCharts
|
||||
string strColor = ColorUtility.ToHtmlStringRGBA(m_ThemeInfo.GetColor(index));
|
||||
string key = m_Series.series[index].name;
|
||||
if (string.IsNullOrEmpty(key)) key = m_Legend.GetData(index);
|
||||
float value = m_Series.series[index].data[0];
|
||||
float value = m_Series.series[index].yData[0];
|
||||
string txt = "";
|
||||
if (!string.IsNullOrEmpty(m_Pie.name))
|
||||
{
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace XCharts
|
||||
dataPosList.Add(new List<Vector3>());
|
||||
continue;
|
||||
}
|
||||
var dataList = m_Series.series[i].data;
|
||||
var dataList = m_Series.series[i].yData;
|
||||
var color = m_ThemeInfo.GetColor(i);
|
||||
var areaColor = color;
|
||||
areaColor.a = (byte)m_Radar.areaAipha;
|
||||
@@ -330,7 +330,7 @@ namespace XCharts
|
||||
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];
|
||||
float value = m_Series.series[index].yData[i];
|
||||
sb.Append("\n");
|
||||
sb.AppendFormat("{0}: {1}", key, value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user