mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-20 07:20:08 +00:00
增加SmoothDash平滑虚线的支持
This commit is contained in:
@@ -73,11 +73,16 @@ namespace XCharts
|
||||
/// </summary>
|
||||
Normal,
|
||||
/// <summary>
|
||||
/// the normal line chart,
|
||||
/// the smooth line chart,
|
||||
/// 平滑曲线。
|
||||
/// </summary>
|
||||
Smooth,
|
||||
/// <summary>
|
||||
/// the smooth-dash line chart,
|
||||
/// 平滑虚线。
|
||||
/// </summary>
|
||||
SmoothDash,
|
||||
/// <summary>
|
||||
/// step line.
|
||||
/// 阶梯线图:当前点。
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -131,6 +130,29 @@ namespace XCharts
|
||||
float currDetailProgress = lp.x;
|
||||
float totalDetailProgress = serie.dataPoints[dataCount - 1].x;
|
||||
serie.animation.InitProgress(dataCount, currDetailProgress, totalDetailProgress);
|
||||
|
||||
Vector3 firstLastPos = Vector3.zero, lastNextPos = Vector3.zero;
|
||||
if (serie.minShow > 0 && serie.minShow < showData.Count)
|
||||
{
|
||||
i = serie.minShow - 1;
|
||||
float yValue = showData[i].data[1];
|
||||
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref firstLastPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
firstLastPos = lp;
|
||||
}
|
||||
if (serie.maxShow > 0 && serie.maxShow < showData.Count)
|
||||
{
|
||||
i = serie.maxShow;
|
||||
float yValue = showData[i].data[1];
|
||||
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref lastNextPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
lastNextPos = serie.dataPoints[serie.dataPoints.Count - 1];
|
||||
}
|
||||
|
||||
for (i = 1; i < serie.dataPoints.Count; i++)
|
||||
{
|
||||
np = serie.dataPoints[i];
|
||||
@@ -145,8 +167,9 @@ namespace XCharts
|
||||
areaColor, areaToColor, zeroPos);
|
||||
break;
|
||||
case LineType.Smooth:
|
||||
llp = i > 1 ? serie.dataPoints[i - 2] : lp;
|
||||
nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : np;
|
||||
case LineType.SmoothDash:
|
||||
llp = i > 1 ? serie.dataPoints[i - 2] : firstLastPos;
|
||||
nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : lastNextPos;
|
||||
isFinish = DrawSmoothLine(vh, serieIndex, serie, xAxis, lp, np, llp, nnp, i,
|
||||
lineColor, areaColor, areaToColor, isStack, zeroPos);
|
||||
break;
|
||||
@@ -401,6 +424,7 @@ namespace XCharts
|
||||
areaColor, areaToColor, zeroPos);
|
||||
break;
|
||||
case LineType.Smooth:
|
||||
case LineType.SmoothDash:
|
||||
llp = i > 1 ? serie.dataPoints[i - 2] : lp;
|
||||
nnp = i < serie.dataPoints.Count - 1 ? serie.dataPoints[i + 1] : np;
|
||||
isFinish = DrawSmoothLine(vh, serieIndex, serie, yAxis, lp, np, llp, nnp, i,
|
||||
@@ -844,6 +868,16 @@ namespace XCharts
|
||||
else ChartHelper.GetBezierList(ref bezierPoints, vh, lp, np, llp, nnp, fine, lineSmoothStyle);
|
||||
|
||||
Vector3 start, to;
|
||||
if (serie.lineType == LineType.SmoothDash)
|
||||
{
|
||||
for (int i = 0; i < bezierPoints.Count - 2; i += 2)
|
||||
{
|
||||
start = bezierPoints[i];
|
||||
to = bezierPoints[i + 1];
|
||||
ChartHelper.DrawLine(vh, start, to, lineWidth, lineColor);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
start = bezierPoints[0];
|
||||
|
||||
var dir = bezierPoints[1] - start;
|
||||
|
||||
@@ -522,7 +522,8 @@ namespace XCharts
|
||||
}
|
||||
if (nep == ep) cp2 = ep;
|
||||
else cp2 = ep - (nep - sp).normalized * diff;
|
||||
int segment = (int)(dist / (fine ? 3f : 7f));
|
||||
dist = Vector3.Distance(sp, ep);
|
||||
int segment = (int)(dist / (fine ? 2f : 6f));
|
||||
if (segment < 1) segment = (int)(dist / 0.5f);
|
||||
if (segment < 4) segment = 4;
|
||||
GetBezierList2(ref posList, sp, ep, segment, cp1, cp2);
|
||||
|
||||
Reference in New Issue
Block a user