Files
XCharts/Runtime/Coord/Grid/GridCoordHandler.cs

90 lines
3.3 KiB
C#
Raw Normal View History

2021-11-23 13:20:07 +08:00
using System;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using XUGL;
2022-02-19 22:37:57 +08:00
namespace XCharts.Runtime
2021-11-23 13:20:07 +08:00
{
[UnityEngine.Scripting.Preserve]
internal sealed class GridCoordHandler : MainComponentHandler<GridCoord>
{
public override void InitComponent()
{
var grid = component;
grid.painter = chart.painter;
2022-05-22 22:17:38 +08:00
grid.refreshComponent = delegate()
2021-11-23 13:20:07 +08:00
{
grid.UpdateRuntimeData(chart.chartX, chart.chartY, chart.chartWidth, chart.chartHeight);
chart.OnCoordinateChanged();
};
grid.refreshComponent();
}
public override void CheckComponent(StringBuilder sb)
{
var grid = component;
if (grid.left >= chart.chartWidth)
sb.Append("warning:grid->left > chartWidth\n");
if (grid.right >= chart.chartWidth)
sb.Append("warning:grid->right > chartWidth\n");
if (grid.top >= chart.chartHeight)
sb.Append("warning:grid->top > chartHeight\n");
if (grid.bottom >= chart.chartHeight)
sb.Append("warning:grid->bottom > chartHeight\n");
if (grid.left + grid.right >= chart.chartWidth)
sb.Append("warning:grid.left + grid.right > chartWidth\n");
if (grid.top + grid.bottom >= chart.chartHeight)
sb.Append("warning:grid.top + grid.bottom > chartHeight\n");
}
public override void Update()
{
if (chart.isPointerInChart)
{
2021-12-19 20:53:55 +08:00
component.context.isPointerEnter = component.Contains(chart.pointerPos);
2021-11-23 13:20:07 +08:00
}
else
{
2021-12-19 20:53:55 +08:00
component.context.isPointerEnter = false;
2021-11-23 13:20:07 +08:00
}
}
public override void DrawBase(VertexHelper vh)
{
if (!SeriesHelper.IsAnyClipSerie(chart.series))
{
2022-02-25 08:10:09 +08:00
DrawCoord(vh, component);
2021-11-23 13:20:07 +08:00
}
}
public override void DrawUpper(VertexHelper vh)
2021-11-23 13:20:07 +08:00
{
if (SeriesHelper.IsAnyClipSerie(chart.series))
{
2022-02-25 08:10:09 +08:00
DrawCoord(vh, component);
2021-11-23 13:20:07 +08:00
}
}
2022-02-25 08:10:09 +08:00
private void DrawCoord(VertexHelper vh, GridCoord grid)
2021-11-23 13:20:07 +08:00
{
2022-02-25 08:10:09 +08:00
if (!grid.show) return;
if (!ChartHelper.IsClearColor(grid.backgroundColor))
2021-11-23 13:20:07 +08:00
{
var p1 = new Vector2(grid.context.x, grid.context.y);
var p2 = new Vector2(grid.context.x, grid.context.y + grid.context.height);
var p3 = new Vector2(grid.context.x + grid.context.width, grid.context.y + grid.context.height);
var p4 = new Vector2(grid.context.x + grid.context.width, grid.context.y);
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, grid.backgroundColor);
}
2022-02-25 08:10:09 +08:00
if (grid.showBorder)
{
var borderWidth = grid.borderWidth == 0 ? chart.theme.axis.lineWidth * 2 : grid.borderWidth;
2022-05-22 22:17:38 +08:00
var borderColor = ChartHelper.IsClearColor(grid.borderColor) ?
chart.theme.axis.lineColor :
grid.borderColor;
2022-02-25 08:10:09 +08:00
UGL.DrawBorder(vh, grid.context.center, grid.context.width - borderWidth,
grid.context.height - borderWidth, borderWidth, borderColor);
}
2021-11-23 13:20:07 +08:00
}
}
}