mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 18:00:26 +00:00
增加Axis的图标、自动换行、自定义长宽的支持
This commit is contained in:
@@ -100,6 +100,8 @@ namespace XCharts
|
||||
[SerializeField] protected bool m_Inverse = false;
|
||||
[SerializeField] private bool m_Clockwise = true;
|
||||
[SerializeField] private bool m_InsertDataToHead;
|
||||
[SerializeField] private IconStyle m_IconStyle = new IconStyle();
|
||||
[SerializeField] protected List<Sprite> m_Icons = new List<Sprite>();
|
||||
[SerializeField] protected List<string> m_Data = new List<string>();
|
||||
[SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine;
|
||||
[SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName;
|
||||
@@ -288,6 +290,14 @@ namespace XCharts
|
||||
set { if (value != null) { m_Data = value; SetAllDirty(); } }
|
||||
}
|
||||
/// <summary>
|
||||
/// 类目数据对应的图标。
|
||||
/// </summary>
|
||||
public List<Sprite> icons
|
||||
{
|
||||
get { return m_Icons; }
|
||||
set { if (value != null) { m_Icons = value; SetAllDirty(); } }
|
||||
}
|
||||
/// <summary>
|
||||
/// axis Line.
|
||||
/// 坐标轴轴线。
|
||||
/// /// </summary>
|
||||
@@ -350,6 +360,14 @@ namespace XCharts
|
||||
get { return m_InsertDataToHead; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_InsertDataToHead, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 图标样式。
|
||||
/// </summary>
|
||||
public IconStyle iconStyle
|
||||
{
|
||||
get { return m_IconStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_IconStyle, value)) SetAllDirty(); }
|
||||
}
|
||||
public override bool vertsDirty
|
||||
{
|
||||
get { return m_VertsDirty || axisLine.anyDirty || axisTick.anyDirty || splitLine.anyDirty || splitArea.anyDirty; }
|
||||
@@ -374,11 +392,7 @@ namespace XCharts
|
||||
splitArea.ClearVerticesDirty();
|
||||
}
|
||||
public int index { get; internal set; }
|
||||
/// <summary>
|
||||
/// the axis label text list.
|
||||
/// 坐标轴刻度标签的Text列表。
|
||||
/// </summary>
|
||||
public List<ChartText> axisLabelTextList { get { return m_AxisLabelTextList; } set { m_AxisLabelTextList = value; } }
|
||||
public List<ChartLabel> runtimeAxisLabelList { get { return m_AxisLabelList; } set { m_AxisLabelList = value; } }
|
||||
/// <summary>
|
||||
/// the current minimun value.
|
||||
/// 当前最小值。
|
||||
@@ -429,7 +443,7 @@ namespace XCharts
|
||||
private int filterEnd;
|
||||
private int filterMinShow;
|
||||
private List<string> filterData;
|
||||
private List<ChartText> m_AxisLabelTextList = new List<ChartText>();
|
||||
private List<ChartLabel> m_AxisLabelList = new List<ChartLabel>();
|
||||
private GameObject m_TooltipLabel;
|
||||
private ChartText m_TooltipLabelText;
|
||||
private RectTransform m_TooltipLabelRect;
|
||||
@@ -461,12 +475,15 @@ namespace XCharts
|
||||
axis.logBase = logBase;
|
||||
axis.logBaseE = logBaseE;
|
||||
axis.ceilRate = ceilRate;
|
||||
axis.insertDataToHead = insertDataToHead;
|
||||
axis.iconStyle = iconStyle.Clone();
|
||||
axis.axisLine = axisLine.Clone();
|
||||
axis.axisName = axisName.Clone();
|
||||
axis.axisTick = axisTick.Clone();
|
||||
axis.axisLabel = axisLabel.Clone();
|
||||
axis.splitLine = splitLine.Clone();
|
||||
axis.splitArea = splitArea.Clone();
|
||||
axis.icons = new List<Sprite>();
|
||||
axis.data = new List<string>();
|
||||
ChartHelper.CopyList(axis.data, data);
|
||||
return axis;
|
||||
@@ -487,6 +504,8 @@ namespace XCharts
|
||||
logBase = axis.logBase;
|
||||
logBaseE = axis.logBaseE;
|
||||
ceilRate = axis.ceilRate;
|
||||
insertDataToHead = axis.insertDataToHead;
|
||||
iconStyle.Copy(axis.iconStyle);
|
||||
axisLine.Copy(axis.axisLine);
|
||||
axisName.Copy(axis.axisName);
|
||||
axisTick.Copy(axis.axisTick);
|
||||
@@ -494,6 +513,7 @@ namespace XCharts
|
||||
splitLine.Copy(axis.splitLine);
|
||||
splitArea.Copy(axis.splitArea);
|
||||
ChartHelper.CopyList(data, axis.data);
|
||||
ChartHelper.CopyList<Sprite>(icons, axis.icons);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -502,6 +522,7 @@ namespace XCharts
|
||||
public void ClearData()
|
||||
{
|
||||
m_Data.Clear();
|
||||
m_Icons.Clear();
|
||||
m_RuntimeData.Clear();
|
||||
SetAllDirty();
|
||||
}
|
||||
@@ -552,6 +573,20 @@ namespace XCharts
|
||||
SetAllDirty();
|
||||
}
|
||||
|
||||
public void AddIcon(Sprite icon)
|
||||
{
|
||||
if (maxCache > 0)
|
||||
{
|
||||
while (m_Icons.Count > maxCache)
|
||||
{
|
||||
m_Icons.RemoveAt(m_InsertDataToHead ? m_Icons.Count - 1 : 0);
|
||||
}
|
||||
}
|
||||
if (m_InsertDataToHead) m_Icons.Insert(0, icon);
|
||||
else m_Icons.Add(icon);
|
||||
SetAllDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得指定索引的类目数据
|
||||
/// </summary>
|
||||
@@ -580,6 +615,14 @@ namespace XCharts
|
||||
return "";
|
||||
}
|
||||
|
||||
public Sprite GetIcon(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_Icons.Count)
|
||||
return m_Icons[index];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得指定区域缩放的类目数据列表
|
||||
/// </summary>
|
||||
@@ -667,12 +710,12 @@ namespace XCharts
|
||||
{
|
||||
var minValue = GetCurrMinValue(duration);
|
||||
var maxValue = GetCurrMaxValue(duration);
|
||||
for (int i = 0; i < axisLabelTextList.Count; i++)
|
||||
for (int i = 0; i < runtimeAxisLabelList.Count; i++)
|
||||
{
|
||||
if (axisLabelTextList[i] != null)
|
||||
if (runtimeAxisLabelList[i] != null)
|
||||
{
|
||||
var text = AxisHelper.GetLabelName(this, coordinateWidth, i, minValue, maxValue, dataZoom, forcePercent);
|
||||
axisLabelTextList[i].SetText(text);
|
||||
runtimeAxisLabelList[i].SetText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -876,7 +919,8 @@ namespace XCharts
|
||||
m_Data = new List<string>()
|
||||
{
|
||||
"x1","x2","x3","x4","x5"
|
||||
}
|
||||
},
|
||||
m_Icons = new List<Sprite>(5),
|
||||
};
|
||||
axis.splitLine.show = false;
|
||||
axis.splitLine.lineStyle.type = LineStyle.Type.None;
|
||||
@@ -908,6 +952,7 @@ namespace XCharts
|
||||
m_BoundaryGap = false,
|
||||
m_Position = AxisPosition.Left,
|
||||
m_Data = new List<string>(5),
|
||||
|
||||
};
|
||||
axis.splitLine.show = true;
|
||||
axis.splitLine.lineStyle.type = LineStyle.Type.None;
|
||||
|
||||
@@ -26,6 +26,9 @@ namespace XCharts
|
||||
[SerializeField] private string m_NumericFormatter = "";
|
||||
[SerializeField] private bool m_ShowAsPositiveNumber = false;
|
||||
[SerializeField] private bool m_OnZero = false;
|
||||
[SerializeField] private float m_Width = 0f;
|
||||
[SerializeField] private float m_Height = 0f;
|
||||
[SerializeField] private bool m_AutoAlign = true;
|
||||
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
|
||||
@@ -106,6 +109,30 @@ namespace XCharts
|
||||
get { return m_OnZero; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 文本的宽。为0时会自动匹配。
|
||||
/// </summary>
|
||||
public float width
|
||||
{
|
||||
get { return m_Width; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 文本的高。为0时会自动匹配。
|
||||
/// </summary>
|
||||
public float height
|
||||
{
|
||||
get { return m_Height; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 文本是否自动选对齐方式。为false时会用TextStyle下的alignment。
|
||||
/// </summary>
|
||||
public bool autoAlign
|
||||
{
|
||||
get { return m_AutoAlign; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_AutoAlign, value)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文本限制。
|
||||
@@ -150,28 +177,34 @@ namespace XCharts
|
||||
|
||||
public AxisLabel Clone()
|
||||
{
|
||||
var axisLable = new AxisLabel();
|
||||
axisLable.show = show;
|
||||
axisLable.formatter = formatter;
|
||||
axisLable.interval = interval;
|
||||
axisLable.inside = inside;
|
||||
axisLable.margin = margin;
|
||||
axisLable.numericFormatter = numericFormatter;
|
||||
axisLable.textLimit = textLimit.Clone();
|
||||
axisLable.textStyle.Copy(textStyle);
|
||||
return axisLable;
|
||||
var axisLabel = new AxisLabel();
|
||||
axisLabel.show = show;
|
||||
axisLabel.formatter = formatter;
|
||||
axisLabel.interval = interval;
|
||||
axisLabel.inside = inside;
|
||||
axisLabel.margin = margin;
|
||||
axisLabel.numericFormatter = numericFormatter;
|
||||
axisLabel.width = width;
|
||||
axisLabel.height = height;
|
||||
axisLabel.autoAlign = autoAlign;
|
||||
axisLabel.textLimit = textLimit.Clone();
|
||||
axisLabel.textStyle.Copy(textStyle);
|
||||
return axisLabel;
|
||||
}
|
||||
|
||||
public void Copy(AxisLabel axisLable)
|
||||
public void Copy(AxisLabel axisLabel)
|
||||
{
|
||||
show = axisLable.show;
|
||||
formatter = axisLable.formatter;
|
||||
interval = axisLable.interval;
|
||||
inside = axisLable.inside;
|
||||
margin = axisLable.margin;
|
||||
numericFormatter = axisLable.numericFormatter;
|
||||
textLimit.Copy(axisLable.textLimit);
|
||||
textStyle.Copy(axisLable.textStyle);
|
||||
show = axisLabel.show;
|
||||
formatter = axisLabel.formatter;
|
||||
interval = axisLabel.interval;
|
||||
inside = axisLabel.inside;
|
||||
margin = axisLabel.margin;
|
||||
numericFormatter = axisLabel.numericFormatter;
|
||||
width = axisLabel.width;
|
||||
height = axisLabel.height;
|
||||
autoAlign = axisLabel.autoAlign;
|
||||
textLimit.Copy(axisLabel.textLimit);
|
||||
textStyle.Copy(axisLabel.textStyle);
|
||||
}
|
||||
|
||||
public void SetRelatedText(ChartText txt, float labelWidth)
|
||||
|
||||
@@ -10,9 +10,6 @@ using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// 系列数据项的图标
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class IconStyle : SubComponent
|
||||
{
|
||||
@@ -25,8 +22,8 @@ namespace XCharts
|
||||
[SerializeField] private Layer m_Layer;
|
||||
[SerializeField] private Sprite m_Sprite;
|
||||
[SerializeField] private Color m_Color = Color.white;
|
||||
[SerializeField] private float m_Width = 40;
|
||||
[SerializeField] private float m_Height = 40;
|
||||
[SerializeField] private float m_Width = 20;
|
||||
[SerializeField] private float m_Height = 20;
|
||||
[SerializeField] private Vector3 m_Offset;
|
||||
|
||||
public void Reset()
|
||||
@@ -35,8 +32,8 @@ namespace XCharts
|
||||
m_Layer = Layer.UnderLabel;
|
||||
m_Sprite = null;
|
||||
m_Color = Color.white;
|
||||
m_Width = 40;
|
||||
m_Height = 40;
|
||||
m_Width = 20;
|
||||
m_Height = 20;
|
||||
m_Offset = Vector3.zero;
|
||||
}
|
||||
/// <summary>
|
||||
@@ -70,6 +67,28 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
|
||||
|
||||
public IconStyle Clone()
|
||||
{
|
||||
var iconStyle = new IconStyle();
|
||||
iconStyle.show = show;
|
||||
iconStyle.layer = layer;
|
||||
iconStyle.sprite = sprite;
|
||||
iconStyle.color = color;
|
||||
iconStyle.width = width;
|
||||
iconStyle.height = height;
|
||||
iconStyle.offset = offset;
|
||||
return iconStyle;
|
||||
}
|
||||
|
||||
public void Copy(IconStyle iconStyle)
|
||||
{
|
||||
show = iconStyle.show;
|
||||
layer = iconStyle.layer;
|
||||
sprite = iconStyle.sprite;
|
||||
color = iconStyle.color;
|
||||
width = iconStyle.width;
|
||||
height = iconStyle.height;
|
||||
offset = iconStyle.offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace XCharts
|
||||
{
|
||||
[SerializeField] private Font m_Font;
|
||||
|
||||
[SerializeField] private bool m_Wrap = true;
|
||||
[SerializeField] private float m_Rotate = 0;
|
||||
[SerializeField] private Vector2 m_Offset = Vector2.zero;
|
||||
[SerializeField] private Color m_Color = Color.clear;
|
||||
@@ -119,6 +120,14 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否自动换行。
|
||||
/// </summary>
|
||||
public bool wrap
|
||||
{
|
||||
get { return m_Wrap; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Wrap, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 对齐方式。
|
||||
/// </summary>
|
||||
public TextAnchor alignment
|
||||
@@ -186,6 +195,7 @@ namespace XCharts
|
||||
fontStyle = textStyle.fontStyle;
|
||||
lineSpacing = textStyle.lineSpacing;
|
||||
alignment = textStyle.alignment;
|
||||
wrap = textStyle.wrap;
|
||||
#if dUI_TextMeshPro
|
||||
m_TMPFont = textStyle.tmpFont;
|
||||
m_TMPAlignment = textStyle.tmpAlignment;
|
||||
@@ -210,7 +220,7 @@ namespace XCharts
|
||||
|
||||
public int GetFontSize(ComponentTheme defaultTheme)
|
||||
{
|
||||
if(fontSize == 0) return defaultTheme.fontSize;
|
||||
if (fontSize == 0) return defaultTheme.fontSize;
|
||||
else return fontSize;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user