mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 06:20:15 +00:00
优化RadarChart雷达图,增加多雷达图支持
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -12,7 +13,28 @@ namespace XCharts
|
||||
[System.Serializable]
|
||||
public class Legend : JsonDataSupport, IPropertyChanged, IEquatable<Legend>
|
||||
{
|
||||
/// <summary>
|
||||
/// Selected mode of legend, which controls whether series can be toggled displaying by clicking legends.
|
||||
/// It is enabled by default, and you may set it to be false to disabled it.
|
||||
/// 图例选择的模式,控制是否可以通过点击图例改变系列的显示状态。默认开启图例选择,可以设成 None 关闭。
|
||||
/// </summary>
|
||||
public enum SelectedMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 多选。
|
||||
/// </summary>
|
||||
Multiple,
|
||||
/// <summary>
|
||||
/// 单选。
|
||||
/// </summary>
|
||||
Single,
|
||||
/// <summary>
|
||||
/// 无法选择。
|
||||
/// </summary>
|
||||
None
|
||||
}
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private SelectedMode m_SelectedMode;
|
||||
[SerializeField] private Orient m_Orient = Orient.Horizonal;
|
||||
[SerializeField] private Location m_Location = Location.defaultRight;
|
||||
[SerializeField] private float m_ItemWidth = 50.0f;
|
||||
@@ -29,6 +51,12 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// Selected mode of legend, which controls whether series can be toggled displaying by clicking legends.
|
||||
/// 选择模式。控制是否可以通过点击图例改变系列的显示状态。默认开启图例选择,可以设成 None 关闭。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public SelectedMode selectedMode { get { return m_SelectedMode; } set { m_SelectedMode = value; } }
|
||||
/// <summary>
|
||||
/// Specify whether the layout of legend component is horizontal or vertical.
|
||||
/// 布局方式是横还是竖。
|
||||
/// </summary>
|
||||
@@ -66,6 +94,12 @@ namespace XCharts
|
||||
/// 如果 data 没有被指定,会自动从当前系列中获取。指定data时里面的数据项和serie匹配时才会生效。
|
||||
/// </summary>
|
||||
public List<string> data { get { return m_Data; } }
|
||||
/// <summary>
|
||||
/// the button list of legend.
|
||||
/// 图例按钮列表。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Dictionary<string, Button> buttonList { get { return m_DataBtnList; } }
|
||||
|
||||
/// <summary>
|
||||
/// 一个在顶部居中显示的默认图例。
|
||||
@@ -77,6 +111,7 @@ namespace XCharts
|
||||
var legend = new Legend
|
||||
{
|
||||
m_Show = false,
|
||||
m_SelectedMode = SelectedMode.Multiple,
|
||||
m_Orient = Orient.Horizonal,
|
||||
m_Location = Location.defaultTop,
|
||||
m_ItemWidth = 60.0f,
|
||||
@@ -91,6 +126,7 @@ namespace XCharts
|
||||
public void Copy(Legend legend)
|
||||
{
|
||||
m_Show = legend.show;
|
||||
m_SelectedMode = legend.selectedMode;
|
||||
m_Orient = legend.orient;
|
||||
m_Location.Copy(legend.location);
|
||||
m_ItemWidth = legend.itemWidth;
|
||||
@@ -124,6 +160,7 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
return show == other.show &&
|
||||
selectedMode == other.selectedMode &&
|
||||
orient == other.orient &&
|
||||
location == other.location &&
|
||||
itemWidth == other.itemWidth &&
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -12,6 +13,15 @@ namespace XCharts
|
||||
[System.Serializable]
|
||||
public class Radar : JsonDataSupport, IEquatable<Radar>
|
||||
{
|
||||
/// <summary>
|
||||
/// Radar render type, in which 'Polygon' and 'Circle' are supported.
|
||||
/// 雷达图绘制类型,支持 'Polygon' 和 'Circle'。
|
||||
/// </summary>
|
||||
public enum Shape
|
||||
{
|
||||
Polygon,
|
||||
Circle
|
||||
}
|
||||
/// <summary>
|
||||
/// Indicator of radar chart, which is used to assign multiple variables(dimensions) in radar chart.
|
||||
/// 雷达图的指示器,用来指定雷达图中的多个变量(维度)。
|
||||
@@ -39,9 +49,14 @@ namespace XCharts
|
||||
public float min { get { return m_Min; } set { m_Min = value; } }
|
||||
/// <summary>
|
||||
/// Specfy a color the the indicator.
|
||||
/// 标签特定的颜色。
|
||||
/// 标签特定的颜色。默认取自主题的axisTextColor。
|
||||
/// </summary>
|
||||
public Color color { get { return m_Color; } set { m_Color = value; } }
|
||||
/// <summary>
|
||||
/// the text conponent of indicator.
|
||||
/// 指示器的文本组件。
|
||||
/// </summary>
|
||||
public Text text { get; set; }
|
||||
|
||||
public Indicator Clone()
|
||||
{
|
||||
@@ -54,43 +69,51 @@ namespace XCharts
|
||||
};
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj is Indicator)
|
||||
{
|
||||
return Equals((Indicator)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(Indicator other)
|
||||
{
|
||||
return name.Equals(other.name);
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_Name.Equals(other.name) &&
|
||||
ChartHelper.IsValueEqualsColor(m_Color, other.color);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] private bool m_Cricle;
|
||||
[SerializeField] private bool m_Area;
|
||||
|
||||
[SerializeField] private Shape m_Shape;
|
||||
[SerializeField] private float m_Radius = 100;
|
||||
[SerializeField] private int m_SplitNumber = 5;
|
||||
|
||||
[SerializeField] private float m_Left;
|
||||
[SerializeField] private float m_Right;
|
||||
[SerializeField] private float m_Top;
|
||||
[SerializeField] private float m_Bottom;
|
||||
|
||||
[SerializeField] private float m_LineTickness = 1f;
|
||||
[SerializeField] private float m_LinePointSize = 5f;
|
||||
[SerializeField] private Color m_LineColor = Color.grey;
|
||||
[Range(0, 255)]
|
||||
[SerializeField] private int m_AreaAlpha;
|
||||
|
||||
[SerializeField] private List<Color> m_BackgroundColorList = new List<Color>();
|
||||
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
|
||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
|
||||
[SerializeField] private AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
|
||||
[SerializeField] private bool m_Indicator = true;
|
||||
[SerializeField] private List<Indicator> m_IndicatorList = new List<Indicator>();
|
||||
|
||||
/// <summary>
|
||||
/// True is render radar as cricle,otherwise render as polygon.
|
||||
///雷达图是否绘制成圆形,true为圆形,false为多边形。
|
||||
/// Radar render type, in which 'Polygon' and 'Circle' are supported.
|
||||
/// 雷达图绘制类型,支持 'Polygon' 和 'Circle'。
|
||||
/// </summary>
|
||||
public bool cricle { get { return m_Cricle; } set { m_Cricle = value; } }
|
||||
/// <summary>
|
||||
/// Whether to fill color in area.
|
||||
/// 是否区域填充颜色
|
||||
/// </summary>
|
||||
public bool area { get { return m_Area; } set { m_Area = value; } }
|
||||
/// <value></value>
|
||||
public Shape shape { get { return m_Shape; } set { m_Shape = value; } }
|
||||
/// <summary>
|
||||
/// the radius of radar.
|
||||
/// 雷达图的半径。
|
||||
@@ -102,50 +125,21 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public int splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
|
||||
/// <summary>
|
||||
/// Distance between radar component and the left side of the container.
|
||||
/// 雷达图离容器左侧的距离。
|
||||
/// the center of radar chart.
|
||||
/// 雷达图的中心点。数组的第一项是横坐标,第二项是纵坐标。
|
||||
/// 当值为0-1之间时表示百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度。
|
||||
/// </summary>
|
||||
public float left { get { return m_Left; } set { m_Left = value; } }
|
||||
public float[] center { get { return m_Center; } set { m_Center = value; } }
|
||||
/// <summary>
|
||||
/// Distance between radar component and the right side of the container.
|
||||
/// 雷达图离容器右侧的距离。
|
||||
/// the line style of radar.
|
||||
/// 线条样式。
|
||||
/// </summary>
|
||||
public float right { get { return m_Right; } set { m_Right = value; } }
|
||||
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
|
||||
/// <summary>
|
||||
/// Distance between radar component and the top side of the container.
|
||||
/// 雷达图离容器上侧的距离。
|
||||
/// Split area of axis in grid area.
|
||||
/// 分割区域。
|
||||
/// </summary>
|
||||
public float top { get { return m_Top; } set { m_Top = value; } }
|
||||
/// <summary>
|
||||
/// Distance between radar component and the bottom side of the container.
|
||||
/// 雷达图离容器下侧的距离。
|
||||
/// </summary>
|
||||
public float bottom { get { return m_Bottom; } set { m_Bottom = value; } }
|
||||
/// <summary>
|
||||
/// the tickness of line.
|
||||
/// 线的粗细。
|
||||
/// </summary>
|
||||
public float lineTickness { get { return m_LineTickness; } set { m_LineTickness = value; } }
|
||||
/// <summary>
|
||||
/// the size of point.
|
||||
/// 圆点大小。
|
||||
/// </summary>
|
||||
public float linePointSize { get { return m_LinePointSize; } set { m_LinePointSize = value; } }
|
||||
/// <summary>
|
||||
/// the color of line.
|
||||
/// 线的颜色。
|
||||
/// </summary>
|
||||
public Color lineColor { get { return m_LineColor; } set { m_LineColor = value; } }
|
||||
/// <summary>
|
||||
/// the alpha of area color.
|
||||
/// 区域填充时的颜色alpha值
|
||||
/// </summary>
|
||||
public int areaAlpha { get { return m_AreaAlpha; } set { m_AreaAlpha = value; } }
|
||||
/// <summary>
|
||||
/// the color list of split area.
|
||||
/// 分割区域颜色列表。
|
||||
/// </summary>
|
||||
public List<Color> backgroundColorList { get { return m_BackgroundColorList; } }
|
||||
public AxisSplitArea splitArea { get { return m_SplitArea; } set { m_SplitArea = value; } }
|
||||
/// <summary>
|
||||
/// Whether to show indicator.
|
||||
/// 是否显示指示器。
|
||||
@@ -157,55 +151,77 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public List<Indicator> indicatorList { get { return m_IndicatorList; } }
|
||||
|
||||
/// <summary>
|
||||
/// the center position of radar in container.
|
||||
/// 雷达图在容器中的具体中心点。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Vector2 centerPos { get; set; }
|
||||
/// <summary>
|
||||
/// the true radius of radar.
|
||||
/// 雷达图的运行时实际半径。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float actualRadius { get; set; }
|
||||
/// <summary>
|
||||
/// the data position list of radar.
|
||||
/// 雷达图的所有数据坐标点列表。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<int,List<Vector3>> dataPosList = new Dictionary<int,List<Vector3>>();
|
||||
|
||||
public static Radar defaultRadar
|
||||
{
|
||||
get
|
||||
{
|
||||
var radar = new Radar
|
||||
{
|
||||
m_Cricle = false,
|
||||
m_Area = false,
|
||||
m_Radius = 100,
|
||||
m_Shape = Shape.Polygon,
|
||||
m_Radius = 0.4f,
|
||||
m_SplitNumber = 5,
|
||||
m_Left = 0,
|
||||
m_Right = 0,
|
||||
m_Top = 0,
|
||||
m_Bottom = 0,
|
||||
m_LineTickness = 1f,
|
||||
m_LinePointSize = 5f,
|
||||
m_AreaAlpha = 150,
|
||||
m_LineColor = Color.grey,
|
||||
m_Indicator = true,
|
||||
m_BackgroundColorList = new List<Color> {
|
||||
new Color32(246, 246, 246, 255),
|
||||
new Color32(231, 231, 231, 255)
|
||||
},
|
||||
m_IndicatorList = new List<Indicator>(5){
|
||||
new Indicator(){name="radar1",max = 100},
|
||||
new Indicator(){name="radar2",max = 100},
|
||||
new Indicator(){name="radar3",max = 100},
|
||||
new Indicator(){name="radar4",max = 100},
|
||||
new Indicator(){name="radar5",max = 100},
|
||||
new Indicator(){name="indicator1",max = 100},
|
||||
new Indicator(){name="indicator2",max = 100},
|
||||
new Indicator(){name="indicator3",max = 100},
|
||||
new Indicator(){name="indicator4",max = 100},
|
||||
new Indicator(){name="indicator5",max = 100},
|
||||
}
|
||||
};
|
||||
radar.center[0] = 0.5f;
|
||||
radar.center[1] = 0.45f;
|
||||
radar.splitArea.show = true;
|
||||
radar.lineStyle.width = 0.3f;
|
||||
return radar;
|
||||
}
|
||||
}
|
||||
|
||||
public void Copy(Radar other)
|
||||
{
|
||||
m_Shape = other.shape;
|
||||
m_Radius = other.radius;
|
||||
m_SplitNumber = other.splitNumber;
|
||||
m_Left = other.left;
|
||||
m_Right = other.right;
|
||||
m_Top = other.top;
|
||||
m_Bottom = other.bottom;
|
||||
m_Center[0] = other.center[0];
|
||||
m_Center[1] = other.center[1];
|
||||
m_Indicator = other.indicator;
|
||||
m_AreaAlpha = other.areaAlpha;
|
||||
indicatorList.Clear();
|
||||
foreach (var d in other.indicatorList) indicatorList.Add(d.Clone());
|
||||
}
|
||||
|
||||
public Radar Clone()
|
||||
{
|
||||
var radar = new Radar();
|
||||
radar.shape = shape;
|
||||
radar.radius = radius;
|
||||
radar.splitNumber = splitNumber;
|
||||
radar.center[0] = center[0];
|
||||
radar.center[1] = center[1];
|
||||
radar.indicatorList.Clear();
|
||||
radar.indicator = indicator;
|
||||
foreach (var d in indicatorList) radar.indicatorList.Add(d.Clone());
|
||||
return radar;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
@@ -229,11 +245,10 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
return radius == other.radius &&
|
||||
shape == other.shape &&
|
||||
splitNumber == other.splitNumber &&
|
||||
left == other.left &&
|
||||
right == other.right &&
|
||||
top == other.top &&
|
||||
bottom == other.bottom &&
|
||||
center[0] == other.center[0] &&
|
||||
center[1] == other.center[1] &&
|
||||
indicator == other.indicator &&
|
||||
IsEqualsIndicatorList(indicatorList, other.indicatorList);
|
||||
}
|
||||
@@ -305,6 +320,14 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public float GetIndicatorMin(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_IndicatorList.Count)
|
||||
{
|
||||
return m_IndicatorList[index].min;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public float GetIndicatorMax(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_IndicatorList.Count)
|
||||
@@ -313,5 +336,34 @@ namespace XCharts
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void UpdateRadarCenter(float chartWidth, float chartHeight)
|
||||
{
|
||||
if (center.Length < 2) return;
|
||||
var centerX = center[0] <= 1 ? chartWidth * center[0] : center[0];
|
||||
var centerY = center[1] <= 1 ? chartHeight * center[1] : center[1];
|
||||
centerPos = new Vector2(centerX, centerY);
|
||||
if (radius <= 0)
|
||||
{
|
||||
actualRadius = 0;
|
||||
}
|
||||
else if (radius <= 1)
|
||||
{
|
||||
actualRadius = Mathf.Min(chartWidth, chartHeight) * radius;
|
||||
}
|
||||
else
|
||||
{
|
||||
actualRadius = radius;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 GetIndicatorPosition(int index)
|
||||
{
|
||||
int indicatorNum = indicatorList.Count;
|
||||
var angle = 2 * Mathf.PI / indicatorNum * index;
|
||||
var x = centerPos.x + actualRadius * Mathf.Sin(angle);
|
||||
var y = centerPos.y + actualRadius * Mathf.Cos(angle);
|
||||
return new Vector3(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,10 @@ namespace XCharts
|
||||
[SerializeField] private SerieType m_Type;
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private string m_Stack;
|
||||
[SerializeField] [Range(0, 1)] private int m_AxisIndex;
|
||||
[SerializeField] [Range(0, 1)] private int m_AxisIndex = 0;
|
||||
[SerializeField] private int m_RadarIndex = 0;
|
||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
|
||||
[SerializeField] private AreaStyle m_AreaStyle = AreaStyle.defaultAreaStyle;
|
||||
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
|
||||
#region PieChart field
|
||||
[SerializeField] private bool m_ClickOffset = true;
|
||||
@@ -83,7 +86,7 @@ namespace XCharts
|
||||
#endregion
|
||||
[SerializeField] private SerieLabel m_Label = new SerieLabel();
|
||||
[SerializeField] private SerieLabel m_HighlightLabel = new SerieLabel();
|
||||
[SerializeField] [Range(1, 6)] private int m_ShowDataDimension;
|
||||
[SerializeField] [Range(1, 10)] private int m_ShowDataDimension;
|
||||
[SerializeField] private bool m_ShowDataName;
|
||||
[FormerlySerializedAs("m_Data")]
|
||||
[SerializeField] private List<float> m_YData = new List<float>();
|
||||
@@ -116,6 +119,23 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public int axisIndex { get { return m_AxisIndex; } set { m_AxisIndex = value; } }
|
||||
/// <summary>
|
||||
/// Index of radar component that radar chart uses.
|
||||
/// 雷达图所使用的 radar 组件的 index。
|
||||
/// </summary>
|
||||
public int radarIndex { get { return m_RadarIndex; } set { m_RadarIndex = value; } }
|
||||
/// <summary>
|
||||
/// The style of line.
|
||||
/// 线条样式。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
|
||||
/// <summary>
|
||||
/// The style of area.
|
||||
/// 区域填充样式。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public AreaStyle areaStyle { get { return m_AreaStyle; } set { m_AreaStyle = value; } }
|
||||
/// <summary>
|
||||
/// the symbol of serie data item.
|
||||
/// 标记的图形。
|
||||
/// </summary>
|
||||
@@ -360,7 +380,7 @@ namespace XCharts
|
||||
m_YData.Add(yValue);
|
||||
m_Data.Add(new SerieData() { data = new List<float>() { xValue, yValue }, name = dataName });
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 将一组数据添加到系列中。
|
||||
/// 如果数据只有一个,默认添加到维度Y中。
|
||||
@@ -393,7 +413,7 @@ namespace XCharts
|
||||
{
|
||||
if (i == 0) m_XData.Add(valueList[i]);
|
||||
else if (i == 1) m_YData.Add(valueList[i]);
|
||||
serieData.data.Add(valueList[0]);
|
||||
serieData.data.Add(valueList[i]);
|
||||
}
|
||||
m_Data.Add(serieData);
|
||||
}
|
||||
@@ -545,6 +565,31 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得指定维数的最大最小值
|
||||
/// </summary>
|
||||
/// <param name="dimension"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
public void GetMinMaxData(int dimension, out float minValue, out float maxValue, DataZoom dataZoom = null)
|
||||
{
|
||||
var dataList = GetDataList(dataZoom);
|
||||
float max = float.MinValue;
|
||||
float min = float.MaxValue;
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
var serieData = dataList[i];
|
||||
if (serieData.data.Count > dimension)
|
||||
{
|
||||
var value = serieData.data[dimension];
|
||||
if (value > max) max = value;
|
||||
if (value < min) min = value;
|
||||
}
|
||||
}
|
||||
maxValue = max;
|
||||
minValue = min;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据dataZoom更新数据列表缓存
|
||||
/// </summary>
|
||||
@@ -664,6 +709,42 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public Color GetAreaColor(ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
if (areaStyle.color != Color.clear)
|
||||
{
|
||||
var color = areaStyle.color;
|
||||
if (highlight) color *= color;
|
||||
color.a *= areaStyle.opactiy;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a *= areaStyle.opactiy;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public Color GetLineColor(ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
if (lineStyle.color != Color.clear)
|
||||
{
|
||||
var color = lineStyle.color;
|
||||
if (highlight) color *= color;
|
||||
color.a *= lineStyle.opactiy;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a *= lineStyle.opactiy;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从json中导入数据
|
||||
/// </summary>
|
||||
|
||||
@@ -558,58 +558,6 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得指定系列的最大值
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public float GetMaxValue(int index)
|
||||
{
|
||||
float max = int.MinValue;
|
||||
float min = int.MaxValue;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var showData = m_Series[i].yData;
|
||||
if (showData[index] > max)
|
||||
{
|
||||
max = Mathf.Ceil(showData[index]);
|
||||
}
|
||||
if (showData[index] < min)
|
||||
{
|
||||
min = Mathf.Ceil(showData[index]);
|
||||
}
|
||||
}
|
||||
if (max < 1 && max > -1) return max;
|
||||
if (max < 0 && min < 0) max = min;
|
||||
return ChartHelper.GetMaxDivisibleValue(max);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得指定系列的最小值
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public float GetMinValue(int index)
|
||||
{
|
||||
float max = int.MinValue;
|
||||
float min = int.MaxValue;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var showData = m_Series[i].yData;
|
||||
if (showData[index] > max)
|
||||
{
|
||||
max = Mathf.Ceil(showData[index]);
|
||||
}
|
||||
if (showData[index] < min)
|
||||
{
|
||||
min = Mathf.Ceil(showData[index]);
|
||||
}
|
||||
}
|
||||
if (min < 1 && min > -1) return min;
|
||||
if (min < 0 && max < 0) min = max;
|
||||
return ChartHelper.GetMinDivisibleValue(min);
|
||||
}
|
||||
|
||||
private HashSet<string> _setForStack = new HashSet<string>();
|
||||
/// <summary>
|
||||
/// 是否由数据堆叠
|
||||
@@ -729,21 +677,15 @@ namespace XCharts
|
||||
serieNameList.Clear();
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
if (serie.type == SerieType.Pie)
|
||||
if (!string.IsNullOrEmpty(serie.name) && !serieNameList.Contains(serie.name))
|
||||
{
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(data.name) && !serieNameList.Contains(data.name))
|
||||
{
|
||||
serieNameList.Add(data.name);
|
||||
}
|
||||
}
|
||||
serieNameList.Add(serie.name);
|
||||
}
|
||||
else
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(serie.name) && !serieNameList.Contains(serie.name))
|
||||
if (!string.IsNullOrEmpty(data.name) && !serieNameList.Contains(data.name))
|
||||
{
|
||||
serieNameList.Add(serie.name);
|
||||
serieNameList.Add(data.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
83
Scripts/UI/Internal/AreaStyle.cs
Normal file
83
Scripts/UI/Internal/AreaStyle.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/UI/Internal/AreaStyle.cs.meta
Normal file
11
Scripts/UI/Internal/AreaStyle.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 031cbc008c7d34cb0ad96257d0bfa6d9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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()
|
||||
|
||||
@@ -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>
|
||||
|
||||
55
Scripts/UI/Internal/LineStyle.cs
Normal file
55
Scripts/UI/Internal/LineStyle.cs
Normal 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; } }
|
||||
}
|
||||
}
|
||||
11
Scripts/UI/Internal/LineStyle.cs.meta
Normal file
11
Scripts/UI/Internal/LineStyle.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22d2d2622e9364e80a073f9c2e4cdd0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -31,30 +31,6 @@ namespace XCharts
|
||||
|
||||
public Pie pie { get { return m_Pie; } }
|
||||
|
||||
/// <summary>
|
||||
/// Where legend is activated.
|
||||
/// </summary>
|
||||
/// <param name="legendName">the name of legend</param>
|
||||
/// <returns></returns>
|
||||
public override bool IsActiveByLegend(string legendName)
|
||||
{
|
||||
foreach (var serie in m_Series.series)
|
||||
{
|
||||
foreach (var serieData in serie.data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(serieData.name))
|
||||
{
|
||||
if (string.IsNullOrEmpty(legendName)) return true;
|
||||
}
|
||||
else if (serieData.name.Equals(legendName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -152,7 +128,7 @@ namespace XCharts
|
||||
tempData.angleList.Add(0);
|
||||
continue;
|
||||
}
|
||||
float degree = serie.roseType == RoseType.Area ? (totalDegree / showdataCount) : (totalDegree * value / tempData.dataTotal);
|
||||
float degree = serie.roseType == RoseType.Area ? (totalDegree / showdataCount) : (totalDegree * value / tempData.dataTotal);
|
||||
float toDegree = startDegree + degree;
|
||||
|
||||
float outSideRadius = serie.roseType > 0 ?
|
||||
@@ -429,9 +405,9 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLegendButtonClick(int index, string legendName)
|
||||
protected override void OnLegendButtonClick(int index, string legendName, bool show)
|
||||
{
|
||||
bool active = CheckDataShow(legendName);
|
||||
bool active = CheckDataShow(legendName, show);
|
||||
var bgColor1 = active ? m_ThemeInfo.GetColor(index) : m_ThemeInfo.legendUnableColor;
|
||||
m_Legend.UpdateButtonColor(legendName, bgColor1);
|
||||
RefreshChart();
|
||||
@@ -440,52 +416,17 @@ namespace XCharts
|
||||
protected override void OnLegendButtonEnter(int index, string legendName)
|
||||
{
|
||||
m_IsEnterLegendButtom = true;
|
||||
CheckDataHighlighted(legendName);
|
||||
CheckDataHighlighted(legendName, true);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected override void OnLegendButtonExit(int index, string legendName)
|
||||
{
|
||||
m_IsEnterLegendButtom = false;
|
||||
CheckDataHighlighted(legendName);
|
||||
CheckDataHighlighted(legendName, false);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
private bool CheckDataShow(string legendName)
|
||||
{
|
||||
bool show = false;
|
||||
foreach (var serie in m_Series.series)
|
||||
{
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (legendName.Equals(data.name))
|
||||
{
|
||||
data.show = !data.show;
|
||||
data.highlighted = false;
|
||||
if (data.show) show = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return show;
|
||||
}
|
||||
|
||||
private bool CheckDataHighlighted(string legendName)
|
||||
{
|
||||
bool show = false;
|
||||
foreach (var serie in m_Series.series)
|
||||
{
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (legendName.Equals(data.name))
|
||||
{
|
||||
data.highlighted = !data.highlighted;
|
||||
if (data.highlighted) show = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return show;
|
||||
}
|
||||
|
||||
private void UpdatePieCenter(Serie serie)
|
||||
{
|
||||
if (serie.center.Length < 2) return;
|
||||
|
||||
@@ -13,16 +13,13 @@ namespace XCharts
|
||||
{
|
||||
private const string INDICATOR_TEXT = "indicator";
|
||||
|
||||
[SerializeField]
|
||||
private Radar m_Radar = Radar.defaultRadar;
|
||||
private Radar m_CheckRadar = Radar.defaultRadar;
|
||||
private float m_RadarCenterX = 0f;
|
||||
private float m_RadarCenterY = 0f;
|
||||
private float m_RadarRadius = 0;
|
||||
private List<Text> indicatorTextList = new List<Text>();
|
||||
private List<List<Vector3>> dataPosList = new List<List<Vector3>>();
|
||||
//[SerializeField] private Radar radar = Radar.defaultRadar;
|
||||
[SerializeField] private List<Radar> m_Radars = new List<Radar>();
|
||||
private List<Radar> m_CheckRadars = new List<Radar>();
|
||||
private bool m_IsEnterLegendButtom;
|
||||
|
||||
public Radar radar { get { return m_Radar; } }
|
||||
//public Radar radar { get { return radar; } }
|
||||
public List<Radar> radars { get { return m_Radars; } }
|
||||
|
||||
/// <summary>
|
||||
/// 移除所有数据,包含指示器数据。
|
||||
@@ -30,12 +27,38 @@ namespace XCharts
|
||||
public override void RemoveData()
|
||||
{
|
||||
base.RemoveData();
|
||||
m_Radar.indicatorList.Clear();
|
||||
foreach (var radar in m_Radars)
|
||||
{
|
||||
radar.indicatorList.Clear();
|
||||
}
|
||||
m_CheckRadars.Clear();
|
||||
}
|
||||
|
||||
protected override void OnLegendButtonClick(int index, string legendName, bool show)
|
||||
{
|
||||
bool active = CheckDataShow(legendName, show);
|
||||
var bgColor1 = active ? m_ThemeInfo.GetColor(index) : m_ThemeInfo.legendUnableColor;
|
||||
m_Legend.UpdateButtonColor(legendName, bgColor1);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected override void OnLegendButtonEnter(int index, string legendName)
|
||||
{
|
||||
m_IsEnterLegendButtom = true;
|
||||
CheckDataHighlighted(legendName, true);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected override void OnLegendButtonExit(int index, string legendName)
|
||||
{
|
||||
m_IsEnterLegendButtom = false;
|
||||
CheckDataHighlighted(legendName, false);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
UpdateRadarCenter();
|
||||
InitIndicator();
|
||||
}
|
||||
|
||||
@@ -50,198 +73,255 @@ namespace XCharts
|
||||
{
|
||||
base.Reset();
|
||||
RemoveData();
|
||||
m_Radar = Radar.defaultRadar;
|
||||
m_Radars.Add(Radar.defaultRadar);
|
||||
m_Title.text = "RadarChart";
|
||||
AddSerie("serie1", SerieType.Radar);
|
||||
var serie = AddSerie("serie1", SerieType.Radar);
|
||||
serie.symbol.type = SerieSymbolType.EmptyCircle;
|
||||
serie.symbol.size = 4;
|
||||
serie.symbol.selectedSize = 6;
|
||||
List<float> data = new List<float>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
AddData(0, Random.Range(20, 90));
|
||||
data.Add(Random.Range(20, 90));
|
||||
}
|
||||
AddData(0, data);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
private void InitIndicator()
|
||||
{
|
||||
indicatorTextList.Clear();
|
||||
ChartHelper.HideAllObject(transform, INDICATOR_TEXT);
|
||||
int indicatorNum = m_Radar.indicatorList.Count;
|
||||
float txtWid = 100;
|
||||
float txtHig = 20;
|
||||
for (int i = 0; i < indicatorNum; i++)
|
||||
for (int n = 0; n < m_Radars.Count; n++)
|
||||
{
|
||||
var pos = GetIndicatorPosition(i);
|
||||
TextAnchor anchor = TextAnchor.MiddleCenter;
|
||||
var diff = pos.x - m_RadarCenterX;
|
||||
if (diff < -1f)
|
||||
Radar radar = m_Radars[n];
|
||||
radar.UpdateRadarCenter(chartWidth, chartHeight);
|
||||
int indicatorNum = radar.indicatorList.Count;
|
||||
float txtWid = 100;
|
||||
float txtHig = 20;
|
||||
for (int i = 0; i < indicatorNum; i++)
|
||||
{
|
||||
pos = new Vector3(pos.x - 5, pos.y);
|
||||
anchor = TextAnchor.MiddleRight;
|
||||
var indicator = radar.indicatorList[i];
|
||||
var pos = radar.GetIndicatorPosition(i);
|
||||
TextAnchor anchor = TextAnchor.MiddleCenter;
|
||||
var diff = pos.x - radar.centerPos.x;
|
||||
if (diff < -1f)
|
||||
{
|
||||
pos = new Vector3(pos.x - 5, pos.y);
|
||||
anchor = TextAnchor.MiddleRight;
|
||||
}
|
||||
else if (diff > 1f)
|
||||
{
|
||||
anchor = TextAnchor.MiddleLeft;
|
||||
pos = new Vector3(pos.x + txtWid + 5, pos.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
anchor = TextAnchor.MiddleCenter;
|
||||
float y = pos.y > radar.centerPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
|
||||
pos = new Vector3(pos.x + txtWid / 2, y);
|
||||
}
|
||||
var textColor = indicator.color == Color.clear ? (Color)m_ThemeInfo.axisTextColor : indicator.color;
|
||||
Text txt = ChartHelper.AddTextObject(INDICATOR_TEXT + "_" + n + "_" + i, transform, m_ThemeInfo.font,
|
||||
textColor, anchor, Vector2.zero, Vector2.zero, new Vector2(1, 0.5f),
|
||||
new Vector2(txtWid, txtHig));
|
||||
txt.transform.localPosition = pos;
|
||||
txt.text = radar.indicatorList[i].name;
|
||||
txt.gameObject.SetActive(radar.indicator);
|
||||
}
|
||||
else if (diff > 1f)
|
||||
{
|
||||
anchor = TextAnchor.MiddleLeft;
|
||||
pos = new Vector3(pos.x + txtWid + 5, pos.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
anchor = TextAnchor.MiddleCenter;
|
||||
float y = pos.y > m_RadarCenterY ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
|
||||
pos = new Vector3(pos.x + txtWid / 2, y);
|
||||
}
|
||||
Text txt = ChartHelper.AddTextObject(INDICATOR_TEXT + i, transform, m_ThemeInfo.font,
|
||||
m_ThemeInfo.titleTextColor, anchor, Vector2.zero, Vector2.zero, new Vector2(1, 0.5f),
|
||||
new Vector2(txtWid, txtHig));
|
||||
txt.transform.localPosition = pos;
|
||||
txt.text = m_Radar.indicatorList[i].name;
|
||||
txt.gameObject.SetActive(m_Radar.indicator);
|
||||
indicatorTextList.Add(txt);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckRadarInfoChanged()
|
||||
{
|
||||
if (m_CheckRadar != m_Radar)
|
||||
if (!ChartHelper.IsValueEqualsList(m_CheckRadars, m_Radars))
|
||||
{
|
||||
m_CheckRadar.Copy(m_Radar);
|
||||
m_CheckRadars.Clear();
|
||||
foreach (var radar in m_Radars) m_CheckRadars.Add(radar.Clone());
|
||||
OnRadarChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRadarChanged()
|
||||
{
|
||||
UpdateRadarCenter();
|
||||
InitIndicator();
|
||||
m_Tooltip.UpdateToTop();
|
||||
}
|
||||
|
||||
private Vector3 GetIndicatorPosition(int i)
|
||||
{
|
||||
int indicatorNum = m_Radar.indicatorList.Count;
|
||||
var angle = 2 * Mathf.PI / indicatorNum * i;
|
||||
var x = m_RadarCenterX + m_Radar.radius * Mathf.Sin(angle);
|
||||
var y = m_RadarCenterY + m_Radar.radius * Mathf.Cos(angle);
|
||||
|
||||
return new Vector3(x, y);
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
UpdateRadarCenter();
|
||||
if (m_Radar.cricle)
|
||||
DrawCricleRadar(vh);
|
||||
else
|
||||
DrawRadar(vh);
|
||||
foreach (var radar in m_Radars)
|
||||
{
|
||||
radar.UpdateRadarCenter(chartWidth, chartHeight);
|
||||
if (radar.shape == Radar.Shape.Circle)
|
||||
{
|
||||
DrawCricleRadar(vh, radar);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawRadar(vh, radar);
|
||||
}
|
||||
}
|
||||
DrawData(vh);
|
||||
}
|
||||
|
||||
protected override void OnThemeChanged()
|
||||
{
|
||||
base.OnThemeChanged();
|
||||
m_Radar.backgroundColorList.Clear();
|
||||
switch (m_ThemeInfo.theme)
|
||||
foreach (var radar in m_Radars)
|
||||
{
|
||||
case Theme.Dark:
|
||||
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#6f6f6f"));
|
||||
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#606060"));
|
||||
break;
|
||||
case Theme.Default:
|
||||
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#f6f6f6"));
|
||||
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#e7e7e7"));
|
||||
break;
|
||||
case Theme.Light:
|
||||
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#f6f6f6"));
|
||||
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#e7e7e7"));
|
||||
break;
|
||||
radar.splitArea.color.Clear();
|
||||
switch (m_ThemeInfo.theme)
|
||||
{
|
||||
case Theme.Dark:
|
||||
radar.splitArea.color.Add(ThemeInfo.GetColor("#6f6f6f"));
|
||||
radar.splitArea.color.Add(ThemeInfo.GetColor("#606060"));
|
||||
break;
|
||||
case Theme.Default:
|
||||
radar.splitArea.color.Add(ThemeInfo.GetColor("#f6f6f6"));
|
||||
radar.splitArea.color.Add(ThemeInfo.GetColor("#e7e7e7"));
|
||||
break;
|
||||
case Theme.Light:
|
||||
radar.splitArea.color.Add(ThemeInfo.GetColor("#f6f6f6"));
|
||||
radar.splitArea.color.Add(ThemeInfo.GetColor("#e7e7e7"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
InitIndicator();
|
||||
}
|
||||
|
||||
HashSet<string> serieNameSet = new HashSet<string>();
|
||||
Dictionary<string, int> serieNameSet = new Dictionary<string, int>();
|
||||
private void DrawData(VertexHelper vh)
|
||||
{
|
||||
int indicatorNum = m_Radar.indicatorList.Count;
|
||||
var angle = 2 * Mathf.PI / indicatorNum;
|
||||
var p = new Vector3(m_RadarCenterX, m_RadarCenterY);
|
||||
Vector3 startPoint = Vector3.zero;
|
||||
Vector3 toPoint = Vector3.zero;
|
||||
Vector3 firstPoint = Vector3.zero;
|
||||
dataPosList.Clear();
|
||||
dataPosList.Capacity = m_Series.Count;
|
||||
|
||||
serieNameSet.Clear();
|
||||
int serieNameCount = -1;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.series[i];
|
||||
if (string.IsNullOrEmpty(serie.name)) serieNameCount++;
|
||||
else if (!serieNameSet.Contains(serie.name))
|
||||
{
|
||||
serieNameSet.Add(serie.name);
|
||||
serieNameCount++;
|
||||
}
|
||||
var radar = m_Radars[serie.radarIndex];
|
||||
int indicatorNum = radar.indicatorList.Count;
|
||||
var angle = 2 * Mathf.PI / indicatorNum;
|
||||
Vector3 p = radar.centerPos;
|
||||
if (!IsActive(i))
|
||||
{
|
||||
dataPosList.Add(new List<Vector3>());
|
||||
continue;
|
||||
}
|
||||
var dataList = m_Series.series[i].yData;
|
||||
var color = m_ThemeInfo.GetColor(i);
|
||||
var areaColor = color;
|
||||
areaColor.a = (byte)m_Radar.areaAlpha;
|
||||
|
||||
List<Vector3> pointList = new List<Vector3>(dataList.Count);
|
||||
dataPosList.Add(pointList);
|
||||
for (int j = 0; j < dataList.Count; j++)
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
var max = m_Radar.GetIndicatorMax(j) > 0 ?
|
||||
m_Radar.GetIndicatorMax(j) :
|
||||
GetMaxValue(j);
|
||||
var radius = max < 0 ? m_Radar.radius - m_Radar.radius * dataList[j] / max
|
||||
: m_Radar.radius * dataList[j] / max;
|
||||
var currAngle = j * angle;
|
||||
if (j == 0)
|
||||
var serieData = serie.data[j];
|
||||
int key = i * 100 + j;
|
||||
if (!radar.dataPosList.ContainsKey(key))
|
||||
{
|
||||
startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
||||
p.y + radius * Mathf.Cos(currAngle));
|
||||
firstPoint = startPoint;
|
||||
radar.dataPosList.Add(i * 100 + j, new List<Vector3>(serieData.data.Count));
|
||||
}
|
||||
else
|
||||
{
|
||||
toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
||||
p.y + radius * Mathf.Cos(currAngle));
|
||||
if (m_Radar.area)
|
||||
{
|
||||
ChartHelper.DrawTriangle(vh, p, startPoint, toPoint, areaColor);
|
||||
}
|
||||
ChartHelper.DrawLine(vh, startPoint, toPoint, m_Radar.lineTickness, color);
|
||||
startPoint = toPoint;
|
||||
radar.dataPosList[key].Clear();
|
||||
}
|
||||
string dataName = serieData.name;
|
||||
int serieIndex = 0;
|
||||
if (string.IsNullOrEmpty(dataName))
|
||||
{
|
||||
serieNameCount++;
|
||||
serieIndex = serieNameCount;
|
||||
}
|
||||
else if (!serieNameSet.ContainsKey(dataName))
|
||||
{
|
||||
serieNameSet.Add(dataName, serieNameCount);
|
||||
serieNameCount++;
|
||||
serieIndex = serieNameCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
serieIndex = serieNameSet[dataName];
|
||||
}
|
||||
if (!serieData.show)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var isHighlight = serie.highlighted || serieData.highlighted ||
|
||||
(m_Tooltip.show && m_Tooltip.dataIndex[0] == i && m_Tooltip.dataIndex[1] == j);
|
||||
var areaColor = serie.GetAreaColor(m_ThemeInfo, serieIndex, isHighlight);
|
||||
var lineColor = serie.GetLineColor(m_ThemeInfo, serieIndex, isHighlight);
|
||||
int dataCount = radar.indicatorList.Count;
|
||||
List<Vector3> pointList = radar.dataPosList[key];
|
||||
for (int n = 0; n < dataCount; n++)
|
||||
{
|
||||
if (n >= serieData.data.Count) break;
|
||||
float min = radar.GetIndicatorMin(n);
|
||||
float max = radar.GetIndicatorMax(n);
|
||||
float value = serieData.data[n];
|
||||
if (max == 0)
|
||||
{
|
||||
serie.GetMinMaxData(n, out min, out max);
|
||||
min = radar.GetIndicatorMin(n);
|
||||
}
|
||||
var radius = max < 0 ? radar.actualRadius - radar.actualRadius * value / max
|
||||
: radar.actualRadius * value / max;
|
||||
var currAngle = n * angle;
|
||||
if (n == 0)
|
||||
{
|
||||
startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
||||
p.y + radius * Mathf.Cos(currAngle));
|
||||
firstPoint = startPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
|
||||
p.y + radius * Mathf.Cos(currAngle));
|
||||
if (serie.areaStyle.show)
|
||||
{
|
||||
ChartHelper.DrawTriangle(vh, p, startPoint, toPoint, areaColor);
|
||||
}
|
||||
if (serie.lineStyle.show)
|
||||
{
|
||||
ChartHelper.DrawLine(vh, startPoint, toPoint, serie.lineStyle.width, lineColor);
|
||||
}
|
||||
startPoint = toPoint;
|
||||
}
|
||||
pointList.Add(startPoint);
|
||||
}
|
||||
if (serie.areaStyle.show)
|
||||
{
|
||||
ChartHelper.DrawTriangle(vh, p, startPoint, firstPoint, areaColor);
|
||||
}
|
||||
if (serie.lineStyle.show)
|
||||
{
|
||||
ChartHelper.DrawLine(vh, startPoint, firstPoint, serie.lineStyle.width, lineColor);
|
||||
}
|
||||
if (serie.symbol.type != SerieSymbolType.None)
|
||||
{
|
||||
var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size);
|
||||
float symbolRadius = symbolSize - serie.lineStyle.width * 2;
|
||||
foreach (var point in pointList)
|
||||
{
|
||||
DrawSymbol(vh, serie.symbol.type, symbolSize, serie.lineStyle.width, point, lineColor);
|
||||
}
|
||||
}
|
||||
pointList.Add(startPoint);
|
||||
}
|
||||
if (m_Radar.area) ChartHelper.DrawTriangle(vh, p, startPoint, firstPoint, areaColor);
|
||||
ChartHelper.DrawLine(vh, startPoint, firstPoint, m_Radar.lineTickness, color);
|
||||
foreach (var point in pointList)
|
||||
{
|
||||
float radius = m_Radar.linePointSize - m_Radar.lineTickness * 2;
|
||||
|
||||
ChartHelper.DrawCricle(vh, point, radius, Color.white);
|
||||
ChartHelper.DrawDoughnut(vh, point, radius, m_Radar.linePointSize, 0, 360, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawRadar(VertexHelper vh)
|
||||
private void DrawRadar(VertexHelper vh, Radar radar)
|
||||
{
|
||||
float insideRadius = 0, outsideRadius = 0;
|
||||
float block = m_Radar.radius / m_Radar.splitNumber;
|
||||
int indicatorNum = m_Radar.indicatorList.Count;
|
||||
Vector3 p1, p2, p3, p4;
|
||||
Vector3 p = new Vector3(m_RadarCenterX, m_RadarCenterY);
|
||||
float angle = 2 * Mathf.PI / indicatorNum;
|
||||
for (int i = 0; i < m_Radar.splitNumber; i++)
|
||||
if (!radar.lineStyle.show && !radar.splitArea.show)
|
||||
{
|
||||
Color color = m_Radar.backgroundColorList[i % m_Radar.backgroundColorList.Count];
|
||||
return;
|
||||
}
|
||||
float insideRadius = 0, outsideRadius = 0;
|
||||
float block = radar.actualRadius / radar.splitNumber;
|
||||
int indicatorNum = radar.indicatorList.Count;
|
||||
Vector3 p1, p2, p3, p4;
|
||||
Vector3 p = radar.centerPos;
|
||||
float angle = 2 * Mathf.PI / indicatorNum;
|
||||
var lineColor = GetLineColor(radar);
|
||||
for (int i = 0; i < radar.splitNumber; i++)
|
||||
{
|
||||
Color color = radar.splitArea.color[i % radar.splitArea.color.Count];
|
||||
outsideRadius = insideRadius + block;
|
||||
p1 = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0));
|
||||
p2 = new Vector3(p.x + outsideRadius * Mathf.Sin(0), p.y + outsideRadius * Mathf.Cos(0));
|
||||
@@ -252,9 +332,14 @@ namespace XCharts
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle),
|
||||
p.y + insideRadius * Mathf.Cos(currAngle));
|
||||
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
ChartHelper.DrawLine(vh, p2, p3, m_Radar.lineTickness, m_Radar.lineColor);
|
||||
if (radar.splitArea.show)
|
||||
{
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
}
|
||||
if (radar.lineStyle.show)
|
||||
{
|
||||
ChartHelper.DrawLine(vh, p2, p3, radar.lineStyle.width, lineColor);
|
||||
}
|
||||
p1 = p4;
|
||||
p2 = p3;
|
||||
}
|
||||
@@ -265,24 +350,38 @@ namespace XCharts
|
||||
float currAngle = j * angle;
|
||||
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
ChartHelper.DrawLine(vh, p, p3, m_Radar.lineTickness / 2, m_Radar.lineColor);
|
||||
if (radar.lineStyle.show)
|
||||
{
|
||||
ChartHelper.DrawLine(vh, p, p3, radar.lineStyle.width / 2, lineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCricleRadar(VertexHelper vh)
|
||||
private void DrawCricleRadar(VertexHelper vh, Radar radar)
|
||||
{
|
||||
if (!radar.lineStyle.show && !radar.splitArea.show)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float insideRadius = 0, outsideRadius = 0;
|
||||
float block = m_Radar.radius / m_Radar.splitNumber;
|
||||
int indicatorNum = m_Radar.indicatorList.Count;
|
||||
Vector3 p = new Vector3(m_RadarCenterX, m_RadarCenterY);
|
||||
float block = radar.actualRadius / radar.splitNumber;
|
||||
int indicatorNum = radar.indicatorList.Count;
|
||||
Vector3 p = radar.centerPos;
|
||||
Vector3 p1;
|
||||
float angle = 2 * Mathf.PI / indicatorNum;
|
||||
for (int i = 0; i < m_Radar.splitNumber; i++)
|
||||
var lineColor = GetLineColor(radar);
|
||||
for (int i = 0; i < radar.splitNumber; i++)
|
||||
{
|
||||
Color color = m_Radar.backgroundColorList[i % m_Radar.backgroundColorList.Count];
|
||||
Color color = radar.splitArea.color[i % radar.splitArea.color.Count];
|
||||
outsideRadius = insideRadius + block;
|
||||
ChartHelper.DrawDoughnut(vh, p, insideRadius, outsideRadius, 0, 360, color);
|
||||
ChartHelper.DrawCicleNotFill(vh, p, outsideRadius, m_Radar.lineTickness, m_Radar.lineColor);
|
||||
if (radar.splitArea.show)
|
||||
{
|
||||
ChartHelper.DrawDoughnut(vh, p, insideRadius, outsideRadius, 0, 360, color);
|
||||
}
|
||||
if (radar.lineStyle.show)
|
||||
{
|
||||
ChartHelper.DrawCicleNotFill(vh, p, outsideRadius, radar.lineStyle.width, lineColor);
|
||||
}
|
||||
insideRadius = outsideRadius;
|
||||
}
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
@@ -290,76 +389,99 @@ namespace XCharts
|
||||
float currAngle = j * angle;
|
||||
p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
ChartHelper.DrawLine(vh, p, p1, m_Radar.lineTickness / 2, m_Radar.lineColor);
|
||||
if (radar.lineStyle.show)
|
||||
{
|
||||
ChartHelper.DrawLine(vh, p, p1, radar.lineStyle.width / 2, lineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRadarCenter()
|
||||
private Color GetLineColor(Radar radar)
|
||||
{
|
||||
float diffX = chartWidth - m_Radar.left - m_Radar.right;
|
||||
float diffY = chartHeight - m_Radar.top - m_Radar.bottom;
|
||||
float diff = Mathf.Min(diffX, diffY);
|
||||
if (m_Radar.radius <= 0)
|
||||
if (radar.lineStyle.color != Color.clear)
|
||||
{
|
||||
m_RadarRadius = diff / 3 * 2;
|
||||
m_RadarCenterX = m_Radar.left + m_RadarRadius;
|
||||
m_RadarCenterY = m_Radar.bottom + m_RadarRadius;
|
||||
var color = radar.lineStyle.color;
|
||||
color.a *= radar.lineStyle.opactiy;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_RadarRadius = m_Radar.radius;
|
||||
m_RadarCenterX = chartWidth / 2;
|
||||
m_RadarCenterY = chartHeight / 2;
|
||||
if (m_Radar.left > 0) m_RadarCenterX = m_Radar.left + m_RadarRadius;
|
||||
if (m_Radar.right > 0) m_RadarCenterX = chartWidth - m_Radar.right - m_RadarRadius;
|
||||
if (m_Radar.top > 0) m_RadarCenterY = chartHeight - m_Radar.top - m_RadarRadius;
|
||||
if (m_Radar.bottom > 0) m_RadarCenterY = m_Radar.bottom + m_RadarRadius;
|
||||
var color = (Color)m_ThemeInfo.axisLineColor;
|
||||
color.a *= radar.lineStyle.opactiy;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void CheckTootipArea(Vector2 local)
|
||||
{
|
||||
if (dataPosList.Count <= 0) return;
|
||||
m_Tooltip.dataIndex[0] = -1;
|
||||
if (m_IsEnterLegendButtom) return;
|
||||
|
||||
bool highlight = false;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (!IsActive(i)) continue;
|
||||
for (int j = 0; j < dataPosList[i].Count; j++)
|
||||
var serie = m_Series.GetSerie(i);
|
||||
var radar = m_Radars[serie.radarIndex];
|
||||
var dist = Vector2.Distance(radar.centerPos, local);
|
||||
if (dist > radar.actualRadius + serie.symbol.size)
|
||||
{
|
||||
if (Vector3.Distance(local, dataPosList[i][j]) <= m_Radar.linePointSize * 1.2f)
|
||||
continue;
|
||||
}
|
||||
for (int n = 0; n < serie.data.Count; n++)
|
||||
{
|
||||
var posKey = i * 100 + n;
|
||||
if (radar.dataPosList.ContainsKey(posKey))
|
||||
{
|
||||
m_Tooltip.dataIndex[0] = i;
|
||||
break;
|
||||
var posList = radar.dataPosList[posKey];
|
||||
foreach (var pos in posList)
|
||||
{
|
||||
if (Vector2.Distance(pos, local) <= serie.symbol.size * 1.2f)
|
||||
{
|
||||
m_Tooltip.dataIndex[0] = i;
|
||||
m_Tooltip.dataIndex[1] = n;
|
||||
highlight = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_Tooltip.dataIndex[0] >= 0)
|
||||
|
||||
if (!highlight)
|
||||
{
|
||||
if (m_Tooltip.IsActive())
|
||||
{
|
||||
m_Tooltip.SetActive(false);
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
RefreshChart();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Tooltip.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RefreshTooltip()
|
||||
{
|
||||
base.RefreshTooltip();
|
||||
int index = m_Tooltip.dataIndex[0];
|
||||
if (index < 0)
|
||||
int serieIndex = m_Tooltip.dataIndex[0];
|
||||
if (serieIndex < 0)
|
||||
{
|
||||
m_Tooltip.SetActive(false);
|
||||
return;
|
||||
}
|
||||
m_Tooltip.SetActive(true);
|
||||
StringBuilder sb = new StringBuilder(m_Legend.data[index]);
|
||||
for (int i = 0; i < m_Radar.indicatorList.Count; i++)
|
||||
var serie = m_Series.GetSerie(serieIndex);
|
||||
var radar = m_Radars[serie.radarIndex];
|
||||
var serieData = serie.GetSerieData(m_Tooltip.dataIndex[1]);
|
||||
StringBuilder sb = new StringBuilder(serieData.name);
|
||||
for (int i = 0; i < radar.indicatorList.Count; i++)
|
||||
{
|
||||
string key = m_Radar.indicatorList[i].name;
|
||||
float value = m_Series.series[index].yData[i];
|
||||
string key = radar.indicatorList[i].name;
|
||||
float value = serieData.GetData(i);
|
||||
sb.Append("\n");
|
||||
sb.AppendFormat("{0}: {1}", key, value);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace XCharts
|
||||
{
|
||||
public static class ChartHelper
|
||||
{
|
||||
public static float CRICLE_SMOOTHNESS = 2.5f;
|
||||
public static float CRICLE_SMOOTHNESS = 2f;
|
||||
private static UIVertex[] vertex = new UIVertex[4];
|
||||
|
||||
public static void HideAllObject(GameObject obj, string match = null)
|
||||
|
||||
Reference in New Issue
Block a user