mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-27 11:40:13 +00:00
增加Radar雷达组件更多样式配置参数支持
This commit is contained in:
@@ -30,6 +30,20 @@ namespace XCharts
|
||||
Circle
|
||||
}
|
||||
/// <summary>
|
||||
/// 显示位置。
|
||||
/// </summary>
|
||||
public enum PositionType
|
||||
{
|
||||
/// <summary>
|
||||
/// 显示在顶点处。
|
||||
/// </summary>
|
||||
Vertice,
|
||||
/// <summary>
|
||||
/// 显示在两者之间。
|
||||
/// </summary>
|
||||
Between,
|
||||
}
|
||||
/// <summary>
|
||||
/// Indicator of radar chart, which is used to assign multiple variables(dimensions) in radar chart.
|
||||
/// 雷达图的指示器,用来指定雷达图中的多个变量(维度)。
|
||||
/// </summary>
|
||||
@@ -39,7 +53,8 @@ namespace XCharts
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private float m_Max;
|
||||
[SerializeField] private float m_Min;
|
||||
[SerializeField] private Color m_Color;
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
|
||||
/// <summary>
|
||||
/// 指示器名称。
|
||||
/// </summary>
|
||||
@@ -55,10 +70,10 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public float min { get { return m_Min; } set { m_Min = value; } }
|
||||
/// <summary>
|
||||
/// Specfy a color the the indicator.
|
||||
/// 标签特定的颜色。默认取自主题的axisTextColor。
|
||||
/// the style of text.
|
||||
/// 文本样式。
|
||||
/// </summary>
|
||||
public Color color { get { return m_Color; } set { m_Color = value; } }
|
||||
public TextStyle textStyle { get { return m_TextStyle; } set { m_TextStyle = value; } }
|
||||
/// <summary>
|
||||
/// the text conponent of indicator.
|
||||
/// 指示器的文本组件。
|
||||
@@ -72,7 +87,7 @@ namespace XCharts
|
||||
m_Name = name,
|
||||
m_Max = max,
|
||||
m_Min = min,
|
||||
m_Color = color
|
||||
m_TextStyle = textStyle.Clone()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -99,7 +114,7 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
return m_Name.Equals(other.name) &&
|
||||
ChartHelper.IsValueEqualsColor(m_Color, other.color);
|
||||
m_TextStyle.Equals(other.textStyle);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
@@ -114,6 +129,8 @@ namespace XCharts
|
||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
|
||||
[SerializeField] private AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
|
||||
[SerializeField] private bool m_Indicator = true;
|
||||
[SerializeField] private PositionType m_PositionType = PositionType.Vertice;
|
||||
[SerializeField] private float m_IndicatorGap = 10;
|
||||
[SerializeField] private List<Indicator> m_IndicatorList = new List<Indicator>();
|
||||
/// <summary>
|
||||
/// Radar render type, in which 'Polygon' and 'Circle' are supported.
|
||||
@@ -153,6 +170,14 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public bool indicator { get { return m_Indicator; } set { m_Indicator = value; } }
|
||||
/// <summary>
|
||||
/// 指示器和雷达的间距。
|
||||
/// </summary>
|
||||
public float indicatorGap { get { return m_IndicatorGap; } set { m_IndicatorGap = value; } }
|
||||
/// <summary>
|
||||
/// 指示器显示位置类型。
|
||||
/// </summary>
|
||||
public PositionType positionType { get { return m_PositionType; } set { m_PositionType = value; } }
|
||||
/// <summary>
|
||||
/// the indicator list.
|
||||
/// 指示器列表。
|
||||
/// </summary>
|
||||
@@ -168,6 +193,7 @@ namespace XCharts
|
||||
/// 雷达图的运行时实际半径。
|
||||
/// </summary>
|
||||
public float runtimeRadius { get; internal set; }
|
||||
public float runtimeDataRadius { get; internal set; }
|
||||
/// <summary>
|
||||
/// the data position list of radar.
|
||||
/// 雷达图的所有数据坐标点列表。
|
||||
@@ -216,12 +242,14 @@ namespace XCharts
|
||||
{
|
||||
var radar = new Radar();
|
||||
radar.shape = shape;
|
||||
radar.positionType = positionType;
|
||||
radar.radius = radius;
|
||||
radar.splitNumber = splitNumber;
|
||||
radar.center[0] = center[0];
|
||||
radar.center[1] = center[1];
|
||||
radar.indicatorList.Clear();
|
||||
radar.indicator = indicator;
|
||||
radar.indicatorGap = indicatorGap;
|
||||
foreach (var d in indicatorList) radar.indicatorList.Add(d.Clone());
|
||||
return radar;
|
||||
}
|
||||
@@ -250,10 +278,12 @@ namespace XCharts
|
||||
}
|
||||
return radius == other.radius &&
|
||||
shape == other.shape &&
|
||||
positionType == other.positionType &&
|
||||
splitNumber == other.splitNumber &&
|
||||
center[0] == other.center[0] &&
|
||||
center[1] == other.center[1] &&
|
||||
indicator == other.indicator &&
|
||||
indicatorGap == other.indicatorGap &&
|
||||
IsEqualsIndicatorList(indicatorList, other.indicatorList);
|
||||
}
|
||||
|
||||
@@ -359,14 +389,32 @@ namespace XCharts
|
||||
{
|
||||
runtimeRadius = radius;
|
||||
}
|
||||
if (shape == Radar.Shape.Polygon && positionType == PositionType.Between)
|
||||
{
|
||||
var angle = Mathf.PI / indicatorList.Count;
|
||||
runtimeDataRadius = runtimeRadius * Mathf.Cos(angle);
|
||||
}
|
||||
else
|
||||
{
|
||||
runtimeDataRadius = runtimeRadius;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 GetIndicatorPosition(int index)
|
||||
{
|
||||
int indicatorNum = indicatorList.Count;
|
||||
var angle = 2 * Mathf.PI / indicatorNum * index;
|
||||
var x = runtimeCenterPos.x + runtimeRadius * Mathf.Sin(angle);
|
||||
var y = runtimeCenterPos.y + runtimeRadius * Mathf.Cos(angle);
|
||||
var angle = 0f;
|
||||
switch (positionType)
|
||||
{
|
||||
case PositionType.Vertice:
|
||||
angle = 2 * Mathf.PI / indicatorNum * index;
|
||||
break;
|
||||
case PositionType.Between:
|
||||
angle = 2 * Mathf.PI / indicatorNum * (index + 0.5f);
|
||||
break;
|
||||
}
|
||||
var x = runtimeCenterPos.x + (runtimeRadius + indicatorGap) * Mathf.Sin(angle);
|
||||
var y = runtimeCenterPos.y + (runtimeRadius + indicatorGap) * Mathf.Cos(angle);
|
||||
return new Vector3(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
129
Runtime/Component/Sub/TextStyle.cs
Normal file
129
Runtime/Component/Sub/TextStyle.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System.Threading;
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings related to text.
|
||||
/// 文本的相关设置。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TextStyle : SubComponent, IEquatable<TextStyle>
|
||||
{
|
||||
[SerializeField] private float m_Rotate = 0;
|
||||
[SerializeField] private Vector2 m_Offset = Vector2.zero;
|
||||
[SerializeField] private Color m_Color = Color.clear;
|
||||
[SerializeField] private int m_FontSize = 18;
|
||||
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
|
||||
|
||||
/// <summary>
|
||||
/// Rotation of text.
|
||||
/// 文本的旋转。
|
||||
/// </summary>
|
||||
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
|
||||
/// <summary>
|
||||
/// the offset of position.
|
||||
/// 坐标偏移。
|
||||
/// </summary>
|
||||
public Vector2 offset { get { return m_Offset; } set { m_Offset = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// the color of text.
|
||||
/// 文本的颜色。
|
||||
/// </summary>
|
||||
public Color color { get { return m_Color; } set { m_Color = value; } }
|
||||
/// <summary>
|
||||
/// font size.
|
||||
/// 文本字体大小。
|
||||
/// </summary>
|
||||
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
|
||||
/// <summary>
|
||||
/// font style.
|
||||
/// 文本字体的风格。
|
||||
/// </summary>
|
||||
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
|
||||
|
||||
public TextStyle()
|
||||
{
|
||||
}
|
||||
|
||||
public TextStyle(int fontSize)
|
||||
{
|
||||
this.fontSize = fontSize;
|
||||
}
|
||||
|
||||
public TextStyle(int fontSize, FontStyle fontStyle)
|
||||
{
|
||||
this.fontSize = fontSize;
|
||||
this.fontStyle = fontStyle;
|
||||
}
|
||||
|
||||
public TextStyle(int fontSize, FontStyle fontStyle, Color color)
|
||||
{
|
||||
this.fontSize = fontSize;
|
||||
this.fontStyle = fontStyle;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public TextStyle(int fontSize, FontStyle fontStyle, Color color, int rorate)
|
||||
{
|
||||
this.fontSize = fontSize;
|
||||
this.fontStyle = fontStyle;
|
||||
this.color = color;
|
||||
this.rotate = rotate;
|
||||
}
|
||||
|
||||
public TextStyle Clone()
|
||||
{
|
||||
var textStyle = new TextStyle();
|
||||
textStyle.rotate = rotate;
|
||||
textStyle.color = color;
|
||||
textStyle.fontSize = fontSize;
|
||||
textStyle.fontStyle = fontStyle;
|
||||
textStyle.offset = offset;
|
||||
return textStyle;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj is TextStyle)
|
||||
{
|
||||
return Equals((TextStyle)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(TextStyle other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return rotate == other.rotate &&
|
||||
fontSize == other.fontSize &&
|
||||
fontStyle == other.fontStyle &&
|
||||
offset == other.offset &&
|
||||
ChartHelper.IsValueEqualsColor(m_Color, other.color);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Sub/TextStyle.cs.meta
Normal file
11
Runtime/Component/Sub/TextStyle.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8f6b652968894ab195666501dda672c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user