mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 23:10:06 +00:00
3.0 - unitypackage
This commit is contained in:
32
Runtime/Component/Axis/ParallelAxis/ParallelAxis.cs
Normal file
32
Runtime/Component/Axis/ParallelAxis/ParallelAxis.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
[RequireChartComponent(typeof(ParallelCoord))]
|
||||
[ComponentHandler(typeof(ParallelAxisHander), true)]
|
||||
public class ParallelAxis : Axis
|
||||
{
|
||||
public override void SetDefaultValue()
|
||||
{
|
||||
m_Show = true;
|
||||
m_Type = AxisType.Value;
|
||||
m_Min = 0;
|
||||
m_Max = 0;
|
||||
m_SplitNumber = 0;
|
||||
m_BoundaryGap = true;
|
||||
m_Position = AxisPosition.Bottom;
|
||||
m_Offset = 0;
|
||||
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;
|
||||
iconStyle.show = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Axis/ParallelAxis/ParallelAxis.cs.meta
Normal file
11
Runtime/Component/Axis/ParallelAxis/ParallelAxis.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7bc01c54f4d6485389fd57c37810c74
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
163
Runtime/Component/Axis/ParallelAxis/ParallelAxisHander.cs
Normal file
163
Runtime/Component/Axis/ParallelAxis/ParallelAxisHander.cs
Normal file
@@ -0,0 +1,163 @@
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class ParallelAxisHander : AxisHandler<ParallelAxis>
|
||||
{
|
||||
private Orient m_Orient;
|
||||
private ParallelCoord m_Parallel;
|
||||
|
||||
protected override Orient orient { get { return m_Orient; } }
|
||||
|
||||
public override void InitComponent()
|
||||
{
|
||||
InitParallelAxis(component);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
UpdateContext(component);
|
||||
}
|
||||
|
||||
public override void DrawBase(VertexHelper vh)
|
||||
{
|
||||
UpdateContext(component);
|
||||
DrawParallelAxisSplit(vh, component);
|
||||
DrawParallelAxisLine(vh, component);
|
||||
DrawParallelAxisTick(vh, component);
|
||||
}
|
||||
|
||||
private void UpdateContext(ParallelAxis axis)
|
||||
{
|
||||
var parallel = chart.GetChartComponent<ParallelCoord>(axis.parallelIndex);
|
||||
if (parallel == null)
|
||||
return;
|
||||
|
||||
m_Orient = parallel.orient;
|
||||
m_Parallel = parallel;
|
||||
var axisCount = chart.GetChartComponentNum<ParallelAxis>();
|
||||
|
||||
if (m_Orient == Orient.Horizonal)
|
||||
{
|
||||
var each = axisCount > 1 ? parallel.context.height / (axisCount - 1) : 0;
|
||||
axis.context.x = parallel.context.x;
|
||||
axis.context.y = parallel.context.y + (axis.index) * each;
|
||||
axis.context.width = parallel.context.width;
|
||||
}
|
||||
else
|
||||
{
|
||||
var each = axisCount > 1 ? parallel.context.width / (axisCount - 1) : 0;
|
||||
axis.context.x = parallel.context.x + (axis.index) * each;
|
||||
axis.context.y = parallel.context.y;
|
||||
axis.context.width = parallel.context.height;
|
||||
}
|
||||
axis.context.orient = m_Orient;
|
||||
axis.context.height = 0;
|
||||
axis.context.position = new Vector3(axis.context.x, axis.context.y);
|
||||
}
|
||||
|
||||
private void InitParallelAxis(ParallelAxis axis)
|
||||
{
|
||||
var theme = chart.theme;
|
||||
var xAxisIndex = axis.index;
|
||||
axis.painter = chart.painter;
|
||||
axis.refreshComponent = delegate ()
|
||||
{
|
||||
UpdateContext(axis);
|
||||
InitAxis(axis, null, chart, this,
|
||||
m_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)
|
||||
{
|
||||
if (m_Parallel == null)
|
||||
return Vector3.zero;
|
||||
|
||||
return GetLabelPosition(i, m_Orient, component, null,
|
||||
chart.theme.axis,
|
||||
scaleWid,
|
||||
component.context.x,
|
||||
component.context.y,
|
||||
component.context.width,
|
||||
component.context.height);
|
||||
}
|
||||
|
||||
private void DrawParallelAxisSplit(VertexHelper vh, ParallelAxis axis)
|
||||
{
|
||||
if (AxisHelper.NeedShowSplit(axis))
|
||||
{
|
||||
if (m_Parallel == null)
|
||||
return;
|
||||
|
||||
var dataZoom = chart.GetDataZoomOfAxis(axis);
|
||||
|
||||
DrawAxisSplit(vh, axis, chart.theme.axis, dataZoom,
|
||||
m_Orient,
|
||||
axis.context.x,
|
||||
axis.context.y,
|
||||
axis.context.width,
|
||||
axis.context.height);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawParallelAxisTick(VertexHelper vh, ParallelAxis axis)
|
||||
{
|
||||
if (AxisHelper.NeedShowSplit(axis))
|
||||
{
|
||||
if (m_Parallel == null)
|
||||
return;
|
||||
|
||||
var dataZoom = chart.GetDataZoomOfAxis(axis);
|
||||
|
||||
DrawAxisTick(vh, axis, chart.theme.axis, dataZoom,
|
||||
m_Orient,
|
||||
axis.context.x,
|
||||
axis.context.y,
|
||||
axis.context.width);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawParallelAxisLine(VertexHelper vh, ParallelAxis axis)
|
||||
{
|
||||
if (axis.show && axis.axisLine.show)
|
||||
{
|
||||
if (m_Parallel == null)
|
||||
return;
|
||||
|
||||
DrawAxisLine(vh, axis,
|
||||
chart.theme.axis,
|
||||
m_Orient,
|
||||
axis.context.x,
|
||||
axis.context.y,
|
||||
axis.context.width);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26ab25bf702c54ad38461c91ba1451af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user