Skip to content

Commit

Permalink
完善SerieSymbol以支持象形柱图PictorialBarChart扩展
Browse files Browse the repository at this point in the history
  • Loading branch information
monitor1394 committed Jul 22, 2021
1 parent b20e768 commit bdd53bb
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 11 deletions.
1 change: 1 addition & 0 deletions Assets/XCharts/CHANGELOG-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

## master

* (2021.07.22) Improved `SerieSymbol` to support `PictorialBarchart` extension
* (2021.07.19) Fixed issue where `Tooltip` was not displayed on `WdbGL` platform
* (2021.07.18) Added `iconStyle` for serie
* (2021.07.15) Added `MarkLine` (#142)
Expand Down
1 change: 1 addition & 0 deletions Assets/XCharts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

## master

* (2021.07.22) 完善`SerieSymbol`以支持象形柱图`PictorialBarChart`扩展
* (2021.07.19) 修复`WdbGL`平台上`Tooltip`不显示的问题
* (2021.07.18) 增加`Serie``iconStyle`统一配置图标
* (2021.07.15) 增加`MarkLine`标线 (#142)
Expand Down
20 changes: 15 additions & 5 deletions Assets/XCharts/Editor/PropertyDrawers/SerieSymbolDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,36 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
if (MakeFoldout(prop, "m_Show"))
{
++EditorGUI.indentLevel;
var type = (SerieSymbolType)prop.FindPropertyRelative("m_Type").enumValueIndex;
PropertyField(prop, "m_Type");
if (type == SerieSymbolType.Custom)
{
PropertyField(prop, "m_Image");
PropertyField(prop, "m_ImageType");
PropertyField(prop, "m_Width");
// PropertyField(prop, "m_Height");
// PropertyField(prop, "m_Offset");
}
PropertyField(prop, "m_Gap");
PropertyField(prop, "m_SizeType");
switch ((SerieSymbolSizeType)prop.FindPropertyRelative("m_SizeType").enumValueIndex)
{
case SerieSymbolSizeType.Custom:
PropertyField(prop, "m_Size");
PropertyField(prop, "m_SelectedSize");
PropertyField(prop, "m_Size");
PropertyField(prop, "m_SelectedSize");
break;
case SerieSymbolSizeType.FromData:
PropertyField(prop, "m_DataIndex");
PropertyField(prop, "m_DataScale");
PropertyField(prop, "m_SelectedDataScale");
PropertyField(prop, "m_DataIndex");
PropertyField(prop, "m_DataScale");
PropertyField(prop, "m_SelectedDataScale");
break;
case SerieSymbolSizeType.Callback:
break;
}
PropertyField(prop, "m_StartIndex");
PropertyField(prop, "m_Interval");
PropertyField(prop, "m_ForceShowLast");
PropertyField(prop, "m_Repeat");
--EditorGUI.indentLevel;
}
}
Expand Down
6 changes: 4 additions & 2 deletions Assets/XCharts/Runtime/API/BaseGraph_API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ public void RemoveChartObject()

public bool ScreenPointToChartPoint(Vector2 screenPoint, out Vector2 chartPoint)
{
#if UNITY_STANDALONE
screenPoint = Display.RelativeMouseAt(screenPoint);
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
var relative = Display.RelativeMouseAt(screenPoint);
if(relative != Vector3.zero)
screenPoint = relative;
#endif
var cam = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : canvas.worldCamera;
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
Expand Down
2 changes: 2 additions & 0 deletions Assets/XCharts/Runtime/Component/Sub/SerieData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace XCharts
{
Expand Down Expand Up @@ -176,6 +177,7 @@ internal set
public float runtimeAngle { get; set; }
public Vector3 runtiemPieOffsetCenter { get; set; }
public float runtimeStackHig { get; set; }
public Image runtimeSymbol { get; set; }
private List<double> m_PreviousData = new List<double>();
private List<float> m_DataUpdateTime = new List<float>();
private List<bool> m_DataUpdateFlag = new List<bool>();
Expand Down
65 changes: 64 additions & 1 deletion Assets/XCharts/Runtime/Component/Sub/SerieSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace XCharts
{
Expand Down Expand Up @@ -43,7 +44,11 @@ public enum SerieSymbolType
/// <summary>
/// 箭头。
/// </summary>
Arrow
Arrow,
/// <summary>
/// 自定义标记。
/// </summary>
Custom
}

/// <summary>
Expand Down Expand Up @@ -96,6 +101,12 @@ public class SerieSymbol : SubComponent
[SerializeField] private int m_Interval;
[SerializeField] private bool m_ForceShowLast = false;
[SerializeField] private float m_Gap = 0;
[SerializeField] private float m_Width = 0f;
[SerializeField] private float m_Height = 0f;
[SerializeField] private bool m_Repeat = false;
[SerializeField] private Vector2 m_Offset = Vector2.zero;
[SerializeField] private Sprite m_Image;
[SerializeField] private Image.Type m_ImageType;

public void Reset()
{
Expand All @@ -113,6 +124,12 @@ public void Reset()
m_Interval = 0;
m_ForceShowLast = false;
m_Gap = 0;
m_Width = 0f;
m_Height = 0f;
m_Repeat = false;
m_Offset = Vector2.zero;
m_Image = null;
m_ImageType = Image.Type.Simple;
}

/// <summary>
Expand Down Expand Up @@ -241,6 +258,52 @@ public float gap
get { return m_Gap; }
set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetVerticesDirty(); }
}
/// <summary>
/// 图形的宽。
/// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetAllDirty(); }
}
/// <summary>
/// 图形的高。
/// </summary>
public float height
{
get { return m_Height; }
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetAllDirty(); }
}
/// <summary>
/// 图形是否重复。
/// </summary>
public bool repeat
{
get { return m_Repeat; }
set { if (PropertyUtil.SetStruct(ref m_Repeat, value)) SetAllDirty(); }
}
/// <summary>
/// 自定义的标记图形。
/// </summary>
public Sprite image
{
get { return m_Image; }
set { if (PropertyUtil.SetClass(ref m_Image, value)) SetAllDirty(); }
}
public Image.Type imageType
{
get { return m_ImageType; }
set { if (PropertyUtil.SetStruct(ref m_ImageType, value)) SetAllDirty(); }
}
/// <summary>
/// 图形的偏移。
/// </summary>
public Vector2 offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetAllDirty(); }
}
public Vector3 offset3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
private List<float> m_AnimationSize = new List<float>() { 0, 5, 10 };
/// <summary>
/// the setting for effect scatter.
Expand Down
2 changes: 1 addition & 1 deletion Assets/XCharts/Runtime/Internal/BaseChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected override void Update()
foreach (var draw in m_ComponentHandlers) draw.Update();
}

