Files
XCharts/Runtime/Serie/SerieDataContext.cs

150 lines
5.0 KiB
C#
Raw Normal View History

2021-12-19 20:53:55 +08:00
using System.Collections.Generic;
2021-11-23 13:20:07 +08:00
using UnityEngine;
using UnityEngine.UI;
2022-02-19 22:37:57 +08:00
namespace XCharts.Runtime
2021-01-11 08:54:28 +08:00
{
2021-12-08 08:31:32 +08:00
public class SerieDataContext
{
2022-03-31 21:54:34 +08:00
public Vector3 labelPosition;
2022-09-08 08:00:13 +08:00
public Vector3 labelLinePosition;
public Vector3 labelLinePosition2;
2021-12-09 07:12:15 +08:00
/// <summary>
/// 开始角度
/// </summary>
2022-03-31 21:54:34 +08:00
public float startAngle;
2021-12-09 07:12:15 +08:00
/// <summary>
/// 结束角度
/// </summary>
2022-03-31 21:54:34 +08:00
public float toAngle;
2021-12-09 07:12:15 +08:00
/// <summary>
/// 一半时的角度
/// </summary>
2022-03-31 21:54:34 +08:00
public float halfAngle;
2021-12-09 07:12:15 +08:00
/// <summary>
/// 当前角度
/// </summary>
2022-03-31 21:54:34 +08:00
public float currentAngle;
2021-12-09 07:12:15 +08:00
/// <summary>
/// 饼图数据项的内半径
/// </summary>
2022-03-31 21:54:34 +08:00
public float insideRadius;
2021-12-09 07:12:15 +08:00
/// <summary>
/// 饼图数据项的偏移半径
/// </summary>
2022-03-31 21:54:34 +08:00
public float offsetRadius;
public float outsideRadius;
public Vector3 position;
/// <summary>
/// is the exchange animation end.
/// ||交换动画是否结束。
/// </summary>
public bool exchangeEnd;
/// <summary>
/// the current position of the exchange animation.
/// ||交换动画的当前位置。
/// </summary>
public Vector3 exchangePosition;
private float exchangeStartTime;
private Vector3 exchangeStartPosition;
private Vector3 exchangeEndPosition;
2021-12-19 20:53:55 +08:00
public List<Vector3> dataPoints = new List<Vector3>();
2022-05-31 08:17:54 +08:00
public List<ChartLabel> dataLabels = new List<ChartLabel>();
2022-03-04 22:17:32 +08:00
public List<SerieData> children = new List<SerieData>();
2021-12-09 07:12:15 +08:00
/// <summary>
/// 绘制区域。
/// </summary>
2022-03-31 21:54:34 +08:00
public Rect rect;
public Rect backgroundRect;
2022-03-31 21:54:34 +08:00
public Rect subRect;
public int level;
public SerieData parent;
public Color32 color;
public double area;
public float angle;
public Vector3 offsetCenter;
2022-05-04 08:45:19 +08:00
public Vector3 areaCenter;
2022-03-31 21:54:34 +08:00
public float stackHeight;
public bool isClip;
2021-12-31 13:00:17 +08:00
public bool canShowLabel = true;
2022-03-31 21:54:34 +08:00
public Image symbol;
2021-12-09 07:12:15 +08:00
/// <summary>
/// Whether the data item is highlighted.
2023-11-11 23:32:24 +08:00
/// ||该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
2021-12-09 07:12:15 +08:00
/// </summary>
public bool highlight;
2022-05-04 08:45:19 +08:00
public bool selected;
/// <summary>
/// the id of the node in the graph.
/// ||图中节点的id。
/// </summary>
public string graphNodeId;
2023-12-09 23:22:00 +08:00
public double inTotalValue;
public double outTotalValue;
public void Reset()
{
canShowLabel = true;
highlight = false;
parent = null;
symbol = null;
rect = Rect.zero;
subRect = Rect.zero;
exchangeEnd = true;
exchangeStartPosition = Vector3.zero;
exchangePosition = Vector3.zero;
exchangeEndPosition = Vector3.zero;
children.Clear();
dataPoints.Clear();
2022-05-31 08:17:54 +08:00
dataLabels.Clear();
}
public void UpdateExchangePosition(ref float x, ref float y, float totalTime)
{
if (exchangeEndPosition.x != x || exchangeEndPosition.y != y)
{
if (exchangeStartPosition == Vector3.zero || Time.time - exchangeStartTime < 0.1f)
{
exchangeEnd = true;
exchangeStartTime = Time.time;
exchangeEndPosition.x = x;
exchangeEndPosition.y = y;
exchangeStartPosition = exchangeEndPosition;
exchangePosition = exchangeEndPosition;
return;
}
else
{
exchangeEnd = false;
exchangeStartTime = Time.time;
exchangeStartPosition = exchangePosition;
exchangeEndPosition.x = x;
exchangeEndPosition.y = y;
}
}
if (exchangeStartPosition == exchangeEndPosition)
{
exchangeEnd = true;
exchangePosition = exchangeEndPosition;
x = exchangePosition.x;
y = exchangePosition.y;
return;
}
var spendTime = Time.time - exchangeStartTime;
totalTime /= 1000;
if (spendTime >= totalTime)
{
exchangeEnd = true;
exchangeStartPosition = exchangeEndPosition;
exchangePosition = exchangeEndPosition;
x = exchangePosition.x;
y = exchangePosition.y;
return;
}
exchangePosition = Vector3.Lerp(exchangeStartPosition, exchangeEndPosition, spendTime / totalTime);
x = exchangePosition.x;
y = exchangePosition.y;
return;
}
2021-12-08 08:31:32 +08:00
}
2021-01-11 08:54:28 +08:00
}