增加PieRadargridIndex支持设置指定网格

This commit is contained in:
monitor1394
2023-08-29 22:20:29 +08:00
parent e4fbe5670f
commit 8df1dbe0fb
17 changed files with 164 additions and 63 deletions

View File

@@ -621,7 +621,8 @@ namespace XCharts.Runtime
var startY = grid.context.y + xAxis.offset;
if (xAxis.IsTop())
startY += grid.context.height;
else if (xAxis.axisLine.onZero && relativedAxis.IsValue() && relativedAxis.gridIndex == xAxis.gridIndex)
else if (xAxis.axisLine.onZero && relativedAxis != null && relativedAxis.IsValue()
&& relativedAxis.gridIndex == xAxis.gridIndex)
startY += relativedAxis.context.offset;
return startY;
}
@@ -631,7 +632,8 @@ namespace XCharts.Runtime
var startX = grid.context.x + yAxis.offset;
if (yAxis.IsRight())
startX += grid.context.width;
else if (yAxis.axisLine.onZero && relativedAxis.IsValue() && relativedAxis.gridIndex == yAxis.gridIndex)
else if (yAxis.axisLine.onZero && relativedAxis != null && relativedAxis.IsValue()
&& relativedAxis.gridIndex == yAxis.gridIndex)
startX += relativedAxis.context.offset;
return startX;
}

View File

