mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 15:00:08 +00:00
重构LineChart和BarChart,移除Line和Bar组件,参数统一放到Serie中配置。
This commit is contained in:
@@ -10,19 +10,19 @@ namespace XCharts
|
||||
[DisallowMultipleComponent]
|
||||
public class BarChart : CoordinateChart
|
||||
{
|
||||
[SerializeField] private Bar m_Bar = Bar.defaultBar;
|
||||
|
||||
public Bar bar { get { return m_Bar; } }
|
||||
private float m_BarLastOffset = 0;
|
||||
private HashSet<string> m_SerieNameSet = new HashSet<string>();
|
||||
private Dictionary<int, List<Serie>> m_StackSeries = new Dictionary<int, List<Serie>>();
|
||||
private List<float> m_SeriesCurrHig = new List<float>();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
m_Bar = Bar.defaultBar;
|
||||
m_Title.text = "BarChart";
|
||||
m_Tooltip.type = Tooltip.Type.Shadow;
|
||||
RemoveData();
|
||||
AddSerie("serie1", SerieType.Line);
|
||||
AddSerie("serie1", SerieType.Bar);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
AddXAxisData("x" + (i + 1));
|
||||
@@ -32,17 +32,21 @@ namespace XCharts
|
||||
#endif
|
||||
|
||||
private void DrawYBarSerie(VertexHelper vh, int serieIndex, int stackCount,
|
||||
Serie serie, Color color, ref List<float> seriesHig)
|
||||
Serie serie, int colorIndex, ref List<float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.name)) return;
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
|
||||
float barWid = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
|
||||
float offset = m_Bar.inSameBar ?
|
||||
(scaleWid - barWid - m_Bar.space * (stackCount - 1)) / 2 :
|
||||
(scaleWid - barWid * stackCount - m_Bar.space * (stackCount - 1)) / 2;
|
||||
|
||||
float categoryWidth = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
|
||||
float barGap = GetBarGap();
|
||||
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
float offset = (categoryWidth - totalBarWidth) / 2;
|
||||
float barGapWidth = barWidth + barWidth * barGap;
|
||||
float space = serie.barGap == -1 ? offset : offset + m_BarLastOffset;
|
||||
|
||||
var showData = serie.GetDataList(m_DataZoom);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
|
||||
@@ -62,46 +66,50 @@ namespace XCharts
|
||||
}
|
||||
float value = showData[i].data[1];
|
||||
float pX = seriesHig[i] + coordinateX + xAxis.zeroXOffset + yAxis.axisLine.width;
|
||||
float pY = coordinateY + +i * scaleWid;
|
||||
if (!yAxis.boundaryGap) pY -= scaleWid / 2;
|
||||
float pY = coordinateY + +i * categoryWidth;
|
||||
if (!yAxis.boundaryGap) pY -= categoryWidth / 2;
|
||||
float barHig = (xAxis.minValue > 0 ? value - xAxis.minValue : value)
|
||||
/ (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
||||
float space = m_Bar.inSameBar ? offset :
|
||||
offset + serieIndex * (barWid + m_Bar.space);
|
||||
seriesHig[i] += barHig;
|
||||
Vector3 p1 = new Vector3(pX, pY + space + barWid);
|
||||
Vector3 p2 = new Vector3(pX + barHig, pY + space + barWid);
|
||||
Vector3 p1 = new Vector3(pX, pY + space + barWidth);
|
||||
Vector3 p2 = new Vector3(pX + barHig, pY + space + barWidth);
|
||||
Vector3 p3 = new Vector3(pX + barHig, pY + space);
|
||||
Vector3 p4 = new Vector3(pX, pY + space);
|
||||
if ((m_Tooltip.show && m_Tooltip.IsSelected(i))
|
||||
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|
||||
|| serie.data[i].highlighted
|
||||
|| serie.highlighted)
|
||||
{
|
||||
color *= 1.05f;
|
||||
}
|
||||
|| serie.highlighted;
|
||||
if (serie.show)
|
||||
{
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
|
||||
Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, areaColor, areaToColor);
|
||||
}
|
||||
}
|
||||
if (!m_Series.IsStack(serie.stack, SerieType.Bar))
|
||||
{
|
||||
m_BarLastOffset += barGapWidth;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawXBarSerie(VertexHelper vh, int serieIndex, int stackCount,
|
||||
Serie serie, Color color, ref List<float> seriesHig)
|
||||
Serie serie, int colorIndex, ref List<float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.name)) return;
|
||||
var showData = serie.GetDataList(m_DataZoom);
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
float scaleWid = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
|
||||
float barWid = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
|
||||
float offset = m_Bar.inSameBar ?
|
||||
(scaleWid - barWid - m_Bar.space * (stackCount - 1)) / 2 :
|
||||
(scaleWid - barWid * stackCount - m_Bar.space * (stackCount - 1)) / 2;
|
||||
float categoryWidth = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
|
||||
float barGap = GetBarGap();
|
||||
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
float offset = (categoryWidth - totalBarWidth) / 2;
|
||||
float barGapWidth = barWidth + barWidth * barGap;
|
||||
float space = serie.barGap == -1 ? offset : offset + m_BarLastOffset;
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
|
||||
: showData.Count;
|
||||
|
||||
if (seriesHig.Count < minShowDataNumber)
|
||||
{
|
||||
for (int i = 0; i < minShowDataNumber; i++)
|
||||
@@ -116,63 +124,130 @@ namespace XCharts
|
||||
seriesHig.Add(0);
|
||||
}
|
||||
float value = showData[i].data[1];
|
||||
float pX = coordinateX + i * scaleWid;
|
||||
float pX = coordinateX + i * categoryWidth;
|
||||
float zeroY = coordinateY + yAxis.zeroYOffset;
|
||||
if (!xAxis.boundaryGap) pX -= scaleWid / 2;
|
||||
if (!xAxis.boundaryGap) pX -= categoryWidth / 2;
|
||||
float pY = seriesHig[i] + zeroY + xAxis.axisLine.width;
|
||||
float barHig = (yAxis.minValue > 0 ? value - yAxis.minValue : value)
|
||||
/ (yAxis.maxValue - yAxis.minValue) * coordinateHig;
|
||||
seriesHig[i] += barHig;
|
||||
float space = m_Bar.inSameBar ? offset :
|
||||
offset + serieIndex * (barWid + m_Bar.space);
|
||||
|
||||
Vector3 p1 = new Vector3(pX + space, pY);
|
||||
Vector3 p2 = new Vector3(pX + space, pY + barHig);
|
||||
Vector3 p3 = new Vector3(pX + space + barWid, pY + barHig);
|
||||
Vector3 p4 = new Vector3(pX + space + barWid, pY);
|
||||
if ((m_Tooltip.show && m_Tooltip.IsSelected(i))
|
||||
Vector3 p3 = new Vector3(pX + space + barWidth, pY + barHig);
|
||||
Vector3 p4 = new Vector3(pX + space + barWidth, pY);
|
||||
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|
||||
|| serie.data[i].highlighted
|
||||
|| serie.highlighted)
|
||||
{
|
||||
color *= 1.05f;
|
||||
}
|
||||
|| serie.highlighted;
|
||||
|
||||
if (serie.show)
|
||||
{
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
|
||||
Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
|
||||
ChartHelper.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor);
|
||||
}
|
||||
}
|
||||
if (!m_Series.IsStack(serie.stack, SerieType.Bar))
|
||||
{
|
||||
m_BarLastOffset += barGapWidth;
|
||||
}
|
||||
}
|
||||
|
||||
private float GetBarGap()
|
||||
{
|
||||
float gap = 0.3f;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.series[i];
|
||||
if (serie.type == SerieType.Bar)
|
||||
{
|
||||
if (serie.barGap != 0)
|
||||
{
|
||||
gap = serie.barGap;
|
||||
}
|
||||
}
|
||||
}
|
||||
return gap;
|
||||
}
|
||||
|
||||
|
||||
private HashSet<string> barStackSet = new HashSet<string>();
|
||||
private float GetBarTotalWidth(float categoryWidth, float gap)
|
||||
{
|
||||
float total = 0;
|
||||
float lastGap = 0;
|
||||
barStackSet.Clear();
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.series[i];
|
||||
if (serie.type == SerieType.Bar && serie.show)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
if (barStackSet.Contains(serie.stack)) continue;
|
||||
barStackSet.Add(serie.stack);
|
||||
}
|
||||
var width = GetStackBarWidth(categoryWidth, serie);
|
||||
if (gap == -1)
|
||||
{
|
||||
if (width > total) total = width;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastGap = width * gap;
|
||||
total += width;
|
||||
total += lastGap;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (total > 0 && gap != -1) total -= lastGap;
|
||||
return total;
|
||||
}
|
||||
|
||||
private float GetStackBarWidth(float categoryWidth, Serie now)
|
||||
{
|
||||
if (string.IsNullOrEmpty(now.stack)) return now.GetBarWidth(categoryWidth);
|
||||
float barWidth = 0;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.series[i];
|
||||
if (serie.type == SerieType.Bar && serie.show && now.stack.Equals(serie.stack))
|
||||
{
|
||||
if (serie.barWidth > barWidth) barWidth = serie.barWidth;
|
||||
}
|
||||
}
|
||||
if (barWidth > 1) return barWidth;
|
||||
else return barWidth * categoryWidth;
|
||||
}
|
||||
|
||||
private HashSet<string> serieNameSet = new HashSet<string>();
|
||||
private Dictionary<int, List<Serie>> stackSeries = new Dictionary<int, List<Serie>>();
|
||||
private List<float> seriesCurrHig = new List<float>();
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
bool yCategory = m_YAxises[0].IsCategory() || m_YAxises[1].IsCategory();
|
||||
m_Series.GetStackSeries(ref stackSeries);
|
||||
int seriesCount = stackSeries.Count;
|
||||
m_Series.GetStackSeries(ref m_StackSeries);
|
||||
int seriesCount = m_StackSeries.Count;
|
||||
int serieNameCount = -1;
|
||||
serieNameSet.Clear();
|
||||
m_SerieNameSet.Clear();
|
||||
m_BarLastOffset = 0;
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
var serieList = stackSeries[j];
|
||||
seriesCurrHig.Clear();
|
||||
if (seriesCurrHig.Capacity != serieList[0].dataCount)
|
||||
{
|
||||
seriesCurrHig.Capacity = serieList[0].dataCount;
|
||||
}
|
||||
var serieList = m_StackSeries[j];
|
||||
m_SeriesCurrHig.Clear();
|
||||
// if (m_SeriesCurrHig.Capacity != serieList[0].dataCount)
|
||||
// {
|
||||
// m_SeriesCurrHig.Capacity = serieList[0].dataCount;
|
||||
// }
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
Serie serie = serieList[n];
|
||||
if (string.IsNullOrEmpty(serie.name)) serieNameCount++;
|
||||
else if (!serieNameSet.Contains(serie.name))
|
||||
else if (!m_SerieNameSet.Contains(serie.name))
|
||||
{
|
||||
serieNameSet.Add(serie.name);
|
||||
m_SerieNameSet.Add(serie.name);
|
||||
serieNameCount++;
|
||||
}
|
||||
Color color = m_ThemeInfo.GetColor(serieNameCount);
|
||||
if (yCategory) DrawYBarSerie(vh, j, seriesCount, serie, color, ref seriesCurrHig);
|
||||
else DrawXBarSerie(vh, j, seriesCount, serie, color, ref seriesCurrHig);
|
||||
if (yCategory) DrawYBarSerie(vh, j, seriesCount, serie, serieNameCount, ref m_SeriesCurrHig);
|
||||
else DrawXBarSerie(vh, j, seriesCount, serie, serieNameCount, ref m_SeriesCurrHig);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -631,7 +631,7 @@ namespace XCharts
|
||||
{
|
||||
public XAxis Clone()
|
||||
{
|
||||
var axis = new XAxis();
|
||||
var axis = XAxisPool.Get();
|
||||
axis.show = show;
|
||||
axis.type = type;
|
||||
axis.min = min;
|
||||
@@ -644,7 +644,7 @@ namespace XCharts
|
||||
axis.axisName.Copy(axisName);
|
||||
axis.axisLabel.Copy(axisLabel);
|
||||
axis.data.Clear();
|
||||
axis.data.Capacity = data.Count;
|
||||
if (axis.data.Capacity < data.Count) axis.data.Capacity = data.Count;
|
||||
foreach (var d in data) axis.data.Add(d);
|
||||
return axis;
|
||||
}
|
||||
@@ -683,7 +683,7 @@ namespace XCharts
|
||||
{
|
||||
public YAxis Clone()
|
||||
{
|
||||
var axis = new YAxis();
|
||||
var axis = YAxisPool.Get();
|
||||
axis.show = show;
|
||||
axis.type = type;
|
||||
axis.min = min;
|
||||
@@ -696,7 +696,7 @@ namespace XCharts
|
||||
axis.axisName.Copy(axisName);
|
||||
axis.axisLabel.Copy(axisLabel);
|
||||
axis.data.Clear();
|
||||
axis.data.Capacity = data.Count;
|
||||
if (axis.data.Capacity < data.Count) axis.data.Capacity = data.Count;
|
||||
foreach (var d in data) axis.data.Add(d);
|
||||
return axis;
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// bar component.global setting for bar chart.
|
||||
/// 柱状图的全局配置组件。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class Bar
|
||||
{
|
||||
[SerializeField] private bool m_InSameBar = false;
|
||||
[SerializeField] private float m_BarWidth = 0.7f;
|
||||
[SerializeField] private float m_Space = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to draw all bar in the same bar,but not stacked.
|
||||
/// 非堆叠同柱。多序列绘制在同一bar上,但不堆叠,而是覆盖绘制。
|
||||
/// </summary>
|
||||
public bool inSameBar { get { return m_InSameBar; } set { m_InSameBar = value; } }
|
||||
/// <summary>
|
||||
/// the width of bar.
|
||||
/// 状态的宽度。
|
||||
/// </summary>
|
||||
public float barWidth { get { return m_BarWidth; } set { m_BarWidth = value; } }
|
||||
/// <summary>
|
||||
/// the space of bars.
|
||||
/// 多柱状间的间距。
|
||||
/// </summary>
|
||||
public float space { get { return m_Space; } set { m_Space = value; } }
|
||||
|
||||
public static Bar defaultBar
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Bar()
|
||||
{
|
||||
m_InSameBar = false,
|
||||
m_BarWidth = 0.6f,
|
||||
m_Space = 10
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// The global settings of line chart.
|
||||
/// LineChart的全局配置。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class Line
|
||||
{
|
||||
/// <summary>
|
||||
/// the type fo step line.
|
||||
/// 阶梯线图类型。
|
||||
/// </summary>
|
||||
public enum StepType
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前点。
|
||||
/// </summary>
|
||||
Start,
|
||||
/// <summary>
|
||||
/// 当前点和下一个点的中间。
|
||||
/// </summary>
|
||||
Middle,
|
||||
/// <summary>
|
||||
/// 下一个拐点
|
||||
/// </summary>
|
||||
End
|
||||
}
|
||||
[SerializeField] private float m_Tickness;
|
||||
[SerializeField] private bool m_Smooth;
|
||||
[SerializeField] [Range(1f, 10f)] private float m_SmoothStyle;
|
||||
[SerializeField] private bool m_Area;
|
||||
[SerializeField] private bool m_Step;
|
||||
[SerializeField] private StepType m_StepType;
|
||||
|
||||
/// <summary>
|
||||
/// the tickness of lines.
|
||||
/// 线条粗细。
|
||||
/// </summary>
|
||||
public float tickness { get { return m_Tickness; } set { m_Tickness = value; } }
|
||||
/// <summary>
|
||||
/// smoothness.
|
||||
/// 平滑风格。
|
||||
/// </summary>
|
||||
public float smoothStyle { get { return m_SmoothStyle; } set { m_SmoothStyle = value; } }
|
||||
/// <summary>
|
||||
/// Whether the lines are displayed smoothly.
|
||||
/// 是否平滑显示。
|
||||
/// </summary>
|
||||
public bool smooth { get { return m_Smooth; } set { m_Smooth = value; } }
|
||||
/// <summary>
|
||||
/// Whether to show area.
|
||||
/// 是否显示区域填充颜色。
|
||||
/// </summary>
|
||||
public bool area { get { return m_Area; } set { m_Area = value; } }
|
||||
/// <summary>
|
||||
/// Whether to show as a step line.
|
||||
/// 是否是阶梯线图。
|
||||
/// </summary>
|
||||
public bool step { get { return m_Step; } set { m_Step = value; } }
|
||||
/// <summary>
|
||||
/// the type of step line.
|
||||
/// 阶梯线图类型。
|
||||
/// </summary>
|
||||
public StepType stepTpe { get { return m_StepType; } set { m_StepType = value; } }
|
||||
|
||||
public static Line defaultLine
|
||||
{
|
||||
get
|
||||
{
|
||||
var line = new Line
|
||||
{
|
||||
m_Tickness = 0.8f,
|
||||
m_Smooth = false,
|
||||
m_SmoothStyle = 2f,
|
||||
m_Area = false,
|
||||
m_Step = false,
|
||||
m_StepType = StepType.Middle
|
||||
};
|
||||
return line;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,39 @@ namespace XCharts
|
||||
Area
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the type of line chart.
|
||||
/// 折线图样式类型
|
||||
/// </summary>
|
||||
public enum LineType
|
||||
{
|
||||
/// <summary>
|
||||
/// the normal line chart,
|
||||
/// 所有扇区圆心角相同,仅通过半径展现数据大小。
|
||||
/// </summary>
|
||||
Normal,
|
||||
/// <summary>
|
||||
/// the normal line chart,
|
||||
/// 平滑曲线。
|
||||
/// </summary>
|
||||
Smooth,
|
||||
/// <summary>
|
||||
/// step line.
|
||||
/// 阶梯线图:当前点。
|
||||
/// </summary>
|
||||
StepStart,
|
||||
/// <summary>
|
||||
/// step line.
|
||||
/// 阶梯线图:当前点和下一个点的中间。
|
||||
/// </summary>
|
||||
StepMiddle,
|
||||
/// <summary>
|
||||
/// step line.
|
||||
/// 阶梯线图:下一个拐点。
|
||||
/// </summary>
|
||||
StepEnd
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 系列。每个系列通过 type 决定自己的图表类型。
|
||||
/// </summary>
|
||||
@@ -74,9 +107,14 @@ namespace XCharts
|
||||
[SerializeField] private string m_Stack;
|
||||
[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();
|
||||
[SerializeField] private LineType m_LineType = LineType.Normal;
|
||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
|
||||
[SerializeField] private float m_BarWidth = 0.6f;
|
||||
[SerializeField] private float m_BarGap = 0.3f; // 30%
|
||||
[SerializeField] private float m_BarCategoryGap = 0.2f; // 20%
|
||||
|
||||
#region PieChart field
|
||||
[SerializeField] private bool m_ClickOffset = true;
|
||||
[SerializeField] private RoseType m_RoseType = RoseType.None;
|
||||
@@ -96,7 +134,8 @@ namespace XCharts
|
||||
[NonSerialized] private int m_FilterStart;
|
||||
[NonSerialized] private int m_FilterEnd;
|
||||
[NonSerialized] private List<SerieData> m_FilterData;
|
||||
[NonSerialized] private Dictionary<int, List<Vector3>> m_SmoothPoints = new Dictionary<int, List<Vector3>>();
|
||||
[NonSerialized] private Dictionary<int, List<Vector3>> m_UpSmoothPoints = new Dictionary<int, List<Vector3>>();
|
||||
[NonSerialized] private Dictionary<int, List<Vector3>> m_DownSmoothPoints = new Dictionary<int, List<Vector3>>();
|
||||
[NonSerialized] private List<Vector3> m_DataPoints = new List<Vector3>();
|
||||
|
||||
/// <summary>
|
||||
@@ -130,12 +169,6 @@ namespace XCharts
|
||||
/// </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>
|
||||
@@ -147,30 +180,70 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public SerieSymbol symbol { get { return m_Symbol; } set { m_Symbol = value; } }
|
||||
/// <summary>
|
||||
/// The type of line chart.
|
||||
/// 折线图样式类型。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public LineType lineType { get { return m_LineType; } set { m_LineType = value; } }
|
||||
/// <summary>
|
||||
/// The style of line.
|
||||
/// 线条样式。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
|
||||
/// <summary>
|
||||
/// The width of the bar. Adaptive when default 0.
|
||||
/// 柱条的宽度,不设时自适应。支持设置成相对于类目宽度的百分比。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float barWidth { get { return m_BarWidth; } set { m_BarWidth = value; } }
|
||||
/// <summary>
|
||||
/// The gap between bars between different series, is a percent value like '0.3f' , which means 30% of the bar width, can be set as a fixed value.
|
||||
/// <para>Set barGap as '-1' can overlap bars that belong to different series, which is useful when making a series of bar be background.
|
||||
/// In a single coodinate system, this attribute is shared by multiple 'bar' series.
|
||||
/// This attribute should be set on the last 'bar' series in the coodinate system,
|
||||
/// then it will be adopted by all 'bar' series in the coordinate system.</para>
|
||||
/// 不同系列的柱间距离。为百分比(如 '0.3f',表示柱子宽度的 30%)
|
||||
/// 如果想要两个系列的柱子重叠,可以设置 barGap 为 '-1f'。这在用柱子做背景的时候有用。
|
||||
/// 在同一坐标系上,此属性会被多个 'bar' 系列共享。此属性应设置于此坐标系中最后一个 'bar' 系列上才会生效,并且是对此坐标系中所有 'bar' 系列生效。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float barGap { get { return m_BarGap; } set { m_BarGap = value; } }
|
||||
/// <summary>
|
||||
/// The bar gap of a single series, defaults to be 20% of the category gap, can be set as a fixed value.
|
||||
/// In a single coodinate system, this attribute is shared by multiple 'bar' series.
|
||||
/// This attribute should be set on the last 'bar' series in the coodinate system,
|
||||
/// then it will be adopted by all 'bar' series in the coordinate system.
|
||||
/// 同一系列的柱间距离,默认为类目间距的20%,可设固定值。
|
||||
/// 在同一坐标系上,此属性会被多个 'bar' 系列共享。此属性应设置于此坐标系中最后一个 'bar' 系列上才会生效,并且是对此坐标系中所有 'bar' 系列生效。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float barCategoryGap { get { return m_BarCategoryGap; } set { m_BarCategoryGap = value; } }
|
||||
/// <summary>
|
||||
/// Whether offset when mouse click pie chart item.
|
||||
/// 鼠标点击时是否开启偏移,一般用在PieChart图表中。
|
||||
/// </summary>
|
||||
public bool clickOffset { get { return m_ClickOffset; } set { m_ClickOffset = value; } }
|
||||
public bool pieClickOffset { get { return m_ClickOffset; } set { m_ClickOffset = value; } }
|
||||
/// <summary>
|
||||
/// Whether to show as Nightingale chart.
|
||||
/// 是否展示成南丁格尔图,通过半径区分数据大小。
|
||||
/// </summary>
|
||||
public RoseType roseType { get { return m_RoseType; } set { m_RoseType = value; } }
|
||||
public RoseType pieRoseType { get { return m_RoseType; } set { m_RoseType = value; } }
|
||||
/// <summary>
|
||||
/// the space of pie chart item.
|
||||
/// 饼图项间的空隙留白。
|
||||
/// </summary>
|
||||
public float space { get { return m_Space; } set { m_Space = value; } }
|
||||
public float pieSpace { get { return m_Space; } set { m_Space = value; } }
|
||||
/// <summary>
|
||||
/// the center of pie chart.
|
||||
/// 饼图的中心点。
|
||||
/// </summary>
|
||||
public float[] center { get { return m_Center; } set { m_Center = value; } }
|
||||
public float[] pieCenter { get { return m_Center; } set { m_Center = value; } }
|
||||
/// <summary>
|
||||
/// the radius of pie chart.
|
||||
/// 饼图的半径。radius[0]表示内径,radius[1]表示外径。
|
||||
/// </summary>
|
||||
public float[] radius { get { return m_Radius; } set { m_Radius = value; } }
|
||||
public float[] pieRadius { get { return m_Radius; } set { m_Radius = value; } }
|
||||
/// <summary>
|
||||
/// Text label of graphic element,to explain some data information about graphic item like value, name and so on.
|
||||
/// 图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
|
||||
@@ -209,28 +282,49 @@ namespace XCharts
|
||||
/// 数据项个数。
|
||||
/// </summary>
|
||||
public int dataCount { get { return m_Data.Count; } }
|
||||
/// <summary>
|
||||
/// 整个系列的每段曲线的点列表
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Dictionary<int, List<Vector3>> smoothPoints { get { return m_SmoothPoints; } }
|
||||
|
||||
public List<Vector3> dataPoints { get { return m_DataPoints; } }
|
||||
|
||||
public List<Vector3> GetSmoothList(int dataIndex, int size = 100)
|
||||
public List<Vector3> GetUpSmoothList(int dataIndex, int size = 100)
|
||||
{
|
||||
if (m_SmoothPoints.ContainsKey(dataIndex))
|
||||
if (m_UpSmoothPoints.ContainsKey(dataIndex))
|
||||
{
|
||||
return m_SmoothPoints[dataIndex];
|
||||
return m_UpSmoothPoints[dataIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = new List<Vector3>(size);
|
||||
m_SmoothPoints[dataIndex] = list;
|
||||
m_UpSmoothPoints[dataIndex] = list;
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Vector3> GetDownSmoothList(int dataIndex, int size = 100)
|
||||
{
|
||||
if (m_DownSmoothPoints.ContainsKey(dataIndex))
|
||||
{
|
||||
return m_DownSmoothPoints[dataIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = new List<Vector3>(size);
|
||||
m_DownSmoothPoints[dataIndex] = list;
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearSmoothList(int dataIndex)
|
||||
{
|
||||
if (m_UpSmoothPoints.ContainsKey(dataIndex))
|
||||
{
|
||||
m_UpSmoothPoints[dataIndex].Clear();
|
||||
}
|
||||
if (m_DownSmoothPoints.ContainsKey(dataIndex))
|
||||
{
|
||||
m_DownSmoothPoints[dataIndex].Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 维度Y对应数据中最大值。
|
||||
/// </summary>
|
||||
@@ -683,36 +777,81 @@ namespace XCharts
|
||||
{
|
||||
var color = areaStyle.color;
|
||||
if (highlight) color *= color;
|
||||
color.a *= areaStyle.opactiy;
|
||||
color.a *= areaStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a *= areaStyle.opactiy;
|
||||
color.a *= areaStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public Color GetAreaToColor(ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
if (areaStyle.toColor != Color.clear)
|
||||
{
|
||||
var color = areaStyle.toColor;
|
||||
if (highlight) color *= color;
|
||||
color.a *= areaStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetAreaColor(theme, index, highlight);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
color.a *= lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a *= lineStyle.opactiy;
|
||||
color.a *= lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public Color GetSymbolColor(ThemeInfo theme, int index, bool highlight)
|
||||
{
|
||||
if (symbol.color != Color.clear)
|
||||
{
|
||||
var color = symbol.color;
|
||||
if (highlight) color *= color;
|
||||
color.a *= symbol.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.GetColor(index);
|
||||
if (highlight) color *= color;
|
||||
color.a *= symbol.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public float GetBarWidth(float categoryWidth)
|
||||
{
|
||||
if (m_BarWidth > 1) return m_BarWidth;
|
||||
else return m_BarWidth * categoryWidth;
|
||||
}
|
||||
|
||||
public float GetBarGap(float categoryWidth)
|
||||
{
|
||||
if (m_BarGap == -1) return 0;
|
||||
else if (m_BarGap <= 1) return GetBarWidth(categoryWidth) * m_BarGap;
|
||||
else return m_BarGap;
|
||||
}
|
||||
/// <summary>
|
||||
/// 从json中导入数据
|
||||
/// </summary>
|
||||
|
||||
@@ -118,6 +118,51 @@ namespace XCharts
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得上一个同堆叠且显示的serie。
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public Serie GetLastStackSerie(int index)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
return GetLastStackSerie(serie);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同堆叠的serie是否有渐变色的。
|
||||
/// </summary>
|
||||
/// <param name="stack"></param>
|
||||
/// <returns></returns>
|
||||
public bool IsAnyGradientSerie(string stack)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stack)) return false;
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
if (serie.show && serie.areaStyle.show && stack.Equals(serie.stack))
|
||||
{
|
||||
if (serie.areaStyle.color != serie.areaStyle.toColor && serie.areaStyle.toColor != Color.clear) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得上一个同堆叠且显示的serie。
|
||||
/// </summary>
|
||||
/// <param name="serie"></param>
|
||||
/// <returns></returns>
|
||||
public Serie GetLastStackSerie(Serie serie)
|
||||
{
|
||||
if (serie == null || string.IsNullOrEmpty(serie.stack)) return null;
|
||||
for (int i = serie.index - 1; i >= 0; i--)
|
||||
{
|
||||
var temp = m_Series[i];
|
||||
if (temp.show && serie.stack.Equals(temp.stack)) return temp;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含指定名字的系列
|
||||
/// </summary>
|
||||
@@ -605,19 +650,16 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsStack(string stackName)
|
||||
public bool IsStack(string stackName, SerieType type)
|
||||
{
|
||||
_setForStack.Clear();
|
||||
if (string.IsNullOrEmpty(stackName)) return false;
|
||||
int count = 0;
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
if (string.IsNullOrEmpty(serie.stack)) continue;
|
||||
if (_setForStack.Contains(serie.stack))
|
||||
if (serie.show && serie.type == type)
|
||||
{
|
||||
if (serie.stack.Equals(stackName)) return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_setForStack.Add(serie.stack);
|
||||
if (stackName.Equals(serie.stack)) count++;
|
||||
if (count >= 2) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace XCharts
|
||||
/// 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 float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
|
||||
|
||||
public static AreaStyle defaultAreaStyle
|
||||
{
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace XCharts
|
||||
[SerializeField] protected int m_MinShowDataNumber;
|
||||
[SerializeField] protected int m_MaxShowDataNumber;
|
||||
[SerializeField] protected int m_MaxCacheDataNumber;
|
||||
[SerializeField] [Range(1, 8)] private float m_LineSmoothStyle = 2f;
|
||||
|
||||
[NonSerialized] private Theme m_CheckTheme = 0;
|
||||
[NonSerialized] private Title m_CheckTitle = Title.defaultTitle;
|
||||
@@ -176,7 +177,7 @@ namespace XCharts
|
||||
var titleObject = ChartHelper.AddObject(s_TitleObjectName, transform, anchorMin, anchorMax,
|
||||
pivot, new Vector2(chartWidth, chartHeight));
|
||||
titleObject.transform.localPosition = titlePosition;
|
||||
ChartHelper.HideAllObject(titleObject, s_TitleObjectName);
|
||||
ChartHelper.HideAllObject(titleObject);
|
||||
|
||||
Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot,
|
||||
|
||||
@@ -73,6 +73,13 @@ namespace XCharts
|
||||
set { m_MaxCacheDataNumber = value; if (m_MaxCacheDataNumber < 0) m_MaxCacheDataNumber = 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the smooth line chart style.
|
||||
/// 平滑折线图的平滑系数。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float lineSmoothStyle { get { return m_LineSmoothStyle; } set { m_LineSmoothStyle = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Set the size of chart.
|
||||
/// 设置图表的大小。
|
||||
|
||||
@@ -334,7 +334,6 @@ namespace XCharts
|
||||
|
||||
private void InitAxisY()
|
||||
{
|
||||
ChartHelper.HideAllObject(gameObject, "split_y");//old name
|
||||
for (int i = 0; i < m_YAxises.Count; i++)
|
||||
{
|
||||
InitYAxis(i, m_YAxises[i]);
|
||||
@@ -351,7 +350,7 @@ namespace XCharts
|
||||
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
|
||||
axisObj.transform.localPosition = Vector3.zero;
|
||||
axisObj.SetActive(yAxis.show && yAxis.axisLabel.show);
|
||||
ChartHelper.HideAllObject(axisObj, objName);
|
||||
ChartHelper.HideAllObject(axisObj);
|
||||
|
||||
var labelColor = yAxis.axisLabel.color == Color.clear ?
|
||||
(Color)m_ThemeInfo.axisTextColor :
|
||||
@@ -434,7 +433,6 @@ namespace XCharts
|
||||
|
||||
private void InitAxisX()
|
||||
{
|
||||
ChartHelper.HideAllObject(gameObject, "split_x");//old name
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
InitXAxis(i, m_XAxises[i]);
|
||||
@@ -447,19 +445,19 @@ namespace XCharts
|
||||
xAxis.maxValue = 100;
|
||||
xAxis.axisLabelTextList.Clear();
|
||||
float labelWidth = xAxis.GetScaleWidth(coordinateWid, m_DataZoom);
|
||||
string objName = xAxisIndex > 0 ? s_DefaultAxisX + "2" : s_DefaultAxisX;
|
||||
string objName = xAxisIndex > 0 ? ChartHelper.Cancat(s_DefaultAxisX, 2) : s_DefaultAxisX;
|
||||
var axisObj = ChartHelper.AddObject(objName, transform, chartAnchorMin,
|
||||
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
|
||||
axisObj.transform.localPosition = Vector3.zero;
|
||||
axisObj.SetActive(xAxis.show && xAxis.axisLabel.show);
|
||||
ChartHelper.HideAllObject(axisObj, objName);
|
||||
ChartHelper.HideAllObject(axisObj);
|
||||
var labelColor = xAxis.axisLabel.color == Color.clear ?
|
||||
(Color)m_ThemeInfo.axisTextColor :
|
||||
xAxis.axisLabel.color;
|
||||
for (int i = 0; i < xAxis.GetSplitNumber(m_DataZoom); i++)
|
||||
{
|
||||
bool inside = xAxis.axisLabel.inside;
|
||||
Text txt = ChartHelper.AddTextObject(objName + i, axisObj.transform,
|
||||
Text txt = ChartHelper.AddTextObject(ChartHelper.Cancat(objName, i), axisObj.transform,
|
||||
m_ThemeInfo.font, labelColor, TextAnchor.MiddleCenter, new Vector2(0, 1),
|
||||
new Vector2(0, 1), new Vector2(1, 0.5f), new Vector2(labelWidth, 20),
|
||||
xAxis.axisLabel.fontSize, xAxis.axisLabel.rotate, xAxis.axisLabel.fontStyle);
|
||||
@@ -480,7 +478,7 @@ namespace XCharts
|
||||
switch (xAxis.axisName.location)
|
||||
{
|
||||
case AxisName.Location.Start:
|
||||
axisName = ChartHelper.AddTextObject(objName + "_name", axisObj.transform,
|
||||
axisName = ChartHelper.AddTextObject(ChartHelper.Cancat(objName, "_name"), axisObj.transform,
|
||||
m_ThemeInfo.font, color, TextAnchor.MiddleRight, new Vector2(1, 0.5f),
|
||||
new Vector2(1, 0.5f), new Vector2(1, 0.5f), new Vector2(100, 20), fontSize,
|
||||
xAxis.axisName.rotate, xAxis.axisName.fontStyle);
|
||||
@@ -489,7 +487,7 @@ namespace XCharts
|
||||
new Vector2(coordinateX - gap, coordinateY);
|
||||
break;
|
||||
case AxisName.Location.Middle:
|
||||
axisName = ChartHelper.AddTextObject(objName + "_name", axisObj.transform,
|
||||
axisName = ChartHelper.AddTextObject(ChartHelper.Cancat(objName, "_name"), axisObj.transform,
|
||||
m_ThemeInfo.font, color, TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f),
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), fontSize,
|
||||
xAxis.axisName.rotate, xAxis.axisName.fontStyle);
|
||||
@@ -498,7 +496,7 @@ namespace XCharts
|
||||
new Vector2(coordinateX + coordinateWid / 2, coordinateY - gap);
|
||||
break;
|
||||
case AxisName.Location.End:
|
||||
axisName = ChartHelper.AddTextObject(objName + "_name", axisObj.transform,
|
||||
axisName = ChartHelper.AddTextObject(ChartHelper.Cancat(objName, "_name"), axisObj.transform,
|
||||
m_ThemeInfo.font, color, TextAnchor.MiddleLeft, new Vector2(0, 0.5f),
|
||||
new Vector2(0, 0.5f), new Vector2(0, 0.5f), new Vector2(100, 20), fontSize,
|
||||
xAxis.axisName.rotate, xAxis.axisName.fontStyle);
|
||||
@@ -513,7 +511,7 @@ namespace XCharts
|
||||
{
|
||||
Vector2 privot = xAxisIndex > 0 ? new Vector2(0.5f, 1) : new Vector2(0.5f, 1);
|
||||
var labelParent = m_Tooltip.gameObject.transform;
|
||||
GameObject labelObj = ChartHelper.AddTooltipLabel(objName + "_label", labelParent, m_ThemeInfo.font, privot);
|
||||
GameObject labelObj = ChartHelper.AddTooltipLabel(ChartHelper.Cancat(objName, "_label"), labelParent, m_ThemeInfo.font, privot);
|
||||
xAxis.SetTooltipLabel(labelObj);
|
||||
xAxis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor);
|
||||
xAxis.SetTooltipLabelActive(xAxis.show && m_Tooltip.show && m_Tooltip.type == Tooltip.Type.Corss);
|
||||
@@ -525,7 +523,7 @@ namespace XCharts
|
||||
var dataZoomObject = ChartHelper.AddObject(s_DefaultDataZoom, transform, chartAnchorMin,
|
||||
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
|
||||
dataZoomObject.transform.localPosition = Vector3.zero;
|
||||
ChartHelper.HideAllObject(dataZoomObject, s_DefaultDataZoom);
|
||||
ChartHelper.HideAllObject(dataZoomObject);
|
||||
m_DataZoom.startLabel = ChartHelper.AddTextObject(s_DefaultDataZoom + "start",
|
||||
dataZoomObject.transform, m_ThemeInfo.font, m_ThemeInfo.dataZoomTextColor, TextAnchor.MiddleRight,
|
||||
Vector2.zero, Vector2.zero, new Vector2(1, 0.5f), new Vector2(200, 20));
|
||||
@@ -604,6 +602,10 @@ namespace XCharts
|
||||
{
|
||||
if (!ChartHelper.IsValueEqualsList<YAxis>(m_CheckYAxises, m_YAxises))
|
||||
{
|
||||
foreach (var axis in m_CheckYAxises)
|
||||
{
|
||||
YAxisPool.Release(axis);
|
||||
}
|
||||
m_CheckYAxises.Clear();
|
||||
foreach (var axis in m_YAxises) m_CheckYAxises.Add(axis.Clone());
|
||||
OnYAxisChanged();
|
||||
@@ -614,6 +616,10 @@ namespace XCharts
|
||||
{
|
||||
if (!ChartHelper.IsValueEqualsList<XAxis>(m_CheckXAxises, m_XAxises))
|
||||
{
|
||||
foreach (var axis in m_CheckXAxises)
|
||||
{
|
||||
XAxisPool.Release(axis);
|
||||
}
|
||||
m_CheckXAxises.Clear();
|
||||
foreach (var axis in m_XAxises) m_CheckXAxises.Add(axis.Clone());
|
||||
OnXAxisChanged();
|
||||
|
||||
@@ -50,6 +50,6 @@ namespace XCharts
|
||||
/// 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; } }
|
||||
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -74,7 +74,7 @@ namespace XCharts
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (serie.clickOffset) isClickOffset = true;
|
||||
if (serie.pieClickOffset) isClickOffset = true;
|
||||
PieTempData tempData;
|
||||
if (i < m_PieTempDataList.Count)
|
||||
{
|
||||
@@ -95,7 +95,7 @@ namespace XCharts
|
||||
float totalDegree = 360;
|
||||
float startDegree = 0;
|
||||
int showdataCount = 0;
|
||||
if (serie.roseType == RoseType.Area)
|
||||
if (serie.pieRoseType == RoseType.Area)
|
||||
{
|
||||
foreach (var sd in serie.data)
|
||||
{
|
||||
@@ -128,10 +128,10 @@ namespace XCharts
|
||||
tempData.angleList.Add(0);
|
||||
continue;
|
||||
}
|
||||
float degree = serie.roseType == RoseType.Area ? (totalDegree / showdataCount) : (totalDegree * value / tempData.dataTotal);
|
||||
float degree = serie.pieRoseType == RoseType.Area ? (totalDegree / showdataCount) : (totalDegree * value / tempData.dataTotal);
|
||||
float toDegree = startDegree + degree;
|
||||
|
||||
float outSideRadius = serie.roseType > 0 ?
|
||||
float outSideRadius = serie.pieRoseType > 0 ?
|
||||
tempData.insideRadius + (tempData.outsideRadius - tempData.insideRadius) * value / tempData.dataMax :
|
||||
tempData.outsideRadius;
|
||||
if (serieData.highlighted)
|
||||
@@ -140,8 +140,8 @@ namespace XCharts
|
||||
color *= 1.2f;
|
||||
outSideRadius += m_Pie.tooltipExtraRadius;
|
||||
}
|
||||
var offset = serie.space;
|
||||
if (serie.clickOffset && serieData.selected)
|
||||
var offset = serie.pieSpace;
|
||||
if (serie.pieClickOffset && serieData.selected)
|
||||
{
|
||||
offset += m_Pie.selectedOffset;
|
||||
}
|
||||
@@ -153,10 +153,10 @@ namespace XCharts
|
||||
var center = tempData.center;
|
||||
if (offset > 0)
|
||||
{
|
||||
float offsetRadius = serie.space / Mathf.Sin(halfDegree * Mathf.Deg2Rad);
|
||||
float offsetRadius = serie.pieSpace / Mathf.Sin(halfDegree * Mathf.Deg2Rad);
|
||||
var insideRadius = tempData.insideRadius - offsetRadius;
|
||||
var outsideRadius = outSideRadius - offsetRadius;
|
||||
if (serie.clickOffset && serieData.selected)
|
||||
if (serie.pieClickOffset && serieData.selected)
|
||||
{
|
||||
offsetRadius += m_Pie.selectedOffset;
|
||||
if (insideRadius > 0) insideRadius += m_Pie.selectedOffset;
|
||||
@@ -261,7 +261,7 @@ namespace XCharts
|
||||
float totalDegree = 360;
|
||||
float startDegree = 0;
|
||||
int showdataCount = 0;
|
||||
if (serie.roseType == RoseType.Area)
|
||||
if (serie.pieRoseType == RoseType.Area)
|
||||
{
|
||||
foreach (var sd in serie.data)
|
||||
{
|
||||
@@ -294,18 +294,18 @@ namespace XCharts
|
||||
tempData.angleList.Add(0);
|
||||
continue;
|
||||
}
|
||||
float degree = serie.roseType == RoseType.Area ? (totalDegree / showdataCount) : (totalDegree * value / tempData.dataTotal);
|
||||
float degree = serie.pieRoseType == RoseType.Area ? (totalDegree / showdataCount) : (totalDegree * value / tempData.dataTotal);
|
||||
float toDegree = startDegree + degree;
|
||||
|
||||
float outSideRadius = serie.roseType > 0 ?
|
||||
float outSideRadius = serie.pieRoseType > 0 ?
|
||||
tempData.insideRadius + (tempData.outsideRadius - tempData.insideRadius) * value / tempData.dataMax :
|
||||
tempData.outsideRadius;
|
||||
if (serieData.highlighted)
|
||||
{
|
||||
outSideRadius += m_Pie.tooltipExtraRadius;
|
||||
}
|
||||
var offset = serie.space;
|
||||
if (serie.clickOffset && serieData.selected)
|
||||
var offset = serie.pieSpace;
|
||||
if (serie.pieClickOffset && serieData.selected)
|
||||
{
|
||||
offset += m_Pie.selectedOffset;
|
||||
}
|
||||
@@ -313,10 +313,10 @@ namespace XCharts
|
||||
float currAngle = startDegree + halfDegree;
|
||||
if (offset > 0)
|
||||
{
|
||||
float offsetRadius = serie.space / Mathf.Sin(halfDegree * Mathf.Deg2Rad);
|
||||
float offsetRadius = serie.pieSpace / Mathf.Sin(halfDegree * Mathf.Deg2Rad);
|
||||
var insideRadius = tempData.insideRadius - offsetRadius;
|
||||
var outsideRadius = outSideRadius - offsetRadius;
|
||||
if (serie.clickOffset && serieData.selected)
|
||||
if (serie.pieClickOffset && serieData.selected)
|
||||
{
|
||||
offsetRadius += m_Pie.selectedOffset;
|
||||
if (insideRadius > 0) insideRadius += m_Pie.selectedOffset;
|
||||
@@ -431,14 +431,14 @@ namespace XCharts
|
||||
|
||||
private void UpdatePieCenter(Serie serie)
|
||||
{
|
||||
if (serie.center.Length < 2) return;
|
||||
if (serie.pieCenter.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];
|
||||
var centerX = serie.pieCenter[0] <= 1 ? chartWidth * serie.pieCenter[0] : serie.pieCenter[0];
|
||||
var centerY = serie.pieCenter[1] <= 1 ? chartHeight * serie.pieCenter[1] : serie.pieCenter[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];
|
||||
tempData.insideRadius = serie.pieRadius[0] <= 1 ? minWidth * serie.pieRadius[0] : serie.pieRadius[0];
|
||||
tempData.outsideRadius = serie.pieRadius[1] <= 1 ? minWidth * serie.pieRadius[1] : serie.pieRadius[1];
|
||||
}
|
||||
|
||||
protected override void CheckTootipArea(Vector2 local)
|
||||
|
||||
@@ -403,13 +403,13 @@ namespace XCharts
|
||||
if (radar.lineStyle.color != Color.clear)
|
||||
{
|
||||
var color = radar.lineStyle.color;
|
||||
color.a *= radar.lineStyle.opactiy;
|
||||
color.a *= radar.lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)m_ThemeInfo.axisLineColor;
|
||||
color.a *= radar.lineStyle.opactiy;
|
||||
color.a *= radar.lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
35
Scripts/UI/Utility/AxisPool.cs
Normal file
35
Scripts/UI/Utility/AxisPool.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class XAxisPool
|
||||
{
|
||||
private static readonly ObjectPool<XAxis> s_ListPool = new ObjectPool<XAxis>(null, null);
|
||||
|
||||
public static XAxis Get()
|
||||
{
|
||||
return s_ListPool.Get();
|
||||
}
|
||||
|
||||
public static void Release(XAxis toRelease)
|
||||
{
|
||||
s_ListPool.Release(toRelease);
|
||||
}
|
||||
}
|
||||
|
||||
public static class YAxisPool
|
||||
{
|
||||
private static readonly ObjectPool<YAxis> s_ListPool = new ObjectPool<YAxis>(null, null);
|
||||
|
||||
public static YAxis Get()
|
||||
{
|
||||
return s_ListPool.Get();
|
||||
}
|
||||
|
||||
public static void Release(YAxis toRelease)
|
||||
{
|
||||
s_ListPool.Release(toRelease);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f4f93f97ce4c4274a4153986a3e5752
|
||||
guid: 9cd917166df95406ca680235ef51403c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -8,6 +8,7 @@ namespace XCharts
|
||||
private static Dictionary<float, string> s_ValueToF1Str = new Dictionary<float, string>(1000);
|
||||
private static Dictionary<float, string> s_ValueToF2Str = new Dictionary<float, string>(1000);
|
||||
private static Dictionary<float, string> s_ValueToStr = new Dictionary<float, string>(1000);
|
||||
private static Dictionary<int, string> s_IntToStr = new Dictionary<int, string>(1000);
|
||||
|
||||
public static string FloatToStr(float value, int f = 0)
|
||||
{
|
||||
@@ -27,5 +28,18 @@ namespace XCharts
|
||||
return valueDic[value];
|
||||
}
|
||||
}
|
||||
|
||||
public static string IntToStr(int value)
|
||||
{
|
||||
if (s_IntToStr.ContainsKey(value))
|
||||
{
|
||||
return s_IntToStr[value];
|
||||
}
|
||||
else
|
||||
{
|
||||
s_IntToStr[value] = value.ToString();
|
||||
return s_IntToStr[value];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
@@ -11,9 +12,26 @@ namespace XCharts
|
||||
{
|
||||
public static float CRICLE_SMOOTHNESS = 2f;
|
||||
private static UIVertex[] vertex = new UIVertex[4];
|
||||
private static StringBuilder s_Builder = new StringBuilder();
|
||||
|
||||
public static void SetActive(GameObject gameObject,bool active){
|
||||
SetActive(gameObject.transform,active);
|
||||
|
||||
public static string Cancat(string str1, string str2)
|
||||
{
|
||||
s_Builder.Length = 0;
|
||||
s_Builder.Append(str1).Append(str2);
|
||||
return s_Builder.ToString();
|
||||
}
|
||||
|
||||
public static string Cancat(string str1, int i)
|
||||
{
|
||||
s_Builder.Length = 0;
|
||||
s_Builder.Append(str1).Append(ChartCached.IntToStr(i));
|
||||
return s_Builder.ToString();
|
||||
}
|
||||
|
||||
public static void SetActive(GameObject gameObject, bool active)
|
||||
{
|
||||
SetActive(gameObject.transform, active);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -21,8 +39,9 @@ namespace XCharts
|
||||
/// </summary>
|
||||
/// <param name="transform"></param>
|
||||
/// <param name="active"></param>
|
||||
public static void SetActive(Transform transform,bool active){
|
||||
if(active) transform.localScale = Vector3.one;
|
||||
public static void SetActive(Transform transform, bool active)
|
||||
{
|
||||
if (active) transform.localScale = Vector3.one;
|
||||
else transform.localScale = Vector3.zero;
|
||||
}
|
||||
public static void HideAllObject(GameObject obj, string match = null)
|
||||
@@ -35,14 +54,14 @@ namespace XCharts
|
||||
for (int i = 0; i < parent.childCount; i++)
|
||||
{
|
||||
if (match == null)
|
||||
SetActive(parent.GetChild(i),false);
|
||||
//parent.GetChild(i).gameObject.SetActive(false);
|
||||
SetActive(parent.GetChild(i), false);
|
||||
//parent.GetChild(i).gameObject.SetActive(false);
|
||||
else
|
||||
{
|
||||
var go = parent.GetChild(i);
|
||||
if (go.name.StartsWith(match))
|
||||
{
|
||||
SetActive(go,false);
|
||||
SetActive(go, false);
|
||||
//go.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
@@ -236,6 +255,12 @@ namespace XCharts
|
||||
|
||||
public static void DrawTriangle(VertexHelper vh, Vector3 p1,
|
||||
Vector3 p2, Vector3 p3, Color32 color)
|
||||
{
|
||||
DrawTriangle(vh, p1, p2, p3, color, color, color);
|
||||
}
|
||||
|
||||
public static void DrawTriangle(VertexHelper vh, Vector3 p1,
|
||||
Vector3 p2, Vector3 p3, Color32 color, Color32 color2, Color32 color3)
|
||||
{
|
||||
UIVertex v1 = new UIVertex();
|
||||
v1.position = p1;
|
||||
@@ -243,11 +268,11 @@ namespace XCharts
|
||||
v1.uv0 = Vector3.zero;
|
||||
UIVertex v2 = new UIVertex();
|
||||
v2.position = p2;
|
||||
v2.color = color;
|
||||
v2.color = color2;
|
||||
v2.uv0 = Vector3.zero;
|
||||
UIVertex v3 = new UIVertex();
|
||||
v3.position = p3;
|
||||
v3.color = color;
|
||||
v3.color = color3;
|
||||
v3.uv0 = Vector3.zero;
|
||||
int startIndex = vh.currentVertCount;
|
||||
vh.AddVert(v1);
|
||||
@@ -340,7 +365,21 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetBezierList(ref List<Vector3> posList, Vector3 sp, Vector3 ep, float k = 2.0f)
|
||||
public static void GetPointList(ref List<Vector3> posList, Vector3 sp, Vector3 ep, float k = 30f)
|
||||
{
|
||||
Vector3 dir = (ep - sp).normalized;
|
||||
float dist = Vector3.Distance(sp, ep);
|
||||
int segment = (int)(dist / k);
|
||||
posList.Clear();
|
||||
posList.Add(sp);
|
||||
for (int i = 1; i < segment; i++)
|
||||
{
|
||||
posList.Add(sp + dir * dist * i / segment);
|
||||
}
|
||||
posList.Add(ep);
|
||||
}
|
||||
|
||||
public static void GetBezierList(ref List<Vector3> posList, Vector3 sp, Vector3 ep, bool fine, float k = 2.0f)
|
||||
{
|
||||
Vector3 dir = (ep - sp).normalized;
|
||||
float dist = Vector3.Distance(sp, ep);
|
||||
@@ -348,20 +387,20 @@ namespace XCharts
|
||||
Vector3 cp2 = sp + dist / k * dir * (k - 1);
|
||||
cp1.y = sp.y;
|
||||
cp2.y = ep.y;
|
||||
int segment = (int)(dist / 0.6f);
|
||||
int segment = (int)(dist / (fine ? 3f : 7f));
|
||||
GetBezierList2(ref posList, sp, ep, segment, cp1, cp2);
|
||||
}
|
||||
|
||||
public static void GetBezierListVertical(ref List<Vector3> posList, Vector3 sp, Vector3 ep, float k = 2.0f)
|
||||
public static void GetBezierListVertical(ref List<Vector3> posList, Vector3 sp, Vector3 ep, bool fine, float k = 2.0f)
|
||||
{
|
||||
Vector3 dir = (ep - sp).normalized;
|
||||
float dist = Vector3.Distance(sp, ep);
|
||||
Vector3 cp1 = sp + dist / k * dir * 1;
|
||||
Vector3 cp2 = sp + dist / k * dir * (k - 1);
|
||||
cp1.y = sp.y;
|
||||
cp2.y = ep.y;
|
||||
int segment = (int)(dist / 0.6f);
|
||||
GetBezierList2(ref posList, sp, ep, segment, cp2, cp1);
|
||||
cp1.x = sp.x;
|
||||
cp2.x = ep.x;
|
||||
int segment = (int)(dist / (fine ? 3f : 7f));
|
||||
GetBezierList2(ref posList, sp, ep, segment, cp1, cp2);
|
||||
}
|
||||
|
||||
public static List<Vector3> GetBezierList(Vector3 sp, Vector3 ep, int segment, Vector3 cp)
|
||||
|
||||
20
Scripts/UI/Utility/ListPool.cs
Normal file
20
Scripts/UI/Utility/ListPool.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class ListPool<T>
|
||||
{
|
||||
private static readonly ObjectPool<List<T>> s_ListPool = new ObjectPool<List<T>>(null, Clear);
|
||||
static void Clear(List<T> l) { l.Clear(); }
|
||||
|
||||
public static List<T> Get()
|
||||
{
|
||||
return s_ListPool.Get();
|
||||
}
|
||||
|
||||
public static void Release(List<T> toRelease)
|
||||
{
|
||||
s_ListPool.Release(toRelease);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a4ce8176d040474db7238ccc962c79f
|
||||
guid: ece4661d8c4714c65b661d0116c6f754
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
49
Scripts/UI/Utility/ObjectPool.cs
Normal file
49
Scripts/UI/Utility/ObjectPool.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class ObjectPool<T> where T : new()
|
||||
{
|
||||
private readonly Stack<T> m_Stack = new Stack<T>();
|
||||
private readonly UnityAction<T> m_ActionOnGet;
|
||||
private readonly UnityAction<T> m_ActionOnRelease;
|
||||
|
||||
public int countAll { get; private set; }
|
||||
public int countActive { get { return countAll - countInactive; } }
|
||||
public int countInactive { get { return m_Stack.Count; } }
|
||||
|
||||
public ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease)
|
||||
{
|
||||
m_ActionOnGet = actionOnGet;
|
||||
m_ActionOnRelease = actionOnRelease;
|
||||
}
|
||||
|
||||
public T Get()
|
||||
{
|
||||
T element;
|
||||
if (m_Stack.Count == 0)
|
||||
{
|
||||
element = new T();
|
||||
countAll++;
|
||||
}
|
||||
else
|
||||
{
|
||||
element = m_Stack.Pop();
|
||||
}
|
||||
if (m_ActionOnGet != null)
|
||||
m_ActionOnGet(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public void Release(T element)
|
||||
{
|
||||
if (m_Stack.Count > 0 && ReferenceEquals(m_Stack.Peek(), element))
|
||||
Debug.LogError("Internal error. Trying to destroy object that is already released to pool.");
|
||||
if (m_ActionOnRelease != null)
|
||||
m_ActionOnRelease(element);
|
||||
m_Stack.Push(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/UI/Utility/ObjectPool.cs.meta
Normal file
11
Scripts/UI/Utility/ObjectPool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8268dac56ab4147d3af647ca5ccd337a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user