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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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