설명 없음
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.

ParallelCoord.cs 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using UnityEngine;
  3. namespace XCharts.Runtime
  4. {
  5. /// <summary>
  6. /// Grid component.
  7. /// |Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart can be drawn in grid.
  8. /// |网格组件。
  9. /// 直角坐标系内绘图网格。可以在网格上绘制折线图,柱状图,散点图。
  10. /// </summary>
  11. [Serializable]
  12. [ComponentHandler(typeof(ParallelCoordHandler), true)]
  13. public class ParallelCoord : CoordSystem, IUpdateRuntimeData, ISerieContainer
  14. {
  15. [SerializeField] private bool m_Show = true;
  16. [SerializeField] protected Orient m_Orient = Orient.Vertical;
  17. [SerializeField] private float m_Left = 0.1f;
  18. [SerializeField] private float m_Right = 0.08f;
  19. [SerializeField] private float m_Top = 0.22f;
  20. [SerializeField] private float m_Bottom = 0.12f;
  21. [SerializeField] private Color m_BackgroundColor;
  22. public ParallelCoordContext context = new ParallelCoordContext();
  23. /// <summary>
  24. /// Whether to show the grid in rectangular coordinate.
  25. /// |是否显示直角坐标系网格。
  26. /// </summary>
  27. public bool show
  28. {
  29. get { return m_Show; }
  30. set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
  31. }
  32. /// <summary>
  33. /// Orientation of the axis. By default, it's 'Vertical'. You can set it to be 'Horizonal' to make a vertical axis.
  34. /// |坐标轴朝向。默认为垂直朝向。
  35. /// </summary>
  36. public Orient orient
  37. {
  38. get { return m_Orient; }
  39. set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetAllDirty(); }
  40. }
  41. /// <summary>
  42. /// Distance between grid component and the left side of the container.
  43. /// |grid 组件离容器左侧的距离。
  44. /// </summary>
  45. public float left
  46. {
  47. get { return m_Left; }
  48. set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetAllDirty(); }
  49. }
  50. /// <summary>
  51. /// Distance between grid component and the right side of the container.
  52. /// |grid 组件离容器右侧的距离。
  53. /// </summary>
  54. public float right
  55. {
  56. get { return m_Right; }
  57. set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetAllDirty(); }
  58. }
  59. /// <summary>
  60. /// Distance between grid component and the top side of the container.
  61. /// |grid 组件离容器上侧的距离。
  62. /// </summary>
  63. public float top
  64. {
  65. get { return m_Top; }
  66. set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetAllDirty(); }
  67. }
  68. /// <summary>
  69. /// Distance between grid component and the bottom side of the container.
  70. /// |grid 组件离容器下侧的距离。
  71. /// </summary>
  72. public float bottom
  73. {
  74. get { return m_Bottom; }
  75. set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetAllDirty(); }
  76. }
  77. /// <summary>
  78. /// Background color of grid, which is transparent by default.
  79. /// |网格背景色,默认透明。
  80. /// </summary>
  81. public Color backgroundColor
  82. {
  83. get { return m_BackgroundColor; }
  84. set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
  85. }
  86. public bool IsPointerEnter()
  87. {
  88. return context.runtimeIsPointerEnter;
  89. }
  90. public void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)
  91. {
  92. context.left = left <= 1 ? left * chartWidth : left;
  93. context.bottom = bottom <= 1 ? bottom * chartHeight : bottom;
  94. context.top = top <= 1 ? top * chartHeight : top;
  95. context.right = right <= 1 ? right * chartWidth : right;
  96. context.x = chartX + context.left;
  97. context.y = chartY + context.bottom;
  98. context.width = chartWidth - context.left - context.right;
  99. context.height = chartHeight - context.top - context.bottom;
  100. context.position = new Vector3(context.x, context.y);
  101. }
  102. public bool Contains(Vector3 pos)
  103. {
  104. return Contains(pos.x, pos.y);
  105. }
  106. public bool Contains(float x, float y)
  107. {
  108. if (x < context.x - 1 || x > context.x + context.width + 1 ||
  109. y < context.y - 1 || y > context.y + context.height + 1)
  110. {
  111. return false;
  112. }
  113. return true;
  114. }
  115. }
  116. }