mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 16:00:24 +00:00
增加PieChart的Animation初始化动画配置支持
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -797,8 +797,10 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
foreach (var serie in m_Series)
|
foreach (var serie in m_Series)
|
||||||
{
|
{
|
||||||
if(serie.animation.enable)
|
if (serie.animation.enable)
|
||||||
|
{
|
||||||
serie.animation.Start();
|
serie.animation.Start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,5 +185,13 @@ namespace XCharts
|
|||||||
if (!enable || m_IsEnd) return dest;
|
if (!enable || m_IsEnd) return dest;
|
||||||
return m_CurrSymbolProgress;
|
return m_CurrSymbolProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float GetCurrDetail(){
|
||||||
|
return m_CurrDetailProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetCurrData(){
|
||||||
|
return m_CurrDataProgress;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,6 +55,10 @@ namespace XCharts
|
|||||||
public RectTransform labelRect { get; private set; }
|
public RectTransform labelRect { get; private set; }
|
||||||
public Image labelImage { get; private set; }
|
public Image labelImage { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 是否可以显示Label
|
||||||
|
/// </summary>
|
||||||
|
public bool canShowLabel { get; set; }
|
||||||
|
/// <summary>
|
||||||
/// the maxinum value.
|
/// the maxinum value.
|
||||||
/// 最大值。
|
/// 最大值。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -69,11 +69,14 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
var serie = m_Series.series[i];
|
var serie = m_Series.series[i];
|
||||||
serie.index = i;
|
serie.index = i;
|
||||||
|
var data = serie.data;
|
||||||
|
serie.animation.InitProgress(data.Count, 0, 360);
|
||||||
if (!serie.show)
|
if (!serie.show)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!serie.animation.NeedAnimation(i)) break;
|
||||||
|
bool isFinish = true;
|
||||||
if (serie.pieClickOffset) isClickOffset = true;
|
if (serie.pieClickOffset) isClickOffset = true;
|
||||||
PieTempData tempData;
|
PieTempData tempData;
|
||||||
if (i < m_PieTempDataList.Count)
|
if (i < m_PieTempDataList.Count)
|
||||||
@@ -90,18 +93,17 @@ namespace XCharts
|
|||||||
tempData.dataMax = serie.yMax;
|
tempData.dataMax = serie.yMax;
|
||||||
tempData.dataTotal = serie.yTotal;
|
tempData.dataTotal = serie.yTotal;
|
||||||
UpdatePieCenter(serie);
|
UpdatePieCenter(serie);
|
||||||
var data = serie.data;
|
|
||||||
|
|
||||||
float totalDegree = 360;
|
float totalDegree = 360;
|
||||||
float startDegree = 0;
|
float startDegree = 0;
|
||||||
int showdataCount = 0;
|
int showdataCount = 0;
|
||||||
if (serie.pieRoseType == RoseType.Area)
|
|
||||||
|
foreach (var sd in serie.data)
|
||||||
{
|
{
|
||||||
foreach (var sd in serie.data)
|
if (sd.show && serie.pieRoseType == RoseType.Area) showdataCount++;
|
||||||
{
|
sd.canShowLabel = false;
|
||||||
if (sd.show) showdataCount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int n = 0; n < data.Count; n++)
|
for (int n = 0; n < data.Count; n++)
|
||||||
{
|
{
|
||||||
var serieData = data[n];
|
var serieData = data[n];
|
||||||
@@ -151,6 +153,13 @@ namespace XCharts
|
|||||||
float currSin = Mathf.Sin(currRad);
|
float currSin = Mathf.Sin(currRad);
|
||||||
float currCos = Mathf.Cos(currRad);
|
float currCos = Mathf.Cos(currRad);
|
||||||
var center = tempData.center;
|
var center = tempData.center;
|
||||||
|
|
||||||
|
var currDegree = toDegree;
|
||||||
|
if (serie.animation.CheckDetailBreak(n, toDegree))
|
||||||
|
{
|
||||||
|
isFinish = false;
|
||||||
|
currDegree = serie.animation.GetCurrDetail();
|
||||||
|
}
|
||||||
if (offset > 0)
|
if (offset > 0)
|
||||||
{
|
{
|
||||||
float offsetRadius = serie.pieSpace / Mathf.Sin(halfDegree * Mathf.Deg2Rad);
|
float offsetRadius = serie.pieSpace / Mathf.Sin(halfDegree * Mathf.Deg2Rad);
|
||||||
@@ -167,17 +176,35 @@ namespace XCharts
|
|||||||
center.y + offsetRadius * currCos);
|
center.y + offsetRadius * currCos);
|
||||||
|
|
||||||
ChartHelper.DrawDoughnut(vh, offestCenter, insideRadius, outsideRadius,
|
ChartHelper.DrawDoughnut(vh, offestCenter, insideRadius, outsideRadius,
|
||||||
startDegree, toDegree, color);
|
startDegree, currDegree, color);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ChartHelper.DrawDoughnut(vh, center, tempData.insideRadius, outSideRadius,
|
ChartHelper.DrawDoughnut(vh, center, tempData.insideRadius, outSideRadius,
|
||||||
startDegree, toDegree, color);
|
startDegree, currDegree, color);
|
||||||
|
}
|
||||||
|
serieData.canShowLabel = currDegree >= currAngle;
|
||||||
|
if (currDegree >= currAngle)
|
||||||
|
{
|
||||||
|
DrawLabelLine(vh, serie, tempData, outSideRadius, center, currAngle, color);
|
||||||
}
|
}
|
||||||
DrawLabelLine(vh, serie, tempData, outSideRadius, center, currAngle, color);
|
|
||||||
isDrawPie = true;
|
isDrawPie = true;
|
||||||
tempData.angleList.Add(toDegree);
|
tempData.angleList.Add(toDegree);
|
||||||
startDegree = toDegree;
|
startDegree = toDegree;
|
||||||
|
if (isFinish) serie.animation.SetDataFinish(n);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!serie.animation.IsFinish())
|
||||||
|
{
|
||||||
|
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
|
||||||
|
float speed = 360 / duration;
|
||||||
|
float symbolSpeed = serie.symbol.size / duration;
|
||||||
|
serie.animation.CheckProgress(Time.deltaTime * speed);
|
||||||
|
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
|
||||||
|
RefreshChart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
raycastTarget = isClickOffset && isDataHighlight;
|
raycastTarget = isClickOffset && isDataHighlight;
|
||||||
@@ -241,6 +268,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PieTempData tempData;
|
PieTempData tempData;
|
||||||
if (i < m_PieTempDataList.Count)
|
if (i < m_PieTempDataList.Count)
|
||||||
{
|
{
|
||||||
@@ -271,6 +299,11 @@ namespace XCharts
|
|||||||
for (int n = 0; n < data.Count; n++)
|
for (int n = 0; n < data.Count; n++)
|
||||||
{
|
{
|
||||||
var serieData = data[n];
|
var serieData = data[n];
|
||||||
|
if (!serieData.canShowLabel)
|
||||||
|
{
|
||||||
|
serieData.SetLabelActive(false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
float value = serieData.data[1];
|
float value = serieData.data[1];
|
||||||
string dataName = serieData.name;
|
string dataName = serieData.name;
|
||||||
Color color;
|
Color color;
|
||||||
@@ -322,11 +355,11 @@ namespace XCharts
|
|||||||
if (insideRadius > 0) insideRadius += m_Pie.selectedOffset;
|
if (insideRadius > 0) insideRadius += m_Pie.selectedOffset;
|
||||||
outsideRadius += m_Pie.selectedOffset;
|
outsideRadius += m_Pie.selectedOffset;
|
||||||
}
|
}
|
||||||
DrawLabel(serie, serieData, tempData, color, currAngle, offsetRadius, insideRadius, outsideRadius);
|
DrawLabel(serie, n, serieData, tempData, color, currAngle, offsetRadius, insideRadius, outsideRadius);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DrawLabel(serie, serieData, tempData, color, currAngle, 0, tempData.insideRadius, outSideRadius);
|
DrawLabel(serie, n, serieData, tempData, color, currAngle, 0, tempData.insideRadius, outSideRadius);
|
||||||
}
|
}
|
||||||
tempData.angleList.Add(toDegree);
|
tempData.angleList.Add(toDegree);
|
||||||
startDegree = toDegree;
|
startDegree = toDegree;
|
||||||
@@ -334,12 +367,12 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawLabel(Serie serie, SerieData serieData, PieTempData tempData, Color serieColor,
|
private void DrawLabel(Serie serie, int dataIndex, SerieData serieData, PieTempData tempData, Color serieColor,
|
||||||
float currAngle, float offsetRadius, float insideRadius, float outsideRadius)
|
float currAngle, float offsetRadius, float insideRadius, float outsideRadius)
|
||||||
{
|
{
|
||||||
if (serieData.labelText == null) return;
|
if (serieData.labelText == null) return;
|
||||||
var isHighlight = (serieData.highlighted && serie.highlightLabel.show);
|
var isHighlight = (serieData.highlighted && serie.highlightLabel.show);
|
||||||
if (serie.label.show || isHighlight)
|
if ((serie.label.show || isHighlight) && serieData.canShowLabel)
|
||||||
{
|
{
|
||||||
serieData.SetLabelActive(true);
|
serieData.SetLabelActive(true);
|
||||||
float rotate = 0;
|
float rotate = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user