mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-27 11:40:13 +00:00
增加Serie的radarType参数设置多圈和单圈雷达图
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
# 更新日志
|
# 更新日志
|
||||||
|
|
||||||
|
* (2020.03.20) 增加`Serie`的`radarType`参数设置`多圈`和`单圈`雷达图
|
||||||
* (2020.03.17) 增加`BarChart`可用`ItemStyle`的`backgroundColor`设置数据项背景颜色
|
* (2020.03.17) 增加`BarChart`可用`ItemStyle`的`backgroundColor`设置数据项背景颜色
|
||||||
* (2020.03.17) 增加`SerieData`的`ItemStyle`和`Emphasis`可单独配置数据项样式的支持
|
* (2020.03.17) 增加`SerieData`的`ItemStyle`和`Emphasis`可单独配置数据项样式的支持
|
||||||
* (2020.03.15) 重构`EmptyCricle`类型的`Symbol`边宽取自`ItemStyle`的`borderWidth`
|
* (2020.03.15) 重构`EmptyCricle`类型的`Symbol`边宽取自`ItemStyle`的`borderWidth`参数
|
||||||
* (2020.03.15) 重构`SerieSymbol`,去掉`color`和`opacity`参数,用`ItemStyle`参数代替
|
* (2020.03.15) 重构`SerieSymbol`,去掉`color`和`opacity`参数,用`ItemStyle`参数代替
|
||||||
* (2020.03.14) 发布`v1.3.1`版本
|
* (2020.03.14) 发布`v1.3.1`版本
|
||||||
* (2020.03.14) 修复`LineChart`开启`ingore`时部分数据可能绘制异常的问题
|
* (2020.03.14) 修复`LineChart`开启`ingore`时部分数据可能绘制异常的问题
|
||||||
|
|||||||
@@ -546,9 +546,15 @@
|
|||||||
* `show`:系列是否显示在图表上。
|
* `show`:系列是否显示在图表上。
|
||||||
* `type`:`Radar`。
|
* `type`:`Radar`。
|
||||||
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
|
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
|
||||||
|
* `radarType`:雷达图类型`RadarType`,支持以下类型:
|
||||||
|
* `Multiple`:多圈雷达图。此时可一个雷达里绘制多个圈,一个serieData就可组成一个圈(多维数据)。
|
||||||
|
* `Single`:单圈雷达图。此时一个雷达只能绘制一个圈,多个serieData组成一个圈,数据取自`data[1]`。
|
||||||
* `radarIndex`:雷达图所使用的 `radar` 组件的 `index`。
|
* `radarIndex`:雷达图所使用的 `radar` 组件的 `index`。
|
||||||
* `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。
|
* `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。
|
||||||
* `lineStyle`:线条样式 [LineStyle](#LineStyle)。
|
* `lineStyle`:线条样式 [LineStyle](#LineStyle)。
|
||||||
|
* `itemStyle`:标记样式 [ItemStyle](#ItemStyle)。
|
||||||
|
* `areaStyle`:区域填充样式 [AreaStyle](#AreaStyle)。
|
||||||
|
* `label`:图形上的文本标签 [SerieLabel](#SerieLabel),可用于说明图形的一些数据信息,比如值,名称等。
|
||||||
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
|
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
|
||||||
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1`到`n`维数据。
|
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1`到`n`维数据。
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ namespace XCharts
|
|||||||
SerializedProperty name = prop.FindPropertyRelative("m_Name");
|
SerializedProperty name = prop.FindPropertyRelative("m_Name");
|
||||||
SerializedProperty stack = prop.FindPropertyRelative("m_Stack");
|
SerializedProperty stack = prop.FindPropertyRelative("m_Stack");
|
||||||
SerializedProperty m_AxisIndex = prop.FindPropertyRelative("m_AxisIndex");
|
SerializedProperty m_AxisIndex = prop.FindPropertyRelative("m_AxisIndex");
|
||||||
|
SerializedProperty m_RadarType = prop.FindPropertyRelative("m_RadarType");
|
||||||
SerializedProperty m_RadarIndex = prop.FindPropertyRelative("m_RadarIndex");
|
SerializedProperty m_RadarIndex = prop.FindPropertyRelative("m_RadarIndex");
|
||||||
SerializedProperty m_MinShow = prop.FindPropertyRelative("m_MinShow");
|
SerializedProperty m_MinShow = prop.FindPropertyRelative("m_MinShow");
|
||||||
SerializedProperty m_MaxShow = prop.FindPropertyRelative("m_MaxShow");
|
SerializedProperty m_MaxShow = prop.FindPropertyRelative("m_MaxShow");
|
||||||
@@ -213,6 +214,8 @@ namespace XCharts
|
|||||||
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
|
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
|
||||||
break;
|
break;
|
||||||
case SerieType.Radar:
|
case SerieType.Radar:
|
||||||
|
EditorGUI.PropertyField(drawRect, m_RadarType);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_RadarIndex);
|
EditorGUI.PropertyField(drawRect, m_RadarIndex);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_Symbol);
|
EditorGUI.PropertyField(drawRect, m_Symbol);
|
||||||
@@ -223,6 +226,8 @@ namespace XCharts
|
|||||||
drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle);
|
drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle);
|
||||||
EditorGUI.PropertyField(drawRect, m_AreaStyle);
|
EditorGUI.PropertyField(drawRect, m_AreaStyle);
|
||||||
drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle);
|
drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle);
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Label);
|
||||||
|
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
|
||||||
EditorGUI.PropertyField(drawRect, m_Emphasis);
|
EditorGUI.PropertyField(drawRect, m_Emphasis);
|
||||||
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
|
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
|
||||||
break;
|
break;
|
||||||
@@ -490,11 +495,12 @@ namespace XCharts
|
|||||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
|
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
|
||||||
break;
|
break;
|
||||||
case SerieType.Radar:
|
case SerieType.Radar:
|
||||||
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
|
height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
|
||||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
|
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
|
||||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
|
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
|
||||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle"));
|
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_ItemStyle"));
|
||||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AreaStyle"));
|
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AreaStyle"));
|
||||||
|
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
|
||||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
|
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
|
||||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
|
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ namespace XCharts
|
|||||||
/// the center position of radar in container.
|
/// the center position of radar in container.
|
||||||
/// 雷达图在容器中的具体中心点。
|
/// 雷达图在容器中的具体中心点。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Vector2 runtimeCenterPos { get; internal set; }
|
public Vector3 runtimeCenterPos { get; internal set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the true radius of radar.
|
/// the true radius of radar.
|
||||||
/// 雷达图的运行时实际半径。
|
/// 雷达图的运行时实际半径。
|
||||||
|
|||||||
@@ -165,6 +165,20 @@ namespace XCharts
|
|||||||
ProgressBar
|
ProgressBar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 雷达图类型
|
||||||
|
/// </summary>
|
||||||
|
public enum RadarType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 多圈雷达图。此时可一个雷达里绘制多个圈,一个serieData就可组成一个圈(多维数据)。
|
||||||
|
/// </summary>
|
||||||
|
Multiple,
|
||||||
|
/// <summary>
|
||||||
|
/// 单圈雷达图。此时一个雷达只能绘制一个圈,多个serieData组成一个圈,数据取自`data[1]`。
|
||||||
|
/// </summary>
|
||||||
|
Single
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 采样类型
|
/// 采样类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -256,6 +270,7 @@ namespace XCharts
|
|||||||
[SerializeField] private bool m_Clip = true;
|
[SerializeField] private bool m_Clip = true;
|
||||||
[SerializeField] private bool m_Ignore = false;
|
[SerializeField] private bool m_Ignore = false;
|
||||||
[SerializeField] private float m_IgnoreValue = 0;
|
[SerializeField] private float m_IgnoreValue = 0;
|
||||||
|
[SerializeField] private RadarType m_RadarType = RadarType.Multiple;
|
||||||
|
|
||||||
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
|
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
|
||||||
|
|
||||||
@@ -627,6 +642,14 @@ namespace XCharts
|
|||||||
set { if (PropertyUtility.SetStruct(ref m_IgnoreValue, value)) SetVerticesDirty(); }
|
set { if (PropertyUtility.SetStruct(ref m_IgnoreValue, value)) SetVerticesDirty(); }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 雷达图类型。
|
||||||
|
/// </summary>
|
||||||
|
public RadarType radarType
|
||||||
|
{
|
||||||
|
get { return m_RadarType; }
|
||||||
|
set { if (PropertyUtility.SetStruct(ref m_RadarType, value)) SetVerticesDirty(); }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// 仪表盘轴线。
|
/// 仪表盘轴线。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public GaugeAxis gaugeAxis
|
public GaugeAxis gaugeAxis
|
||||||
@@ -1413,9 +1436,9 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
internal float GetBarWidth(float categoryWidth)
|
internal float GetBarWidth(float categoryWidth)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ namespace XCharts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否启用单个数据项的高亮样式。
|
/// 是否启用单个数据项的高亮样式。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool enableEmphasis{ get { return m_EnableEmphasis; } set { m_EnableEmphasis = value; } }
|
public bool enableEmphasis { get { return m_EnableEmphasis; } set { m_EnableEmphasis = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 单个数据项的高亮样式设置。
|
/// 单个数据项的高亮样式设置。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -172,7 +172,6 @@ namespace XCharts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public float runtimePieOffsetRadius { get; internal set; }
|
public float runtimePieOffsetRadius { get; internal set; }
|
||||||
public Vector3 runtiemPieOffsetCenter { get; internal set; }
|
public Vector3 runtiemPieOffsetCenter { get; internal set; }
|
||||||
|
|
||||||
private List<float> m_PreviousData = new List<float>();
|
private List<float> m_PreviousData = new List<float>();
|
||||||
private List<float> m_DataUpdateTime = new List<float>();
|
private List<float> m_DataUpdateTime = new List<float>();
|
||||||
private List<bool> m_DataUpdateFlag = new List<bool>();
|
private List<bool> m_DataUpdateFlag = new List<bool>();
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ namespace XCharts
|
|||||||
radar.ClearDirty();
|
radar.ClearDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_RadarsDirty = false;
|
||||||
}
|
}
|
||||||
base.CheckComponent();
|
base.CheckComponent();
|
||||||
}
|
}
|
||||||
@@ -205,134 +206,320 @@ namespace XCharts
|
|||||||
Dictionary<string, int> serieNameSet = new Dictionary<string, int>();
|
Dictionary<string, int> serieNameSet = new Dictionary<string, int>();
|
||||||
private void DrawData(VertexHelper vh)
|
private void DrawData(VertexHelper vh)
|
||||||
{
|
{
|
||||||
Vector3 startPoint = Vector3.zero;
|
|
||||||
Vector3 toPoint = Vector3.zero;
|
|
||||||
Vector3 firstPoint = Vector3.zero;
|
|
||||||
|
|
||||||
serieNameSet.Clear();
|
serieNameSet.Clear();
|
||||||
int serieNameCount = -1;
|
|
||||||
for (int i = 0; i < m_Series.Count; i++)
|
for (int i = 0; i < m_Series.Count; i++)
|
||||||
{
|
{
|
||||||
var serie = m_Series.list[i];
|
var serie = m_Series.list[i];
|
||||||
var radar = m_Radars[serie.radarIndex];
|
serie.index = i;
|
||||||
int indicatorNum = radar.indicatorList.Count;
|
switch (serie.radarType)
|
||||||
var angle = 2 * Mathf.PI / indicatorNum;
|
{
|
||||||
Vector3 p = radar.runtimeCenterPos;
|
case RadarType.Multiple:
|
||||||
serie.animation.InitProgress(1, 0, 1);
|
DrawMutipleRadar(vh, serie, i);
|
||||||
if (!IsActive(i) || serie.animation.HasFadeOut())
|
break;
|
||||||
|
case RadarType.Single:
|
||||||
|
DrawSingleRadar(vh, serie, i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawMutipleRadar(VertexHelper vh, Serie serie, int i)
|
||||||
|
{
|
||||||
|
var startPoint = Vector3.zero;
|
||||||
|
var toPoint = Vector3.zero;
|
||||||
|
var firstPoint = Vector3.zero;
|
||||||
|
|
||||||
|
var radar = m_Radars[serie.radarIndex];
|
||||||
|
var indicatorNum = radar.indicatorList.Count;
|
||||||
|
var angle = 2 * Mathf.PI / indicatorNum;
|
||||||
|
var centerPos = radar.runtimeCenterPos;
|
||||||
|
var serieNameCount = -1;
|
||||||
|
serie.animation.InitProgress(1, 0, 1);
|
||||||
|
if (!IsActive(i) || serie.animation.HasFadeOut())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var rate = serie.animation.GetCurrRate();
|
||||||
|
var dataChanging = false;
|
||||||
|
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||||
|
for (int j = 0; j < serie.data.Count; j++)
|
||||||
|
{
|
||||||
|
var serieData = serie.data[j];
|
||||||
|
int key = i * 1000 + j;
|
||||||
|
if (!radar.runtimeDataPosList.ContainsKey(key))
|
||||||
|
{
|
||||||
|
radar.runtimeDataPosList.Add(i * 1000 + j, new List<Vector3>(serieData.data.Count));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
radar.runtimeDataPosList[key].Clear();
|
||||||
|
}
|
||||||
|
string dataName = serieData.name;
|
||||||
|
int serieIndex = 0;
|
||||||
|
if (string.IsNullOrEmpty(dataName))
|
||||||
|
{
|
||||||
|
serieNameCount++;
|
||||||
|
serieIndex = serieNameCount;
|
||||||
|
}
|
||||||
|
else if (!serieNameSet.ContainsKey(dataName))
|
||||||
|
{
|
||||||
|
serieNameSet.Add(dataName, serieNameCount);
|
||||||
|
serieNameCount++;
|
||||||
|
serieIndex = serieNameCount;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serieIndex = serieNameSet[dataName];
|
||||||
|
}
|
||||||
|
if (!serieData.show)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var rate = serie.animation.GetCurrRate();
|
var isHighlight = serie.highlighted || serieData.highlighted ||
|
||||||
var dataChanging = false;
|
(m_Tooltip.show && m_Tooltip.runtimeDataIndex[0] == i && m_Tooltip.runtimeDataIndex[1] == j);
|
||||||
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
var areaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, serieIndex, isHighlight);
|
||||||
for (int j = 0; j < serie.data.Count; j++)
|
var areaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, serieIndex, isHighlight);
|
||||||
|
var lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, serieIndex, isHighlight);
|
||||||
|
int dataCount = radar.indicatorList.Count;
|
||||||
|
List<Vector3> pointList = radar.runtimeDataPosList[key];
|
||||||
|
for (int n = 0; n < dataCount; n++)
|
||||||
{
|
{
|
||||||
var serieData = serie.data[j];
|
if (n >= serieData.data.Count) break;
|
||||||
int key = i * 100 + j;
|
float min = radar.GetIndicatorMin(n);
|
||||||
if (!radar.runtimeDataPosList.ContainsKey(key))
|
float max = radar.GetIndicatorMax(n);
|
||||||
|
float value = serieData.GetCurrData(n, dataChangeDuration);
|
||||||
|
if (serieData.IsDataChanged()) dataChanging = true;
|
||||||
|
if (max == 0)
|
||||||
{
|
{
|
||||||
radar.runtimeDataPosList.Add(i * 100 + j, new List<Vector3>(serieData.data.Count));
|
serie.GetMinMaxData(n, out min, out max);
|
||||||
|
min = radar.GetIndicatorMin(n);
|
||||||
|
}
|
||||||
|
var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
|
||||||
|
: radar.runtimeDataRadius * value / max;
|
||||||
|
var currAngle = (n + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle;
|
||||||
|
radius *= rate;
|
||||||
|
if (n == 0)
|
||||||
|
{
|
||||||
|
startPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle),
|
||||||
|
centerPos.y + radius * Mathf.Cos(currAngle));
|
||||||
|
firstPoint = startPoint;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
radar.runtimeDataPosList[key].Clear();
|
toPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle),
|
||||||
}
|
centerPos.y + radius * Mathf.Cos(currAngle));
|
||||||
string dataName = serieData.name;
|
if (serie.areaStyle.show)
|
||||||
int serieIndex = 0;
|
|
||||||
if (string.IsNullOrEmpty(dataName))
|
|
||||||
{
|
|
||||||
serieNameCount++;
|
|
||||||
serieIndex = serieNameCount;
|
|
||||||
}
|
|
||||||
else if (!serieNameSet.ContainsKey(dataName))
|
|
||||||
{
|
|
||||||
serieNameSet.Add(dataName, serieNameCount);
|
|
||||||
serieNameCount++;
|
|
||||||
serieIndex = serieNameCount;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
serieIndex = serieNameSet[dataName];
|
|
||||||
}
|
|
||||||
if (!serieData.show)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var isHighlight = serie.highlighted || serieData.highlighted ||
|
|
||||||
(m_Tooltip.show && m_Tooltip.runtimeDataIndex[0] == i && m_Tooltip.runtimeDataIndex[1] == j);
|
|
||||||
var areaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, serieIndex, isHighlight);
|
|
||||||
var areaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, serieIndex, isHighlight);
|
|
||||||
var lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, serieIndex, isHighlight);
|
|
||||||
int dataCount = radar.indicatorList.Count;
|
|
||||||
List<Vector3> pointList = radar.runtimeDataPosList[key];
|
|
||||||
for (int n = 0; n < dataCount; n++)
|
|
||||||
{
|
|
||||||
if (n >= serieData.data.Count) break;
|
|
||||||
float min = radar.GetIndicatorMin(n);
|
|
||||||
float max = radar.GetIndicatorMax(n);
|
|
||||||
float value = serieData.GetCurrData(n, dataChangeDuration);
|
|
||||||
if (serieData.IsDataChanged()) dataChanging = true;
|
|
||||||
if (max == 0)
|
|
||||||
{
|
{
|
||||||
serie.GetMinMaxData(n, out min, out max);
|
ChartDrawer.DrawTriangle(vh, startPoint, toPoint, centerPos, areaColor, areaColor, areaToColor);
|
||||||
min = radar.GetIndicatorMin(n);
|
|
||||||
}
|
}
|
||||||
var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
|
if (serie.lineStyle.show)
|
||||||
: radar.runtimeDataRadius * value / max;
|
|
||||||
var currAngle = (n + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle;
|
|
||||||
radius *= rate;
|
|
||||||
if (n == 0)
|
|
||||||
{
|
{
|
||||||
startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor);
|
||||||
p.y + radius * Mathf.Cos(currAngle));
|
|
||||||
firstPoint = startPoint;
|
|
||||||
}
|
}
|
||||||
else
|
startPoint = toPoint;
|
||||||
{
|
|
||||||
toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
|
||||||
p.y + radius * Mathf.Cos(currAngle));
|
|
||||||
if (serie.areaStyle.show)
|
|
||||||
{
|
|
||||||
ChartDrawer.DrawTriangle(vh, startPoint, toPoint, p, areaColor, areaColor, areaToColor);
|
|
||||||
}
|
|
||||||
if (serie.lineStyle.show)
|
|
||||||
{
|
|
||||||
DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor);
|
|
||||||
}
|
|
||||||
startPoint = toPoint;
|
|
||||||
}
|
|
||||||
pointList.Add(startPoint);
|
|
||||||
}
|
}
|
||||||
|
pointList.Add(startPoint);
|
||||||
|
}
|
||||||
|
if (serie.areaStyle.show)
|
||||||
|
{
|
||||||
|
ChartDrawer.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor);
|
||||||
|
}
|
||||||
|
if (serie.lineStyle.show)
|
||||||
|
{
|
||||||
|
DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor);
|
||||||
|
}
|
||||||
|
if (serie.symbol.type != SerieSymbolType.None)
|
||||||
|
{
|
||||||
|
var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size);
|
||||||
|
var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight);
|
||||||
|
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight);
|
||||||
|
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, isHighlight);
|
||||||
|
foreach (var point in pointList)
|
||||||
|
{
|
||||||
|
DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor,
|
||||||
|
symbolToColor, serie.symbol.gap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!serie.animation.IsFinish())
|
||||||
|
{
|
||||||
|
serie.animation.CheckProgress(1);
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
if (dataChanging)
|
||||||
|
{
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawSingleRadar(VertexHelper vh, Serie serie, int i)
|
||||||
|
{
|
||||||
|
var startPoint = Vector3.zero;
|
||||||
|
var toPoint = Vector3.zero;
|
||||||
|
var firstPoint = Vector3.zero;
|
||||||
|
|
||||||
|
var radar = m_Radars[serie.radarIndex];
|
||||||
|
var indicatorNum = radar.indicatorList.Count;
|
||||||
|
var angle = 2 * Mathf.PI / indicatorNum;
|
||||||
|
var centerPos = radar.runtimeCenterPos;
|
||||||
|
var serieNameCount = -1;
|
||||||
|
serie.animation.InitProgress(1, 0, 1);
|
||||||
|
if (!IsActive(i) || serie.animation.HasFadeOut())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var rate = serie.animation.GetCurrRate();
|
||||||
|
var dataChanging = false;
|
||||||
|
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||||
|
int key = i * 1000;
|
||||||
|
if (!radar.runtimeDataPosList.ContainsKey(key))
|
||||||
|
{
|
||||||
|
radar.runtimeDataPosList.Add(i * 1000, new List<Vector3>(serie.dataCount));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
radar.runtimeDataPosList[key].Clear();
|
||||||
|
}
|
||||||
|
var pointList = radar.runtimeDataPosList[key];
|
||||||
|
var startIndex = GetStartShowIndex(serie);
|
||||||
|
var endIndex = GetEndShowIndex(serie);
|
||||||
|
for (int j = 0; j < serie.data.Count; j++)
|
||||||
|
{
|
||||||
|
var serieData = serie.data[j];
|
||||||
|
serieData.index = j;
|
||||||
|
string dataName = serieData.name;
|
||||||
|
int serieIndex = 0;
|
||||||
|
if (string.IsNullOrEmpty(dataName))
|
||||||
|
{
|
||||||
|
serieNameCount++;
|
||||||
|
serieIndex = serieNameCount;
|
||||||
|
}
|
||||||
|
else if (!serieNameSet.ContainsKey(dataName))
|
||||||
|
{
|
||||||
|
serieNameSet.Add(dataName, serieNameCount);
|
||||||
|
serieNameCount++;
|
||||||
|
serieIndex = serieNameCount;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serieIndex = serieNameSet[dataName];
|
||||||
|
}
|
||||||
|
if (!serieData.show)
|
||||||
|
{
|
||||||
|
serieData.labelPosition = Vector3.zero;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var isHighlight = serie.highlighted || serieData.highlighted ||
|
||||||
|
(m_Tooltip.show && m_Tooltip.runtimeDataIndex[0] == i && m_Tooltip.runtimeDataIndex[1] == j);
|
||||||
|
var areaColor = SerieHelper.GetAreaColor(serie, m_ThemeInfo, serieIndex, isHighlight);
|
||||||
|
var areaToColor = SerieHelper.GetAreaToColor(serie, m_ThemeInfo, serieIndex, isHighlight);
|
||||||
|
var lineColor = SerieHelper.GetLineColor(serie, m_ThemeInfo, serieIndex, isHighlight);
|
||||||
|
int dataCount = radar.indicatorList.Count;
|
||||||
|
var index = serieData.index;
|
||||||
|
var p = radar.runtimeCenterPos;
|
||||||
|
var min = radar.GetIndicatorMin(index);
|
||||||
|
var max = radar.GetIndicatorMax(index);
|
||||||
|
var value = serieData.GetCurrData(1, dataChangeDuration);
|
||||||
|
if (serieData.IsDataChanged()) dataChanging = true;
|
||||||
|
if (max == 0)
|
||||||
|
{
|
||||||
|
serie.GetMinMaxData(index, out min, out max);
|
||||||
|
min = radar.GetIndicatorMin(index);
|
||||||
|
}
|
||||||
|
var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
|
||||||
|
: radar.runtimeDataRadius * value / max;
|
||||||
|
var currAngle = (index + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle;
|
||||||
|
radius *= rate;
|
||||||
|
if (index == startIndex)
|
||||||
|
{
|
||||||
|
startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
||||||
|
p.y + radius * Mathf.Cos(currAngle));
|
||||||
|
firstPoint = startPoint;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
||||||
|
p.y + radius * Mathf.Cos(currAngle));
|
||||||
if (serie.areaStyle.show)
|
if (serie.areaStyle.show)
|
||||||
{
|
{
|
||||||
ChartDrawer.DrawTriangle(vh, startPoint, firstPoint, p, areaColor, areaColor, areaToColor);
|
ChartDrawer.DrawTriangle(vh, startPoint, toPoint, p, areaColor, areaColor, areaToColor);
|
||||||
}
|
}
|
||||||
if (serie.lineStyle.show)
|
if (serie.lineStyle.show)
|
||||||
{
|
{
|
||||||
DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor);
|
DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor);
|
||||||
}
|
|
||||||
if (serie.symbol.type != SerieSymbolType.None)
|
|
||||||
{
|
|
||||||
var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size);
|
|
||||||
var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight);
|
|
||||||
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight);
|
|
||||||
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, isHighlight);
|
|
||||||
foreach (var point in pointList)
|
|
||||||
{
|
|
||||||
DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor,
|
|
||||||
symbolToColor, serie.symbol.gap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
startPoint = toPoint;
|
||||||
}
|
}
|
||||||
if (!serie.animation.IsFinish())
|
serieData.labelPosition = startPoint;
|
||||||
|
pointList.Add(startPoint);
|
||||||
|
|
||||||
|
if (serie.areaStyle.show && j == endIndex)
|
||||||
{
|
{
|
||||||
serie.animation.CheckProgress(1);
|
ChartDrawer.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor);
|
||||||
RefreshChart();
|
|
||||||
}
|
}
|
||||||
if (dataChanging)
|
if (serie.lineStyle.show && j == endIndex)
|
||||||
{
|
{
|
||||||
RefreshChart();
|
DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (serie.symbol.type != SerieSymbolType.None)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < serie.data.Count; j++)
|
||||||
|
{
|
||||||
|
var serieData = serie.data[j];
|
||||||
|
if (!serieData.show) continue;
|
||||||
|
var isHighlight = serie.highlighted || serieData.highlighted ||
|
||||||
|
(m_Tooltip.show && m_Tooltip.runtimeDataIndex[0] == i && m_Tooltip.runtimeDataIndex[1] == j);
|
||||||
|
var serieIndex = serieData.index;
|
||||||
|
var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size);
|
||||||
|
var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight);
|
||||||
|
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight);
|
||||||
|
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, isHighlight);
|
||||||
|
DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, serieData.labelPosition, symbolColor,
|
||||||
|
symbolToColor, serie.symbol.gap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!serie.animation.IsFinish())
|
||||||
|
{
|
||||||
|
serie.animation.CheckProgress(1);
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
if (dataChanging)
|
||||||
|
{
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int GetStartShowIndex(Serie serie)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < serie.dataCount; i++)
|
||||||
|
{
|
||||||
|
if (serie.data[i].show) return i;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
private int GetEndShowIndex(Serie serie)
|
||||||
|
{
|
||||||
|
for (int i = serie.dataCount - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (serie.data[i].show) return i;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawRadarSymbol(VertexHelper vh, Serie serie, SerieData serieData, int serieIndex, bool isHighlight,
|
||||||
|
List<Vector3> pointList)
|
||||||
|
{
|
||||||
|
if (serie.symbol.type != SerieSymbolType.None)
|
||||||
|
{
|
||||||
|
var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size);
|
||||||
|
var symbolColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight);
|
||||||
|
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieIndex, isHighlight);
|
||||||
|
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, isHighlight);
|
||||||
|
foreach (var point in pointList)
|
||||||
|
{
|
||||||
|
DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor,
|
||||||
|
symbolToColor, serie.symbol.gap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -449,15 +636,33 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int n = 0; n < serie.data.Count; n++)
|
switch (serie.radarType)
|
||||||
{
|
{
|
||||||
var posKey = i * 100 + n;
|
case RadarType.Multiple:
|
||||||
if (radar.runtimeDataPosList.ContainsKey(posKey))
|
for (int n = 0; n < serie.data.Count; n++)
|
||||||
{
|
|
||||||
var posList = radar.runtimeDataPosList[posKey];
|
|
||||||
foreach (var pos in posList)
|
|
||||||
{
|
{
|
||||||
if (Vector2.Distance(pos, local) <= serie.symbol.size * 1.2f)
|
var posKey = i * 1000 + n;
|
||||||
|
if (radar.runtimeDataPosList.ContainsKey(posKey))
|
||||||
|
{
|
||||||
|
var posList = radar.runtimeDataPosList[posKey];
|
||||||
|
foreach (var pos in posList)
|
||||||
|
{
|
||||||
|
if (Vector2.Distance(pos, local) <= serie.symbol.size * 1.2f)
|
||||||
|
{
|
||||||
|
m_Tooltip.runtimeDataIndex[0] = i;
|
||||||
|
m_Tooltip.runtimeDataIndex[1] = n;
|
||||||
|
highlight = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RadarType.Single:
|
||||||
|
for (int n = 0; n < serie.data.Count; n++)
|
||||||
|
{
|
||||||
|
var serieData = serie.data[n];
|
||||||
|
if (Vector2.Distance(serieData.labelPosition, local) <= serie.symbol.size * 1.2f)
|
||||||
{
|
{
|
||||||
m_Tooltip.runtimeDataIndex[0] = i;
|
m_Tooltip.runtimeDataIndex[0] = i;
|
||||||
m_Tooltip.runtimeDataIndex[1] = n;
|
m_Tooltip.runtimeDataIndex[1] = n;
|
||||||
@@ -465,8 +670,9 @@ namespace XCharts
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!highlight)
|
if (!highlight)
|
||||||
@@ -501,14 +707,30 @@ namespace XCharts
|
|||||||
m_Tooltip.SetActive(true);
|
m_Tooltip.SetActive(true);
|
||||||
var serie = m_Series.GetSerie(serieIndex);
|
var serie = m_Series.GetSerie(serieIndex);
|
||||||
var radar = m_Radars[serie.radarIndex];
|
var radar = m_Radars[serie.radarIndex];
|
||||||
var serieData = serie.GetSerieData(m_Tooltip.runtimeDataIndex[1]);
|
var dataIndex = m_Tooltip.runtimeDataIndex[1];
|
||||||
StringBuilder sb = new StringBuilder(serieData.name);
|
var serieData = serie.GetSerieData(dataIndex);
|
||||||
for (int i = 0; i < radar.indicatorList.Count; i++)
|
StringBuilder sb = new StringBuilder();
|
||||||
|
switch (serie.radarType)
|
||||||
{
|
{
|
||||||
string key = radar.indicatorList[i].name;
|
case RadarType.Multiple:
|
||||||
float value = serieData.GetData(i);
|
sb.Append(serieData.name);
|
||||||
if ((i == 0 && !string.IsNullOrEmpty(serieData.name)) || i > 0) sb.Append("\n");
|
for (int i = 0; i < radar.indicatorList.Count; i++)
|
||||||
sb.AppendFormat("{0}: {1}", key, ChartCached.FloatToStr(value, 0, m_Tooltip.forceENotation));
|
{
|
||||||
|
string key = radar.indicatorList[i].name;
|
||||||
|
float value = serieData.GetData(i);
|
||||||
|
if ((i == 0 && !string.IsNullOrEmpty(serieData.name)) || i > 0) sb.Append("\n");
|
||||||
|
sb.AppendFormat("{0}: {1}", key, ChartCached.FloatToStr(value, 0, m_Tooltip.forceENotation));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RadarType.Single:
|
||||||
|
string key2 = serieData.name;
|
||||||
|
float value2 = serieData.GetData(1);
|
||||||
|
if (string.IsNullOrEmpty(key2))
|
||||||
|
{
|
||||||
|
key2 = radar.indicatorList[dataIndex].name;
|
||||||
|
}
|
||||||
|
sb.AppendFormat("{0}: {1}", key2, ChartCached.FloatToStr(value2, 0, m_Tooltip.forceENotation));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
m_Tooltip.UpdateContentText(sb.ToString());
|
m_Tooltip.UpdateContentText(sb.ToString());
|
||||||
var pos = m_Tooltip.GetContentPos();
|
var pos = m_Tooltip.GetContentPos();
|
||||||
@@ -522,5 +744,42 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
m_Tooltip.UpdateContentPos(pos);
|
m_Tooltip.UpdateContentPos(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnRefreshLabel()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_Series.Count; i++)
|
||||||
|
{
|
||||||
|
var serie = m_Series.GetSerie(i);
|
||||||
|
if (!serie.show && serie.radarType != RadarType.Single) continue;
|
||||||
|
var radar = m_Radars[serie.radarIndex];
|
||||||
|
var center = radar.runtimeCenterPos;
|
||||||
|
for (int n = 0; n < serie.dataCount; n++)
|
||||||
|
{
|
||||||
|
var serieData = serie.data[n];
|
||||||
|
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||||
|
var labelPos = serieData.labelPosition;
|
||||||
|
if (serieLabel.margin != 0)
|
||||||
|
{
|
||||||
|
labelPos += serieLabel.margin * (labelPos - center).normalized;
|
||||||
|
}
|
||||||
|
serieData.SetGameObjectPosition(labelPos);
|
||||||
|
serieData.UpdateIcon();
|
||||||
|
if (serie.show && serieLabel.show && serieData.canShowLabel)
|
||||||
|
{
|
||||||
|
var value = serieData.GetCurrData(1);
|
||||||
|
var max = radar.GetIndicatorMax(n);
|
||||||
|
SerieLabelHelper.ResetLabel(serieData, serieLabel, themeInfo, i);
|
||||||
|
serieData.SetLabelActive(serieData.labelPosition != Vector3.zero);
|
||||||
|
serieData.SetLabelPosition(serieLabel.offset);
|
||||||
|
var content = serieLabel.GetFormatterContent(serie.name, serieData.name, value, max);
|
||||||
|
if (serieData.SetLabelText(content)) RefreshChart();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serieData.SetLabelActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user