@@ -109,6 +109,7 @@ namespace XCharts.Runtime
[SerializeField] private bool m_ConnectCenter = false;
[SerializeField] private bool m_LineGradient = true;
[SerializeField][Since("v3.4.0")] private float m_StartAngle;
[SerializeField][Since("v3.8.0")] private int m_GridIndex = -1;
[SerializeField] private List<Indicator> m_IndicatorList = new List<Indicator>();
public RadarCoordContext context = new RadarCoordContext();
@@ -120,6 +121,15 @@ namespace XCharts.Runtime
/// </summary>
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } }
/// <summary>
/// Index of layout component that serie uses. Default is -1 means not use layout, otherwise use the first layout component.
/// |所使用的 layout 组件的 index。 默认为-1不指定index, 当为大于或等于0时, 为第一个layout组件的第index个格子。
/// </summary>
public int gridIndex
{
get { return m_GridIndex; }
set { if (PropertyUtil.SetStruct(ref m_GridIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// Radar render type, in which 'Polygon' and 'Circle' are supported.
/// |雷达图绘制类型,支持 'Polygon' 和 'Circle'。
/// </summary>
@@ -286,6 +296,7 @@ namespace XCharts.Runtime
public override void SetDefaultValue()
{
m_Show = true;
m_GridIndex = -1;
m_Shape = Shape.Polygon;
m_Radius = 0.35f;
m_SplitNumber = 5;
@@ -341,9 +352,21 @@ namespace XCharts.Runtime
return 0;
}
internal void UpdateRadarCenter(Vector3 chartPosition, float chartWidth, float chartHeight)
internal void UpdateRadarCenter(BaseChart chart)
{
if (center.Length < 2) return;
var chartPosition = chart.chartPosition;
var chartWidth = chart.chartWidth;
var chartHeight = chart.chartWidth;
if (gridIndex >= 0)
{
var layout = chart.GetChartComponent<GridLayout>(0);
if (layout != null)
{
layout.UpdateRuntimeData(chart);
layout.UpdateGridContext(gridIndex, ref chartPosition, ref chartWidth, ref chartHeight);
}
}
var centerX = center[0] <= 1 ? chartWidth * center[0] : center[0];
var centerY = center[1] <= 1 ? chartHeight * center[1] : center[1];
context.center = chartPosition + new Vector3(centerX, centerY);

View File

@@ -39,7 +39,7 @@ namespace XCharts.Runtime
radar.painter = chart.GetPainter(radar.index);
radar.refreshComponent = delegate()
{
radar.UpdateRadarCenter(chart.chartPosition, chart.chartWidth, chart.chartHeight);
radar.UpdateRadarCenter(chart);
var radarObject = ChartHelper.AddObject("Radar" + radar.index, chart.transform, chart.chartMinAnchor,
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
radar.gameObject = radarObject;
@@ -64,7 +64,7 @@ namespace XCharts.Runtime
private void DrawRadarCoord(VertexHelper vh, RadarCoord radar)
{
if (!radar.show) return;
radar.UpdateRadarCenter(chart.chartPosition, chart.chartWidth, chart.chartHeight);
radar.UpdateRadarCenter(chart);
if (radar.shape == RadarCoord.Shape.Circle)
{
DrawCricleRadar(vh, radar);

View File

@@ -37,6 +37,13 @@ namespace XCharts.Runtime
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>
/// <value></value>
public int layoutIndex
{
get { return m_LayoutIndex; }
@@ -115,67 +122,108 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
}
public bool IsPointerEnter()
{
return context.isPointerEnter;
}
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 context);
return;
layout.UpdateGridContext(index, ref chartX, ref chartY, ref chartWidth, ref chartHeight);
}
}
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;
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 && x <= context.x + context.width;
}
/// <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 && y <= context.y + context.height;
}
/// <summary>
/// Clamp the position of pos to the grid.
/// |将位置限制在网格内。
/// </summary>
/// <param name="pos"></param>
[Since("v3.7.0")]
public void Clamp(ref Vector3 pos)
{
@@ -183,6 +231,11 @@ namespace XCharts.Runtime
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)
{
@@ -190,6 +243,11 @@ namespace XCharts.Runtime
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)
{

View File

@@ -11,10 +11,6 @@ namespace XCharts.Runtime
public float height;
public Vector3 position;
public Vector3 center;
public float left;
public float right;
public float bottom;
public float top;
public bool isPointerEnter;
public List<ChartLabel> endLabelList = new List<ChartLabel>();
}

View File

@@ -6,10 +6,6 @@ namespace XCharts.Runtime
public float y;
public float width;
public float height;
public float left;
public float right;
public float bottom;
public float top;
public float eachWidth;
public float eachHeight;
}

View File

@@ -20,6 +20,7 @@ namespace XCharts.Runtime
[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();
@@ -95,6 +96,15 @@ namespace XCharts.Runtime
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)
{
@@ -102,29 +112,37 @@ namespace XCharts.Runtime
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;
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 GridCoordContext gridContext)
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;
gridContext.x = context.x + column * (context.eachWidth + spacing.x);
gridContext.y = context.y + row * (context.eachHeight + spacing.y);
gridContext.width = context.eachWidth;
gridContext.height = context.eachHeight;
gridContext.position = new Vector3(gridContext.x, gridContext.y);
gridContext.center = new Vector3(gridContext.x + gridContext.width / 2, gridContext.y + gridContext.height / 2);
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);
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 9abc8e277fa0f41c1a0b13133bb736c4
guid: 691ae1f57760b4a948c94f3faa0ef6f4
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -478,7 +478,7 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_ParallelIndex, value)) SetAllDirty(); }
}
/// <summary>
/// Index of layout component that serie uses.
/// Index of layout component that serie uses. Default is -1 means not use layout, otherwise use the first layout component.
/// |所使用的 layout 组件的 index。 默认为-1不指定index, 当为大于或等于0时, 为第一个layout组件的第index个格子。
/// </summary>
public int gridIndex

View File

@@ -221,12 +221,10 @@ namespace XCharts.Runtime
var chartHeight = chart.chartHeight;
if (serie.gridIndex >= 0)
{
var grid = chart.GetChartComponent<GridCoord>(serie.gridIndex);
if (grid != null)
var layout = chart.GetChartComponent<GridLayout>(0);
if (layout != null)
{
chartPosition = grid.context.position;
chartWidth = grid.context.width;
chartHeight = grid.context.height;
layout.UpdateGridContext(serie.gridIndex, ref chartPosition, ref chartWidth, ref chartHeight);
}
}
var centerX = serie.center[0] <= 1 ? chartWidth * serie.center[0] : serie.center[0];