mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 17:30:10 +00:00
增加GridCoord3D3D坐标系
This commit is contained in:
@@ -75,7 +75,8 @@ namespace XCharts.Runtime
|
||||
Left,
|
||||
Right,
|
||||
Bottom,
|
||||
Top
|
||||
Top,
|
||||
Center
|
||||
}
|
||||
|
||||
[SerializeField] protected bool m_Show = true;
|
||||
@@ -729,10 +730,14 @@ namespace XCharts.Runtime
|
||||
/// <param name="value"></param>
|
||||
/// <param name="axisLength"></param>
|
||||
/// <returns></returns>
|
||||
public float GetDistance(double value, float axisLength)
|
||||
public float GetDistance(double value, float axisLength = 0)
|
||||
{
|
||||
if (context.minMaxRange == 0)
|
||||
return 0;
|
||||
if (axisLength == 0)
|
||||
{
|
||||
axisLength = context.length;
|
||||
}
|
||||
|
||||
if (IsCategory() && boundaryGap)
|
||||
{
|
||||
|
||||
160
Runtime/Component/Axis/Axis3DHelper.cs
Normal file
160
Runtime/Component/Axis/Axis3DHelper.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class Axis3DHelper
|
||||
{
|
||||
public static Vector3 Get3DGridPosition(GridCoord3D grid, XAxis3D xAxis, YAxis3D yAxis, ZAxis3D zAxis, double xValue, double yValue, double zValue)
|
||||
{
|
||||
var x = xAxis.GetDistance(xValue);
|
||||
var y = yAxis.GetDistance(yValue);
|
||||
var z = zAxis.GetDistance(zValue);
|
||||
|
||||
var dest = grid.context.pointA;
|
||||
dest += xAxis.context.dire * x;
|
||||
dest += yAxis.context.dire * y;
|
||||
dest += zAxis.context.dire * z;
|
||||
return dest;
|
||||
}
|
||||
|
||||
public static Vector3 Get3DGridPosition(GridCoord3D grid, XAxis3D xAxis, YAxis3D yAxis, double xValue, double yValue)
|
||||
{
|
||||
var x = xAxis.GetDistance(xValue);
|
||||
var y = yAxis.GetDistance(yValue);
|
||||
|
||||
var dest = grid.context.pointA;
|
||||
dest += xAxis.context.dire * x;
|
||||
dest += yAxis.context.dire * y;
|
||||
return dest;
|
||||
}
|
||||
|
||||
internal static void DrawAxisTick(VertexHelper vh, Axis axis, AxisTheme theme, DataZoom dataZoom,
|
||||
Vector3 start, Vector3 end, Vector3 relativedDire)
|
||||
{
|
||||
var tickLength = axis.axisTick.GetLength(theme.tickLength);
|
||||
var axisLength = Vector3.Distance(start, end);
|
||||
var axisDire = (end - start).normalized;
|
||||
|
||||
if (axis.position == Axis.AxisPosition.Right)
|
||||
{
|
||||
relativedDire = -relativedDire;
|
||||
}
|
||||
|
||||
if (AxisHelper.NeedShowSplit(axis))
|
||||
{
|
||||
var size = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom);
|
||||
if (axis.IsTime())
|
||||
{
|
||||
size += 1;
|
||||
if (!ChartHelper.IsEquals(axis.GetLastLabelValue(), axis.context.maxValue))
|
||||
size += 1;
|
||||
}
|
||||
var tickWidth = axis.axisTick.GetWidth(theme.tickWidth);
|
||||
var tickColor = axis.axisTick.GetColor(theme.tickColor);
|
||||
var current = start;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom);
|
||||
var hideTick = (i == 0 && (!axis.axisTick.showStartTick || axis.axisTick.alignWithLabel)) ||
|
||||
(i == size - 1 && !axis.axisTick.showEndTick);
|
||||
if (axis.axisTick.show && !hideTick)
|
||||
{
|
||||
UGL.DrawLine(vh, current, current + relativedDire * tickLength, tickWidth, tickColor);
|
||||
}
|
||||
current += axisDire * scaleWidth;
|
||||
}
|
||||
}
|
||||
if (axis.show && axis.axisLine.show && axis.axisLine.showArrow)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawAxisSplit(VertexHelper vh, Axis axis, AxisTheme theme, DataZoom dataZoom,
|
||||
Vector3 start, Vector3 end, Axis relativedAxis)
|
||||
{
|
||||
if (relativedAxis == null) return;
|
||||
var axisLength = Vector3.Distance(start, end);
|
||||
var axisDire = (end - start).normalized;
|
||||
var splitLength = relativedAxis.context.length;
|
||||
var relativeDire = relativedAxis.context.dire;
|
||||
var axisLineWidth = axis.axisLine.GetWidth(theme.lineWidth);
|
||||
splitLength -= axisLineWidth;
|
||||
var lineColor = axis.splitLine.GetColor(theme.splitLineColor);
|
||||
var lineWidth = axis.splitLine.GetWidth(theme.lineWidth);
|
||||
var lineType = axis.splitLine.GetType(theme.splitLineType);
|
||||
|
||||
var size = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom);
|
||||
if (axis.IsTime())
|
||||
{
|
||||
size += 1;
|
||||
if (!ChartHelper.IsEquals(axis.GetLastLabelValue(), axis.context.maxValue))
|
||||
size += 1;
|
||||
}
|
||||
|
||||
var current = start;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, axis.IsTime() ? i : i + 1, dataZoom);
|
||||
if (axis.boundaryGap && axis.axisTick.alignWithLabel)
|
||||
current -= axisDire * scaleWidth / 2;
|
||||
|
||||
if (axis.splitArea.show && i <= size - 1)
|
||||
{
|
||||
var p1 = current;
|
||||
var p2 = current + relativeDire * splitLength;
|
||||
var p3 = p2 + axisDire * scaleWidth;
|
||||
var p4 = p1 + axisDire * scaleWidth;
|
||||
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, axis.splitArea.GetColor(i, theme));
|
||||
}
|
||||
if (axis.splitLine.show)
|
||||
{
|
||||
if (axis.splitLine.NeedShow(i, size))
|
||||
{
|
||||
if (relativedAxis == null || !relativedAxis.axisLine.show
|
||||
|| (Vector3.Distance(current, relativedAxis.context.start) > 0.5f && Vector3.Distance(current, relativedAxis.context.end) > 0.5f))
|
||||
{
|
||||
ChartDrawer.DrawLineStyle(vh,
|
||||
lineType,
|
||||
lineWidth,
|
||||
current,
|
||||
current + relativeDire * splitLength,
|
||||
lineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
current += axisDire * scaleWidth;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 GetLabelPosition(int i, Axis axis, Axis relativedAxis, AxisTheme theme, float scaleWid)
|
||||
{
|
||||
var axisStart = axis.context.start;
|
||||
var axisEnd = axis.context.end;
|
||||
var axisDire = axis.context.dire;
|
||||
var relativedDire = relativedAxis != null ? relativedAxis.context.dire : Vector3.zero;
|
||||
var axisLength = Vector3.Distance(axisStart, axisEnd);
|
||||
var inside = axis.axisLabel.inside;
|
||||
var fontSize = axis.axisLabel.textStyle.GetFontSize(theme);
|
||||
var current = axis.offset;
|
||||
|
||||
if (axis.position == Axis.AxisPosition.Right)
|
||||
{
|
||||
relativedDire = -relativedDire;
|
||||
}
|
||||
|
||||
if (axis.IsTime() || axis.IsValue())
|
||||
{
|
||||
scaleWid = axis.context.minMaxRange != 0 ?
|
||||
axis.GetDistance(axis.GetLabelValue(i), axisLength) :
|
||||
0;
|
||||
}
|
||||
|
||||
return axisStart + axisDire * scaleWid + axis.axisLabel.offset - relativedDire * (axis.axisLabel.distance + fontSize / 2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Axis/Axis3DHelper.cs.meta
Normal file
11
Runtime/Component/Axis/Axis3DHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52469636872044a81a291bb00b71a140
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -15,6 +15,9 @@ namespace XCharts.Runtime
|
||||
/// 坐标轴的起点Y
|
||||
/// </summary>
|
||||
public float y;
|
||||
public Vector3 start;
|
||||
public Vector3 end;
|
||||
public Vector3 dire;
|
||||
/// <summary>
|
||||
/// 坐标轴原点X
|
||||
/// </summary>
|
||||
@@ -25,6 +28,7 @@ namespace XCharts.Runtime
|
||||
public float zeroY;
|
||||
public float width;
|
||||
public float height;
|
||||
public float length;
|
||||
public Vector3 position;
|
||||
public float left;
|
||||
public float right;
|
||||
|
||||
@@ -369,6 +369,116 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
protected void InitAxis3D(Axis relativedAxis, Orient orient)
|
||||
{
|
||||
Axis axis = component;
|
||||
var axisLength = (axis.context.end - axis.context.start).magnitude;
|
||||
chart.InitAxisRuntimeData(axis);
|
||||
|
||||
var objName = ChartCached.GetComponentObjectName(axis);
|
||||
var axisObj = ChartHelper.AddObject(objName,
|
||||
chart.transform,
|
||||
chart.chartMinAnchor,
|
||||
chart.chartMaxAnchor,
|
||||
chart.chartPivot,
|
||||
chart.chartSizeDelta);
|
||||
|
||||
axisObj.SetActive(axis.show);
|
||||
axisObj.hideFlags = chart.chartHideFlags;
|
||||
ChartHelper.HideAllObject(axisObj);
|
||||
|
||||
axis.gameObject = axisObj;
|
||||
axis.context.labelObjectList.Clear();
|
||||
|
||||
if (!axis.show)
|
||||
return;
|
||||
|
||||
var axisLabelTextStyle = axis.axisLabel.textStyle;
|
||||
var dataZoom = chart.GetDataZoomOfAxis(axis);
|
||||
var splitNumber = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom);
|
||||
var totalWidth = 0f;
|
||||
var eachWidth = AxisHelper.GetEachWidth(axis, axisLength, dataZoom);
|
||||
var gapWidth = axis.boundaryGap ? eachWidth / 2 : 0;
|
||||
|
||||
var textWidth = axis.axisLabel.width > 0 ?
|
||||
axis.axisLabel.width :
|
||||
AxisHelper.GetScaleWidth(axis, axisLength, 0, dataZoom);
|
||||
|
||||
var textHeight = axis.axisLabel.height > 0 ?
|
||||
axis.axisLabel.height :
|
||||
20f;
|
||||
|
||||
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series);
|
||||
var inside = axis.axisLabel.inside;
|
||||
var defaultAlignment = orient == Orient.Horizonal ? TextAnchor.MiddleCenter :
|
||||
((inside && axis.IsLeft()) || (!inside && axis.IsRight()) ?
|
||||
TextAnchor.MiddleLeft :
|
||||
TextAnchor.MiddleRight);
|
||||
if (axis.IsCategory() && axis.boundaryGap)
|
||||
splitNumber -= 1;
|
||||
axis.context.aligment = defaultAlignment;
|
||||
for (int i = 0; i < splitNumber; i++)
|
||||
{
|
||||
var labelWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom);
|
||||
var labelName = AxisHelper.GetLabelName(axis, axisLength, i,
|
||||
axis.context.destMinValue,
|
||||
axis.context.destMaxValue,
|
||||
dataZoom, isPercentStack);
|
||||
|
||||
var label = ChartHelper.AddAxisLabelObject(splitNumber, i,
|
||||
ChartCached.GetAxisLabelName(i),
|
||||
axisObj.transform,
|
||||
new Vector2(textWidth, textHeight),
|
||||
axis, chart.theme.axis, labelName,
|
||||
Color.clear,
|
||||
defaultAlignment,
|
||||
chart.theme.GetColor(i));
|
||||
|
||||
if (i == 0)
|
||||
axis.axisLabel.SetRelatedText(label.text, labelWidth);
|
||||
|
||||
var pos = GetLabelPosition(totalWidth + gapWidth, i);
|
||||
label.SetPosition(pos);
|
||||
//CheckValueLabelActive(axis, i, label, pos);
|
||||
|
||||
axis.context.labelObjectList.Add(label);
|
||||
|
||||
totalWidth += labelWidth;
|
||||
}
|
||||
if (axis.axisName.show)
|
||||
{
|
||||
ChartLabel label = null;
|
||||
var offset = axis.axisName.labelStyle.offset;
|
||||
var autoColor = axis.axisLine.GetColor(chart.theme.axis.lineColor);
|
||||
switch (axis.axisName.labelStyle.position)
|
||||
{
|
||||
case LabelStyle.Position.Start:
|
||||
|
||||
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
|
||||
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
|
||||
label.SetActive(axis.axisName.labelStyle.show);
|
||||
label.SetPosition(axis.context.start + offset);
|
||||
break;
|
||||
|
||||
case LabelStyle.Position.Middle:
|
||||
|
||||
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
|
||||
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
|
||||
label.SetActive(axis.axisName.labelStyle.show);
|
||||
label.SetPosition((axis.context.start + axis.context.end) / 2 + offset);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
|
||||
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
|
||||
label.SetActive(axis.axisName.labelStyle.show);
|
||||
label.SetPosition(axis.context.end + offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void InitAxis(Axis relativedAxis, Orient orient,
|
||||
float axisStartX, float axisStartY, float axisLength, float relativedLength)
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace XCharts.Runtime
|
||||
[SerializeField] private bool m_AutoColor;
|
||||
[SerializeField][Since("v3.3.0")] private bool m_ShowStartLine = true;
|
||||
[SerializeField][Since("v3.3.0")] private bool m_ShowEndLine = true;
|
||||
[SerializeField][Since("v3.11.0")] private bool m_ShowZLine = true;
|
||||
|
||||
/// <summary>
|
||||
/// The distance between the split line and axis line.
|
||||
@@ -53,6 +54,15 @@ namespace XCharts.Runtime
|
||||
get { return m_ShowEndLine; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_ShowEndLine, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether to show the Z axis part of the split line. Generally used for 3D coordinate systems.
|
||||
/// ||是否显示Z轴部分分割线。一般用于3D坐标系。
|
||||
/// </summary>
|
||||
public bool showZLine
|
||||
{
|
||||
get { return m_ShowZLine; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_ShowZLine, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } }
|
||||
public override void ClearVerticesDirty()
|
||||
|
||||
@@ -45,6 +45,7 @@ namespace XCharts.Runtime
|
||||
axis.context.x = parallel.context.x;
|
||||
axis.context.y = parallel.context.y + (axis.index) * each;
|
||||
axis.context.width = parallel.context.width;
|
||||
axis.context.length = parallel.context.width;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -52,6 +53,7 @@ namespace XCharts.Runtime
|
||||
axis.context.x = parallel.context.x + (axis.index) * each;
|
||||
axis.context.y = parallel.context.y;
|
||||
axis.context.width = parallel.context.height;
|
||||
axis.context.length = parallel.context.height;
|
||||
}
|
||||
axis.context.orient = m_Orient;
|
||||
axis.context.height = 0;
|
||||
|
||||
@@ -123,6 +123,12 @@ namespace XCharts.Runtime
|
||||
else
|
||||
context.y = chartY + context.bottom;
|
||||
|
||||
context.start = new Vector3(context.x, context.y);
|
||||
if (m_Orient == Orient.Horizonal)
|
||||
context.end = new Vector3(context.x + context.width, context.y);
|
||||
else
|
||||
context.end = new Vector3(context.x, context.y + context.height);
|
||||
context.length = (context.end - context.start).magnitude;
|
||||
context.position = new Vector3(context.x, context.y);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,11 @@ namespace XCharts.Runtime
|
||||
var relativedAxis = chart.GetChartComponent<YAxis>(axis.gridIndex);
|
||||
axis.context.x = grid.context.x;
|
||||
axis.context.y = AxisHelper.GetXAxisXOrY(grid, axis, relativedAxis);
|
||||
axis.context.start = new Vector3(grid.context.x, axis.context.y);
|
||||
axis.context.end = new Vector3(grid.context.x + grid.context.width, axis.context.y);
|
||||
var vec = axis.context.end - axis.context.start;
|
||||
axis.context.dire = vec.normalized;
|
||||
axis.context.length = vec.magnitude;
|
||||
axis.context.zeroY = grid.context.y;
|
||||
axis.context.zeroX = grid.context.x + axis.context.offset;
|
||||
}
|
||||
|
||||
8
Runtime/Component/Axis/XAxis3D.meta
Normal file
8
Runtime/Component/Axis/XAxis3D.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6350e9983955e49c5b48704d3866cbfe
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
Runtime/Component/Axis/XAxis3D/XAxis3D.cs
Normal file
36
Runtime/Component/Axis/XAxis3D/XAxis3D.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// The x axis in cartesian(rectangular) coordinate.
|
||||
/// ||直角坐标系 grid 中的 x 轴。
|
||||
/// </summary>
|
||||
[Since("v3.11.0")]
|
||||
[System.Serializable]
|
||||
[RequireChartComponent(typeof(GridCoord3D))]
|
||||
[ComponentHandler(typeof(XAxis3DHander), true)]
|
||||
public class XAxis3D : Axis
|
||||
{
|
||||
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_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;
|
||||
axisName.name = "X";
|
||||
axisName.labelStyle.position = LabelStyle.Position.Middle;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Axis/XAxis3D/XAxis3D.cs.meta
Normal file
11
Runtime/Component/Axis/XAxis3D/XAxis3D.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9129bca9c2a864e1ea337d7eb74d1024
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
190
Runtime/Component/Axis/XAxis3D/XAxis3DHander.cs
Normal file
190
Runtime/Component/Axis/XAxis3D/XAxis3DHander.cs
Normal file
@@ -0,0 +1,190 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class XAxis3DHander : AxisHandler<XAxis3D>
|
||||
{
|
||||
protected override Orient orient { get { return Orient.Horizonal; } }
|
||||
|
||||
public override void InitComponent()
|
||||
{
|
||||
InitXAxis(component);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
UpdateAxisMinMaxValue(component.index, component);
|
||||
if (!chart.isTriggerOnClick)
|
||||
{
|
||||
UpdatePointerValue(component);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
base.OnPointerClick(eventData);
|
||||
if (chart.isTriggerOnClick)
|
||||
{
|
||||
UpdatePointerValue(component);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
base.OnPointerExit(eventData);
|
||||
if (chart.isTriggerOnClick)
|
||||
{
|
||||
component.context.pointerValue = double.PositiveInfinity;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawBase(VertexHelper vh)
|
||||
{
|
||||
UpdatePosition(component);
|
||||
DrawXAxisSplit(vh, component);
|
||||
DrawXAxisLine(vh, component);
|
||||
DrawXAxisTick(vh, component);
|
||||
}
|
||||
|
||||
private void UpdatePosition(XAxis3D axis)
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(axis.gridIndex);
|
||||
if (grid != null)
|
||||
{
|
||||
if (axis.position == Axis.AxisPosition.Right || axis.position == Axis.AxisPosition.Top)
|
||||
{
|
||||
axis.context.start = grid.xyExchanged ? grid.context.pointD : grid.context.pointB;
|
||||
axis.context.end = grid.context.pointC;
|
||||
}
|
||||
else
|
||||
{
|
||||
axis.context.start = grid.context.pointA;
|
||||
axis.context.end = grid.xyExchanged ? grid.context.pointB : grid.context.pointD;
|
||||
}
|
||||
var vect = axis.context.end - axis.context.start;
|
||||
axis.context.x = axis.context.start.x;
|
||||
axis.context.y = axis.context.start.y;
|
||||
axis.context.dire = vect.normalized;
|
||||
axis.context.length = vect.magnitude;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitXAxis(XAxis3D xAxis)
|
||||
{
|
||||
var theme = chart.theme;
|
||||
var xAxisIndex = xAxis.index;
|
||||
xAxis.painter = chart.painter;
|
||||
xAxis.refreshComponent = delegate ()
|
||||
{
|
||||
var yAxis = chart.GetChartComponent<YAxis3D>(xAxis.index);
|
||||
InitAxis3D(yAxis, orient);
|
||||
};
|
||||
xAxis.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)
|
||||
{
|
||||
var yAxis = chart.GetChartComponent<YAxis3D>(component.index);
|
||||
return Axis3DHelper.GetLabelPosition(i, component, yAxis, chart.theme.axis, scaleWid);
|
||||
}
|
||||
|
||||
private void DrawXAxisSplit(VertexHelper vh, XAxis3D xAxis)
|
||||
{
|
||||
if (AxisHelper.NeedShowSplit(xAxis))
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(xAxis.gridIndex);
|
||||
var relativedAxis = chart.GetChartComponent<YAxis3D>(xAxis.gridIndex);
|
||||
var dataZoom = chart.GetDataZoomOfAxis(xAxis);
|
||||
var isLeft = grid.IsLeft();
|
||||
if (grid.xyExchanged)
|
||||
{
|
||||
Axis3DHelper.DrawAxisSplit(vh, xAxis, chart.theme.axis, dataZoom,
|
||||
grid.context.pointA,
|
||||
grid.context.pointB,
|
||||
relativedAxis);
|
||||
if (xAxis.splitLine.showZLine)
|
||||
{
|
||||
var relativedAxis2 = chart.GetChartComponent<ZAxis3D>(xAxis.gridIndex);
|
||||
Axis3DHelper.DrawAxisSplit(vh, xAxis, chart.theme.axis, dataZoom,
|
||||
isLeft ? grid.context.pointD : grid.context.pointA,
|
||||
isLeft ? grid.context.pointC : grid.context.pointB,
|
||||
relativedAxis2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Axis3DHelper.DrawAxisSplit(vh, xAxis, chart.theme.axis, dataZoom,
|
||||
grid.context.pointA,
|
||||
grid.context.pointD,
|
||||
relativedAxis);
|
||||
if (xAxis.splitLine.showZLine)
|
||||
{
|
||||
var relativedAxis2 = chart.GetChartComponent<ZAxis3D>(xAxis.gridIndex);
|
||||
Axis3DHelper.DrawAxisSplit(vh, xAxis, chart.theme.axis, dataZoom,
|
||||
grid.context.pointB,
|
||||
grid.context.pointC,
|
||||
relativedAxis2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawXAxisTick(VertexHelper vh, XAxis3D xAxis)
|
||||
{
|
||||
if (AxisHelper.NeedShowSplit(xAxis))
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(xAxis.gridIndex);
|
||||
if (grid == null)
|
||||
return;
|
||||
|
||||
var dataZoom = chart.GetDataZoomOfAxis(xAxis);
|
||||
var relativedAxis = chart.GetChartComponent<YAxis3D>(xAxis.gridIndex);
|
||||
Axis3DHelper.DrawAxisTick(vh, xAxis, chart.theme.axis, dataZoom,
|
||||
xAxis.context.start,
|
||||
xAxis.context.end,
|
||||
-relativedAxis.context.dire);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawXAxisLine(VertexHelper vh, XAxis3D axis)
|
||||
{
|
||||
if (axis.show && axis.axisLine.show)
|
||||
{
|
||||
var theme = chart.theme.axis;
|
||||
var lineWidth = axis.axisLine.GetWidth(theme.lineWidth);
|
||||
var lineType = axis.axisLine.GetType(theme.lineType);
|
||||
var lineColor = axis.axisLine.GetColor(theme.lineColor);
|
||||
|
||||
var start = axis.context.start;
|
||||
var end = axis.context.end;
|
||||
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, start, end, lineColor);
|
||||
}
|
||||
}
|
||||
|
||||
internal override float GetAxisLineXOrY()
|
||||
{
|
||||
return component.context.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Axis/XAxis3D/XAxis3DHander.cs.meta
Normal file
11
Runtime/Component/Axis/XAxis3D/XAxis3DHander.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc1147481a423494d963df29b423f3a0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -35,6 +35,11 @@ namespace XCharts.Runtime
|
||||
var relativedAxis = chart.GetChartComponent<XAxis>(axis.gridIndex);
|
||||
axis.context.x = AxisHelper.GetYAxisXOrY(grid, axis, relativedAxis);
|
||||
axis.context.y = grid.context.y;
|
||||
axis.context.start = new Vector3(axis.context.x, grid.context.y);
|
||||
axis.context.end = new Vector3(axis.context.x, grid.context.y + grid.context.height);
|
||||
var vect = axis.context.end - axis.context.start;
|
||||
axis.context.dire = vect.normalized;
|
||||
axis.context.length = vect.magnitude;
|
||||
axis.context.zeroX = axis.context.x;
|
||||
axis.context.zeroY = axis.context.y + axis.context.offset;
|
||||
}
|
||||
|
||||
8
Runtime/Component/Axis/YAxis3D.meta
Normal file
8
Runtime/Component/Axis/YAxis3D.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa26616789b6b4903aae479a4c552b89
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Runtime/Component/Axis/YAxis3D/YAxis3D.cs
Normal file
33
Runtime/Component/Axis/YAxis3D/YAxis3D.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// The x axis in cartesian(rectangular) coordinate.
|
||||
/// ||直角坐标系 grid 中的 y 轴。
|
||||
/// </summary>
|
||||
[Since("v3.11.0")]
|
||||
[System.Serializable]
|
||||
[RequireChartComponent(typeof(GridCoord3D), typeof(XAxis3D))]
|
||||
[ComponentHandler(typeof(YAxis3DHander), true)]
|
||||
public class YAxis3D : Axis
|
||||
{
|
||||
public override void SetDefaultValue()
|
||||
{
|
||||
m_Show = true;
|
||||
m_Type = AxisType.Value;
|
||||
m_Min = 0;
|
||||
m_Max = 0;
|
||||
m_SplitNumber = 0;
|
||||
m_BoundaryGap = false;
|
||||
m_Position = AxisPosition.Left;
|
||||
m_Data = new List<string>(5);
|
||||
splitLine.show = true;
|
||||
splitLine.lineStyle.type = LineStyle.Type.None;
|
||||
axisLabel.textLimit.enable = false;
|
||||
axisTick.showStartTick = true;
|
||||
axisName.name = "Y";
|
||||
axisName.labelStyle.position = LabelStyle.Position.Middle;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Axis/YAxis3D/YAxis3D.cs.meta
Normal file
11
Runtime/Component/Axis/YAxis3D/YAxis3D.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3cb4a6657aaf473bbae7162eb189cc0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
176
Runtime/Component/Axis/YAxis3D/YAxis3DHander.cs
Normal file
176
Runtime/Component/Axis/YAxis3D/YAxis3DHander.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class YAxis3DHander : AxisHandler<YAxis3D>
|
||||
{
|
||||
protected override Orient orient { get { return Orient.Vertical; } }
|
||||
|
||||
public override void InitComponent()
|
||||
{
|
||||
InitYAxis(component);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
UpdateAxisMinMaxValue(component.index, component);
|
||||
UpdatePointerValue(component);
|
||||
}
|
||||
|
||||
public override void DrawBase(VertexHelper vh)
|
||||
{
|
||||
UpdatePosition(component);
|
||||
DrawYAxisSplit(vh, component.index, component);
|
||||
DrawYAxisLine(vh, component.index, component);
|
||||
DrawYAxisTick(vh, component.index, component);
|
||||
}
|
||||
|
||||
private void UpdatePosition(YAxis3D axis)
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(axis.gridIndex);
|
||||
if (grid != null)
|
||||
{
|
||||
if (axis.position == Axis.AxisPosition.Right)
|
||||
{
|
||||
axis.context.start = grid.xyExchanged ? grid.context.pointB : grid.context.pointD;
|
||||
axis.context.end = grid.context.pointC;
|
||||
}
|
||||
else
|
||||
{
|
||||
axis.context.start = grid.context.pointA;
|
||||
axis.context.end = grid.xyExchanged ? grid.context.pointD : grid.context.pointB;
|
||||
}
|
||||
axis.context.x = axis.context.start.x;
|
||||
axis.context.y = axis.context.start.y;
|
||||
var vect = axis.context.end - axis.context.start;
|
||||
axis.context.dire = vect.normalized;
|
||||
axis.context.length = vect.magnitude;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitYAxis(YAxis3D yAxis)
|
||||
{
|
||||
var theme = chart.theme;
|
||||
var yAxisIndex = yAxis.index;
|
||||
yAxis.painter = chart.painter;
|
||||
yAxis.refreshComponent = delegate ()
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(yAxis.gridIndex);
|
||||
if (grid != null)
|
||||
{
|
||||
var xAxis = chart.GetChartComponent<YAxis3D>(yAxis.index);
|
||||
InitAxis3D(xAxis, orient);
|
||||
}
|
||||
};
|
||||
yAxis.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(axis, i, label, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override Vector3 GetLabelPosition(float scaleWid, int i)
|
||||
{
|
||||
var xAxis = chart.GetChartComponent<XAxis3D>(component.index);
|
||||
return Axis3DHelper.GetLabelPosition(i, component, xAxis, chart.theme.axis, scaleWid);
|
||||
}
|
||||
|
||||
private void DrawYAxisSplit(VertexHelper vh, int yAxisIndex, YAxis3D yAxis)
|
||||
{
|
||||
if (AxisHelper.NeedShowSplit(yAxis))
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(yAxis.gridIndex);
|
||||
var relativedAxis = chart.GetChartComponent<XAxis3D>(yAxis.gridIndex);
|
||||
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
|
||||
var isLeft = grid.IsLeft();
|
||||
if (grid.xyExchanged)
|
||||
{
|
||||
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
|
||||
grid.context.pointA,
|
||||
grid.context.pointD,
|
||||
relativedAxis);
|
||||
if (yAxis.splitLine.showZLine)
|
||||
{
|
||||
var relativedAxis2 = chart.GetChartComponent<ZAxis3D>(yAxis.gridIndex);
|
||||
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
|
||||
grid.context.pointB, grid.context.pointC, relativedAxis2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
|
||||
grid.context.pointA,
|
||||
grid.context.pointB,
|
||||
relativedAxis);
|
||||
if (yAxis.splitLine.showZLine)
|
||||
{
|
||||
var relativedAxis2 = chart.GetChartComponent<ZAxis3D>(yAxis.gridIndex);
|
||||
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
|
||||
isLeft ? grid.context.pointD : grid.context.pointA,
|
||||
isLeft ? grid.context.pointC : grid.context.pointB,
|
||||
relativedAxis2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawYAxisTick(VertexHelper vh, int yAxisIndex, YAxis3D yAxis)
|
||||
{
|
||||
if (AxisHelper.NeedShowSplit(yAxis))
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(yAxis.gridIndex);
|
||||
if (grid == null)
|
||||
return;
|
||||
|
||||
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
|
||||
var relativedAxis = chart.GetChartComponent<XAxis3D>(yAxis.gridIndex);
|
||||
|
||||
Axis3DHelper.DrawAxisTick(vh, yAxis, chart.theme.axis, dataZoom,
|
||||
yAxis.context.start,
|
||||
yAxis.context.end,
|
||||
-relativedAxis.context.dire);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawYAxisLine(VertexHelper vh, int axisIndex, YAxis3D axis)
|
||||
{
|
||||
if (axis.show && axis.axisLine.show)
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(axis.gridIndex);
|
||||
if (grid == null)
|
||||
return;
|
||||
|
||||
var theme = chart.theme.axis;
|
||||
|
||||
var lineWidth = axis.axisLine.GetWidth(theme.lineWidth);
|
||||
var lineType = axis.axisLine.GetType(theme.lineType);
|
||||
var lineColor = axis.axisLine.GetColor(theme.lineColor);
|
||||
|
||||
var start = axis.context.start;
|
||||
var end = axis.context.end;
|
||||
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, start, end, lineColor);
|
||||
}
|
||||
}
|
||||
|
||||
internal override float GetAxisLineXOrY()
|
||||
{
|
||||
return component.context.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Axis/YAxis3D/YAxis3DHander.cs.meta
Normal file
11
Runtime/Component/Axis/YAxis3D/YAxis3DHander.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56b4be734c61645e1bf91c22a6e3da6c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Runtime/Component/Axis/ZAxis3D.meta
Normal file
8
Runtime/Component/Axis/ZAxis3D.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 378448672ed084b0798c7ad343314693
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Runtime/Component/Axis/ZAxis3D/ZAxis3D.cs
Normal file
33
Runtime/Component/Axis/ZAxis3D/ZAxis3D.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// The x axis in cartesian(rectangular) coordinate.
|
||||
/// ||直角坐标系 grid 中的 y 轴。
|
||||
/// </summary>
|
||||
[Since("v3.11.0")]
|
||||
[System.Serializable]
|
||||
[RequireChartComponent(typeof(GridCoord3D), typeof(XAxis3D))]
|
||||
[ComponentHandler(typeof(ZAxis3DHander), true)]
|
||||
public class ZAxis3D : Axis
|
||||
{
|
||||
public override void SetDefaultValue()
|
||||
{
|
||||
m_Show = true;
|
||||
m_Type = AxisType.Value;
|
||||
m_Min = 0;
|
||||
m_Max = 0;
|
||||
m_SplitNumber = 0;
|
||||
m_BoundaryGap = false;
|
||||
m_Position = AxisPosition.Left;
|
||||
m_Data = new List<string>(5);
|
||||
splitLine.show = true;
|
||||
splitLine.lineStyle.type = LineStyle.Type.None;
|
||||
axisLabel.textLimit.enable = false;
|
||||
axisTick.showStartTick = true;
|
||||
axisName.name = "Z";
|
||||
axisName.labelStyle.position = LabelStyle.Position.Middle;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Axis/ZAxis3D/ZAxis3D.cs.meta
Normal file
11
Runtime/Component/Axis/ZAxis3D/ZAxis3D.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65aa8ae88610c431ebdab86935af2379
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
198
Runtime/Component/Axis/ZAxis3D/ZAxis3DHander.cs
Normal file
198
Runtime/Component/Axis/ZAxis3D/ZAxis3DHander.cs
Normal file
@@ -0,0 +1,198 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class ZAxis3DHander : AxisHandler<ZAxis3D>
|
||||
{
|
||||
protected override Orient orient { get { return Orient.Vertical; } }
|
||||
|
||||
public override void InitComponent()
|
||||
{
|
||||
InitYAxis(component);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
UpdateAxisMinMaxValue(component.index, component);
|
||||
UpdatePointerValue(component);
|
||||
}
|
||||
|
||||
public override void DrawBase(VertexHelper vh)
|
||||
{
|
||||
UpdatePosition(component);
|
||||
DrawZAxisSplit(vh, component.index, component);
|
||||
DrawZAxisLine(vh, component.index, component);
|
||||
DrawZAxisTick(vh, component.index, component);
|
||||
}
|
||||
|
||||
private void UpdatePosition(ZAxis3D axis)
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(axis.gridIndex);
|
||||
if (grid != null)
|
||||
{
|
||||
if (grid.context.pointB.x < grid.context.pointA.x)
|
||||
{
|
||||
axis.context.start = grid.context.pointD;
|
||||
axis.context.end = grid.context.pointH;
|
||||
}
|
||||
else if (axis.position == Axis.AxisPosition.Center)
|
||||
{
|
||||
axis.context.start = grid.context.pointB;
|
||||
axis.context.end = grid.context.pointF;
|
||||
}
|
||||
else if (axis.position == Axis.AxisPosition.Right)
|
||||
{
|
||||
axis.context.start = grid.context.pointC;
|
||||
axis.context.end = grid.context.pointG;
|
||||
}
|
||||
else
|
||||
{
|
||||
axis.context.start = grid.context.pointA;
|
||||
axis.context.end = grid.context.pointE;
|
||||
}
|
||||
axis.context.x = axis.context.start.x;
|
||||
axis.context.y = axis.context.start.y;
|
||||
var vect = axis.context.end - axis.context.start;
|
||||
axis.context.dire = vect.normalized;
|
||||
axis.context.length = vect.magnitude;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitYAxis(ZAxis3D yAxis)
|
||||
{
|
||||
var theme = chart.theme;
|
||||
var yAxisIndex = yAxis.index;
|
||||
yAxis.painter = chart.painter;
|
||||
yAxis.refreshComponent = delegate ()
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(yAxis.gridIndex);
|
||||
if (grid != null)
|
||||
{
|
||||
var relativedAxis = chart.GetChartComponent<ZAxis3D>(yAxis.index);
|
||||
InitAxis3D(relativedAxis, orient);
|
||||
}
|
||||
};
|
||||
yAxis.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(axis, i, label, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override Vector3 GetLabelPosition(float scaleWid, int i)
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(component.gridIndex);
|
||||
if (grid == null)
|
||||
return Vector3.zero;
|
||||
|
||||
var yAxis = chart.GetChartComponent<XAxis3D>(component.index);
|
||||
return Axis3DHelper.GetLabelPosition(i, component, yAxis,
|
||||
chart.theme.axis,
|
||||
scaleWid);
|
||||
}
|
||||
|
||||
private void DrawZAxisSplit(VertexHelper vh, int yAxisIndex, ZAxis3D yAxis)
|
||||
{
|
||||
if (AxisHelper.NeedShowSplit(yAxis))
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(yAxis.gridIndex);
|
||||
if (grid == null)
|
||||
return;
|
||||
|
||||
var isLeft = grid.IsLeft();
|
||||
if (grid.xyExchanged)
|
||||
{
|
||||
var relativedAxis = chart.GetChartComponent<XAxis3D>(yAxis.gridIndex);
|
||||
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
|
||||
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
|
||||
isLeft ? grid.context.pointD : grid.context.pointA,
|
||||
isLeft ? grid.context.pointH : grid.context.pointE,
|
||||
relativedAxis);
|
||||
if (yAxis.splitLine.showZLine)
|
||||
{
|
||||
var relativedAxis2 = chart.GetChartComponent<YAxis3D>(yAxis.gridIndex);
|
||||
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
|
||||
grid.context.pointB,
|
||||
grid.context.pointF,
|
||||
relativedAxis2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var relativedAxis = chart.GetChartComponent<YAxis3D>(yAxis.gridIndex);
|
||||
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
|
||||
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
|
||||
isLeft ? grid.context.pointD : grid.context.pointA,
|
||||
isLeft ? grid.context.pointH : grid.context.pointE,
|
||||
relativedAxis);
|
||||
if (yAxis.splitLine.showZLine)
|
||||
{
|
||||
var relativedAxis2 = chart.GetChartComponent<XAxis3D>(yAxis.gridIndex);
|
||||
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
|
||||
grid.context.pointB,
|
||||
grid.context.pointF,
|
||||
relativedAxis2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawZAxisTick(VertexHelper vh, int yAxisIndex, ZAxis3D zAxis)
|
||||
{
|
||||
if (AxisHelper.NeedShowSplit(zAxis))
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(zAxis.gridIndex);
|
||||
if (grid == null)
|
||||
return;
|
||||
|
||||
var dataZoom = chart.GetDataZoomOfAxis(zAxis);
|
||||
var relativedDire = grid.context.pointA - grid.context.pointB;
|
||||
Axis3DHelper.DrawAxisTick(vh, zAxis, chart.theme.axis, dataZoom,
|
||||
zAxis.context.start,
|
||||
zAxis.context.end,
|
||||
relativedDire.normalized);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawZAxisLine(VertexHelper vh, int axisIndex, ZAxis3D axis)
|
||||
{
|
||||
if (axis.show && axis.axisLine.show)
|
||||
{
|
||||
var grid = chart.GetChartComponent<GridCoord3D>(axis.gridIndex);
|
||||
if (grid == null)
|
||||
return;
|
||||
|
||||
var theme = chart.theme.axis;
|
||||
|
||||
var lineWidth = axis.axisLine.GetWidth(theme.lineWidth);
|
||||
var lineType = axis.axisLine.GetType(theme.lineType);
|
||||
var lineColor = axis.axisLine.GetColor(theme.lineColor);
|
||||
|
||||
var start = axis.context.start;
|
||||
var end = axis.context.end;
|
||||
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, start, end, lineColor);
|
||||
}
|
||||
}
|
||||
|
||||
internal override float GetAxisLineXOrY()
|
||||
{
|
||||
return component.context.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Axis/ZAxis3D/ZAxis3DHander.cs.meta
Normal file
11
Runtime/Component/Axis/ZAxis3D/ZAxis3DHander.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67fb4be32885d4915979719c676aac5a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -386,8 +386,8 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
public float runtimeRangeMinHeight { get { return (float) ((rangeMin - min) / (max - min) * itemHeight); } }
|
||||
public float runtimeRangeMaxHeight { get { return (float) ((rangeMax - min) / (max - min) * itemHeight); } }
|
||||
public float runtimeRangeMinHeight { get { return (float)((rangeMin - min) / (max - min) * itemHeight); } }
|
||||
public float runtimeRangeMaxHeight { get { return (float)((rangeMax - min) / (max - min) * itemHeight); } }
|
||||
|
||||
public void AddColors(List<Color32> colors)
|
||||
{
|
||||
@@ -413,6 +413,25 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
public Color32 GetColor(double xValue, double yValue, double zValue, byte alpha = 255)
|
||||
{
|
||||
Color32 color;
|
||||
if (m_Dimension == 0)
|
||||
{
|
||||
color = GetColor(xValue);
|
||||
}
|
||||
else if (m_Dimension == 1)
|
||||
{
|
||||
color = GetColor(yValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = GetColor(zValue);
|
||||
}
|
||||
color.a = alpha;
|
||||
return color;
|
||||
}
|
||||
|
||||
public Color32 GetColor(double value)
|
||||
{
|
||||
int index = GetIndex(value);
|
||||
@@ -437,7 +456,7 @@ namespace XCharts.Runtime
|
||||
if (index == splitNumber - 1)
|
||||
return m_InRange[index].color;
|
||||
else
|
||||
return Color32.Lerp(m_InRange[index].color, m_InRange[index + 1].color, (float) rate);
|
||||
return Color32.Lerp(m_InRange[index].color, m_InRange[index + 1].color, (float)rate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
8
Runtime/Coord/Grid3D.meta
Normal file
8
Runtime/Coord/Grid3D.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14f9081aa22ba4bcb9cdbfbb95c7221e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
270
Runtime/Coord/Grid3D/GridCoord3D.cs
Normal file
270
Runtime/Coord/Grid3D/GridCoord3D.cs
Normal file
@@ -0,0 +1,270 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// View control component in 3D coordinate system.
|
||||
/// ||3D视角控制组件。
|
||||
/// </summary>
|
||||
[Since("v3.11.0")]
|
||||
[Serializable]
|
||||
public class ViewControl : ChildComponent
|
||||
{
|
||||
[SerializeField][Range(-90, 180)] private float m_Alpha = 90f;
|
||||
[SerializeField][Range(-90, 90)] private float m_Beta = 55f;
|
||||
|
||||
/// <summary>
|
||||
/// The angle of the view in the x-z plane.
|
||||
/// ||视角在x-z平面的角度。
|
||||
/// </summary>
|
||||
public float alpha
|
||||
{
|
||||
get { return m_Alpha; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Alpha, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The angle of the view in the y-z plane.
|
||||
/// ||视角在y-z平面的角度。
|
||||
/// </summary>
|
||||
public float beta
|
||||
{
|
||||
get { return m_Beta; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Beta, value)) SetVerticesDirty(); }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grid component.
|
||||
/// ||Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart can be drawn in grid.
|
||||
/// ||3D网格组件。
|
||||
/// 3D直角坐标系内绘图网格。可以在网格上绘制3D折线图,3D柱状图,3D散点图。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[ComponentHandler(typeof(GridCoord3DHandler), true)]
|
||||
public class GridCoord3D : CoordSystem, IUpdateRuntimeData, ISerieContainer
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private float m_Left = 0.15f;
|
||||
[SerializeField] private float m_Right = 0.2f;
|
||||
[SerializeField] private float m_Top = 0.3f;
|
||||
[SerializeField] private float m_Bottom = 0.15f;
|
||||
[SerializeField] private bool m_ShowBorder = false;
|
||||
[SerializeField] private float m_BoxWidth = 0.55f;
|
||||
[SerializeField] private float m_BoxHeight = 0.4f;
|
||||
[SerializeField] private float m_BoxDepth = 0.2f;
|
||||
[SerializeField] private bool m_XYExchanged = false;
|
||||
[SerializeField] private ViewControl m_ViewControl = new ViewControl();
|
||||
|
||||
public GridCoord3DContext context = new GridCoord3DContext();
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show the grid in rectangular coordinate.
|
||||
/// ||是否显示直角坐标系网格。
|
||||
/// </summary>
|
||||
public bool show
|
||||
{
|
||||
get { return m_Show; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the left side of the container.
|
||||
/// ||grid 组件离容器左侧的距离。
|
||||
/// </summary>
|
||||
public float left
|
||||
{
|
||||
get { return m_Left; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the right side of the container.
|
||||
/// ||grid 组件离容器右侧的距离。
|
||||
/// </summary>
|
||||
public float right
|
||||
{
|
||||
get { return m_Right; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the top side of the container.
|
||||
/// ||grid 组件离容器上侧的距离。
|
||||
/// </summary>
|
||||
public float top
|
||||
{
|
||||
get { return m_Top; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the bottom side of the container.
|
||||
/// ||grid 组件离容器下侧的距离。
|
||||
/// </summary>
|
||||
public float bottom
|
||||
{
|
||||
get { return m_Bottom; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether to show the grid border.
|
||||
/// ||是否显示网格边框。
|
||||
/// </summary>
|
||||
public bool showBorder
|
||||
{
|
||||
get { return m_ShowBorder; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_ShowBorder, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The width of the box in the coordinate system.
|
||||
/// ||坐标系的宽度。
|
||||
/// </summary>
|
||||
public float boxWidth
|
||||
{
|
||||
get { return m_BoxWidth; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_BoxWidth, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The height of the box in the coordinate system.
|
||||
/// ||坐标系的高度。
|
||||
/// </summary>
|
||||
public float boxHeight
|
||||
{
|
||||
get { return m_BoxHeight; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_BoxHeight, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The depth of the box in the coordinate system.
|
||||
/// ||坐标系的深度。
|
||||
/// </summary>
|
||||
public float boxDepth
|
||||
{
|
||||
get { return m_BoxDepth; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_BoxDepth, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether to exchange the x and y axes.
|
||||
/// ||是否交换x和y轴。
|
||||
/// </summary>
|
||||
public bool xyExchanged
|
||||
{
|
||||
get { return m_XYExchanged; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_XYExchanged, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// View control component in 3D coordinate system.
|
||||
/// ||3D视角控制组件。
|
||||
/// </summary>
|
||||
public ViewControl viewControl
|
||||
{
|
||||
get { return m_ViewControl; }
|
||||
//set { if (PropertyUtil.SetClass(ref m_ViewControl, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
public void UpdateRuntimeData(BaseChart chart)
|
||||
{
|
||||
var chartX = chart.chartX;
|
||||
var chartY = chart.chartY;
|
||||
var chartWidth = chart.chartWidth;
|
||||
var chartHeight = chart.chartHeight;
|
||||
var actualLeft = left <= 1 ? left * chartWidth : left;
|
||||
var actualBottom = bottom <= 1 ? bottom * chartHeight : bottom;
|
||||
var actualBoxWidth = m_BoxWidth <= 1 ? m_BoxWidth * chartWidth : m_BoxWidth;
|
||||
var actualBoxHeight = m_BoxHeight <= 1 ? m_BoxHeight * chartHeight : m_BoxHeight;
|
||||
var actualBoxDepth = m_BoxDepth <= 1 ? m_BoxDepth * chartWidth : m_BoxDepth;
|
||||
context.x = chartX + actualLeft;
|
||||
context.y = chartY + actualBottom;
|
||||
context.pointA.x = context.x;
|
||||
context.pointA.y = context.y;
|
||||
|
||||
var angle = m_ViewControl.alpha * Mathf.Deg2Rad;
|
||||
context.pointD.x = context.x + actualBoxWidth * Mathf.Sin(angle);
|
||||
context.pointD.y = context.y - actualBoxWidth * Mathf.Cos(angle);
|
||||
|
||||
angle = (90 - m_ViewControl.beta) * Mathf.Deg2Rad;
|
||||
context.pointB.x = context.x + actualBoxDepth * Mathf.Cos(angle);
|
||||
context.pointB.y = context.y + actualBoxDepth * Mathf.Sin(angle);
|
||||
|
||||
context.pointC = context.pointB + (context.pointD - context.pointA);
|
||||
|
||||
context.pointE.x = context.pointA.x;
|
||||
context.pointE.y = context.pointA.y + actualBoxHeight;
|
||||
|
||||
var diff = context.pointE - context.pointA;
|
||||
context.pointF = context.pointB + diff;
|
||||
context.pointG = context.pointC + diff;
|
||||
context.pointH = context.pointD + diff;
|
||||
|
||||
var minX = Mathf.Min(context.pointA.x, context.pointB.x, context.pointC.x, context.pointD.x, context.pointE.x, context.pointF.x, context.pointG.x, context.pointH.x);
|
||||
var minY = Mathf.Min(context.pointA.y, context.pointB.y, context.pointC.y, context.pointD.y, context.pointE.y, context.pointF.y, context.pointG.y, context.pointH.y);
|
||||
var maxX = Mathf.Max(context.pointA.x, context.pointB.x, context.pointC.x, context.pointD.x, context.pointE.x, context.pointF.x, context.pointG.x, context.pointH.x);
|
||||
var maxY = Mathf.Max(context.pointA.y, context.pointB.y, context.pointC.y, context.pointD.y, context.pointE.y, context.pointF.y, context.pointG.y, context.pointH.y);
|
||||
|
||||
context.maxRect.x = minX;
|
||||
context.maxRect.y = minY;
|
||||
context.maxRect.width = maxX - minX;
|
||||
context.maxRect.height = maxY - minY;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The opening of the coordinate system faces to the left.
|
||||
/// 坐标系开口朝向左边。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsLeft()
|
||||
{
|
||||
return context.pointB.x < context.pointA.x;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the pointer is in the grid.
|
||||
/// ||指针是否在网格内。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsPointerEnter()
|
||||
{
|
||||
return context.isPointerEnter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the given position is in the grid.
|
||||
/// ||给定的位置是否在网格内。
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public bool Contains(Vector3 pos)
|
||||
{
|
||||
if (!context.maxRect.Contains(pos)) return false;
|
||||
if (UGLHelper.IsPointInPolygon(pos, context.pointA, context.pointB, context.pointC, context.pointD)) return true;
|
||||
if (UGLHelper.IsPointInPolygon(pos, context.pointB, context.pointF, context.pointG, context.pointC)) return true;
|
||||
if (IsLeft())
|
||||
if (UGLHelper.IsPointInPolygon(pos, context.pointC, context.pointG, context.pointH, context.pointD)) return true;
|
||||
else
|
||||
if (UGLHelper.IsPointInPolygon(pos, context.pointA, context.pointE, context.pointF, context.pointB)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamp the position of pos to the grid.
|
||||
/// ||将位置限制在网格内。
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
public void Clamp(ref Vector3 pos)
|
||||
{
|
||||
//TODO:
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a given line segment will not intersect the Grid boundary at all.
|
||||
/// ||判断给定的线段是否与Grid边界是否完全不会相交。
|
||||
/// </summary>
|
||||
/// <param name="sp"></param>
|
||||
/// <param name="ep"></param>
|
||||
/// <returns></returns>
|
||||
public bool NotAnyIntersect(Vector3 sp, Vector3 ep)
|
||||
{
|
||||
//TODO:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Coord/Grid3D/GridCoord3D.cs.meta
Normal file
11
Runtime/Coord/Grid3D/GridCoord3D.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95f8c8c3492e54987af59175d94f8761
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Runtime/Coord/Grid3D/GridCoord3DContext.cs
Normal file
23
Runtime/Coord/Grid3D/GridCoord3DContext.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public class GridCoord3DContext : MainComponentContext
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public Rect maxRect = new Rect(0, 0, 0, 0);
|
||||
public bool isPointerEnter;
|
||||
public List<ChartLabel> endLabelList = new List<ChartLabel>();
|
||||
//public Vector3 position = Vector3.zero;
|
||||
public Vector3 pointA = Vector3.zero;
|
||||
public Vector3 pointB = Vector3.zero;
|
||||
public Vector3 pointC = Vector3.zero;
|
||||
public Vector3 pointD = Vector3.zero;
|
||||
public Vector3 pointE = Vector3.zero;
|
||||
public Vector3 pointF = Vector3.zero;
|
||||
public Vector3 pointG = Vector3.zero;
|
||||
public Vector3 pointH = Vector3.zero;
|
||||
}
|
||||
}
|
||||
11
Runtime/Coord/Grid3D/GridCoord3DContext.cs.meta
Normal file
11
Runtime/Coord/Grid3D/GridCoord3DContext.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4a0f1dda078b4877bfabe3c16815498
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
80
Runtime/Coord/Grid3D/GridCoord3DHandler.cs
Normal file
80
Runtime/Coord/Grid3D/GridCoord3DHandler.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class GridCoord3DHandler : MainComponentHandler<GridCoord3D>
|
||||
{
|
||||
public override void InitComponent()
|
||||
{
|
||||
var grid = component;
|
||||
grid.painter = chart.painter;
|
||||
grid.refreshComponent = delegate()
|
||||
{
|
||||
grid.UpdateRuntimeData(chart);
|
||||
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)
|
||||
{
|
||||
component.context.isPointerEnter = component.Contains(chart.pointerPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
component.context.isPointerEnter = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawBase(VertexHelper vh)
|
||||
{
|
||||
if (!SeriesHelper.IsAnyClipSerie(chart.series))
|
||||
{
|
||||
DrawCoord(vh, component);
|
||||
}
|
||||
}
|
||||
public override void DrawUpper(VertexHelper vh)
|
||||
{
|
||||
if (SeriesHelper.IsAnyClipSerie(chart.series))
|
||||
{
|
||||
DrawCoord(vh, component);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCoord(VertexHelper vh, GridCoord3D grid)
|
||||
{
|
||||
if (!grid.show) return;
|
||||
if (grid.showBorder)
|
||||
{
|
||||
var borderWidth = chart.theme.axis.lineWidth * 2;
|
||||
var borderColor = chart.theme.axis.lineColor;
|
||||
UGL.DrawBorder(vh, grid.context.maxRect, borderWidth, borderColor);
|
||||
// UGL.DrawBorder(vh, grid.context.center, grid.context.width - borderWidth,
|
||||
// grid.context.height - borderWidth, borderWidth, borderColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Coord/Grid3D/GridCoord3DHandler.cs.meta
Normal file
11
Runtime/Coord/Grid3D/GridCoord3DHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92481e92b90724f46b3a7e8c585e12e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -13,10 +13,14 @@ namespace XCharts.Runtime
|
||||
var needAnimationData = !axis.context.needAnimation;
|
||||
if (IsAllAxisValue())
|
||||
{
|
||||
if (axis is XAxis)
|
||||
if (axis is XAxis || axis is XAxis3D)
|
||||
{
|
||||
SeriesHelper.GetXMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData);
|
||||
}
|
||||
else if (axis is ZAxis3D)
|
||||
{
|
||||
SeriesHelper.GetZMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData);
|
||||
}
|
||||
else
|
||||
{
|
||||
SeriesHelper.GetYMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData);
|
||||
|
||||
@@ -386,6 +386,11 @@ namespace XCharts.Runtime
|
||||
public int depth = -1;
|
||||
public bool expand = true;
|
||||
public int level = 0;
|
||||
public Vector3 position;
|
||||
public Vector3 delta;
|
||||
public float weight;
|
||||
public float repulsion;
|
||||
public Vector3 pp;
|
||||
|
||||
public GraphNode(string id, string name, int dataIndex)
|
||||
{
|
||||
@@ -472,6 +477,7 @@ namespace XCharts.Runtime
|
||||
|
||||
public List<Vector3> points = new List<Vector3>();
|
||||
public float width;
|
||||
public float distance;
|
||||
public bool highlight;
|
||||
public bool expand = true;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
internal static class DataHelper
|
||||
public static class DataHelper
|
||||
{
|
||||
public static double DataAverage(ref List<SerieData> showData, SampleType sampleType,
|
||||
int minCount, int maxCount, int rate)
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace XCharts.Runtime
|
||||
public static Serie AddDefaultSerie(BaseChart chart, string serieName)
|
||||
{
|
||||
var serie = chart.AddSerie<Candlestick>(serieName);
|
||||
var defaultDataCount = 5;
|
||||
var lastValue = 50d;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
|
||||
@@ -285,7 +285,7 @@ namespace XCharts.Runtime
|
||||
maxCount -= serie.context.dataZoomStartIndexOffset;
|
||||
var scaleWid = AxisHelper.GetDataWidth(axis, axisLength, maxCount, dataZoom);
|
||||
var scaleRelativedWid = AxisHelper.GetDataWidth(relativedAxis, axisRelativedLength, maxCount, dataZoom);
|
||||
int rate = LineHelper.GetDataAverageRate(serie, m_SerieGrid, maxCount, false);
|
||||
int rate = LineHelper.GetDataAverageRate(serie, axisLength, maxCount, false);
|
||||
var totalAverage = serie.sampleAverage > 0 ?
|
||||
serie.sampleAverage :
|
||||
DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
|
||||
|
||||
@@ -5,17 +5,16 @@ using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
internal static class LineHelper
|
||||
public static class LineHelper
|
||||
{
|
||||
private static List<Vector3> s_CurvesPosList = new List<Vector3>();
|
||||
|
||||
public static int GetDataAverageRate(Serie serie, GridCoord grid, int maxCount, bool isYAxis)
|
||||
public static int GetDataAverageRate(Serie serie, float axisLength, int maxCount, bool isYAxis)
|
||||
{
|
||||
var sampleDist = serie.sampleDist;
|
||||
var rate = 0;
|
||||
var width = isYAxis ? grid.context.height : grid.context.width;
|
||||
if (sampleDist > 0)
|
||||
rate = (int)((maxCount - serie.minShow) / (width / sampleDist));
|
||||
rate = (int)((maxCount - serie.minShow) / (axisLength / sampleDist));
|
||||
if (rate < 1)
|
||||
rate = 1;
|
||||
return rate;
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace XCharts.Runtime
|
||||
var scaleWid = AxisHelper.GetDataWidth(axis, axisLength, maxCount, dataZoom);
|
||||
var scaleRelativedWid = AxisHelper.GetDataWidth(relativedAxis, axisRelativedLength, maxCount, dataZoom);
|
||||
|
||||
int rate = LineHelper.GetDataAverageRate(serie, m_SerieGrid, maxCount, false);
|
||||
int rate = LineHelper.GetDataAverageRate(serie, axisLength, maxCount, false);
|
||||
var totalAverage = serie.sampleAverage > 0 ?
|
||||
serie.sampleAverage :
|
||||
DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
|
||||
|
||||
@@ -7,11 +7,23 @@ namespace XCharts.Runtime
|
||||
{
|
||||
public Vector3 position;
|
||||
public bool isIgnoreBreak;
|
||||
public double xValue;
|
||||
public double yValue;
|
||||
public double zValue;
|
||||
|
||||
public PointInfo(Vector3 pos, bool ignore)
|
||||
// public PointInfo(Vector3 pos, bool ignore)
|
||||
// {
|
||||
// this.position = pos;
|
||||
// this.isIgnoreBreak = ignore;
|
||||
// }
|
||||
|
||||
public PointInfo(Vector3 pos, bool ignore, double x = 0, double y = 0, double z = 0)
|
||||
{
|
||||
this.position = pos;
|
||||
this.isIgnoreBreak = ignore;
|
||||
this.xValue = x;
|
||||
this.yValue = y;
|
||||
this.zValue = z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -311,7 +311,7 @@ namespace XCharts.Runtime
|
||||
public static void GetXMinMaxValue(BaseChart chart, int axisIndex, bool inverse, out double minValue,
|
||||
out double maxValue, bool isPolar = false, bool filterByDataZoom = true, bool needAnimation = false)
|
||||
{
|
||||
GetMinMaxValue(chart, axisIndex, inverse, false, out minValue, out maxValue, isPolar, filterByDataZoom, needAnimation);
|
||||
GetMinMaxValue(chart, axisIndex, inverse, 0, out minValue, out maxValue, isPolar, filterByDataZoom, needAnimation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -324,13 +324,26 @@ namespace XCharts.Runtime
|
||||
public static void GetYMinMaxValue(BaseChart chart, int axisIndex, bool inverse, out double minValue,
|
||||
out double maxValue, bool isPolar = false, bool filterByDataZoom = true, bool needAnimation = false)
|
||||
{
|
||||
GetMinMaxValue(chart, axisIndex, inverse, true, out minValue, out maxValue, isPolar, filterByDataZoom, needAnimation);
|
||||
GetMinMaxValue(chart, axisIndex, inverse, 1, out minValue, out maxValue, isPolar, filterByDataZoom, needAnimation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得维度Z的最大最小值
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <param name="axisIndex"></param>
|
||||
/// <param name="minValue"></param>
|
||||
/// <param name="maxValue"></param>
|
||||
public static void GetZMinMaxValue(BaseChart chart, int axisIndex, bool inverse, out double minValue,
|
||||
out double maxValue, bool isPolar = false, bool filterByDataZoom = true, bool needAnimation = false)
|
||||
{
|
||||
GetMinMaxValue(chart, axisIndex, inverse, 2, out minValue, out maxValue, isPolar, filterByDataZoom, needAnimation);
|
||||
}
|
||||
|
||||
private static Dictionary<int, List<Serie>> _stackSeriesForMinMax = new Dictionary<int, List<Serie>>();
|
||||
private static Dictionary<int, double> _serieTotalValueForMinMax = new Dictionary<int, double>();
|
||||
public static void GetMinMaxValue(BaseChart chart, int axisIndex,
|
||||
bool inverse, bool yValue, out double minValue, out double maxValue, bool isPolar = false,
|
||||
bool inverse, int dimension, out double minValue, out double maxValue, bool isPolar = false,
|
||||
bool filterByDataZoom = true, bool needAnimation = false)
|
||||
{
|
||||
double min = double.MaxValue;
|
||||
@@ -371,8 +384,8 @@ namespace XCharts.Runtime
|
||||
var performanceMode = serie.IsPerformanceMode();
|
||||
foreach (var data in showData)
|
||||
{
|
||||
var currData = performanceMode ? data.GetData(yValue ? 1 : 0, inverse) :
|
||||
data.GetCurrData(yValue ? 1 : 0, dataAddDuration, updateDuration, unscaledTime, inverse);
|
||||
var currData = performanceMode ? data.GetData(dimension, inverse) :
|
||||
data.GetCurrData(dimension, dataAddDuration, updateDuration, unscaledTime, inverse);
|
||||
if (!serie.IsIgnoreValue(data, currData))
|
||||
{
|
||||
if (currData > max) max = currData;
|
||||
@@ -419,7 +432,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
else
|
||||
{
|
||||
currData = showData[j].GetCurrData(yValue ? 1 : 0, dataAddDuration, updateDuration, unscaledTime, inverse);
|
||||
currData = showData[j].GetCurrData(dimension, dataAddDuration, updateDuration, unscaledTime, inverse);
|
||||
}
|
||||
if (!serie.IsIgnoreValue(showData[j], currData))
|
||||
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData;
|
||||
|
||||
@@ -310,7 +310,7 @@ namespace XUGL
|
||||
/// <param name="nbp">下一个点的下角点</param>
|
||||
/// <param name="itp">交汇点的上角点</param>
|
||||
/// <param name="ibp">交汇点的下角点</param>
|
||||
internal static void GetLinePoints(Vector3 lp, Vector3 cp, Vector3 np, float width,
|
||||
public static void GetLinePoints(Vector3 lp, Vector3 cp, Vector3 np, float width,
|
||||
ref Vector3 ltp, ref Vector3 lbp,
|
||||
ref Vector3 ntp, ref Vector3 nbp,
|
||||
ref Vector3 itp, ref Vector3 ibp,
|
||||
@@ -397,6 +397,23 @@ namespace XUGL
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
|
||||
public static bool IsPointInPolygon(Vector3 p, params Vector3[] polyons)
|
||||
{
|
||||
if (polyons.Length == 0) return false;
|
||||
var inside = false;
|
||||
var j = polyons.Length - 1;
|
||||
for (int i = 0; i < polyons.Length; j = i++)
|
||||
{
|
||||
var pi = polyons[i];
|
||||
var pj = polyons[j];
|
||||
if (((pi.y <= p.y && p.y < pj.y) || (pj.y <= p.y && p.y < pi.y)) &&
|
||||
(p.x < (pj.x - pi.x) * (p.y - pi.y) / (pj.y - pi.y) + pi.x))
|
||||
inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
|
||||
public static bool IsPointInPolygon(Vector3 p, List<Vector2> polyons)
|
||||
{
|
||||
if (polyons.Count == 0) return false;
|
||||
|
||||
Reference in New Issue
Block a user