Skip to content

Commit

Permalink
增加漏斗图基础代码支持
Browse files Browse the repository at this point in the history
  • Loading branch information
monitor1394 committed May 29, 2021
1 parent b849633 commit f1a1483
Show file tree
Hide file tree
Showing 18 changed files with 348 additions and 65 deletions.
14 changes: 11 additions & 3 deletions Assets/XCharts/Editor/PropertyDrawers/SerieDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,14 @@ private void DrawData(Rect pos, SerializedProperty prop, SerieType serieType, re
var gap = 0;
var namegap = 0;
#endif
EditorGUI.PropertyField(new Rect(drawRect.x, drawRect.y, pos.width - 2 * nameWid - 2, pos.height), m_DataDimension);
EditorGUI.PropertyField(new Rect(drawRect.x, drawRect.y, pos.width - 2 * nameWid - 2, pos.height),
m_DataDimension);
var nameRect = new Rect(pos.width - 2 * nameWid + 14 + gap, drawRect.y, nameWid - gap, pos.height);
if (XChartsSettings.editorBlockEnable)
{
nameRect.x += ChartEditorHelper.BLOCK_WIDTH;
}
if (GUI.Button(nameRect, new GUIContent("Name")))
if (GUI.Button(nameRect, new GUIContent("name")))
{
m_ShowDataName.boolValue = !m_ShowDataName.boolValue;
}
Expand All @@ -262,10 +263,17 @@ private void DrawData(Rect pos, SerializedProperty prop, SerieType serieType, re
{
iconRect.x += ChartEditorHelper.BLOCK_WIDTH;
}
if (GUI.Button(iconRect, new GUIContent("More...")))
if (GUI.Button(iconRect, new GUIContent("more")))
{
m_ShowDataIcon.boolValue = !m_ShowDataIcon.boolValue;
}
var jsonRect = new Rect(pos.width - 70, drawRect.y - pos.height - 2, 90, pos.height);
if (GUI.Button(jsonRect, new GUIContent("data from json")))
{
PraseJsonDataEditor.chart = prop.serializedObject.targetObject as BaseChart;
PraseJsonDataEditor.serieIndex = index;
PraseJsonDataEditor.ShowWindow();
}
AddSingleLineHeight();
var listSize = m_Datas.arraySize;
listSize = EditorGUI.IntField(drawRect, "Size", listSize);
Expand Down
1 change: 1 addition & 0 deletions Assets/XCharts/Editor/PropertyDrawers/SerieLabelDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
PropertyField(prop, "m_LineType");
PropertyField(prop, "m_LineColor");
PropertyField(prop, "m_LineWidth");
PropertyField(prop, "m_LineGap");
PropertyField(prop, "m_LineLength1");
PropertyField(prop, "m_LineLength2");
PropertyField(prop, "m_TextStyle");
Expand Down
54 changes: 54 additions & 0 deletions Assets/XCharts/Editor/Window/PraseJsonDataEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace XCharts
{
public class PraseJsonDataEditor : EditorWindow
{
public static BaseChart chart;
public static int serieIndex;
private static PraseJsonDataEditor window;
private string inputJsonText = "";

public static void ShowWindow()
{
window = GetWindow<PraseJsonDataEditor>();
window.titleContent = new GUIContent("PraseJsonData");
window.minSize = new Vector2(450, 550);
window.Focus();
window.Show();
}

void OnInspectorUpdate()
{
Repaint();
}

private void OnGUI()
{
if (chart == null)
{
Close();
return;
}
EditorGUILayout.LabelField("Input json data, or echarts serie data:");
inputJsonText = EditorGUILayout.TextArea(inputJsonText, GUILayout.Height(400));
if (GUILayout.Button("Add"))
{
var serie = chart.series.GetSerie(serieIndex);
if (serie != null)
{
serie.ParseJsonData(inputJsonText);
}
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/XCharts/Editor/Window/PraseJsonDataEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Assets/XCharts/Runtime/API/BaseChart_API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,14 @@ public virtual void SetActive(int serieIndex, bool active)
}
}

internal virtual void UpdateLegendColor(string legendName, bool active)
public virtual void UpdateLegendColor(string legendName, bool active)
{
var legendIndex = m_LegendRealShowName.IndexOf(legendName);
if (legendIndex >= 0)
{
foreach (var legend in m_Legends)
{
var iconColor = LegendHelper.GetIconColor(legend, legendIndex, m_Theme, m_Series, legendName, active);
var iconColor = LegendHelper.GetIconColor(this, legendIndex, legendName, active);
var contentColor = LegendHelper.GetContentColor(legend, m_Theme, active);
legend.UpdateButtonColor(legendName, iconColor);
legend.UpdateContentColor(legendName, contentColor);
Expand Down Expand Up @@ -775,6 +775,11 @@ public virtual string GetCustomSerieTypeName()
return null;
}

public virtual bool GetCustomSerieDataNameForColor()
{
return false;
}

public int GetLegendRealShowNameIndex(string name)
{
return m_LegendRealShowName.IndexOf(name);
Expand Down
82 changes: 79 additions & 3 deletions Assets/XCharts/Runtime/Component/Main/Serie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,35 @@ public enum SampleType
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>
Expand Down Expand Up @@ -263,6 +292,8 @@ public class Serie : MainComponent

[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;
Expand Down Expand Up @@ -303,6 +334,10 @@ public class Serie : MainComponent
[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;
Expand Down Expand Up @@ -627,22 +662,38 @@ public float[] radius
set { if (value != null && value.Length == 2) { m_Radius = value; SetVerticesDirty(); } }
}
/// <summary>
/// 最小值,映射到 startAngle
/// 最小值。
/// </summary>
public float min
{
get { return m_Min; }
set { if (PropertyUtil.SetStruct(ref m_Min, value)) SetVerticesDirty(); }
}
/// <summary>
/// 最大值,映射到 endAngle
/// 最大值。
/// </summary>
public float max
{
get { return m_Max; }
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
Expand Down Expand Up @@ -975,6 +1026,30 @@ public bool insertDataToHead
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; } }
Expand Down Expand Up @@ -1078,6 +1153,7 @@ public override void ClearComponentDirty()
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()
Expand Down Expand Up @@ -1584,7 +1660,7 @@ public List<SerieData> GetDataList(DataZoom dataZoom = null)
}
else
{
return m_Data;
return runtimeFilterData.Count > 0 ? runtimeFilterData : m_Data;
}
}

Expand Down
26 changes: 26 additions & 0 deletions Assets/XCharts/Runtime/Component/Sub/SerieData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ internal set
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()
{
Expand Down Expand Up @@ -381,5 +382,30 @@ public void SetLabelActive(bool flag)
{
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;
}
}
}
Loading

0 comments on commit f1a1483

Please sign in to comment.