mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-26 02:40:13 +00:00
增加Pie和Radar的gridIndex支持设置指定网格
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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>();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9abc8e277fa0f41c1a0b13133bb736c4
|
||||
guid: 691ae1f57760b4a948c94f3faa0ef6f4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
Reference in New Issue
Block a user