3.0 - unitypackage

This commit is contained in:
monitor1394
2022-01-05 21:40:48 +08:00
parent c160867765
commit 228a4b2840
846 changed files with 105 additions and 467693 deletions

View File

@@ -0,0 +1,146 @@
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Single axis.
/// 单轴。
/// </summary>
[System.Serializable]
[ComponentHandler(typeof(SingleAxisHander), true)]
public class SingleAxis : Axis, IUpdateRuntimeData
{
[SerializeField] protected Orient m_Orient = Orient.Horizonal;
[SerializeField] private float m_Left = 0.1f;
[SerializeField] private float m_Right = 0.1f;
[SerializeField] private float m_Top = 0f;
[SerializeField] private float m_Bottom = 0.2f;
[SerializeField] private float m_Width = 0;
[SerializeField] private float m_Height = 50;
/// <summary>
/// Orientation of the axis. By default, it's 'Horizontal'. You can set it to be 'Vertical' to make a vertical axis.
/// 坐标轴朝向。默认为水平朝向。
/// </summary>
public Orient orient
{
get { return m_Orient; }
set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 组件离容器左侧的距离。
/// </summary>
public float left
{
get { return m_Left; }
set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between component and the right side of the container.
/// 组件离容器右侧的距离。
/// </summary>
public float right
{
get { return m_Right; }
set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between component and the top side of the container.
/// 组件离容器上侧的距离。
/// </summary>
public float top
{
get { return m_Top; }
set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between component and the bottom side of the container.
/// 组件离容器下侧的距离。
/// </summary>
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetAllDirty(); }
}
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetAllDirty(); }
}
public float height
{
get { return m_Height; }
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetAllDirty(); }
}
public void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)
{
context.left = left <= 1 ? left * chartWidth : left;
context.bottom = bottom <= 1 ? bottom * chartHeight : bottom;
context.top = top <= 1 ? top * chartHeight : top;
context.right = right <= 1 ? right * chartWidth : right;
context.height = height <= 1 ? height * chartHeight : height;
if (m_Orient == Orient.Horizonal)
{
context.width = width == 0
? chartWidth - context.left - context.right
: (width <= 1 ? chartWidth * width : width);
}
else
{
context.width = width == 0
? chartHeight - context.top - context.bottom
: (width <= 1 ? chartHeight * width : width);
}
if (context.left != 0 && context.right == 0)
context.x = chartX + context.left;
else if (context.left == 0 && context.right != 0)
context.x = chartX + chartWidth - context.right - context.width;
else
context.x = chartX + context.left;
if (context.bottom != 0 && context.top == 0)
context.y = chartY + context.bottom;
else if (context.bottom == 0 && context.top != 0)
context.y = chartY + chartHeight - context.top - context.height;
else
context.y = chartY + context.bottom;
context.position = new Vector3(context.x, context.y);
}
public override void SetDefaultValue()
{
m_Show = true;
m_Type = AxisType.Category;
m_Min = 0;
m_Max = 0;
m_SplitNumber = 0;
m_BoundaryGap = true;
m_Position = AxisPosition.Bottom;
m_Offset = 0;
m_Left = 0.1f;
m_Right = 0.1f;
m_Top = 0;
m_Bottom = 0.2f;
m_Width = 0;
m_Height = 50;
m_Data = new List<string>() { "x1", "x2", "x3", "x4", "x5" };
m_Icons = new List<Sprite>(5);
splitLine.show = false;
splitLine.lineStyle.type = LineStyle.Type.None;
axisLabel.textLimit.enable = true;
axisTick.showStartTick = true;
axisTick.showEndTick = true;
iconStyle.show = false;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aeb871d6555744e609bd651306c601a8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,122 @@
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
[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(axis, null, chart, this,
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, axis, 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)
{
var axisStartY = axis.context.y + axis.offset;
DrawAxisLine(vh, axis,
chart.theme.axis,
axis.orient,
axis.context.x,
axisStartY,
axis.context.width);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 50b3514e3079543ea9000d21d809cad3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: