mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-17 14:00:12 +00:00
重构代码,增加BaseGraph基类
This commit is contained in:
@@ -31,32 +31,32 @@ namespace XCharts.Examples
|
||||
chart.onScroll = OnScroll;
|
||||
}
|
||||
|
||||
void OnPointerEnter(BaseChart chart, PointerEventData eventData)
|
||||
void OnPointerEnter(BaseGraph chart, PointerEventData eventData)
|
||||
{
|
||||
//Debug.LogError("enter:" + chart);
|
||||
}
|
||||
|
||||
void OnPointerExit(BaseChart chart, PointerEventData eventData)
|
||||
void OnPointerExit(BaseGraph chart, PointerEventData eventData)
|
||||
{
|
||||
//Debug.LogError("exit:" + chart);
|
||||
}
|
||||
|
||||
void OnPointerDown(BaseChart chart, PointerEventData eventData)
|
||||
void OnPointerDown(BaseGraph chart, PointerEventData eventData)
|
||||
{
|
||||
//Debug.LogError("down:" + chart);
|
||||
}
|
||||
|
||||
void OnPointerUp(BaseChart chart, PointerEventData eventData)
|
||||
void OnPointerUp(BaseGraph chart, PointerEventData eventData)
|
||||
{
|
||||
//Debug.LogError("up:" + chart);
|
||||
}
|
||||
|
||||
void OnPointerClick(BaseChart chart, PointerEventData eventData)
|
||||
void OnPointerClick(BaseGraph chart, PointerEventData eventData)
|
||||
{
|
||||
//Debug.LogError("click:" + chart);
|
||||
}
|
||||
|
||||
void OnScroll(BaseChart chart, PointerEventData eventData)
|
||||
void OnScroll(BaseGraph chart, PointerEventData eventData)
|
||||
{
|
||||
//Debug.LogError("scroll:" + chart);
|
||||
}
|
||||
|
||||
@@ -9,13 +9,12 @@ using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// The base class of all charts.
|
||||
/// 所有Chart的基类,不可直接使用。
|
||||
/// 所有Chart的基类。
|
||||
/// </summary>
|
||||
public partial class BaseChart
|
||||
{
|
||||
@@ -92,76 +91,19 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Vector3 chartPosition { get { return m_ChartPosition; } }
|
||||
public Rect chartRect { get { return m_ChartRect; } }
|
||||
/// <summary>
|
||||
/// The postion of pointer.
|
||||
/// 鼠标位置
|
||||
/// </summary>
|
||||
public Vector2 pointerPos { get; protected set; }
|
||||
/// <summary>
|
||||
/// 警告信息。
|
||||
/// </summary>
|
||||
public string warningInfo { get; protected set; }
|
||||
public bool isControlledByLayout { get { return m_IsControlledByLayout; } }
|
||||
/// <summary>
|
||||
/// 强制开启鼠标事件检测。
|
||||
/// </summary>
|
||||
public bool forceOpenRaycastTarget { get { return m_ForceOpenRaycastTarget; } set { m_ForceOpenRaycastTarget = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义绘制回调。
|
||||
/// </summary>
|
||||
public Action<VertexHelper> onCustomDraw { set { m_OnCustomDrawCallback = value; } }
|
||||
/// <summary>
|
||||
/// 鼠标点击回调。
|
||||
/// </summary>
|
||||
public Action<BaseChart, PointerEventData> onPointerClick { set { m_OnPointerClick = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标按下回调。
|
||||
/// </summary>
|
||||
public Action<BaseChart, PointerEventData> onPointerDown { set { m_OnPointerDown = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标弹起回调。
|
||||
/// </summary>
|
||||
public Action<BaseChart, PointerEventData> onPointerUp { set { m_OnPointerUp = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标进入回调。
|
||||
/// </summary>
|
||||
public Action<BaseChart, PointerEventData> onPointerEnter { set { m_OnPointerEnter = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标退出回调。
|
||||
/// </summary>
|
||||
public Action<BaseChart, PointerEventData> onPointerExit { set { m_OnPointerExit = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标开始拖拽回调。
|
||||
/// </summary>
|
||||
public Action<BaseChart, PointerEventData> onBeginDrag { set { m_OnBeginDrag = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标拖拽回调。
|
||||
/// </summary>
|
||||
public Action<BaseChart, PointerEventData> onDrag { set { m_OnDrag = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标结束拖拽回调。
|
||||
/// </summary>
|
||||
public Action<BaseChart, PointerEventData> onEndDrag { set { m_OnEndDrag = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标滚动回调。
|
||||
/// </summary>
|
||||
public Action<BaseChart, PointerEventData> onScroll { set { m_OnScroll = value; m_ForceOpenRaycastTarget = true; } }
|
||||
|
||||
/// <summary>
|
||||
/// 设置图表的宽高(在非stretch pivot下才有效,其他情况需要自己调整RectTransform)
|
||||
/// Redraw chart in next frame.
|
||||
/// 在下一帧刷新图表。
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
public virtual void SetSize(float width, float height)
|
||||
public void RefreshChart()
|
||||
{
|
||||
if (LayerHelper.IsFixedWidthHeight(rectTransform))
|
||||
{
|
||||
rectTransform.sizeDelta = new Vector2(width, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Can't set size on stretch pivot,you need to modify rectTransform by yourself.");
|
||||
}
|
||||
m_RefreshChart = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -562,17 +504,6 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redraw chart in next frame.
|
||||
/// 在下一帧刷新图表。
|
||||
/// </summary>
|
||||
public void RefreshChart()
|
||||
{
|
||||
m_RefreshChart = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 刷新文本标签Label,重新初始化,当有改动Label参数时手动调用改接口
|
||||
/// </summary>
|
||||
@@ -718,16 +649,6 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测警告信息。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string CheckWarning()
|
||||
{
|
||||
warningInfo = CheckHelper.CheckChart(this);
|
||||
return warningInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以开启背景组件。背景组件在chart受上层布局控制时无法开启。
|
||||
/// </summary>
|
||||
|
||||
133
Runtime/API/BaseGraph_API.cs
Normal file
133
Runtime/API/BaseGraph_API.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// The base class of all graphs or components.
|
||||
/// 所有图形的基类。
|
||||
/// </summary>
|
||||
public partial class BaseGraph
|
||||
{
|
||||
/// <summary>
|
||||
/// The x of graph.
|
||||
/// 图表的X
|
||||
/// </summary>
|
||||
public float graphX { get { return m_GraphX; } }
|
||||
/// <summary>
|
||||
/// The y of graph.
|
||||
/// 图表的Y
|
||||
/// </summary>
|
||||
public float graphY { get { return m_GraphY; } }
|
||||
/// <summary>
|
||||
/// The width of graph.
|
||||
/// 图表的宽
|
||||
/// </summary>
|
||||
public float graphWidth { get { return m_GraphWidth; } }
|
||||
/// <summary>
|
||||
/// The height of graph.
|
||||
/// 图表的高
|
||||
/// </summary>
|
||||
public float graphHeight { get { return m_GraphHeight; } }
|
||||
/// <summary>
|
||||
/// The position of graph.
|
||||
/// 图表的左下角起始坐标。
|
||||
/// </summary>
|
||||
public Vector3 graphPosition { get { return m_GraphPosition; } }
|
||||
public Rect graphRect { get { return m_GraphRect; } }
|
||||
/// <summary>
|
||||
/// The postion of pointer.
|
||||
/// 鼠标位置
|
||||
/// </summary>
|
||||
public Vector2 pointerPos { get; protected set; }
|
||||
/// <summary>
|
||||
/// 警告信息。
|
||||
/// </summary>
|
||||
public string warningInfo { get; protected set; }
|
||||
public bool isControlledByLayout { get { return m_IsControlledByLayout; } }
|
||||
/// <summary>
|
||||
/// 强制开启鼠标事件检测。
|
||||
/// </summary>
|
||||
public bool forceOpenRaycastTarget { get { return m_ForceOpenRaycastTarget; } set { m_ForceOpenRaycastTarget = value; } }
|
||||
/// <summary>
|
||||
/// 鼠标点击回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onPointerClick { set { m_OnPointerClick = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标按下回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onPointerDown { set { m_OnPointerDown = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标弹起回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onPointerUp { set { m_OnPointerUp = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标进入回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onPointerEnter { set { m_OnPointerEnter = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标退出回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onPointerExit { set { m_OnPointerExit = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标开始拖拽回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onBeginDrag { set { m_OnBeginDrag = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标拖拽回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onDrag { set { m_OnDrag = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标结束拖拽回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onEndDrag { set { m_OnEndDrag = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标滚动回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onScroll { set { m_OnScroll = value; m_ForceOpenRaycastTarget = true; } }
|
||||
|
||||
/// <summary>
|
||||
/// 设置图表的宽高(在非stretch pivot下才有效,其他情况需要自己调整RectTransform)
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
public virtual void SetSize(float width, float height)
|
||||
{
|
||||
if (LayerHelper.IsFixedWidthHeight(rectTransform))
|
||||
{
|
||||
rectTransform.sizeDelta = new Vector2(width, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Can't set size on stretch pivot,you need to modify rectTransform by yourself.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redraw graph in next frame.
|
||||
/// 在下一帧刷新图表。
|
||||
/// </summary>
|
||||
public void RefreshGraph()
|
||||
{
|
||||
m_RefreshChart = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测警告信息。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string CheckWarning()
|
||||
{
|
||||
warningInfo = CheckHelper.CheckChart(this);
|
||||
return warningInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/API/BaseGraph_API.cs.meta
Normal file
11
Runtime/API/BaseGraph_API.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e17adfd3dc62d435cb79fa8c330fe186
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -63,7 +63,7 @@ namespace XCharts
|
||||
[SerializeField] private float m_PaddingLeftRight = 5f;
|
||||
[SerializeField] private float m_PaddingTopBottom = 5f;
|
||||
[SerializeField] private string m_IgnoreDataDefaultContent = "-";
|
||||
[SerializeField] private bool m_AlwayShow = true;
|
||||
[SerializeField] private bool m_AlwayShow = false;
|
||||
[SerializeField] private Sprite m_BackgroundImage;
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle(18, FontStyle.Normal);
|
||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid, 0.7f);
|
||||
|
||||
@@ -15,6 +15,13 @@ namespace XCharts
|
||||
{
|
||||
return !ChartHelper.IsClearColor(color) && color.a == 0;
|
||||
}
|
||||
|
||||
public static string CheckChart(BaseGraph chart)
|
||||
{
|
||||
if (chart is BaseChart) return CheckChart((BaseChart)chart);
|
||||
else return string.Empty;
|
||||
}
|
||||
|
||||
public static string CheckChart(BaseChart chart)
|
||||
{
|
||||
var sb = ChartHelper.sb;
|
||||
|
||||
@@ -30,9 +30,7 @@ namespace XCharts
|
||||
Vertical
|
||||
}
|
||||
|
||||
public partial class BaseChart : MaskableGraphic, IPointerDownHandler, IPointerUpHandler,
|
||||
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler, IPointerClickHandler,
|
||||
IDragHandler, IEndDragHandler, IScrollHandler
|
||||
public partial class BaseChart : BaseGraph
|
||||
{
|
||||
protected static readonly string s_BackgroundObjectName = "background";
|
||||
protected static readonly string s_TitleObjectName = "title";
|
||||
@@ -42,10 +40,7 @@ namespace XCharts
|
||||
protected static readonly string s_SerieTitleObjectName = "serie";
|
||||
|
||||
[SerializeField] protected string m_ChartName;
|
||||
[SerializeField] protected float m_ChartWidth;
|
||||
[SerializeField] protected float m_ChartHeight;
|
||||
[SerializeField] protected float m_ChartX;
|
||||
[SerializeField] protected float m_ChartY;
|
||||
|
||||
[SerializeField] protected ThemeInfo m_ThemeInfo;
|
||||
[SerializeField] protected Title m_Title = Title.defaultTitle;
|
||||
[SerializeField] protected Background m_Background = Background.defaultBackground;
|
||||
@@ -53,27 +48,19 @@ namespace XCharts
|
||||
[SerializeField] protected Tooltip m_Tooltip = Tooltip.defaultTooltip;
|
||||
[SerializeField] protected Series m_Series = Series.defaultSeries;
|
||||
[SerializeField] protected Settings m_Settings = new Settings();
|
||||
[SerializeField] protected bool m_DebugMode = false;
|
||||
|
||||
protected Action<VertexHelper> m_OnCustomDrawCallback;
|
||||
protected Action<BaseChart, PointerEventData> m_OnPointerClick;
|
||||
protected Action<BaseChart, PointerEventData> m_OnPointerDown;
|
||||
protected Action<BaseChart, PointerEventData> m_OnPointerUp;
|
||||
protected Action<BaseChart, PointerEventData> m_OnPointerEnter;
|
||||
protected Action<BaseChart, PointerEventData> m_OnPointerExit;
|
||||
protected Action<BaseChart, PointerEventData> m_OnBeginDrag;
|
||||
protected Action<BaseChart, PointerEventData> m_OnDrag;
|
||||
protected Action<BaseChart, PointerEventData> m_OnEndDrag;
|
||||
protected Action<BaseChart, PointerEventData> m_OnScroll;
|
||||
|
||||
protected float m_ChartWidth;
|
||||
protected float m_ChartHeight;
|
||||
protected float m_ChartX;
|
||||
protected float m_ChartY;
|
||||
protected Vector3 m_ChartPosition = Vector3.zero;
|
||||
protected Vector2 m_ChartMinAnchor;
|
||||
protected Vector2 m_ChartMaxAnchor;
|
||||
protected Vector2 m_ChartPivot;
|
||||
protected Vector2 m_ChartSizeDelta;
|
||||
protected Rect m_ChartRect = new Rect(0, 0, 0, 0);
|
||||
protected Action<VertexHelper> m_OnCustomDrawCallback;
|
||||
|
||||
protected bool m_RefreshChart = false;
|
||||
protected bool m_RefreshLabel = false;
|
||||
protected bool m_ReinitLabel = false;
|
||||
protected bool m_ReinitTitle = false;
|
||||
@@ -82,19 +69,12 @@ namespace XCharts
|
||||
protected List<string> m_LegendRealShowName = new List<string>();
|
||||
protected GameObject m_SerieLabelRoot;
|
||||
protected GameObject m_BackgroundRoot;
|
||||
protected bool m_ForceOpenRaycastTarget;
|
||||
protected bool m_IsControlledByLayout = false;
|
||||
|
||||
protected Vector2 chartAnchorMax { get { return m_ChartMinAnchor; } }
|
||||
protected Vector2 chartAnchorMin { get { return m_ChartMaxAnchor; } }
|
||||
protected Vector2 chartPivot { get { return m_ChartPivot; } }
|
||||
protected HideFlags chartHideFlags { get { return m_DebugMode ? HideFlags.None : HideFlags.HideInHierarchy; } }
|
||||
|
||||
private Theme m_CheckTheme = 0;
|
||||
private Vector3 m_LastLocalPosition;
|
||||
|
||||
protected virtual void InitComponent()
|
||||
protected override void InitComponent()
|
||||
{
|
||||
base.InitComponent();
|
||||
InitBackground();
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
@@ -128,18 +108,16 @@ namespace XCharts
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
protected override void Update()
|
||||
{
|
||||
CheckSize();
|
||||
CheckComponent();
|
||||
CheckPointerPos();
|
||||
base.Update();
|
||||
CheckTooltip();
|
||||
CheckRefreshChart();
|
||||
CheckRefreshLabel();
|
||||
CheckAnimation();
|
||||
}
|
||||
|
||||
protected virtual void CheckComponent()
|
||||
protected override void CheckComponent()
|
||||
{
|
||||
if (m_Series.anyDirty)
|
||||
{
|
||||
@@ -562,72 +540,10 @@ namespace XCharts
|
||||
return m_Legend.location.GetPosition(chartWidth, chartHeight);
|
||||
}
|
||||
|
||||
private void CheckSize()
|
||||
protected override bool IsNeedCheckPointerPos()
|
||||
{
|
||||
var currWidth = rectTransform.rect.width;
|
||||
var currHeight = rectTransform.rect.height;
|
||||
|
||||
if (m_ChartWidth == 0 && m_ChartHeight == 0 && (currWidth != 0 || currHeight != 0))
|
||||
{
|
||||
Awake();
|
||||
}
|
||||
|
||||
if (m_ChartWidth != currWidth || m_ChartHeight != currHeight ||
|
||||
m_ChartMinAnchor != rectTransform.anchorMin || m_ChartMaxAnchor != rectTransform.anchorMax)
|
||||
{
|
||||
UpdateSize();
|
||||
}
|
||||
if (!ChartHelper.IsValueEqualsVector3(m_LastLocalPosition, transform.localPosition))
|
||||
{
|
||||
m_LastLocalPosition = transform.localPosition;
|
||||
OnLocalPositionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSize()
|
||||
{
|
||||
m_ChartWidth = rectTransform.rect.width;
|
||||
m_ChartHeight = rectTransform.rect.height;
|
||||
|
||||
m_ChartMaxAnchor = rectTransform.anchorMax;
|
||||
m_ChartMinAnchor = rectTransform.anchorMin;
|
||||
m_ChartSizeDelta = rectTransform.sizeDelta;
|
||||
m_ReinitLabel = true;
|
||||
|
||||
rectTransform.pivot = LayerHelper.ResetChartPositionAndPivot(m_ChartMinAnchor, m_ChartMaxAnchor,
|
||||
m_ChartWidth, m_ChartHeight, ref m_ChartX, ref m_ChartY);
|
||||
m_ChartPivot = rectTransform.pivot;
|
||||
|
||||
m_ChartRect.x = m_ChartX;
|
||||
m_ChartRect.y = m_ChartY;
|
||||
m_ChartRect.width = m_ChartWidth;
|
||||
m_ChartRect.height = m_ChartHeight;
|
||||
m_ChartPosition.x = m_ChartX;
|
||||
m_ChartPosition.y = m_ChartY;
|
||||
|
||||
OnSizeChanged();
|
||||
}
|
||||
|
||||
private void CheckPointerPos()
|
||||
{
|
||||
if (m_ForceOpenRaycastTarget) raycastTarget = true;
|
||||
var needCheck = (m_Tooltip.show && m_Tooltip.runtimeInited)
|
||||
return (m_Tooltip.show && m_Tooltip.runtimeInited)
|
||||
|| raycastTarget;
|
||||
if (needCheck)
|
||||
{
|
||||
if (canvas == null) return;
|
||||
Vector2 local;
|
||||
var cam = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : canvas.worldCamera;
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||
Input.mousePosition, cam, out local))
|
||||
{
|
||||
pointerPos = Vector2.zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
pointerPos = local;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckTooltip()
|
||||
@@ -675,7 +591,7 @@ namespace XCharts
|
||||
{
|
||||
}
|
||||
|
||||
protected void CheckRefreshChart()
|
||||
protected override void CheckRefreshChart()
|
||||
{
|
||||
if (m_RefreshChart || m_Series.vertsDirty)
|
||||
{
|
||||
@@ -719,8 +635,20 @@ namespace XCharts
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnSizeChanged()
|
||||
protected override void OnSizeChanged()
|
||||
{
|
||||
base.OnSizeChanged();
|
||||
m_ChartWidth = m_GraphWidth;
|
||||
m_ChartHeight = m_GraphHeight;
|
||||
m_ChartX = m_GraphX;
|
||||
m_ChartY = m_GraphY;
|
||||
m_ChartPosition = m_GraphPosition;
|
||||
m_ChartMinAnchor = m_GraphMinAnchor;
|
||||
m_ChartMaxAnchor = m_GraphMaxAnchor;
|
||||
m_ChartPivot = m_GraphPivot;
|
||||
m_ChartSizeDelta = m_GraphSizeDelta;
|
||||
m_ChartRect = m_GraphRect;
|
||||
|
||||
m_Background.SetAllDirty();
|
||||
m_Title.SetAllDirty();
|
||||
m_Legend.SetAllDirty();
|
||||
@@ -730,7 +658,7 @@ namespace XCharts
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected virtual void OnLocalPositionChanged()
|
||||
protected override void OnLocalPositionChanged()
|
||||
{
|
||||
m_Background.SetAllDirty();
|
||||
}
|
||||
@@ -792,7 +720,7 @@ namespace XCharts
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void DrawBackground(VertexHelper vh)
|
||||
protected override void DrawBackground(VertexHelper vh)
|
||||
{
|
||||
Vector3 p1 = new Vector3(chartX, chartY + chartHeight);
|
||||
Vector3 p2 = new Vector3(chartX + chartWidth, chartY + chartHeight);
|
||||
@@ -816,7 +744,7 @@ namespace XCharts
|
||||
if (serieData == null || serieData.labelObject == null) return;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
if (!serieLabel.show) return;
|
||||
var invert = serieLabel.autoOffset
|
||||
var invert = serieLabel.autoOffset
|
||||
&& serie.type == SerieType.Line
|
||||
&& SerieHelper.IsDownPoint(serie, serieData.index)
|
||||
&& !serie.areaStyle.show;
|
||||
@@ -844,50 +772,5 @@ namespace XCharts
|
||||
serieLabel.borderWidth, serieLabel.borderColor, serieLabel.rotate);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerClick != null) m_OnPointerClick(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerDown != null) m_OnPointerDown(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerUp != null) m_OnPointerUp(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerEnter != null) m_OnPointerEnter(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerExit != null) m_OnPointerExit(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnBeginDrag != null) m_OnBeginDrag(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnEndDrag != null) m_OnEndDrag(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnDrag != null) m_OnDrag(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnScroll(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnScroll != null) m_OnScroll(this, eventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
261
Runtime/Internal/BaseGraphic.cs
Normal file
261
Runtime/Internal/BaseGraphic.cs
Normal file
@@ -0,0 +1,261 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public partial class BaseGraph : MaskableGraphic, IPointerDownHandler, IPointerUpHandler,
|
||||
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler, IPointerClickHandler,
|
||||
IDragHandler, IEndDragHandler, IScrollHandler
|
||||
{
|
||||
[SerializeField] protected bool m_DebugMode = false;
|
||||
|
||||
protected float m_GraphWidth;
|
||||
protected float m_GraphHeight;
|
||||
protected float m_GraphX;
|
||||
protected float m_GraphY;
|
||||
protected Vector3 m_GraphPosition = Vector3.zero;
|
||||
protected Vector2 m_GraphMinAnchor;
|
||||
protected Vector2 m_GraphMaxAnchor;
|
||||
protected Vector2 m_GraphPivot;
|
||||
protected Vector2 m_GraphSizeDelta;
|
||||
protected Rect m_GraphRect = new Rect(0, 0, 0, 0);
|
||||
protected bool m_RefreshChart = false;
|
||||
protected bool m_ForceOpenRaycastTarget;
|
||||
protected bool m_IsControlledByLayout = false;
|
||||
protected Vector3 m_LastLocalPosition;
|
||||
|
||||
protected Action<BaseGraph, PointerEventData> m_OnPointerClick;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnPointerDown;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnPointerUp;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnPointerEnter;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnPointerExit;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnBeginDrag;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnDrag;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnEndDrag;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnScroll;
|
||||
|
||||
protected Vector2 chartAnchorMax { get { return m_GraphMinAnchor; } }
|
||||
protected Vector2 chartAnchorMin { get { return m_GraphMaxAnchor; } }
|
||||
protected Vector2 chartPivot { get { return m_GraphPivot; } }
|
||||
protected HideFlags chartHideFlags { get { return m_DebugMode ? HideFlags.None : HideFlags.HideInHierarchy; } }
|
||||
|
||||
|
||||
protected virtual void InitComponent()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
if (transform.parent != null)
|
||||
{
|
||||
m_IsControlledByLayout = transform.parent.GetComponent<LayoutGroup>() != null;
|
||||
}
|
||||
raycastTarget = false;
|
||||
m_LastLocalPosition = transform.localPosition;
|
||||
UpdateSize();
|
||||
InitComponent();
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
m_RefreshChart = true;
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
CheckSize();
|
||||
CheckComponent();
|
||||
CheckPointerPos();
|
||||
CheckRefreshChart();
|
||||
}
|
||||
|
||||
protected virtual void CheckComponent()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnValidate()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
for (int i = transform.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
DestroyImmediate(transform.GetChild(i).gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckSize()
|
||||
{
|
||||
var currWidth = rectTransform.rect.width;
|
||||
var currHeight = rectTransform.rect.height;
|
||||
|
||||
if (m_GraphWidth == 0 && m_GraphHeight == 0 && (currWidth != 0 || currHeight != 0))
|
||||
{
|
||||
Awake();
|
||||
}
|
||||
|
||||
if (m_GraphWidth != currWidth || m_GraphHeight != currHeight ||
|
||||
m_GraphMinAnchor != rectTransform.anchorMin || m_GraphMaxAnchor != rectTransform.anchorMax)
|
||||
{
|
||||
UpdateSize();
|
||||
}
|
||||
if (!ChartHelper.IsValueEqualsVector3(m_LastLocalPosition, transform.localPosition))
|
||||
{
|
||||
m_LastLocalPosition = transform.localPosition;
|
||||
OnLocalPositionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateSize()
|
||||
{
|
||||
m_GraphWidth = rectTransform.rect.width;
|
||||
m_GraphHeight = rectTransform.rect.height;
|
||||
|
||||
m_GraphMaxAnchor = rectTransform.anchorMax;
|
||||
m_GraphMinAnchor = rectTransform.anchorMin;
|
||||
m_GraphSizeDelta = rectTransform.sizeDelta;
|
||||
|
||||
rectTransform.pivot = LayerHelper.ResetChartPositionAndPivot(m_GraphMinAnchor, m_GraphMaxAnchor,
|
||||
m_GraphWidth, m_GraphHeight, ref m_GraphX, ref m_GraphY);
|
||||
m_GraphPivot = rectTransform.pivot;
|
||||
|
||||
m_GraphRect.x = m_GraphX;
|
||||
m_GraphRect.y = m_GraphY;
|
||||
m_GraphRect.width = m_GraphWidth;
|
||||
m_GraphRect.height = m_GraphHeight;
|
||||
m_GraphPosition.x = m_GraphX;
|
||||
m_GraphPosition.y = m_GraphY;
|
||||
|
||||
OnSizeChanged();
|
||||
}
|
||||
|
||||
private void CheckPointerPos()
|
||||
{
|
||||
if (m_ForceOpenRaycastTarget) raycastTarget = true;
|
||||
if (IsNeedCheckPointerPos())
|
||||
{
|
||||
if (canvas == null) return;
|
||||
Vector2 local;
|
||||
var cam = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : canvas.worldCamera;
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||
Input.mousePosition, cam, out local))
|
||||
{
|
||||
pointerPos = Vector2.zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
pointerPos = local;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool IsNeedCheckPointerPos()
|
||||
{
|
||||
return raycastTarget;
|
||||
}
|
||||
|
||||
protected virtual void CheckRefreshChart()
|
||||
{
|
||||
if (m_RefreshChart)
|
||||
{
|
||||
SetVerticesDirty();
|
||||
m_RefreshChart = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnSizeChanged()
|
||||
{
|
||||
m_RefreshChart = true;
|
||||
}
|
||||
|
||||
protected virtual void OnLocalPositionChanged()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
vh.Clear();
|
||||
DrawBackground(vh);
|
||||
DrawGraphic(vh);
|
||||
}
|
||||
|
||||
protected virtual void DrawGraphic(VertexHelper vh)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void DrawBackground(VertexHelper vh)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerClick != null) m_OnPointerClick(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerDown != null) m_OnPointerDown(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerUp != null) m_OnPointerUp(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerEnter != null) m_OnPointerEnter(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerExit != null) m_OnPointerExit(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnBeginDrag != null) m_OnBeginDrag(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnEndDrag != null) m_OnEndDrag(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnDrag != null) m_OnDrag(this, eventData);
|
||||
}
|
||||
|
||||
public virtual void OnScroll(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnScroll != null) m_OnScroll(this, eventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/BaseGraphic.cs.meta
Normal file
11
Runtime/Internal/BaseGraphic.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aeefeda71c22e4a9dbbadcf703048287
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user