Files
XCharts/Runtime/Coord/Polar/PolarCoord.cs

72 lines
2.7 KiB
C#
Raw Normal View History

2020-07-01 09:38:00 +08:00
using System;
using UnityEngine;
2022-02-19 22:37:57 +08:00
namespace XCharts.Runtime
2020-07-01 09:38:00 +08:00
{
/// <summary>
/// Polar coordinate can be used in scatter and line chart. Every polar coordinate has an angleAxis and a radiusAxis.
2022-03-24 08:37:06 +08:00
/// |极坐标系组件。
2020-07-01 09:38:00 +08:00
/// 极坐标系,可以用于散点图和折线图。每个极坐标系拥有一个角度轴和一个半径轴。
/// </summary>
[Serializable]
2021-11-23 13:20:07 +08:00
[ComponentHandler(typeof(PolarCoordHandler), true)]
2022-01-26 20:47:14 +08:00
public class PolarCoord : CoordSystem, ISerieContainer
2020-07-01 09:38:00 +08:00
{
[SerializeField] private bool m_Show = true;
2021-11-23 13:20:07 +08:00
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.45f };
[SerializeField] private float[] m_Radius = new float[2] { 0, 0.35f };
2020-07-01 09:38:00 +08:00
[SerializeField] private Color m_BackgroundColor;
2021-11-23 13:20:07 +08:00
public PolarCoordContext context = new PolarCoordContext();
2020-07-01 09:38:00 +08:00
/// <summary>
2020-07-10 09:13:26 +08:00
/// Whether to show the polor component.
2022-03-24 08:37:06 +08:00
/// |是否显示极坐标。
2020-07-01 09:38:00 +08:00
/// </summary>
public bool show
{
get { return m_Show; }
2021-01-11 08:54:28 +08:00
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
2020-07-01 09:38:00 +08:00
}
/// <summary>
2022-03-31 21:54:34 +08:00
/// The center of ploar. The center[0] is the x-coordinate, and the center[1] is the y-coordinate.
/// When value between 0 and 1 represents a percentage relative to the chart.
2022-03-24 08:37:06 +08:00
/// |极坐标的中心点。数组的第一项是横坐标,第二项是纵坐标。
2020-07-01 09:38:00 +08:00
/// 当值为0-1之间时表示百分比设置成百分比时第一项是相对于容器宽度第二项是相对于容器高度。
/// </summary>
public float[] center
{
get { return m_Center; }
set { if (value != null) { m_Center = value; SetAllDirty(); } }
}
/// <summary>
2022-03-31 21:54:34 +08:00
/// the radius of polar.
/// |半径。radius[0]表示内径radius[1]表示外径。
2020-07-01 09:38:00 +08:00
/// </summary>
public float[] radius
2020-07-01 09:38:00 +08:00
{
get { return m_Radius; }
set { if (value != null && value.Length == 2) { m_Radius = value; SetAllDirty(); } }
2020-07-01 09:38:00 +08:00
}
/// <summary>
2022-03-31 21:54:34 +08:00
/// Background color of polar, which is transparent by default.
2022-03-24 08:37:06 +08:00
/// |极坐标的背景色,默认透明。
2020-07-01 09:38:00 +08:00
/// </summary>
public Color backgroundColor
{
get { return m_BackgroundColor; }
2021-01-11 08:54:28 +08:00
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
2020-07-01 09:38:00 +08:00
}
2020-07-10 09:13:26 +08:00
2022-01-26 20:47:14 +08:00
public bool IsPointerEnter()
{
return context.isPointerEnter;
}
public bool Contains(Vector3 pos)
{
var dist = Vector3.Distance(pos, context.center);
return dist >= context.insideRadius && dist <= context.outsideRadius;
2022-01-26 20:47:14 +08:00
}
2020-07-01 09:38:00 +08:00
}
}