增加RadarCoordstartAngle可设置Radar起始角度

This commit is contained in:
monitor1394
2022-10-26 08:04:44 +08:00
parent 42a77a9439
commit ce4e88c51c
7 changed files with 34 additions and 14 deletions

View File

@@ -108,6 +108,7 @@ namespace XCharts.Runtime
[SerializeField] private Color32 m_OutRangeColor = Color.red;
[SerializeField] private bool m_ConnectCenter = false;
[SerializeField] private bool m_LineGradient = true;
[SerializeField][Since("v3.4.0")] private float m_StartAngle;
[SerializeField] private List<Indicator> m_IndicatorList = new List<Indicator>();
public RadarCoordContext context = new RadarCoordContext();
@@ -264,6 +265,14 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_LineGradient, value)) SetAllDirty(); }
}
/// <summary>
/// 起始角度。和时钟一样12点钟位置是0度顺时针到360度。
/// </summary>
public float startAngle
{
get { return m_StartAngle; }
set { if (PropertyUtil.SetStruct(ref m_StartAngle, value)) SetVerticesDirty(); }
}
/// <summary>
/// the indicator list.
/// |指示器列表。
/// </summary>

View File

@@ -124,7 +124,8 @@ namespace XCharts.Runtime
int indicatorNum = radar.indicatorList.Count;
Vector3 p1, p2, p3, p4;
Vector3 p = radar.context.center;
float angle = 2 * Mathf.PI / indicatorNum;
var startAngle = radar.startAngle * Mathf.PI / 180;
var angle = 2 * Mathf.PI / indicatorNum;
var lineColor = radar.axisLine.GetColor(chart.theme.axis.splitLineColor);
var lineWidth = radar.axisLine.GetWidth(chart.theme.axis.lineWidth);
var lineType = radar.axisLine.GetType(chart.theme.axis.lineType);
@@ -135,11 +136,11 @@ namespace XCharts.Runtime
{
var color = radar.splitArea.GetColor(i, chart.theme.axis);
outsideRadius = insideRadius + block;
p1 = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0));
p2 = new Vector3(p.x + outsideRadius * Mathf.Sin(0), p.y + outsideRadius * Mathf.Cos(0));
p1 = new Vector3(p.x + insideRadius * Mathf.Sin(startAngle), p.y + insideRadius * Mathf.Cos(startAngle));
p2 = new Vector3(p.x + outsideRadius * Mathf.Sin(startAngle), p.y + outsideRadius * Mathf.Cos(startAngle));
for (int j = 0; j <= indicatorNum; j++)
{
float currAngle = j * angle;
float currAngle = startAngle + j * angle;
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
p.y + outsideRadius * Mathf.Cos(currAngle));
p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle),
@@ -161,7 +162,7 @@ namespace XCharts.Runtime
{
for (int j = 0; j <= indicatorNum; j++)
{
float currAngle = j * angle;
float currAngle = startAngle + j * angle;
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
p.y + outsideRadius * Mathf.Cos(currAngle));
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, p, p3, lineColor);

View File

@@ -224,6 +224,7 @@ namespace XCharts.Runtime
var unscaledTime = serie.animation.unscaledTime;
SerieHelper.GetAllMinMaxData(serie, m_RadarCoord.ceilRate);
Color32 areaColor, areaToColor;
var startAngle = m_RadarCoord.startAngle * Mathf.PI / 180;
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
@@ -264,7 +265,7 @@ namespace XCharts.Runtime
}
}
var radius = (float) (m_RadarCoord.context.dataRadius * (value - min) / (max - min));
var currAngle = (n + (m_RadarCoord.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle;
var currAngle = startAngle + (n + (m_RadarCoord.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle;
radius *= rate;
if (n == 0)
{
@@ -365,6 +366,7 @@ namespace XCharts.Runtime
var unscaledTime = serie.animation.unscaledTime;
var startIndex = GetStartShowIndex(serie);
var endIndex = GetEndShowIndex(serie);
var startAngle = m_RadarCoord.startAngle * Mathf.PI / 180;
SerieHelper.UpdateMinMaxData(serie, 1, m_RadarCoord.ceilRate);
for (int j = 0; j < serie.data.Count; j++)
{
@@ -397,7 +399,7 @@ namespace XCharts.Runtime
}
var radius = (float) (max < 0 ? m_RadarCoord.context.dataRadius - m_RadarCoord.context.dataRadius * value / max :
m_RadarCoord.context.dataRadius * value / max);
var currAngle = (index + (m_RadarCoord.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle;
var currAngle = startAngle + (index + (m_RadarCoord.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle;
radius *= rate;
if (index == startIndex)
{