mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-16 13:30:10 +00:00
增加堆叠区域图
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
@@ -41,81 +42,158 @@ namespace XCharts
|
||||
|
||||
private void DrawXCategory(VertexHelper vh)
|
||||
{
|
||||
int seriesCount = m_Series.Count;
|
||||
var stackSeries = m_Series.GetStackSeries();
|
||||
int seriesCount = stackSeries.Count;
|
||||
float scaleWid = m_XAxis.GetDataWidth(coordinateWid);
|
||||
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++)
|
||||
{
|
||||
if (!IsActive(j)) continue;
|
||||
Serie serie = m_Series.series[j];
|
||||
Color32 color = m_ThemeInfo.GetColor(j);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
float startX = zeroX + (m_XAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
|
||||
: serie.data.Count;
|
||||
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
var seriesCurrHig = new Dictionary<int, float>();
|
||||
var serieList = stackSeries[j];
|
||||
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
float value = serie.data[i];
|
||||
float dataHig = coordinateY + (value - minValue) / (maxValue - minValue) * coordinateHig;
|
||||
np = new Vector3(startX + i * scaleWid, dataHig);
|
||||
if (i > 0)
|
||||
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;
|
||||
float startX = zeroX + (m_XAxis.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)
|
||||
if(!m_Line.smooth && points.Count > 0)
|
||||
{
|
||||
var list = ChartHelper.GetBezierList(lp, np, m_Line.smoothStyle);
|
||||
Vector3 start, to;
|
||||
start = list[0];
|
||||
for (int k = 1; k < list.Length; k++)
|
||||
for (int m = points.Count - dataCount; m < points.Count; m++)
|
||||
{
|
||||
to = list[k];
|
||||
ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color);
|
||||
start = to;
|
||||
lastPoints.Add(points[m]);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(m_Line.smooth && smoothPoints.Count > 0)
|
||||
{
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
for(int m = 0; m < smoothPoints.Count; m++)
|
||||
{
|
||||
ChartHelper.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY),
|
||||
new Vector3(lp.x, zeroY), color);
|
||||
lastSmoothPoints.Add(smoothPoints[m]);
|
||||
}
|
||||
smoothPoints.Clear();
|
||||
}
|
||||
|
||||
}
|
||||
lp = np;
|
||||
int smoothPointCount = 1;
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
{
|
||||
if (!seriesCurrHig.ContainsKey(i))
|
||||
{
|
||||
seriesCurrHig[i] = 0;
|
||||
}
|
||||
float value = serie.data[i];
|
||||
float pX = startX + i * scaleWid;
|
||||
float pY = seriesCurrHig[i] + zeroY + m_Coordinate.tickness;
|
||||
float dataHig = value / (maxValue - minValue) * coordinateHig;
|
||||
|
||||
np = new Vector3(pX, pY+ dataHig);
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
|
||||
ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Line.point)
|
||||
{
|
||||
points.Add(np);
|
||||
colorList.Add(color);
|
||||
}
|
||||
seriesCurrHig[i] += dataHig;
|
||||
lp = np;
|
||||
}
|
||||
if (serie.show)
|
||||
{
|
||||
serieCount++;
|
||||
}
|
||||
}
|
||||
// draw point
|
||||
if (m_Line.point)
|
||||
{
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
float value = serie.data[i];
|
||||
float dataHig = coordinateY + (value - minValue) / (maxValue - minValue) * coordinateHig;
|
||||
Vector3 p = new Vector3(startX + i * scaleWid, dataHig);
|
||||
Vector3 p = points[i];
|
||||
float pointWid = m_Line.pointWidth;
|
||||
if (m_Tooltip.show && i == m_Tooltip.dataIndex - 1)
|
||||
if (m_Tooltip.show && i% dataCount == m_Tooltip.dataIndex - 1)
|
||||
{
|
||||
pointWid = pointWid * 1.8f;
|
||||
}
|
||||
if (m_Theme == Theme.Dark)
|
||||
{
|
||||
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, color,
|
||||
ChartHelper.DrawCricle(vh, p, pointWid, colorList[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, color);
|
||||
pointWid, 0, 360, colorList[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//draw tooltip line
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
@@ -129,61 +207,83 @@ namespace XCharts
|
||||
|
||||
private void DrawYCategory(VertexHelper vh)
|
||||
{
|
||||
int seriesCount = m_Series.Count;
|
||||
var stackSeries = m_Series.GetStackSeries();
|
||||
int seriesCount = stackSeries.Count;
|
||||
float scaleWid = m_YAxis.GetDataWidth(coordinateHig);
|
||||
int serieCount = 0;
|
||||
List<Vector3> pointList = new List<Vector3>();
|
||||
List<Color> pointColorList = new List<Color>();
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
if (!IsActive(j)) continue;
|
||||
Serie serie = m_Series.series[j];
|
||||
Color32 color = m_ThemeInfo.GetColor(j);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
float startY = coordinateY + (m_YAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
|
||||
: serie.data.Count;
|
||||
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
var seriesCurrHig = new Dictionary<int, float>();
|
||||
var serieList = stackSeries[j];
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
float value = serie.data[i];
|
||||
float dataHig = coordinateX + (value - minValue) / (maxValue - minValue) * coordinateWid;
|
||||
np = new Vector3(dataHig,startY + i * scaleWid);
|
||||
if (i > 0)
|
||||
Serie serie = serieList[n];
|
||||
if (!m_Legend.IsActive(serie.name)) continue;
|
||||
Color color = m_ThemeInfo.GetColor(serieCount);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
float startY = coordinateY + (m_YAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
|
||||
: serie.data.Count;
|
||||
for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
{
|
||||
if (m_Line.smooth)
|
||||
if (!seriesCurrHig.ContainsKey(i))
|
||||
{
|
||||
var list = ChartHelper.GetBezierList(lp, np, m_Line.smoothStyle);
|
||||
Vector3 start, to;
|
||||
start = list[0];
|
||||
for (int k = 1; k < list.Length; k++)
|
||||
seriesCurrHig[i] = 0;
|
||||
}
|
||||
float value = serie.data[i];
|
||||
float pY = startY + i * scaleWid;
|
||||
float pX = seriesCurrHig[i] + zeroY + m_Coordinate.tickness;
|
||||
float dataHig = value / (maxValue - minValue) * coordinateWid;
|
||||
seriesCurrHig[i] += dataHig;
|
||||
np = new Vector3(pX+ dataHig, pY);
|
||||
if (m_Line.point)
|
||||
{
|
||||
pointList.Add(np);
|
||||
pointColorList.Add(color);
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
if (m_Line.smooth)
|
||||
{
|
||||
to = list[k];
|
||||
ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color);
|
||||
start = to;
|
||||
var list = ChartHelper.GetBezierList(lp, np, m_Line.smoothStyle);
|
||||
Vector3 start, to;
|
||||
start = list[0];
|
||||
for (int k = 1; k < list.Length; k++)
|
||||
{
|
||||
to = list[k];
|
||||
ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color);
|
||||
start = to;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
ChartHelper.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY),
|
||||
new Vector3(lp.x, zeroY), color);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
|
||||
if (m_Line.area)
|
||||
{
|
||||
ChartHelper.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY),
|
||||
new Vector3(lp.x, zeroY), color);
|
||||
}
|
||||
}
|
||||
|
||||
lp = np;
|
||||
}
|
||||
|
||||
if (serie.show)
|
||||
{
|
||||
serieCount++;
|
||||
}
|
||||
lp = np;
|
||||
}
|
||||
// draw point
|
||||
if (m_Line.point)
|
||||
{
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
for (int i = 0; i < pointList.Count; i++)
|
||||
{
|
||||
float value = serie.data[i];
|
||||
float dataHig = coordinateX + (value - minValue) / (maxValue - minValue) * coordinateWid;
|
||||
Vector3 p = new Vector3(dataHig,startY + i * scaleWid);
|
||||
Vector3 p = pointList[i];
|
||||
Color color = pointColorList[i];
|
||||
float pointWid = m_Line.pointWidth;
|
||||
if (m_Tooltip.show && i == m_Tooltip.dataIndex - 1)
|
||||
{
|
||||
@@ -204,6 +304,82 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//int seriesCount = m_Series.Count;
|
||||
//float scaleWid = m_YAxis.GetDataWidth(coordinateHig);
|
||||
//for (int j = 0; j < seriesCount; j++)
|
||||
//{
|
||||
// if (!IsActive(j)) continue;
|
||||
// Serie serie = m_Series.series[j];
|
||||
// Color32 color = m_ThemeInfo.GetColor(j);
|
||||
// Vector3 lp = Vector3.zero;
|
||||
// Vector3 np = Vector3.zero;
|
||||
// float startY = coordinateY + (m_YAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
|
||||
// int maxCount = maxShowDataNumber > 0 ?
|
||||
// (maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
|
||||
// : serie.data.Count;
|
||||
|
||||
// for (int i = minShowDataNumber; i < maxCount; i++)
|
||||
// {
|
||||
// float value = serie.data[i];
|
||||
// float dataHig = coordinateX + (value - minValue) / (maxValue - minValue) * coordinateWid;
|
||||
// np = new Vector3(dataHig,startY + i * scaleWid);
|
||||
// if (i > 0)
|
||||
// {
|
||||
// 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++)
|
||||
// {
|
||||
// to = list[k];
|
||||
// ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color);
|
||||
// start = to;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
|
||||
// if (m_Line.area)
|
||||
// {
|
||||
// ChartHelper.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY),
|
||||
// new Vector3(lp.x, zeroY), color);
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
// lp = np;
|
||||
// }
|
||||
// // draw point
|
||||
// if (m_Line.point)
|
||||
// {
|
||||
// for (int i = 0; i < serie.data.Count; i++)
|
||||
// {
|
||||
// float value = serie.data[i];
|
||||
// float dataHig = coordinateX + (value - minValue) / (maxValue - minValue) * coordinateWid;
|
||||
// Vector3 p = new Vector3(dataHig,startY + i * scaleWid);
|
||||
// float pointWid = m_Line.pointWidth;
|
||||
// if (m_Tooltip.show && i == m_Tooltip.dataIndex - 1)
|
||||
// {
|
||||
// pointWid = pointWid * 1.8f;
|
||||
// }
|
||||
// if (m_Theme == Theme.Dark)
|
||||
// {
|
||||
|
||||
// ChartHelper.DrawCricle(vh, p, pointWid, color,
|
||||
// (int)m_Line.pointWidth * 5);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ChartHelper.DrawCricle(vh, p, pointWid, Color.white);
|
||||
// ChartHelper.DrawDoughnut(vh, p, pointWid - m_Line.tickness,
|
||||
// pointWid, 0, 360, color);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//draw tooltip line
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user