mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 00:20:18 +00:00
3.0
This commit is contained in:
@@ -6,12 +6,12 @@ namespace XCharts.Runtime
|
||||
{
|
||||
public class ChartLabel : Image
|
||||
{
|
||||
[SerializeField] private ChartText m_LabelText;
|
||||
|
||||
private bool m_AutoHideIconWhenLabelEmpty = false;
|
||||
private bool m_LabelAutoSize = true;
|
||||
private float m_LabelPaddingLeftRight = 3f;
|
||||
private float m_LabelPaddingTopBottom = 3f;
|
||||
|
||||
private ChartText m_LabelText;
|
||||
private RectTransform m_LabelRect;
|
||||
private RectTransform m_LabelBackgroundRect;
|
||||
private RectTransform m_IconRect;
|
||||
|
||||
@@ -7,6 +7,7 @@ using TMPro;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[System.Serializable]
|
||||
public class ChartText
|
||||
{
|
||||
private float m_ExtraWidth;
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
internal 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);
|
||||
}
|
||||
}
|
||||
|
||||
internal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a709ca44e9a445bd86bde1bbfae80de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,6 +7,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
internal class ObjectPool<T> where T : new()
|
||||
{
|
||||
private readonly bool m_NewIfEmpty = true;
|
||||
private readonly Stack<T> m_Stack = new Stack<T>();
|
||||
private readonly UnityAction<T> m_ActionOnGet;
|
||||
private readonly UnityAction<T> m_ActionOnRelease;
|
||||
@@ -15,8 +16,9 @@ namespace XCharts.Runtime
|
||||
public int countActive { get { return countAll - countInactive; } }
|
||||
public int countInactive { get { return m_Stack.Count; } }
|
||||
|
||||
public ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease)
|
||||
public ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease, bool newIfEmpty = true)
|
||||
{
|
||||
m_NewIfEmpty = newIfEmpty;
|
||||
m_ActionOnGet = actionOnGet;
|
||||
m_ActionOnRelease = actionOnRelease;
|
||||
}
|
||||
@@ -26,6 +28,7 @@ namespace XCharts.Runtime
|
||||
T element;
|
||||
if (m_Stack.Count == 0)
|
||||
{
|
||||
if (!m_NewIfEmpty) return default(T);
|
||||
element = new T();
|
||||
countAll++;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
@@ -37,15 +36,6 @@ namespace XCharts.Runtime
|
||||
return element;
|
||||
}
|
||||
|
||||
private static GameObject CreateSerieLabel(string name, Transform parent, LabelStyle label, Color color,
|
||||
float iconWidth, float iconHeight, ThemeStyle theme)
|
||||
{
|
||||
var element = ChartHelper.AddSerieLabel(name, parent, label.backgroundWidth, label.backgroundHeight,
|
||||
color, label.textStyle, theme);
|
||||
ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight);
|
||||
return element;
|
||||
}
|
||||
|
||||
public static void Release(GameObject element)
|
||||
{
|
||||
if (element == null) return;
|
||||
@@ -72,5 +62,14 @@ namespace XCharts.Runtime
|
||||
m_Stack.Clear();
|
||||
m_ReleaseDic.Clear();
|
||||
}
|
||||
|
||||
private static GameObject CreateSerieLabel(string name, Transform parent, LabelStyle label, Color color,
|
||||
float iconWidth, float iconHeight, ThemeStyle theme)
|
||||
{
|
||||
var element = ChartHelper.AddSerieLabel(name, parent, label.backgroundWidth, label.backgroundHeight,
|
||||
color, label.textStyle, theme);
|
||||
ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight);
|
||||
return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,11 +233,12 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
public static ChartText AddTextObject(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax,
|
||||
Vector2 pivot, Vector2 sizeDelta, TextStyle textStyle, ComponentTheme theme)
|
||||
Vector2 pivot, Vector2 sizeDelta, TextStyle textStyle, ComponentTheme theme, ChartText chartText = null)
|
||||
{
|
||||
GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
txtObj.transform.localEulerAngles = new Vector3(0, 0, textStyle.rotate);
|
||||
var chartText = new ChartText();
|
||||
if(chartText == null)
|
||||
chartText = new ChartText();
|
||||
#if dUI_TextMeshPro
|
||||
RemoveComponent<Text>(txtObj);
|
||||
chartText.tmpText = GetOrAddComponent<TextMeshProUGUI>(txtObj);
|
||||
@@ -377,9 +378,11 @@ namespace XCharts.Runtime
|
||||
var sizeDelta = new Vector2(width, height);
|
||||
GameObject iconObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
var img = GetOrAddComponent<Image>(iconObj);
|
||||
img.raycastTarget = false;
|
||||
img.type = type;
|
||||
if (sprite != null)
|
||||
if (img.raycastTarget != false)
|
||||
img.raycastTarget = false;
|
||||
if (img.type != type)
|
||||
img.type = type;
|
||||
if (sprite != null && img.sprite != sprite)
|
||||
{
|
||||
img.sprite = sprite;
|
||||
if (width == 0 || height == 0)
|
||||
@@ -398,15 +401,14 @@ namespace XCharts.Runtime
|
||||
var iconStyle = axis.iconStyle;
|
||||
var labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
var label = GetOrAddComponent<ChartLabel>(labelObj);
|
||||
|
||||
var labelShow = axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0);
|
||||
if (labelShow)
|
||||
{
|
||||
if (!axis.axisLabel.showStartLabel && index == 0) labelShow = false;
|
||||
else if (!axis.axisLabel.showEndLabel && index == total - 1) labelShow = false;
|
||||
}
|
||||
label.label = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme);
|
||||
label.icon = ChartHelper.AddIcon("Icon", label.gameObject.transform, iconStyle.width, iconStyle.height);
|
||||
label.label = AddTextObject("Text", label.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme, label.label);
|
||||
label.icon = ChartHelper.AddIcon("Icon", label.transform, iconStyle.width, iconStyle.height);
|
||||
label.SetAutoSize(false);
|
||||
label.UpdateIcon(iconStyle, axis.GetIcon(index));
|
||||
label.label.SetActive(labelShow);
|
||||
@@ -421,7 +423,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
var label = GetOrAddComponent<ChartLabel>(labelObj);
|
||||
label.label = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme);
|
||||
label.label = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme, label.label);
|
||||
label.icon = ChartHelper.AddIcon("Icon", label.gameObject.transform, 0, 0);
|
||||
label.SetAutoSize(true);
|
||||
label.label.SetActive(true);
|
||||
@@ -468,7 +470,7 @@ namespace XCharts.Runtime
|
||||
var label = GetOrAddComponent<ChartLabel>(labelGameObject);
|
||||
label.labelBackground = ChartHelper.AddIcon("Background", label.gameObject.transform, 50, 20);
|
||||
label.labelBackground.color = Color.black;
|
||||
label.label = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme.tooltip);
|
||||
label.label = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme.tooltip, label.label);
|
||||
label.SetAutoSize(true);
|
||||
label.SetText("");
|
||||
label.color = textStyle.color;
|
||||
|
||||
Reference in New Issue
Block a user