internal Painter GetPainter(int index)
public Painter GetPainter(int index)
{
if (index >= 0 && index < m_PainterList.Count)
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/XCharts/Runtime/Internal/BaseGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public partial class BaseGraph : MaskableGraphic, IPointerDownHandler, IPointerU
protected Vector2 graphAnchorMax { get { return m_GraphMinAnchor; } }
protected Vector2 graphAnchorMin { get { return m_GraphMaxAnchor; } }
protected Vector2 graphPivot { get { return m_GraphPivot; } }
internal HideFlags chartHideFlags { get { return m_DebugMode ? HideFlags.None : HideFlags.HideInHierarchy; } }
public HideFlags chartHideFlags { get { return m_DebugMode ? HideFlags.None : HideFlags.HideInHierarchy; } }

private ScrollRect m_ScrollRect;

Expand Down
12 changes: 11 additions & 1 deletion Assets/XCharts/Runtime/Internal/Utility/ChartHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ internal static Painter AddPainterObject(string name, Transform parent, Vector2
return ChartHelper.GetOrAddComponent<Painter>(painterObj);
}

public static Image AddIcon(string name, Transform parent, float width, float height)
public static Image AddIcon(string name, Transform parent, float width, float height, Sprite sprite = null,
Image.Type type = Image.Type.Simple)
{
var anchorMax = new Vector2(0.5f, 0.5f);
var anchorMin = new Vector2(0.5f, 0.5f);
Expand All @@ -396,6 +397,15 @@ public static Image AddIcon(string name, Transform parent, float width, float he
GameObject iconObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
var img = GetOrAddComponent<Image>(iconObj);
img.raycastTarget = false;
img.type = type;
if (sprite != null)
{
img.sprite = sprite;
if (width == 0 || height == 0)
{
img.SetNativeSize();
}
}
return img;
}

Expand Down

0 comments on commit bdd53bb

Please sign in to comment.