mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 23:10:06 +00:00
增加二维数据支持,XY轴都可以设置为数值轴
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user