[feature][polar] support circular polar

This commit is contained in:
monitor1394
2022-09-14 07:13:45 +08:00
parent ac7628ce68
commit afbfa20fd9
11 changed files with 50 additions and 32 deletions

View File

@@ -14,7 +14,7 @@ namespace XCharts.Runtime
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.45f };
[SerializeField] private float m_Radius = 0.35f;
[SerializeField] private float[] m_Radius = new float[2] { 0, 0.35f };
[SerializeField] private Color m_BackgroundColor;
public PolarCoordContext context = new PolarCoordContext();
@@ -41,12 +41,12 @@ namespace XCharts.Runtime
}
/// <summary>
/// the radius of polar.
/// |极坐标的半径。
/// |半径。radius[0]表示内径radius[1]表示外径。
/// </summary>
public float radius
public float[] radius
{
get { return m_Radius; }
set { if (PropertyUtil.SetStruct(ref m_Radius, value)) SetAllDirty(); }
set { if (value != null && value.Length == 2) { m_Radius = value; SetAllDirty(); } }
}
/// <summary>
/// Background color of polar, which is transparent by default.
@@ -65,7 +65,8 @@ namespace XCharts.Runtime
public bool Contains(Vector3 pos)
{
return Vector3.Distance(pos, context.center) < context.radius;
var dist = Vector3.Distance(pos, context.center);
return dist >= context.insideRadius && dist <= context.outsideRadius;
}
}
}

View File

@@ -10,11 +10,17 @@ namespace XCharts.Runtime
/// |极坐标在容器中的具体中心点。
/// </summary>
public Vector3 center;
public float radius;
/// <summary>
/// the true radius of polar.
/// |极坐标的运行时实际半径。
/// |极坐标的运行时实际半径。
/// </summary>
public float radius;
public float insideRadius;
/// <summary>
/// the true radius of polar.
/// |极坐标的运行时实际外半径。
/// </summary>
public float outsideRadius;
public bool isPointerEnter;
}
}

View File

@@ -10,6 +10,7 @@ namespace XCharts.Runtime
{
public override void Update()
{
base.Update();
PolarHelper.UpdatePolarCenter(component, chart.chartPosition, chart.chartWidth, chart.chartHeight);
if (chart.isPointerInChart)
@@ -26,9 +27,22 @@ namespace XCharts.Runtime
private void DrawPolar(VertexHelper vh, PolarCoord polar)
{
PolarHelper.UpdatePolarCenter(polar, chart.chartPosition, chart.chartWidth, chart.chartHeight);
if (!ChartHelper.IsClearColor(polar.backgroundColor))
if (polar.show && !ChartHelper.IsClearColor(polar.backgroundColor))
{
UGL.DrawCricle(vh, polar.context.center, polar.context.radius, 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);
}
}
}
}

View File

@@ -9,19 +9,12 @@ namespace XCharts.Runtime
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);
if (polar.radius <= 0)
{
polar.context.radius = 0;
}
else if (polar.radius <= 1)
{
polar.context.radius = Mathf.Min(chartWidth, chartHeight) * polar.radius;
}
else
{
polar.context.radius = polar.radius;
}
polar.context.insideRadius = polar.radius[0] <= 1 ? minWidth * polar.radius[0] : polar.radius[0];
polar.context.outsideRadius = polar.radius[1] <= 1 ? minWidth * polar.radius[1] : polar.radius[1];
polar.context.radius = polar.context.outsideRadius - polar.context.insideRadius;
}
}
}