123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using UnityEngine;
- using UnityEngine.UI;
-
- namespace XCharts.Runtime
- {
- [UnityEngine.Scripting.Preserve]
- internal sealed class SingleAxisHander : AxisHandler<SingleAxis>
- {
- protected override Orient orient { get { return component.orient; } }
-
- public override void InitComponent()
- {
- InitXAxis(component);
- }
-
- public override void Update()
- {
- UpdateAxisMinMaxValue(component.index, component);
- UpdatePointerValue(component);
- }
-
- public override void DrawBase(VertexHelper vh)
- {
- DrawSingleAxisSplit(vh, component);
- DrawSingleAxisLine(vh, component);
- DrawSingleAxisTick(vh, component);
- }
-
- private void InitXAxis(SingleAxis axis)
- {
- var theme = chart.theme;
- var xAxisIndex = axis.index;
- axis.painter = chart.painter;
- axis.refreshComponent = delegate()
- {
- axis.UpdateRuntimeData(chart.chartX,
- chart.chartY,
- chart.chartWidth,
- chart.chartHeight);
-
- InitAxis(null,
- axis.orient,
- axis.context.x,
- axis.context.y,
- axis.context.width,
- axis.context.height);
- };
- axis.refreshComponent();
- }
-
- internal override void UpdateAxisLabelText(Axis axis)
- {
- base.UpdateAxisLabelText(axis);
- if (axis.IsTime() || axis.IsValue())
- {
- for (int i = 0; i < axis.context.labelObjectList.Count; i++)
- {
- var label = axis.context.labelObjectList[i];
- if (label != null)
- {
- var pos = GetLabelPosition(0, i);
- label.SetPosition(pos);
- CheckValueLabelActive(component, i, label, pos);
- }
- }
- }
- }
-
- protected override Vector3 GetLabelPosition(float scaleWid, int i)
- {
- return GetLabelPosition(i, component.orient, component, null,
- chart.theme.axis,
- scaleWid,
- component.context.x,
- component.context.y,
- component.context.width,
- component.context.height);
- }
-
- private void DrawSingleAxisSplit(VertexHelper vh, SingleAxis axis)
- {
- if (AxisHelper.NeedShowSplit(axis))
- {
- var dataZoom = chart.GetDataZoomOfAxis(axis);
- DrawAxisSplit(vh, chart.theme.axis, dataZoom,
- axis.orient,
- axis.context.x,
- axis.context.y,
- axis.context.width,
- axis.context.height);
- }
- }
-
- private void DrawSingleAxisTick(VertexHelper vh, SingleAxis axis)
- {
- if (AxisHelper.NeedShowSplit(axis))
- {
- var dataZoom = chart.GetDataZoomOfAxis(axis);
- DrawAxisTick(vh, axis, chart.theme.axis, dataZoom,
- axis.orient,
- axis.context.x,
- axis.context.y,
- axis.context.width);
- }
- }
-
- private void DrawSingleAxisLine(VertexHelper vh, SingleAxis axis)
- {
- if (axis.show && axis.axisLine.show)
- {
- DrawAxisLine(vh, axis,
- chart.theme.axis,
- axis.orient,
- axis.context.x,
- GetAxisLineXOrY(),
- axis.context.width);
- }
- }
-
- internal override float GetAxisLineXOrY()
- {
- return component.context.y + component.offset;
- }
- }
- }
|