diff --git a/Examples/Runtime/Example02_ChartEvent.cs b/Examples/Runtime/Example02_ChartEvent.cs
index 3686a14d..4be8cdc1 100644
--- a/Examples/Runtime/Example02_ChartEvent.cs
+++ b/Examples/Runtime/Example02_ChartEvent.cs
@@ -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);
}
diff --git a/Runtime/API/BaseChart_API.cs b/Runtime/API/BaseChart_API.cs
index 4f4e0325..adf5d7cc 100644
--- a/Runtime/API/BaseChart_API.cs
+++ b/Runtime/API/BaseChart_API.cs
@@ -9,13 +9,12 @@ using UnityEngine;
using System.Collections.Generic;
using System;
using UnityEngine.UI;
-using UnityEngine.EventSystems;
namespace XCharts
{
///
/// The base class of all charts.
- /// 所有Chart的基类,不可直接使用。
+ /// 所有Chart的基类。
///
public partial class BaseChart
{
@@ -92,76 +91,19 @@ namespace XCharts
///
public Vector3 chartPosition { get { return m_ChartPosition; } }
public Rect chartRect { get { return m_ChartRect; } }
- ///
- /// The postion of pointer.
- /// 鼠标位置
- ///
- public Vector2 pointerPos { get; protected set; }
- ///
- /// 警告信息。
- ///
- public string warningInfo { get; protected set; }
- public bool isControlledByLayout { get { return m_IsControlledByLayout; } }
- ///
- /// 强制开启鼠标事件检测。
- ///
- public bool forceOpenRaycastTarget { get { return m_ForceOpenRaycastTarget; } set { m_ForceOpenRaycastTarget = value; } }
+
///
/// 自定义绘制回调。
///
public Action onCustomDraw { set { m_OnCustomDrawCallback = value; } }
- ///
- /// 鼠标点击回调。
- ///
- public Action onPointerClick { set { m_OnPointerClick = value; m_ForceOpenRaycastTarget = true; } }
- ///
- /// 鼠标按下回调。
- ///
- public Action onPointerDown { set { m_OnPointerDown = value; m_ForceOpenRaycastTarget = true; } }
- ///
- /// 鼠标弹起回调。
- ///
- public Action onPointerUp { set { m_OnPointerUp = value; m_ForceOpenRaycastTarget = true; } }
- ///
- /// 鼠标进入回调。
- ///
- public Action onPointerEnter { set { m_OnPointerEnter = value; m_ForceOpenRaycastTarget = true; } }
- ///
- /// 鼠标退出回调。
- ///
- public Action onPointerExit { set { m_OnPointerExit = value; m_ForceOpenRaycastTarget = true; } }
- ///
- /// 鼠标开始拖拽回调。
- ///
- public Action onBeginDrag { set { m_OnBeginDrag = value; m_ForceOpenRaycastTarget = true; } }
- ///
- /// 鼠标拖拽回调。
- ///
- public Action onDrag { set { m_OnDrag = value; m_ForceOpenRaycastTarget = true; } }
- ///
- /// 鼠标结束拖拽回调。
- ///
- public Action onEndDrag { set { m_OnEndDrag = value; m_ForceOpenRaycastTarget = true; } }
- ///
- /// 鼠标滚动回调。
- ///
- public Action onScroll { set { m_OnScroll = value; m_ForceOpenRaycastTarget = true; } }
///
- /// 设置图表的宽高(在非stretch pivot下才有效,其他情况需要自己调整RectTransform)
+ /// Redraw chart in next frame.
+ /// 在下一帧刷新图表。
///
- ///
- ///
- 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;
}
///
@@ -562,17 +504,6 @@ namespace XCharts
return false;
}
- ///
- /// Redraw chart in next frame.
- /// 在下一帧刷新图表。
- ///
- public void RefreshChart()
- {
- m_RefreshChart = true;
- }
-
-
-
///
/// 刷新文本标签Label,重新初始化,当有改动Label参数时手动调用改接口
///
@@ -718,16 +649,6 @@ namespace XCharts
}
}
- ///
- /// 检测警告信息。
- ///
- ///
- public string CheckWarning()
- {
- warningInfo = CheckHelper.CheckChart(this);
- return warningInfo;
- }
-
///
/// 是否可以开启背景组件。背景组件在chart受上层布局控制时无法开启。
///
diff --git a/Runtime/API/BaseGraph_API.cs b/Runtime/API/BaseGraph_API.cs
new file mode 100644
index 00000000..0dd379c5
--- /dev/null
+++ b/Runtime/API/BaseGraph_API.cs
@@ -0,0 +1,133 @@
+/******************************************/
+/* */
+/* Copyright (c) 2018 monitor1394 */
+/* https://github.com/monitor1394 */
+/* */
+/******************************************/
+
+using UnityEngine;
+using System;
+using UnityEngine.EventSystems;
+
+namespace XCharts
+{
+ ///
+ /// The base class of all graphs or components.
+ /// 所有图形的基类。
+ ///
+ public partial class BaseGraph
+ {
+ ///
+ /// The x of graph.
+ /// 图表的X
+ ///
+ public float graphX { get { return m_GraphX; } }
+ ///
+ /// The y of graph.
+ /// 图表的Y
+ ///
+ public float graphY { get { return m_GraphY; } }
+ ///
+ /// The width of graph.
+ /// 图表的宽
+ ///
+ public float graphWidth { get { return m_GraphWidth; } }
+ ///
+ /// The height of graph.
+ /// 图表的高
+ ///
+ public float graphHeight { get { return m_GraphHeight; } }
+ ///
+ /// The position of graph.
+ /// 图表的左下角起始坐标。
+ ///
+ public Vector3 graphPosition { get { return m_GraphPosition; } }
+ public Rect graphRect { get { return m_GraphRect; } }
+ ///
+ /// The postion of pointer.
+ /// 鼠标位置
+ ///
+ public Vector2 pointerPos { get; protected set; }
+ ///
+ /// 警告信息。
+ ///
+ public string warningInfo { get; protected set; }
+ public bool isControlledByLayout { get { return m_IsControlledByLayout; } }
+ ///
+ /// 强制开启鼠标事件检测。
+ ///
+ public bool forceOpenRaycastTarget { get { return m_ForceOpenRaycastTarget; } set { m_ForceOpenRaycastTarget = value; } }
+ ///
+ /// 鼠标点击回调。
+ ///
+ public Action onPointerClick { set { m_OnPointerClick = value; m_ForceOpenRaycastTarget = true; } }
+ ///
+ /// 鼠标按下回调。
+ ///
+ public Action onPointerDown { set { m_OnPointerDown = value; m_ForceOpenRaycastTarget = true; } }
+ ///
+ /// 鼠标弹起回调。
+ ///
+ public Action onPointerUp { set { m_OnPointerUp = value; m_ForceOpenRaycastTarget = true; } }
+ ///
+ /// 鼠标进入回调。
+ ///
+ public Action onPointerEnter { set { m_OnPointerEnter = value; m_ForceOpenRaycastTarget = true; } }
+ ///
+ /// 鼠标退出回调。
+ ///
+ public Action onPointerExit { set { m_OnPointerExit = value; m_ForceOpenRaycastTarget = true; } }
+ ///
+ /// 鼠标开始拖拽回调。
+ ///
+ public Action onBeginDrag { set { m_OnBeginDrag = value; m_ForceOpenRaycastTarget = true; } }
+ ///
+ /// 鼠标拖拽回调。
+ ///
+ public Action onDrag { set { m_OnDrag = value; m_ForceOpenRaycastTarget = true; } }
+ ///
+ /// 鼠标结束拖拽回调。
+ ///
+ public Action onEndDrag { set { m_OnEndDrag = value; m_ForceOpenRaycastTarget = true; } }
+ ///
+ /// 鼠标滚动回调。
+ ///
+ public Action onScroll { set { m_OnScroll = value; m_ForceOpenRaycastTarget = true; } }
+
+ ///
+ /// 设置图表的宽高(在非stretch pivot下才有效,其他情况需要自己调整RectTransform)
+ ///
+ ///
+ ///
+ 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.");
+ }
+ }
+
+ ///
+ /// Redraw graph in next frame.
+ /// 在下一帧刷新图表。
+ ///
+ public void RefreshGraph()
+ {
+ m_RefreshChart = true;
+ }
+
+ ///
+ /// 检测警告信息。
+ ///
+ ///
+ public string CheckWarning()
+ {
+ warningInfo = CheckHelper.CheckChart(this);
+ return warningInfo;
+ }
+ }
+}
diff --git a/Runtime/API/BaseGraph_API.cs.meta b/Runtime/API/BaseGraph_API.cs.meta
new file mode 100644
index 00000000..f685568a
--- /dev/null
+++ b/Runtime/API/BaseGraph_API.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e17adfd3dc62d435cb79fa8c330fe186
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Runtime/Component/Main/Tooltip.cs b/Runtime/Component/Main/Tooltip.cs
index 2f01f68f..26d7ed4f 100644
--- a/Runtime/Component/Main/Tooltip.cs
+++ b/Runtime/Component/Main/Tooltip.cs
@@ -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);
diff --git a/Runtime/Helper/CheckHelper.cs b/Runtime/Helper/CheckHelper.cs
index 2dc8dd5c..3c2850b5 100644
--- a/Runtime/Helper/CheckHelper.cs
+++ b/Runtime/Helper/CheckHelper.cs
@@ -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;
diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs
index 19b6a05c..e871ac33 100644
--- a/Runtime/Internal/BaseChart.cs
+++ b/Runtime/Internal/BaseChart.cs
@@ -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 m_OnCustomDrawCallback;
- protected Action m_OnPointerClick;
- protected Action m_OnPointerDown;
- protected Action m_OnPointerUp;
- protected Action m_OnPointerEnter;
- protected Action m_OnPointerExit;
- protected Action m_OnBeginDrag;
- protected Action m_OnDrag;
- protected Action m_OnEndDrag;
- protected Action 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 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 m_LegendRealShowName = new List();
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);
- }
}
}
diff --git a/Runtime/Internal/BaseGraphic.cs b/Runtime/Internal/BaseGraphic.cs
new file mode 100644
index 00000000..6ab228d4
--- /dev/null
+++ b/Runtime/Internal/BaseGraphic.cs
@@ -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 m_OnPointerClick;
+ protected Action m_OnPointerDown;
+ protected Action m_OnPointerUp;
+ protected Action m_OnPointerEnter;
+ protected Action m_OnPointerExit;
+ protected Action m_OnBeginDrag;
+ protected Action m_OnDrag;
+ protected Action m_OnEndDrag;
+ protected Action 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() != 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);
+ }
+ }
+}
diff --git a/Runtime/Internal/BaseGraphic.cs.meta b/Runtime/Internal/BaseGraphic.cs.meta
new file mode 100644
index 00000000..0d0df077
--- /dev/null
+++ b/Runtime/Internal/BaseGraphic.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: aeefeda71c22e4a9dbbadcf703048287
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: