mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 01:10:08 +00:00
增加漏斗图基础代码支持
This commit is contained in:
@@ -225,6 +225,35 @@ namespace XCharts
|
||||
Sum
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据排序方式
|
||||
/// </summary>
|
||||
public enum SerieDataSortType
|
||||
{
|
||||
/// <summary>
|
||||
/// 按 data 的顺序
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// 升序
|
||||
/// </summary>
|
||||
Ascending,
|
||||
/// <summary>
|
||||
/// 降序
|
||||
/// </summary>
|
||||
Descending,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对齐方式
|
||||
/// </summary>
|
||||
public enum SerieAlign
|
||||
{
|
||||
Center,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 系列。每个系列通过 type 决定自己的图表类型。
|
||||
/// </summary>
|
||||
@@ -263,6 +292,8 @@ namespace XCharts
|
||||
|
||||
[SerializeField] private float m_Min;
|
||||
[SerializeField] private float m_Max;
|
||||
[SerializeField] private float m_MinSize = 0f;
|
||||
[SerializeField] private float m_MaxSize = 1f;
|
||||
[SerializeField] private float m_StartAngle;
|
||||
[SerializeField] private float m_EndAngle;
|
||||
[SerializeField] private float m_MinAngle;
|
||||
@@ -303,6 +334,10 @@ namespace XCharts
|
||||
[SerializeField] private float m_WaveSpeed = 5f;
|
||||
[SerializeField] private float m_WaveOffset = 0f;
|
||||
[SerializeField] private RadarType m_RadarType = RadarType.Multiple;
|
||||
|
||||
[SerializeField] private SerieDataSortType m_DataSortType = SerieDataSortType.Descending;
|
||||
[SerializeField] private Orient m_Orient = Orient.Vertical;
|
||||
[SerializeField] private SerieAlign m_Align = SerieAlign.Center;
|
||||
[SerializeField] private float m_Left;
|
||||
[SerializeField] private float m_Right;
|
||||
[SerializeField] private float m_Top;
|
||||
@@ -627,7 +662,7 @@ namespace XCharts
|
||||
set { if (value != null && value.Length == 2) { m_Radius = value; SetVerticesDirty(); } }
|
||||
}
|
||||
/// <summary>
|
||||
/// 最小值,映射到 startAngle。
|
||||
/// 最小值。
|
||||
/// </summary>
|
||||
public float min
|
||||
{
|
||||
@@ -635,7 +670,7 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetStruct(ref m_Min, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 最大值,映射到 endAngle。
|
||||
/// 最大值。
|
||||
/// </summary>
|
||||
public float max
|
||||
{
|
||||
@@ -643,6 +678,22 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetStruct(ref m_Max, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 数据最小值 min 映射的宽度。
|
||||
/// </summary>
|
||||
public float minSize
|
||||
{
|
||||
get { return m_MinSize; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_MinSize, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 数据最大值 max 映射的宽度。
|
||||
/// </summary>
|
||||
public float maxSize
|
||||
{
|
||||
get { return m_MaxSize; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_MaxSize, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 起始角度。和时钟一样,12点钟位置是0度,顺时针到360度。
|
||||
/// </summary>
|
||||
public float startAngle
|
||||
@@ -975,6 +1026,30 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetStruct(ref m_InsertDataToHead, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 组件的数据排序。
|
||||
/// </summary>
|
||||
public SerieDataSortType dataSortType
|
||||
{
|
||||
get { return m_DataSortType; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_DataSortType, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 组件的朝向。
|
||||
/// </summary>
|
||||
public Orient orient
|
||||
{
|
||||
get { return m_Orient; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 组件水平方向对齐方式。
|
||||
/// </summary>
|
||||
public SerieAlign align
|
||||
{
|
||||
get { return m_Align; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Align, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 系列中的数据内容数组。SerieData可以设置1到n维数据。
|
||||
/// </summary>
|
||||
public List<SerieData> data { get { return m_Data; } }
|
||||
@@ -1078,6 +1153,7 @@ namespace XCharts
|
||||
public float runtimeY { get; internal set; }
|
||||
public float runtimeWidth { get; internal set; }
|
||||
public float runtimeHeight { get; internal set; }
|
||||
public List<SerieData> runtimeFilterData { get { return m_FilterData; } }
|
||||
public bool nameDirty { get { return m_NameDirty; } }
|
||||
|
||||
private void SetNameDirty()
|
||||
@@ -1584,7 +1660,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_Data;
|
||||
return runtimeFilterData.Count > 0 ? runtimeFilterData : m_Data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -207,6 +207,7 @@ namespace XCharts
|
||||
private List<float> m_PreviousData = new List<float>();
|
||||
private List<float> m_DataUpdateTime = new List<float>();
|
||||
private List<bool> m_DataUpdateFlag = new List<bool>();
|
||||
private List<Vector2> m_PolygonPoints = new List<Vector2>();
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
@@ -381,5 +382,30 @@ namespace XCharts
|
||||
{
|
||||
if (labelObject != null) labelObject.SetLabelActive(flag);
|
||||
}
|
||||
|
||||
public void SetPolygon(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4)
|
||||
{
|
||||
m_PolygonPoints.Clear();
|
||||
m_PolygonPoints.Add(p1);
|
||||
m_PolygonPoints.Add(p2);
|
||||
m_PolygonPoints.Add(p3);
|
||||
m_PolygonPoints.Add(p4);
|
||||
}
|
||||
|
||||
public bool IsInPolygon(Vector2 p)
|
||||
{
|
||||
if (m_PolygonPoints.Count == 0) return false;
|
||||
var inside = false;
|
||||
var j = m_PolygonPoints.Count - 1;
|
||||
for (int i = 0; i < m_PolygonPoints.Count; j = i++)
|
||||
{
|
||||
var pi = m_PolygonPoints[i];
|
||||
var pj = m_PolygonPoints[j];
|
||||
if (((pi.y <= p.y && p.y < pj.y) || (pj.y <= p.y && p.y < pi.y)) &&
|
||||
(p.x < (pj.x - pi.x) * (p.y - pi.y) / (pj.y - pi.y) + pi.x))
|
||||
inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,20 +44,20 @@ namespace XCharts
|
||||
/// </summary>
|
||||
Top,
|
||||
/// <summary>
|
||||
/// the left of symbol.
|
||||
/// 图形标志的左边。
|
||||
/// </summary>
|
||||
//Left,
|
||||
/// <summary>
|
||||
/// the right of symbol.
|
||||
/// 图形标志的右边。
|
||||
/// </summary>
|
||||
//Right,
|
||||
/// <summary>
|
||||
/// the bottom of symbol.
|
||||
/// 图形标志的底部。
|
||||
/// </summary>
|
||||
Bottom,
|
||||
/// <summary>
|
||||
/// the left of symbol.
|
||||
/// 图形标志的左边。
|
||||
/// </summary>
|
||||
Left,
|
||||
/// <summary>
|
||||
/// the right of symbol.
|
||||
/// 图形标志的右边。
|
||||
/// </summary>
|
||||
Right,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -91,6 +91,7 @@ namespace XCharts
|
||||
[SerializeField] private LineType m_LineType = LineType.BrokenLine;
|
||||
[SerializeField] private Color32 m_LineColor = ChartConst.clearColor32;
|
||||
[SerializeField] private float m_LineWidth = 1.0f;
|
||||
[SerializeField] private float m_LineGap = 1.0f;
|
||||
[SerializeField] private float m_LineLength1 = 25f;
|
||||
[SerializeField] private float m_LineLength2 = 15f;
|
||||
[SerializeField] private bool m_Border = false;
|
||||
@@ -114,6 +115,7 @@ namespace XCharts
|
||||
m_LineType = LineType.BrokenLine;
|
||||
m_LineColor = Color.clear;
|
||||
m_LineWidth = 1.0f;
|
||||
m_LineGap = 1.0f;
|
||||
m_LineLength1 = 25f;
|
||||
m_LineLength2 = 15f;
|
||||
m_Border = false;
|
||||
@@ -251,6 +253,15 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the gap of container and guild line.
|
||||
/// 视觉引导线和容器的间距。
|
||||
/// </summary>
|
||||
public float lineGap
|
||||
{
|
||||
get { return m_LineGap; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_LineGap, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The length of the first segment of visual guide line.
|
||||
/// 视觉引导线第一段的长度。
|
||||
/// </summary>
|
||||
@@ -325,5 +336,45 @@ namespace XCharts
|
||||
get { return m_TextStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetAllDirty(); }
|
||||
}
|
||||
|
||||
public bool IsInside()
|
||||
{
|
||||
return position == Position.Inside || position == Position.Center;
|
||||
}
|
||||
|
||||
public Color GetColor(Color defaultColor)
|
||||
{
|
||||
if (ChartHelper.IsClearColor(textStyle.color))
|
||||
{
|
||||
return IsInside() ? Color.black : defaultColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
return textStyle.color;
|
||||
}
|
||||
}
|
||||
|
||||
public TextAnchor GetAutoAlignment()
|
||||
{
|
||||
if (textStyle.autoAlign) return textStyle.alignment;
|
||||
else
|
||||
{
|
||||
switch (position)
|
||||
{
|
||||
case SerieLabel.Position.Inside:
|
||||
case SerieLabel.Position.Center:
|
||||
case SerieLabel.Position.Top:
|
||||
case SerieLabel.Position.Bottom:
|
||||
return TextAnchor.MiddleCenter;
|
||||
case SerieLabel.Position.Outside:
|
||||
case SerieLabel.Position.Right:
|
||||
return TextAnchor.MiddleLeft;
|
||||
case SerieLabel.Position.Left:
|
||||
return TextAnchor.MiddleRight;
|
||||
default:
|
||||
return TextAnchor.MiddleCenter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace XCharts
|
||||
public class TextStyle : SubComponent
|
||||
{
|
||||
[SerializeField] private Font m_Font;
|
||||
[SerializeField] private bool m_AutoWrap = true;
|
||||
[SerializeField] private bool m_AutoWrap = false;
|
||||
[SerializeField] private bool m_AutoAlign = true;
|
||||
[SerializeField] private float m_Rotate = 0;
|
||||
[SerializeField] private Vector2 m_Offset = Vector2.zero;
|
||||
|
||||
Reference in New Issue
Block a user