No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PolarCoord.cs 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using UnityEngine;
  3. namespace XCharts.Runtime
  4. {
  5. /// <summary>
  6. /// Polar coordinate can be used in scatter and line chart. Every polar coordinate has an angleAxis and a radiusAxis.
  7. /// |极坐标系组件。
  8. /// 极坐标系,可以用于散点图和折线图。每个极坐标系拥有一个角度轴和一个半径轴。
  9. /// </summary>
  10. [Serializable]
  11. [ComponentHandler(typeof(PolarCoordHandler), true)]
  12. public class PolarCoord : CoordSystem, ISerieContainer
  13. {
  14. [SerializeField] private bool m_Show = true;
  15. [SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.45f };
  16. [SerializeField] private float[] m_Radius = new float[2] { 0, 0.35f };
  17. [SerializeField] private Color m_BackgroundColor;
  18. public PolarCoordContext context = new PolarCoordContext();
  19. /// <summary>
  20. /// Whether to show the polor component.
  21. /// |是否显示极坐标。
  22. /// </summary>
  23. public bool show
  24. {
  25. get { return m_Show; }
  26. set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
  27. }
  28. /// <summary>
  29. /// The center of ploar. The center[0] is the x-coordinate, and the center[1] is the y-coordinate.
  30. /// When value between 0 and 1 represents a percentage relative to the chart.
  31. /// |极坐标的中心点。数组的第一项是横坐标,第二项是纵坐标。
  32. /// 当值为0-1之间时表示百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度。
  33. /// </summary>
  34. public float[] center
  35. {
  36. get { return m_Center; }
  37. set { if (value != null) { m_Center = value; SetAllDirty(); } }
  38. }
  39. /// <summary>
  40. /// the radius of polar.
  41. /// |半径。radius[0]表示内径,radius[1]表示外径。
  42. /// </summary>
  43. public float[] radius
  44. {
  45. get { return m_Radius; }
  46. set { if (value != null && value.Length == 2) { m_Radius = value; SetAllDirty(); } }
  47. }
  48. /// <summary>
  49. /// Background color of polar, which is transparent by default.
  50. /// |极坐标的背景色,默认透明。
  51. /// </summary>
  52. public Color backgroundColor
  53. {
  54. get { return m_BackgroundColor; }
  55. set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
  56. }
  57. public bool IsPointerEnter()
  58. {
  59. return context.isPointerEnter;
  60. }
  61. public bool Contains(Vector3 pos)
  62. {
  63. var dist = Vector3.Distance(pos, context.center);
  64. return dist >= context.insideRadius && dist <= context.outsideRadius;
  65. }
  66. }
  67. }