UI update 02
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da5534d24de514e54911c0efb7b7b2ba
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[Serializable]
|
||||
[ComponentHandler(typeof(CalendarCoordHandler), true)]
|
||||
public class CalendarCoord : CoordSystem, IUpdateRuntimeData, ISerieContainer
|
||||
{
|
||||
public bool IsPointerEnter()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void UpdateRuntimeData(BaseChart chart)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eccc042d880064df8a2a99be68969918
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class CalendarCoordHandler : MainComponentHandler<CalendarCoord>
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57a6c8647580846888712d387da72d1a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d09a247055fa44dcab4eb4c61401a9b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,337 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Grid component.
|
||||
/// ||Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart can be drawn in grid.
|
||||
/// ||网格组件。
|
||||
/// 直角坐标系内绘图网格。可以在网格上绘制折线图,柱状图,散点图。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[ComponentHandler(typeof(GridCoordHandler), true)]
|
||||
public class GridCoord : CoordSystem, IUpdateRuntimeData, ISerieContainer
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField][Since("v3.8.0")] private int m_LayoutIndex = -1;
|
||||
[SerializeField] private float m_Left = 0.11f;
|
||||
[SerializeField] private float m_Right = 0.08f;
|
||||
[SerializeField] private float m_Top = 0.22f;
|
||||
[SerializeField] private float m_Bottom = 0.14f;
|
||||
[SerializeField] private Color32 m_BackgroundColor;
|
||||
[SerializeField] private bool m_ShowBorder = false;
|
||||
[SerializeField] private float m_BorderWidth = 0f;
|
||||
[SerializeField] private Color32 m_BorderColor;
|
||||
|
||||
public GridCoordContext context = new GridCoordContext();
|
||||
|
||||
/// <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>
|
||||
/// The index of the grid layout component to which the grid belongs.
|
||||
/// The default is -1, which means that it does not belong to any grid layout component.
|
||||
/// When this value is set, the left, right, top, and bottom properties will be invalid.
|
||||
/// ||网格所属的网格布局组件的索引。默认为-1,表示不属于任何网格布局组件。当设置了该值时,left、right、top、bottom属性将失效。
|
||||
/// </summary>
|
||||
public int layoutIndex
|
||||
{
|
||||
get { return m_LayoutIndex; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_LayoutIndex, 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>
|
||||
/// Background color of grid, which is transparent by default.
|
||||
/// ||网格背景色,默认透明。
|
||||
/// </summary>
|
||||
public Color32 backgroundColor
|
||||
{
|
||||
get { return m_BackgroundColor; }
|
||||
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <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>
|
||||
/// Border width of grid.
|
||||
/// ||网格边框宽。
|
||||
/// </summary>
|
||||
public float borderWidth
|
||||
{
|
||||
get { return m_BorderWidth; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The color of grid border.
|
||||
/// ||网格边框颜色。
|
||||
/// </summary>
|
||||
public Color32 borderColor
|
||||
{
|
||||
get { return m_BorderColor; }
|
||||
set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
public void UpdateRuntimeData(BaseChart chart)
|
||||
{
|
||||
var chartX = chart.chartX;
|
||||
var chartY = chart.chartY;
|
||||
var chartWidth = chart.chartWidth;
|
||||
var chartHeight = chart.chartHeight;
|
||||
if (layoutIndex >= 0)
|
||||
{
|
||||
var layout = chart.GetChartComponent<GridLayout>(layoutIndex);
|
||||
if (layout != null)
|
||||
{
|
||||
layout.UpdateRuntimeData(chart);
|
||||
layout.UpdateGridContext(index, ref chartX, ref chartY, ref chartWidth, ref chartHeight);
|
||||
}
|
||||
}
|
||||
var actualLeft = left <= 1 ? left * chartWidth : left;
|
||||
var actualBottom = bottom <= 1 ? bottom * chartHeight : bottom;
|
||||
var actualTop = top <= 1 ? top * chartHeight : top;
|
||||
var actualRight = right <= 1 ? right * chartWidth : right;
|
||||
context.x = chartX + actualLeft;
|
||||
context.y = chartY + actualBottom;
|
||||
context.width = chartWidth - actualLeft - actualRight;
|
||||
context.height = chartHeight - actualTop - actualBottom;
|
||||
context.position = new Vector3(context.x, context.y);
|
||||
context.center = new Vector3(context.x + context.width / 2, context.y + context.height / 2);
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
return Contains(pos.x, pos.y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the given position is in the grid.
|
||||
/// ||给定的位置是否在网格内。
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <param name="isYAxis"></param>
|
||||
/// <returns></returns>
|
||||
[Since("v3.7.0")]
|
||||
public bool Contains(Vector3 pos, bool isYAxis)
|
||||
{
|
||||
return isYAxis ? ContainsY(pos.y) : ContainsX(pos.x);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the given position is in the grid.
|
||||
/// ||给定的位置是否在网格内。
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <returns></returns>
|
||||
public bool Contains(float x, float y)
|
||||
{
|
||||
return ContainsX(x) && ContainsY(y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the given x is in the grid.
|
||||
/// ||给定的x是否在网格内。
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <returns></returns>
|
||||
[Since("v3.7.0")]
|
||||
public bool ContainsX(float x)
|
||||
{
|
||||
return x >= context.x - 0.01f && x <= context.x + context.width + 0.01f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the given y is in the grid.
|
||||
/// ||给定的y是否在网格内。
|
||||
/// </summary>
|
||||
/// <param name="y"></param>
|
||||
/// <returns></returns>
|
||||
[Since("v3.7.0")]
|
||||
public bool ContainsY(float y)
|
||||
{
|
||||
return y >= context.y - 0.01f && y <= context.y + context.height + 0.01f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamp the position of pos to the grid.
|
||||
/// ||将位置限制在网格内。
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
[Since("v3.7.0")]
|
||||
public void Clamp(ref Vector3 pos)
|
||||
{
|
||||
ClampX(ref pos);
|
||||
ClampY(ref pos);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamp the x position of pos to the grid.
|
||||
/// ||将位置的X限制在网格内。
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
[Since("v3.7.0")]
|
||||
public void ClampX(ref Vector3 pos)
|
||||
{
|
||||
if (pos.x < context.x) pos.x = context.x;
|
||||
else if (pos.x > context.x + context.width) pos.x = context.x + context.width;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamp the y position of pos to the grid.
|
||||
/// ||将位置的Y限制在网格内。
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
[Since("v3.7.0")]
|
||||
public void ClampY(ref Vector3 pos)
|
||||
{
|
||||
if (pos.y < context.y) pos.y = context.y;
|
||||
else if (pos.y > context.y + context.height) pos.y = context.y + context.height;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
[Since("v3.10.0")]
|
||||
public bool NotAnyIntersect(Vector3 sp, Vector3 ep)
|
||||
{
|
||||
if (sp.x < context.x && ep.x < context.x)
|
||||
return true;
|
||||
if (sp.x > context.x + context.width && ep.x > context.x + context.width)
|
||||
return true;
|
||||
if (sp.y < context.y && ep.y < context.y)
|
||||
return true;
|
||||
if (sp.y > context.y + context.height && ep.y > context.y + context.height)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给定的线段和Grid边界的交点
|
||||
/// </summary>
|
||||
/// <param name="sp"></param>
|
||||
/// <param name="ep"></param>
|
||||
/// <returns></returns>
|
||||
public bool BoundaryPoint(Vector3 sp, Vector3 ep, ref Vector3 point)
|
||||
{
|
||||
if (Contains(sp) && Contains(ep))
|
||||
return false;
|
||||
if (sp.x < context.x && ep.x < context.x)
|
||||
return false;
|
||||
if (sp.x > context.x + context.width && ep.x > context.x + context.width)
|
||||
return false;
|
||||
if (sp.y < context.y && ep.y < context.y)
|
||||
return false;
|
||||
if (sp.y > context.y + context.height && ep.y > context.y + context.height)
|
||||
return false;
|
||||
var lb = new Vector3(context.x, context.y);
|
||||
var lt = new Vector3(context.x, context.y + context.height);
|
||||
var rt = new Vector3(context.x + context.width, context.y + context.height);
|
||||
var rb = new Vector3(context.x + context.width, context.y);
|
||||
if (UGLHelper.GetIntersection(sp, ep, rb, rt, ref point))
|
||||
return true;
|
||||
if (UGLHelper.GetIntersection(sp, ep, lt, rt, ref point))
|
||||
return true;
|
||||
if (UGLHelper.GetIntersection(sp, ep, lb, rb, ref point))
|
||||
return true;
|
||||
if (UGLHelper.GetIntersection(sp, ep, lb, lt, ref point))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给定的线段和Grid边界的交点
|
||||
/// </summary>
|
||||
/// <param name="sp"></param>
|
||||
/// <param name="ep"></param>
|
||||
/// <returns></returns>
|
||||
public bool BoundaryPoint(Vector3 sp, Vector3 ep, ref List<Vector3> point)
|
||||
{
|
||||
if (Contains(sp) && Contains(ep))
|
||||
return false;
|
||||
var lb = new Vector3(context.x, context.y);
|
||||
var lt = new Vector3(context.x, context.y + context.height);
|
||||
var rt = new Vector3(context.x + context.width, context.y + context.height);
|
||||
var rb = new Vector3(context.x + context.width, context.y);
|
||||
var flag = false;
|
||||
if (UGLHelper.GetIntersection(sp, ep, lb, lt, ref point))
|
||||
flag = true;
|
||||
if (UGLHelper.GetIntersection(sp, ep, lt, rt, ref point))
|
||||
flag = true;
|
||||
if (UGLHelper.GetIntersection(sp, ep, lb, rb, ref point))
|
||||
flag = true;
|
||||
if (UGLHelper.GetIntersection(sp, ep, rb, rt, ref point))
|
||||
flag = true;
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f99c74cc7f2c44bfcae9f5c40e6b7c46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public class GridCoordContext : MainComponentContext
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public float width;
|
||||
public float height;
|
||||
public Vector3 position;
|
||||
public Vector3 center;
|
||||
public bool isPointerEnter;
|
||||
public List<ChartLabel> endLabelList = new List<ChartLabel>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a7c139761fe64d93be4c65619a0fd38
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,95 @@
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class GridCoordHandler : MainComponentHandler<GridCoord>
|
||||
{
|
||||
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)
|
||||
{
|
||||
DrawBackground(vh, component);
|
||||
if (!SeriesHelper.IsAnyClipSerie(chart.series))
|
||||
{
|
||||
DrawCoord(vh, component);
|
||||
}
|
||||
}
|
||||
public override void DrawUpper(VertexHelper vh)
|
||||
{
|
||||
if (SeriesHelper.IsAnyClipSerie(chart.series))
|
||||
{
|
||||
DrawCoord(vh, component);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(VertexHelper vh, GridCoord grid)
|
||||
{
|
||||
if (!grid.show) return;
|
||||
if (!ChartHelper.IsClearColor(grid.backgroundColor))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCoord(VertexHelper vh, GridCoord grid)
|
||||
{
|
||||
if (!grid.show) return;
|
||||
if (grid.showBorder)
|
||||
{
|
||||
var borderWidth = grid.borderWidth == 0 ? chart.theme.axis.lineWidth * 2 : grid.borderWidth;
|
||||
var borderColor = ChartHelper.IsClearColor(grid.borderColor) ?
|
||||
chart.theme.axis.lineColor :
|
||||
grid.borderColor;
|
||||
UGL.DrawBorder(vh, grid.context.center, grid.context.width - borderWidth,
|
||||
grid.context.height - borderWidth, borderWidth, borderColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e22a9b603e57459f97040b285f3936a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public class GridLayoutContext : MainComponentContext
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public float width;
|
||||
public float height;
|
||||
public float eachWidth;
|
||||
public float eachHeight;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7265c042ebd33458eb12c112d46d9a60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class GridLayoutHandler : MainComponentHandler<GridLayout>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b1c1f0fa475b484286b0b2c688dc3c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Grid layout component. Used to manage the layout of multiple `GridCoord`, and the number of rows and columns of the grid can be controlled by `row` and `column`.
|
||||
/// ||网格布局组件。用于管理多个`GridCoord`的布局,可以通过`row`和`column`来控制网格的行列数。
|
||||
/// </summary>
|
||||
[Since("v3.8.0")]
|
||||
[Serializable]
|
||||
[ComponentHandler(typeof(GridLayoutHandler), true)]
|
||||
public class GridLayout : MainComponent, IUpdateRuntimeData
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private float m_Left = 0.1f;
|
||||
[SerializeField] private float m_Right = 0.08f;
|
||||
[SerializeField] private float m_Top = 0.22f;
|
||||
[SerializeField] private float m_Bottom = 0.12f;
|
||||
[SerializeField] private int m_Row = 2;
|
||||
[SerializeField] private int m_Column = 2;
|
||||
[SerializeField] private Vector2 m_Spacing = Vector2.zero;
|
||||
[SerializeField] protected bool m_Inverse = false;
|
||||
|
||||
public GridLayoutContext context = new GridLayoutContext();
|
||||
|
||||
/// <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>
|
||||
/// the row count of grid layout.
|
||||
/// ||网格布局的行数。
|
||||
/// </summary>
|
||||
public int row
|
||||
{
|
||||
get { return m_Row; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Row, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the column count of grid layout.
|
||||
/// ||网格布局的列数。
|
||||
/// </summary>
|
||||
public int column
|
||||
{
|
||||
get { return m_Column; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Column, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the spacing of grid layout.
|
||||
/// ||网格布局的间距。
|
||||
/// </summary>
|
||||
public Vector2 spacing
|
||||
{
|
||||
get { return m_Spacing; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Spacing, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether to inverse the grid layout.
|
||||
/// ||是否反转网格布局。
|
||||
/// </summary>
|
||||
public bool inverse
|
||||
{
|
||||
get { return m_Inverse; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Inverse, value)) SetAllDirty(); }
|
||||
}
|
||||
|
||||
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 actualTop = top <= 1 ? top * chartHeight : top;
|
||||
var actualRight = right <= 1 ? right * chartWidth : right;
|
||||
context.x = chartX + actualLeft;
|
||||
context.y = chartY + actualBottom;
|
||||
context.width = chartWidth - actualLeft - actualRight;
|
||||
context.height = chartHeight - actualTop - actualBottom;
|
||||
context.eachWidth = (context.width - spacing.x * (column - 1)) / column;
|
||||
context.eachHeight = (context.height - spacing.y * (row - 1)) / row;
|
||||
}
|
||||
|
||||
internal void UpdateGridContext(int index, ref float x, ref float y, ref float width, ref float height)
|
||||
{
|
||||
var row = index / m_Column;
|
||||
var column = index % m_Column;
|
||||
|
||||
x = context.x + column * (context.eachWidth + spacing.x);
|
||||
if(m_Inverse)
|
||||
y = context.y + row * (context.eachHeight + spacing.y);
|
||||
else
|
||||
y = context.y + context.height - (row + 1) * context.eachHeight - row * spacing.y;
|
||||
width = context.eachWidth;
|
||||
height = context.eachHeight;
|
||||
}
|
||||
|
||||
internal void UpdateGridContext(int index, ref Vector3 position, ref float width, ref float height)
|
||||
{
|
||||
float x = 0, y = 0;
|
||||
UpdateGridContext(index, ref x, ref y, ref width, ref height);
|
||||
position = new Vector3(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 691ae1f57760b4a948c94f3faa0ef6f4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14f9081aa22ba4bcb9cdbfbb95c7221e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95f8c8c3492e54987af59175d94f8761
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4a0f1dda078b4877bfabe3c16815498
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,79 @@
|
||||
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 DrawUpper(VertexHelper vh)
|
||||
{
|
||||
DrawCoord(vh, component);
|
||||
}
|
||||
|
||||
private void DrawCoord(VertexHelper vh, GridCoord3D grid)
|
||||
{
|
||||
if (!grid.show) return;
|
||||
if (grid.showBorder)
|
||||
{
|
||||
var borderWidth = chart.theme.axis.lineWidth;
|
||||
var borderColor = chart.theme.axis.lineColor;
|
||||
if (grid.IsLeft())
|
||||
{
|
||||
UGL.DrawLine(vh, grid.context.pointA, grid.context.pointE, borderWidth, borderColor);
|
||||
UGL.DrawLine(vh, grid.context.pointE, grid.context.pointF, borderWidth, borderColor);
|
||||
UGL.DrawLine(vh, grid.context.pointE, grid.context.pointH, borderWidth, borderColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawLine(vh, grid.context.pointD, grid.context.pointH, borderWidth, borderColor);
|
||||
UGL.DrawLine(vh, grid.context.pointE, grid.context.pointH, borderWidth, borderColor);
|
||||
UGL.DrawLine(vh, grid.context.pointG, grid.context.pointH, borderWidth, borderColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92481e92b90724f46b3a7e8c585e12e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30b1519a34fcc4ca3a56834527584719
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Grid component.
|
||||
/// ||Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart can be drawn in grid.
|
||||
/// ||网格组件。
|
||||
/// 直角坐标系内绘图网格。可以在网格上绘制折线图,柱状图,散点图。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[ComponentHandler(typeof(ParallelCoordHandler), true)]
|
||||
public class ParallelCoord : CoordSystem, IUpdateRuntimeData, ISerieContainer
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] protected Orient m_Orient = Orient.Vertical;
|
||||
[SerializeField] private float m_Left = 0.1f;
|
||||
[SerializeField] private float m_Right = 0.08f;
|
||||
[SerializeField] private float m_Top = 0.22f;
|
||||
[SerializeField] private float m_Bottom = 0.12f;
|
||||
[SerializeField] private Color m_BackgroundColor;
|
||||
|
||||
public ParallelCoordContext context = new ParallelCoordContext();
|
||||
|
||||
/// <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>
|
||||
/// Orientation of the axis. By default, it's 'Vertical'. You can set it to be 'Horizonal' 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 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>
|
||||
/// Background color of grid, which is transparent by default.
|
||||
/// ||网格背景色,默认透明。
|
||||
/// </summary>
|
||||
public Color backgroundColor
|
||||
{
|
||||
get { return m_BackgroundColor; }
|
||||
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
public bool IsPointerEnter()
|
||||
{
|
||||
return context.runtimeIsPointerEnter;
|
||||
}
|
||||
|
||||
public void UpdateRuntimeData(BaseChart chart)
|
||||
{
|
||||
var chartX = chart.chartX;
|
||||
var chartY = chart.chartY;
|
||||
var chartWidth = chart.chartWidth;
|
||||
var chartHeight = chart.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.x = chartX + context.left;
|
||||
context.y = chartY + context.bottom;
|
||||
context.width = chartWidth - context.left - context.right;
|
||||
context.height = chartHeight - context.top - context.bottom;
|
||||
context.position = new Vector3(context.x, context.y);
|
||||
}
|
||||
|
||||
public bool Contains(Vector3 pos)
|
||||
{
|
||||
return Contains(pos.x, pos.y);
|
||||
}
|
||||
|
||||
public bool Contains(float x, float y)
|
||||
{
|
||||
if (x < context.x - 1 || x > context.x + context.width + 1 ||
|
||||
y < context.y - 1 || y > context.y + context.height + 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7be31c76736845a9b2c92a7b8051290
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public class ParallelCoordContext : MainComponentContext
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public float width;
|
||||
public float height;
|
||||
public Vector3 position;
|
||||
public float left;
|
||||
public float right;
|
||||
public float bottom;
|
||||
public float top;
|
||||
public bool runtimeIsPointerEnter;
|
||||
internal List<ParallelAxis> parallelAxes = new List<ParallelAxis>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14f338556609b48568d2504a1b153be7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,176 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class ParallelCoordHandler : MainComponentHandler<ParallelCoord>
|
||||
{
|
||||
private Dictionary<int, double> m_SerieDimMin = new Dictionary<int, double>();
|
||||
private Dictionary<int, double> m_SerieDimMax = new Dictionary<int, double>();
|
||||
private double m_LastInterval;
|
||||
private int m_LastSplitNumber;
|
||||
|
||||
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()
|
||||
{
|
||||
UpdatePointerEnter();
|
||||
UpdateParallelAxisMinMaxValue();
|
||||
}
|
||||
|
||||
public override void DrawBase(VertexHelper vh)
|
||||
{
|
||||
if (!SeriesHelper.IsAnyClipSerie(chart.series))
|
||||
{
|
||||
DrawCoord(vh);
|
||||
}
|
||||
}
|
||||
public override void DrawUpper(VertexHelper vh)
|
||||
{
|
||||
if (SeriesHelper.IsAnyClipSerie(chart.series))
|
||||
{
|
||||
DrawCoord(vh);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCoord(VertexHelper vh)
|
||||
{
|
||||
var grid = component;
|
||||
if (grid.show && !ChartHelper.IsClearColor(grid.backgroundColor))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePointerEnter()
|
||||
{
|
||||
if (chart.isPointerInChart)
|
||||
component.context.runtimeIsPointerEnter = component.Contains(chart.pointerPos);
|
||||
else
|
||||
component.context.runtimeIsPointerEnter = false;
|
||||
}
|
||||
|
||||
private void UpdateParallelAxisMinMaxValue()
|
||||
{
|
||||
var list = chart.GetChartComponents<ParallelAxis>();
|
||||
if (list.Count != component.context.parallelAxes.Count)
|
||||
{
|
||||
component.context.parallelAxes.Clear();
|
||||
foreach (var com in chart.GetChartComponents<ParallelAxis>())
|
||||
{
|
||||
var axis = com as ParallelAxis;
|
||||
if (axis.parallelIndex == component.index)
|
||||
component.context.parallelAxes.Add(axis);
|
||||
}
|
||||
}
|
||||
m_SerieDimMin.Clear();
|
||||
m_SerieDimMax.Clear();
|
||||
foreach (var serie in chart.series)
|
||||
{
|
||||
if ((serie is Parallel) && serie.parallelIndex == component.index)
|
||||
{
|
||||
foreach (var serieData in serie.data)
|
||||
{
|
||||
for (int i = 0; i < serieData.data.Count; i++)
|
||||
{
|
||||
var value = serieData.data[i];
|
||||
if (!m_SerieDimMin.ContainsKey(i))
|
||||
m_SerieDimMin[i] = value;
|
||||
else if (m_SerieDimMin[i] > value)
|
||||
m_SerieDimMin[i] = value;
|
||||
|
||||
if (!m_SerieDimMax.ContainsKey(i))
|
||||
m_SerieDimMax[i] = value;
|
||||
else if (m_SerieDimMax[i] < value)
|
||||
m_SerieDimMax[i] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < component.context.parallelAxes.Count; i++)
|
||||
{
|
||||
var axis = component.context.parallelAxes[i];
|
||||
if (axis.IsCategory())
|
||||
{
|
||||
m_SerieDimMax[i] = axis.data.Count > 0 ? axis.data.Count - 1 : 0;
|
||||
m_SerieDimMin[i] = 0;
|
||||
}
|
||||
else if (axis.minMaxType == Axis.AxisMinMaxType.Custom)
|
||||
{
|
||||
m_SerieDimMin[i] = axis.min;
|
||||
m_SerieDimMax[i] = axis.max;
|
||||
}
|
||||
else if (m_SerieDimMax.ContainsKey(i))
|
||||
{
|
||||
|
||||
var tempMinValue = m_SerieDimMin[i];
|
||||
var tempMaxValue = m_SerieDimMax[i];
|
||||
AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
|
||||
m_SerieDimMin[i] = tempMinValue;
|
||||
m_SerieDimMax[i] = tempMaxValue;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < component.context.parallelAxes.Count; i++)
|
||||
{
|
||||
if (m_SerieDimMax.ContainsKey(i))
|
||||
{
|
||||
var axis = component.context.parallelAxes[i];
|
||||
var tempMinValue = m_SerieDimMin[i];
|
||||
var tempMaxValue = m_SerieDimMax[i];
|
||||
|
||||
if (tempMinValue != axis.context.minValue ||
|
||||
tempMaxValue != axis.context.maxValue ||
|
||||
m_LastInterval != axis.interval ||
|
||||
m_LastSplitNumber != axis.splitNumber)
|
||||
{
|
||||
m_LastSplitNumber = axis.splitNumber;
|
||||
m_LastInterval = axis.interval;
|
||||
|
||||
axis.UpdateMinMaxValue(tempMinValue, tempMaxValue);
|
||||
axis.context.offset = 0;
|
||||
axis.context.lastCheckInverse = axis.inverse;
|
||||
|
||||
(axis.handler as ParallelAxisHander).UpdateAxisTickValueList(axis);
|
||||
(axis.handler as ParallelAxisHander).UpdateAxisLabelText(axis);
|
||||
chart.RefreshChart();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb7323519e00e4916a9c42c5faa36a38
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43b3734481ac34ff89708f2edfa473ca
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Polar coordinate can be used in scatter and line chart. Every polar coordinate has an angleAxis and a radiusAxis.
|
||||
/// ||极坐标系组件。
|
||||
/// 极坐标系,可以用于散点图和折线图。每个极坐标系拥有一个角度轴和一个半径轴。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[ComponentHandler(typeof(PolarCoordHandler), true)]
|
||||
public class PolarCoord : CoordSystem, ISerieContainer
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.44f };
|
||||
[SerializeField] private float[] m_Radius = new float[2] { 0, 0.31f };
|
||||
[SerializeField] private Color m_BackgroundColor;
|
||||
[SerializeField][Since("v3.8.0")] private float m_IndicatorLabelOffset = 30f;
|
||||
|
||||
public PolarCoordContext context = new PolarCoordContext();
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show the polor component.
|
||||
/// ||是否显示极坐标。
|
||||
/// </summary>
|
||||
public bool show
|
||||
{
|
||||
get { return m_Show; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The center of ploar. The center[0] is the x-coordinate, and the center[1] is the y-coordinate.
|
||||
/// When value between 0 and 1 represents a percentage relative to the chart.
|
||||
/// ||极坐标的中心点。数组的第一项是横坐标,第二项是纵坐标。
|
||||
/// 当值为0-1之间时表示百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度。
|
||||
/// </summary>
|
||||
public float[] center
|
||||
{
|
||||
get { return m_Center; }
|
||||
set { if (value != null) { m_Center = value; SetAllDirty(); } }
|
||||
}
|
||||
/// <summary>
|
||||
/// the radius of polar.
|
||||
/// ||半径。radius[0]表示内径,radius[1]表示外径。
|
||||
/// </summary>
|
||||
public float[] radius
|
||||
{
|
||||
get { return m_Radius; }
|
||||
set { if (value != null && value.Length == 2) { m_Radius = value; SetAllDirty(); } }
|
||||
}
|
||||
/// <summary>
|
||||
/// Background color of polar, which is transparent by default.
|
||||
/// ||极坐标的背景色,默认透明。
|
||||
/// </summary>
|
||||
public Color backgroundColor
|
||||
{
|
||||
get { return m_BackgroundColor; }
|
||||
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The offset of indicator label.
|
||||
/// ||指示器标签的偏移量。
|
||||
/// </summary>
|
||||
public float indicatorLabelOffset
|
||||
{
|
||||
get { return m_IndicatorLabelOffset; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_IndicatorLabelOffset, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
public bool IsPointerEnter()
|
||||
{
|
||||
return context.isPointerEnter;
|
||||
}
|
||||
|
||||
public bool Contains(Vector3 pos)
|
||||
{
|
||||
var dist = Vector3.Distance(pos, context.center);
|
||||
return dist >= context.insideRadius && dist <= context.outsideRadius;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec567fac460994411a8aadcb5e0f9b68
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public class PolarCoordContext : MainComponentContext
|
||||
{
|
||||
/// <summary>
|
||||
/// the center position of polar in container.
|
||||
/// ||极坐标在容器中的具体中心点。
|
||||
/// </summary>
|
||||
public Vector3 center;
|
||||
public float radius;
|
||||
/// <summary>
|
||||
/// the true radius of polar.
|
||||
/// ||极坐标的运行时实际内半径。
|
||||
/// </summary>
|
||||
public float insideRadius;
|
||||
/// <summary>
|
||||
/// the true radius of polar.
|
||||
/// ||极坐标的运行时实际外半径。
|
||||
/// </summary>
|
||||
public float outsideRadius;
|
||||
public bool isPointerEnter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2eaaaa315fbae4fc3a9976f51a1396b3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class PolarCoordHandler : MainComponentHandler<PolarCoord>
|
||||
{
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
PolarHelper.UpdatePolarCenter(component, chart.chartPosition, chart.chartWidth, chart.chartHeight);
|
||||
|
||||
if (chart.isPointerInChart)
|
||||
component.context.isPointerEnter = component.Contains(chart.pointerPos);
|
||||
else
|
||||
component.context.isPointerEnter = false;
|
||||
}
|
||||
|
||||
public override void DrawBase(VertexHelper vh)
|
||||
{
|
||||
DrawPolar(vh, component);
|
||||
}
|
||||
|
||||
private void DrawPolar(VertexHelper vh, PolarCoord polar)
|
||||
{
|
||||
PolarHelper.UpdatePolarCenter(polar, chart.chartPosition, chart.chartWidth, chart.chartHeight);
|
||||
if (polar.show && !ChartHelper.IsClearColor(polar.backgroundColor))
|
||||
{
|
||||
if (polar.context.insideRadius > 0)
|
||||
{
|
||||
UGL.DrawDoughnut(vh, polar.context.center,
|
||||
polar.context.insideRadius,
|
||||
polar.context.outsideRadius,
|
||||
polar.backgroundColor,
|
||||
ColorUtil.clearColor32);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawCricle(vh, polar.context.center,
|
||||
polar.context.outsideRadius,
|
||||
polar.backgroundColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af4b941946def4928b416260dec7ac9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
internal static class PolarHelper
|
||||
{
|
||||
public static void UpdatePolarCenter(PolarCoord polar, Vector3 chartPosition, float chartWidth, float chartHeight)
|
||||
{
|
||||
if (polar.center.Length < 2) return;
|
||||
var centerX = polar.center[0] <= 1 ? chartWidth * polar.center[0] : polar.center[0];
|
||||
var centerY = polar.center[1] <= 1 ? chartHeight * polar.center[1] : polar.center[1];
|
||||
var minWidth = Mathf.Min(chartWidth, chartHeight);
|
||||
|
||||
polar.context.center = chartPosition + new Vector3(centerX, centerY);
|
||||
polar.context.insideRadius = polar.context.outsideRadius = 0;
|
||||
if (polar.radius.Length >= 2)
|
||||
{
|
||||
polar.context.insideRadius = ChartHelper.GetActualValue(polar.radius[0], minWidth, 1);
|
||||
polar.context.outsideRadius = ChartHelper.GetActualValue(polar.radius[1], minWidth, 1);
|
||||
}
|
||||
else if (polar.radius.Length >= 1)
|
||||
{
|
||||
polar.context.outsideRadius = ChartHelper.GetActualValue(polar.radius[0], minWidth, 1);
|
||||
}
|
||||
polar.context.radius = polar.context.outsideRadius - polar.context.insideRadius;
|
||||
}
|
||||
|
||||
public static Vector3 UpdatePolarAngleAndPos(PolarCoord polar, AngleAxis angleAxis, RadiusAxis radiusAxis, SerieData serieData)
|
||||
{
|
||||
var value = serieData.GetData(0);
|
||||
var angle = angleAxis.GetValueAngle(serieData.GetData(1));
|
||||
var radius = polar.context.insideRadius + radiusAxis.GetValueLength(value, polar.context.radius);
|
||||
|
||||
angle = (angle + 360) % 360;
|
||||
serieData.context.angle = angle;
|
||||
serieData.context.position = ChartHelper.GetPos(polar.context.center, radius, angle, true);
|
||||
|
||||
return serieData.context.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: feb363cc2ae0846b89612143ce4535ae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 102d61482a6f946cc82f228c88369dfd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[Serializable]
|
||||
[ComponentHandler(null)]
|
||||
public class SingleAxisCoord : CoordSystem
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3e972d6eb5bc45e1ba7b2c5740474fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user