增加漏斗图基础代码支持

This commit is contained in:
monitor1394
2021-05-29 22:07:09 +08:00
parent 7c52279aba
commit 8ca1ac1dea
18 changed files with 351 additions and 68 deletions

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}
}
}

View File

@@ -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;