mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 00:20:18 +00:00
增加selected等相关参数配置PieChart的选中效果
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,9 @@ namespace XCharts
|
||||
SerializedProperty m_Right;
|
||||
SerializedProperty m_Top;
|
||||
SerializedProperty m_Bottom;
|
||||
SerializedProperty m_Selected;
|
||||
SerializedProperty m_SelectedIndex;
|
||||
SerializedProperty m_SelectedOffset;
|
||||
bool m_PieModuleToggle = true;
|
||||
|
||||
private void InitProperty(SerializedProperty prop)
|
||||
@@ -30,6 +33,9 @@ namespace XCharts
|
||||
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");
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
@@ -50,6 +56,12 @@ namespace XCharts
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_TooltipExtraRadius);
|
||||
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);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Rose);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Space);
|
||||
@@ -70,7 +82,7 @@ namespace XCharts
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
if (m_PieModuleToggle)
|
||||
return 11 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
|
||||
return 14 * EditorGUIUtility.singleLineHeight + 13 * EditorGUIUtility.standardVerticalSpacing;
|
||||
else
|
||||
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ namespace XCharts
|
||||
[SerializeField] private float m_InsideRadius;
|
||||
[SerializeField] private float m_OutsideRadius;
|
||||
[SerializeField] private float m_TooltipExtraRadius;
|
||||
[SerializeField] private bool m_Selected;
|
||||
[SerializeField] private int m_SelectedIndex;
|
||||
[SerializeField] private float m_SelectedOffset;
|
||||
[SerializeField] private bool m_Rose;
|
||||
[SerializeField] private float m_Space;
|
||||
[SerializeField] private float m_Left;
|
||||
@@ -20,6 +23,9 @@ namespace XCharts
|
||||
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 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 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; } }
|
||||
@@ -37,7 +43,9 @@ namespace XCharts
|
||||
m_InsideRadius = 0f,
|
||||
m_OutsideRadius = 80f,
|
||||
m_TooltipExtraRadius = 10f,
|
||||
m_Rose = false
|
||||
m_Rose = false,
|
||||
m_Selected = false,
|
||||
m_SelectedOffset = 10,
|
||||
};
|
||||
return pie;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
@@ -16,6 +17,21 @@ namespace XCharts
|
||||
|
||||
public Pie pie { get { return m_Pie; } }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
raycastTarget = m_Pie.selected;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
if (raycastTarget != m_Pie.selected)
|
||||
{
|
||||
raycastTarget = m_Pie.selected;
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
|
||||
public override void AddData(string legend, float value)
|
||||
{
|
||||
m_Legend.AddData(legend);
|
||||
@@ -71,8 +87,24 @@ namespace XCharts
|
||||
{
|
||||
outSideRadius += m_Pie.tooltipExtraRadius;
|
||||
}
|
||||
ChartHelper.DrawDoughnut(vh, m_PieCenter, m_Pie.insideRadius,
|
||||
outSideRadius, startDegree, toDegree, m_ThemeInfo.GetColor(i));
|
||||
var offset = m_Pie.space;
|
||||
if (m_Pie.selected && m_Pie.selectedIndex == i + 1)
|
||||
{
|
||||
offset += m_Pie.selectedOffset;
|
||||
}
|
||||
if (offset > 0)
|
||||
{
|
||||
float currAngle = (startDegree + (toDegree - startDegree) / 2) * Mathf.Deg2Rad;
|
||||
var offestCenter = new Vector3(m_PieCenter.x + offset * Mathf.Sin(currAngle),
|
||||
m_PieCenter.y + offset * Mathf.Cos(currAngle));
|
||||
ChartHelper.DrawDoughnut(vh, offestCenter, m_Pie.insideRadius, outSideRadius,
|
||||
startDegree, toDegree, m_ThemeInfo.GetColor(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.DrawDoughnut(vh, m_PieCenter, m_Pie.insideRadius, outSideRadius,
|
||||
startDegree, toDegree, m_ThemeInfo.GetColor(i));
|
||||
}
|
||||
m_AngleList.Add(toDegree);
|
||||
startDegree = toDegree;
|
||||
}
|
||||
@@ -136,7 +168,6 @@ namespace XCharts
|
||||
|
||||
protected override void CheckTootipArea(Vector2 local)
|
||||
{
|
||||
|
||||
float dist = Vector2.Distance(local, m_PieCenter);
|
||||
if (dist > m_PieRadius)
|
||||
{
|
||||
@@ -145,22 +176,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 dir = local - m_PieCenter;
|
||||
float angle = VectorAngle(Vector2.up, dir);
|
||||
m_Tooltip.dataIndex = 0;
|
||||
for (int i = m_AngleList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (i == 0 && angle < m_AngleList[i])
|
||||
{
|
||||
m_Tooltip.dataIndex = 1;
|
||||
break;
|
||||
}
|
||||
else if (angle < m_AngleList[i] && angle > m_AngleList[i - 1])
|
||||
{
|
||||
m_Tooltip.dataIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_Tooltip.dataIndex = GetPosPieIndex(local);
|
||||
}
|
||||
if (m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
@@ -174,6 +190,24 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private int GetPosPieIndex(Vector2 local)
|
||||
{
|
||||
Vector2 dir = local - m_PieCenter;
|
||||
float angle = VectorAngle(Vector2.up, dir);
|
||||
for (int i = m_AngleList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (i == 0 && angle < m_AngleList[i])
|
||||
{
|
||||
return m_Tooltip.dataIndex = 1;
|
||||
}
|
||||
else if (angle < m_AngleList[i] && angle > m_AngleList[i - 1])
|
||||
{
|
||||
return m_Tooltip.dataIndex = i + 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
float VectorAngle(Vector2 from, Vector2 to)
|
||||
{
|
||||
float angle;
|
||||
@@ -217,5 +251,20 @@ namespace XCharts
|
||||
}
|
||||
m_Tooltip.UpdateContentPos(pos);
|
||||
}
|
||||
|
||||
public override void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
var local = transform.InverseTransformPoint(eventData.position);
|
||||
var selectedIndex = GetPosPieIndex(local);
|
||||
if (selectedIndex != m_Pie.selectedIndex)
|
||||
{
|
||||
m_Pie.selectedIndex = selectedIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Pie.selectedIndex = 0;
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
26
README.md
26
README.md
@@ -21,6 +21,7 @@ An ECharts style UGUI Charting Library for Unity
|
||||
|
||||
## 更新日志
|
||||
|
||||
* (2019.07.02)增加`selected`等相关参数配置`PieChart`的选中效果
|
||||
* (2019.06.30)增加`SplitArea`配置坐标轴`分割区域`
|
||||
* (2019.06.29)增加`AxisName`配置坐标轴`名称`
|
||||
* (2019.06.20)增加`AreaAlpha`控制`RadarChart`的`Area`透明度
|
||||
@@ -40,7 +41,8 @@ An ECharts style UGUI Charting Library for Unity
|
||||
|
||||
## 内置示例
|
||||
|
||||
* 折线图
|
||||
### 折线图
|
||||
|
||||
1. 基础折线图
|
||||
2. 负数数值轴+自定义最大最小刻度
|
||||
3. XY轴互换
|
||||
@@ -54,7 +56,9 @@ An ECharts style UGUI Charting Library for Unity
|
||||
11. 动态数据
|
||||
12. 大数据量面积图
|
||||
13. 大数据+区域缩放
|
||||
* 柱状图
|
||||
|
||||
### 柱状图
|
||||
|
||||
1. 基础柱状图
|
||||
2. 负数数值轴+自定义最大最小刻度
|
||||
3. XY轴互换
|
||||
@@ -64,17 +68,23 @@ An ECharts style UGUI Charting Library for Unity
|
||||
7. 深圳月最低生活费组成(单位:元)
|
||||
8. 非堆叠同柱
|
||||
9. 5000数据
|
||||
* 饼图
|
||||
|
||||
### 饼图
|
||||
|
||||
1. Customized Pie
|
||||
2. 环形图
|
||||
3. 南丁格尔玫瑰图
|
||||
4. 某站点用户访问来源
|
||||
5. 用代码添加和更新数据
|
||||
* 雷达图
|
||||
3. 环形图+默认选中
|
||||
4. 南丁格尔玫瑰图
|
||||
5. 某站点用户访问来源
|
||||
6. 用代码添加和更新数据
|
||||
|
||||
### 雷达图
|
||||
|
||||
1. 多边形雷达图+指定最大值
|
||||
2. 圆形+自定义背景
|
||||
3. 填充颜色
|
||||
* 其他
|
||||
|
||||
### 其他
|
||||
|
||||
## 入门教程
|
||||
|
||||
|
||||
Reference in New Issue
Block a user