增加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

@@ -953,7 +953,7 @@ Grid component.
|field|default|since|comment|
|--|--|--|--|
|show|true||Whether to show the grid in rectangular coordinate.
|layoutIndex|-1|v3.8.0|
|layoutIndex|-1|v3.8.0|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.
|left|0.1f||Distance between grid component and the left side of the container.
|right|0.08f||Distance between grid component and the right side of the container.
|top|0.22f||Distance between grid component and the top side of the container.
@@ -990,6 +990,7 @@ Grid layout component. Used to manage the layout of multiple `GridCoord`, and th
|row|2||the row count of grid layout.
|column|2||the column count of grid layout.
|spacing|Vector2.zero||the spacing of grid layout.
|inverse|false||Whether to inverse the grid layout.
```mdx-code-block
</APITable>
@@ -1096,6 +1097,7 @@ Indicator of radar chart, which is used to assign multiple variables(dimensions)
|connectCenter|false||Whether serie data connect to radar center with line.
|lineGradient|true||Whether need gradient for data line.
|startAngle||v3.4.0|起始角度。和时钟一样12点钟位置是0度顺时针到360度。
|gridIndex|-1|v3.8.0|Index of layout component that serie uses. Default is -1 means not use layout, otherwise use the first layout component.
|indicatorList|||the indicator list.
```mdx-code-block
@@ -1734,7 +1736,7 @@ Configurations of select state.
|polarIndex|0||Index of polar component that serie uses.
|singleAxisIndex|0||Index of single axis component that serie uses.
|parallelIndex|0||Index of parallel coord component that serie uses.
|gridIndex|-1|v3.8.0|Index of layout component that serie uses.
|gridIndex|-1|v3.8.0|Index of layout component that serie uses. Default is -1 means not use layout, otherwise use the first layout component.
|minShow|||The min number of data to show in chart.
|maxShow|||The max number of data to show in chart.
|maxCache|||The max number of serie data cache. The first data will be remove when the size of serie data is larger then maxCache.

View File

@@ -78,6 +78,7 @@ slug: /changelog
日志详情:
* (2023.08.29) 增加`Pie``Radar``gridIndex`支持设置指定网格
* (2023.08.29) 增加`GridLayout`网格布局组件用于管理多个`GridCoord`的布局
* (2023.08.25) 修复`MarkLine`多个时只显示一个`Label`的问题
* (2023.08.25) 修复`MarkLine`在开启`Clip`后还绘制在坐标系外的问题

View File

@@ -953,7 +953,7 @@ Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart
|field|default|since|comment|
|--|--|--|--|
|show|true||是否显示直角坐标系网格。
|layoutIndex|-1|v3.8.0|
|layoutIndex|-1|v3.8.0|网格所属的网格布局组件的索引。默认为-1表示不属于任何网格布局组件。当设置了该值时left、right、top、bottom属性将失效。
|left|0.1f||grid 组件离容器左侧的距离。
|right|0.08f||grid 组件离容器右侧的距离。
|top|0.22f||grid 组件离容器上侧的距离。
@@ -990,6 +990,7 @@ Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart
|row|2||网格布局的行数。
|column|2||网格布局的列数。
|spacing|Vector2.zero||网格布局的间距。
|inverse|false||是否反转网格布局。
```mdx-code-block
</APITable>
@@ -1096,6 +1097,7 @@ Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart
|connectCenter|false||数值是否连线到中心点。
|lineGradient|true||数值线段是否需要渐变。
|startAngle||v3.4.0|起始角度。和时钟一样12点钟位置是0度顺时针到360度。
|gridIndex|-1|v3.8.0|所使用的 layout 组件的 index。 默认为-1不指定index, 当为大于或等于0时, 为第一个layout组件的第index个格子。
|indicatorList|||指示器列表。
```mdx-code-block

View File

@@ -9,12 +9,15 @@ namespace XCharts.Editor
public override void OnInspectorGUI()
{
++EditorGUI.indentLevel;
var layoutIndex = baseProperty.FindPropertyRelative("m_LayoutIndex").intValue;
PropertyField("m_LayoutIndex");
PropertyField("m_Left");
PropertyField("m_Right");
PropertyField("m_Top");
PropertyField("m_Bottom");
if (layoutIndex < 0)
{
PropertyField("m_Left");
PropertyField("m_Right");
PropertyField("m_Top");
PropertyField("m_Bottom");
}
PropertyField("m_BackgroundColor");
PropertyField("m_ShowBorder");
PropertyField("m_BorderWidth");

View File

@@ -16,6 +16,7 @@ namespace XCharts.Editor
PropertyField("m_Row");
PropertyField("m_Column");
PropertyField("m_Spacing");
PropertyField("m_Inverse");
--EditorGUI.indentLevel;
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 97c3db8110ca44c3bb088f8af9c56aa6
guid: 4288bf299494d43d497436ace4b7a5a3
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -10,6 +10,7 @@ namespace XCharts.Editor
public override void OnInspectorGUI()
{
++EditorGUI.indentLevel;
PropertyField("m_GridIndex");
PropertyField("m_Shape");
PropertyField("m_PositionType");
PropertyTwoFiled("m_Center");

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];