mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-20 07:20:08 +00:00
整理代码结构,支持Package Manager添加
This commit is contained in:
39
Scripts/Runtime/Internal/AxisPool.cs
Normal file
39
Scripts/Runtime/Internal/AxisPool.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class XAxisPool
|
||||
{
|
||||
private static readonly ObjectPool<XAxis> s_ListPool = new ObjectPool<XAxis>(null, null);
|
||||
|
||||
public static XAxis Get()
|
||||
{
|
||||
return s_ListPool.Get();
|
||||
}
|
||||
|
||||
public static void Release(XAxis toRelease)
|
||||
{
|
||||
s_ListPool.Release(toRelease);
|
||||
}
|
||||
}
|
||||
|
||||
public static class YAxisPool
|
||||
{
|
||||
private static readonly ObjectPool<YAxis> s_ListPool = new ObjectPool<YAxis>(null, null);
|
||||
|
||||
public static YAxis Get()
|
||||
{
|
||||
return s_ListPool.Get();
|
||||
}
|
||||
|
||||
public static void Release(YAxis toRelease)
|
||||
{
|
||||
s_ListPool.Release(toRelease);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/Runtime/Internal/AxisPool.cs.meta
Normal file
11
Scripts/Runtime/Internal/AxisPool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d6006e13d2c640b9909e4d4121c01ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
782
Scripts/Runtime/Internal/BaseChart.cs
Normal file
782
Scripts/Runtime/Internal/BaseChart.cs
Normal file
@@ -0,0 +1,782 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// the layout is horizontal or vertical.
|
||||
/// 垂直还是水平布局方式。
|
||||
/// </summary>
|
||||
public enum Orient
|
||||
{
|
||||
/// <summary>
|
||||
/// 水平
|
||||
/// </summary>
|
||||
Horizonal,
|
||||
/// <summary>
|
||||
/// 垂直
|
||||
/// </summary>
|
||||
Vertical
|
||||
}
|
||||
|
||||
public partial class BaseChart : Graphic, IPointerDownHandler, IPointerUpHandler,
|
||||
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler,
|
||||
IDragHandler, IEndDragHandler, IScrollHandler
|
||||
{
|
||||
private static readonly string s_TitleObjectName = "title";
|
||||
private static readonly string s_LegendObjectName = "legend";
|
||||
private static readonly string s_SerieLabelObjectName = "label";
|
||||
|
||||
[SerializeField] protected float m_ChartWidth;
|
||||
[SerializeField] protected float m_ChartHeight;
|
||||
[SerializeField] protected ThemeInfo m_ThemeInfo;
|
||||
[SerializeField] protected Title m_Title = Title.defaultTitle;
|
||||
[SerializeField] protected Legend m_Legend = Legend.defaultLegend;
|
||||
[SerializeField] protected Tooltip m_Tooltip = Tooltip.defaultTooltip;
|
||||
[SerializeField] protected Series m_Series = Series.defaultSeries;
|
||||
[SerializeField] protected Settings m_Settings = new Settings();
|
||||
[SerializeField] protected float m_Large = 1;
|
||||
[SerializeField] protected Action<VertexHelper> m_CustomDrawCallback;
|
||||
|
||||
[NonSerialized] private Theme m_CheckTheme = 0;
|
||||
[NonSerialized] private Title m_CheckTitle = Title.defaultTitle;
|
||||
[NonSerialized] private Legend m_CheckLegend = Legend.defaultLegend;
|
||||
[NonSerialized] private float m_CheckWidth = 0;
|
||||
[NonSerialized] private float m_CheckHeight = 0;
|
||||
[NonSerialized] private float m_CheckSerieCount = 0;
|
||||
[NonSerialized] private List<string> m_CheckSerieName = new List<string>();
|
||||
[NonSerialized] private bool m_RefreshChart = false;
|
||||
[NonSerialized] private bool m_RefreshLabel = false;
|
||||
[NonSerialized] private bool m_ReinitLabel = false;
|
||||
[NonSerialized] private bool m_CheckAnimation = false;
|
||||
[NonSerialized] protected List<string> m_LegendRealShowName = new List<string>();
|
||||
|
||||
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
|
||||
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
|
||||
protected Vector2 chartPivot { get { return rectTransform.pivot; } }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
if (m_ThemeInfo == null)
|
||||
{
|
||||
m_ThemeInfo = ThemeInfo.Default;
|
||||
}
|
||||
raycastTarget = false;
|
||||
rectTransform.anchorMax = Vector2.zero;
|
||||
rectTransform.anchorMin = Vector2.zero;
|
||||
rectTransform.pivot = Vector2.zero;
|
||||
m_ChartWidth = rectTransform.sizeDelta.x;
|
||||
m_ChartHeight = rectTransform.sizeDelta.y;
|
||||
m_CheckWidth = m_ChartWidth;
|
||||
m_CheckHeight = m_ChartHeight;
|
||||
m_CheckTheme = m_ThemeInfo.theme;
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
InitSerieLabel();
|
||||
InitTooltip();
|
||||
m_Series.AnimationStop();
|
||||
m_Series.AnimationStart();
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
CheckSize();
|
||||
CheckTheme();
|
||||
CheckTile();
|
||||
CheckLegend();
|
||||
CheckPointerPos();
|
||||
CheckTooltip();
|
||||
CheckRefreshChart();
|
||||
CheckRefreshLabel();
|
||||
CheckAnimation();
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
Awake();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
ChartHelper.HideAllObject(transform);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
var sizeDelta = rectTransform.sizeDelta;
|
||||
if (sizeDelta.x < 580 && sizeDelta.y < 300)
|
||||
{
|
||||
rectTransform.sizeDelta = new Vector2(580, 300);
|
||||
}
|
||||
ChartHelper.HideAllObject(transform);
|
||||
m_ThemeInfo = ThemeInfo.Default;
|
||||
m_Title = Title.defaultTitle;
|
||||
m_Legend = Legend.defaultLegend;
|
||||
m_Tooltip = Tooltip.defaultTooltip;
|
||||
m_Series = Series.defaultSeries;
|
||||
Awake();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
for (int i = transform.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
DestroyImmediate(transform.GetChild(i).gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitTitle()
|
||||
{
|
||||
m_Title.OnChanged();
|
||||
TextAnchor anchor = m_Title.location.textAnchor;
|
||||
Vector2 anchorMin = m_Title.location.anchorMin;
|
||||
Vector2 anchorMax = m_Title.location.anchorMax;
|
||||
Vector2 pivot = m_Title.location.pivot;
|
||||
Vector3 titlePosition = m_Title.location.GetPosition(chartWidth, chartHeight);
|
||||
Vector3 subTitlePosition = -new Vector3(0, m_Title.textFontSize + m_Title.itemGap, 0);
|
||||
float titleWid = chartWidth;
|
||||
|
||||
var titleObject = ChartHelper.AddObject(s_TitleObjectName, transform, anchorMin, anchorMax,
|
||||
pivot, new Vector2(chartWidth, chartHeight));
|
||||
titleObject.transform.localPosition = titlePosition;
|
||||
ChartHelper.HideAllObject(titleObject);
|
||||
|
||||
Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot,
|
||||
new Vector2(titleWid, m_Title.textFontSize), m_Title.textFontSize);
|
||||
|
||||
titleText.alignment = anchor;
|
||||
titleText.gameObject.SetActive(m_Title.show);
|
||||
titleText.transform.localPosition = Vector2.zero;
|
||||
titleText.text = m_Title.text.Replace("\\n", "\n");
|
||||
|
||||
Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot,
|
||||
new Vector2(titleWid, m_Title.subTextFontSize), m_Title.subTextFontSize);
|
||||
|
||||
subText.alignment = anchor;
|
||||
subText.gameObject.SetActive(m_Title.show && !string.IsNullOrEmpty(m_Title.subText));
|
||||
subText.transform.localPosition = subTitlePosition;
|
||||
subText.text = m_Title.subText.Replace("\\n", "\n");
|
||||
}
|
||||
|
||||
private void InitLegend()
|
||||
{
|
||||
m_Legend.OnChanged();
|
||||
TextAnchor anchor = m_Legend.location.textAnchor;
|
||||
Vector2 anchorMin = m_Legend.location.anchorMin;
|
||||
Vector2 anchorMax = m_Legend.location.anchorMax;
|
||||
Vector2 pivot = m_Legend.location.pivot;
|
||||
|
||||
var legendObject = ChartHelper.AddObject(s_LegendObjectName, transform, anchorMin, anchorMax,
|
||||
pivot, new Vector2(chartWidth, chartHeight));
|
||||
legendObject.transform.localPosition = m_Legend.location.GetPosition(chartWidth, chartHeight);
|
||||
|
||||
m_LegendRealShowName = m_Series.GetSerieNameList();
|
||||
List<string> datas;
|
||||
if (m_Legend.show && m_Legend.data.Count > 0)
|
||||
{
|
||||
datas = new List<string>();
|
||||
for (int i = 0; i < m_LegendRealShowName.Count; i++)
|
||||
{
|
||||
if (m_Legend.data.Contains(m_LegendRealShowName[i])) datas.Add(m_LegendRealShowName[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
datas = m_LegendRealShowName;
|
||||
}
|
||||
int totalLegend = 0;
|
||||
for (int i = 0; i < datas.Count; i++)
|
||||
{
|
||||
if (!m_Series.IsLegalLegendName(datas[i])) continue;
|
||||
totalLegend++;
|
||||
}
|
||||
m_Legend.RemoveButton();
|
||||
ChartHelper.DestoryAllChilds(legendObject.transform);
|
||||
if (!m_Legend.show) return;
|
||||
for (int i = 0; i < datas.Count; i++)
|
||||
{
|
||||
if (!m_Series.IsLegalLegendName(datas[i])) continue;
|
||||
string legendName = m_Legend.GetFormatterContent(datas[i]);
|
||||
var readIndex = m_LegendRealShowName.IndexOf(datas[i]);
|
||||
var objName = s_LegendObjectName + "_" + i + "_" + datas[i];
|
||||
Button btn = ChartHelper.AddButtonObject(objName, legendObject.transform,
|
||||
m_ThemeInfo.font, m_Legend.itemFontSize, m_ThemeInfo.legendTextColor, anchor,
|
||||
anchorMin, anchorMax, pivot, new Vector2(m_Legend.itemWidth, m_Legend.itemHeight));
|
||||
var bgColor = IsActiveByLegend(datas[i]) ?
|
||||
m_ThemeInfo.GetColor(readIndex) : m_ThemeInfo.legendUnableColor;
|
||||
m_Legend.SetButton(legendName, btn, totalLegend);
|
||||
m_Legend.UpdateButtonColor(legendName, bgColor);
|
||||
btn.GetComponentInChildren<Text>().text = legendName;
|
||||
ChartHelper.ClearEventListener(btn.gameObject);
|
||||
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
|
||||
{
|
||||
if (data.selectedObject == null || m_Legend.selectedMode == Legend.SelectedMode.None) return;
|
||||
var temp = data.selectedObject.name.Split('_');
|
||||
string selectedName = temp[2];
|
||||
int clickedIndex = int.Parse(temp[1]);
|
||||
if (m_Legend.selectedMode == Legend.SelectedMode.Multiple)
|
||||
{
|
||||
OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName));
|
||||
}
|
||||
else
|
||||
{
|
||||
var btnList = m_Legend.buttonList.Values.ToArray();
|
||||
if (btnList.Length == 1)
|
||||
{
|
||||
OnLegendButtonClick(0, selectedName, !IsActiveByLegend(selectedName));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int n = 0; n < btnList.Length; n++)
|
||||
{
|
||||
temp = btnList[n].name.Split('_');
|
||||
selectedName = temp[2];
|
||||
var index = int.Parse(temp[1]);
|
||||
OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerEnter, (data) =>
|
||||
{
|
||||
if (btn == null) return;
|
||||
var temp = btn.name.Split('_');
|
||||
string selectedName = temp[2];
|
||||
int index = int.Parse(temp[1]);
|
||||
OnLegendButtonEnter(index, selectedName);
|
||||
});
|
||||
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerExit, (data) =>
|
||||
{
|
||||
if (btn == null) return;
|
||||
var temp = btn.name.Split('_');
|
||||
string selectedName = temp[2];
|
||||
int index = int.Parse(temp[1]);
|
||||
OnLegendButtonExit(index, selectedName);
|
||||
});
|
||||
}
|
||||
if (m_Legend.selectedMode == Legend.SelectedMode.Single)
|
||||
{
|
||||
for (int n = 0; n < m_LegendRealShowName.Count; n++)
|
||||
{
|
||||
OnLegendButtonClick(n, m_LegendRealShowName[n], n == 0 ? true : false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitSerieLabel()
|
||||
{
|
||||
var labelObject = ChartHelper.AddObject(s_SerieLabelObjectName, transform, chartAnchorMin,
|
||||
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
|
||||
ChartHelper.DestoryAllChilds(labelObject.transform);
|
||||
int count = 0;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.list[i];
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
var serieData = serie.data[j];
|
||||
if (!serie.label.show && j > 100) continue;
|
||||
var textName = s_SerieLabelObjectName + "_" + i + "_" + j + "_" + serieData.name;
|
||||
var color = Color.grey;
|
||||
if (serie.type == SerieType.Pie)
|
||||
{
|
||||
color = (serie.label.position == SerieLabel.Position.Inside) ? Color.white :
|
||||
(Color)m_ThemeInfo.GetColor(count);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = serie.label.color != Color.clear ? serie.label.color :
|
||||
(Color)m_ThemeInfo.GetColor(i);
|
||||
}
|
||||
var backgroundColor = serie.label.backgroundColor;
|
||||
var labelObj = ChartHelper.AddSerieLabel(textName, labelObject.transform, m_ThemeInfo.font,
|
||||
color, backgroundColor, serie.label.fontSize, serie.label.fontStyle, serie.label.rotate,
|
||||
serie.label.backgroundWidth, serie.label.backgroundHeight);
|
||||
|
||||
var iconObj = ChartHelper.AddIcon("Icon", labelObj.transform, serieData.iconWidth, serieData.iconHeight);
|
||||
serieData.SetIconObj(iconObj);
|
||||
|
||||
var isAutoSize = serie.label.backgroundWidth == 0 || serie.label.backgroundHeight == 0;
|
||||
serieData.InitLabel(labelObj, isAutoSize, serie.label.paddingLeftRight, serie.label.paddingTopBottom);
|
||||
serieData.SetLabelActive(false);
|
||||
serieData.SetLabelText(serieData.name);
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitTooltip()
|
||||
{
|
||||
var tooltipObject = ChartHelper.AddObject("tooltip", transform, chartAnchorMin,
|
||||
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
|
||||
tooltipObject.transform.localPosition = Vector3.zero;
|
||||
DestroyImmediate(tooltipObject.GetComponent<Image>());
|
||||
var parent = tooltipObject.transform;
|
||||
ChartHelper.HideAllObject(tooltipObject.transform);
|
||||
GameObject content = ChartHelper.AddTooltipContent("content", parent, m_ThemeInfo.font,
|
||||
m_Tooltip.fontSize, m_Tooltip.fontStyle);
|
||||
m_Tooltip.SetObj(tooltipObject);
|
||||
m_Tooltip.SetContentObj(content);
|
||||
m_Tooltip.SetContentBackgroundColor(m_ThemeInfo.tooltipBackgroundColor);
|
||||
m_Tooltip.SetContentTextColor(m_ThemeInfo.tooltipTextColor);
|
||||
m_Tooltip.SetActive(false);
|
||||
}
|
||||
|
||||
private Vector3 GetLegendPosition(int i)
|
||||
{
|
||||
return m_Legend.location.GetPosition(chartWidth, chartHeight);
|
||||
}
|
||||
|
||||
private void CheckSize()
|
||||
{
|
||||
var sizeDelta = rectTransform.sizeDelta;
|
||||
if (m_CheckWidth == 0 && m_CheckHeight == 0 && (sizeDelta.x != 0 || sizeDelta.y != 0))
|
||||
{
|
||||
Awake();
|
||||
}
|
||||
else if (m_CheckWidth != sizeDelta.x || m_CheckHeight != sizeDelta.y)
|
||||
{
|
||||
SetSize(sizeDelta.x, sizeDelta.y);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckTheme()
|
||||
{
|
||||
if (m_CheckTheme != m_ThemeInfo.theme)
|
||||
{
|
||||
m_CheckTheme = m_ThemeInfo.theme;
|
||||
OnThemeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckTile()
|
||||
{
|
||||
if (!m_CheckTitle.Equals(m_Title))
|
||||
{
|
||||
m_CheckTitle.Copy(m_Title);
|
||||
OnTitleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckLegend()
|
||||
{
|
||||
if (m_CheckLegend != m_Legend)
|
||||
{
|
||||
m_CheckLegend.Copy(m_Legend);
|
||||
OnLegendChanged();
|
||||
}
|
||||
else if (m_Legend.show)
|
||||
{
|
||||
if (m_CheckSerieCount != m_Series.Count)
|
||||
{
|
||||
m_CheckSerieCount = m_Series.Count;
|
||||
m_CheckSerieName.Clear();
|
||||
var serieNames = m_Series.GetSerieNameList();
|
||||
foreach (var name in serieNames) m_CheckSerieName.Add(name);
|
||||
OnLegendChanged();
|
||||
}
|
||||
else if (!ChartHelper.IsValueEqualsList(m_CheckSerieName, m_Series.GetSerieNameList()))
|
||||
{
|
||||
var serieNames = m_Series.GetSerieNameList();
|
||||
foreach (var name in serieNames) m_CheckSerieName.Add(name);
|
||||
OnLegendChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckPointerPos()
|
||||
{
|
||||
var needCheck = (m_Tooltip.show && m_Tooltip.inited)
|
||||
|| raycastTarget;
|
||||
if (needCheck)
|
||||
{
|
||||
if (canvas == null) return;
|
||||
Vector2 local;
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||
Input.mousePosition, canvas.worldCamera, out local))
|
||||
{
|
||||
pointerPos = Vector2.zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
pointerPos = local;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckTooltip()
|
||||
{
|
||||
if (!m_Tooltip.show || !m_Tooltip.inited)
|
||||
{
|
||||
if (m_Tooltip.IsActive())
|
||||
{
|
||||
m_Tooltip.ClearValue();
|
||||
m_Tooltip.SetActive(false);
|
||||
RefreshChart();
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < m_Tooltip.dataIndex.Count; i++)
|
||||
{
|
||||
m_Tooltip.dataIndex[i] = -1;
|
||||
}
|
||||
Vector2 local = pointerPos;
|
||||
if (canvas == null) return;
|
||||
|
||||
if (local == Vector2.zero)
|
||||
{
|
||||
if (m_Tooltip.IsActive())
|
||||
{
|
||||
m_Tooltip.SetActive(false);
|
||||
RefreshChart();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (local.x < 0 || local.x > chartWidth ||
|
||||
local.y < 0 || local.y > chartHeight)
|
||||
{
|
||||
if (m_Tooltip.IsActive())
|
||||
{
|
||||
m_Tooltip.SetActive(false);
|
||||
RefreshChart();
|
||||
}
|
||||
return;
|
||||
}
|
||||
m_Tooltip.pointerPos = local;
|
||||
CheckTootipArea(local);
|
||||
}
|
||||
|
||||
protected virtual void CheckTootipArea(Vector2 localPostion)
|
||||
{
|
||||
}
|
||||
|
||||
protected void CheckRefreshChart()
|
||||
{
|
||||
if (m_RefreshChart)
|
||||
{
|
||||
int tempWid = (int)chartWidth;
|
||||
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid - 1);
|
||||
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid);
|
||||
m_RefreshChart = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void CheckRefreshLabel()
|
||||
{
|
||||
if (m_ReinitLabel)
|
||||
{
|
||||
m_ReinitLabel = false;
|
||||
m_LegendRealShowName = m_Series.GetSerieNameList();
|
||||
InitSerieLabel();
|
||||
}
|
||||
if (m_RefreshLabel)
|
||||
{
|
||||
m_RefreshLabel = false;
|
||||
OnRefreshLabel();
|
||||
}
|
||||
}
|
||||
|
||||
protected void CheckAnimation()
|
||||
{
|
||||
if (!m_CheckAnimation)
|
||||
{
|
||||
m_CheckAnimation = true;
|
||||
m_Series.AnimationStart();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnRefreshLabel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected virtual void OnSizeChanged()
|
||||
{
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
InitTooltip();
|
||||
}
|
||||
|
||||
protected virtual void OnThemeChanged()
|
||||
{
|
||||
switch (m_ThemeInfo.theme)
|
||||
{
|
||||
case Theme.Dark:
|
||||
m_ThemeInfo.Copy(ThemeInfo.Dark);
|
||||
break;
|
||||
case Theme.Default:
|
||||
m_ThemeInfo.Copy(ThemeInfo.Default);
|
||||
break;
|
||||
case Theme.Light:
|
||||
m_ThemeInfo.Copy(ThemeInfo.Light);
|
||||
break;
|
||||
}
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
InitTooltip();
|
||||
}
|
||||
|
||||
protected virtual void OnTitleChanged()
|
||||
{
|
||||
InitTitle();
|
||||
}
|
||||
|
||||
protected virtual void OnLegendChanged()
|
||||
{
|
||||
InitLegend();
|
||||
}
|
||||
|
||||
protected virtual void OnYMaxValueChanged()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnLegendButtonClick(int index, string legendName, bool show)
|
||||
{
|
||||
foreach (var serie in m_Series.GetSeries(legendName))
|
||||
{
|
||||
SetActive(serie.index, show);
|
||||
}
|
||||
OnYMaxValueChanged();
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected virtual void OnLegendButtonEnter(int index, string legendName)
|
||||
{
|
||||
var serie = m_Series.GetSerie(index);
|
||||
serie.highlighted = true;
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected virtual void OnLegendButtonExit(int index, string legendName)
|
||||
{
|
||||
var serie = m_Series.GetSerie(index);
|
||||
serie.highlighted = false;
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected bool CheckDataShow(string legendName, bool show)
|
||||
{
|
||||
bool needShow = false;
|
||||
foreach (var serie in m_Series.list)
|
||||
{
|
||||
if (legendName.Equals(serie.name))
|
||||
{
|
||||
serie.show = show;
|
||||
serie.highlighted = false;
|
||||
if (serie.show) needShow = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (legendName.Equals(data.name))
|
||||
{
|
||||
data.show = show;
|
||||
data.highlighted = false;
|
||||
if (data.show) needShow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return needShow;
|
||||
}
|
||||
|
||||
protected bool CheckDataHighlighted(string legendName, bool heighlight)
|
||||
{
|
||||
bool show = false;
|
||||
foreach (var serie in m_Series.list)
|
||||
{
|
||||
if (legendName.Equals(serie.name))
|
||||
{
|
||||
serie.highlighted = heighlight;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var data in serie.data)
|
||||
{
|
||||
if (legendName.Equals(data.name))
|
||||
{
|
||||
data.highlighted = heighlight;
|
||||
if (data.highlighted) show = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return show;
|
||||
}
|
||||
|
||||
protected virtual void RefreshTooltip()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
vh.Clear();
|
||||
DrawBackground(vh);
|
||||
DrawChart(vh);
|
||||
if (m_CustomDrawCallback != null)
|
||||
{
|
||||
m_CustomDrawCallback(vh);
|
||||
}
|
||||
DrawTooltip(vh);
|
||||
m_RefreshLabel = true;
|
||||
}
|
||||
|
||||
protected virtual void DrawChart(VertexHelper vh)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void DrawTooltip(VertexHelper vh)
|
||||
{
|
||||
}
|
||||
|
||||
private void DrawBackground(VertexHelper vh)
|
||||
{
|
||||
// draw bg
|
||||
Vector3 p1 = new Vector3(0, chartHeight);
|
||||
Vector3 p2 = new Vector3(chartWidth, chartHeight);
|
||||
Vector3 p3 = new Vector3(chartWidth, 0);
|
||||
Vector3 p4 = new Vector3(0, 0);
|
||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.backgroundColor);
|
||||
}
|
||||
|
||||
protected void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
|
||||
float tickness, Vector3 pos, Color color)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SerieSymbolType.None:
|
||||
break;
|
||||
case SerieSymbolType.Circle:
|
||||
ChartDrawer.DrawCricle(vh, pos, symbolSize, color, m_Settings.cicleSmoothness);
|
||||
break;
|
||||
case SerieSymbolType.EmptyCircle:
|
||||
ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness);
|
||||
break;
|
||||
case SerieSymbolType.Rect:
|
||||
ChartDrawer.DrawPolygon(vh, pos, symbolSize, color);
|
||||
break;
|
||||
case SerieSymbolType.Triangle:
|
||||
var x = symbolSize * Mathf.Cos(30 * Mathf.PI / 180);
|
||||
var y = symbolSize * Mathf.Sin(30 * Mathf.PI / 180);
|
||||
var p1 = new Vector2(pos.x - x, pos.y - y);
|
||||
var p2 = new Vector2(pos.x, pos.y + symbolSize);
|
||||
var p3 = new Vector2(pos.x + x, pos.y - y);
|
||||
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
|
||||
break;
|
||||
case SerieSymbolType.Diamond:
|
||||
p1 = new Vector2(pos.x - symbolSize, pos.y);
|
||||
p2 = new Vector2(pos.x, pos.y + symbolSize);
|
||||
p3 = new Vector2(pos.x + symbolSize, pos.y);
|
||||
var p4 = new Vector2(pos.x, pos.y - symbolSize);
|
||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData)
|
||||
{
|
||||
var labelHalfWid = serieData.GetLabelWidth() / 2;
|
||||
var labelHalfHig = serieData.GetLabelHeight() / 2;
|
||||
var centerPos = serieData.labelPosition + serie.label.offset;
|
||||
var p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
|
||||
var p2 = new Vector3(centerPos.x + labelHalfWid, centerPos.y + labelHalfHig);
|
||||
var p3 = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig);
|
||||
var p4 = new Vector3(centerPos.x - labelHalfWid, centerPos.y - labelHalfHig);
|
||||
|
||||
if (serie.label.rotate > 0)
|
||||
{
|
||||
p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serie.label.rotate);
|
||||
}
|
||||
|
||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, serie.label.backgroundColor);
|
||||
|
||||
if (serie.label.border)
|
||||
{
|
||||
var borderWid = serie.label.borderWidth;
|
||||
p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig + borderWid);
|
||||
p2 = new Vector3(centerPos.x + labelHalfWid + 2 * borderWid, centerPos.y + labelHalfHig + borderWid);
|
||||
p3 = new Vector3(centerPos.x + labelHalfWid + borderWid, centerPos.y + labelHalfHig);
|
||||
p4 = new Vector3(centerPos.x + labelHalfWid + borderWid, centerPos.y - labelHalfHig - 2 * borderWid);
|
||||
var p5 = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig - borderWid);
|
||||
var p6 = new Vector3(centerPos.x - labelHalfWid - 2 * borderWid, centerPos.y - labelHalfHig - borderWid);
|
||||
var p7 = new Vector3(centerPos.x - labelHalfWid - borderWid, centerPos.y - labelHalfHig);
|
||||
var p8 = new Vector3(centerPos.x - labelHalfWid - borderWid, centerPos.y + labelHalfHig + 2 * borderWid);
|
||||
if (serie.label.rotate > 0)
|
||||
{
|
||||
p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p5 = ChartHelper.RotateRound(p5, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p6 = ChartHelper.RotateRound(p6, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p7 = ChartHelper.RotateRound(p7, centerPos, Vector3.forward, serie.label.rotate);
|
||||
p8 = ChartHelper.RotateRound(p8, centerPos, Vector3.forward, serie.label.rotate);
|
||||
}
|
||||
ChartDrawer.DrawLine(vh, p1, p2, borderWid, serie.label.borderColor);
|
||||
ChartDrawer.DrawLine(vh, p3, p4, borderWid, serie.label.borderColor);
|
||||
ChartDrawer.DrawLine(vh, p5, p6, borderWid, serie.label.borderColor);
|
||||
ChartDrawer.DrawLine(vh, p7, p8, borderWid, serie.label.borderColor);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnScroll(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Runtime/Internal/BaseChart.cs.meta
Normal file
13
Scripts/Runtime/Internal/BaseChart.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5053a63a1ebdfe4f8972f194156c3d3
|
||||
timeCreated: 1536967243
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1631
Scripts/Runtime/Internal/CoordinateChart.cs
Normal file
1631
Scripts/Runtime/Internal/CoordinateChart.cs
Normal file
File diff suppressed because it is too large
Load Diff
13
Scripts/Runtime/Internal/CoordinateChart.cs.meta
Normal file
13
Scripts/Runtime/Internal/CoordinateChart.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c20b1e83703d1084c899f1f1b605c278
|
||||
timeCreated: 1538087401
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
299
Scripts/Runtime/Internal/CoordinateChart_DrawBar.cs
Normal file
299
Scripts/Runtime/Internal/CoordinateChart_DrawBar.cs
Normal file
@@ -0,0 +1,299 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public partial class CoordinateChart
|
||||
{
|
||||
protected float m_BarLastOffset = 0;
|
||||
|
||||
protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.name)) return;
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
|
||||
float categoryWidth = yAxis.GetDataWidth(coordinateHeight, m_DataZoom);
|
||||
float barGap = GetBarGap();
|
||||
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
float offset = (categoryWidth - totalBarWidth) / 2;
|
||||
float barGapWidth = barWidth + barWidth * barGap;
|
||||
float space = serie.barGap == -1 ? offset : offset + m_BarLastOffset;
|
||||
|
||||
var showData = serie.GetDataList(m_DataZoom);
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
|
||||
: showData.Count;
|
||||
if (seriesHig.Count < serie.minShow)
|
||||
{
|
||||
for (int i = 0; i < serie.minShow; i++)
|
||||
{
|
||||
seriesHig.Add(0);
|
||||
}
|
||||
}
|
||||
var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
|
||||
for (int i = serie.minShow; i < maxCount; i++)
|
||||
{
|
||||
if (i >= seriesHig.Count)
|
||||
{
|
||||
seriesHig.Add(0);
|
||||
}
|
||||
float value = showData[i].data[1];
|
||||
float pX = seriesHig[i] + coordinateX + xAxis.zeroXOffset + yAxis.axisLine.width;
|
||||
float pY = coordinateY + +i * categoryWidth;
|
||||
if (!yAxis.boundaryGap) pY -= categoryWidth / 2;
|
||||
|
||||
var barHig = 0f;
|
||||
var valueTotal = 0f;
|
||||
if (isPercentStack)
|
||||
{
|
||||
valueTotal = GetSameStackTotalValue(serie.stack, i);
|
||||
barHig = value / valueTotal * coordinateWidth;
|
||||
seriesHig[i] += barHig;
|
||||
}
|
||||
else
|
||||
{
|
||||
valueTotal = xAxis.maxValue - xAxis.minValue;
|
||||
barHig = (xAxis.minValue > 0 ? value - xAxis.minValue : value)
|
||||
/ valueTotal * coordinateWidth;
|
||||
seriesHig[i] += barHig;
|
||||
}
|
||||
|
||||
float currHig = CheckAnimation(serie, i, barHig);
|
||||
|
||||
Vector3 p1 = new Vector3(pX, pY + space + barWidth);
|
||||
Vector3 p2 = new Vector3(pX + currHig, pY + space + barWidth);
|
||||
Vector3 p3 = new Vector3(pX + currHig, pY + space);
|
||||
Vector3 p4 = new Vector3(pX, pY + space);
|
||||
serie.dataPoints.Add(new Vector3(pX + currHig, pY + space + barWidth / 2));
|
||||
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|
||||
|| serie.data[i].highlighted
|
||||
|| serie.highlighted;
|
||||
if (serie.show)
|
||||
{
|
||||
Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
|
||||
Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
|
||||
if (serie.barType == BarType.Zebra)
|
||||
{
|
||||
p1 = (p4 + p1) / 2;
|
||||
p2 = (p2 + p3) / 2;
|
||||
ChartDrawer.DrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, areaColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!m_Series.IsStack(serie.stack, SerieType.Bar))
|
||||
{
|
||||
m_BarLastOffset += barGapWidth;
|
||||
}
|
||||
}
|
||||
|
||||
private float CheckAnimation(Serie serie, int dataIndex, float barHig)
|
||||
{
|
||||
float currHig = barHig;
|
||||
if (!serie.animation.IsFinish())
|
||||
{
|
||||
if (serie.animation.IsInDelay()) currHig = 0;
|
||||
else
|
||||
{
|
||||
var speed = serie.animation.duration > 0 ? barHig / serie.animation.duration * 1000 : barHig;
|
||||
currHig = serie.animation.GetDataState(dataIndex) + speed * Time.deltaTime;
|
||||
serie.animation.SetDataState(dataIndex, currHig);
|
||||
if (Mathf.Abs(currHig) >= Mathf.Abs(barHig))
|
||||
{
|
||||
serie.animation.End();
|
||||
currHig = barHig;
|
||||
}
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
return currHig;
|
||||
}
|
||||
|
||||
protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.name)) return;
|
||||
var showData = serie.GetDataList(m_DataZoom);
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
|
||||
float categoryWidth = xAxis.GetDataWidth(coordinateWidth, m_DataZoom);
|
||||
float barGap = GetBarGap();
|
||||
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
float offset = (categoryWidth - totalBarWidth) / 2;
|
||||
float barGapWidth = barWidth + barWidth * barGap;
|
||||
float space = serie.barGap == -1 ? offset : offset + m_BarLastOffset;
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
|
||||
: showData.Count;
|
||||
|
||||
if (seriesHig.Count < serie.minShow)
|
||||
{
|
||||
for (int i = 0; i < serie.minShow; i++)
|
||||
{
|
||||
seriesHig.Add(0);
|
||||
}
|
||||
}
|
||||
|
||||
var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
|
||||
for (int i = serie.minShow; i < maxCount; i++)
|
||||
{
|
||||
if (i >= seriesHig.Count)
|
||||
{
|
||||
seriesHig.Add(0);
|
||||
}
|
||||
float value = showData[i].data[1];
|
||||
float pX = coordinateX + i * categoryWidth;
|
||||
float zeroY = coordinateY + yAxis.zeroYOffset;
|
||||
if (!xAxis.boundaryGap) pX -= categoryWidth / 2;
|
||||
float pY = seriesHig[i] + zeroY + xAxis.axisLine.width;
|
||||
|
||||
var barHig = 0f;
|
||||
var valueTotal = 0f;
|
||||
if (isPercentStack)
|
||||
{
|
||||
valueTotal = GetSameStackTotalValue(serie.stack, i);
|
||||
barHig = value / valueTotal * coordinateHeight;
|
||||
seriesHig[i] += barHig;
|
||||
}
|
||||
else
|
||||
{
|
||||
valueTotal = yAxis.maxValue - yAxis.minValue;
|
||||
barHig = (yAxis.minValue > 0 ? value - yAxis.minValue : value)
|
||||
/ valueTotal * coordinateHeight;
|
||||
seriesHig[i] += barHig;
|
||||
}
|
||||
|
||||
float currHig = CheckAnimation(serie, i, barHig);
|
||||
|
||||
Vector3 p1 = new Vector3(pX + space, pY);
|
||||
Vector3 p2 = new Vector3(pX + space, pY + currHig);
|
||||
Vector3 p3 = new Vector3(pX + space + barWidth, pY + currHig);
|
||||
Vector3 p4 = new Vector3(pX + space + barWidth, pY);
|
||||
serie.dataPoints.Add(new Vector3(pX + space + barWidth / 2, pY + currHig));
|
||||
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|
||||
|| serie.data[i].highlighted
|
||||
|| serie.highlighted;
|
||||
|
||||
if (serie.show)
|
||||
{
|
||||
Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
|
||||
Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
|
||||
if (serie.barType == BarType.Zebra)
|
||||
{
|
||||
p1 = (p4 + p1) / 2;
|
||||
p2 = (p2 + p3) / 2;
|
||||
ChartDrawer.DrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, areaColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!m_Series.IsStack(serie.stack, SerieType.Bar))
|
||||
{
|
||||
m_BarLastOffset += barGapWidth;
|
||||
}
|
||||
}
|
||||
|
||||
private float GetBarGap()
|
||||
{
|
||||
float gap = 0.3f;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.list[i];
|
||||
if (serie.type == SerieType.Bar)
|
||||
{
|
||||
if (serie.barGap != 0)
|
||||
{
|
||||
gap = serie.barGap;
|
||||
}
|
||||
}
|
||||
}
|
||||
return gap;
|
||||
}
|
||||
|
||||
private float GetSameStackTotalValue(string stack, int dataIndex)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stack)) return 0;
|
||||
float total = 0;
|
||||
foreach (var serie in m_Series.list)
|
||||
{
|
||||
if (serie.type == SerieType.Bar)
|
||||
{
|
||||
if (stack.Equals(serie.stack))
|
||||
{
|
||||
total += serie.data[dataIndex].data[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
private HashSet<string> barStackSet = new HashSet<string>();
|
||||
private float GetBarTotalWidth(float categoryWidth, float gap)
|
||||
{
|
||||
float total = 0;
|
||||
float lastGap = 0;
|
||||
barStackSet.Clear();
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.list[i];
|
||||
if (serie.type == SerieType.Bar && serie.show)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
if (barStackSet.Contains(serie.stack)) continue;
|
||||
barStackSet.Add(serie.stack);
|
||||
}
|
||||
var width = GetStackBarWidth(categoryWidth, serie);
|
||||
if (gap == -1)
|
||||
{
|
||||
if (width > total) total = width;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastGap = width * gap;
|
||||
total += width;
|
||||
total += lastGap;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (total > 0 && gap != -1) total -= lastGap;
|
||||
return total;
|
||||
}
|
||||
|
||||
private float GetStackBarWidth(float categoryWidth, Serie now)
|
||||
{
|
||||
if (string.IsNullOrEmpty(now.stack)) return now.GetBarWidth(categoryWidth);
|
||||
float barWidth = 0;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.list[i];
|
||||
if (serie.type == SerieType.Bar && serie.show && now.stack.Equals(serie.stack))
|
||||
{
|
||||
if (serie.barWidth > barWidth) barWidth = serie.barWidth;
|
||||
}
|
||||
}
|
||||
if (barWidth > 1) return barWidth;
|
||||
else return barWidth * categoryWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/Runtime/Internal/CoordinateChart_DrawBar.cs.meta
Normal file
11
Scripts/Runtime/Internal/CoordinateChart_DrawBar.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2abce1026caf74ffbb653c6e1a8d1e3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
384
Scripts/Runtime/Internal/CoordinateChart_DrawHeatmap.cs
Normal file
384
Scripts/Runtime/Internal/CoordinateChart_DrawHeatmap.cs
Normal file
@@ -0,0 +1,384 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public partial class CoordinateChart
|
||||
{
|
||||
private bool m_VisualMapMinDrag;
|
||||
private bool m_VisualMapMaxDrag;
|
||||
|
||||
protected void CheckVisualMap()
|
||||
{
|
||||
if (!m_VisualMap.enable || !m_VisualMap.show) return;
|
||||
Vector2 local;
|
||||
if (canvas == null) return;
|
||||
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||
Input.mousePosition, canvas.worldCamera, out local))
|
||||
{
|
||||
if (m_VisualMap.rtSelectedIndex >= 0)
|
||||
{
|
||||
m_VisualMap.rtSelectedIndex = -1;
|
||||
RefreshChart();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (local.x < 0 || local.x > chartWidth ||
|
||||
local.y < 0 || local.y > chartHeight ||
|
||||
!m_VisualMap.IsInRangeRect(local, chartWidth, chartHeight))
|
||||
{
|
||||
if (m_VisualMap.rtSelectedIndex >= 0)
|
||||
{
|
||||
m_VisualMap.rtSelectedIndex = -1;
|
||||
RefreshChart();
|
||||
}
|
||||
return;
|
||||
}
|
||||
var pos1 = Vector3.zero;
|
||||
var pos2 = Vector3.zero;
|
||||
var halfHig = m_VisualMap.itemHeight / 2;
|
||||
var centerPos = m_VisualMap.location.GetPosition(chartWidth, chartHeight);
|
||||
var selectedIndex = -1;
|
||||
var value = 0f;
|
||||
switch (m_VisualMap.orient)
|
||||
{
|
||||
case Orient.Horizonal:
|
||||
pos1 = centerPos + Vector3.left * halfHig;
|
||||
pos2 = centerPos + Vector3.right * halfHig;
|
||||
value = m_VisualMap.min + (local.x - pos1.x) / (pos2.x - pos1.x) * (m_VisualMap.max - m_VisualMap.min);
|
||||
selectedIndex = m_VisualMap.GetIndex(value);
|
||||
break;
|
||||
case Orient.Vertical:
|
||||
pos1 = centerPos + Vector3.down * halfHig;
|
||||
pos2 = centerPos + Vector3.up * halfHig;
|
||||
value = m_VisualMap.min + (local.y - pos1.y) / (pos2.y - pos1.y) * (m_VisualMap.max - m_VisualMap.min);
|
||||
selectedIndex = m_VisualMap.GetIndex(value);
|
||||
break;
|
||||
}
|
||||
m_VisualMap.rtSelectedValue = value;
|
||||
m_VisualMap.rtSelectedIndex = selectedIndex;
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected void OnDragVisualMapStart()
|
||||
{
|
||||
if (!m_VisualMap.enable || !m_VisualMap.show || !m_VisualMap.calculable) return;
|
||||
var inMinRect = m_VisualMap.IsInRangeMinRect(pointerPos, chartWidth, chartHeight, m_Settings.visualMapTriangeLen);
|
||||
var inMaxRect = m_VisualMap.IsInRangeMaxRect(pointerPos, chartWidth, chartHeight, m_Settings.visualMapTriangeLen);
|
||||
if (inMinRect || inMaxRect)
|
||||
{
|
||||
if (inMinRect)
|
||||
{
|
||||
m_VisualMapMinDrag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_VisualMapMaxDrag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnDragVisualMap()
|
||||
{
|
||||
if (!m_VisualMap.enable || !m_VisualMap.show || !m_VisualMap.calculable) return;
|
||||
if (!m_VisualMapMinDrag && !m_VisualMapMaxDrag) return;
|
||||
|
||||
var value = m_VisualMap.GetValue(pointerPos, chartWidth, chartHeight);
|
||||
if (m_VisualMapMinDrag)
|
||||
{
|
||||
m_VisualMap.rangeMin = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_VisualMap.rangeMax = value;
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected void OnDragVisualMapEnd()
|
||||
{
|
||||
if (!m_VisualMap.enable || !m_VisualMap.show || !m_VisualMap.calculable) return;
|
||||
if (m_VisualMapMinDrag || m_VisualMapMaxDrag)
|
||||
{
|
||||
RefreshChart();
|
||||
m_VisualMapMinDrag = false;
|
||||
m_VisualMapMaxDrag = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
|
||||
{
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var xCount = xAxis.data.Count;
|
||||
var yCount = yAxis.data.Count;
|
||||
var xWidth = coordinateWidth / xCount;
|
||||
var yWidth = coordinateHeight / yCount;
|
||||
|
||||
var zeroX = coordinateX;
|
||||
var zeroY = coordinateY;
|
||||
var dataList = serie.GetDataList();
|
||||
var rangeMin = m_VisualMap.rangeMin;
|
||||
var rangeMax = m_VisualMap.rangeMax;
|
||||
var color = m_ThemeInfo.GetColor(serie.index);
|
||||
var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0;
|
||||
var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : Color.clear;
|
||||
borderColor.a *= serie.itemStyle.opacity;
|
||||
serie.dataPoints.Clear();
|
||||
serie.animation.InitProgress(1, 0, xCount);
|
||||
var animationIndex = serie.animation.GetCurrIndex();
|
||||
for (int i = 0; i < xCount; i++)
|
||||
{
|
||||
for (int j = 0; j < yCount; j++)
|
||||
{
|
||||
var dataIndex = i * yCount + j;
|
||||
if (dataIndex >= dataList.Count) continue;
|
||||
var serieData = dataList[dataIndex];
|
||||
var dimension = m_VisualMap.enable && m_VisualMap.dimension > 0 ? m_VisualMap.dimension - 1 :
|
||||
serieData.data.Count - 1;
|
||||
var value = serieData.data[dimension];
|
||||
var pos = new Vector3(zeroX + (i + 0.5f) * xWidth, zeroY + (j + 0.5f) * yWidth);
|
||||
serie.dataPoints.Add(pos);
|
||||
serieData.canShowLabel = false;
|
||||
if (value == 0) continue;
|
||||
if (m_VisualMap.enable)
|
||||
{
|
||||
if ((value < rangeMin && rangeMin != m_VisualMap.min)
|
||||
|| (value > rangeMax && rangeMax != m_VisualMap.max))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!m_VisualMap.IsInSelectedValue(value)) continue;
|
||||
color = m_VisualMap.GetColor(value);
|
||||
}
|
||||
if(animationIndex>= 0 && i> animationIndex) continue;
|
||||
serieData.canShowLabel = true;
|
||||
var emphasis = (m_Tooltip.show && i == (int)m_Tooltip.xValues[0] && j == (int)m_Tooltip.yValues[0])
|
||||
|| m_VisualMap.rtSelectedIndex > 0;
|
||||
var rectWid = xWidth - 2 * borderWidth;
|
||||
var rectHig = yWidth - 2 * borderWidth;
|
||||
ChartDrawer.DrawPolygon(vh, pos, rectWid / 2, rectHig / 2, color);
|
||||
if (borderWidth > 0 && borderColor != Color.clear)
|
||||
{
|
||||
ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor);
|
||||
}
|
||||
if (m_VisualMap.hoverLink && emphasis && serie.emphasis.show && serie.emphasis.itemStyle.borderWidth > 0)
|
||||
{
|
||||
var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth;
|
||||
var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderColor : Color.clear;
|
||||
ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!serie.animation.IsFinish())
|
||||
{
|
||||
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
|
||||
float speed = xCount / duration;
|
||||
serie.animation.CheckProgress(Time.deltaTime * speed);
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawVisualMap(VertexHelper vh)
|
||||
{
|
||||
if (!m_VisualMap.enable || !m_VisualMap.show) return;
|
||||
var centerPos = m_VisualMap.location.GetPosition(chartWidth, chartHeight);
|
||||
|
||||
var pos1 = Vector3.zero;
|
||||
var pos2 = Vector3.zero;
|
||||
var dir = Vector3.zero;
|
||||
var halfWid = m_VisualMap.itemWidth / 2;
|
||||
var halfHig = m_VisualMap.itemHeight / 2;
|
||||
var xRadius = 0f;
|
||||
var yRadius = 0f;
|
||||
var splitNum = m_VisualMap.rtInRange.Count;
|
||||
var splitWid = m_VisualMap.itemHeight / (splitNum - 1);
|
||||
var isVertical = false;
|
||||
var colors = m_VisualMap.rtInRange;
|
||||
var triangeLen = m_Settings.visualMapTriangeLen;
|
||||
switch (m_VisualMap.orient)
|
||||
{
|
||||
case Orient.Horizonal:
|
||||
pos1 = centerPos + Vector3.left * halfHig;
|
||||
pos2 = centerPos + Vector3.right * halfHig;
|
||||
dir = Vector3.right;
|
||||
xRadius = splitWid / 2;
|
||||
yRadius = halfWid;
|
||||
isVertical = false;
|
||||
if (m_VisualMap.calculable)
|
||||
{
|
||||
var p0 = pos1 + Vector3.right * m_VisualMap.rangeMinHeight;
|
||||
var p1 = p0 + Vector3.up * halfWid;
|
||||
var p2 = p0 + Vector3.up * (halfWid + triangeLen);
|
||||
var p3 = p2 + Vector3.left * triangeLen;
|
||||
var color = m_VisualMap.GetColor(m_VisualMap.rangeMin);
|
||||
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
|
||||
p0 = pos1 + Vector3.right * m_VisualMap.rangeMaxHeight;
|
||||
p1 = p0 + Vector3.up * halfWid;
|
||||
p2 = p0 + Vector3.up * (halfWid + triangeLen);
|
||||
p3 = p2 + Vector3.right * triangeLen;
|
||||
color = m_VisualMap.GetColor(m_VisualMap.rangeMax);
|
||||
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
|
||||
}
|
||||
break;
|
||||
case Orient.Vertical:
|
||||
pos1 = centerPos + Vector3.down * halfHig;
|
||||
pos2 = centerPos + Vector3.up * halfHig;
|
||||
dir = Vector3.up;
|
||||
xRadius = halfWid;
|
||||
yRadius = splitWid / 2;
|
||||
isVertical = true;
|
||||
if (m_VisualMap.calculable)
|
||||
{
|
||||
var p0 = pos1 + Vector3.up * m_VisualMap.rangeMinHeight;
|
||||
var p1 = p0 + Vector3.right * halfWid;
|
||||
var p2 = p0 + Vector3.right * (halfWid + triangeLen);
|
||||
var p3 = p2 + Vector3.down * triangeLen;
|
||||
var color = m_VisualMap.GetColor(m_VisualMap.rangeMin);
|
||||
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
|
||||
p0 = pos1 + Vector3.up * m_VisualMap.rangeMaxHeight;
|
||||
p1 = p0 + Vector3.right * halfWid;
|
||||
p2 = p0 + Vector3.right * (halfWid + triangeLen);
|
||||
p3 = p2 + Vector3.up * triangeLen;
|
||||
color = m_VisualMap.GetColor(m_VisualMap.rangeMax);
|
||||
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (m_VisualMap.calculable && (m_VisualMap.rangeMin > m_VisualMap.min
|
||||
|| m_VisualMap.rangeMax < m_VisualMap.max))
|
||||
{
|
||||
var rangeMin = m_VisualMap.rangeMin;
|
||||
var rangeMax = m_VisualMap.rangeMax;
|
||||
var diff = (m_VisualMap.max - m_VisualMap.min) / (splitNum - 1);
|
||||
for (int i = 1; i < splitNum; i++)
|
||||
{
|
||||
var splitMin = m_VisualMap.min + (i - 1) * diff;
|
||||
var splitMax = splitMin + diff;
|
||||
if (rangeMin > splitMax || rangeMax < splitMin)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (rangeMin <= splitMin && rangeMax >= splitMax)
|
||||
{
|
||||
var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid;
|
||||
var startColor = colors[i - 1];
|
||||
var toColor = colors[i];
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
|
||||
}
|
||||
else if (rangeMin > splitMin && rangeMax >= splitMax)
|
||||
{
|
||||
var p0 = pos1 + dir * m_VisualMap.rangeMinHeight;
|
||||
var splitMaxPos = pos1 + dir * i * splitWid;
|
||||
var splitPos = p0 + (splitMaxPos - p0) / 2;
|
||||
var startColor = m_VisualMap.GetColor(m_VisualMap.rangeMin);
|
||||
var toColor = colors[i];
|
||||
var yRadius1 = Vector3.Distance(p0, splitMaxPos) / 2;
|
||||
if (m_VisualMap.orient == Orient.Vertical)
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
|
||||
else
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
|
||||
}
|
||||
else if (rangeMax < splitMax && rangeMin <= splitMin)
|
||||
{
|
||||
var p0 = pos1 + dir * m_VisualMap.rangeMaxHeight;
|
||||
var splitMinPos = pos1 + dir * (i - 1) * splitWid;
|
||||
var splitPos = splitMinPos + (p0 - splitMinPos) / 2;
|
||||
var startColor = colors[i - 1];
|
||||
var toColor = m_VisualMap.GetColor(m_VisualMap.rangeMax);
|
||||
var yRadius1 = Vector3.Distance(p0, splitMinPos) / 2;
|
||||
if (m_VisualMap.orient == Orient.Vertical)
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
|
||||
else
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
|
||||
}
|
||||
else
|
||||
{
|
||||
var p0 = pos1 + dir * m_VisualMap.rangeMinHeight;
|
||||
var p1 = pos1 + dir * m_VisualMap.rangeMaxHeight;
|
||||
var splitPos = (p0 + p1) / 2;
|
||||
var startColor = m_VisualMap.GetColor(m_VisualMap.rangeMin);
|
||||
var toColor = m_VisualMap.GetColor(m_VisualMap.rangeMax);
|
||||
var yRadius1 = Vector3.Distance(p0, p1) / 2;
|
||||
if (m_VisualMap.orient == Orient.Vertical)
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
|
||||
else
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 1; i < splitNum; i++)
|
||||
{
|
||||
var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid;
|
||||
var startColor = colors[i - 1];
|
||||
var toColor = colors[i];
|
||||
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_VisualMap.rangeMin > m_VisualMap.min)
|
||||
{
|
||||
var p0 = pos1 + dir * m_VisualMap.rangeMinHeight;
|
||||
ChartDrawer.DrawPolygon(vh, pos1, p0, m_VisualMap.itemWidth / 2, m_ThemeInfo.visualMapBackgroundColor);
|
||||
}
|
||||
if (m_VisualMap.rangeMax < m_VisualMap.max)
|
||||
{
|
||||
var p1 = pos1 + dir * m_VisualMap.rangeMaxHeight;
|
||||
ChartDrawer.DrawPolygon(vh, p1, pos2, m_VisualMap.itemWidth / 2, m_ThemeInfo.visualMapBackgroundColor);
|
||||
}
|
||||
|
||||
if (m_VisualMap.hoverLink)
|
||||
{
|
||||
if (m_VisualMap.rtSelectedIndex >= 0)
|
||||
{
|
||||
var p0 = pos1 + dir * m_VisualMap.rangeMinHeight;
|
||||
var p1 = pos1 + dir * m_VisualMap.rangeMaxHeight;
|
||||
|
||||
if (m_VisualMap.orient == Orient.Vertical)
|
||||
{
|
||||
var p2 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y + (triangeLen / 2), p0.y, p1.y));
|
||||
var p3 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y - (triangeLen / 2), p0.y, p1.y));
|
||||
var p4 = new Vector3(centerPos.x + halfWid + triangeLen / 2, pointerPos.y);
|
||||
ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]);
|
||||
}
|
||||
else
|
||||
{
|
||||
var p2 = new Vector3(Mathf.Clamp(pointerPos.x + (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
|
||||
var p3 = new Vector3(Mathf.Clamp(pointerPos.x - (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
|
||||
var p4 = new Vector3(pointerPos.x, centerPos.y + halfWid + triangeLen / 2);
|
||||
ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]);
|
||||
}
|
||||
}
|
||||
else if (m_Tooltip.show && m_Tooltip.xValues[0] >= 0 && m_Tooltip.yValues[0] >= 0)
|
||||
{
|
||||
// var p0 = pos1 + dir * m_VisualMap.rangeMinHeight;
|
||||
// var p1 = pos1 + dir * m_VisualMap.rangeMaxHeight;
|
||||
// if (m_VisualMap.orient == Orient.Vertical)
|
||||
// {
|
||||
// var p2 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y + (triangeLen / 2), p0.y, p1.y));
|
||||
// var p3 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y - (triangeLen / 2), p0.y, p1.y));
|
||||
// var p4 = new Vector3(centerPos.x + halfWid + triangeLen / 2, pointerPos.y);
|
||||
// ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var p2 = new Vector3(Mathf.Clamp(pointerPos.x + (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
|
||||
// var p3 = new Vector3(Mathf.Clamp(pointerPos.x - (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
|
||||
// var p4 = new Vector3(pointerPos.x, centerPos.y + halfWid + triangeLen / 2);
|
||||
// ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/Runtime/Internal/CoordinateChart_DrawHeatmap.cs.meta
Normal file
11
Scripts/Runtime/Internal/CoordinateChart_DrawHeatmap.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2713cb84109d8491aa61bf37d1fa850e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1297
Scripts/Runtime/Internal/CoordinateChart_DrawLine.cs
Normal file
1297
Scripts/Runtime/Internal/CoordinateChart_DrawLine.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
Scripts/Runtime/Internal/CoordinateChart_DrawLine.cs.meta
Normal file
11
Scripts/Runtime/Internal/CoordinateChart_DrawLine.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e81383a033c064b2cbc5f63387113bb3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
73
Scripts/Runtime/Internal/CoordinateChart_DrawScatter.cs
Normal file
73
Scripts/Runtime/Internal/CoordinateChart_DrawScatter.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public partial class CoordinateChart
|
||||
{
|
||||
protected void DrawScatterSerie(VertexHelper vh, int colorIndex, Serie serie)
|
||||
{
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var color = serie.symbol.color != Color.clear ? serie.symbol.color : (Color)m_ThemeInfo.GetColor(colorIndex);
|
||||
color.a *= serie.symbol.opacity;
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow)
|
||||
: serie.dataCount;
|
||||
serie.animation.InitProgress(1, 0, 1);
|
||||
var rate = serie.animation.GetCurrRate();
|
||||
for (int n = serie.minShow; n < maxCount; n++)
|
||||
{
|
||||
var serieData = serie.GetDataList(m_DataZoom)[n];
|
||||
float xValue = serieData.data[0];
|
||||
float yValue = serieData.data[1];
|
||||
float pX = coordinateX + xAxis.axisLine.width;
|
||||
float pY = coordinateY + yAxis.axisLine.width;
|
||||
float xDataHig = (xValue - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWidth;
|
||||
float yDataHig = (yValue - yAxis.minValue) / (yAxis.maxValue - yAxis.minValue) * coordinateHeight;
|
||||
var pos = new Vector3(pX + xDataHig, pY + yDataHig);
|
||||
|
||||
var datas = serie.data[n].data;
|
||||
float symbolSize = 0;
|
||||
if (serie.highlighted || serieData.highlighted)
|
||||
{
|
||||
symbolSize = serie.symbol.GetSelectedSize(datas);
|
||||
}
|
||||
else
|
||||
{
|
||||
symbolSize = serie.symbol.GetSize(datas);
|
||||
}
|
||||
symbolSize *= rate;
|
||||
if (symbolSize > 100) symbolSize = 100;
|
||||
if (serie.type == SerieType.EffectScatter)
|
||||
{
|
||||
for (int count = 0; count < serie.symbol.animationSize.Count; count++)
|
||||
{
|
||||
var nowSize = serie.symbol.animationSize[count];
|
||||
color.a = (symbolSize - nowSize) / symbolSize;
|
||||
DrawSymbol(vh, serie.symbol.type, nowSize, 3, pos, color);
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawSymbol(vh, serie.symbol.type, symbolSize, 3, pos, color);
|
||||
}
|
||||
}
|
||||
if (!serie.animation.IsFinish())
|
||||
{
|
||||
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
|
||||
float speed = 1 / duration;
|
||||
serie.animation.CheckProgress(Time.deltaTime * speed);
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/Runtime/Internal/CoordinateChart_DrawScatter.cs.meta
Normal file
11
Scripts/Runtime/Internal/CoordinateChart_DrawScatter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f06734940c9e4f92897bb83573394a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
45
Scripts/Runtime/Internal/JsonDataSupport.cs
Normal file
45
Scripts/Runtime/Internal/JsonDataSupport.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// 支持从json格式的字符串中导入数据
|
||||
/// </summary>
|
||||
public class JsonDataSupport : IJsonData, ISerializationCallbackReceiver
|
||||
{
|
||||
[SerializeField] protected string m_JsonData;
|
||||
[SerializeField] protected bool m_DataFromJson;
|
||||
|
||||
/// <summary>
|
||||
/// json格式的字符串数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string jsonData { get { return m_JsonData; } set { m_JsonData = value; ParseJsonData(value); } }
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
if (m_DataFromJson)
|
||||
{
|
||||
ParseJsonData(m_JsonData);
|
||||
m_DataFromJson = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void ParseJsonData(string json)
|
||||
{
|
||||
throw new Exception("no support yet");
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Scripts/Runtime/Internal/JsonDataSupport.cs.meta
Normal file
13
Scripts/Runtime/Internal/JsonDataSupport.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73e326ed8a76f90408bfa9feb1797433
|
||||
timeCreated: 1555379601
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Scripts/Runtime/Internal/ListPool.cs
Normal file
27
Scripts/Runtime/Internal/ListPool.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class ListPool<T>
|
||||
{
|
||||
private static readonly ObjectPool<List<T>> s_ListPool = new ObjectPool<List<T>>(null, Clear);
|
||||
static void Clear(List<T> l) { l.Clear(); }
|
||||
|
||||
public static List<T> Get()
|
||||
{
|
||||
return s_ListPool.Get();
|
||||
}
|
||||
|
||||
public static void Release(List<T> toRelease)
|
||||
{
|
||||
s_ListPool.Release(toRelease);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/Runtime/Internal/ListPool.cs.meta
Normal file
11
Scripts/Runtime/Internal/ListPool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 359b8b077c5954701a132fe69eb8ba9c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
56
Scripts/Runtime/Internal/ObjectPool.cs
Normal file
56
Scripts/Runtime/Internal/ObjectPool.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class ObjectPool<T> where T : new()
|
||||
{
|
||||
private readonly Stack<T> m_Stack = new Stack<T>();
|
||||
private readonly UnityAction<T> m_ActionOnGet;
|
||||
private readonly UnityAction<T> m_ActionOnRelease;
|
||||
|
||||
public int countAll { get; private set; }
|
||||
public int countActive { get { return countAll - countInactive; } }
|
||||
public int countInactive { get { return m_Stack.Count; } }
|
||||
|
||||
public ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease)
|
||||
{
|
||||
m_ActionOnGet = actionOnGet;
|
||||
m_ActionOnRelease = actionOnRelease;
|
||||
}
|
||||
|
||||
public T Get()
|
||||
{
|
||||
T element;
|
||||
if (m_Stack.Count == 0)
|
||||
{
|
||||
element = new T();
|
||||
countAll++;
|
||||
}
|
||||
else
|
||||
{
|
||||
element = m_Stack.Pop();
|
||||
}
|
||||
if (m_ActionOnGet != null)
|
||||
m_ActionOnGet(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public void Release(T element)
|
||||
{
|
||||
if (m_Stack.Count > 0 && ReferenceEquals(m_Stack.Peek(), element))
|
||||
Debug.LogError("Internal error. Trying to destroy object that is already released to pool.");
|
||||
if (m_ActionOnRelease != null)
|
||||
m_ActionOnRelease(element);
|
||||
m_Stack.Push(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/Runtime/Internal/ObjectPool.cs.meta
Normal file
11
Scripts/Runtime/Internal/ObjectPool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a543f22be703f4d58b47fa6d343581c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user