mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-30 13:28:47 +00:00
增加PieChart多饼图支持
This commit is contained in:
239061
Demo/Prefabs/xchart.prefab
239061
Demo/Prefabs/xchart.prefab
File diff suppressed because it is too large
Load Diff
@@ -24,12 +24,12 @@ public class Demo_PieChart : MonoBehaviour
|
|||||||
time = 0;
|
time = 0;
|
||||||
if (count < 5)
|
if (count < 5)
|
||||||
{
|
{
|
||||||
chart.AddData("time" + count, Random.Range(10, 100));
|
chart.AddData(0, Random.Range(10, 100), "time" + count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int index = count % 5;
|
int index = count % 5;
|
||||||
chart.UpdateData("time" + index, Random.Range(10, 100));
|
chart.UpdateData(0, Random.Range(10, 100),index);
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|||||||
109680
Demo/demo_xchart.unity
109680
Demo/demo_xchart.unity
File diff suppressed because it is too large
Load Diff
@@ -23,18 +23,7 @@ namespace XCharts
|
|||||||
|
|
||||||
private void InitProperty(SerializedProperty prop)
|
private void InitProperty(SerializedProperty prop)
|
||||||
{
|
{
|
||||||
m_Name = prop.FindPropertyRelative("m_Name");
|
|
||||||
m_InsideRadius = prop.FindPropertyRelative("m_InsideRadius");
|
|
||||||
m_OutsideRadius = prop.FindPropertyRelative("m_OutsideRadius");
|
|
||||||
m_TooltipExtraRadius = prop.FindPropertyRelative("m_TooltipExtraRadius");
|
m_TooltipExtraRadius = prop.FindPropertyRelative("m_TooltipExtraRadius");
|
||||||
m_Rose = prop.FindPropertyRelative("m_Rose");
|
|
||||||
m_Space = prop.FindPropertyRelative("m_Space");
|
|
||||||
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_Selected = prop.FindPropertyRelative("m_Selected");
|
|
||||||
m_SelectedIndex = prop.FindPropertyRelative("m_SelectedIndex");
|
|
||||||
m_SelectedOffset = prop.FindPropertyRelative("m_SelectedOffset");
|
m_SelectedOffset = prop.FindPropertyRelative("m_SelectedOffset");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,32 +37,10 @@ namespace XCharts
|
|||||||
if (m_PieModuleToggle)
|
if (m_PieModuleToggle)
|
||||||
{
|
{
|
||||||
++EditorGUI.indentLevel;
|
++EditorGUI.indentLevel;
|
||||||
EditorGUI.PropertyField(drawRect, m_Name);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_InsideRadius);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_OutsideRadius);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_TooltipExtraRadius);
|
EditorGUI.PropertyField(drawRect, m_TooltipExtraRadius);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_Selected);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_SelectedIndex);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_SelectedOffset);
|
EditorGUI.PropertyField(drawRect, m_SelectedOffset);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_Rose);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_Space);
|
|
||||||
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.indentLevel;
|
--EditorGUI.indentLevel;
|
||||||
}
|
}
|
||||||
@@ -82,7 +49,7 @@ namespace XCharts
|
|||||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||||
{
|
{
|
||||||
if (m_PieModuleToggle)
|
if (m_PieModuleToggle)
|
||||||
return 14 * EditorGUIUtility.singleLineHeight + 13 * EditorGUIUtility.standardVerticalSpacing;
|
return 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
|
||||||
else
|
else
|
||||||
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ namespace XCharts
|
|||||||
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_Symbol = prop.FindPropertyRelative("m_Symbol");
|
SerializedProperty m_Symbol = prop.FindPropertyRelative("m_Symbol");
|
||||||
|
SerializedProperty m_RoseType = prop.FindPropertyRelative("m_RoseType");
|
||||||
|
SerializedProperty m_ClickOffset = prop.FindPropertyRelative("m_ClickOffset");
|
||||||
|
SerializedProperty m_Space = prop.FindPropertyRelative("m_Space");
|
||||||
|
SerializedProperty m_Center = prop.FindPropertyRelative("m_Center");
|
||||||
|
SerializedProperty m_Radius = prop.FindPropertyRelative("m_Radius");
|
||||||
SerializedProperty m_DataDimension = prop.FindPropertyRelative("m_ShowDataDimension");
|
SerializedProperty m_DataDimension = prop.FindPropertyRelative("m_ShowDataDimension");
|
||||||
SerializedProperty m_ShowDataName = prop.FindPropertyRelative("m_ShowDataName");
|
SerializedProperty m_ShowDataName = prop.FindPropertyRelative("m_ShowDataName");
|
||||||
SerializedProperty m_Datas = prop.FindPropertyRelative("m_Data");
|
SerializedProperty m_Datas = prop.FindPropertyRelative("m_Data");
|
||||||
@@ -31,10 +36,19 @@ namespace XCharts
|
|||||||
string moduleName = "Serie " + index;
|
string moduleName = "Serie " + index;
|
||||||
bool toggle = m_SerieModuleToggle[index];
|
bool toggle = m_SerieModuleToggle[index];
|
||||||
m_SerieModuleToggle[index] = ChartEditorHelper.MakeFoldout(ref drawRect, ref toggle, moduleName, show);
|
m_SerieModuleToggle[index] = ChartEditorHelper.MakeFoldout(ref drawRect, ref toggle, moduleName, show);
|
||||||
|
if (!m_SerieModuleToggle[index])
|
||||||
|
{
|
||||||
|
drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2 + 20;
|
||||||
|
drawRect.width = pos.width - drawRect.x + 15;
|
||||||
|
EditorGUI.PropertyField(drawRect, type, GUIContent.none);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
if (m_SerieModuleToggle[index])
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
++EditorGUI.indentLevel;
|
++EditorGUI.indentLevel;
|
||||||
|
drawRect.x = pos.x;
|
||||||
|
drawRect.width = pos.width;
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, type);
|
EditorGUI.PropertyField(drawRect, type);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, name);
|
EditorGUI.PropertyField(drawRect, name);
|
||||||
@@ -43,13 +57,48 @@ namespace XCharts
|
|||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
EditorGUI.PropertyField(drawRect, m_AxisIndex);
|
EditorGUI.PropertyField(drawRect, m_AxisIndex);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
if (type.enumValueIndex == (int)SerieType.Line
|
|
||||||
|| type.enumValueIndex == (int)SerieType.Scatter
|
var serieType = (SerieType)type.enumValueIndex;
|
||||||
|| type.enumValueIndex == (int)SerieType.EffectScatter)
|
if (serieType == SerieType.Line
|
||||||
|
|| serieType == SerieType.Scatter
|
||||||
|
|| serieType == SerieType.EffectScatter)
|
||||||
{
|
{
|
||||||
EditorGUI.PropertyField(drawRect, m_Symbol);
|
EditorGUI.PropertyField(drawRect, m_Symbol);
|
||||||
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
|
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
|
||||||
}
|
}
|
||||||
|
if (serieType == SerieType.Pie)
|
||||||
|
{
|
||||||
|
EditorGUI.PropertyField(drawRect, m_RoseType);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Space);
|
||||||
|
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;
|
||||||
|
|
||||||
|
centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height);
|
||||||
|
centerYRect = new Rect(centerXRect.x + tempWidth - 20, drawRect.y, tempWidth, drawRect.height);
|
||||||
|
EditorGUI.LabelField(drawRect, "Radius");
|
||||||
|
while (m_Radius.arraySize < 2)
|
||||||
|
{
|
||||||
|
m_Radius.InsertArrayElementAtIndex(m_Radius.arraySize);
|
||||||
|
}
|
||||||
|
EditorGUI.PropertyField(centerXRect, m_Radius.GetArrayElementAtIndex(0), GUIContent.none);
|
||||||
|
EditorGUI.PropertyField(centerYRect, m_Radius.GetArrayElementAtIndex(1), GUIContent.none);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_ClickOffset);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
}
|
||||||
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
||||||
m_DataFoldout[index] = EditorGUI.Foldout(drawRect, m_DataFoldout[index], "Data");
|
m_DataFoldout[index] = EditorGUI.Foldout(drawRect, m_DataFoldout[index], "Data");
|
||||||
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop, pos.width);
|
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop, pos.width);
|
||||||
@@ -76,6 +125,7 @@ namespace XCharts
|
|||||||
if (m_DataDimension.intValue < 1) m_DataDimension.intValue = 1;
|
if (m_DataDimension.intValue < 1) m_DataDimension.intValue = 1;
|
||||||
int dimension = m_DataDimension.intValue;
|
int dimension = m_DataDimension.intValue;
|
||||||
bool showName = m_ShowDataName.boolValue;
|
bool showName = m_ShowDataName.boolValue;
|
||||||
|
bool showSelected = (serieType == SerieType.Pie);
|
||||||
if (listSize != m_Datas.arraySize)
|
if (listSize != m_Datas.arraySize)
|
||||||
{
|
{
|
||||||
while (listSize > m_Datas.arraySize)
|
while (listSize > m_Datas.arraySize)
|
||||||
@@ -88,20 +138,20 @@ namespace XCharts
|
|||||||
int num = listSize > 10 ? 10 : listSize;
|
int num = listSize > 10 ? 10 : listSize;
|
||||||
for (int i = 0; i < num; i++)
|
for (int i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
DrawDataElement(ref drawRect, dimension, m_Datas, showName, i, pos.width);
|
DrawDataElement(ref drawRect, dimension, m_Datas, showName, showSelected, i, pos.width);
|
||||||
}
|
}
|
||||||
if (num >= 10)
|
if (num >= 10)
|
||||||
{
|
{
|
||||||
EditorGUI.LabelField(drawRect, "...");
|
EditorGUI.LabelField(drawRect, "...");
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
DrawDataElement(ref drawRect, dimension, m_Datas, showName, listSize - 1, pos.width);
|
DrawDataElement(ref drawRect, dimension, m_Datas, showName, showSelected, listSize - 1, pos.width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_Datas.arraySize; i++)
|
for (int i = 0; i < m_Datas.arraySize; i++)
|
||||||
{
|
{
|
||||||
DrawDataElement(ref drawRect, dimension, m_Datas, showName, i, pos.width);
|
DrawDataElement(ref drawRect, dimension, m_Datas, showName, showSelected, i, pos.width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EditorGUI.indentLevel--;
|
EditorGUI.indentLevel--;
|
||||||
@@ -110,7 +160,8 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawDataElement(ref Rect drawRect, int dimension, SerializedProperty m_Datas, bool showName, int index, float currentWidth)
|
private void DrawDataElement(ref Rect drawRect, int dimension, SerializedProperty m_Datas, bool showName,
|
||||||
|
bool showSelected, int index, float currentWidth)
|
||||||
{
|
{
|
||||||
var lastX = drawRect.x;
|
var lastX = drawRect.x;
|
||||||
var lastWid = drawRect.width;
|
var lastWid = drawRect.width;
|
||||||
@@ -118,6 +169,7 @@ namespace XCharts
|
|||||||
var lastLabelWid = EditorGUIUtility.labelWidth;
|
var lastLabelWid = EditorGUIUtility.labelWidth;
|
||||||
var serieData = m_Datas.GetArrayElementAtIndex(index);
|
var serieData = m_Datas.GetArrayElementAtIndex(index);
|
||||||
var sereName = serieData.FindPropertyRelative("m_Name");
|
var sereName = serieData.FindPropertyRelative("m_Name");
|
||||||
|
var selected = serieData.FindPropertyRelative("m_Selected");
|
||||||
var data = serieData.FindPropertyRelative("m_Data");
|
var data = serieData.FindPropertyRelative("m_Data");
|
||||||
var fieldCount = dimension + (showName ? 1 : 0);
|
var fieldCount = dimension + (showName ? 1 : 0);
|
||||||
|
|
||||||
@@ -126,7 +178,20 @@ namespace XCharts
|
|||||||
while (2 > data.arraySize)
|
while (2 > data.arraySize)
|
||||||
data.InsertArrayElementAtIndex(data.arraySize);
|
data.InsertArrayElementAtIndex(data.arraySize);
|
||||||
SerializedProperty element = data.GetArrayElementAtIndex(1);
|
SerializedProperty element = data.GetArrayElementAtIndex(1);
|
||||||
|
if (showSelected)
|
||||||
|
{
|
||||||
|
drawRect.width = drawRect.width - 18;
|
||||||
EditorGUI.PropertyField(drawRect, element);
|
EditorGUI.PropertyField(drawRect, element);
|
||||||
|
drawRect.x = currentWidth - 45;
|
||||||
|
EditorGUI.PropertyField(drawRect, selected, GUIContent.none);
|
||||||
|
drawRect.x = lastX;
|
||||||
|
drawRect.width = lastWid;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EditorGUI.PropertyField(drawRect, element);
|
||||||
|
}
|
||||||
|
|
||||||
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -171,15 +236,20 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
|
height += 6 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
|
||||||
SerializedProperty type = prop.FindPropertyRelative("m_Type");
|
SerializedProperty type = prop.FindPropertyRelative("m_Type");
|
||||||
if (type.enumValueIndex == (int)SerieType.Line
|
var serieType = (SerieType)type.enumValueIndex;
|
||||||
|| type.enumValueIndex == (int)SerieType.Scatter
|
if (serieType == SerieType.Line
|
||||||
|| type.enumValueIndex == (int)SerieType.EffectScatter)
|
|| serieType == SerieType.Scatter
|
||||||
|
|| serieType == SerieType.EffectScatter)
|
||||||
{
|
{
|
||||||
|
|
||||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
|
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
|
||||||
}
|
}
|
||||||
|
if (serieType == SerieType.Pie)
|
||||||
|
{
|
||||||
|
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
}
|
||||||
if (m_DataFoldout[index])
|
if (m_DataFoldout[index])
|
||||||
{
|
{
|
||||||
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
||||||
|
|||||||
@@ -97,6 +97,12 @@ namespace XCharts
|
|||||||
Vector3 p2 = new Vector3(pX + barHig, pY + space + barWid);
|
Vector3 p2 = new Vector3(pX + barHig, pY + space + barWid);
|
||||||
Vector3 p3 = new Vector3(pX + barHig, pY + space);
|
Vector3 p3 = new Vector3(pX + barHig, pY + space);
|
||||||
Vector3 p4 = new Vector3(pX, pY + space);
|
Vector3 p4 = new Vector3(pX, pY + space);
|
||||||
|
if ((m_Tooltip.show && m_Tooltip.IsSelectedDataIndex(i))
|
||||||
|
|| serie.data[i].highlighted
|
||||||
|
|| serie.highlighted)
|
||||||
|
{
|
||||||
|
color *= 1.05f;
|
||||||
|
}
|
||||||
if (serie.show)
|
if (serie.show)
|
||||||
{
|
{
|
||||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
|
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||||
@@ -147,6 +153,12 @@ namespace XCharts
|
|||||||
Vector3 p2 = new Vector3(pX + space, pY + barHig);
|
Vector3 p2 = new Vector3(pX + space, pY + barHig);
|
||||||
Vector3 p3 = new Vector3(pX + space + barWid, pY + barHig);
|
Vector3 p3 = new Vector3(pX + space + barWid, pY + barHig);
|
||||||
Vector3 p4 = new Vector3(pX + space + barWid, pY);
|
Vector3 p4 = new Vector3(pX + space + barWid, pY);
|
||||||
|
if ((m_Tooltip.show && m_Tooltip.IsSelectedDataIndex(i))
|
||||||
|
|| serie.data[i].highlighted
|
||||||
|
|| serie.highlighted)
|
||||||
|
{
|
||||||
|
color *= 1.05f;
|
||||||
|
}
|
||||||
if (serie.show)
|
if (serie.show)
|
||||||
{
|
{
|
||||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
|
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace XCharts
|
|||||||
Vertical
|
Vertical
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BaseChart : Graphic, IPointerDownHandler, IPointerUpHandler,
|
public partial class BaseChart : Graphic, IPointerDownHandler, IPointerUpHandler,
|
||||||
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler,
|
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler,
|
||||||
IDragHandler, IEndDragHandler, IScrollHandler
|
IDragHandler, IEndDragHandler, IScrollHandler
|
||||||
{
|
{
|
||||||
@@ -26,7 +26,6 @@ namespace XCharts
|
|||||||
[SerializeField] protected Legend m_Legend = Legend.defaultLegend;
|
[SerializeField] protected Legend m_Legend = Legend.defaultLegend;
|
||||||
[SerializeField] protected Tooltip m_Tooltip = Tooltip.defaultTooltip;
|
[SerializeField] protected Tooltip m_Tooltip = Tooltip.defaultTooltip;
|
||||||
[SerializeField] protected Series m_Series = Series.defaultSeries;
|
[SerializeField] protected Series m_Series = Series.defaultSeries;
|
||||||
|
|
||||||
[SerializeField] protected float m_Large = 1;
|
[SerializeField] protected float m_Large = 1;
|
||||||
[SerializeField] protected int m_MinShowDataNumber;
|
[SerializeField] protected int m_MinShowDataNumber;
|
||||||
[SerializeField] protected int m_MaxShowDataNumber;
|
[SerializeField] protected int m_MaxShowDataNumber;
|
||||||
@@ -45,278 +44,6 @@ namespace XCharts
|
|||||||
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
|
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
|
||||||
protected Vector2 chartPivot { get { return rectTransform.pivot; } }
|
protected Vector2 chartPivot { get { return rectTransform.pivot; } }
|
||||||
|
|
||||||
public Title title { get { return m_Title; } }
|
|
||||||
public Legend legend { get { return m_Legend; } }
|
|
||||||
public Tooltip tooltip { get { return m_Tooltip; } }
|
|
||||||
public Series series { get { return m_Series; } }
|
|
||||||
|
|
||||||
public float chartWidth { get { return m_ChartWidth; } }
|
|
||||||
public float chartHeight { get { return m_ChartHeight; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The min number of data to show in chart.
|
|
||||||
/// </summary>
|
|
||||||
public int minShowDataNumber
|
|
||||||
{
|
|
||||||
get { return m_MinShowDataNumber; }
|
|
||||||
set { m_MinShowDataNumber = value; if (m_MinShowDataNumber < 0) m_MinShowDataNumber = 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The max number of data to show in chart.
|
|
||||||
/// </summary>
|
|
||||||
public int maxShowDataNumber
|
|
||||||
{
|
|
||||||
get { return m_MaxShowDataNumber; }
|
|
||||||
set { m_MaxShowDataNumber = value; if (m_MaxShowDataNumber < 0) m_MaxShowDataNumber = 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The max number of serie and axis data cache.
|
|
||||||
/// The first data will be remove when the size of serie and axis data is larger then maxCacheDataNumber.
|
|
||||||
/// default:0,unlimited.
|
|
||||||
/// </summary>
|
|
||||||
public int maxCacheDataNumber
|
|
||||||
{
|
|
||||||
get { return m_MaxCacheDataNumber; }
|
|
||||||
set { m_MaxCacheDataNumber = value; if (m_MaxCacheDataNumber < 0) m_MaxCacheDataNumber = 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set the size of chart.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="width">width</param>
|
|
||||||
/// <param name="height">height</param>
|
|
||||||
public virtual void SetSize(float width, float height)
|
|
||||||
{
|
|
||||||
m_ChartWidth = width;
|
|
||||||
m_ChartHeight = height;
|
|
||||||
m_CheckWidth = width;
|
|
||||||
m_CheckHeight = height;
|
|
||||||
rectTransform.sizeDelta = new Vector2(m_ChartWidth, m_ChartHeight);
|
|
||||||
OnSizeChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Remove all series and legend data.
|
|
||||||
/// It just emptying all of serie's data without emptying the list of series.
|
|
||||||
/// </summary>
|
|
||||||
public virtual void ClearData()
|
|
||||||
{
|
|
||||||
m_Series.ClearData();
|
|
||||||
m_Legend.ClearData();
|
|
||||||
RefreshChart();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Remove legend and serie by name.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieName">the name of serie</param>
|
|
||||||
public virtual void RemoveData(string serieName)
|
|
||||||
{
|
|
||||||
m_Series.Remove(serieName);
|
|
||||||
m_Legend.RemoveData(serieName);
|
|
||||||
RefreshChart();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Remove all data from series and legend.
|
|
||||||
/// The series list is also cleared.
|
|
||||||
/// </summary>
|
|
||||||
public virtual void RemoveData()
|
|
||||||
{
|
|
||||||
m_Legend.ClearData();
|
|
||||||
m_Series.RemoveAll();
|
|
||||||
RefreshChart();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add a serie to serie list.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieName">the name of serie</param>
|
|
||||||
/// <param name="type">the type of serie</param>
|
|
||||||
/// <param name="show">whether to show this serie</param>
|
|
||||||
/// <returns>the added serie</returns>
|
|
||||||
public virtual Serie AddSerie(string serieName, SerieType type, bool show = true)
|
|
||||||
{
|
|
||||||
m_Legend.AddData(serieName);
|
|
||||||
return m_Series.AddSerie(serieName, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add a data to serie.
|
|
||||||
/// If serieName doesn't exist in legend,will be add to legend.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieName">the name of serie</param>
|
|
||||||
/// <param name="value">the data to add</param>
|
|
||||||
/// <returns>Returns True on success</returns>
|
|
||||||
public virtual bool AddData(string serieName, float value)
|
|
||||||
{
|
|
||||||
m_Legend.AddData(serieName);
|
|
||||||
var success = m_Series.AddData(serieName, value, m_MaxCacheDataNumber);
|
|
||||||
if (success) RefreshChart();
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add a data to serie.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieIndex">the index of serie</param>
|
|
||||||
/// <param name="value">the data to add</param>
|
|
||||||
/// <returns>Returns True on success</returns>
|
|
||||||
public virtual bool AddData(int serieIndex, float value)
|
|
||||||
{
|
|
||||||
var success = m_Series.AddData(serieIndex, value, m_MaxCacheDataNumber);
|
|
||||||
if (success) RefreshChart();
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add an arbitray dimension data to serie,such as (x,y,z,...).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieName">the name of serie</param>
|
|
||||||
/// <param name="multidimensionalData">the (x,y,z,...) data</param>
|
|
||||||
/// <returns>Returns True on success</returns>
|
|
||||||
public virtual bool AddData(string serieName, List<float> multidimensionalData)
|
|
||||||
{
|
|
||||||
var success = m_Series.AddData(serieName, multidimensionalData, m_MaxCacheDataNumber);
|
|
||||||
if (success) RefreshChart();
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add an arbitray dimension data to serie,such as (x,y,z,...).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieIndex">the index of serie,index starts at 0</param>
|
|
||||||
/// <param name="multidimensionalData">the (x,y,z,...) data</param>
|
|
||||||
/// <returns>Returns True on success</returns>
|
|
||||||
public virtual bool AddData(int serieIndex, List<float> multidimensionalData)
|
|
||||||
{
|
|
||||||
var success = m_Series.AddData(serieIndex, multidimensionalData, m_MaxCacheDataNumber);
|
|
||||||
if (success) RefreshChart();
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add a (x,y) data to serie.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieName">the name of serie</param>
|
|
||||||
/// <param name="xValue">x data</param>
|
|
||||||
/// <param name="yValue">y data</param>
|
|
||||||
/// <returns>Returns True on success</returns>
|
|
||||||
public virtual bool AddData(string serieName, float xValue, float yValue)
|
|
||||||
{
|
|
||||||
var success = m_Series.AddXYData(serieName, xValue, yValue, m_MaxCacheDataNumber);
|
|
||||||
if (success) RefreshChart();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add a (x,y) data to serie.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieIndex">the index of serie</param>
|
|
||||||
/// <param name="xValue">x data</param>
|
|
||||||
/// <param name="yValue">y data</param>
|
|
||||||
/// <returns>Returns True on success</returns>
|
|
||||||
public virtual bool AddData(int serieIndex, float xValue, float yValue)
|
|
||||||
{
|
|
||||||
var success = m_Series.AddXYData(serieIndex, xValue, yValue, m_MaxCacheDataNumber);
|
|
||||||
if (success) RefreshChart();
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Update serie data by serie name.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieName">the name of serie</param>
|
|
||||||
/// <param name="value">the data will be update</param>
|
|
||||||
/// <param name="dataIndex">the index of data</param>
|
|
||||||
public virtual void UpdateData(string serieName, float value, int dataIndex = 0)
|
|
||||||
{
|
|
||||||
m_Series.UpdateData(serieName, value, dataIndex);
|
|
||||||
RefreshChart();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Update serie data by serie index.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieIndex">the index of serie</param>
|
|
||||||
/// <param name="value">the data will be update</param>
|
|
||||||
/// <param name="dataIndex">the index of data</param>
|
|
||||||
public virtual void UpdateData(int serieIndex, float value, int dataIndex = 0)
|
|
||||||
{
|
|
||||||
m_Series.UpdateData(serieIndex, value, dataIndex);
|
|
||||||
RefreshChart();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether to show serie and legend.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieName">the name of serie</param>
|
|
||||||
/// <param name="active">Active or not</param>
|
|
||||||
public virtual void SetActive(string serieName, bool active)
|
|
||||||
{
|
|
||||||
var serie = m_Series.GetSerie(serieName);
|
|
||||||
if (serie != null)
|
|
||||||
{
|
|
||||||
SetActive(serie.index, active);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether to show serie and legend.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieIndex">the index of serie</param>
|
|
||||||
/// <param name="active">Active or not</param>
|
|
||||||
public virtual void SetActive(int serieIndex, bool active)
|
|
||||||
{
|
|
||||||
m_Series.SetActive(serieIndex, active);
|
|
||||||
var serie = m_Series.GetSerie(serieIndex);
|
|
||||||
if (serie != null && !string.IsNullOrEmpty(serie.name))
|
|
||||||
{
|
|
||||||
var bgColor1 = active ? m_ThemeInfo.GetColor(serie.index) : m_ThemeInfo.legendUnableColor;
|
|
||||||
m_Legend.UpdateButtonColor(serie.name, bgColor1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether serie is activated.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieName">the name of serie</param>
|
|
||||||
/// <returns>True when activated</returns>
|
|
||||||
public virtual bool IsActive(string serieName)
|
|
||||||
{
|
|
||||||
return m_Series.IsActive(serieName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether serie is activated.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serieIndex">the index of serie</param>
|
|
||||||
/// <returns>True when activated</returns>
|
|
||||||
public virtual bool IsActive(int serieIndex)
|
|
||||||
{
|
|
||||||
return m_Series.IsActive(serieIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Redraw chart next frame.
|
|
||||||
/// </summary>
|
|
||||||
public void RefreshChart()
|
|
||||||
{
|
|
||||||
m_RefreshChart = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Update chart theme
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="theme">theme</param>
|
|
||||||
public void UpdateTheme(Theme theme)
|
|
||||||
{
|
|
||||||
m_ThemeInfo.theme = theme;
|
|
||||||
OnThemeChanged();
|
|
||||||
RefreshChart();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Awake()
|
protected override void Awake()
|
||||||
{
|
{
|
||||||
if (m_ThemeInfo == null)
|
if (m_ThemeInfo == null)
|
||||||
@@ -338,6 +65,10 @@ namespace XCharts
|
|||||||
TransferOldVersionData();
|
TransferOldVersionData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Start() {
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Update()
|
protected virtual void Update()
|
||||||
{
|
{
|
||||||
CheckSize();
|
CheckSize();
|
||||||
@@ -390,12 +121,22 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
foreach (var serie in m_Series.series)
|
foreach (var serie in m_Series.series)
|
||||||
{
|
{
|
||||||
if (serie.yData.Count > 0 && serie.data.Count == 0)
|
if (serie.yData.Count <= 0) continue;
|
||||||
|
bool needTransfer = true;
|
||||||
|
foreach (var sd in serie.data)
|
||||||
{
|
{
|
||||||
|
foreach (var value in sd.data)
|
||||||
|
{
|
||||||
|
if (value != 0) needTransfer = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (needTransfer)
|
||||||
|
{
|
||||||
|
serie.data.Clear();
|
||||||
for (int i = 0; i < serie.yData.Count; i++)
|
for (int i = 0; i < serie.yData.Count; i++)
|
||||||
{
|
{
|
||||||
float xvalue, yvalue;
|
float xvalue = i < serie.xData.Count ? serie.xData[i] : i;
|
||||||
serie.GetXYData(i, null, out xvalue, out yvalue);
|
float yvalue = serie.yData[i];
|
||||||
var serieData = new SerieData();
|
var serieData = new SerieData();
|
||||||
serieData.data = new List<float>() { xvalue, yvalue };
|
serieData.data = new List<float>() { xvalue, yvalue };
|
||||||
serie.data.Add(serieData);
|
serie.data.Add(serieData);
|
||||||
@@ -472,24 +213,37 @@ namespace XCharts
|
|||||||
for (int i = 0; i < datas.Count; i++)
|
for (int i = 0; i < datas.Count; i++)
|
||||||
{
|
{
|
||||||
string legendName = datas[i];
|
string legendName = datas[i];
|
||||||
Button btn = ChartHelper.AddButtonObject(s_LegendObjectName + "_" + legendName, legendObject.transform,
|
Button btn = ChartHelper.AddButtonObject(s_LegendObjectName + "_" + i + "_" + legendName, legendObject.transform,
|
||||||
m_ThemeInfo.font, m_Legend.itemFontSize, m_ThemeInfo.legendTextColor, anchor,
|
m_ThemeInfo.font, m_Legend.itemFontSize, m_ThemeInfo.legendTextColor, anchor,
|
||||||
anchorMin, anchorMax, pivot, new Vector2(m_Legend.itemWidth, m_Legend.itemHeight));
|
anchorMin, anchorMax, pivot, new Vector2(m_Legend.itemWidth, m_Legend.itemHeight));
|
||||||
var bgColor = IsActive(legendName) ? m_ThemeInfo.GetColor(i) : m_ThemeInfo.legendUnableColor;
|
var bgColor = IsLegendActive(legendName) ? m_ThemeInfo.GetColor(i) : m_ThemeInfo.legendUnableColor;
|
||||||
m_Legend.SetButton(legendName, btn, datas.Count);
|
m_Legend.SetButton(legendName, btn, datas.Count);
|
||||||
m_Legend.UpdateButtonColor(legendName, bgColor);
|
m_Legend.UpdateButtonColor(legendName, bgColor);
|
||||||
btn.GetComponentInChildren<Text>().text = legendName;
|
btn.GetComponentInChildren<Text>().text = legendName;
|
||||||
|
ChartHelper.ClearEventListener(btn.gameObject);
|
||||||
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
|
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
|
||||||
{
|
{
|
||||||
if (data.selectedObject == null) return;
|
if (data.selectedObject == null) return;
|
||||||
string selectedName = data.selectedObject.name.Split('_')[1];
|
var temp = data.selectedObject.name.Split('_');
|
||||||
foreach (var serie in m_Series.GetSeries(selectedName))
|
string selectedName = temp[2];
|
||||||
|
int index = int.Parse(temp[1]);
|
||||||
|
OnLegendButtonClick(index, selectedName);
|
||||||
|
});
|
||||||
|
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerEnter, (data) =>
|
||||||
{
|
{
|
||||||
SetActive(serie.index, !serie.show);
|
if (btn == null) return;
|
||||||
}
|
var temp = btn.name.Split('_');
|
||||||
OnYMaxValueChanged();
|
string selectedName = temp[2];
|
||||||
OnLegendButtonClicked();
|
int index = int.Parse(temp[1]);
|
||||||
RefreshChart();
|
OnLegendButtonEnter(index, selectedName);
|
||||||
|
});
|
||||||
|
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerExit, (data) =>
|
||||||
|
{
|
||||||
|
if (btn == null) return;
|
||||||
|
var temp = btn.name.Split('_');
|
||||||
|
string selectedName = temp[2];
|
||||||
|
int index = int.Parse(temp[1]);
|
||||||
|
OnLegendButtonExit(index, selectedName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -590,22 +344,25 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_Tooltip.dataIndex[0] = m_Tooltip.dataIndex[1] = -1;
|
for (int i = 0; i < m_Tooltip.dataIndex.Count; i++)
|
||||||
|
{
|
||||||
|
m_Tooltip.dataIndex[i] = -1;
|
||||||
|
}
|
||||||
Vector2 local;
|
Vector2 local;
|
||||||
if (canvas == null) return;
|
if (canvas == null) return;
|
||||||
|
|
||||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||||
Input.mousePosition, canvas.worldCamera, out local))
|
Input.mousePosition, canvas.worldCamera, out local))
|
||||||
{
|
{
|
||||||
|
if(m_Tooltip.IsActive()) RefreshChart();
|
||||||
m_Tooltip.SetActive(false);
|
m_Tooltip.SetActive(false);
|
||||||
RefreshChart();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (local.x < 0 || local.x > chartWidth ||
|
if (local.x < 0 || local.x > chartWidth ||
|
||||||
local.y < 0 || local.y > chartHeight)
|
local.y < 0 || local.y > chartHeight)
|
||||||
{
|
{
|
||||||
|
if(m_Tooltip.IsActive()) RefreshChart();
|
||||||
m_Tooltip.SetActive(false);
|
m_Tooltip.SetActive(false);
|
||||||
RefreshChart();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_Tooltip.pointerPos = local;
|
m_Tooltip.pointerPos = local;
|
||||||
@@ -667,8 +424,26 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnLegendButtonClicked()
|
protected virtual void OnLegendButtonClick(int index, string legendName)
|
||||||
{
|
{
|
||||||
|
foreach (var serie in m_Series.GetSeries(legendName))
|
||||||
|
{
|
||||||
|
SetActive(serie.index, !serie.show);
|
||||||
|
}
|
||||||
|
OnYMaxValueChanged();
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnLegendButtonEnter(int index, string legendName)
|
||||||
|
{
|
||||||
|
var serie = m_Series.GetSerie(index);
|
||||||
|
serie.highlighted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnLegendButtonExit(int index, string legendName)
|
||||||
|
{
|
||||||
|
var serie = m_Series.GetSerie(index);
|
||||||
|
serie.highlighted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void RefreshTooltip()
|
protected virtual void RefreshTooltip()
|
||||||
@@ -701,7 +476,8 @@ namespace XCharts
|
|||||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.backgroundColor);
|
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.backgroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, float tickness, Vector3 pos, Color color)
|
protected void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
|
||||||
|
float tickness, Vector3 pos, Color color)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
|||||||
292
Scripts/UI/Internal/BaseChart_API.cs
Normal file
292
Scripts/UI/Internal/BaseChart_API.cs
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace XCharts
|
||||||
|
{
|
||||||
|
public partial class BaseChart
|
||||||
|
{
|
||||||
|
public Title title { get { return m_Title; } }
|
||||||
|
public Legend legend { get { return m_Legend; } }
|
||||||
|
public Tooltip tooltip { get { return m_Tooltip; } }
|
||||||
|
public Series series { get { return m_Series; } }
|
||||||
|
|
||||||
|
public float chartWidth { get { return m_ChartWidth; } }
|
||||||
|
public float chartHeight { get { return m_ChartHeight; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The min number of data to show in chart.
|
||||||
|
/// </summary>
|
||||||
|
public int minShowDataNumber
|
||||||
|
{
|
||||||
|
get { return m_MinShowDataNumber; }
|
||||||
|
set { m_MinShowDataNumber = value; if (m_MinShowDataNumber < 0) m_MinShowDataNumber = 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The max number of data to show in chart.
|
||||||
|
/// </summary>
|
||||||
|
public int maxShowDataNumber
|
||||||
|
{
|
||||||
|
get { return m_MaxShowDataNumber; }
|
||||||
|
set { m_MaxShowDataNumber = value; if (m_MaxShowDataNumber < 0) m_MaxShowDataNumber = 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The max number of serie and axis data cache.
|
||||||
|
/// The first data will be remove when the size of serie and axis data is larger then maxCacheDataNumber.
|
||||||
|
/// default:0,unlimited.
|
||||||
|
/// </summary>
|
||||||
|
public int maxCacheDataNumber
|
||||||
|
{
|
||||||
|
get { return m_MaxCacheDataNumber; }
|
||||||
|
set { m_MaxCacheDataNumber = value; if (m_MaxCacheDataNumber < 0) m_MaxCacheDataNumber = 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the size of chart.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="width">width</param>
|
||||||
|
/// <param name="height">height</param>
|
||||||
|
public virtual void SetSize(float width, float height)
|
||||||
|
{
|
||||||
|
m_ChartWidth = width;
|
||||||
|
m_ChartHeight = height;
|
||||||
|
m_CheckWidth = width;
|
||||||
|
m_CheckHeight = height;
|
||||||
|
rectTransform.sizeDelta = new Vector2(m_ChartWidth, m_ChartHeight);
|
||||||
|
OnSizeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove all series and legend data.
|
||||||
|
/// It just emptying all of serie's data without emptying the list of series.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void ClearData()
|
||||||
|
{
|
||||||
|
m_Series.ClearData();
|
||||||
|
m_Legend.ClearData();
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove legend and serie by name.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieName">the name of serie</param>
|
||||||
|
public virtual void RemoveData(string serieName)
|
||||||
|
{
|
||||||
|
m_Series.Remove(serieName);
|
||||||
|
m_Legend.RemoveData(serieName);
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove all data from series and legend.
|
||||||
|
/// The series list is also cleared.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void RemoveData()
|
||||||
|
{
|
||||||
|
m_Legend.ClearData();
|
||||||
|
m_Series.RemoveAll();
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a serie to serie list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieName">the name of serie</param>
|
||||||
|
/// <param name="type">the type of serie</param>
|
||||||
|
/// <param name="show">whether to show this serie</param>
|
||||||
|
/// <returns>the added serie</returns>
|
||||||
|
public virtual Serie AddSerie(string serieName, SerieType type, bool show = true)
|
||||||
|
{
|
||||||
|
m_Legend.AddData(serieName);
|
||||||
|
return m_Series.AddSerie(serieName, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a data to serie.
|
||||||
|
/// If serieName doesn't exist in legend,will be add to legend.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieName">the name of serie</param>
|
||||||
|
/// <param name="data">the data to add</param>
|
||||||
|
/// <param name="dataName">the name of data</param>
|
||||||
|
/// <returns>Returns True on success</returns>
|
||||||
|
public virtual bool AddData(string serieName, float data, string dataName = null)
|
||||||
|
{
|
||||||
|
m_Legend.AddData(serieName);
|
||||||
|
var success = m_Series.AddData(serieName, data, dataName, m_MaxCacheDataNumber);
|
||||||
|
if (success) RefreshChart();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a data to serie.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieIndex">the index of serie</param>
|
||||||
|
/// <param name="data">the data to add</param>
|
||||||
|
/// <param name="dataName">the name of data</param>
|
||||||
|
/// <returns>Returns True on success</returns>
|
||||||
|
public virtual bool AddData(int serieIndex, float data, string dataName = null)
|
||||||
|
{
|
||||||
|
var success = m_Series.AddData(serieIndex, data, dataName, m_MaxCacheDataNumber);
|
||||||
|
if (success) RefreshChart();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add an arbitray dimension data to serie,such as (x,y,z,...).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieName">the name of serie</param>
|
||||||
|
/// <param name="multidimensionalData">the (x,y,z,...) data</param>
|
||||||
|
/// <param name="dataName">the name of data</param>
|
||||||
|
/// <returns>Returns True on success</returns>
|
||||||
|
public virtual bool AddData(string serieName, List<float> multidimensionalData, string dataName = null)
|
||||||
|
{
|
||||||
|
var success = m_Series.AddData(serieName, multidimensionalData, dataName, m_MaxCacheDataNumber);
|
||||||
|
if (success) RefreshChart();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add an arbitray dimension data to serie,such as (x,y,z,...).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieIndex">the index of serie,index starts at 0</param>
|
||||||
|
/// <param name="multidimensionalData">the (x,y,z,...) data</param>
|
||||||
|
/// <param name="dataName">the name of data</param>
|
||||||
|
/// <returns>Returns True on success</returns>
|
||||||
|
public virtual bool AddData(int serieIndex, List<float> multidimensionalData, string dataName = null)
|
||||||
|
{
|
||||||
|
var success = m_Series.AddData(serieIndex, multidimensionalData, dataName, m_MaxCacheDataNumber);
|
||||||
|
if (success) RefreshChart();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a (x,y) data to serie.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieName">the name of serie</param>
|
||||||
|
/// <param name="xValue">x data</param>
|
||||||
|
/// <param name="yValue">y data</param>
|
||||||
|
/// <param name="dataName">the name of data</param>
|
||||||
|
/// <returns>Returns True on success</returns>
|
||||||
|
public virtual bool AddData(string serieName, float xValue, float yValue, string dataName)
|
||||||
|
{
|
||||||
|
var success = m_Series.AddXYData(serieName, xValue, yValue, dataName, m_MaxCacheDataNumber);
|
||||||
|
if (success) RefreshChart();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a (x,y) data to serie.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieIndex">the index of serie</param>
|
||||||
|
/// <param name="xValue">x data</param>
|
||||||
|
/// <param name="yValue">y data</param>
|
||||||
|
/// <param name="dataName">the name of data</param>
|
||||||
|
/// <returns>Returns True on success</returns>
|
||||||
|
public virtual bool AddData(int serieIndex, float xValue, float yValue, string dataName = null)
|
||||||
|
{
|
||||||
|
var success = m_Series.AddXYData(serieIndex, xValue, yValue, dataName, m_MaxCacheDataNumber);
|
||||||
|
if (success) RefreshChart();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update serie data by serie name.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieName">the name of serie</param>
|
||||||
|
/// <param name="value">the data will be update</param>
|
||||||
|
/// <param name="dataIndex">the index of data</param>
|
||||||
|
public virtual void UpdateData(string serieName, float value, int dataIndex = 0)
|
||||||
|
{
|
||||||
|
m_Series.UpdateData(serieName, value, dataIndex);
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update serie data by serie index.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieIndex">the index of serie</param>
|
||||||
|
/// <param name="value">the data will be update</param>
|
||||||
|
/// <param name="dataIndex">the index of data</param>
|
||||||
|
public virtual void UpdateData(int serieIndex, float value, int dataIndex = 0)
|
||||||
|
{
|
||||||
|
m_Series.UpdateData(serieIndex, value, dataIndex);
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to show serie and legend.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieName">the name of serie</param>
|
||||||
|
/// <param name="active">Active or not</param>
|
||||||
|
public virtual void SetActive(string serieName, bool active)
|
||||||
|
{
|
||||||
|
var serie = m_Series.GetSerie(serieName);
|
||||||
|
if (serie != null)
|
||||||
|
{
|
||||||
|
SetActive(serie.index, active);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to show serie and legend.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieIndex">the index of serie</param>
|
||||||
|
/// <param name="active">Active or not</param>
|
||||||
|
public virtual void SetActive(int serieIndex, bool active)
|
||||||
|
{
|
||||||
|
m_Series.SetActive(serieIndex, active);
|
||||||
|
var serie = m_Series.GetSerie(serieIndex);
|
||||||
|
if (serie != null && !string.IsNullOrEmpty(serie.name))
|
||||||
|
{
|
||||||
|
var bgColor1 = active ? m_ThemeInfo.GetColor(serie.index) : m_ThemeInfo.legendUnableColor;
|
||||||
|
m_Legend.UpdateButtonColor(serie.name, bgColor1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether serie is activated.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieName">the name of serie</param>
|
||||||
|
/// <returns>True when activated</returns>
|
||||||
|
public virtual bool IsActive(string serieName)
|
||||||
|
{
|
||||||
|
return m_Series.IsActive(serieName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether serie is activated.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serieIndex">the index of serie</param>
|
||||||
|
/// <returns>True when activated</returns>
|
||||||
|
public virtual bool IsActive(int serieIndex)
|
||||||
|
{
|
||||||
|
return m_Series.IsActive(serieIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool IsLegendActive(string legendName)
|
||||||
|
{
|
||||||
|
return IsActive(legendName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Redraw chart next frame.
|
||||||
|
/// </summary>
|
||||||
|
public void RefreshChart()
|
||||||
|
{
|
||||||
|
m_RefreshChart = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update chart theme
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="theme">theme</param>
|
||||||
|
public void UpdateTheme(Theme theme)
|
||||||
|
{
|
||||||
|
m_ThemeInfo.theme = theme;
|
||||||
|
OnThemeChanged();
|
||||||
|
RefreshChart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Scripts/UI/Internal/BaseChart_API.cs.meta
Normal file
11
Scripts/UI/Internal/BaseChart_API.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 55240c555461146d28a72b071eb77a4d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -171,18 +171,21 @@ namespace XCharts
|
|||||||
for (int j = 0; j < m_Series.Count; j++)
|
for (int j = 0; j < m_Series.Count; j++)
|
||||||
{
|
{
|
||||||
var serie = m_Series.GetSerie(j);
|
var serie = m_Series.GetSerie(j);
|
||||||
serie.selected = false;
|
for (int n = 0; n < serie.data.Count; n++)
|
||||||
for (int n = 0; n < serie.xData.Count; n++)
|
|
||||||
{
|
{
|
||||||
var xdata = serie.xData[n];
|
var serieData = serie.data[n];
|
||||||
var ydata = serie.yData[n];
|
var xdata = serieData.data[0];
|
||||||
var serieData = serie.GetSerieData(n);
|
var ydata = serieData.data[1];
|
||||||
var symbolSize = serie.symbol.GetSize(serieData == null ? null : serieData.data);
|
var symbolSize = serie.symbol.GetSize(serieData == null ? null : serieData.data);
|
||||||
if (Mathf.Abs(xValue - xdata) / xRate < symbolSize
|
if (Mathf.Abs(xValue - xdata) / xRate < symbolSize
|
||||||
&& Mathf.Abs(yValue - ydata) / yRate < symbolSize)
|
&& Mathf.Abs(yValue - ydata) / yRate < symbolSize)
|
||||||
{
|
{
|
||||||
m_Tooltip.dataIndex[i] = n;
|
m_Tooltip.dataIndex[i] = n;
|
||||||
serie.selected = true;
|
serieData.highlighted = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serieData.highlighted = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,7 +288,8 @@ namespace XCharts
|
|||||||
serie.GetXYData(index, m_DataZoom, out xValue, out yValue);
|
serie.GetXYData(index, m_DataZoom, out xValue, out yValue);
|
||||||
if (isCartesian)
|
if (isCartesian)
|
||||||
{
|
{
|
||||||
if (serie.selected)
|
var serieData = serie.GetSerieData(index, m_DataZoom);
|
||||||
|
if (serieData != null && serieData.highlighted)
|
||||||
{
|
{
|
||||||
sb.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "");
|
sb.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "");
|
||||||
sb.Append("[").Append(ChartCached.FloatToStr(xValue)).Append(",")
|
sb.Append("[").Append(ChartCached.FloatToStr(xValue)).Append(",")
|
||||||
@@ -295,7 +299,7 @@ namespace XCharts
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
sb.Append("\n")
|
sb.Append("\n")
|
||||||
.Append("<color=").Append(m_ThemeInfo.GetColorStr(i)).Append(">● </color>")
|
.Append("<color=#").Append(m_ThemeInfo.GetColorStr(i)).Append(">● </color>")
|
||||||
.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "")
|
.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "")
|
||||||
.Append(ChartCached.FloatToStr(yValue));
|
.Append(ChartCached.FloatToStr(yValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,6 +156,11 @@ namespace XCharts
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int GetIndex(string legendName)
|
||||||
|
{
|
||||||
|
return m_Data.IndexOf(legendName);
|
||||||
|
}
|
||||||
|
|
||||||
public void RemoveButton()
|
public void RemoveButton()
|
||||||
{
|
{
|
||||||
m_DataBtnList.Clear();
|
m_DataBtnList.Clear();
|
||||||
|
|||||||
@@ -5,33 +5,10 @@ namespace XCharts
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class Pie
|
public class Pie
|
||||||
{
|
{
|
||||||
[SerializeField] private string m_Name;
|
|
||||||
[SerializeField] private float m_InsideRadius;
|
|
||||||
[SerializeField] private float m_OutsideRadius;
|
|
||||||
[SerializeField] private float m_TooltipExtraRadius;
|
[SerializeField] private float m_TooltipExtraRadius;
|
||||||
[SerializeField] private bool m_Selected;
|
|
||||||
[SerializeField] private int m_SelectedIndex;
|
|
||||||
[SerializeField] private float m_SelectedOffset;
|
[SerializeField] private float m_SelectedOffset;
|
||||||
[SerializeField] private bool m_Rose;
|
|
||||||
[SerializeField] private float m_Space;
|
|
||||||
[SerializeField] private float m_Left;
|
|
||||||
[SerializeField] private float m_Right;
|
|
||||||
[SerializeField] private float m_Top;
|
|
||||||
[SerializeField] private float m_Bottom;
|
|
||||||
|
|
||||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
|
||||||
public float insideRadius { get { return m_InsideRadius; } set { m_InsideRadius = value; } }
|
|
||||||
public float outsideRadius { get { return m_OutsideRadius; } set { m_OutsideRadius = value; } }
|
|
||||||
public float tooltipExtraRadius { get { return m_TooltipExtraRadius; } set { m_TooltipExtraRadius = value; } }
|
public float tooltipExtraRadius { get { return m_TooltipExtraRadius; } set { m_TooltipExtraRadius = value; } }
|
||||||
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
|
|
||||||
public int selectedIndex { get { return m_SelectedIndex; } set { m_SelectedIndex = value; } }
|
|
||||||
public float selectedOffset { get { return m_SelectedOffset; } set { m_SelectedOffset = value; } }
|
public float selectedOffset { get { return m_SelectedOffset; } set { m_SelectedOffset = value; } }
|
||||||
public bool rose { get { return m_Rose; } set { m_Rose = value; } }
|
|
||||||
public float space { get { return m_Space; } set { m_Space = value; } }
|
|
||||||
public float left { get { return m_Left; } set { m_Left = value; } }
|
|
||||||
public float right { get { return m_Right; } set { m_Right = value; } }
|
|
||||||
public float top { get { return m_Top; } set { m_Top = value; } }
|
|
||||||
public float bottom { get { return m_Bottom; } set { m_Bottom = value; } }
|
|
||||||
|
|
||||||
public static Pie defaultPie
|
public static Pie defaultPie
|
||||||
{
|
{
|
||||||
@@ -39,13 +16,8 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
var pie = new Pie
|
var pie = new Pie
|
||||||
{
|
{
|
||||||
m_Name = "Pie",
|
|
||||||
m_InsideRadius = 0f,
|
|
||||||
m_OutsideRadius = 80f,
|
|
||||||
m_TooltipExtraRadius = 10f,
|
m_TooltipExtraRadius = 10f,
|
||||||
m_Rose = false,
|
m_SelectedOffset = 10f,
|
||||||
m_Selected = false,
|
|
||||||
m_SelectedOffset = 10,
|
|
||||||
};
|
};
|
||||||
return pie;
|
return pie;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,132 +16,29 @@ namespace XCharts
|
|||||||
EffectScatter
|
EffectScatter
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SerieSymbolType
|
public enum RoseType
|
||||||
{
|
{
|
||||||
EmptyCircle,
|
|
||||||
Circle,
|
|
||||||
Rect,
|
|
||||||
Triangle,
|
|
||||||
Diamond,
|
|
||||||
None,
|
None,
|
||||||
|
Radius,
|
||||||
|
Area
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The way to get serie symbol size.
|
|
||||||
/// <para> `Custom`:Specify constant for symbol size. </para>
|
|
||||||
/// <para> `FromData`:Specify the dataIndex and dataScale to calculate symbol size,the formula:data[dataIndex]*dataScale. </para>
|
|
||||||
/// <para> `Callback`:Specify callback function for symbol size. </para>
|
|
||||||
/// </summary>
|
|
||||||
public enum SerieSymbolSizeType
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Specify constant for symbol size.
|
|
||||||
/// </summary>
|
|
||||||
Custom,
|
|
||||||
/// <summary>
|
|
||||||
/// Specify the dataIndex and dataScale to calculate symbol size
|
|
||||||
/// </summary>
|
|
||||||
FromData,
|
|
||||||
/// <summary>
|
|
||||||
/// Specify callback function for symbol size
|
|
||||||
/// </summary>
|
|
||||||
Callback,
|
|
||||||
}
|
|
||||||
|
|
||||||
[System.Serializable]
|
|
||||||
public class SerieData
|
|
||||||
{
|
|
||||||
[SerializeField] private string m_Name;
|
|
||||||
[SerializeField] private List<float> m_Data = new List<float>();
|
|
||||||
|
|
||||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
|
||||||
public List<float> data { get { return m_Data; } set { m_Data = value; } }
|
|
||||||
}
|
|
||||||
|
|
||||||
public delegate float SymbolSizeCallback(List<float> data);
|
|
||||||
|
|
||||||
[System.Serializable]
|
|
||||||
public class SerieSymbol
|
|
||||||
{
|
|
||||||
[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 int m_DataIndex = 1;
|
|
||||||
[SerializeField] private float m_DataScale = 1;
|
|
||||||
[SerializeField] private float m_SelectedDataScale = 1.5f;
|
|
||||||
[SerializeField] private SymbolSizeCallback m_SizeCallback;
|
|
||||||
[SerializeField] private SymbolSizeCallback m_SelectedSizeCallback;
|
|
||||||
|
|
||||||
public SerieSymbolType type { get { return m_Type; } set { m_Type = value; } }
|
|
||||||
public float size { get { return m_Size; } set { m_Size = value; } }
|
|
||||||
public float selectedSize { get { return m_SelectedSize; } set { m_SelectedSize = value; } }
|
|
||||||
public int dataIndex { get { return m_DataIndex; } set { m_DataIndex = value; } }
|
|
||||||
public float dataScale { get { return m_DataScale; } set { m_DataScale = value; } }
|
|
||||||
public float selectedDataScale { get { return m_SelectedDataScale; } set { m_SelectedDataScale = value; } }
|
|
||||||
public SymbolSizeCallback sizeCallback { get { return m_SizeCallback; } set { m_SizeCallback = value; } }
|
|
||||||
public SymbolSizeCallback selectedSizeCallback { get { return m_SelectedSizeCallback; } set { m_SelectedSizeCallback = value; } }
|
|
||||||
|
|
||||||
private List<float> m_AnimationSize = new List<float>() { 0, 5, 10 };
|
|
||||||
public List<float> animationSize { get { return m_AnimationSize; } }
|
|
||||||
public Color animationColor { get; set; }
|
|
||||||
|
|
||||||
public float GetSize(List<float> data)
|
|
||||||
{
|
|
||||||
if (data == null) return size;
|
|
||||||
switch (m_SizeType)
|
|
||||||
{
|
|
||||||
case SerieSymbolSizeType.Custom:
|
|
||||||
return size;
|
|
||||||
case SerieSymbolSizeType.FromData:
|
|
||||||
if (dataIndex >= 0 && dataIndex < data.Count)
|
|
||||||
{
|
|
||||||
return data[dataIndex] * m_DataScale;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
case SerieSymbolSizeType.Callback:
|
|
||||||
if (sizeCallback != null) return sizeCallback(data);
|
|
||||||
else return size;
|
|
||||||
default: return size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public float GetSelectedSize(List<float> data)
|
|
||||||
{
|
|
||||||
if (data == null) return selectedSize;
|
|
||||||
switch (m_SizeType)
|
|
||||||
{
|
|
||||||
case SerieSymbolSizeType.Custom:
|
|
||||||
return selectedSize;
|
|
||||||
case SerieSymbolSizeType.FromData:
|
|
||||||
if (dataIndex >= 0 && dataIndex < data.Count)
|
|
||||||
{
|
|
||||||
return data[dataIndex] * m_SelectedDataScale;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return selectedSize;
|
|
||||||
}
|
|
||||||
case SerieSymbolSizeType.Callback:
|
|
||||||
if (selectedSizeCallback != null) return selectedSizeCallback(data);
|
|
||||||
else return selectedSize;
|
|
||||||
default: return selectedSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class Serie : JsonDataSupport
|
public class Serie : JsonDataSupport
|
||||||
{
|
{
|
||||||
[SerializeField] [DefaultValue("true")] private bool m_Show = true;
|
[SerializeField] [DefaultValue("true")] private bool m_Show = true;
|
||||||
[SerializeField] private SerieType m_Type;
|
[SerializeField] private SerieType m_Type;
|
||||||
[SerializeField] private bool m_Selected;
|
|
||||||
[SerializeField] private string m_Name;
|
[SerializeField] private string m_Name;
|
||||||
[SerializeField] private string m_Stack;
|
[SerializeField] private string m_Stack;
|
||||||
[SerializeField] [Range(0, 1)] private int m_AxisIndex;
|
[SerializeField] [Range(0, 1)] private int m_AxisIndex;
|
||||||
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
|
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
|
||||||
|
#region PieChart
|
||||||
|
[SerializeField] private bool m_ClickOffset = true;
|
||||||
|
[SerializeField] private RoseType m_RoseType = RoseType.None;
|
||||||
|
[SerializeField] private float m_Space;
|
||||||
|
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
|
||||||
|
[SerializeField] private float[] m_Radius = new float[2] { 0, 80 };
|
||||||
|
#endregion
|
||||||
|
|
||||||
[SerializeField] [Range(1, 6)] private int m_ShowDataDimension;
|
[SerializeField] [Range(1, 6)] private int m_ShowDataDimension;
|
||||||
[SerializeField] private bool m_ShowDataName;
|
[SerializeField] private bool m_ShowDataName;
|
||||||
@@ -150,15 +47,26 @@ namespace XCharts
|
|||||||
[SerializeField] private List<float> m_XData = new List<float>();
|
[SerializeField] private List<float> m_XData = new List<float>();
|
||||||
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
|
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
|
||||||
|
|
||||||
public int index { get; set; }
|
|
||||||
public int dataCount { get { return m_Data.Count; } }
|
|
||||||
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
|
|
||||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||||
public SerieType type { get { return m_Type; } set { m_Type = value; } }
|
public SerieType type { get { return m_Type; } set { m_Type = value; } }
|
||||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||||
public string stack { get { return m_Stack; } set { m_Stack = value; } }
|
public string stack { get { return m_Stack; } set { m_Stack = value; } }
|
||||||
public int axisIndex { get { return m_AxisIndex; } set { m_AxisIndex = value; } }
|
public int axisIndex { get { return m_AxisIndex; } set { m_AxisIndex = value; } }
|
||||||
public SerieSymbol symbol { get { return m_Symbol; } set { m_Symbol = value; } }
|
public SerieSymbol symbol { get { return m_Symbol; } set { m_Symbol = value; } }
|
||||||
|
public bool clickOffset { get { return m_ClickOffset; } set { m_ClickOffset = value; } }
|
||||||
|
public RoseType roseType { get { return m_RoseType; } set { m_RoseType = value; } }
|
||||||
|
public float space { get { return m_Space; } set { m_Space = value; } }
|
||||||
|
public float[] center { get { return m_Center; } set { m_Center = value; } }
|
||||||
|
public float[] radius { get { return m_Radius; } set { m_Radius = value; } }
|
||||||
|
|
||||||
|
public int index { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the serie is highlighted.
|
||||||
|
/// 该系列是否高亮,一般由图例悬停触发。
|
||||||
|
/// </summary>
|
||||||
|
public bool highlighted { get; set; }
|
||||||
|
public int dataCount { get { return m_Data.Count; } }
|
||||||
|
|
||||||
public List<float> yData { get { return m_YData; } }
|
public List<float> yData { get { return m_YData; } }
|
||||||
public List<float> xData { get { return m_XData; } }
|
public List<float> xData { get { return m_XData; } }
|
||||||
public List<SerieData> data { get { return m_Data; } }
|
public List<SerieData> data { get { return m_Data; } }
|
||||||
@@ -175,11 +83,11 @@ namespace XCharts
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
float max = int.MinValue;
|
float max = int.MinValue;
|
||||||
foreach (var data in yData)
|
foreach (var sdata in data)
|
||||||
{
|
{
|
||||||
if (data > max)
|
if (sdata.show && sdata.data[1] > max)
|
||||||
{
|
{
|
||||||
max = data;
|
max = sdata.data[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return max;
|
return max;
|
||||||
@@ -191,11 +99,11 @@ namespace XCharts
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
float max = int.MinValue;
|
float max = int.MinValue;
|
||||||
foreach (var data in xData)
|
foreach (var sdata in data)
|
||||||
{
|
{
|
||||||
if (data > max)
|
if (sdata.show && sdata.data[0] > max)
|
||||||
{
|
{
|
||||||
max = data;
|
max = sdata.data[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return max;
|
return max;
|
||||||
@@ -207,11 +115,11 @@ namespace XCharts
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
float min = int.MaxValue;
|
float min = int.MaxValue;
|
||||||
foreach (var data in yData)
|
foreach (var sdata in data)
|
||||||
{
|
{
|
||||||
if (data < min)
|
if (sdata.show && sdata.data[1] < min)
|
||||||
{
|
{
|
||||||
min = data;
|
min = sdata.data[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return min;
|
return min;
|
||||||
@@ -223,11 +131,11 @@ namespace XCharts
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
float min = int.MaxValue;
|
float min = int.MaxValue;
|
||||||
foreach (var data in xData)
|
foreach (var sdata in data)
|
||||||
{
|
{
|
||||||
if (data < min)
|
if (sdata.show && sdata.data[0] < min)
|
||||||
{
|
{
|
||||||
min = data;
|
min = sdata.data[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return min;
|
return min;
|
||||||
@@ -239,9 +147,10 @@ namespace XCharts
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
float total = 0;
|
float total = 0;
|
||||||
foreach (var data in yData)
|
foreach (var sdata in data)
|
||||||
{
|
{
|
||||||
total += data;
|
if (sdata.show)
|
||||||
|
total += sdata.data[1];
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
@@ -252,9 +161,10 @@ namespace XCharts
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
float total = 0;
|
float total = 0;
|
||||||
foreach (var data in xData)
|
foreach (var sdata in data)
|
||||||
{
|
{
|
||||||
total += data;
|
if (sdata.show)
|
||||||
|
total += sdata.data[0];
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
@@ -274,7 +184,7 @@ namespace XCharts
|
|||||||
m_Data.RemoveAt(index);
|
m_Data.RemoveAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddYData(float value, int maxDataNumber = 0, string dataName = null)
|
public void AddYData(float value, string dataName = null, int maxDataNumber = 0)
|
||||||
{
|
{
|
||||||
if (maxDataNumber > 0)
|
if (maxDataNumber > 0)
|
||||||
{
|
{
|
||||||
@@ -288,7 +198,7 @@ namespace XCharts
|
|||||||
m_Data.Add(new SerieData() { data = new List<float>() { xValue, value }, name = dataName });
|
m_Data.Add(new SerieData() { data = new List<float>() { xValue, value }, name = dataName });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddXYData(float xValue, float yValue, int maxDataNumber = 0, string dataName = null)
|
public void AddXYData(float xValue, float yValue, string dataName = null, int maxDataNumber = 0)
|
||||||
{
|
{
|
||||||
if (maxDataNumber > 0)
|
if (maxDataNumber > 0)
|
||||||
{
|
{
|
||||||
@@ -301,16 +211,16 @@ namespace XCharts
|
|||||||
m_Data.Add(new SerieData() { data = new List<float>() { xValue, yValue }, name = dataName });
|
m_Data.Add(new SerieData() { data = new List<float>() { xValue, yValue }, name = dataName });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddData(List<float> valueList, int maxDataNumber = 0, string dataName = null)
|
public void AddData(List<float> valueList, string dataName = null, int maxDataNumber = 0)
|
||||||
{
|
{
|
||||||
if (valueList == null || valueList.Count == 0) return;
|
if (valueList == null || valueList.Count == 0) return;
|
||||||
if (valueList.Count == 1)
|
if (valueList.Count == 1)
|
||||||
{
|
{
|
||||||
AddYData(valueList[0], maxDataNumber, dataName);
|
AddYData(valueList[0], dataName, maxDataNumber);
|
||||||
}
|
}
|
||||||
else if (valueList.Count == 2)
|
else if (valueList.Count == 2)
|
||||||
{
|
{
|
||||||
AddXYData(valueList[0], valueList[1], maxDataNumber, dataName);
|
AddXYData(valueList[0], valueList[1], dataName, maxDataNumber);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -335,22 +245,27 @@ namespace XCharts
|
|||||||
public float GetYData(int index, DataZoom dataZoom = null)
|
public float GetYData(int index, DataZoom dataZoom = null)
|
||||||
{
|
{
|
||||||
if (index < 0) return 0;
|
if (index < 0) return 0;
|
||||||
var showData = GetYDataList(dataZoom);
|
|
||||||
if (index < showData.Count)
|
|
||||||
{
|
|
||||||
return showData[index];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var serieData = GetDataList(dataZoom);
|
var serieData = GetDataList(dataZoom);
|
||||||
if (index < serieData.Count)
|
if (index < serieData.Count)
|
||||||
{
|
{
|
||||||
return serieData[index].data[1];
|
return serieData[index].data[1];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void GetYData(int index, out float yData, out string dataName, DataZoom dataZoom = null)
|
||||||
|
{
|
||||||
|
yData = 0;
|
||||||
|
dataName = null;
|
||||||
|
if (index < 0) return;
|
||||||
|
var serieData = GetDataList(dataZoom);
|
||||||
|
if (index < serieData.Count)
|
||||||
|
{
|
||||||
|
yData = serieData[index].data[1];
|
||||||
|
dataName = serieData[index].name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public SerieData GetSerieData(int index, DataZoom dataZoom = null)
|
public SerieData GetSerieData(int index, DataZoom dataZoom = null)
|
||||||
{
|
{
|
||||||
var data = GetDataList(dataZoom);
|
var data = GetDataList(dataZoom);
|
||||||
@@ -366,15 +281,6 @@ namespace XCharts
|
|||||||
xValue = 0;
|
xValue = 0;
|
||||||
yVlaue = 0;
|
yVlaue = 0;
|
||||||
if (index < 0) return;
|
if (index < 0) return;
|
||||||
var xShowData = GetXDataList(dataZoom);
|
|
||||||
var yShowData = GetYDataList(dataZoom);
|
|
||||||
if (index < xShowData.Count && index < yShowData.Count)
|
|
||||||
{
|
|
||||||
xValue = xShowData[index];
|
|
||||||
yVlaue = yShowData[index];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var showData = GetDataList(dataZoom);
|
var showData = GetDataList(dataZoom);
|
||||||
if (index < showData.Count)
|
if (index < showData.Count)
|
||||||
{
|
{
|
||||||
@@ -383,7 +289,6 @@ namespace XCharts
|
|||||||
yVlaue = serieData.data[1];
|
yVlaue = serieData.data[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public List<float> GetYDataList(DataZoom dataZoom)
|
public List<float> GetYDataList(DataZoom dataZoom)
|
||||||
{
|
{
|
||||||
@@ -442,8 +347,6 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void UpdateFilterData(DataZoom dataZoom)
|
public void UpdateFilterData(DataZoom dataZoom)
|
||||||
{
|
{
|
||||||
if (dataZoom != null && dataZoom.show)
|
if (dataZoom != null && dataZoom.show)
|
||||||
@@ -517,6 +420,24 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClearHighlight()
|
||||||
|
{
|
||||||
|
highlighted = false;
|
||||||
|
foreach (var sd in m_Data)
|
||||||
|
{
|
||||||
|
sd.highlighted = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetHighlight(int index)
|
||||||
|
{
|
||||||
|
if (index <= 0) return;
|
||||||
|
for (int i = 0; i < m_Data.Count; i++)
|
||||||
|
{
|
||||||
|
m_Data[i].highlighted = index == i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void ParseJsonData(string jsonData)
|
public override void ParseJsonData(string jsonData)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
||||||
@@ -555,6 +476,34 @@ namespace XCharts
|
|||||||
m_Data.Add(serieData);
|
m_Data.Add(serieData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (temp.IndexOf("value") > -1 && temp.IndexOf("name") > -1)
|
||||||
|
{
|
||||||
|
string[] datas = temp.Split(new string[] { "},", "} ,", "}" }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
for (int i = 0; i < datas.Length; i++)
|
||||||
|
{
|
||||||
|
var arr = datas[i].Replace("{", "").Split(',');
|
||||||
|
var serieData = new SerieData();
|
||||||
|
foreach (var a in arr)
|
||||||
|
{
|
||||||
|
if (a.StartsWith("value:"))
|
||||||
|
{
|
||||||
|
float value = float.Parse(a.Substring(6, a.Length - 6));
|
||||||
|
serieData.data = new List<float>() { i, value };
|
||||||
|
}
|
||||||
|
else if (a.StartsWith("name:"))
|
||||||
|
{
|
||||||
|
string name = a.Substring(6, a.Length - 6 - 1);
|
||||||
|
serieData.name = name;
|
||||||
|
}
|
||||||
|
else if (a.StartsWith("selected:"))
|
||||||
|
{
|
||||||
|
string selected = a.Substring(9, a.Length - 9);
|
||||||
|
serieData.selected = bool.Parse(selected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_Data.Add(serieData);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string[] datas = temp.Split(',');
|
string[] datas = temp.Split(',');
|
||||||
@@ -565,10 +514,8 @@ namespace XCharts
|
|||||||
if (flag)
|
if (flag)
|
||||||
{
|
{
|
||||||
var serieData = new SerieData();
|
var serieData = new SerieData();
|
||||||
|
serieData.data = new List<float>() { i, value };
|
||||||
serieData.data.Add(value);
|
|
||||||
m_Data.Add(serieData);
|
m_Data.Add(serieData);
|
||||||
m_XData.Add(value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
40
Scripts/UI/Internal/SerieData.cs
Normal file
40
Scripts/UI/Internal/SerieData.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XCharts
|
||||||
|
{
|
||||||
|
[System.Serializable]
|
||||||
|
/// <summary>
|
||||||
|
/// A data item of serie.系列中的一个数据项。
|
||||||
|
/// </summary>
|
||||||
|
public class SerieData
|
||||||
|
{
|
||||||
|
[SerializeField] private string m_Name;
|
||||||
|
[SerializeField] private bool m_Selected;
|
||||||
|
[SerializeField] private List<float> m_Data = new List<float>();
|
||||||
|
|
||||||
|
private bool m_Show = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the name of data item.数据项名称。
|
||||||
|
/// </summary>
|
||||||
|
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the data item is selected.该数据项是否被选中。
|
||||||
|
/// </summary>
|
||||||
|
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// An arbitrary dimension data list of data item.可指定任意维数的数值列表。
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
|
public List<float> data { get { return m_Data; } set { m_Data = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the data item is showed.该数据项是否要显示。
|
||||||
|
/// </summary>
|
||||||
|
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the data item is highlighted.该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
|
||||||
|
/// </summary>
|
||||||
|
public bool highlighted { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Scripts/UI/Internal/SerieData.cs.meta
Normal file
11
Scripts/UI/Internal/SerieData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d61959eca953d46639084862f812b408
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
112
Scripts/UI/Internal/SerieSymbol.cs
Normal file
112
Scripts/UI/Internal/SerieSymbol.cs
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XCharts
|
||||||
|
{
|
||||||
|
public enum SerieSymbolType
|
||||||
|
{
|
||||||
|
EmptyCircle,
|
||||||
|
Circle,
|
||||||
|
Rect,
|
||||||
|
Triangle,
|
||||||
|
Diamond,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The way to get serie symbol size.
|
||||||
|
/// <para> `Custom`:Specify constant for symbol size. </para>
|
||||||
|
/// <para> `FromData`:Specify the dataIndex and dataScale to calculate symbol size,the formula:data[dataIndex]*dataScale. </para>
|
||||||
|
/// <para> `Callback`:Specify callback function for symbol size. </para>
|
||||||
|
/// </summary>
|
||||||
|
public enum SerieSymbolSizeType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Specify constant for symbol size.
|
||||||
|
/// </summary>
|
||||||
|
Custom,
|
||||||
|
/// <summary>
|
||||||
|
/// Specify the dataIndex and dataScale to calculate symbol size
|
||||||
|
/// </summary>
|
||||||
|
FromData,
|
||||||
|
/// <summary>
|
||||||
|
/// Specify callback function for symbol size
|
||||||
|
/// </summary>
|
||||||
|
Callback,
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate float SymbolSizeCallback(List<float> data);
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class SerieSymbol
|
||||||
|
{
|
||||||
|
[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 int m_DataIndex = 1;
|
||||||
|
[SerializeField] private float m_DataScale = 1;
|
||||||
|
[SerializeField] private float m_SelectedDataScale = 1.5f;
|
||||||
|
[SerializeField] private SymbolSizeCallback m_SizeCallback;
|
||||||
|
[SerializeField] private SymbolSizeCallback m_SelectedSizeCallback;
|
||||||
|
|
||||||
|
public SerieSymbolType type { get { return m_Type; } set { m_Type = value; } }
|
||||||
|
public float size { get { return m_Size; } set { m_Size = value; } }
|
||||||
|
public float selectedSize { get { return m_SelectedSize; } set { m_SelectedSize = value; } }
|
||||||
|
public int dataIndex { get { return m_DataIndex; } set { m_DataIndex = value; } }
|
||||||
|
public float dataScale { get { return m_DataScale; } set { m_DataScale = value; } }
|
||||||
|
public float selectedDataScale { get { return m_SelectedDataScale; } set { m_SelectedDataScale = value; } }
|
||||||
|
public SymbolSizeCallback sizeCallback { get { return m_SizeCallback; } set { m_SizeCallback = value; } }
|
||||||
|
public SymbolSizeCallback selectedSizeCallback { get { return m_SelectedSizeCallback; } set { m_SelectedSizeCallback = value; } }
|
||||||
|
|
||||||
|
private List<float> m_AnimationSize = new List<float>() { 0, 5, 10 };
|
||||||
|
public List<float> animationSize { get { return m_AnimationSize; } }
|
||||||
|
public Color animationColor { get; set; }
|
||||||
|
|
||||||
|
public float GetSize(List<float> data)
|
||||||
|
{
|
||||||
|
if (data == null) return size;
|
||||||
|
switch (m_SizeType)
|
||||||
|
{
|
||||||
|
case SerieSymbolSizeType.Custom:
|
||||||
|
return size;
|
||||||
|
case SerieSymbolSizeType.FromData:
|
||||||
|
if (dataIndex >= 0 && dataIndex < data.Count)
|
||||||
|
{
|
||||||
|
return data[dataIndex] * m_DataScale;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
case SerieSymbolSizeType.Callback:
|
||||||
|
if (sizeCallback != null) return sizeCallback(data);
|
||||||
|
else return size;
|
||||||
|
default: return size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetSelectedSize(List<float> data)
|
||||||
|
{
|
||||||
|
if (data == null) return selectedSize;
|
||||||
|
switch (m_SizeType)
|
||||||
|
{
|
||||||
|
case SerieSymbolSizeType.Custom:
|
||||||
|
return selectedSize;
|
||||||
|
case SerieSymbolSizeType.FromData:
|
||||||
|
if (dataIndex >= 0 && dataIndex < data.Count)
|
||||||
|
{
|
||||||
|
return data[dataIndex] * m_SelectedDataScale;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return selectedSize;
|
||||||
|
}
|
||||||
|
case SerieSymbolSizeType.Callback:
|
||||||
|
if (selectedSizeCallback != null) return selectedSizeCallback(data);
|
||||||
|
else return selectedSize;
|
||||||
|
default: return selectedSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Scripts/UI/Internal/SerieSymbol.cs.meta
Normal file
11
Scripts/UI/Internal/SerieSymbol.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 09616736d585e45b1940795215733660
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -150,67 +150,67 @@ namespace XCharts
|
|||||||
return serie;
|
return serie;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddData(string serieName, float value, int maxDataNumber = 0)
|
public bool AddData(string serieName, float value, string dataName = null, int maxDataNumber = 0)
|
||||||
{
|
{
|
||||||
var serie = GetSerie(serieName);
|
var serie = GetSerie(serieName);
|
||||||
if (serie != null)
|
if (serie != null)
|
||||||
{
|
{
|
||||||
serie.AddYData(value, maxDataNumber);
|
serie.AddYData(value, dataName, maxDataNumber);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddData(int index, float value, int maxDataNumber = 0)
|
public bool AddData(int index, float value, string dataName = null, int maxDataNumber = 0)
|
||||||
{
|
{
|
||||||
var serie = GetSerie(index);
|
var serie = GetSerie(index);
|
||||||
if (serie != null)
|
if (serie != null)
|
||||||
{
|
{
|
||||||
serie.AddYData(value, maxDataNumber);
|
serie.AddYData(value, dataName, maxDataNumber);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddData(string serieName, List<float> multidimensionalData, int maxDataNumber = 0)
|
public bool AddData(string serieName, List<float> multidimensionalData, string dataName = null, int maxDataNumber = 0)
|
||||||
{
|
{
|
||||||
var serie = GetSerie(serieName);
|
var serie = GetSerie(serieName);
|
||||||
if (serie != null)
|
if (serie != null)
|
||||||
{
|
{
|
||||||
serie.AddData(multidimensionalData, maxDataNumber);
|
serie.AddData(multidimensionalData, dataName, maxDataNumber);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddData(int serieIndex, List<float> multidimensionalData, int maxDataNumber = 0)
|
public bool AddData(int serieIndex, List<float> multidimensionalData, string dataName = null, int maxDataNumber = 0)
|
||||||
{
|
{
|
||||||
var serie = GetSerie(serieIndex);
|
var serie = GetSerie(serieIndex);
|
||||||
if (serie != null)
|
if (serie != null)
|
||||||
{
|
{
|
||||||
serie.AddData(multidimensionalData, maxDataNumber);
|
serie.AddData(multidimensionalData, dataName, maxDataNumber);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddXYData(string serieName, float xValue, float yValue, int maxDataNumber = 0)
|
public bool AddXYData(string serieName, float xValue, float yValue, string dataName = null, int maxDataNumber = 0)
|
||||||
{
|
{
|
||||||
var serie = GetSerie(serieName);
|
var serie = GetSerie(serieName);
|
||||||
if (serie != null)
|
if (serie != null)
|
||||||
{
|
{
|
||||||
serie.AddXYData(xValue, yValue, maxDataNumber);
|
serie.AddXYData(xValue, yValue, dataName, maxDataNumber);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddXYData(int index, float xValue, float yValue, int maxDataNumber = 0)
|
public bool AddXYData(int index, float xValue, float yValue, string dataName = null, int maxDataNumber = 0)
|
||||||
{
|
{
|
||||||
var serie = GetSerie(index);
|
var serie = GetSerie(index);
|
||||||
if (serie != null)
|
if (serie != null)
|
||||||
{
|
{
|
||||||
serie.AddXYData(xValue, yValue, maxDataNumber);
|
serie.AddXYData(xValue, yValue, dataName, maxDataNumber);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -305,7 +305,7 @@ namespace XCharts
|
|||||||
public bool IsTooltipSelected(int serieIndex)
|
public bool IsTooltipSelected(int serieIndex)
|
||||||
{
|
{
|
||||||
var serie = GetSerie(serieIndex);
|
var serie = GetSerie(serieIndex);
|
||||||
if (serie != null) return serie.selected;
|
if (serie != null) return serie.highlighted;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,17 +520,31 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<string> serieNameList = new List<string>();
|
||||||
public List<string> GetSerieNameList()
|
public List<string> GetSerieNameList()
|
||||||
{
|
{
|
||||||
var list = new List<string>();
|
serieNameList.Clear();
|
||||||
foreach (var serie in m_Series)
|
foreach (var serie in m_Series)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(serie.name) && !list.Contains(serie.name))
|
if (serie.type == SerieType.Pie)
|
||||||
{
|
{
|
||||||
list.Add(serie.name);
|
foreach (var data in serie.data)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(data.name) && !serieNameList.Contains(data.name))
|
||||||
|
{
|
||||||
|
serieNameList.Add(data.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(serie.name) && !serieNameList.Contains(serie.name))
|
||||||
|
{
|
||||||
|
serieNameList.Add(serie.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return serieNameList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetSerieSymbolSizeCallback(SymbolSizeCallback size, SymbolSizeCallback selectedSize)
|
public void SetSerieSymbolSizeCallback(SymbolSizeCallback size, SymbolSizeCallback selectedSize)
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ namespace XCharts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The data index currently indicated by Tooltip.
|
/// The data index currently indicated by Tooltip.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int[] dataIndex { get; set; }
|
public List<int> dataIndex { get; set; }
|
||||||
public int[] lastDataIndex { get; set; }
|
public List<int> lastDataIndex { get; set; }
|
||||||
public float[] xValues { get; set; }
|
public float[] xValues { get; set; }
|
||||||
public float[] yValues { get; set; }
|
public float[] yValues { get; set; }
|
||||||
|
|
||||||
@@ -85,8 +85,8 @@ namespace XCharts
|
|||||||
m_Show = true,
|
m_Show = true,
|
||||||
xValues = new float[2],
|
xValues = new float[2],
|
||||||
yValues = new float[2],
|
yValues = new float[2],
|
||||||
dataIndex = new int[2],
|
dataIndex = new List<int>() { -1, -1 },
|
||||||
lastDataIndex = new int[2]
|
lastDataIndex = new List<int>() { -1, -1 }
|
||||||
};
|
};
|
||||||
return tooltip;
|
return tooltip;
|
||||||
}
|
}
|
||||||
@@ -141,6 +141,11 @@ namespace XCharts
|
|||||||
yValues[0] = yValues[1] = -1;
|
yValues[0] = yValues[1] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsActive()
|
||||||
|
{
|
||||||
|
return m_GameObject != null && m_GameObject.activeInHierarchy;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetActive(bool flag)
|
public void SetActive(bool flag)
|
||||||
{
|
{
|
||||||
lastDataIndex[0] = lastDataIndex[1] = -1;
|
lastDataIndex[0] = lastDataIndex[1] = -1;
|
||||||
|
|||||||
@@ -102,7 +102,9 @@ namespace XCharts
|
|||||||
var dataIndex = i % dataCount;
|
var dataIndex = i % dataCount;
|
||||||
var serie = m_Series.GetSerie(pointSerieIndex[i]);
|
var serie = m_Series.GetSerie(pointSerieIndex[i]);
|
||||||
float symbolSize = serie.symbol.size;
|
float symbolSize = serie.symbol.size;
|
||||||
if (m_Tooltip.show && m_Tooltip.IsSelectedDataIndex(dataIndex))
|
if ((m_Tooltip.show && m_Tooltip.IsSelectedDataIndex(dataIndex))
|
||||||
|
|| serie.data[dataIndex].highlighted
|
||||||
|
|| serie.highlighted)
|
||||||
{
|
{
|
||||||
if (IsCartesian())
|
if (IsCartesian())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Text;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
@@ -11,61 +12,52 @@ namespace XCharts
|
|||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class PieChart : BaseChart
|
public class PieChart : BaseChart
|
||||||
{
|
{
|
||||||
|
private class PieTempData
|
||||||
|
{
|
||||||
|
public List<float> angleList = new List<float>();
|
||||||
|
public Vector2 center;
|
||||||
|
public float insideRadius;
|
||||||
|
public float outsideRadius;
|
||||||
|
public float dataMax;
|
||||||
|
public float dataTotal;
|
||||||
|
}
|
||||||
|
|
||||||
[SerializeField] private Pie m_Pie = Pie.defaultPie;
|
[SerializeField] private Pie m_Pie = Pie.defaultPie;
|
||||||
|
|
||||||
private float m_PieCenterX = 0f;
|
private bool isDrawPie;
|
||||||
private float m_PieCenterY = 0f;
|
private bool m_IsEnterLegendButtom;
|
||||||
private float m_PieRadius = 0;
|
private List<PieTempData> m_PieTempDataList = new List<PieTempData>();
|
||||||
private Vector2 m_PieCenter;
|
|
||||||
private List<float> m_AngleList = new List<float>();
|
|
||||||
|
|
||||||
public Pie pie { get { return m_Pie; } }
|
public Pie pie { get { return m_Pie; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a data to pie.
|
/// Where legend is activated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="serieName">the name of data</param>
|
/// <param name="legendName">the name of legend</param>
|
||||||
/// <param name="value">the data</param>
|
/// <returns></returns>
|
||||||
/// <returns>Return true forever</returns>
|
public override bool IsLegendActive(string legendName)
|
||||||
public override bool AddData(string serieName, float value)
|
{
|
||||||
|
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))
|
||||||
{
|
{
|
||||||
m_Legend.AddData(serieName);
|
|
||||||
var serie = m_Series.AddSerie(serieName, SerieType.Pie);
|
|
||||||
serie.ClearData();
|
|
||||||
serie.AddYData(value);
|
|
||||||
RefreshChart();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Update the data for the specified name.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="legend">the name of data</param>
|
|
||||||
/// <param name="value">the data</param>
|
|
||||||
/// <param name="dataIndex">is not used in this function</param>
|
|
||||||
public override void UpdateData(string legend, float value, int dataIndex = 0)
|
|
||||||
{
|
|
||||||
var serie = m_Series.GetSerie(legend);
|
|
||||||
if (serie != null)
|
|
||||||
{
|
|
||||||
serie.UpdateYData(0, value);
|
|
||||||
RefreshChart();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Awake()
|
protected override void Awake()
|
||||||
{
|
{
|
||||||
raycastTarget = m_Pie.selected;
|
base.Awake();
|
||||||
}
|
raycastTarget = false;
|
||||||
|
|
||||||
protected override void Update()
|
|
||||||
{
|
|
||||||
base.Update();
|
|
||||||
if (raycastTarget != m_Pie.selected)
|
|
||||||
{
|
|
||||||
raycastTarget = m_Pie.selected;
|
|
||||||
RefreshChart();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
@@ -75,166 +67,250 @@ namespace XCharts
|
|||||||
m_Pie = Pie.defaultPie;
|
m_Pie = Pie.defaultPie;
|
||||||
m_Title.text = "PieChart";
|
m_Title.text = "PieChart";
|
||||||
RemoveData();
|
RemoveData();
|
||||||
AddData("serie1", 80);
|
AddSerie("serie1", SerieType.Pie);
|
||||||
AddData("serie2", 20);
|
AddData(0, 70, "pie1");
|
||||||
|
AddData(0, 20, "pie2");
|
||||||
|
AddData(0, 10, "pie3");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HashSet<string> serieNameSet = new HashSet<string>();
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
if (!isDrawPie) RefreshChart();
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<string, int> serieNameSet = new Dictionary<string, int>();
|
||||||
protected override void DrawChart(VertexHelper vh)
|
protected override void DrawChart(VertexHelper vh)
|
||||||
{
|
{
|
||||||
base.DrawChart(vh);
|
base.DrawChart(vh);
|
||||||
UpdatePieCenter();
|
|
||||||
float totalDegree = 360;
|
|
||||||
float startDegree = 0;
|
|
||||||
float dataTotal = GetDataTotal();
|
|
||||||
float dataMax = GetDataMax();
|
|
||||||
m_AngleList.Clear();
|
|
||||||
serieNameSet.Clear();
|
serieNameSet.Clear();
|
||||||
int serieNameCount = -1;
|
int serieNameCount = -1;
|
||||||
|
bool isClickOffset = false;
|
||||||
|
bool isDataHighlight = false;
|
||||||
for (int i = 0; i < m_Series.Count; i++)
|
for (int i = 0; i < m_Series.Count; i++)
|
||||||
{
|
{
|
||||||
var serie = m_Series.series[i];
|
var serie = m_Series.series[i];
|
||||||
serie.index = i;
|
serie.index = i;
|
||||||
var data = serie.yData;
|
|
||||||
if (string.IsNullOrEmpty(serie.name)) serieNameCount++;
|
if (!serie.show)
|
||||||
else if (!serieNameSet.Contains(serie.name))
|
|
||||||
{
|
{
|
||||||
serieNameSet.Add(serie.name);
|
|
||||||
serieNameCount++;
|
|
||||||
}
|
|
||||||
if (data.Count <= 0 || !serie.show)
|
|
||||||
{
|
|
||||||
m_AngleList.Add(i > 0 ? m_AngleList[i - 1] : 0);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
float value = data[0];
|
if (serie.clickOffset) isClickOffset = true;
|
||||||
float degree = totalDegree * value / dataTotal;
|
PieTempData tempData;
|
||||||
|
if (i < m_PieTempDataList.Count)
|
||||||
|
{
|
||||||
|
tempData = m_PieTempDataList[i];
|
||||||
|
tempData.angleList.Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tempData = new PieTempData();
|
||||||
|
m_PieTempDataList.Add(tempData);
|
||||||
|
}
|
||||||
|
tempData.angleList.Clear();
|
||||||
|
tempData.dataMax = serie.yMax;
|
||||||
|
tempData.dataTotal = serie.yTotal;
|
||||||
|
UpdatePieCenter(serie);
|
||||||
|
var data = serie.data;
|
||||||
|
|
||||||
|
float totalDegree = 360;
|
||||||
|
float startDegree = 0;
|
||||||
|
for (int n = 0; n < data.Count; n++)
|
||||||
|
{
|
||||||
|
var serieData = data[n];
|
||||||
|
float value = serieData.data[1];
|
||||||
|
string dataName = serieData.name;
|
||||||
|
Color color;
|
||||||
|
if (string.IsNullOrEmpty(dataName))
|
||||||
|
{
|
||||||
|
serieNameCount++;
|
||||||
|
color = m_ThemeInfo.GetColor(serieNameCount);
|
||||||
|
}
|
||||||
|
else if (!serieNameSet.ContainsKey(dataName))
|
||||||
|
{
|
||||||
|
serieNameSet.Add(dataName, serieNameCount);
|
||||||
|
serieNameCount++;
|
||||||
|
color = m_ThemeInfo.GetColor(serieNameCount);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
color = m_ThemeInfo.GetColor(serieNameSet[dataName]);
|
||||||
|
}
|
||||||
|
if (!serieData.show)
|
||||||
|
{
|
||||||
|
tempData.angleList.Add(0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
float degree = totalDegree * value / tempData.dataTotal;
|
||||||
float toDegree = startDegree + degree;
|
float toDegree = startDegree + degree;
|
||||||
|
|
||||||
float outSideRadius = m_Pie.rose ?
|
float outSideRadius = serie.roseType > 0 ?
|
||||||
m_Pie.insideRadius + (m_PieRadius - m_Pie.insideRadius) * value / dataMax :
|
tempData.insideRadius + (tempData.outsideRadius - tempData.insideRadius) * value / tempData.dataMax :
|
||||||
m_PieRadius;
|
tempData.outsideRadius;
|
||||||
if (m_Tooltip.show && m_Tooltip.dataIndex[0] == i)
|
if (serieData.highlighted)
|
||||||
{
|
{
|
||||||
|
isDataHighlight = true;
|
||||||
|
color *= 1.2f;
|
||||||
outSideRadius += m_Pie.tooltipExtraRadius;
|
outSideRadius += m_Pie.tooltipExtraRadius;
|
||||||
}
|
}
|
||||||
var offset = m_Pie.space;
|
var offset = serie.space;
|
||||||
if (m_Pie.selected && m_Pie.selectedIndex == i)
|
if (serie.clickOffset && serieData.selected)
|
||||||
{
|
{
|
||||||
offset += m_Pie.selectedOffset;
|
offset += m_Pie.selectedOffset;
|
||||||
}
|
}
|
||||||
if (offset > 0)
|
if (offset > 0)
|
||||||
{
|
{
|
||||||
float currAngle = (startDegree + (toDegree - startDegree) / 2) * Mathf.Deg2Rad;
|
var halfDegree = (toDegree - startDegree) / 2;
|
||||||
var offestCenter = new Vector3(m_PieCenter.x + offset * Mathf.Sin(currAngle),
|
float offsetRadius = serie.space / Mathf.Sin(halfDegree * Mathf.Deg2Rad);
|
||||||
m_PieCenter.y + offset * Mathf.Cos(currAngle));
|
var insideRadius = tempData.insideRadius - offsetRadius;
|
||||||
ChartHelper.DrawDoughnut(vh, offestCenter, m_Pie.insideRadius, outSideRadius,
|
var outsideRadius = outSideRadius - offsetRadius;
|
||||||
startDegree, toDegree, m_ThemeInfo.GetColor(serieNameCount));
|
if (serie.clickOffset && serieData.selected)
|
||||||
|
{
|
||||||
|
offsetRadius += m_Pie.selectedOffset;
|
||||||
|
if (insideRadius > 0) insideRadius += m_Pie.selectedOffset;
|
||||||
|
outsideRadius += m_Pie.selectedOffset;
|
||||||
|
}
|
||||||
|
float currAngle = (startDegree + halfDegree) * Mathf.Deg2Rad;
|
||||||
|
var offestCenter = new Vector3(tempData.center.x + offsetRadius * Mathf.Sin(currAngle),
|
||||||
|
tempData.center.y + offsetRadius * Mathf.Cos(currAngle));
|
||||||
|
|
||||||
|
ChartHelper.DrawDoughnut(vh, offestCenter, insideRadius, outsideRadius,
|
||||||
|
startDegree, toDegree, color);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ChartHelper.DrawDoughnut(vh, m_PieCenter, m_Pie.insideRadius, outSideRadius,
|
ChartHelper.DrawDoughnut(vh, tempData.center, tempData.insideRadius, outSideRadius,
|
||||||
startDegree, toDegree, m_ThemeInfo.GetColor(serieNameCount));
|
startDegree, toDegree, color);
|
||||||
}
|
}
|
||||||
m_AngleList.Add(toDegree);
|
isDrawPie = true;
|
||||||
|
tempData.angleList.Add(toDegree);
|
||||||
startDegree = toDegree;
|
startDegree = toDegree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
raycastTarget = isClickOffset && isDataHighlight;
|
||||||
protected override void OnLegendButtonClicked()
|
|
||||||
{
|
|
||||||
base.OnLegendButtonClicked();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private float GetDataTotal()
|
protected override void OnLegendButtonClick(int index, string legendName)
|
||||||
{
|
{
|
||||||
float total = 0;
|
bool active = CheckDataShow(legendName);
|
||||||
for (int i = 0; i < m_Series.Count; i++)
|
var bgColor1 = active ? m_ThemeInfo.GetColor(index) : m_ThemeInfo.legendUnableColor;
|
||||||
{
|
m_Legend.UpdateButtonColor(legendName, bgColor1);
|
||||||
if (IsActive(i))
|
RefreshChart();
|
||||||
{
|
|
||||||
total += m_Series.series[i].GetYData(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private float GetDataMax()
|
protected override void OnLegendButtonEnter(int index, string legendName)
|
||||||
{
|
{
|
||||||
float max = 0;
|
m_IsEnterLegendButtom = true;
|
||||||
for (int i = 0; i < m_Series.Count; i++)
|
CheckDataHighlighted(legendName);
|
||||||
{
|
RefreshChart();
|
||||||
if (IsActive(i) && m_Series.series[i].GetYData(0) > max)
|
|
||||||
{
|
|
||||||
max = m_Series.series[i].GetYData(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return max;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdatePieCenter()
|
protected override void OnLegendButtonExit(int index, string legendName)
|
||||||
{
|
{
|
||||||
float diffX = chartWidth - m_Pie.left - m_Pie.right;
|
m_IsEnterLegendButtom = false;
|
||||||
float diffY = chartHeight - m_Pie.top - m_Pie.bottom;
|
CheckDataHighlighted(legendName);
|
||||||
float diff = Mathf.Min(diffX, diffY);
|
RefreshChart();
|
||||||
if (m_Pie.outsideRadius <= 0)
|
|
||||||
{
|
|
||||||
m_PieRadius = diff / 3 * 2;
|
|
||||||
m_PieCenterX = m_Pie.left + m_PieRadius;
|
|
||||||
m_PieCenterY = m_Pie.bottom + m_PieRadius;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
private bool CheckDataShow(string legendName)
|
||||||
{
|
{
|
||||||
m_PieRadius = m_Pie.outsideRadius;
|
bool show = false;
|
||||||
m_PieCenterX = chartWidth / 2;
|
foreach (var serie in m_Series.series)
|
||||||
m_PieCenterY = chartHeight / 2;
|
{
|
||||||
if (m_Pie.left > 0) m_PieCenterX = m_Pie.left + m_PieRadius;
|
foreach (var data in serie.data)
|
||||||
if (m_Pie.right > 0) m_PieCenterX = chartWidth - m_Pie.right - m_PieRadius;
|
{
|
||||||
if (m_Pie.top > 0) m_PieCenterY = chartHeight - m_Pie.top - m_PieRadius;
|
if (legendName.Equals(data.name))
|
||||||
if (m_Pie.bottom > 0) m_PieCenterY = m_Pie.bottom + m_PieRadius;
|
{
|
||||||
|
data.show = !data.show;
|
||||||
|
data.highlighted = false;
|
||||||
|
if (data.show) show = true;
|
||||||
}
|
}
|
||||||
m_PieCenter = new Vector2(m_PieCenterX, m_PieCenterY);
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
var tempData = m_PieTempDataList[serie.index];
|
||||||
|
var centerX = serie.center[0] <= 1 ? chartWidth * serie.center[0] : serie.center[0];
|
||||||
|
var centerY = serie.center[1] <= 1 ? chartHeight * serie.center[1] : serie.center[1];
|
||||||
|
tempData.center = new Vector2(centerX, centerY);
|
||||||
|
var minWidth = Mathf.Min(chartWidth, chartHeight);
|
||||||
|
tempData.insideRadius = serie.radius[0] <= 1 ? minWidth * serie.radius[0] : serie.radius[0];
|
||||||
|
tempData.outsideRadius = serie.radius[1] <= 1 ? minWidth * serie.radius[1] : serie.radius[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CheckTootipArea(Vector2 local)
|
protected override void CheckTootipArea(Vector2 local)
|
||||||
{
|
{
|
||||||
float dist = Vector2.Distance(local, m_PieCenter);
|
if (m_IsEnterLegendButtom) return;
|
||||||
if (dist > m_PieRadius)
|
m_Tooltip.dataIndex.Clear();
|
||||||
|
bool selected = false;
|
||||||
|
for (int i = 0; i < m_PieTempDataList.Count; i++)
|
||||||
{
|
{
|
||||||
m_Tooltip.dataIndex[0] = -1;
|
var serie = m_Series.GetSerie(i);
|
||||||
m_Tooltip.SetActive(false);
|
var tempData = m_PieTempDataList[i];
|
||||||
}
|
int index = GetPosPieIndex(tempData, local);
|
||||||
else
|
m_Tooltip.dataIndex.Add(index);
|
||||||
|
|
||||||
|
bool refresh = false;
|
||||||
|
for (int j = 0; j < serie.data.Count; j++)
|
||||||
{
|
{
|
||||||
m_Tooltip.dataIndex[0] = GetPosPieIndex(local);
|
var serieData = serie.data[j];
|
||||||
|
if (serieData.highlighted != (j == index)) refresh = true;
|
||||||
|
serieData.highlighted = j == index;
|
||||||
}
|
}
|
||||||
if (m_Tooltip.dataIndex[0] >= 0)
|
|
||||||
|
if (index >= 0) selected = true;
|
||||||
|
if (refresh) RefreshChart();
|
||||||
|
}
|
||||||
|
if (selected)
|
||||||
{
|
{
|
||||||
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
|
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
|
||||||
RefreshTooltip();
|
RefreshTooltip();
|
||||||
if (m_Tooltip.IsSelected())
|
|
||||||
{
|
|
||||||
m_Tooltip.UpdateLastDataIndex();
|
|
||||||
RefreshChart();
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_Tooltip.SetActive(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetPosPieIndex(Vector2 local)
|
private int GetPosPieIndex(PieTempData tempData, Vector2 local)
|
||||||
{
|
{
|
||||||
Vector2 dir = local - m_PieCenter;
|
var dist = Vector2.Distance(local, tempData.center);
|
||||||
|
if (dist < tempData.insideRadius || dist > tempData.outsideRadius) return -1;
|
||||||
|
Vector2 dir = local - tempData.center;
|
||||||
float angle = VectorAngle(Vector2.up, dir);
|
float angle = VectorAngle(Vector2.up, dir);
|
||||||
for (int i = m_AngleList.Count - 1; i >= 0; i--)
|
var angleList = tempData.angleList;
|
||||||
|
for (int i = angleList.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
if (angle <= m_AngleList[i]) return m_Tooltip.dataIndex[0] = 0;
|
if (angle <= angleList[i]) return 0;
|
||||||
}
|
}
|
||||||
else if (angle <= m_AngleList[i] && angle > m_AngleList[i - 1])
|
else if (angle <= angleList[i] && angle > angleList[i - 1])
|
||||||
{
|
{
|
||||||
return m_Tooltip.dataIndex[0] = i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@@ -251,27 +327,28 @@ namespace XCharts
|
|||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
protected override void RefreshTooltip()
|
protected override void RefreshTooltip()
|
||||||
{
|
{
|
||||||
base.RefreshTooltip();
|
base.RefreshTooltip();
|
||||||
int index = m_Tooltip.dataIndex[0];
|
bool showTooltip = false;
|
||||||
if (index < 0)
|
for (int i = 0; i < m_PieTempDataList.Count; i++)
|
||||||
{
|
{
|
||||||
m_Tooltip.SetActive(false);
|
int index = m_Tooltip.dataIndex[i];
|
||||||
return;
|
if (index < 0) continue;
|
||||||
}
|
showTooltip = true;
|
||||||
m_Tooltip.SetActive(true);
|
var serie = m_Series.GetSerie(i);
|
||||||
string strColor = ColorUtility.ToHtmlStringRGBA(m_ThemeInfo.GetColor(index));
|
string key = serie.data[index].name;
|
||||||
string key = m_Series.series[index].name;
|
|
||||||
if (string.IsNullOrEmpty(key)) key = m_Legend.GetData(index);
|
if (string.IsNullOrEmpty(key)) key = m_Legend.GetData(index);
|
||||||
float value = m_Series.series[index].yData[0];
|
float value = serie.data[index].data[1];
|
||||||
string txt = "";
|
sb.Length = 0;
|
||||||
if (!string.IsNullOrEmpty(m_Pie.name))
|
if (!string.IsNullOrEmpty(serie.name))
|
||||||
{
|
{
|
||||||
txt += m_Pie.name + "\n";
|
sb.Append(serie.name).Append("\n");
|
||||||
}
|
}
|
||||||
txt += string.Format("<color=#{0}>● </color>{1}: {2}", strColor, key, value);
|
sb.Append("<color=#").Append(m_ThemeInfo.GetColorStr(index)).Append(">● </color>")
|
||||||
m_Tooltip.UpdateContentText(txt);
|
.Append(key).Append(": ").Append(ChartCached.FloatToStr(value));
|
||||||
|
m_Tooltip.UpdateContentText(sb.ToString());
|
||||||
|
|
||||||
var pos = m_Tooltip.GetContentPos();
|
var pos = m_Tooltip.GetContentPos();
|
||||||
if (pos.x + m_Tooltip.width > chartWidth)
|
if (pos.x + m_Tooltip.width > chartWidth)
|
||||||
@@ -284,6 +361,8 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
m_Tooltip.UpdateContentPos(pos);
|
m_Tooltip.UpdateContentPos(pos);
|
||||||
}
|
}
|
||||||
|
m_Tooltip.SetActive(showTooltip);
|
||||||
|
}
|
||||||
|
|
||||||
public override void OnPointerDown(PointerEventData eventData)
|
public override void OnPointerDown(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
@@ -293,14 +372,19 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var selectedIndex = GetPosPieIndex(local);
|
for (int i = 0; i < m_PieTempDataList.Count; i++)
|
||||||
if (selectedIndex != m_Pie.selectedIndex)
|
|
||||||
{
|
{
|
||||||
m_Pie.selectedIndex = selectedIndex;
|
var tempData = m_PieTempDataList[i];
|
||||||
|
int index = GetPosPieIndex(tempData, local);
|
||||||
|
if (index >= 0)
|
||||||
|
{
|
||||||
|
var serie = m_Series.GetSerie(i);
|
||||||
|
for (int j = 0; j < serie.data.Count; j++)
|
||||||
|
{
|
||||||
|
if (j == index) serie.data[j].selected = !serie.data[j].selected;
|
||||||
|
else serie.data[j].selected = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
m_Pie.selectedIndex = -1;
|
|
||||||
}
|
}
|
||||||
RefreshChart();
|
RefreshChart();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,11 +133,6 @@ namespace XCharts
|
|||||||
DrawData(vh);
|
DrawData(vh);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnLegendButtonClicked()
|
|
||||||
{
|
|
||||||
base.OnLegendButtonClicked();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnThemeChanged()
|
protected override void OnThemeChanged()
|
||||||
{
|
{
|
||||||
base.OnThemeChanged();
|
base.OnThemeChanged();
|
||||||
|
|||||||
@@ -91,8 +91,9 @@ namespace XCharts
|
|||||||
: serie.dataCount;
|
: serie.dataCount;
|
||||||
for (int n = minShowDataNumber; n < maxCount; n++)
|
for (int n = minShowDataNumber; n < maxCount; n++)
|
||||||
{
|
{
|
||||||
float xValue, yValue;
|
var serieData = serie.GetDataList(m_DataZoom)[n];
|
||||||
serie.GetXYData(n, m_DataZoom, out xValue, out yValue);
|
float xValue = serieData.data[0];
|
||||||
|
float yValue = serieData.data[1];
|
||||||
float pX = coordinateX + m_Coordinate.tickness;
|
float pX = coordinateX + m_Coordinate.tickness;
|
||||||
float pY = coordinateY + m_Coordinate.tickness;
|
float pY = coordinateY + m_Coordinate.tickness;
|
||||||
float xDataHig = (xValue - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
float xDataHig = (xValue - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
||||||
@@ -101,7 +102,7 @@ namespace XCharts
|
|||||||
|
|
||||||
var datas = serie.data[n].data;
|
var datas = serie.data[n].data;
|
||||||
float symbolSize = 0;
|
float symbolSize = 0;
|
||||||
if (serie.selected && n == m_Tooltip.dataIndex[serie.axisIndex])
|
if (serie.highlighted || serieData.highlighted)
|
||||||
{
|
{
|
||||||
symbolSize = serie.symbol.GetSelectedSize(datas);
|
symbolSize = serie.symbol.GetSelectedSize(datas);
|
||||||
}
|
}
|
||||||
@@ -128,7 +129,6 @@ namespace XCharts
|
|||||||
if (vh.currentVertCount > 60000)
|
if (vh.currentVertCount > 60000)
|
||||||
{
|
{
|
||||||
m_Large++;
|
m_Large++;
|
||||||
Debug.LogError("large:" + m_Large + "," + vh.currentVertCount);
|
|
||||||
RefreshChart();
|
RefreshChart();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
6
Scripts/UI/Utility/ChartButton.cs
Normal file
6
Scripts/UI/Utility/ChartButton.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace XCharts
|
||||||
|
{
|
||||||
|
public class ChartButton{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Scripts/UI/Utility/ChartButton.cs.meta
Normal file
11
Scripts/UI/Utility/ChartButton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9edc7c31bd8554edfb7e22dcf57f942e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -363,7 +363,8 @@ namespace XCharts
|
|||||||
Vector3 cp2)
|
Vector3 cp2)
|
||||||
{
|
{
|
||||||
posList.Clear();
|
posList.Clear();
|
||||||
if(posList.Capacity < segment + 1){
|
if (posList.Capacity < segment + 1)
|
||||||
|
{
|
||||||
posList.Capacity = segment + 1;
|
posList.Capacity = segment + 1;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < segment; i++)
|
for (int i = 0; i < segment; i++)
|
||||||
@@ -418,10 +419,8 @@ namespace XCharts
|
|||||||
points[i] = (1 - t) * points[i] + t * points[i + 1];
|
points[i] = (1 - t) * points[i] + t * points[i + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
curvedPoints.Add(points[0]);
|
curvedPoints.Add(points[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return curvedPoints;
|
return curvedPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,17 +450,13 @@ namespace XCharts
|
|||||||
int startIndex = jsonData.IndexOf("[");
|
int startIndex = jsonData.IndexOf("[");
|
||||||
int endIndex = jsonData.IndexOf("]");
|
int endIndex = jsonData.IndexOf("]");
|
||||||
string temp = jsonData.Substring(startIndex + 1, endIndex - startIndex - 1);
|
string temp = jsonData.Substring(startIndex + 1, endIndex - startIndex - 1);
|
||||||
Debug.LogError("temp:"+temp);
|
|
||||||
if (temp.IndexOf("],") > -1 || temp.IndexOf("] ,") > -1)
|
if (temp.IndexOf("],") > -1 || temp.IndexOf("] ,") > -1)
|
||||||
{
|
{
|
||||||
string[] datas = temp.Split(new string[] { "],", "] ," }, StringSplitOptions.RemoveEmptyEntries);
|
string[] datas = temp.Split(new string[] { "],", "] ," }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
for (int i = 0; i < datas.Length; i++)
|
for (int i = 0; i < datas.Length; i++)
|
||||||
{
|
{
|
||||||
temp = datas[i];
|
temp = datas[i];
|
||||||
Debug.LogError("split:" + temp);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -541,12 +536,20 @@ namespace XCharts
|
|||||||
UnityEngine.Events.UnityAction<BaseEventData> call)
|
UnityEngine.Events.UnityAction<BaseEventData> call)
|
||||||
{
|
{
|
||||||
EventTrigger trigger = GetOrAddComponent<EventTrigger>(obj.gameObject);
|
EventTrigger trigger = GetOrAddComponent<EventTrigger>(obj.gameObject);
|
||||||
EventTrigger.Entry entry1 = new EventTrigger.Entry();
|
EventTrigger.Entry entry = new EventTrigger.Entry();
|
||||||
entry1.eventID = type;
|
entry.eventID = type;
|
||||||
entry1.callback = new EventTrigger.TriggerEvent();
|
entry.callback = new EventTrigger.TriggerEvent();
|
||||||
entry1.callback.AddListener(call);
|
entry.callback.AddListener(call);
|
||||||
|
trigger.triggers.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ClearEventListener(GameObject obj)
|
||||||
|
{
|
||||||
|
EventTrigger trigger = obj.GetComponent<EventTrigger>();
|
||||||
|
if (trigger != null)
|
||||||
|
{
|
||||||
trigger.triggers.Clear();
|
trigger.triggers.Clear();
|
||||||
trigger.triggers.Add(entry1);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user