优化RadarChart雷达图,增加多雷达图支持

This commit is contained in:
monitor1394
2019-08-04 15:24:31 +08:00
parent 757e45d05e
commit bc7be8ce89
32 changed files with 156122 additions and 84445 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,53 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(AreaStyle), true)]
public class AreaStyleDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_AreaStyleToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Origin = prop.FindPropertyRelative("m_Origin");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
SerializedProperty m_ToColor = prop.FindPropertyRelative("m_ToColor");
SerializedProperty m_Opacity = prop.FindPropertyRelative("m_Opacity");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AreaStyleToggle, prop, "Area Style", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_AreaStyleToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Origin);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_ToColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Opacity);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
if (ChartEditorHelper.IsToggle(m_AreaStyleToggle, prop))
{
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
}
else
{
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
return height;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c51fd822c8be44490832d81652d1aef5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,5 @@
using UnityEditor;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
@@ -6,7 +7,7 @@ namespace XCharts
[CustomPropertyDrawer(typeof(AxisLabel), true)]
public class AxisLabelDrawer : PropertyDrawer
{
private bool m_AxisLabelToggle = false;
private Dictionary<string, bool> m_AxisLabelToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
@@ -21,9 +22,9 @@ namespace XCharts
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisLabelToggle, "Axis Label", show, false);
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisLabelToggle,prop, "Axis Label", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_AxisLabelToggle)
if (ChartEditorHelper.IsToggle(m_AxisLabelToggle,prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Inside);
@@ -47,7 +48,7 @@ namespace XCharts
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
if (m_AxisLabelToggle)
if (ChartEditorHelper.IsToggle(m_AxisLabelToggle,prop))
{
height += 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
}

View File

@@ -1,4 +1,5 @@
using UnityEditor;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
@@ -6,7 +7,7 @@ namespace XCharts
[CustomPropertyDrawer(typeof(AxisLine), true)]
public class AxisLineDrawer : PropertyDrawer
{
private bool m_AxisLineToggle = false;
private Dictionary<string, bool> m_AxisLineToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
@@ -20,9 +21,9 @@ namespace XCharts
SerializedProperty m_SymbolOffset = prop.FindPropertyRelative("m_SymbolOffset");
SerializedProperty m_SymbolDent = prop.FindPropertyRelative("m_SymbolDent");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisLineToggle, "Axis Line", show, false);
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisLineToggle, prop, "Axis Line", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_AxisLineToggle)
if (ChartEditorHelper.IsToggle(m_AxisLineToggle,prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_OnZero);
@@ -44,7 +45,7 @@ namespace XCharts
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
if (m_AxisLineToggle)
if (ChartEditorHelper.IsToggle(m_AxisLineToggle,prop))
{
height += 6 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing;
}

View File

@@ -1,4 +1,5 @@
using UnityEditor;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
@@ -6,7 +7,7 @@ namespace XCharts
[CustomPropertyDrawer(typeof(AxisName), true)]
public class AxisNameDrawer : PropertyDrawer
{
private bool m_AxisNameToggle = false;
private Dictionary<string, bool> m_AxisNameToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
@@ -21,9 +22,9 @@ namespace XCharts
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisNameToggle, "Axis Name", show, false);
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisNameToggle, prop, "Axis Name", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_AxisNameToggle)
if (ChartEditorHelper.IsToggle(m_AxisNameToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Name);
@@ -47,7 +48,7 @@ namespace XCharts
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
if (m_AxisNameToggle)
if (ChartEditorHelper.IsToggle(m_AxisNameToggle, prop))
{
height += 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
}

View File

@@ -1,4 +1,5 @@
using UnityEditor;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
@@ -8,7 +9,7 @@ namespace XCharts
{
private bool m_ColorFoldout = false;
private int m_ColorSize = 0;
private bool m_SplitAreaToggle = false;
private Dictionary<string, bool> m_SplitAreaToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
@@ -17,9 +18,9 @@ namespace XCharts
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SplitAreaToggle, "Split Area", show, false);
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SplitAreaToggle, prop, "Split Area", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_SplitAreaToggle)
if (ChartEditorHelper.IsToggle(m_SplitAreaToggle, prop))
{
++EditorGUI.indentLevel;
m_ColorFoldout = EditorGUI.Foldout(drawRect, m_ColorFoldout, "Color");
@@ -36,7 +37,7 @@ namespace XCharts
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
if (m_SplitAreaToggle)
if (ChartEditorHelper.IsToggle(m_SplitAreaToggle, prop))
{
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_ColorFoldout)

View File

@@ -17,6 +17,7 @@ namespace XCharts
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_SelectedMode = prop.FindPropertyRelative("m_SelectedMode");
SerializedProperty orient = prop.FindPropertyRelative("m_Orient");
SerializedProperty location = prop.FindPropertyRelative("m_Location");
SerializedProperty itemWidth = prop.FindPropertyRelative("m_ItemWidth");
@@ -38,6 +39,8 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, itemFontSize);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SelectedMode);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, orient);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, location);
@@ -60,7 +63,7 @@ namespace XCharts
if (m_LegendModuleToggle)
{
SerializedProperty location = prop.FindPropertyRelative("m_Location");
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(location);
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_DataFoldout)
@@ -73,7 +76,7 @@ namespace XCharts
}
if (m_ShowJsonDataArea)
{
height += EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing;
height += EditorGUIUtility.singleLineHeight * 4 + EditorGUIUtility.standardVerticalSpacing;
}
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
return height;

View File

@@ -0,0 +1,52 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(LineStyle), true)]
public class LineStyleDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_LineStyleToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Type = prop.FindPropertyRelative("m_Type");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
SerializedProperty m_Width = prop.FindPropertyRelative("m_Width");
SerializedProperty m_Opacity = prop.FindPropertyRelative("m_Opacity");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_LineStyleToggle, prop, "Line Style", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_LineStyleToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Type);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Width);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Opacity);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
if (ChartEditorHelper.IsToggle(m_LineStyleToggle, prop))
{
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
}
else
{
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
return height;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a36d5076e1414d619b53d1ef998806f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,5 @@
using UnityEditor;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
@@ -6,24 +7,17 @@ namespace XCharts
[CustomPropertyDrawer(typeof(Radar), true)]
public class RadarDrawer : PropertyDrawer
{
SerializedProperty m_Cricle;
SerializedProperty m_Area;
SerializedProperty m_Shape;
SerializedProperty m_Radius;
SerializedProperty m_SplitNumber;
SerializedProperty m_Left;
SerializedProperty m_Right;
SerializedProperty m_Top;
SerializedProperty m_Bottom;
SerializedProperty m_LineTickness;
SerializedProperty m_LinePointSize;
SerializedProperty m_BackgroundColorList;
SerializedProperty m_LineColor;
SerializedProperty m_AreaAlpha;
SerializedProperty m_Center;
SerializedProperty m_LineStyle;
SerializedProperty m_SplitArea;
SerializedProperty m_Indicator;
SerializedProperty m_IndicatorList;
private bool m_RadarModuleToggle = false;
private bool m_IndicatorToggle = false;
private Dictionary<string, bool> m_RadarModuleToggle = new Dictionary<string, bool>();
private Dictionary<string, bool> m_IndicatorToggle = new Dictionary<string, bool>();
private bool m_IndicatorJsonAreaToggle = false;
private string m_IndicatorJsonAreaText;
private int m_IndicatorSize;
@@ -32,19 +26,12 @@ namespace XCharts
private void InitProperty(SerializedProperty prop)
{
m_Cricle = prop.FindPropertyRelative("m_Cricle");
m_Area = prop.FindPropertyRelative("m_Area");
m_Shape = prop.FindPropertyRelative("m_Shape");
m_Radius = prop.FindPropertyRelative("m_Radius");
m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber");
m_Left = prop.FindPropertyRelative("m_Left");
m_Right = prop.FindPropertyRelative("m_Right");
m_Top = prop.FindPropertyRelative("m_Top");
m_Bottom = prop.FindPropertyRelative("m_Bottom");
m_LineTickness = prop.FindPropertyRelative("m_LineTickness");
m_LinePointSize = prop.FindPropertyRelative("m_LinePointSize");
m_LineColor = prop.FindPropertyRelative("m_LineColor");
m_AreaAlpha = prop.FindPropertyRelative("m_AreaAlpha");
m_BackgroundColorList = prop.FindPropertyRelative("m_BackgroundColorList");
m_Center = prop.FindPropertyRelative("m_Center");
m_LineStyle = prop.FindPropertyRelative("m_LineStyle");
m_SplitArea = prop.FindPropertyRelative("m_SplitArea");
m_Indicator = prop.FindPropertyRelative("m_Indicator");
m_IndicatorList = prop.FindPropertyRelative("m_IndicatorList");
}
@@ -56,65 +43,46 @@ namespace XCharts
float defaultLabelWidth = EditorGUIUtility.labelWidth;
float defaultFieldWidth = EditorGUIUtility.fieldWidth;
drawRect.height = EditorGUIUtility.singleLineHeight;
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_RadarModuleToggle, "Radar");
int index = ChartEditorHelper.GetIndexFromPath(prop);
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_RadarModuleToggle, prop, "Radar " + index, null, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_RadarModuleToggle)
if (ChartEditorHelper.IsToggle(m_RadarModuleToggle,prop))
{
++EditorGUI.indentLevel;
EditorGUIUtility.fieldWidth = 10;
EditorGUIUtility.labelWidth = 50;
drawRect.width = 60;
EditorGUI.PropertyField(drawRect, m_Cricle);
EditorGUIUtility.labelWidth = 45;
drawRect.x += 60;
EditorGUI.PropertyField(drawRect, m_Area);
EditorGUIUtility.labelWidth = 70;
drawRect.x += 55;
drawRect.width = 80;
EditorGUI.PropertyField(drawRect, m_Indicator);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.x = pos.x;
drawRect.width = pos.width;
EditorGUIUtility.labelWidth = defaultLabelWidth;
EditorGUIUtility.fieldWidth = defaultFieldWidth;
EditorGUI.PropertyField(drawRect, m_Shape);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.LabelField(drawRect, "Center");
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15;
var tempWidth = (pos.width - startX + 35) / 2;
var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height);
var centerYRect = new Rect(centerXRect.x + tempWidth - 20, drawRect.y, tempWidth, drawRect.height);
while (m_Center.arraySize < 2)
{
m_Center.InsertArrayElementAtIndex(m_Center.arraySize);
}
EditorGUI.PropertyField(centerXRect, m_Center.GetArrayElementAtIndex(0), GUIContent.none);
EditorGUI.PropertyField(centerYRect, m_Center.GetArrayElementAtIndex(1), GUIContent.none);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Radius);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SplitNumber);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Left);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Right);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Top);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Bottom);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LineTickness);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LinePointSize);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_AreaAlpha);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LineColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
m_BackgroundColorToggle = EditorGUI.Foldout(drawRect, m_BackgroundColorToggle, "BackgroundColors");
EditorGUI.PropertyField(drawRect, m_LineStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
EditorGUI.PropertyField(drawRect, m_SplitArea);
drawRect.y += EditorGUI.GetPropertyHeight(m_SplitArea);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_IndicatorToggle, prop, "Indicators", m_Indicator, false);
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_IndicatorJsonAreaToggle, ref m_IndicatorJsonAreaText, prop, pos.width, 20);
drawRect.width = pos.width;
if (m_BackgroundColorToggle)
{
ChartEditorHelper.MakeList(ref drawRect, ref m_BackgroundColorSize, m_BackgroundColorList);
}
drawRect.width = EditorGUIUtility.labelWidth + 10;
m_IndicatorToggle = EditorGUI.Foldout(drawRect, m_IndicatorToggle, "Indicators");
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_IndicatorJsonAreaToggle, ref m_IndicatorJsonAreaText, prop,pos.width);
drawRect.width = pos.width;
if (m_IndicatorToggle)
drawRect.x = pos.x;
if (ChartEditorHelper.IsToggle(m_IndicatorToggle, prop))
{
ChartEditorHelper.MakeList(ref drawRect, ref m_IndicatorSize, m_IndicatorList);
}
@@ -125,27 +93,20 @@ namespace XCharts
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
int propNum = 1;
if (m_RadarModuleToggle)
if (ChartEditorHelper.IsToggle(m_RadarModuleToggle,prop))
{
propNum += 13;
if (m_BackgroundColorToggle)
{
m_BackgroundColorList = prop.FindPropertyRelative("m_BackgroundColorList");
propNum += 2;
propNum += m_BackgroundColorList.arraySize;
}
propNum += 6;
if (m_IndicatorJsonAreaToggle) propNum += 4;
float height = propNum * EditorGUIUtility.singleLineHeight + (propNum - 1) * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SplitArea"));
if (m_IndicatorToggle)
if (ChartEditorHelper.IsToggle(m_IndicatorToggle, prop))
{
m_IndicatorList = prop.FindPropertyRelative("m_IndicatorList");
height += EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing;
for (int i = 0; i < m_IndicatorSize; i++)
for (int i = 0; i < m_IndicatorList.arraySize; i++)
{
height += EditorGUI.GetPropertyHeight(m_IndicatorList.GetArrayElementAtIndex(i));
}

View File

@@ -1,4 +1,5 @@
using UnityEditor;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
@@ -6,35 +7,34 @@ namespace XCharts
[CustomPropertyDrawer(typeof(Radar.Indicator), true)]
public class RadarIndicatorDrawer : PropertyDrawer
{
SerializedProperty m_Name;
SerializedProperty m_Max;
private bool m_RadarModuleToggle = false;
private void InitProperty(SerializedProperty prop)
{
m_Name = prop.FindPropertyRelative("m_Name");
m_Max = prop.FindPropertyRelative("m_Max");
}
private Dictionary<string, bool> m_RadarModuleToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
InitProperty(prop);
SerializedProperty m_Name = prop.FindPropertyRelative("m_Name");
SerializedProperty m_Max = prop.FindPropertyRelative("m_Max");
SerializedProperty m_Min = prop.FindPropertyRelative("m_Min");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
Rect drawRect = pos;
float defaultLabelWidth = EditorGUIUtility.labelWidth;
float defaultFieldWidth = EditorGUIUtility.fieldWidth;
drawRect.height = EditorGUIUtility.singleLineHeight;
m_RadarModuleToggle = EditorGUI.Foldout(drawRect, m_RadarModuleToggle, "Indicator");
int index = ChartEditorHelper.GetIndexFromPath(prop);
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_RadarModuleToggle, prop, "Indicator " + index, m_Name, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_RadarModuleToggle)
if (ChartEditorHelper.IsToggle(m_RadarModuleToggle,prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Name);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Min);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Max);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
--EditorGUI.indentLevel;
}
@@ -42,11 +42,9 @@ namespace XCharts
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
int propNum = 1;
if (m_RadarModuleToggle)
if (ChartEditorHelper.IsToggle(m_RadarModuleToggle,prop))
{
propNum += 2;
return propNum * EditorGUIUtility.singleLineHeight + (propNum - 1) * EditorGUIUtility.standardVerticalSpacing;
return 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
}
else
{

View File

@@ -8,7 +8,7 @@ namespace XCharts
public class SerieDrawer : PropertyDrawer
{
private List<bool> m_SerieModuleToggle = new List<bool>();
private Dictionary<string, bool> m_SerieModuleToggle = new Dictionary<string, bool>();
private List<bool> m_DataFoldout = new List<bool>();
private bool m_ShowJsonDataArea = false;
private string m_JsonDataAreaText;
@@ -22,6 +22,9 @@ namespace XCharts
SerializedProperty name = prop.FindPropertyRelative("m_Name");
SerializedProperty stack = prop.FindPropertyRelative("m_Stack");
SerializedProperty m_AxisIndex = prop.FindPropertyRelative("m_AxisIndex");
SerializedProperty m_RadarIndex = prop.FindPropertyRelative("m_RadarIndex");
SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle");
SerializedProperty m_AreaStyle = prop.FindPropertyRelative("m_AreaStyle");
SerializedProperty m_Symbol = prop.FindPropertyRelative("m_Symbol");
SerializedProperty m_RoseType = prop.FindPropertyRelative("m_RoseType");
SerializedProperty m_ClickOffset = prop.FindPropertyRelative("m_ClickOffset");
@@ -36,9 +39,8 @@ namespace XCharts
int index = InitToggle(prop);
string moduleName = "Serie " + index;
bool toggle = m_SerieModuleToggle[index];
m_SerieModuleToggle[index] = ChartEditorHelper.MakeFoldout(ref drawRect, ref toggle, moduleName, show);
if (!m_SerieModuleToggle[index])
var toggle = ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieModuleToggle, prop, moduleName, show);
if (!toggle)
{
drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2 + 20;
drawRect.width = pos.width - drawRect.x + 15;
@@ -47,6 +49,8 @@ namespace XCharts
}
else
{
var serieType = (SerieType)type.enumValueIndex;
++EditorGUI.indentLevel;
drawRect.x = pos.x;
drawRect.width = pos.width;
@@ -57,13 +61,20 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, stack);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_AxisIndex);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
var serieType = (SerieType)type.enumValueIndex;
if (serieType == SerieType.Radar)
{
EditorGUI.PropertyField(drawRect, m_RadarIndex);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
else
{
EditorGUI.PropertyField(drawRect, m_AxisIndex);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
if (serieType == SerieType.Line
|| serieType == SerieType.Scatter
|| serieType == SerieType.EffectScatter)
|| serieType == SerieType.EffectScatter
|| serieType == SerieType.Radar)
{
EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
@@ -101,9 +112,13 @@ namespace XCharts
EditorGUI.PropertyField(drawRect, m_ClickOffset);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
EditorGUI.PropertyField(drawRect, m_Label,new GUIContent("Normal Label"));
EditorGUI.PropertyField(drawRect, m_LineStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
EditorGUI.PropertyField(drawRect, m_AreaStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle);
EditorGUI.PropertyField(drawRect, m_Label, new GUIContent("Normal Label"));
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
EditorGUI.PropertyField(drawRect, m_HighlightLabel,new GUIContent("Highlight Label"));
EditorGUI.PropertyField(drawRect, m_HighlightLabel, new GUIContent("Highlight Label"));
drawRect.y += EditorGUI.GetPropertyHeight(m_HighlightLabel);
drawRect.width = EditorGUIUtility.labelWidth + 10;
m_DataFoldout[index] = EditorGUI.Foldout(drawRect, m_DataFoldout[index], "Data");
@@ -236,20 +251,23 @@ namespace XCharts
{
float height = 0;
int index = InitToggle(prop);
if (!m_SerieModuleToggle[index])
if (!m_SerieModuleToggle[prop.propertyPath])
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
else
{
height += 6 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AreaStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_HighlightLabel"));
SerializedProperty type = prop.FindPropertyRelative("m_Type");
var serieType = (SerieType)type.enumValueIndex;
if (serieType == SerieType.Line
|| serieType == SerieType.Scatter
|| serieType == SerieType.EffectScatter)
|| serieType == SerieType.EffectScatter
|| serieType == SerieType.Radar)
{
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
@@ -262,12 +280,12 @@ namespace XCharts
{
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
int num = m_Data.arraySize + 2;
if (num > 30) num = 13;
if (num > 30) num = 14;
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
}
if (m_ShowJsonDataArea)
{
height += EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing;
height += EditorGUIUtility.singleLineHeight * 4 + EditorGUIUtility.standardVerticalSpacing;
}
return height;
}
@@ -276,24 +294,17 @@ namespace XCharts
private int InitToggle(SerializedProperty prop)
{
int index = 0;
var temp = prop.displayName.Split(' ');
if (temp == null || temp.Length < 2)
var sindex = prop.propertyPath.LastIndexOf('[');
var eindex = prop.propertyPath.LastIndexOf(']');
if (sindex >= 0 && eindex >= 0)
{
//Debug.LogError("SERIE:"+prop.name+","+prop.displayName+","+prop.FindPropertyRelative("m_Name").stringValue);
index = 0;
}
else
{
int.TryParse(temp[1], out index);
var str = prop.propertyPath.Substring(sindex + 1, eindex - sindex - 1);
int.TryParse(str, out index);
}
if (index >= m_DataFoldout.Count)
{
m_DataFoldout.Add(false);
}
if (index >= m_SerieModuleToggle.Count)
{
m_SerieModuleToggle.Add(false);
}
return index;
}
}

View File

@@ -1,4 +1,5 @@
using UnityEditor;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
@@ -6,7 +7,7 @@ namespace XCharts
[CustomPropertyDrawer(typeof(SerieLabel), true)]
public class SerieLabelDrawer : PropertyDrawer
{
private bool m_SerieLabelToggle = false;
private Dictionary<string, bool> m_SerieLabelToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
@@ -24,9 +25,9 @@ namespace XCharts
SerializedProperty m_LineLength1 = prop.FindPropertyRelative("m_LineLength1");
SerializedProperty m_LineLength2 = prop.FindPropertyRelative("m_LineLength2");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieLabelToggle, prop.displayName, show, false);
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieLabelToggle, prop, null, show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_SerieLabelToggle)
if (ChartEditorHelper.IsToggle(m_SerieLabelToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Position);
@@ -56,7 +57,7 @@ namespace XCharts
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
if (m_SerieLabelToggle)
if (ChartEditorHelper.IsToggle(m_SerieLabelToggle, prop))
{
height += 11 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
}

View File

@@ -10,19 +10,19 @@ namespace XCharts
public class RadarChartEditor : BaseChartEditor
{
protected SerializedProperty m_Radar;
protected bool m_RadarModuleToggle = false;
protected SerializedProperty m_Radars;
protected override void OnEnable()
{
base.OnEnable();
m_Target = (RadarChart)target;
m_Radar = serializedObject.FindProperty("m_Radar");
m_Radars = serializedObject.FindProperty("m_Radars");
}
protected override void OnEndInspectorGUI()
{
base.OnEndInspectorGUI();
EditorGUILayout.PropertyField(m_Radar, true);
EditorGUILayout.PropertyField(m_Radars, true);
}
}
}

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
public class ChartEditorHelper
{
@@ -19,13 +20,13 @@ public class ChartEditorHelper
}
public static void MakeJsonData(ref Rect drawRect, ref bool showTextArea, ref string inputString,
SerializedProperty prop,float currentWidth)
SerializedProperty prop, float currentWidth, float diff = 0)
{
SerializedProperty stringDataProp = prop.FindPropertyRelative("m_JsonData");
SerializedProperty needParseProp = prop.FindPropertyRelative("m_DataFromJson");
float defalutX = drawRect.x;
drawRect.x = EditorGUIUtility.labelWidth + 14;
drawRect.width = currentWidth - EditorGUIUtility.labelWidth;
drawRect.x = EditorGUIUtility.labelWidth + 14 + diff;
drawRect.width = currentWidth - EditorGUIUtility.labelWidth - diff;
if (GUI.Button(drawRect, new GUIContent("Parse JsonData", "Parse data from input json")))
{
showTextArea = !showTextArea;
@@ -56,7 +57,7 @@ public class ChartEditorHelper
drawRect.width = EditorGUIUtility.labelWidth;
moduleToggle = EditorGUI.Foldout(drawRect, moduleToggle, content, bold ? foldoutStyle : EditorStyles.foldout);
drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2;
drawRect.width = EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - 70;
drawRect.width = 40;
if (prop != null)
{
EditorGUI.PropertyField(drawRect, prop, GUIContent.none);
@@ -66,6 +67,43 @@ public class ChartEditorHelper
return moduleToggle;
}
public static bool MakeFoldout(ref Rect drawRect, ref Dictionary<string, bool> moduleToggle, SerializedProperty prop,
string moduleName, SerializedProperty showProp = null, bool bold = true)
{
var key = prop.propertyPath;
if (!moduleToggle.ContainsKey(key))
{
moduleToggle.Add(key, false);
}
var toggle = moduleToggle[key];
float defaultWidth = drawRect.width;
float defaultX = drawRect.x;
drawRect.width = EditorGUIUtility.labelWidth;
var displayName = string.IsNullOrEmpty(moduleName) ? prop.displayName : moduleName;
toggle = EditorGUI.Foldout(drawRect, toggle, displayName, bold ? foldoutStyle : EditorStyles.foldout);
if (moduleToggle[key] != toggle)
{
moduleToggle[key] = toggle;
}
drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2;
if (showProp != null)
{
if (showProp.propertyType == SerializedPropertyType.Boolean)
{
drawRect.width = 40;
}
else
{
drawRect.width = defaultWidth - drawRect.x + 15;
}
EditorGUI.PropertyField(drawRect, showProp, GUIContent.none);
}
drawRect.width = defaultWidth;
drawRect.x = defaultX;
return toggle;
}
public static void MakeList(ref Rect drawRect, ref int listSize, SerializedProperty listProp, SerializedProperty large = null)
{
EditorGUI.indentLevel++;
@@ -88,7 +126,7 @@ public class ChartEditorHelper
for (int i = 0; i < num; i++)
{
element = listProp.GetArrayElementAtIndex(i);
EditorGUI.PropertyField(drawRect, element);
EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + i));
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
}
if (num >= 10)
@@ -96,7 +134,7 @@ public class ChartEditorHelper
EditorGUI.LabelField(drawRect, "...");
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
element = listProp.GetArrayElementAtIndex(listSize - 1);
EditorGUI.PropertyField(drawRect, element);
EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + (listSize - 1)));
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
}
}
@@ -105,10 +143,47 @@ public class ChartEditorHelper
for (int i = 0; i < listProp.arraySize; i++)
{
SerializedProperty element = listProp.GetArrayElementAtIndex(i);
EditorGUI.PropertyField(drawRect, element);
EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + i));
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
}
}
EditorGUI.indentLevel--;
}
public static int InitModuleToggle(ref List<bool> moduleToggle, SerializedProperty prop)
{
int index = 0;
var temp = prop.displayName.Split(' ');
if (temp == null || temp.Length < 2)
{
index = 0;
}
else
{
int.TryParse(temp[1], out index);
}
if (index >= moduleToggle.Count)
{
moduleToggle.Add(false);
}
return index;
}
public static int GetIndexFromPath(SerializedProperty prop)
{
int index = 0;
var sindex = prop.propertyPath.LastIndexOf('[');
var eindex = prop.propertyPath.LastIndexOf(']');
if (sindex >= 0 && eindex >= 0)
{
var str = prop.propertyPath.Substring(sindex + 1, eindex - sindex - 1);
int.TryParse(str, out index);
}
return index;
}
public static bool IsToggle(Dictionary<string, bool> toggle, SerializedProperty prop)
{
return toggle.ContainsKey(prop.propertyPath) && toggle[prop.propertyPath] == true;
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -12,7 +13,28 @@ namespace XCharts
[System.Serializable]
public class Legend : JsonDataSupport, IPropertyChanged, IEquatable<Legend>
{
/// <summary>
/// Selected mode of legend, which controls whether series can be toggled displaying by clicking legends.
/// It is enabled by default, and you may set it to be false to disabled it.
/// 图例选择的模式,控制是否可以通过点击图例改变系列的显示状态。默认开启图例选择,可以设成 None 关闭。
/// </summary>
public enum SelectedMode
{
/// <summary>
/// 多选。
/// </summary>
Multiple,
/// <summary>
/// 单选。
/// </summary>
Single,
/// <summary>
/// 无法选择。
/// </summary>
None
}
[SerializeField] private bool m_Show = true;
[SerializeField] private SelectedMode m_SelectedMode;
[SerializeField] private Orient m_Orient = Orient.Horizonal;
[SerializeField] private Location m_Location = Location.defaultRight;
[SerializeField] private float m_ItemWidth = 50.0f;
@@ -29,6 +51,12 @@ namespace XCharts
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// Selected mode of legend, which controls whether series can be toggled displaying by clicking legends.
/// 选择模式。控制是否可以通过点击图例改变系列的显示状态。默认开启图例选择,可以设成 None 关闭。
/// </summary>
/// <value></value>
public SelectedMode selectedMode { get { return m_SelectedMode; } set { m_SelectedMode = value; } }
/// <summary>
/// Specify whether the layout of legend component is horizontal or vertical.
/// 布局方式是横还是竖。
/// </summary>
@@ -66,6 +94,12 @@ namespace XCharts
/// 如果 data 没有被指定会自动从当前系列中获取。指定data时里面的数据项和serie匹配时才会生效。
/// </summary>
public List<string> data { get { return m_Data; } }
/// <summary>
/// the button list of legend.
/// 图例按钮列表。
/// </summary>
/// <value></value>
public Dictionary<string, Button> buttonList { get { return m_DataBtnList; } }
/// <summary>
/// 一个在顶部居中显示的默认图例。
@@ -77,6 +111,7 @@ namespace XCharts
var legend = new Legend
{
m_Show = false,
m_SelectedMode = SelectedMode.Multiple,
m_Orient = Orient.Horizonal,
m_Location = Location.defaultTop,
m_ItemWidth = 60.0f,
@@ -91,6 +126,7 @@ namespace XCharts
public void Copy(Legend legend)
{
m_Show = legend.show;
m_SelectedMode = legend.selectedMode;
m_Orient = legend.orient;
m_Location.Copy(legend.location);
m_ItemWidth = legend.itemWidth;
@@ -124,6 +160,7 @@ namespace XCharts
return false;
}
return show == other.show &&
selectedMode == other.selectedMode &&
orient == other.orient &&
location == other.location &&
itemWidth == other.itemWidth &&

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System;
using System.Text.RegularExpressions;
using UnityEngine.UI;
namespace XCharts
{
@@ -12,6 +13,15 @@ namespace XCharts
[System.Serializable]
public class Radar : JsonDataSupport, IEquatable<Radar>
{
/// <summary>
/// Radar render type, in which 'Polygon' and 'Circle' are supported.
/// 雷达图绘制类型,支持 'Polygon' 和 'Circle'。
/// </summary>
public enum Shape
{
Polygon,
Circle
}
/// <summary>
/// Indicator of radar chart, which is used to assign multiple variables(dimensions) in radar chart.
/// 雷达图的指示器,用来指定雷达图中的多个变量(维度)。
@@ -39,9 +49,14 @@ namespace XCharts
public float min { get { return m_Min; } set { m_Min = value; } }
/// <summary>
/// Specfy a color the the indicator.
/// 标签特定的颜色。
/// 标签特定的颜色。默认取自主题的axisTextColor。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// the text conponent of indicator.
/// 指示器的文本组件。
/// </summary>
public Text text { get; set; }
public Indicator Clone()
{
@@ -54,43 +69,51 @@ namespace XCharts
};
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is Indicator)
{
return Equals((Indicator)obj);
}
else
{
return false;
}
}
public bool Equals(Indicator other)
{
return name.Equals(other.name);
if (ReferenceEquals(null, other))
{
return false;
}
return m_Name.Equals(other.name) &&
ChartHelper.IsValueEqualsColor(m_Color, other.color);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
[SerializeField] private bool m_Cricle;
[SerializeField] private bool m_Area;
[SerializeField] private Shape m_Shape;
[SerializeField] private float m_Radius = 100;
[SerializeField] private int m_SplitNumber = 5;
[SerializeField] private float m_Left;
[SerializeField] private float m_Right;
[SerializeField] private float m_Top;
[SerializeField] private float m_Bottom;
[SerializeField] private float m_LineTickness = 1f;
[SerializeField] private float m_LinePointSize = 5f;
[SerializeField] private Color m_LineColor = Color.grey;
[Range(0, 255)]
[SerializeField] private int m_AreaAlpha;
[SerializeField] private List<Color> m_BackgroundColorList = new List<Color>();
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
[SerializeField] private AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
[SerializeField] private bool m_Indicator = true;
[SerializeField] private List<Indicator> m_IndicatorList = new List<Indicator>();
/// <summary>
/// True is render radar as cricle,otherwise render as polygon.
///雷达图是否绘制成圆形true为圆形false为多边形
/// Radar render type, in which 'Polygon' and 'Circle' are supported.
/// 雷达图绘制类型,支持 'Polygon' 和 'Circle'
/// </summary>
public bool cricle { get { return m_Cricle; } set { m_Cricle = value; } }
/// <summary>
/// Whether to fill color in area.
/// 是否区域填充颜色
/// </summary>
public bool area { get { return m_Area; } set { m_Area = value; } }
/// <value></value>
public Shape shape { get { return m_Shape; } set { m_Shape = value; } }
/// <summary>
/// the radius of radar.
/// 雷达图的半径。
@@ -102,50 +125,21 @@ namespace XCharts
/// </summary>
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
/// <summary>
/// Distance between radar component and the left side of the container.
/// 雷达图离容器左侧的距离
/// the center of radar chart.
/// 雷达图的中心点。数组的第一项是横坐标,第二项是纵坐标
/// 当值为0-1之间时表示百分比设置成百分比时第一项是相对于容器宽度第二项是相对于容器高度。
/// </summary>
public float left { get { return m_Left; } set { m_Left = value; } }
public float[] center { get { return m_Center; } set { m_Center = value; } }
/// <summary>
/// Distance between radar component and the right side of the container.
/// 雷达图离容器右侧的距离
/// the line style of radar.
/// 线条样式
/// </summary>
public float right { get { return m_Right; } set { m_Right = value; } }
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
/// <summary>
/// Distance between radar component and the top side of the container.
/// 雷达图离容器上侧的距离
/// Split area of axis in grid area.
/// 分割区域
/// </summary>
public float top { get { return m_Top; } set { m_Top = value; } }
/// <summary>
/// Distance between radar component and the bottom side of the container.
/// 雷达图离容器下侧的距离。
/// </summary>
public float bottom { get { return m_Bottom; } set { m_Bottom = value; } }
/// <summary>
/// the tickness of line.
/// 线的粗细。
/// </summary>
public float lineTickness { get { return m_LineTickness; } set { m_LineTickness = value; } }
/// <summary>
/// the size of point.
/// 圆点大小。
/// </summary>
public float linePointSize { get { return m_LinePointSize; } set { m_LinePointSize = value; } }
/// <summary>
/// the color of line.
/// 线的颜色。
/// </summary>
public Color lineColor { get { return m_LineColor; } set { m_LineColor = value; } }
/// <summary>
/// the alpha of area color.
/// 区域填充时的颜色alpha值
/// </summary>
public int areaAlpha { get { return m_AreaAlpha; } set { m_AreaAlpha = value; } }
/// <summary>
/// the color list of split area.
/// 分割区域颜色列表。
/// </summary>
public List<Color> backgroundColorList { get { return m_BackgroundColorList; } }
public AxisSplitArea splitArea { get { return m_SplitArea; } set { m_SplitArea = value; } }
/// <summary>
/// Whether to show indicator.
/// 是否显示指示器。
@@ -157,55 +151,77 @@ namespace XCharts
/// </summary>
public List<Indicator> indicatorList { get { return m_IndicatorList; } }
/// <summary>
/// the center position of radar in container.
/// 雷达图在容器中的具体中心点。
/// </summary>
/// <value></value>
public Vector2 centerPos { get; set; }
/// <summary>
/// the true radius of radar.
/// 雷达图的运行时实际半径。
/// </summary>
/// <value></value>
public float actualRadius { get; set; }
/// <summary>
/// the data position list of radar.
/// 雷达图的所有数据坐标点列表。
/// </summary>
/// <returns></returns>
public Dictionary<int,List<Vector3>> dataPosList = new Dictionary<int,List<Vector3>>();
public static Radar defaultRadar
{
get
{
var radar = new Radar
{
m_Cricle = false,
m_Area = false,
m_Radius = 100,
m_Shape = Shape.Polygon,
m_Radius = 0.4f,
m_SplitNumber = 5,
m_Left = 0,
m_Right = 0,
m_Top = 0,
m_Bottom = 0,
m_LineTickness = 1f,
m_LinePointSize = 5f,
m_AreaAlpha = 150,
m_LineColor = Color.grey,
m_Indicator = true,
m_BackgroundColorList = new List<Color> {
new Color32(246, 246, 246, 255),
new Color32(231, 231, 231, 255)
},
m_IndicatorList = new List<Indicator>(5){
new Indicator(){name="radar1",max = 100},
new Indicator(){name="radar2",max = 100},
new Indicator(){name="radar3",max = 100},
new Indicator(){name="radar4",max = 100},
new Indicator(){name="radar5",max = 100},
new Indicator(){name="indicator1",max = 100},
new Indicator(){name="indicator2",max = 100},
new Indicator(){name="indicator3",max = 100},
new Indicator(){name="indicator4",max = 100},
new Indicator(){name="indicator5",max = 100},
}
};
radar.center[0] = 0.5f;
radar.center[1] = 0.45f;
radar.splitArea.show = true;
radar.lineStyle.width = 0.3f;
return radar;
}
}
public void Copy(Radar other)
{
m_Shape = other.shape;
m_Radius = other.radius;
m_SplitNumber = other.splitNumber;
m_Left = other.left;
m_Right = other.right;
m_Top = other.top;
m_Bottom = other.bottom;
m_Center[0] = other.center[0];
m_Center[1] = other.center[1];
m_Indicator = other.indicator;
m_AreaAlpha = other.areaAlpha;
indicatorList.Clear();
foreach (var d in other.indicatorList) indicatorList.Add(d.Clone());
}
public Radar Clone()
{
var radar = new Radar();
radar.shape = shape;
radar.radius = radius;
radar.splitNumber = splitNumber;
radar.center[0] = center[0];
radar.center[1] = center[1];
radar.indicatorList.Clear();
radar.indicator = indicator;
foreach (var d in indicatorList) radar.indicatorList.Add(d.Clone());
return radar;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
@@ -229,11 +245,10 @@ namespace XCharts
return false;
}
return radius == other.radius &&
shape == other.shape &&
splitNumber == other.splitNumber &&
left == other.left &&
right == other.right &&
top == other.top &&
bottom == other.bottom &&
center[0] == other.center[0] &&
center[1] == other.center[1] &&
indicator == other.indicator &&
IsEqualsIndicatorList(indicatorList, other.indicatorList);
}
@@ -305,6 +320,14 @@ namespace XCharts
}
}
public float GetIndicatorMin(int index)
{
if (index >= 0 && index < m_IndicatorList.Count)
{
return m_IndicatorList[index].min;
}
return 0;
}
public float GetIndicatorMax(int index)
{
if (index >= 0 && index < m_IndicatorList.Count)
@@ -313,5 +336,34 @@ namespace XCharts
}
return 0;
}
public void UpdateRadarCenter(float chartWidth, float chartHeight)
{
if (center.Length < 2) return;
var centerX = center[0] <= 1 ? chartWidth * center[0] : center[0];
var centerY = center[1] <= 1 ? chartHeight * center[1] : center[1];
centerPos = new Vector2(centerX, centerY);
if (radius <= 0)
{
actualRadius = 0;
}
else if (radius <= 1)
{
actualRadius = Mathf.Min(chartWidth, chartHeight) * radius;
}
else
{
actualRadius = radius;
}
}
public Vector3 GetIndicatorPosition(int index)
{
int indicatorNum = indicatorList.Count;
var angle = 2 * Mathf.PI / indicatorNum * index;
var x = centerPos.x + actualRadius * Mathf.Sin(angle);
var y = centerPos.y + actualRadius * Mathf.Cos(angle);
return new Vector3(x, y);
}
}
}

View File

@@ -72,7 +72,10 @@ namespace XCharts
[SerializeField] private SerieType m_Type;
[SerializeField] private string m_Name;
[SerializeField] private string m_Stack;
[SerializeField] [Range(0, 1)] private int m_AxisIndex;
[SerializeField] [Range(0, 1)] private int m_AxisIndex = 0;
[SerializeField] private int m_RadarIndex = 0;
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
[SerializeField] private AreaStyle m_AreaStyle = AreaStyle.defaultAreaStyle;
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
#region PieChart field
[SerializeField] private bool m_ClickOffset = true;
@@ -83,7 +86,7 @@ namespace XCharts
#endregion
[SerializeField] private SerieLabel m_Label = new SerieLabel();
[SerializeField] private SerieLabel m_HighlightLabel = new SerieLabel();
[SerializeField] [Range(1, 6)] private int m_ShowDataDimension;
[SerializeField] [Range(1, 10)] private int m_ShowDataDimension;
[SerializeField] private bool m_ShowDataName;
[FormerlySerializedAs("m_Data")]
[SerializeField] private List<float> m_YData = new List<float>();
@@ -116,6 +119,23 @@ namespace XCharts
/// </summary>
public int axisIndex { get { return m_AxisIndex; } set { m_AxisIndex = value; } }
/// <summary>
/// Index of radar component that radar chart uses.
/// 雷达图所使用的 radar 组件的 index。
/// </summary>
public int radarIndex { get { return m_RadarIndex; } set { m_RadarIndex = value; } }
/// <summary>
/// The style of line.
/// 线条样式。
/// </summary>
/// <value></value>
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
/// <summary>
/// The style of area.
/// 区域填充样式。
/// </summary>
/// <value></value>
public AreaStyle areaStyle { get { return m_AreaStyle; } set { m_AreaStyle = value; } }
/// <summary>
/// the symbol of serie data item.
/// 标记的图形。
/// </summary>
@@ -360,7 +380,7 @@ namespace XCharts
m_YData.Add(yValue);
m_Data.Add(new SerieData() { data = new List<float>() { xValue, yValue }, name = dataName });
}
/// <summary>
/// 将一组数据添加到系列中。
/// 如果数据只有一个默认添加到维度Y中。
@@ -393,7 +413,7 @@ namespace XCharts
{
if (i == 0) m_XData.Add(valueList[i]);
else if (i == 1) m_YData.Add(valueList[i]);
serieData.data.Add(valueList[0]);
serieData.data.Add(valueList[i]);
}
m_Data.Add(serieData);
}
@@ -545,6 +565,31 @@ namespace XCharts
}
}
/// <summary>
/// 获得指定维数的最大最小值
/// </summary>
/// <param name="dimension"></param>
/// <param name="dataZoom"></param>
/// <returns></returns>
public void GetMinMaxData(int dimension, out float minValue, out float maxValue, DataZoom dataZoom = null)
{
var dataList = GetDataList(dataZoom);
float max = float.MinValue;
float min = float.MaxValue;
for (int i = 0; i < dataList.Count; i++)
{
var serieData = dataList[i];
if (serieData.data.Count > dimension)
{
var value = serieData.data[dimension];
if (value > max) max = value;
if (value < min) min = value;
}
}
maxValue = max;
minValue = min;
}
/// <summary>
/// 根据dataZoom更新数据列表缓存
/// </summary>
@@ -664,6 +709,42 @@ namespace XCharts
}
}
public Color GetAreaColor(ThemeInfo theme, int index, bool highlight)
{
if (areaStyle.color != Color.clear)
{
var color = areaStyle.color;
if (highlight) color *= color;
color.a *= areaStyle.opactiy;
return color;
}
else
{
var color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a *= areaStyle.opactiy;
return color;
}
}
public Color GetLineColor(ThemeInfo theme, int index, bool highlight)
{
if (lineStyle.color != Color.clear)
{
var color = lineStyle.color;
if (highlight) color *= color;
color.a *= lineStyle.opactiy;
return color;
}
else
{
var color = (Color)theme.GetColor(index);
if (highlight) color *= color;
color.a *= lineStyle.opactiy;
return color;
}
}
/// <summary>
/// 从json中导入数据
/// </summary>

View File

@@ -558,58 +558,6 @@ namespace XCharts
}
}
/// <summary>
/// 获得指定系列的最大值
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public float GetMaxValue(int index)
{
float max = int.MinValue;
float min = int.MaxValue;
for (int i = 0; i < m_Series.Count; i++)
{
var showData = m_Series[i].yData;
if (showData[index] > max)
{
max = Mathf.Ceil(showData[index]);
}
if (showData[index] < min)
{
min = Mathf.Ceil(showData[index]);
}
}
if (max < 1 && max > -1) return max;
if (max < 0 && min < 0) max = min;
return ChartHelper.GetMaxDivisibleValue(max);
}
/// <summary>
/// 获得指定系列的最小值
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public float GetMinValue(int index)
{
float max = int.MinValue;
float min = int.MaxValue;
for (int i = 0; i < m_Series.Count; i++)
{
var showData = m_Series[i].yData;
if (showData[index] > max)
{
max = Mathf.Ceil(showData[index]);
}
if (showData[index] < min)
{
min = Mathf.Ceil(showData[index]);
}
}
if (min < 1 && min > -1) return min;
if (min < 0 && max < 0) min = max;
return ChartHelper.GetMinDivisibleValue(min);
}
private HashSet<string> _setForStack = new HashSet<string>();
/// <summary>
/// 是否由数据堆叠
@@ -729,21 +677,15 @@ namespace XCharts
serieNameList.Clear();
foreach (var serie in m_Series)
{
if (serie.type == SerieType.Pie)
if (!string.IsNullOrEmpty(serie.name) && !serieNameList.Contains(serie.name))
{
foreach (var data in serie.data)
{
if (!string.IsNullOrEmpty(data.name) && !serieNameList.Contains(data.name))
{
serieNameList.Add(data.name);
}
}
serieNameList.Add(serie.name);
}
else
foreach (var data in serie.data)
{
if (!string.IsNullOrEmpty(serie.name) && !serieNameList.Contains(serie.name))
if (!string.IsNullOrEmpty(data.name) && !serieNameList.Contains(data.name))
{
serieNameList.Add(serie.name);
serieNameList.Add(data.name);
}
}
}

View File

@@ -0,0 +1,83 @@
using UnityEngine;
namespace XCharts
{
/// <summary>
/// The style of area.
/// 区域填充样式。
/// </summary>
[System.Serializable]
public class AreaStyle
{
/// <summary>
/// Origin position of area.
/// 图形区域的起始位置。默认情况下,图形会从坐标轴轴线到数据间进行填充。如果需要填充的区域是坐标轴最大值到数据间,或者坐标轴最小值到数据间,则可以通过这个配置项进行设置。
/// </summary>
public enum AreaOrigin
{
/// <summary>
/// to fill between axis line to data.
/// 填充坐标轴轴线到数据间的区域。
/// </summary>
Auto,
/// <summary>
/// to fill between min axis value (when not inverse) to data.
/// 填充坐标轴底部到数据间的区域。
/// </summary>
Start,
/// <summary>
/// to fill between max axis value (when not inverse) to data.
/// 填充坐标轴顶部到数据间的区域。
/// </summary>
End
}
[SerializeField] private bool m_Show;
[SerializeField] private AreaOrigin m_Origin;
[SerializeField] private Color m_Color;
[SerializeField] private Color m_ToColor;
[SerializeField][Range(0,1)] private float m_Opacity;
/// <summary>
/// Set this to false to prevent the areafrom showing.
/// 是否显示区域填充。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
///
/// 图形区域的起始位置。
/// </summary>
public AreaOrigin origin { get { return m_Origin; } set { m_Origin = value; } }
/// <summary>
/// the color of area,default use serie color.
/// 区域填充的颜色如果toColor不是默认值则表示渐变色的起点颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// Gradient color, start color to toColor.
/// 渐变色的终点颜色。
/// </summary>
/// <value></value>
public Color toColor { get { return m_ToColor; } set { m_ToColor = value; } }
/// <summary>
/// Opacity of the component. Supports value from 0 to 1, and the component will not be drawn when set to 0.
/// 图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opactiy { get { return m_Opacity; } set { m_Opacity = value; } }
public static AreaStyle defaultAreaStyle
{
get
{
var area = new AreaStyle
{
m_Show = false,
m_Color = Color.clear,
m_ToColor = Color.clear,
m_Opacity = 1
};
return area;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 031cbc008c7d34cb0ad96257d0bfa6d9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using System;
@@ -238,11 +239,25 @@ namespace XCharts
ChartHelper.ClearEventListener(btn.gameObject);
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
{
if (data.selectedObject == null) return;
if (data.selectedObject == null || m_Legend.selectedMode == Legend.SelectedMode.None) return;
var temp = data.selectedObject.name.Split('_');
string selectedName = temp[2];
int index = int.Parse(temp[1]);
OnLegendButtonClick(index, selectedName);
int clickedIndex = int.Parse(temp[1]);
if (m_Legend.selectedMode == Legend.SelectedMode.Multiple)
{
OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName));
}
else
{
var btnList = m_Legend.buttonList.Values.ToArray();
for (int n = 0; n < btnList.Length; n++)
{
temp = btnList[n].name.Split('_');
selectedName = temp[2];
var index = int.Parse(temp[1]);
OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false);
}
}
});
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerEnter, (data) =>
{
@@ -261,6 +276,13 @@ namespace XCharts
OnLegendButtonExit(index, selectedName);
});
}
if (m_Legend.selectedMode == Legend.SelectedMode.Single)
{
for (int n = 0; n < datas.Count; n++)
{
OnLegendButtonClick(n, datas[n], n == 0 ? true : false);
}
}
}
private void InitSerieLabel()
@@ -312,19 +334,14 @@ namespace XCharts
return m_Legend.location.GetPosition(chartWidth, chartHeight);
}
protected float GetMaxValue(int index)
{
return m_Series.GetMaxValue(index);
}
private void CheckSize()
{
if (m_CheckWidth != chartWidth || m_CheckHeight != chartHeight)
{
SetSize(chartWidth, chartHeight);
}
var sizeDelta = rectTransform.sizeDelta;
if (m_CheckWidth != sizeDelta.x || m_CheckHeight != sizeDelta.y)
if (m_CheckWidth == 0 && m_CheckHeight == 0 && (sizeDelta.x != 0 || sizeDelta.y != 0))
{
Awake();
}
else if (m_CheckWidth != sizeDelta.x || m_CheckHeight != sizeDelta.y)
{
SetSize(sizeDelta.x, sizeDelta.y);
}
@@ -378,7 +395,6 @@ namespace XCharts
{
if (!m_Tooltip.show || !m_Tooltip.inited)
{
if (m_Tooltip.dataIndex[0] != 0 || m_Tooltip.dataIndex[1] != 0)
{
m_Tooltip.dataIndex[0] = m_Tooltip.dataIndex[1] = -1;
@@ -481,11 +497,11 @@ namespace XCharts
{
}
protected virtual void OnLegendButtonClick(int index, string legendName)
protected virtual void OnLegendButtonClick(int index, string legendName, bool show)
{
foreach (var serie in m_Series.GetSeries(legendName))
{
SetActive(serie.index, !serie.show);
SetActive(serie.index, show);
}
OnYMaxValueChanged();
RefreshChart();
@@ -495,12 +511,65 @@ namespace XCharts
{
var serie = m_Series.GetSerie(index);
serie.highlighted = true;
RefreshChart();
}
protected virtual void OnLegendButtonExit(int index, string legendName)
{
var serie = m_Series.GetSerie(index);
serie.highlighted = false;
RefreshChart();
}
protected bool CheckDataShow(string legendName, bool show)
{
bool needShow = false;
foreach (var serie in m_Series.series)
{
if (legendName.Equals(serie.name))
{
serie.show = show;
serie.highlighted = false;
if (serie.show) needShow = true;
}
else
{
foreach (var data in serie.data)
{
if (legendName.Equals(data.name))
{
data.show = show;
data.highlighted = false;
if (data.show) needShow = true;
}
}
}
}
return needShow;
}
protected bool CheckDataHighlighted(string legendName, bool heighlight)
{
bool show = false;
foreach (var serie in m_Series.series)
{
if (legendName.Equals(serie.name))
{
serie.highlighted = heighlight;
}
else
{
foreach (var data in serie.data)
{
if (legendName.Equals(data.name))
{
data.highlighted = heighlight;
if (data.highlighted) show = true;
}
}
}
}
return show;
}
protected virtual void RefreshTooltip()

View File

@@ -81,10 +81,12 @@ namespace XCharts
/// <param name="height">height</param>
public virtual void SetSize(float width, float height)
{
Debug.LogError("setsize:" + m_CheckWidth + "," + m_CheckHeight + "," + width + height);
m_ChartWidth = width;
m_ChartHeight = height;
m_CheckWidth = width;
m_CheckHeight = height;
rectTransform.sizeDelta = new Vector2(m_ChartWidth, m_ChartHeight);
OnSizeChanged();
}
@@ -321,7 +323,25 @@ namespace XCharts
/// <returns></returns>
public virtual bool IsActiveByLegend(string legendName)
{
return IsActive(legendName);
foreach (var serie in m_Series.series)
{
if (serie.show && legendName.Equals(serie.name))
{
return true;
}
else
{
foreach (var serieData in serie.data)
{
if (serieData.show && legendName.Equals(serieData.name))
{
return true;
}
}
}
}
return false;
}
/// <summary>

View File

@@ -0,0 +1,55 @@
using UnityEngine;
namespace XCharts
{
/// <summary>
/// The style of line.
/// 线条样式。
/// 注: 修改 lineStyle 中的颜色不会影响图例颜色,如果需要图例颜色和折线图颜色一致,需修改 itemStyle.color线条颜色默认也会取改颜色。
/// </summary>
[System.Serializable]
public class LineStyle
{
/// <summary>
/// 线的类型。
/// </summary>
public enum Type
{
Solid,
Dashed,
Dotted
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Type m_Type = Type.Solid;
[SerializeField] private Color m_Color;
[SerializeField] private float m_Width = 0.8f;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
/// <summary>
/// Set this to false to prevent the areafrom showing.
/// 是否显示区域填充。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// the type of line.
/// 线的类型。
/// </summary>
public Type type { get { return m_Type; } set { m_Type = value; } }
/// <summary>
/// the color of line, default use serie color.
/// 线的颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// the width of line.
/// 线宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// Opacity of the line. Supports value from 0 to 1, and the line will not be drawn when set to 0.
/// 线的透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opactiy { get { return m_Opacity; } set { m_Opacity = value; } }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 22d2d2622e9364e80a073f9c2e4cdd0d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -47,5 +48,21 @@ namespace XCharts
/// 该数据项的文本标签。
/// </summary>
public Text label { get; set; }
/// <summary>
/// the maxinum value.
/// 最大值。
/// </summary>
public float max { get { return m_Data.Max(); } }
/// <summary>
/// the mininum value.
/// 最小值。
/// </summary>
public float min { get { return m_Data.Min(); } }
public float GetData(int index)
{
if (index >= 0 && index < m_Data.Count) return m_Data[index];
else return 0;
}
}
}

View File

@@ -73,8 +73,8 @@ namespace XCharts
{
[SerializeField] private SerieSymbolType m_Type = SerieSymbolType.EmptyCircle;
[SerializeField] private SerieSymbolSizeType m_SizeType = SerieSymbolSizeType.Custom;
[SerializeField] private float m_Size = 20f;
[SerializeField] private float m_SelectedSize = 30f;
[SerializeField] private float m_Size = 6f;
[SerializeField] private float m_SelectedSize = 10f;
[SerializeField] private int m_DataIndex = 1;
[SerializeField] private float m_DataScale = 1;
[SerializeField] private float m_SelectedDataScale = 1.5f;

View File

@@ -31,30 +31,6 @@ namespace XCharts
public Pie pie { get { return m_Pie; } }
/// <summary>
/// Where legend is activated.
/// </summary>
/// <param name="legendName">the name of legend</param>
/// <returns></returns>
public override bool IsActiveByLegend(string legendName)
{
foreach (var serie in m_Series.series)
{
foreach (var serieData in serie.data)
{
if (string.IsNullOrEmpty(serieData.name))
{
if (string.IsNullOrEmpty(legendName)) return true;
}
else if (serieData.name.Equals(legendName))
{
return true;
}
}
}
return false;
}
protected override void Awake()
{
base.Awake();
@@ -152,7 +128,7 @@ namespace XCharts
tempData.angleList.Add(0);
continue;
}
float degree = serie.roseType == RoseType.Area ? (totalDegree / showdataCount) : (totalDegree * value / tempData.dataTotal);
float degree = serie.roseType == RoseType.Area ? (totalDegree / showdataCount) : (totalDegree * value / tempData.dataTotal);
float toDegree = startDegree + degree;
float outSideRadius = serie.roseType > 0 ?
@@ -429,9 +405,9 @@ namespace XCharts
}
}
protected override void OnLegendButtonClick(int index, string legendName)
protected override void OnLegendButtonClick(int index, string legendName, bool show)
{
bool active = CheckDataShow(legendName);
bool active = CheckDataShow(legendName, show);
var bgColor1 = active ? m_ThemeInfo.GetColor(index) : m_ThemeInfo.legendUnableColor;
m_Legend.UpdateButtonColor(legendName, bgColor1);
RefreshChart();
@@ -440,52 +416,17 @@ namespace XCharts
protected override void OnLegendButtonEnter(int index, string legendName)
{
m_IsEnterLegendButtom = true;
CheckDataHighlighted(legendName);
CheckDataHighlighted(legendName, true);
RefreshChart();
}
protected override void OnLegendButtonExit(int index, string legendName)
{
m_IsEnterLegendButtom = false;
CheckDataHighlighted(legendName);
CheckDataHighlighted(legendName, false);
RefreshChart();
}
private bool CheckDataShow(string legendName)
{
bool show = false;
foreach (var serie in m_Series.series)
{
foreach (var data in serie.data)
{
if (legendName.Equals(data.name))
{
data.show = !data.show;
data.highlighted = false;
if (data.show) show = true;
}
}
}
return show;
}
private bool CheckDataHighlighted(string legendName)
{
bool show = false;
foreach (var serie in m_Series.series)
{
foreach (var data in serie.data)
{
if (legendName.Equals(data.name))
{
data.highlighted = !data.highlighted;
if (data.highlighted) show = true;
}
}
}
return show;
}
private void UpdatePieCenter(Serie serie)
{
if (serie.center.Length < 2) return;

View File

@@ -13,16 +13,13 @@ namespace XCharts
{
private const string INDICATOR_TEXT = "indicator";
[SerializeField]
private Radar m_Radar = Radar.defaultRadar;
private Radar m_CheckRadar = Radar.defaultRadar;
private float m_RadarCenterX = 0f;
private float m_RadarCenterY = 0f;
private float m_RadarRadius = 0;
private List<Text> indicatorTextList = new List<Text>();
private List<List<Vector3>> dataPosList = new List<List<Vector3>>();
//[SerializeField] private Radar radar = Radar.defaultRadar;
[SerializeField] private List<Radar> m_Radars = new List<Radar>();
private List<Radar> m_CheckRadars = new List<Radar>();
private bool m_IsEnterLegendButtom;
public Radar radar { get { return m_Radar; } }
//public Radar radar { get { return radar; } }
public List<Radar> radars { get { return m_Radars; } }
/// <summary>
/// 移除所有数据,包含指示器数据。
@@ -30,12 +27,38 @@ namespace XCharts
public override void RemoveData()
{
base.RemoveData();
m_Radar.indicatorList.Clear();
foreach (var radar in m_Radars)
{
radar.indicatorList.Clear();
}
m_CheckRadars.Clear();
}
protected override void OnLegendButtonClick(int index, string legendName, bool show)
{
bool active = CheckDataShow(legendName, show);
var bgColor1 = active ? m_ThemeInfo.GetColor(index) : m_ThemeInfo.legendUnableColor;
m_Legend.UpdateButtonColor(legendName, bgColor1);
RefreshChart();
}
protected override void OnLegendButtonEnter(int index, string legendName)
{
m_IsEnterLegendButtom = true;
CheckDataHighlighted(legendName, true);
RefreshChart();
}
protected override void OnLegendButtonExit(int index, string legendName)
{
m_IsEnterLegendButtom = false;
CheckDataHighlighted(legendName, false);
RefreshChart();
}
protected override void Awake()
{
base.Awake();
UpdateRadarCenter();
InitIndicator();
}
@@ -50,198 +73,255 @@ namespace XCharts
{
base.Reset();
RemoveData();
m_Radar = Radar.defaultRadar;
m_Radars.Add(Radar.defaultRadar);
m_Title.text = "RadarChart";
AddSerie("serie1", SerieType.Radar);
var serie = AddSerie("serie1", SerieType.Radar);
serie.symbol.type = SerieSymbolType.EmptyCircle;
serie.symbol.size = 4;
serie.symbol.selectedSize = 6;
List<float> data = new List<float>();
for (int i = 0; i < 5; i++)
{
AddData(0, Random.Range(20, 90));
data.Add(Random.Range(20, 90));
}
AddData(0, data);
}
#endif
private void InitIndicator()
{
indicatorTextList.Clear();
ChartHelper.HideAllObject(transform, INDICATOR_TEXT);
int indicatorNum = m_Radar.indicatorList.Count;
float txtWid = 100;
float txtHig = 20;
for (int i = 0; i < indicatorNum; i++)
for (int n = 0; n < m_Radars.Count; n++)
{
var pos = GetIndicatorPosition(i);
TextAnchor anchor = TextAnchor.MiddleCenter;
var diff = pos.x - m_RadarCenterX;
if (diff < -1f)
Radar radar = m_Radars[n];
radar.UpdateRadarCenter(chartWidth, chartHeight);
int indicatorNum = radar.indicatorList.Count;
float txtWid = 100;
float txtHig = 20;
for (int i = 0; i < indicatorNum; i++)
{
pos = new Vector3(pos.x - 5, pos.y);
anchor = TextAnchor.MiddleRight;
var indicator = radar.indicatorList[i];
var pos = radar.GetIndicatorPosition(i);
TextAnchor anchor = TextAnchor.MiddleCenter;
var diff = pos.x - radar.centerPos.x;
if (diff < -1f)
{
pos = new Vector3(pos.x - 5, pos.y);
anchor = TextAnchor.MiddleRight;
}
else if (diff > 1f)
{
anchor = TextAnchor.MiddleLeft;
pos = new Vector3(pos.x + txtWid + 5, pos.y);
}
else
{
anchor = TextAnchor.MiddleCenter;
float y = pos.y > radar.centerPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
pos = new Vector3(pos.x + txtWid / 2, y);
}
var textColor = indicator.color == Color.clear ? (Color)m_ThemeInfo.axisTextColor : indicator.color;
Text txt = ChartHelper.AddTextObject(INDICATOR_TEXT + "_" + n + "_" + i, transform, m_ThemeInfo.font,
textColor, anchor, Vector2.zero, Vector2.zero, new Vector2(1, 0.5f),
new Vector2(txtWid, txtHig));
txt.transform.localPosition = pos;
txt.text = radar.indicatorList[i].name;
txt.gameObject.SetActive(radar.indicator);
}
else if (diff > 1f)
{
anchor = TextAnchor.MiddleLeft;
pos = new Vector3(pos.x + txtWid + 5, pos.y);
}
else
{
anchor = TextAnchor.MiddleCenter;
float y = pos.y > m_RadarCenterY ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
pos = new Vector3(pos.x + txtWid / 2, y);
}
Text txt = ChartHelper.AddTextObject(INDICATOR_TEXT + i, transform, m_ThemeInfo.font,
m_ThemeInfo.titleTextColor, anchor, Vector2.zero, Vector2.zero, new Vector2(1, 0.5f),
new Vector2(txtWid, txtHig));
txt.transform.localPosition = pos;
txt.text = m_Radar.indicatorList[i].name;
txt.gameObject.SetActive(m_Radar.indicator);
indicatorTextList.Add(txt);
}
}
private void CheckRadarInfoChanged()
{
if (m_CheckRadar != m_Radar)
if (!ChartHelper.IsValueEqualsList(m_CheckRadars, m_Radars))
{
m_CheckRadar.Copy(m_Radar);
m_CheckRadars.Clear();
foreach (var radar in m_Radars) m_CheckRadars.Add(radar.Clone());
OnRadarChanged();
}
}
private void OnRadarChanged()
{
UpdateRadarCenter();
InitIndicator();
m_Tooltip.UpdateToTop();
}
private Vector3 GetIndicatorPosition(int i)
{
int indicatorNum = m_Radar.indicatorList.Count;
var angle = 2 * Mathf.PI / indicatorNum * i;
var x = m_RadarCenterX + m_Radar.radius * Mathf.Sin(angle);
var y = m_RadarCenterY + m_Radar.radius * Mathf.Cos(angle);
return new Vector3(x, y);
}
protected override void DrawChart(VertexHelper vh)
{
base.DrawChart(vh);
UpdateRadarCenter();
if (m_Radar.cricle)
DrawCricleRadar(vh);
else
DrawRadar(vh);
foreach (var radar in m_Radars)
{
radar.UpdateRadarCenter(chartWidth, chartHeight);
if (radar.shape == Radar.Shape.Circle)
{
DrawCricleRadar(vh, radar);
}
else
{
DrawRadar(vh, radar);
}
}
DrawData(vh);
}
protected override void OnThemeChanged()
{
base.OnThemeChanged();
m_Radar.backgroundColorList.Clear();
switch (m_ThemeInfo.theme)
foreach (var radar in m_Radars)
{
case Theme.Dark:
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#6f6f6f"));
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#606060"));
break;
case Theme.Default:
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#f6f6f6"));
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#e7e7e7"));
break;
case Theme.Light:
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#f6f6f6"));
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#e7e7e7"));
break;
radar.splitArea.color.Clear();
switch (m_ThemeInfo.theme)
{
case Theme.Dark:
radar.splitArea.color.Add(ThemeInfo.GetColor("#6f6f6f"));
radar.splitArea.color.Add(ThemeInfo.GetColor("#606060"));
break;
case Theme.Default:
radar.splitArea.color.Add(ThemeInfo.GetColor("#f6f6f6"));
radar.splitArea.color.Add(ThemeInfo.GetColor("#e7e7e7"));
break;
case Theme.Light:
radar.splitArea.color.Add(ThemeInfo.GetColor("#f6f6f6"));
radar.splitArea.color.Add(ThemeInfo.GetColor("#e7e7e7"));
break;
}
}
InitIndicator();
}
HashSet<string> serieNameSet = new HashSet<string>();
Dictionary<string, int> serieNameSet = new Dictionary<string, int>();
private void DrawData(VertexHelper vh)
{
int indicatorNum = m_Radar.indicatorList.Count;
var angle = 2 * Mathf.PI / indicatorNum;
var p = new Vector3(m_RadarCenterX, m_RadarCenterY);
Vector3 startPoint = Vector3.zero;
Vector3 toPoint = Vector3.zero;
Vector3 firstPoint = Vector3.zero;
dataPosList.Clear();
dataPosList.Capacity = m_Series.Count;
serieNameSet.Clear();
int serieNameCount = -1;
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.series[i];
if (string.IsNullOrEmpty(serie.name)) serieNameCount++;
else if (!serieNameSet.Contains(serie.name))
{
serieNameSet.Add(serie.name);
serieNameCount++;
}
var radar = m_Radars[serie.radarIndex];
int indicatorNum = radar.indicatorList.Count;
var angle = 2 * Mathf.PI / indicatorNum;
Vector3 p = radar.centerPos;
if (!IsActive(i))
{
dataPosList.Add(new List<Vector3>());
continue;
}
var dataList = m_Series.series[i].yData;
var color = m_ThemeInfo.GetColor(i);
var areaColor = color;
areaColor.a = (byte)m_Radar.areaAlpha;
List<Vector3> pointList = new List<Vector3>(dataList.Count);
dataPosList.Add(pointList);
for (int j = 0; j < dataList.Count; j++)
for (int j = 0; j < serie.data.Count; j++)
{
var max = m_Radar.GetIndicatorMax(j) > 0 ?
m_Radar.GetIndicatorMax(j) :
GetMaxValue(j);
var radius = max < 0 ? m_Radar.radius - m_Radar.radius * dataList[j] / max
: m_Radar.radius * dataList[j] / max;
var currAngle = j * angle;
if (j == 0)
var serieData = serie.data[j];
int key = i * 100 + j;
if (!radar.dataPosList.ContainsKey(key))
{
startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
p.y + radius * Mathf.Cos(currAngle));
firstPoint = startPoint;
radar.dataPosList.Add(i * 100 + j, new List<Vector3>(serieData.data.Count));
}
else
{
toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
p.y + radius * Mathf.Cos(currAngle));
if (m_Radar.area)
{
ChartHelper.DrawTriangle(vh, p, startPoint, toPoint, areaColor);
}
ChartHelper.DrawLine(vh, startPoint, toPoint, m_Radar.lineTickness, color);
startPoint = toPoint;
radar.dataPosList[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;
}
var isHighlight = serie.highlighted || serieData.highlighted ||
(m_Tooltip.show && m_Tooltip.dataIndex[0] == i && m_Tooltip.dataIndex[1] == j);
var areaColor = serie.GetAreaColor(m_ThemeInfo, serieIndex, isHighlight);
var lineColor = serie.GetLineColor(m_ThemeInfo, serieIndex, isHighlight);
int dataCount = radar.indicatorList.Count;
List<Vector3> pointList = radar.dataPosList[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.data[n];
if (max == 0)
{
serie.GetMinMaxData(n, out min, out max);
min = radar.GetIndicatorMin(n);
}
var radius = max < 0 ? radar.actualRadius - radar.actualRadius * value / max
: radar.actualRadius * value / max;
var currAngle = n * angle;
if (n == 0)
{
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)
{
ChartHelper.DrawTriangle(vh, p, startPoint, toPoint, areaColor);
}
if (serie.lineStyle.show)
{
ChartHelper.DrawLine(vh, startPoint, toPoint, serie.lineStyle.width, lineColor);
}
startPoint = toPoint;
}
pointList.Add(startPoint);
}
if (serie.areaStyle.show)
{
ChartHelper.DrawTriangle(vh, p, startPoint, firstPoint, areaColor);
}
if (serie.lineStyle.show)
{
ChartHelper.DrawLine(vh, startPoint, firstPoint, serie.lineStyle.width, lineColor);
}
if (serie.symbol.type != SerieSymbolType.None)
{
var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size);
float symbolRadius = symbolSize - serie.lineStyle.width * 2;
foreach (var point in pointList)
{
DrawSymbol(vh, serie.symbol.type, symbolSize, serie.lineStyle.width, point, lineColor);
}
}
pointList.Add(startPoint);
}
if (m_Radar.area) ChartHelper.DrawTriangle(vh, p, startPoint, firstPoint, areaColor);
ChartHelper.DrawLine(vh, startPoint, firstPoint, m_Radar.lineTickness, color);
foreach (var point in pointList)
{
float radius = m_Radar.linePointSize - m_Radar.lineTickness * 2;
ChartHelper.DrawCricle(vh, point, radius, Color.white);
ChartHelper.DrawDoughnut(vh, point, radius, m_Radar.linePointSize, 0, 360, color);
}
}
}
private void DrawRadar(VertexHelper vh)
private void DrawRadar(VertexHelper vh, Radar radar)
{
float insideRadius = 0, outsideRadius = 0;
float block = m_Radar.radius / m_Radar.splitNumber;
int indicatorNum = m_Radar.indicatorList.Count;
Vector3 p1, p2, p3, p4;
Vector3 p = new Vector3(m_RadarCenterX, m_RadarCenterY);
float angle = 2 * Mathf.PI / indicatorNum;
for (int i = 0; i < m_Radar.splitNumber; i++)
if (!radar.lineStyle.show && !radar.splitArea.show)
{
Color color = m_Radar.backgroundColorList[i % m_Radar.backgroundColorList.Count];
return;
}
float insideRadius = 0, outsideRadius = 0;
float block = radar.actualRadius / radar.splitNumber;
int indicatorNum = radar.indicatorList.Count;
Vector3 p1, p2, p3, p4;
Vector3 p = radar.centerPos;
float angle = 2 * Mathf.PI / indicatorNum;
var lineColor = GetLineColor(radar);
for (int i = 0; i < radar.splitNumber; i++)
{
Color color = radar.splitArea.color[i % radar.splitArea.color.Count];
outsideRadius = insideRadius + block;
p1 = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0));
p2 = new Vector3(p.x + outsideRadius * Mathf.Sin(0), p.y + outsideRadius * Mathf.Cos(0));
@@ -252,9 +332,14 @@ namespace XCharts
p.y + outsideRadius * Mathf.Cos(currAngle));
p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle),
p.y + insideRadius * Mathf.Cos(currAngle));
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
ChartHelper.DrawLine(vh, p2, p3, m_Radar.lineTickness, m_Radar.lineColor);
if (radar.splitArea.show)
{
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
}
if (radar.lineStyle.show)
{
ChartHelper.DrawLine(vh, p2, p3, radar.lineStyle.width, lineColor);
}
p1 = p4;
p2 = p3;
}
@@ -265,24 +350,38 @@ namespace XCharts
float currAngle = j * angle;
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
p.y + outsideRadius * Mathf.Cos(currAngle));
ChartHelper.DrawLine(vh, p, p3, m_Radar.lineTickness / 2, m_Radar.lineColor);
if (radar.lineStyle.show)
{
ChartHelper.DrawLine(vh, p, p3, radar.lineStyle.width / 2, lineColor);
}
}
}
private void DrawCricleRadar(VertexHelper vh)
private void DrawCricleRadar(VertexHelper vh, Radar radar)
{
if (!radar.lineStyle.show && !radar.splitArea.show)
{
return;
}
float insideRadius = 0, outsideRadius = 0;
float block = m_Radar.radius / m_Radar.splitNumber;
int indicatorNum = m_Radar.indicatorList.Count;
Vector3 p = new Vector3(m_RadarCenterX, m_RadarCenterY);
float block = radar.actualRadius / radar.splitNumber;
int indicatorNum = radar.indicatorList.Count;
Vector3 p = radar.centerPos;
Vector3 p1;
float angle = 2 * Mathf.PI / indicatorNum;
for (int i = 0; i < m_Radar.splitNumber; i++)
var lineColor = GetLineColor(radar);
for (int i = 0; i < radar.splitNumber; i++)
{
Color color = m_Radar.backgroundColorList[i % m_Radar.backgroundColorList.Count];
Color color = radar.splitArea.color[i % radar.splitArea.color.Count];
outsideRadius = insideRadius + block;
ChartHelper.DrawDoughnut(vh, p, insideRadius, outsideRadius, 0, 360, color);
ChartHelper.DrawCicleNotFill(vh, p, outsideRadius, m_Radar.lineTickness, m_Radar.lineColor);
if (radar.splitArea.show)
{
ChartHelper.DrawDoughnut(vh, p, insideRadius, outsideRadius, 0, 360, color);
}
if (radar.lineStyle.show)
{
ChartHelper.DrawCicleNotFill(vh, p, outsideRadius, radar.lineStyle.width, lineColor);
}
insideRadius = outsideRadius;
}
for (int j = 0; j <= indicatorNum; j++)
@@ -290,76 +389,99 @@ namespace XCharts
float currAngle = j * angle;
p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
p.y + outsideRadius * Mathf.Cos(currAngle));
ChartHelper.DrawLine(vh, p, p1, m_Radar.lineTickness / 2, m_Radar.lineColor);
if (radar.lineStyle.show)
{
ChartHelper.DrawLine(vh, p, p1, radar.lineStyle.width / 2, lineColor);
}
}
}
private void UpdateRadarCenter()
private Color GetLineColor(Radar radar)
{
float diffX = chartWidth - m_Radar.left - m_Radar.right;
float diffY = chartHeight - m_Radar.top - m_Radar.bottom;
float diff = Mathf.Min(diffX, diffY);
if (m_Radar.radius <= 0)
if (radar.lineStyle.color != Color.clear)
{
m_RadarRadius = diff / 3 * 2;
m_RadarCenterX = m_Radar.left + m_RadarRadius;
m_RadarCenterY = m_Radar.bottom + m_RadarRadius;
var color = radar.lineStyle.color;
color.a *= radar.lineStyle.opactiy;
return color;
}
else
{
m_RadarRadius = m_Radar.radius;
m_RadarCenterX = chartWidth / 2;
m_RadarCenterY = chartHeight / 2;
if (m_Radar.left > 0) m_RadarCenterX = m_Radar.left + m_RadarRadius;
if (m_Radar.right > 0) m_RadarCenterX = chartWidth - m_Radar.right - m_RadarRadius;
if (m_Radar.top > 0) m_RadarCenterY = chartHeight - m_Radar.top - m_RadarRadius;
if (m_Radar.bottom > 0) m_RadarCenterY = m_Radar.bottom + m_RadarRadius;
var color = (Color)m_ThemeInfo.axisLineColor;
color.a *= radar.lineStyle.opactiy;
return color;
}
}
protected override void CheckTootipArea(Vector2 local)
{
if (dataPosList.Count <= 0) return;
m_Tooltip.dataIndex[0] = -1;
if (m_IsEnterLegendButtom) return;
bool highlight = false;
for (int i = 0; i < m_Series.Count; i++)
{
if (!IsActive(i)) continue;
for (int j = 0; j < dataPosList[i].Count; j++)
var serie = m_Series.GetSerie(i);
var radar = m_Radars[serie.radarIndex];
var dist = Vector2.Distance(radar.centerPos, local);
if (dist > radar.actualRadius + serie.symbol.size)
{
if (Vector3.Distance(local, dataPosList[i][j]) <= m_Radar.linePointSize * 1.2f)
continue;
}
for (int n = 0; n < serie.data.Count; n++)
{
var posKey = i * 100 + n;
if (radar.dataPosList.ContainsKey(posKey))
{
m_Tooltip.dataIndex[0] = i;
break;
var posList = radar.dataPosList[posKey];
foreach (var pos in posList)
{
if (Vector2.Distance(pos, local) <= serie.symbol.size * 1.2f)
{
m_Tooltip.dataIndex[0] = i;
m_Tooltip.dataIndex[1] = n;
highlight = true;
break;
}
}
}
}
}
if (m_Tooltip.dataIndex[0] >= 0)
if (!highlight)
{
if (m_Tooltip.IsActive())
{
m_Tooltip.SetActive(false);
RefreshChart();
}
}
else
{
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
RefreshTooltip();
RefreshChart();
}
else
{
m_Tooltip.SetActive(false);
}
}
protected override void RefreshTooltip()
{
base.RefreshTooltip();
int index = m_Tooltip.dataIndex[0];
if (index < 0)
int serieIndex = m_Tooltip.dataIndex[0];
if (serieIndex < 0)
{
m_Tooltip.SetActive(false);
return;
}
m_Tooltip.SetActive(true);
StringBuilder sb = new StringBuilder(m_Legend.data[index]);
for (int i = 0; i < m_Radar.indicatorList.Count; i++)
var serie = m_Series.GetSerie(serieIndex);
var radar = m_Radars[serie.radarIndex];
var serieData = serie.GetSerieData(m_Tooltip.dataIndex[1]);
StringBuilder sb = new StringBuilder(serieData.name);
for (int i = 0; i < radar.indicatorList.Count; i++)
{
string key = m_Radar.indicatorList[i].name;
float value = m_Series.series[index].yData[i];
string key = radar.indicatorList[i].name;
float value = serieData.GetData(i);
sb.Append("\n");
sb.AppendFormat("{0}: {1}", key, value);
}

View File

@@ -9,7 +9,7 @@ namespace XCharts
{
public static class ChartHelper
{
public static float CRICLE_SMOOTHNESS = 2.5f;
public static float CRICLE_SMOOTHNESS = 2f;
private static UIVertex[] vertex = new UIVertex[4];
public static void HideAllObject(GameObject obj, string match = null)