PolarCoord.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.44f };
  16. [SerializeField] private float[] m_Radius = new float[2] { 0, 0.31f };
  17. [SerializeField] private Color m_BackgroundColor;
  18. [SerializeField][Since("v3.8.0")] private float m_IndicatorLabelOffset = 30f;
  19. public PolarCoordContext context = new PolarCoordContext();
  20. /// <summary>
  21. /// Whether to show the polor component.
  22. /// ||是否显示极坐标。
  23. /// </summary>
  24. public bool show
  25. {
  26. get { return m_Show; }
  27. set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
  28. }
  29. /// <summary>
  30. /// The center of ploar. The center[0] is the x-coordinate, and the center[1] is the y-coordinate.
  31. /// When value between 0 and 1 represents a percentage relative to the chart.
  32. /// ||极坐标的中心点。数组的第一项是横坐标,第二项是纵坐标。
  33. /// 当值为0-1之间时表示百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度。
  34. /// </summary>
  35. public float[] center
  36. {
  37. get { return m_Center; }
  38. set { if (value != null) { m_Center = value; SetAllDirty(); } }
  39. }
  40. /// <summary>
  41. /// the radius of polar.
  42. /// ||半径。radius[0]表示内径,radius[1]表示外径。
  43. /// </summary>
  44. public float[] radius
  45. {
  46. get { return m_Radius; }
  47. set { if (value != null && value.Length == 2) { m_Radius = value; SetAllDirty(); } }
  48. }
  49. /// <summary>
  50. /// Background color of polar, which is transparent by default.
  51. /// ||极坐标的背景色,默认透明。
  52. /// </summary>
  53. public Color backgroundColor
  54. {
  55. get { return m_BackgroundColor; }
  56. set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
  57. }
  58. /// <summary>
  59. /// The offset of indicator label.
  60. /// ||指示器标签的偏移量。
  61. /// </summary>
  62. public float indicatorLabelOffset
  63. {
  64. get { return m_IndicatorLabelOffset; }
  65. set { if (PropertyUtil.SetStruct(ref m_IndicatorLabelOffset, value)) SetVerticesDirty(); }
  66. }
  67. public bool IsPointerEnter()
  68. {
  69. return context.isPointerEnter;
  70. }
  71. public bool Contains(Vector3 pos)
  72. {
  73. var dist = Vector3.Distance(pos, context.center);
  74. return dist >= context.insideRadius && dist <= context.outsideRadius;
  75. }
  76. }
  77. }