UI update 02

This commit is contained in:
2026-06-30 21:21:30 +08:00
parent b2a1e307a4
commit f62f643cfc
1666 changed files with 211081 additions and 22799 deletions
@@ -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: