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.

GridCoordHandler.cs 3.3KB

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