GridCoordHandler.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Text;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using XUGL;
  5. namespace XCharts.Runtime
  6. {
  7. [UnityEngine.Scripting.Preserve]
  8. internal sealed class GridCoordHandler : MainComponentHandler<GridCoord>
  9. {
  10. public override void InitComponent()
  11. {
  12. var grid = component;
  13. grid.painter = chart.painter;
  14. grid.refreshComponent = delegate()
  15. {
  16. grid.UpdateRuntimeData(chart);
  17. chart.OnCoordinateChanged();
  18. };
  19. grid.refreshComponent();
  20. }
  21. public override void CheckComponent(StringBuilder sb)
  22. {
  23. var grid = component;
  24. if (grid.left >= chart.chartWidth)
  25. sb.Append("warning:grid->left > chartWidth\n");
  26. if (grid.right >= chart.chartWidth)
  27. sb.Append("warning:grid->right > chartWidth\n");
  28. if (grid.top >= chart.chartHeight)
  29. sb.Append("warning:grid->top > chartHeight\n");
  30. if (grid.bottom >= chart.chartHeight)
  31. sb.Append("warning:grid->bottom > chartHeight\n");
  32. if (grid.left + grid.right >= chart.chartWidth)
  33. sb.Append("warning:grid.left + grid.right > chartWidth\n");
  34. if (grid.top + grid.bottom >= chart.chartHeight)
  35. sb.Append("warning:grid.top + grid.bottom > chartHeight\n");
  36. }
  37. public override void Update()
  38. {
  39. if (chart.isPointerInChart)
  40. {
  41. component.context.isPointerEnter = component.Contains(chart.pointerPos);
  42. }
  43. else
  44. {
  45. component.context.isPointerEnter = false;
  46. }
  47. }
  48. public override void DrawBase(VertexHelper vh)
  49. {
  50. if (!SeriesHelper.IsAnyClipSerie(chart.series))
  51. {
  52. DrawCoord(vh, component);
  53. }
  54. }
  55. public override void DrawUpper(VertexHelper vh)
  56. {
  57. if (SeriesHelper.IsAnyClipSerie(chart.series))
  58. {
  59. DrawCoord(vh, component);
  60. }
  61. }
  62. private void DrawCoord(VertexHelper vh, GridCoord grid)
  63. {
  64. if (!grid.show) return;
  65. if (!ChartHelper.IsClearColor(grid.backgroundColor))
  66. {
  67. var p1 = new Vector2(grid.context.x, grid.context.y);
  68. var p2 = new Vector2(grid.context.x, grid.context.y + grid.context.height);
  69. var p3 = new Vector2(grid.context.x + grid.context.width, grid.context.y + grid.context.height);
  70. var p4 = new Vector2(grid.context.x + grid.context.width, grid.context.y);
  71. UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, grid.backgroundColor);
  72. }
  73. if (grid.showBorder)
  74. {
  75. var borderWidth = grid.borderWidth == 0 ? chart.theme.axis.lineWidth * 2 : grid.borderWidth;
  76. var borderColor = ChartHelper.IsClearColor(grid.borderColor) ?
  77. chart.theme.axis.lineColor :
  78. grid.borderColor;
  79. UGL.DrawBorder(vh, grid.context.center, grid.context.width - borderWidth,
  80. grid.context.height - borderWidth, borderWidth, borderColor);
  81. }
  82. }
  83. }
  84. }