mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 06:50:18 +00:00
修复区域平滑折线图显示异常的问题
This commit is contained in:
@@ -93,6 +93,12 @@ namespace XCharts
|
||||
[SerializeField] private List<float> m_XData = new List<float>();
|
||||
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
|
||||
|
||||
[NonSerialized] private int m_FilterStart;
|
||||
[NonSerialized] private int m_FilterEnd;
|
||||
[NonSerialized] private List<SerieData> m_FilterData;
|
||||
[NonSerialized] private Dictionary<int, List<Vector3>> m_SmoothPoints = new Dictionary<int, List<Vector3>>();
|
||||
[NonSerialized] private List<Vector3> m_DataPoints = new List<Vector3>();
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show serie in chart.
|
||||
/// 系列是否显示在图表上。
|
||||
@@ -203,10 +209,27 @@ namespace XCharts
|
||||
/// 数据项个数。
|
||||
/// </summary>
|
||||
public int dataCount { get { return m_Data.Count; } }
|
||||
/// <summary>
|
||||
/// 整个系列的每段曲线的点列表
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Dictionary<int, List<Vector3>> smoothPoints { get { return m_SmoothPoints; } }
|
||||
|
||||
private int filterStart { get; set; }
|
||||
private int filterEnd { get; set; }
|
||||
private List<SerieData> filterData { get; set; }
|
||||
public List<Vector3> dataPoints { get { return m_DataPoints; } }
|
||||
|
||||
public List<Vector3> GetSmoothList(int dataIndex, int size = 100)
|
||||
{
|
||||
if (m_SmoothPoints.ContainsKey(dataIndex))
|
||||
{
|
||||
return m_SmoothPoints[dataIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = new List<Vector3>(size);
|
||||
m_SmoothPoints[dataIndex] = list;
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 维度Y对应数据中最大值。
|
||||
@@ -503,11 +526,11 @@ namespace XCharts
|
||||
var startIndex = (int)((m_Data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((m_Data.Count - 1) * dataZoom.end / 100);
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (filterData == null || filterData.Count != count)
|
||||
if (m_FilterData == null || m_FilterData.Count != count)
|
||||
{
|
||||
UpdateFilterData(dataZoom);
|
||||
}
|
||||
return filterData;
|
||||
return m_FilterData;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -550,23 +573,23 @@ namespace XCharts
|
||||
{
|
||||
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
|
||||
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
|
||||
if (startIndex != filterStart || endIndex != filterEnd)
|
||||
if (startIndex != m_FilterStart || endIndex != m_FilterEnd)
|
||||
{
|
||||
filterStart = startIndex;
|
||||
filterEnd = endIndex;
|
||||
m_FilterStart = startIndex;
|
||||
m_FilterEnd = endIndex;
|
||||
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
|
||||
if (m_Data.Count > 0)
|
||||
{
|
||||
filterData = m_Data.GetRange(startIndex, count);
|
||||
m_FilterData = m_Data.GetRange(startIndex, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
filterData = m_Data;
|
||||
m_FilterData = m_Data;
|
||||
}
|
||||
}
|
||||
else if (endIndex == 0)
|
||||
{
|
||||
filterData = new List<SerieData>();
|
||||
m_FilterData = new List<SerieData>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -587,6 +587,24 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsStack(string stackName)
|
||||
{
|
||||
_setForStack.Clear();
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
if (string.IsNullOrEmpty(serie.stack)) continue;
|
||||
if (_setForStack.Contains(serie.stack))
|
||||
{
|
||||
if (serie.stack.Equals(stackName)) return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_setForStack.Add(serie.stack);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得堆叠系列列表
|
||||
/// </summary>
|
||||
|
||||
@@ -244,18 +244,18 @@ namespace XCharts
|
||||
public Color32 GetColor(int index)
|
||||
{
|
||||
if (index < 0) index = 0;
|
||||
var customIndex = index < m_CustomColorPalette.Count ? index : index % m_CustomColorPalette.Count;
|
||||
if (customIndex < m_CustomColorPalette.Count && m_CustomColorPalette[customIndex] != Color.clear)
|
||||
if (m_CustomColorPalette.Count > 0)
|
||||
{
|
||||
return m_CustomColorPalette[customIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
var newIndex = index < m_ColorPalette.Length ? index : index % m_ColorPalette.Length;
|
||||
if (newIndex < m_ColorPalette.Length)
|
||||
return m_ColorPalette[newIndex];
|
||||
else return Color.clear;
|
||||
var customIndex = index < m_CustomColorPalette.Count ? index : index % m_CustomColorPalette.Count;
|
||||
if (customIndex < m_CustomColorPalette.Count && m_CustomColorPalette[customIndex] != Color.clear)
|
||||
{
|
||||
return m_CustomColorPalette[customIndex];
|
||||
}
|
||||
}
|
||||
var newIndex = index < m_ColorPalette.Length ? index : index % m_ColorPalette.Length;
|
||||
if (newIndex < m_ColorPalette.Length)
|
||||
return m_ColorPalette[newIndex];
|
||||
else return Color.clear;
|
||||
}
|
||||
|
||||
Dictionary<int, string> _colorDic = new Dictionary<int, string>();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -26,7 +27,7 @@ namespace XCharts
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
AddXAxisData("x" + (i + 1));
|
||||
AddData(0, Random.Range(10, 90));
|
||||
AddData(0, UnityEngine.Random.Range(10, 90));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -48,21 +49,17 @@ namespace XCharts
|
||||
private Dictionary<int, List<Serie>> stackSeries = new Dictionary<int, List<Serie>>();
|
||||
private List<float> seriesCurrHig = new List<float>();
|
||||
private HashSet<string> serieNameSet = new HashSet<string>();
|
||||
private List<Vector3> points = new List<Vector3>();
|
||||
private List<int> pointSerieIndex = new List<int>();
|
||||
private void DrawLineChart(VertexHelper vh, bool yCategory)
|
||||
{
|
||||
m_Series.GetStackSeries(ref stackSeries);
|
||||
int seriesCount = stackSeries.Count;
|
||||
int serieCount = 0;
|
||||
int dataCount = 0;
|
||||
serieNameSet.Clear();
|
||||
points.Clear();
|
||||
pointSerieIndex.Clear();
|
||||
int serieNameCount = -1;
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
var serieList = stackSeries[j];
|
||||
if (serieList.Count <= 0) continue;
|
||||
seriesCurrHig.Clear();
|
||||
if (seriesCurrHig.Capacity != serieList[0].dataCount)
|
||||
{
|
||||
@@ -71,6 +68,7 @@ namespace XCharts
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
Serie serie = serieList[n];
|
||||
serie.dataPoints.Clear();
|
||||
if (string.IsNullOrEmpty(serie.name)) serieNameCount++;
|
||||
else if (!serieNameSet.Contains(serie.name))
|
||||
{
|
||||
@@ -79,93 +77,74 @@ namespace XCharts
|
||||
}
|
||||
Color color = m_ThemeInfo.GetColor(serieNameCount);
|
||||
if (yCategory)
|
||||
DrawYLineSerie(vh, serieCount, color, serie, ref dataCount, ref points, ref pointSerieIndex, ref seriesCurrHig);
|
||||
DrawYLineSerie(vh, serieCount, color, serie, ref seriesCurrHig);
|
||||
else
|
||||
DrawXLineSerie(vh, serieCount, color, serie, ref dataCount, ref points, ref pointSerieIndex, ref seriesCurrHig);
|
||||
DrawXLineSerie(vh, serieCount, color, serie, ref seriesCurrHig);
|
||||
if (serie.show)
|
||||
{
|
||||
serieCount++;
|
||||
}
|
||||
}
|
||||
DrawLinePoint(vh, dataCount, points, pointSerieIndex);
|
||||
|
||||
}
|
||||
DrawLinePoint(vh);
|
||||
if (yCategory) DrawYTooltipIndicator(vh);
|
||||
else DrawXTooltipIndicator(vh);
|
||||
}
|
||||
|
||||
private void DrawLinePoint(VertexHelper vh, int dataCount, List<Vector3> points, List<int> pointSerieIndex)
|
||||
private void DrawLinePoint(VertexHelper vh)
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
for (int n = 0; n < m_Series.Count; n++)
|
||||
{
|
||||
Vector3 p = points[i];
|
||||
var dataIndex = i % dataCount;
|
||||
var serie = m_Series.GetSerie(pointSerieIndex[i]);
|
||||
var serie = m_Series.GetSerie(n);
|
||||
if (!serie.show) continue;
|
||||
var color = m_ThemeInfo.GetColor(serie.index);
|
||||
float symbolSize = serie.symbol.size;
|
||||
if ((m_Tooltip.show && m_Tooltip.IsSelected(dataIndex))
|
||||
|| serie.data[dataIndex].highlighted
|
||||
|| serie.highlighted)
|
||||
for (int i = 0; i < serie.dataPoints.Count; i++)
|
||||
{
|
||||
if (IsValue())
|
||||
Vector3 p = serie.dataPoints[i];
|
||||
if ((m_Tooltip.show && m_Tooltip.IsSelected(i))
|
||||
|| serie.data[i].highlighted
|
||||
|| serie.highlighted)
|
||||
{
|
||||
if (m_Series.IsHighlight(serie.index))
|
||||
if (IsValue())
|
||||
{
|
||||
if (m_Series.IsHighlight(serie.index))
|
||||
{
|
||||
symbolSize = serie.symbol.selectedSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
symbolSize = serie.symbol.selectedSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
symbolSize = serie.symbol.selectedSize;
|
||||
}
|
||||
DrawSymbol(vh, serie.symbol.type, symbolSize, m_Line.tickness, p, color);
|
||||
}
|
||||
var color = m_ThemeInfo.GetColor(serie.index);
|
||||
DrawSymbol(vh, serie.symbol.type, symbolSize, m_Line.tickness, p, color);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<Vector3> lastPoints = new List<Vector3>();
|
||||
List<Vector3> lastSmoothPoints = new List<Vector3>();
|
||||
List<Vector3> smoothPoints = new List<Vector3>();
|
||||
// List<Vector3> lastPoints = new List<Vector3>();
|
||||
// List<Vector3> lastSmoothPoints = new List<Vector3>();
|
||||
// List<Vector3> smoothPoints = new List<Vector3>();
|
||||
List<Vector3> smoothSegmentPoints = new List<Vector3>();
|
||||
private void DrawXLineSerie(VertexHelper vh, int serieIndex, Color color, Serie serie, ref int dataCount,
|
||||
ref List<Vector3> points, ref List<int> pointSerieIndexs, ref List<float> seriesHig)
|
||||
private void DrawXLineSerie(VertexHelper vh, int serieIndex, Color lineColor, Serie serie, ref List<float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.index)) return;
|
||||
lastPoints.Clear();
|
||||
lastSmoothPoints.Clear();
|
||||
smoothPoints.Clear();
|
||||
var showData = serie.GetDataList(m_DataZoom);
|
||||
|
||||
Color areaColor = new Color(lineColor.r, lineColor.g, lineColor.b, lineColor.a * 0.75f);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var lastSerie = m_Series.GetSerie(serie.index - 1);
|
||||
var isStack = m_Series.IsStack(serie.stack);
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
float scaleWid = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
|
||||
float startX = coordinateX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
|
||||
: showData.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;
|
||||
if (seriesHig.Count < minShowDataNumber)
|
||||
{
|
||||
for (int i = 0; i < minShowDataNumber; i++)
|
||||
@@ -208,11 +187,10 @@ namespace XCharts
|
||||
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);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, lineColor);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, lineColor);
|
||||
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, coordinateY), middle1, np,
|
||||
new Vector2(np.x, coordinateY), areaColor);
|
||||
}
|
||||
@@ -220,13 +198,12 @@ namespace XCharts
|
||||
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, lp, middle1, m_Line.tickness, lineColor);
|
||||
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);
|
||||
new Vector2(middle2.x + m_Line.tickness, middle2.y), m_Line.tickness, lineColor);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, lineColor);
|
||||
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, coordinateY), lp, middle1,
|
||||
new Vector2(middle1.x, coordinateY), areaColor);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(middle2.x + 2 * m_Line.tickness, coordinateY),
|
||||
@@ -237,11 +214,10 @@ namespace XCharts
|
||||
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);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, lineColor);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, lineColor);
|
||||
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, coordinateY), lp,
|
||||
new Vector2(middle1.x - m_Line.tickness, middle1.y),
|
||||
new Vector2(middle1.x - m_Line.tickness, coordinateY), areaColor);
|
||||
@@ -251,58 +227,24 @@ namespace XCharts
|
||||
}
|
||||
else if (m_Line.smooth)
|
||||
{
|
||||
if (xAxis.IsValue()) ChartHelper.GetBezierListVertical(ref smoothSegmentPoints, lp, np, m_Line.smoothStyle);
|
||||
else ChartHelper.GetBezierList(ref smoothSegmentPoints, lp, np, m_Line.smoothStyle);
|
||||
Vector3 start, to;
|
||||
start = smoothSegmentPoints[0];
|
||||
for (int k = 1; k < smoothSegmentPoints.Count; k++)
|
||||
{
|
||||
smoothPoints.Add(smoothSegmentPoints[k]);
|
||||
to = smoothSegmentPoints[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, coordinateY + xAxis.axisLine.width);
|
||||
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, coordinateY + xAxis.axisLine.width);
|
||||
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;
|
||||
}
|
||||
DrawSmoothAreaPoints(vh, serieIndex, serie, xAxis, lp, np, i, lineColor, areaColor, isStack);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, lineColor);
|
||||
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(coordinateX, coordinateY),
|
||||
new Vector3(coordinateX + coordinateWid, coordinateY));
|
||||
if (cross == Vector3.zero)
|
||||
{
|
||||
Vector3 tnp = serieIndex > 0 ?
|
||||
new Vector3(lastPoints[i].x, lastPoints[i].y + m_Line.tickness) :
|
||||
new Vector3(lastSerie.dataPoints[i].x, lastSerie.dataPoints[i].y + m_Line.tickness) :
|
||||
new Vector3(np.x, coordinateY + xAxis.axisLine.width);
|
||||
Vector3 tlp = serieIndex > 0 ?
|
||||
new Vector3(lastPoints[i - 1].x, lastPoints[i - 1].y + m_Line.tickness) :
|
||||
new Vector3(lastSerie.dataPoints[i - 1].x, lastSerie.dataPoints[i - 1].y + m_Line.tickness) :
|
||||
new Vector3(lp.x, coordinateY + xAxis.axisLine.width);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
@@ -318,54 +260,152 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
}
|
||||
if (serie.symbol.type != SerieSymbolType.None || m_Line.area)
|
||||
{
|
||||
points.Add(np);
|
||||
pointSerieIndexs.Add(serie.index);
|
||||
}
|
||||
serie.dataPoints.Add(np);
|
||||
seriesHig[i] += yDataHig;
|
||||
lp = np;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawYLineSerie(VertexHelper vh, int serieIndex, Color color, Serie serie, ref int dataCount,
|
||||
ref List<Vector3> points, ref List<int> pointSerieIndexs, ref List<float> seriesHig)
|
||||
private void DrawSmoothAreaPoints(VertexHelper vh, int serieIndex, Serie serie, Axis xAxis, Vector3 lp,
|
||||
Vector3 np, int dataIndex, Color lineColor, Color areaColor, bool isStack)
|
||||
{
|
||||
bool isYAxis = xAxis is YAxis;
|
||||
if (isYAxis) ChartHelper.GetBezierListVertical(ref smoothSegmentPoints, lp, np, m_Line.smoothStyle);
|
||||
else ChartHelper.GetBezierList(ref smoothSegmentPoints, lp, np, m_Line.smoothStyle);
|
||||
Vector3 start, to;
|
||||
start = smoothSegmentPoints[0];
|
||||
|
||||
var smoothPoints = serie.GetSmoothList(dataIndex, smoothSegmentPoints.Count);
|
||||
smoothPoints.Clear();
|
||||
var lastSerie = m_Series.GetSerie(serie.index - 1);
|
||||
var lastSmoothPoints = lastSerie != null ? lastSerie.GetSmoothList(dataIndex, smoothSegmentPoints.Count) : new List<Vector3>();
|
||||
smoothPoints.Add(start);
|
||||
var lastCount = 1;
|
||||
for (int k = 1; k < smoothSegmentPoints.Count; k++)
|
||||
{
|
||||
smoothPoints.Add(smoothSegmentPoints[k]);
|
||||
to = smoothSegmentPoints[k];
|
||||
ChartHelper.DrawLine(vh, start, to, m_Line.tickness, lineColor);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Vector3 alp, anp, tnp, tlp;
|
||||
if (isYAxis)
|
||||
{
|
||||
alp = new Vector3(start.x - m_Line.tickness, start.y);
|
||||
anp = new Vector3(to.x - m_Line.tickness, to.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
alp = new Vector3(start.x, start.y - m_Line.tickness);
|
||||
anp = new Vector3(to.x, to.y - m_Line.tickness);
|
||||
}
|
||||
if (serieIndex > 0 && isStack)
|
||||
{
|
||||
if (k == smoothSegmentPoints.Count - 1)
|
||||
{
|
||||
if (k < lastSmoothPoints.Count - 1)
|
||||
{
|
||||
tnp = lastSmoothPoints[lastCount - 1];
|
||||
if (isYAxis) tnp.x += m_Line.tickness;
|
||||
else tnp.y += m_Line.tickness;
|
||||
ChartHelper.DrawTriangle(vh, alp, anp, tnp, areaColor);
|
||||
while (lastCount < lastSmoothPoints.Count)
|
||||
{
|
||||
tlp = lastSmoothPoints[lastCount];
|
||||
if (isYAxis) tlp.x += m_Line.tickness;
|
||||
else tlp.y += m_Line.tickness;
|
||||
ChartHelper.DrawTriangle(vh, tnp, anp, tlp, areaColor);
|
||||
lastCount++;
|
||||
tnp = tlp;
|
||||
}
|
||||
start = to;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
if (lastCount >= lastSmoothPoints.Count)
|
||||
{
|
||||
tlp = lastSmoothPoints[lastSmoothPoints.Count - 1];
|
||||
if (isYAxis) tlp.x += m_Line.tickness;
|
||||
else tlp.y += m_Line.tickness;
|
||||
ChartHelper.DrawTriangle(vh, anp, alp, tlp, areaColor);
|
||||
start = to;
|
||||
continue;
|
||||
}
|
||||
if (isYAxis) tnp = new Vector3(lastSmoothPoints[lastCount].x + m_Line.tickness, lastSmoothPoints[lastCount].y);
|
||||
else tnp = new Vector3(lastSmoothPoints[lastCount].x, lastSmoothPoints[lastCount].y + m_Line.tickness);
|
||||
|
||||
var diff = isYAxis ? tnp.y - to.y : tnp.x - to.x;
|
||||
if (Math.Abs(diff) < 1)
|
||||
{
|
||||
if (isYAxis) tlp = new Vector3(lastSmoothPoints[lastCount - 1].x + m_Line.tickness, lastSmoothPoints[lastCount - 1].y);
|
||||
else tlp = new Vector3(lastSmoothPoints[lastCount - 1].x, lastSmoothPoints[lastCount - 1].y + m_Line.tickness);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
lastCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (diff < 0)
|
||||
{
|
||||
if (isYAxis) tnp = new Vector3(lastSmoothPoints[lastCount - 1].x + m_Line.tickness, lastSmoothPoints[lastCount - 1].y);
|
||||
else tnp = new Vector3(lastSmoothPoints[lastCount - 1].x, lastSmoothPoints[lastCount - 1].y + m_Line.tickness);
|
||||
ChartHelper.DrawTriangle(vh, alp, anp, tnp, areaColor);
|
||||
while (diff < 0 && lastCount < lastSmoothPoints.Count)
|
||||
{
|
||||
if (isYAxis) tlp = new Vector3(lastSmoothPoints[lastCount].x + m_Line.tickness, lastSmoothPoints[lastCount].y);
|
||||
else tlp = new Vector3(lastSmoothPoints[lastCount].x, lastSmoothPoints[lastCount].y + m_Line.tickness);
|
||||
ChartHelper.DrawTriangle(vh, tnp, anp, tlp, areaColor);
|
||||
lastCount++;
|
||||
diff = isYAxis ? tlp.y - to.y : tlp.x - to.x;
|
||||
tnp = tlp;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isYAxis) tlp = new Vector3(lastSmoothPoints[lastCount - 1].x + m_Line.tickness, lastSmoothPoints[lastCount - 1].y);
|
||||
else tlp = new Vector3(lastSmoothPoints[lastCount - 1].x, lastSmoothPoints[lastCount - 1].y + m_Line.tickness);
|
||||
ChartHelper.DrawTriangle(vh, alp, anp, tlp, areaColor);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isYAxis)
|
||||
{
|
||||
tnp = new Vector3(coordinateX + xAxis.axisLine.width, to.y);
|
||||
tlp = new Vector3(coordinateX + xAxis.axisLine.width, start.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
tnp = new Vector3(to.x, coordinateY + xAxis.axisLine.width);
|
||||
tlp = new Vector3(start.x, coordinateY + xAxis.axisLine.width);
|
||||
}
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
}
|
||||
start = to;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawYLineSerie(VertexHelper vh, int serieIndex, Color lineColor, Serie serie, ref List<float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.index)) return;
|
||||
lastPoints.Clear();
|
||||
lastSmoothPoints.Clear();
|
||||
smoothPoints.Clear();
|
||||
var showData = serie.GetDataList(m_DataZoom);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
Color areaColor = new Color(lineColor.r, lineColor.g, lineColor.b, lineColor.a * 0.75f);
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var lastSerie = m_Series.GetSerie(serieIndex - 1);
|
||||
var isStack = m_Series.IsStack(serie.stack);
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
|
||||
float startY = coordinateY + (yAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
|
||||
: showData.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;
|
||||
if (seriesHig.Count < minShowDataNumber)
|
||||
{
|
||||
for (int i = 0; i < minShowDataNumber; i++)
|
||||
@@ -394,11 +434,10 @@ namespace XCharts
|
||||
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);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, lineColor);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, lineColor);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, middle1.y), middle1, np,
|
||||
new Vector2(coordinateX, np.y), areaColor);
|
||||
}
|
||||
@@ -406,13 +445,12 @@ namespace XCharts
|
||||
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, lp, middle1, m_Line.tickness, lineColor);
|
||||
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);
|
||||
new Vector2(middle2.x, middle2.y + m_Line.tickness), m_Line.tickness, lineColor);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, lineColor);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, lp.y), lp, middle1,
|
||||
new Vector2(coordinateX, middle1.y), areaColor);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, middle2.y + 2 * m_Line.tickness),
|
||||
@@ -423,11 +461,10 @@ namespace XCharts
|
||||
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);
|
||||
ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, lineColor);
|
||||
ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, lineColor);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, lp.y), middle1,
|
||||
new Vector2(np.x, np.y),
|
||||
new Vector2(coordinateX, np.y), areaColor);
|
||||
@@ -437,57 +474,24 @@ namespace XCharts
|
||||
}
|
||||
else if (m_Line.smooth)
|
||||
{
|
||||
ChartHelper.GetBezierListVertical(ref smoothSegmentPoints, lp, np, m_Line.smoothStyle);
|
||||
Vector3 start, to;
|
||||
start = smoothSegmentPoints[0];
|
||||
for (int k = 1; k < smoothSegmentPoints.Count; k++)
|
||||
{
|
||||
smoothPoints.Add(smoothSegmentPoints[k]);
|
||||
to = smoothSegmentPoints[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(coordinateX + yAxis.axisLine.width, 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(coordinateX + yAxis.axisLine.width, 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;
|
||||
}
|
||||
DrawSmoothAreaPoints(vh, serieIndex, serie, yAxis, lp, np, i, lineColor, areaColor, isStack);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, lineColor);
|
||||
if (m_Line.area)
|
||||
{
|
||||
Vector3 alp = new Vector3(lp.x, lp.y);
|
||||
Vector3 anp = new Vector3(np.x, np.y);
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
var cross = ChartHelper.GetIntersection(lp, np, new Vector3(coordinateX, coordinateY),
|
||||
new Vector3(coordinateX, coordinateY + coordinateHig));
|
||||
if (cross == Vector3.zero)
|
||||
{
|
||||
Vector3 tnp = serieIndex > 0 ?
|
||||
new Vector3(lastPoints[i].x + yAxis.axisLine.width, lastPoints[i].y) :
|
||||
new Vector3(lastSerie.dataPoints[i].x + yAxis.axisLine.width, lastSerie.dataPoints[i].y) :
|
||||
new Vector3(coordinateX + yAxis.axisLine.width, np.y);
|
||||
Vector3 tlp = serieIndex > 0 ?
|
||||
new Vector3(lastPoints[i - 1].x + yAxis.axisLine.width, lastPoints[i - 1].y) :
|
||||
new Vector3(lastSerie.dataPoints[i - 1].x + yAxis.axisLine.width, lastSerie.dataPoints[i - 1].y) :
|
||||
new Vector3(coordinateX + yAxis.axisLine.width, lp.y);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
@@ -503,11 +507,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
}
|
||||
if (serie.symbol.type != SerieSymbolType.None || m_Line.area)
|
||||
{
|
||||
points.Add(np);
|
||||
pointSerieIndexs.Add(serie.index);
|
||||
}
|
||||
serie.dataPoints.Add(np);
|
||||
seriesHig[i] += dataHig;
|
||||
lp = np;
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ namespace XCharts
|
||||
Vector3 cp2 = sp + dist / k * dir * (k - 1);
|
||||
cp1.y = sp.y;
|
||||
cp2.y = ep.y;
|
||||
int segment = (int)(dist / 0.3f);
|
||||
int segment = (int)(dist / 0.6f);
|
||||
GetBezierList2(ref posList, sp, ep, segment, cp1, cp2);
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ namespace XCharts
|
||||
Vector3 cp2 = sp + dist / k * dir * (k - 1);
|
||||
cp1.y = sp.y;
|
||||
cp2.y = ep.y;
|
||||
int segment = (int)(dist / 0.3f);
|
||||
int segment = (int)(dist / 0.6f);
|
||||
GetBezierList2(ref posList, sp, ep, segment, cp2, cp1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user