XCharts 2.0

This commit is contained in:
monitor1394
2021-01-11 08:54:28 +08:00
parent ed8d0687f7
commit 489095865d
304 changed files with 14799 additions and 12503 deletions

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
@@ -55,7 +55,7 @@ namespace XCharts
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// the origin of area.
@@ -64,7 +64,7 @@ namespace XCharts
public AreaOrigin origin
{
get { return m_Origin; }
set { if (PropertyUtility.SetStruct(ref m_Origin, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Origin, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of area,default use serie color.
@@ -73,7 +73,7 @@ namespace XCharts
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color, start color to toColor.
@@ -82,7 +82,7 @@ namespace XCharts
public Color32 toColor
{
get { return m_ToColor; }
set { if (PropertyUtility.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Opacity of the component. Supports value from 0 to 1, and the component will not be drawn when set to 0.
@@ -91,7 +91,7 @@ namespace XCharts
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
/// <summary>
/// 鼠标悬浮时是否高亮之前的区域
@@ -99,7 +99,7 @@ namespace XCharts
public bool tooltipHighlight
{
get { return m_TooltipHighlight; }
set { if (PropertyUtility.SetStruct(ref m_TooltipHighlight, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_TooltipHighlight, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of area,default use serie color.
@@ -108,7 +108,7 @@ namespace XCharts
public Color32 highlightColor
{
get { return m_HighlightColor; }
set { if (PropertyUtility.SetColor(ref m_HighlightColor, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_HighlightColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color, start highlightColor to highlightToColor.
@@ -117,7 +117,7 @@ namespace XCharts
public Color32 highlightToColor
{
get { return m_HighlightToColor; }
set { if (PropertyUtility.SetColor(ref m_HighlightToColor, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_HighlightToColor, value)) SetVerticesDirty(); }
}
public static AreaStyle defaultAreaStyle
@@ -129,10 +129,32 @@ namespace XCharts
m_Show = false,
m_Color = Color.clear,
m_ToColor = Color.clear,
m_Opacity = 1
m_Opacity = 0.6f
};
return area;
}
}
public Color32 GetColor()
{
if (m_Opacity == 1) return m_Color;
var color = m_Color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor(Color32 themeColor)
{
if (!ChartHelper.IsClearColor(color))
{
return GetColor();
}
else
{
var color = themeColor;
color.a = (byte)(color.a * opacity);
return color;
}
}
}
}

View File

@@ -0,0 +1,97 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// </summary>
[Serializable]
public class Arrow : SubComponent
{
[SerializeField] private float m_Width = 10;
[SerializeField] private float m_Height = 15;
[SerializeField] private float m_Offset = 0;
[SerializeField] private float m_Dent = 3;
[SerializeField] private Color32 m_Color = Color.clear;
/// <summary>
/// The widht of arrow.
/// 箭头宽。
/// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
/// <summary>
/// The height of arrow.
/// 箭头高。
/// </summary>
public float height
{
get { return m_Height; }
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetVerticesDirty(); }
}
/// <summary>
/// The offset of arrow.
/// 箭头偏移。
/// </summary>
public float offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
}
/// <summary>
/// The dent of arrow.
/// 箭头的凹度。
/// </summary>
public float dent
{
get { return m_Dent; }
set { if (PropertyUtil.SetStruct(ref m_Dent, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of arrow.
/// 箭头颜色。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
public Arrow Clone()
{
var arrow = new Arrow();
arrow.width = width;
arrow.height = height;
arrow.offset = offset;
arrow.dent = dent;
arrow.color = color;
return arrow;
}
public void Copy(Arrow arrow)
{
width = arrow.width;
height = arrow.height;
offset = arrow.offset;
dent = arrow.dent;
color = arrow.color;
}
public Color32 GetColor(Color32 defaultColor)
{
if (ChartHelper.IsClearColor(color)) return defaultColor;
else return color;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bf0a2263a511d4348a256df8e732bb1b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
@@ -22,15 +22,12 @@ namespace XCharts
[SerializeField] private string m_Formatter;
[SerializeField] private int m_Interval = 0;
[SerializeField] private bool m_Inside = false;
[SerializeField] private float m_Rotate;
[SerializeField] private float m_Margin;
[SerializeField] private Color m_Color;
[SerializeField] private int m_FontSize;
[SerializeField] private FontStyle m_FontStyle;
[SerializeField] private string m_NumericFormatter = "";
[SerializeField] private bool m_ShowAsPositiveNumber = false;
[SerializeField] private bool m_OnZero = false;
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
/// <summary>
/// Set this to false to prevent the axis label from appearing.
@@ -39,7 +36,7 @@ namespace XCharts
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// The display interval of the axis label.
@@ -48,7 +45,7 @@ namespace XCharts
public int interval
{
get { return m_Interval; }
set { if (PropertyUtility.SetStruct(ref m_Interval, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetComponentDirty(); }
}
/// <summary>
/// Set this to true so the axis labels face the inside direction.
@@ -57,16 +54,7 @@ namespace XCharts
public bool inside
{
get { return m_Inside; }
set { if (PropertyUtility.SetStruct(ref m_Inside, value)) SetComponentDirty(); }
}
/// <summary>
/// Rotation degree of axis label, which is especially useful when there is no enough space for category axis.
/// 刻度标签旋转的角度,在类目轴的类目标签显示不下的时候可以通过旋转防止标签之间重叠。
/// </summary>
public float rotate
{
get { return m_Rotate; }
set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetComponentDirty(); }
}
/// <summary>
/// The margin between the axis label and the axis line.
@@ -75,34 +63,7 @@ namespace XCharts
public float margin
{
get { return m_Margin; }
set { if (PropertyUtility.SetStruct(ref m_Margin, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of axis label text.
/// 刻度标签文字的颜色默认取Theme的axisTextColor。
/// </summary>
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetComponentDirty(); }
}
/// <summary>
/// font size.
/// 文字的字体大小。
/// </summary>
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
}
/// <summary>
/// font style.
/// 文字字体的风格。
/// </summary>
public FontStyle fontStyle
{
get { return m_FontStyle; }
set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Margin, value)) SetComponentDirty(); }
}
/// <summary>
/// 图例内容字符串模版格式器。支持用 \n 换行。
@@ -111,7 +72,7 @@ namespace XCharts
public string formatter
{
get { return m_Formatter; }
set { if (PropertyUtility.SetClass(ref m_Formatter, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); }
}
/// <summary>
@@ -124,7 +85,7 @@ namespace XCharts
public string numericFormatter
{
get { return m_NumericFormatter; }
set { if (PropertyUtility.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
}
/// <summary>
@@ -134,7 +95,7 @@ namespace XCharts
public bool showAsPositiveNumber
{
get { return m_ShowAsPositiveNumber; }
set { if (PropertyUtility.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); }
}
/// <summary>
@@ -143,7 +104,7 @@ namespace XCharts
public bool onZero
{
get { return m_OnZero; }
set { if (PropertyUtility.SetStruct(ref m_OnZero, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetComponentDirty(); }
}
/// <summary>
@@ -155,6 +116,16 @@ namespace XCharts
set { if (value != null) { m_TextLimit = value; SetComponentDirty(); } }
}
/// <summary>
/// The text style of axis name.
/// 文本样式。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
}
public override bool componentDirty { get { return m_ComponentDirty || m_TextLimit.componentDirty; } }
internal override void ClearComponentDirty()
{
@@ -171,11 +142,8 @@ namespace XCharts
m_Show = true,
m_Interval = 0,
m_Inside = false,
m_Rotate = 0,
m_Margin = 8,
m_Color = Color.clear,
m_FontSize = 18,
m_FontStyle = FontStyle.Normal
m_TextStyle = new TextStyle(),
};
}
}
@@ -187,12 +155,10 @@ namespace XCharts
axisLable.formatter = formatter;
axisLable.interval = interval;
axisLable.inside = inside;
axisLable.rotate = rotate;
axisLable.margin = margin;
axisLable.color = color;
axisLable.fontSize = fontSize;
axisLable.numericFormatter = numericFormatter;
axisLable.textLimit = textLimit.Clone();
axisLable.textStyle.Copy(textStyle);
return axisLable;
}
@@ -202,15 +168,13 @@ namespace XCharts
formatter = axisLable.formatter;
interval = axisLable.interval;
inside = axisLable.inside;
rotate = axisLable.rotate;
margin = axisLable.margin;
color = axisLable.color;
fontSize = axisLable.fontSize;
numericFormatter = axisLable.numericFormatter;
textLimit.Copy(axisLable.textLimit);
textStyle.Copy(axisLable.textStyle);
}
public void SetRelatedText(Text txt, float labelWidth)
public void SetRelatedText(ChartText txt, float labelWidth)
{
m_TextLimit.SetRelatedText(txt, labelWidth);
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
@@ -11,29 +11,15 @@ namespace XCharts
{
/// <summary>
/// Settings related to axis line.
/// 坐标轴的分隔线。
/// 坐标轴线。
/// </summary>
[System.Serializable]
public class AxisLine : SubComponent
public class AxisLine : BaseLine
{
[SerializeField] private bool m_Show;
[SerializeField] private bool m_OnZero;
[SerializeField] private float m_Width = 0.6f;
[SerializeField] private bool m_Symbol;
[SerializeField] private float m_SymbolWidth;
[SerializeField] private float m_SymbolHeight;
[SerializeField] private float m_SymbolOffset;
[SerializeField] private float m_SymbolDent;
[SerializeField] private bool m_ShowArrow;
[SerializeField] private Arrow m_Arrow = new Arrow();
/// <summary>
/// Set this to false to prevent the axis line from showing.
/// 是否显示坐标轴轴线。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// When mutiple axes exists, this option can be used to specify which axis can be "onZero" to.
/// X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上,只有在另一个轴为数值轴且包含 0 刻度时有效。
@@ -41,63 +27,26 @@ namespace XCharts
public bool onZero
{
get { return m_OnZero; }
set { if (PropertyUtility.SetStruct(ref m_OnZero, value)) SetVerticesDirty(); }
}
/// <summary>
/// line style line width.
/// 坐标轴线线宽。
/// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show the arrow symbol of axis.
/// 是否显示箭头。
/// </summary>
public bool symbol
public bool showArrow
{
get { return m_Symbol; }
set { if (PropertyUtility.SetStruct(ref m_Symbol, value)) SetVerticesDirty(); }
get { return m_ShowArrow; }
set { if (PropertyUtil.SetStruct(ref m_ShowArrow, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of arrow symbol.
/// 箭头
/// the arrow of line.
/// 轴线箭头。
/// </summary>
public float symbolWidth
public Arrow arrow
{
get { return m_SymbolWidth; }
set { if (PropertyUtility.SetStruct(ref m_SymbolWidth, value)) SetVerticesDirty(); }
get { return m_Arrow; }
set { if (PropertyUtil.SetClass(ref m_Arrow, value)) SetVerticesDirty(); }
}
/// <summary>
/// the height of arrow symbol.
/// 箭头高。
/// </summary>
public float symbolHeight
{
get { return m_SymbolHeight; }
set { if (PropertyUtility.SetStruct(ref m_SymbolHeight, value)) SetVerticesDirty(); }
}
/// <summary>
/// the offset of arrow symbol.
/// 箭头偏移。
/// </summary>
public float symbolOffset
{
get { return m_SymbolOffset; }
set { if (PropertyUtility.SetStruct(ref m_SymbolOffset, value)) SetVerticesDirty(); }
}
/// <summary>
/// the dent of arrow symbol.
/// 箭头的凹陷程度。
/// </summary>
public float symbolDent
{
get { return m_SymbolDent; }
set { if (PropertyUtility.SetStruct(ref m_SymbolDent, value)) SetVerticesDirty(); }
}
public static AxisLine defaultAxisLine
{
get
@@ -106,12 +55,9 @@ namespace XCharts
{
m_Show = true,
m_OnZero = true,
m_Width = 0.7f,
m_Symbol = false,
m_SymbolWidth = 10,
m_SymbolHeight = 15,
m_SymbolOffset = -5f,
m_SymbolDent = 3,
m_ShowArrow = false,
m_Arrow = new Arrow(),
m_LineStyle = new LineStyle(LineStyle.Type.None),
};
return axisLine;
}
@@ -122,25 +68,17 @@ namespace XCharts
var axisLine = new AxisLine();
axisLine.show = show;
axisLine.onZero = onZero;
axisLine.width = width;
axisLine.symbol = symbol;
axisLine.symbolWidth = symbolWidth;
axisLine.symbolHeight = symbolHeight;
axisLine.symbolOffset = symbolOffset;
axisLine.symbolDent = symbolDent;
axisLine.showArrow = showArrow;
axisLine.arrow = arrow.Clone();
return axisLine;
}
public void Copy(AxisLine axisLine)
{
show = axisLine.show;
base.Copy(axisLine);
onZero = axisLine.onZero;
width = axisLine.width;
symbol = axisLine.symbol;
symbolWidth = axisLine.symbolWidth;
symbolHeight = axisLine.symbolHeight;
symbolOffset = axisLine.symbolOffset;
symbolDent = axisLine.symbolDent;
showArrow = axisLine.showArrow;
arrow.Copy(axisLine.arrow);
}
}
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
@@ -30,11 +30,7 @@ namespace XCharts
[SerializeField] private bool m_Show;
[SerializeField] private string m_Name;
[SerializeField] private Location m_Location;
[SerializeField] private Vector2 m_Offset;
[SerializeField] private float m_Rotate;
[SerializeField] private Color m_Color;
[SerializeField] private int m_FontSize;
[SerializeField] private FontStyle m_FontStyle;
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
/// <summary>
/// Whether to show axis name.
@@ -43,7 +39,7 @@ namespace XCharts
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// the name of axis.
@@ -52,7 +48,7 @@ namespace XCharts
public string name
{
get { return m_Name; }
set { if (PropertyUtility.SetClass(ref m_Name, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetClass(ref m_Name, value)) SetComponentDirty(); }
}
/// <summary>
/// Location of axis name.
@@ -61,52 +57,17 @@ namespace XCharts
public Location location
{
get { return m_Location; }
set { if (PropertyUtility.SetStruct(ref m_Location, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Location, value)) SetComponentDirty(); }
}
/// <summary>
/// the offset of axis name and axis line.
/// 坐标轴名称与轴线之间的偏移
/// The text style of axis name.
/// 文本样式
/// </summary>
public Vector2 offset
public TextStyle textStyle
{
get { return m_Offset; }
set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetComponentDirty(); }
}
/// <summary>
/// Rotation of axis name.
/// 坐标轴名字旋转,角度值。
/// </summary>
public float rotate
{
get { return m_Rotate; }
set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
}
/// <summary>
/// Color of axis name.
/// 坐标轴名称的文字颜色。
/// </summary>
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetComponentDirty(); }
}
/// <summary>
/// axis name font size.
/// 坐标轴名称的文字大小。
/// </summary>
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
}
/// <summary>
/// axis name font style.
/// 坐标轴名称的文字风格。
/// </summary>
public FontStyle fontStyle
{
get { return m_FontStyle; }
set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
}
public static AxisName defaultAxisName
@@ -118,10 +79,7 @@ namespace XCharts
m_Show = false,
m_Name = "axisName",
m_Location = Location.End,
m_Rotate = 0,
m_Color = Color.clear,
m_FontSize = 18,
m_FontStyle = FontStyle.Normal
m_TextStyle = new TextStyle(),
};
}
}
@@ -132,11 +90,7 @@ namespace XCharts
axisName.show = show;
axisName.name = name;
axisName.location = location;
axisName.offset = offset;
axisName.rotate = rotate;
axisName.color = color;
axisName.fontSize = fontSize;
axisName.fontStyle = fontStyle;
axisName.textStyle.Copy(textStyle);
return axisName;
}
@@ -145,11 +99,7 @@ namespace XCharts
show = axisName.show;
name = axisName.name;
location = axisName.location;
offset = axisName.offset;
rotate = axisName.rotate;
color = axisName.color;
fontSize = axisName.fontSize;
fontStyle = axisName.fontStyle;
textStyle.Copy(axisName.textStyle);
}
}
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using System.Collections.Generic;
@@ -28,7 +28,7 @@ namespace XCharts
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// Color of split area. SplitArea color could also be set in color array,
@@ -49,10 +49,7 @@ namespace XCharts
return new AxisSplitArea()
{
m_Show = false,
m_Color = new List<Color32>(){
new Color32(250,250,250,77),
new Color32(200,200,200,77)
}
m_Color = new List<Color32>() { }
};
}
}
@@ -73,10 +70,18 @@ namespace XCharts
ChartHelper.CopyList(color, splitArea.color);
}
public Color32 getColor(int index)
public Color32 GetColor(int index, BaseAxisTheme theme)
{
var i = index % color.Count;
return color[i];
if (color.Count > 0)
{
var i = index % color.Count;
return color[i];
}
else
{
var i = index % theme.splitAreaColors.Count;
return theme.splitAreaColors[i];
}
}
}
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
@@ -15,33 +15,14 @@ namespace XCharts
/// 坐标轴在 grid 区域中的分隔线。
/// </summary>
[Serializable]
public class AxisSplitLine : SubComponent
public class AxisSplitLine : BaseLine
{
[SerializeField] private bool m_Show;
[SerializeField] private int m_Interval;
[SerializeField] private LineStyle m_LineStyle = new LineStyle(0.7f);
/// <summary>
/// Set this to true to show the split line.
/// 是否显示分隔线。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
public int interval
{
get { return m_Interval; }
set { if (PropertyUtility.SetStruct(ref m_Interval, value)) SetVerticesDirty(); }
}
/// <summary>
/// 线条样式
/// </summary>
public LineStyle lineStyle
{
get { return m_LineStyle; }
set { if (value != null) { m_LineStyle = value; SetVerticesDirty(); } }
set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetVerticesDirty(); }
}
public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } }
@@ -72,23 +53,8 @@ namespace XCharts
public void Copy(AxisSplitLine splitLine)
{
show = splitLine.show;
base.Copy(splitLine);
interval = splitLine.interval;
lineStyle.Copy(splitLine.lineStyle);
}
internal Color32 GetColor(ThemeInfo theme)
{
if (!ChartHelper.IsClearColor(lineStyle.color))
{
return lineStyle.GetColor();
}
else
{
var color = theme.axisSplitLineColor;
color.a = (byte)(color.a * lineStyle.opacity);
return color;
}
}
internal bool NeedShow(int index)

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
@@ -15,23 +15,11 @@ namespace XCharts
/// 坐标轴刻度相关设置。
/// </summary>
[System.Serializable]
public class AxisTick : SubComponent
public class AxisTick : BaseLine
{
[SerializeField] private bool m_Show;
[SerializeField] private bool m_AlignWithLabel;
[SerializeField] private bool m_Inside;
[SerializeField] private float m_Length;
[SerializeField] private float m_Width;
/// <summary>
/// Set this to false to prevent the axis tick from showing.
/// 是否显示坐标轴刻度。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// Align axis tick with label, which is available only when boundaryGap is set to be true in category axis.
/// 类目轴中在 boundaryGap 为 true 的时候有效,可以保证刻度线和标签对齐。
@@ -39,7 +27,7 @@ namespace XCharts
public bool alignWithLabel
{
get { return m_AlignWithLabel; }
set { if (PropertyUtility.SetStruct(ref m_AlignWithLabel, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_AlignWithLabel, value)) SetVerticesDirty(); }
}
/// <summary>
/// Set this to true so the axis labels face the inside direction.
@@ -48,25 +36,7 @@ namespace XCharts
public bool inside
{
get { return m_Inside; }
set { if (PropertyUtility.SetStruct(ref m_Inside, value)) SetVerticesDirty(); }
}
/// <summary>
/// The length of the axis tick.
/// 坐标轴刻度的长度。
/// </summary>
public float length
{
get { return m_Length; }
set { if (PropertyUtility.SetStruct(ref m_Length, value)) SetVerticesDirty(); }
}
/// <summary>
/// The width of the axis tick.Keep the same width with axis line when default 0.
/// 坐标轴刻度的宽度。默认为0时宽度和坐标轴一致。
/// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetVerticesDirty(); }
}
public static AxisTick defaultTick
@@ -78,8 +48,6 @@ namespace XCharts
m_Show = true,
m_AlignWithLabel = false,
m_Inside = false,
m_Width = 0f,
m_Length = 5f
};
return tick;
}
@@ -91,8 +59,7 @@ namespace XCharts
axisTick.show = show;
axisTick.alignWithLabel = alignWithLabel;
axisTick.inside = inside;
axisTick.length = length;
axisTick.width = width;
axisTick.lineStyle = lineStyle.Clone();
return axisTick;
}
@@ -101,8 +68,6 @@ namespace XCharts
show = axisTick.show;
alignWithLabel = axisTick.alignWithLabel;
inside = axisTick.inside;
length = axisTick.length;
width = axisTick.width;
}
}
}

View File

@@ -0,0 +1,89 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to base line.
/// 线条基础配置。
/// </summary>
[System.Serializable]
public class BaseLine : SubComponent
{
[SerializeField] protected bool m_Show;
[SerializeField] protected LineStyle m_LineStyle = new LineStyle();
/// <summary>
/// Set this to false to prevent the axis line from showing.
/// 是否显示坐标轴轴线。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// 线条样式
/// </summary>
public LineStyle lineStyle
{
get { return m_LineStyle; }
set { if (value != null) { m_LineStyle = value; SetVerticesDirty(); } }
}
public static BaseLine defaultBaseLine
{
get
{
var axisLine = new BaseLine
{
m_Show = true,
m_LineStyle = new LineStyle()
};
return axisLine;
}
}
public BaseLine()
{
lineStyle = new LineStyle();
}
public BaseLine(bool show) : base()
{
m_Show = show;
}
public void Copy(BaseLine axisLine)
{
show = axisLine.show;
lineStyle.Copy(axisLine.lineStyle);
}
public LineStyle.Type GetType(LineStyle.Type themeType)
{
return lineStyle.GetType(themeType);
}
public float GetWidth(float themeWidth)
{
return lineStyle.GetWidth(themeWidth);
}
public float GetLength(float themeLength)
{
return lineStyle.GetLength(themeLength);
}
public Color32 GetColor(Color32 themeColor)
{
return lineStyle.GetColor(themeColor);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4c431b00ccffe4db4b61179b6df06eb2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
@@ -41,7 +41,7 @@ namespace XCharts
public SerieLabel label
{
get { return m_Label; }
set { if (PropertyUtility.SetClass(ref m_Label, value, true)) SetAllDirty(); }
set { if (PropertyUtil.SetClass(ref m_Label, value, true)) SetAllDirty(); }
}
/// <summary>
/// 图形样式。
@@ -49,7 +49,7 @@ namespace XCharts
public ItemStyle itemStyle
{
get { return m_ItemStyle; }
set { if (PropertyUtility.SetClass(ref m_ItemStyle, value, true)) SetVerticesDirty(); }
set { if (PropertyUtil.SetClass(ref m_ItemStyle, value, true)) SetVerticesDirty(); }
}
public override bool vertsDirty { get { return m_VertsDirty || label.vertsDirty || itemStyle.vertsDirty; } }

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
@@ -17,135 +17,10 @@ namespace XCharts
[System.Serializable]
public class GaugeAxis : SubComponent
{
[System.Serializable]
public class AxisLine
{
[System.Serializable]
public class StageColor
{
[SerializeField] private float m_Percent;
[SerializeField] private Color32 m_Color;
/// <summary>
/// 结束位置百分比。
/// </summary>
public float percent { get { return m_Percent; } set { m_Percent = value; } }
/// <summary>
/// 颜色。
/// </summary>
public Color32 color { get { return m_Color; } set { m_Color = value; } }
public StageColor(float percent, Color32 color)
{
m_Percent = percent;
m_Color = color;
}
}
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Width = 15f;
[SerializeField] private float m_Opacity = 1f;
[SerializeField] private Color32 m_BarColor;
[SerializeField] private Color32 m_BarBackgroundColor = new Color32(200, 200, 200, 255);
[SerializeField]
private List<StageColor> m_StageColor = new List<StageColor>()
{
new StageColor(0.2f,new Color32(145,199,174,255)),
new StageColor(0.8f,new Color32(99,134,158,255)),
new StageColor(1.0f,new Color32(194,53,49,255)),
};
/// <summary>
/// Set this to false to prevent the axis line from showing.
/// 是否显示坐标轴轴线。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// line style line width.
/// 坐标轴线线宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// The opacity of axis line.
/// 透明度。
/// </summary>
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
/// <summary>
/// 进度条颜色。
/// </summary>
public Color32 barColor { get { return m_BarColor; } set { m_BarColor = value; } }
/// <summary>
/// 进度条背景颜色。
/// </summary>
public Color32 barBackgroundColor { get { return m_BarBackgroundColor; } set { m_BarBackgroundColor = value; } }
/// <summary>
/// 阶段颜色。
/// </summary>
public List<StageColor> stageColor { get { return m_StageColor; } set { m_StageColor = value; } }
}
/// <summary>
/// 分割线
/// </summary>
[System.Serializable]
public class SplitLine
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Length = 15;
[SerializeField]
private LineStyle m_LineStyle = new LineStyle()
{
width = 1.5f,
type = LineStyle.Type.Solid,
color = new Color32(238, 238, 238, 255)
};
/// <summary>
/// 是否显示分割线。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 分割线长度。
/// </summary>
public float length { get { return m_Length; } set { m_Length = value; } }
/// <summary>
/// 分割线样式。
/// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
}
/// <summary>
/// 刻度
/// </summary>
[System.Serializable]
public class AxisTick
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Length = 5;
[SerializeField] private float m_SplitNumber = 5;
[SerializeField]
private LineStyle m_LineStyle = new LineStyle()
{
width = 1f,
type = LineStyle.Type.Solid,
color = new Color32(238, 238, 238, 255)
};
/// <summary>
/// 是否显示刻度。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 刻度长度。当为0-1的浮点数时表示半径的百分比。
/// </summary>
public float length { get { return m_Length; } set { m_Length = value; } }
/// <summary>
/// 分割线之间的分割段数。
/// </summary>
public float splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
/// <summary>
/// 刻度线样式。
/// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
}
[SerializeField] private bool m_Show = true;
[SerializeField] private AxisLine m_AxisLine = new AxisLine();
[SerializeField] private SplitLine m_SplitLine = new SplitLine();
[SerializeField] private AxisTick m_AxisTick = new AxisTick();
[SerializeField] private GaugeAxisLine m_AxisLine = new GaugeAxisLine(true);
[SerializeField] private GaugeAxisSplitLine m_SplitLine = new GaugeAxisSplitLine(true);
[SerializeField] private GaugeAxisTick m_AxisTick = new GaugeAxisTick(true);
[SerializeField] private SerieLabel m_AxisLabel = new SerieLabel();
[SerializeField] private List<string> m_AxisLabelText = new List<string>();
@@ -154,17 +29,17 @@ namespace XCharts
/// axis line style.
/// 仪表盘轴线样式。
/// </summary>
public AxisLine axisLine { get { return m_AxisLine; } set { m_AxisLine = value; } }
public GaugeAxisLine axisLine { get { return m_AxisLine; } set { m_AxisLine = value; } }
/// <summary>
/// slit line style.
/// 分割线。
/// </summary>
public SplitLine splitLine { get { return m_SplitLine; } set { m_SplitLine = value; } }
public GaugeAxisSplitLine splitLine { get { return m_SplitLine; } set { m_SplitLine = value; } }
/// <summary>
/// axis tick style.
/// 刻度。
/// </summary>
public AxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } }
public GaugeAxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } }
/// <summary>
/// axis label style.
/// 文本标签。
@@ -181,23 +56,24 @@ namespace XCharts
public List<float> runtimeStageAngle = new List<float>();
public List<Vector3> runtimeLabelPosition = new List<Vector3>();
private List<LabelObject> m_RuntimeLabelList = new List<LabelObject>();
private List<ChartLabel> m_RuntimeLabelList = new List<ChartLabel>();
internal Color32 GetAxisLineColor(ThemeInfo theme, int index)
internal Color32 GetAxisLineColor(ChartTheme theme, int index)
{
var color = !ChartHelper.IsClearColor(axisLine.barColor) ? axisLine.barColor : theme.GetColor(index);
ChartHelper.SetColorOpacity(ref color, axisLine.opacity);
ChartHelper.SetColorOpacity(ref color, axisLine.lineStyle.opacity);
return color;
}
internal Color32 GetAxisLineBackgroundColor(ThemeInfo theme, int index)
internal Color32 GetAxisLineBackgroundColor(ChartTheme theme, int index)
{
var color = !ChartHelper.IsClearColor(axisLine.barBackgroundColor) ? axisLine.barBackgroundColor : ChartConst.greyColor32;
ChartHelper.SetColorOpacity(ref color, axisLine.opacity);
var color = !ChartHelper.IsClearColor(axisLine.barBackgroundColor)
? axisLine.barBackgroundColor : ChartConst.greyColor32;
ChartHelper.SetColorOpacity(ref color, axisLine.lineStyle.opacity);
return color;
}
internal Color32 GetSplitLineColor(ThemeInfo theme, int serieIndex, float angle)
internal Color32 GetSplitLineColor(Color32 themeColor, int serieIndex, float angle)
{
Color32 color;
if (!ChartHelper.IsClearColor(splitLine.lineStyle.color))
@@ -206,21 +82,12 @@ namespace XCharts
ChartHelper.SetColorOpacity(ref color, splitLine.lineStyle.opacity);
return color;
}
for (int i = 0; i < runtimeStageAngle.Count; i++)
{
if (angle < runtimeStageAngle[i])
{
color = axisLine.stageColor[i].color;
ChartHelper.SetColorOpacity(ref color, splitLine.lineStyle.opacity);
return color;
}
}
color = theme.GetColor(serieIndex);
color = themeColor;
ChartHelper.SetColorOpacity(ref color, splitLine.lineStyle.opacity);
return color;
}
internal Color32 GetAxisTickColor(ThemeInfo theme, int serieIndex, float angle)
internal Color32 GetAxisTickColor(Color32 themeColor, int serieIndex, float angle)
{
Color32 color;
if (!ChartHelper.IsClearColor(axisTick.lineStyle.color))
@@ -229,21 +96,12 @@ namespace XCharts
ChartHelper.SetColorOpacity(ref color, axisTick.lineStyle.opacity);
return color;
}
for (int i = 0; i < runtimeStageAngle.Count; i++)
{
if (angle < runtimeStageAngle[i])
{
color = axisLine.stageColor[i].color;
ChartHelper.SetColorOpacity(ref color, axisTick.lineStyle.opacity);
return color;
}
}
color = theme.GetColor(serieIndex);
color = themeColor;
ChartHelper.SetColorOpacity(ref color, axisTick.lineStyle.opacity);
return color;
}
internal Color32 GetPointerColor(ThemeInfo theme, int serieIndex, float angle, ItemStyle itemStyle)
internal Color32 GetPointerColor(ChartTheme theme, int serieIndex, float angle, ItemStyle itemStyle)
{
Color32 color;
if (!ChartHelper.IsClearColor(itemStyle.color))
@@ -269,12 +127,12 @@ namespace XCharts
m_RuntimeLabelList.Clear();
}
public void AddLabelObject(LabelObject label)
public void AddLabelObject(ChartLabel label)
{
m_RuntimeLabelList.Add(label);
}
public LabelObject GetLabelObject(int index)
public ChartLabel GetLabelObject(int index)
{
if (index >= 0 && index < m_RuntimeLabelList.Count)
{

View File

@@ -0,0 +1,63 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
[System.Serializable]
public class StageColor
{
[SerializeField] private float m_Percent;
[SerializeField] private Color32 m_Color;
/// <summary>
/// 结束位置百分比。
/// </summary>
public float percent { get { return m_Percent; } set { m_Percent = value; } }
/// <summary>
/// 颜色。
/// </summary>
public Color32 color { get { return m_Color; } set { m_Color = value; } }
public StageColor(float percent, Color32 color)
{
m_Percent = percent;
m_Color = color;
}
}
[System.Serializable]
public class GaugeAxisLine : BaseLine
{
[SerializeField] private Color32 m_BarColor;
[SerializeField] private Color32 m_BarBackgroundColor = new Color32(200, 200, 200, 255);
[SerializeField]
private List<StageColor> m_StageColor = new List<StageColor>()
{
new StageColor(0.2f,new Color32(145,199,174,255)),
new StageColor(0.8f,new Color32(99,134,158,255)),
new StageColor(1.0f,new Color32(194,53,49,255)),
};
/// <summary>
/// 进度条颜色。
/// </summary>
public Color32 barColor { get { return m_BarColor; } set { m_BarColor = value; } }
/// <summary>
/// 进度条背景颜色。
/// </summary>
public Color32 barBackgroundColor { get { return m_BarBackgroundColor; } set { m_BarBackgroundColor = value; } }
/// <summary>
/// 阶段颜色。
/// </summary>
public List<StageColor> stageColor { get { return m_StageColor; } set { m_StageColor = value; } }
public GaugeAxisLine(bool show) : base(show)
{
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c35880091e5a4382876c47bd843a99f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
namespace XCharts
{
/// <summary>
/// 分割线
/// </summary>
[System.Serializable]
public class GaugeAxisSplitLine : BaseLine
{
public GaugeAxisSplitLine(bool show) : base(show)
{
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 27a5f68720fa741ddbd50217b585a9e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
namespace XCharts
{
/// <summary>
/// 刻度
/// </summary>
[System.Serializable]
public class GaugeAxisTick : BaseLine
{
[SerializeField] private float m_SplitNumber = 5;
/// <summary>
/// 分割线之间的分割段数。
/// </summary>
public float splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
public GaugeAxisTick(bool show) : base(show)
{
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2e9ace80811494ca5aad05b59c61a74f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
@@ -29,7 +29,7 @@ namespace XCharts
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// Pointer length. It can be an absolute value, or it can be a percentage relative to the radius (0-1).
@@ -38,7 +38,7 @@ namespace XCharts
public float length
{
get { return m_Length; }
set { if (PropertyUtility.SetStruct(ref m_Length, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Length, value)) SetVerticesDirty(); }
}
/// <summary>
/// Pointer width.
@@ -47,7 +47,7 @@ namespace XCharts
public float width
{
get { return m_Width; }
set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
}
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using System.Collections.Generic;
@@ -84,7 +84,7 @@ namespace XCharts
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项颜色。
@@ -92,7 +92,7 @@ namespace XCharts
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color1.
@@ -101,7 +101,7 @@ namespace XCharts
public Color32 toColor
{
get { return m_ToColor; }
set { if (PropertyUtility.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color2.Only valid in line diagrams.
@@ -110,7 +110,7 @@ namespace XCharts
public Color32 toColor2
{
get { return m_ToColor2; }
set { if (PropertyUtility.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项背景颜色。
@@ -118,7 +118,7 @@ namespace XCharts
public Color32 backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 中心区域颜色。
@@ -126,7 +126,7 @@ namespace XCharts
public Color32 centerColor
{
get { return m_CenterColor; }
set { if (PropertyUtility.SetColor(ref m_CenterColor, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_CenterColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 中心区域间隙。
@@ -134,7 +134,7 @@ namespace XCharts
public float centerGap
{
get { return m_CenterGap; }
set { if (PropertyUtility.SetStruct(ref m_CenterGap, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_CenterGap, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项背景宽度。
@@ -142,7 +142,7 @@ namespace XCharts
public float backgroundWidth
{
get { return m_BackgroundWidth; }
set { if (PropertyUtility.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的类型。
@@ -150,7 +150,7 @@ namespace XCharts
public Type borderType
{
get { return m_BorderType; }
set { if (PropertyUtility.SetStruct(ref m_BorderType, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_BorderType, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的颜色。
@@ -158,7 +158,7 @@ namespace XCharts
public Color32 borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtility.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框宽。
@@ -166,7 +166,7 @@ namespace XCharts
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtility.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// 透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
@@ -174,7 +174,7 @@ namespace XCharts
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
/// <summary>
/// 提示框单项的字符串模版格式器。具体配置参考`Tooltip`的`formatter`
@@ -182,7 +182,7 @@ namespace XCharts
public string tooltipFormatter
{
get { return m_TooltipFormatter; }
set { if (PropertyUtility.SetClass(ref m_TooltipFormatter, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetClass(ref m_TooltipFormatter, value)) SetVerticesDirty(); }
}
/// <summary>
/// Standard numeric format strings.
@@ -194,7 +194,7 @@ namespace XCharts
public string numericFormatter
{
get { return m_NumericFormatter; }
set { if (PropertyUtility.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
}
/// <summary>
/// The radius of rounded corner. Its unit is px. Use array to respectively specify the 4 corner radiuses((clockwise upper left, upper right, bottom right and bottom left)).
@@ -203,7 +203,7 @@ namespace XCharts
public float[] cornerRadius
{
get { return m_CornerRadius; }
set { if (PropertyUtility.SetClass(ref m_CornerRadius, value, true)) SetVerticesDirty(); }
set { if (PropertyUtil.SetClass(ref m_CornerRadius, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// 实际边框宽。边框不显示时为0。

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
@@ -28,10 +28,14 @@ namespace XCharts
}
[SerializeField] private bool m_Show;
[SerializeField] Position m_Position;
[SerializeField] private float m_Width = 10;
[SerializeField] private float m_Height = 15;
[SerializeField] private float m_Offset = 0;
[SerializeField] private float m_Dent = 3;
[SerializeField]
private Arrow m_Arrow = new Arrow()
{
width = 10,
height = 15,
offset = 0,
dent = 3
};
/// <summary>
/// Whether to show the arrow.
@@ -40,7 +44,7 @@ namespace XCharts
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// The position of arrow.
@@ -49,43 +53,17 @@ namespace XCharts
public Position position
{
get { return m_Position; }
set { if (PropertyUtility.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
}
/// <summary>
/// The widht of arrow.
/// 箭头
/// the arrow of line.
/// 箭头。
/// </summary>
public float width
public Arrow arrow
{
get { return m_Width; }
set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
/// <summary>
/// The height of arrow.
/// 箭头高。
/// </summary>
public float height
{
get { return m_Height; }
set { if (PropertyUtility.SetStruct(ref m_Height, value)) SetVerticesDirty(); }
}
/// <summary>
/// The offset of arrow.
/// 箭头偏移。
/// </summary>
public float offset
{
get { return m_Offset; }
set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
}
/// <summary>
/// The dent of arrow.
/// 箭头的凹度。
/// </summary>
public float dent
{
get { return m_Dent; }
set { if (PropertyUtility.SetStruct(ref m_Dent, value)) SetVerticesDirty(); }
get { return m_Arrow; }
set { if (PropertyUtil.SetClass(ref m_Arrow, value)) SetVerticesDirty(); }
}
}
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
@@ -44,13 +44,15 @@ namespace XCharts
/// 双点划线
/// </summary>
DashDotDot,
None,
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Type m_Type = Type.Solid;
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_ToColor;
[SerializeField] private Color32 m_ToColor2;
[SerializeField] private float m_Width = 0.8f;
[SerializeField] private float m_Width = 0;
[SerializeField] private float m_Length = 0;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
/// <summary>
@@ -60,7 +62,7 @@ namespace XCharts
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// the type of line.
@@ -69,7 +71,7 @@ namespace XCharts
public Type type
{
get { return m_Type; }
set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of line, default use serie color.
@@ -78,7 +80,7 @@ namespace XCharts
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// the middle color of line, default use serie color.
@@ -87,7 +89,7 @@ namespace XCharts
public Color32 toColor
{
get { return m_ToColor; }
set { if (PropertyUtility.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the end color of line, default use serie color.
@@ -96,7 +98,7 @@ namespace XCharts
public Color32 toColor2
{
get { return m_ToColor2; }
set { if (PropertyUtility.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of line.
@@ -105,7 +107,16 @@ namespace XCharts
public float width
{
get { return m_Width; }
set { if (PropertyUtility.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
/// <summary>
/// the length of line.
/// 线长。
/// /// </summary>
public float length
{
get { return m_Length; }
set { if (PropertyUtil.SetStruct(ref m_Length, value)) SetVerticesDirty(); }
}
/// <summary>
/// Opacity of the line. Supports value from 0 to 1, and the line will not be drawn when set to 0.
@@ -114,7 +125,7 @@ namespace XCharts
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtility.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
public LineStyle()
@@ -126,6 +137,11 @@ namespace XCharts
this.width = width;
}
public LineStyle(LineStyle.Type type)
{
this.type = type;
}
public LineStyle(LineStyle.Type type, float width)
{
this.type = type;
@@ -190,5 +206,34 @@ namespace XCharts
}
return color;
}
public Type GetType(Type themeType)
{
return type == Type.None ? themeType : type;
}
public float GetWidth(float themeWidth)
{
return width == 0 ? themeWidth : width;
}
public float GetLength(float themeLength)
{
return length == 0 ? themeLength : length;
}
public Color32 GetColor(Color32 themeColor)
{
if (!ChartHelper.IsClearColor(color))
{
return GetColor();
}
else
{
var color = themeColor;
color.a = (byte)(color.a * opacity);
return color;
}
}
}
}

View File

@@ -1,12 +1,15 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
@@ -39,7 +42,10 @@ namespace XCharts
[SerializeField] private float m_Top;
[SerializeField] private float m_Bottom;
private TextAnchor m_TextAnchor;
private TextAnchor m_TextAlignment;
#if dUI_TextMeshPro
private TextAlignmentOptions m_TMPTextAlignment;
#endif
private Vector2 m_AnchorMin;
private Vector2 m_AnchorMax;
private Vector2 m_Pivot;
@@ -50,7 +56,7 @@ namespace XCharts
public Align align
{
get { return m_Align; }
set { if (PropertyUtility.SetStruct(ref m_Align, value)) { SetComponentDirty(); UpdateAlign(); } }
set { if (PropertyUtil.SetStruct(ref m_Align, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
@@ -59,7 +65,7 @@ namespace XCharts
public float left
{
get { return m_Left; }
set { if (PropertyUtility.SetStruct(ref m_Left, value)) { SetComponentDirty(); UpdateAlign(); } }
set { if (PropertyUtil.SetStruct(ref m_Left, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
@@ -68,7 +74,7 @@ namespace XCharts
public float right
{
get { return m_Right; }
set { if (PropertyUtility.SetStruct(ref m_Right, value)) { SetComponentDirty(); UpdateAlign(); } }
set { if (PropertyUtil.SetStruct(ref m_Right, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
@@ -77,7 +83,7 @@ namespace XCharts
public float top
{
get { return m_Top; }
set { if (PropertyUtility.SetStruct(ref m_Top, value)) { SetComponentDirty(); UpdateAlign(); } }
set { if (PropertyUtil.SetStruct(ref m_Top, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
@@ -86,7 +92,7 @@ namespace XCharts
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtility.SetStruct(ref m_Bottom, value)) { SetComponentDirty(); UpdateAlign(); } }
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
@@ -94,7 +100,11 @@ namespace XCharts
/// Location对应的Anchor锚点
/// </summary>
/// <value></value>
public TextAnchor runtimeTextAnchor { get { return m_TextAnchor; } }
public TextAnchor runtimeTextAlignment { get { return m_TextAlignment; } }
#if dUI_TextMeshPro
public TextAlignmentOptions runtimeTMPTextAlignment { get { return m_TMPTextAlignment; } }
#endif
/// <summary>
/// the minimum achor.
/// Location对应的anchorMin。
@@ -179,55 +189,82 @@ namespace XCharts
switch (m_Align)
{
case Align.BottomCenter:
m_TextAnchor = TextAnchor.LowerCenter;
m_TextAlignment = TextAnchor.LowerCenter;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Bottom;
#endif
m_AnchorMin = new Vector2(0.5f, 0);
m_AnchorMax = new Vector2(0.5f, 0);
m_Pivot = new Vector2(0.5f, 0);
break;
case Align.BottomLeft:
m_TextAnchor = TextAnchor.LowerLeft;
m_TextAlignment = TextAnchor.LowerLeft;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.BottomLeft;
#endif
m_AnchorMin = new Vector2(0, 0);
m_AnchorMax = new Vector2(0, 0);
m_Pivot = new Vector2(0, 0);
break;
case Align.BottomRight:
m_TextAnchor = TextAnchor.LowerRight;
m_TextAlignment = TextAnchor.LowerRight;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.BottomRight;
#endif
m_AnchorMin = new Vector2(1, 0);
m_AnchorMax = new Vector2(1, 0);
m_Pivot = new Vector2(1, 0);
break;
case Align.Center:
m_TextAnchor = TextAnchor.MiddleCenter;
m_TextAlignment = TextAnchor.MiddleCenter;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Center;
#endif
m_AnchorMin = new Vector2(0.5f, 0.5f);
m_AnchorMax = new Vector2(0.5f, 0.5f);
m_Pivot = new Vector2(0.5f, 0.5f);
break;
case Align.CenterLeft:
m_TextAnchor = TextAnchor.MiddleLeft;
m_TextAlignment = TextAnchor.MiddleLeft;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Left;
#endif
m_AnchorMin = new Vector2(0, 0.5f);
m_AnchorMax = new Vector2(0, 0.5f);
m_Pivot = new Vector2(0, 0.5f);
break;
case Align.CenterRight:
m_TextAnchor = TextAnchor.MiddleRight;
m_TextAlignment = TextAnchor.MiddleRight;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Right;
#endif
m_AnchorMin = new Vector2(1, 0.5f);
m_AnchorMax = new Vector2(1, 0.5f);
m_Pivot = new Vector2(1, 0.5f);
break;
case Align.TopCenter:
m_TextAnchor = TextAnchor.UpperCenter;
m_TextAlignment = TextAnchor.UpperCenter;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Top;
#endif
m_AnchorMin = new Vector2(0.5f, 1);
m_AnchorMax = new Vector2(0.5f, 1);
m_Pivot = new Vector2(0.5f, 1);
break;
case Align.TopLeft:
m_TextAnchor = TextAnchor.UpperLeft;
m_TextAlignment = TextAnchor.UpperLeft;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.TopLeft;
#endif
m_AnchorMin = new Vector2(0, 1);
m_AnchorMax = new Vector2(0, 1);
m_Pivot = new Vector2(0, 1);
break;
case Align.TopRight:
m_TextAnchor = TextAnchor.UpperRight;
m_TextAlignment = TextAnchor.UpperRight;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.TopRight;
#endif
m_AnchorMin = new Vector2(1, 1);
m_AnchorMax = new Vector2(1, 1);
m_Pivot = new Vector2(1, 1);

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Linq;
using System.Collections.Generic;
@@ -34,7 +34,7 @@ namespace XCharts
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
[SerializeField] private List<float> m_Data = new List<float>();
public LabelObject labelObject { get; set; }
public ChartLabel labelObject { get; set; }
private bool m_Show = true;
private float m_RtPieOutsideRadius;
@@ -169,6 +169,7 @@ namespace XCharts
public Vector3 runtimePosition { get; internal set; }
public float runtimeAngle { get; internal set; }
public Vector3 runtiemPieOffsetCenter { get; internal set; }
public float runtimeStackHig { get; internal set; }
private List<float> m_PreviousData = new List<float>();
private List<float> m_DataUpdateTime = new List<float>();
private List<bool> m_DataUpdateFlag = new List<bool>();

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
@@ -83,15 +83,10 @@ namespace XCharts
[SerializeField] private Vector3 m_Offset;
[SerializeField] private float m_Margin;
[SerializeField] private string m_Formatter;
[SerializeField] private float m_Rotate = 0;
[SerializeField] private float m_PaddingLeftRight = 2f;
[SerializeField] private float m_PaddingTopBottom = 2f;
[SerializeField] private Color m_Color;
[SerializeField] private Color32 m_BackgroundColor;
[SerializeField] private float m_BackgroundWidth = 0;
[SerializeField] private float m_BackgroundHeight = 0;
[SerializeField] private int m_FontSize = 18;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private bool m_Line = true;
[SerializeField] private LineType m_LineType = LineType.BrokenLine;
[SerializeField] private Color32 m_LineColor = ChartConst.clearColor32;
@@ -103,6 +98,7 @@ namespace XCharts
[SerializeField] private Color32 m_BorderColor = ChartConst.greyColor32;
[SerializeField] private string m_NumericFormatter = "";
[SerializeField] private bool m_AutoOffset = false;
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
public void Reset()
{
@@ -112,12 +108,8 @@ namespace XCharts
m_Margin = 0;
m_PaddingLeftRight = 2f;
m_PaddingTopBottom = 2f;
m_Color = Color.clear;
m_BackgroundColor = Color.clear;
m_BackgroundWidth = 0;
m_BackgroundHeight = 0;
m_FontSize = 18;
m_FontStyle = FontStyle.Normal;
m_Line = true;
m_LineType = LineType.BrokenLine;
m_LineColor = Color.clear;
@@ -138,7 +130,7 @@ namespace XCharts
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetAllDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
}
/// <summary>
/// The position of label.
@@ -147,7 +139,7 @@ namespace XCharts
public Position position
{
get { return m_Position; }
set { if (PropertyUtility.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
}
/// <summary>
/// 标签内容字符串模版格式器。支持用 \n 换行。
@@ -165,7 +157,7 @@ namespace XCharts
public string formatter
{
get { return m_Formatter; }
set { if (PropertyUtility.SetClass(ref m_Formatter, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetVerticesDirty(); }
}
/// <summary>
/// offset to the host graphic element.
@@ -174,7 +166,7 @@ namespace XCharts
public Vector3 offset
{
get { return m_Offset; }
set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
}
/// <summary>
/// 距离轴线的距离。
@@ -182,25 +174,7 @@ namespace XCharts
public float margin
{
get { return m_Margin; }
set { if (PropertyUtility.SetStruct(ref m_Margin, value)) SetVerticesDirty(); }
}
/// <summary>
/// Text color,If set as default ,the color will assigned as series color.
/// 自定义文字颜色,默认和系列的颜色一致。
/// </summary>
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetStruct(ref m_Color, value)) SetComponentDirty(); }
}
/// <summary>
/// the background color. If set as default, it means than don't show background.
/// 标签的背景色,默认无颜色。
/// </summary>
public Color32 backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtility.SetStruct(ref m_BackgroundColor, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Margin, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of background. If set as default value 0, it means than the background width auto set as the text width.
@@ -210,7 +184,7 @@ namespace XCharts
public float backgroundWidth
{
get { return m_BackgroundWidth; }
set { if (PropertyUtility.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// the height of background. If set as default value 0, it means than the background height auto set as the text height.
@@ -220,16 +194,7 @@ namespace XCharts
public float backgroundHeight
{
get { return m_BackgroundHeight; }
set { if (PropertyUtility.SetStruct(ref m_BackgroundHeight, value)) SetComponentDirty(); }
}
/// <summary>
/// Rotate label.
/// 标签旋转。
/// </summary>
public float rotate
{
get { return m_Rotate; }
set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_BackgroundHeight, value)) SetComponentDirty(); }
}
/// <summary>
/// the text padding of left and right. defaut:2.
@@ -238,7 +203,7 @@ namespace XCharts
public float paddingLeftRight
{
get { return m_PaddingLeftRight; }
set { if (PropertyUtility.SetStruct(ref m_PaddingLeftRight, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_PaddingLeftRight, value)) SetComponentDirty(); }
}
/// <summary>
/// the text padding of top and bottom. defaut:2.
@@ -247,25 +212,7 @@ namespace XCharts
public float paddingTopBottom
{
get { return m_PaddingTopBottom; }
set { if (PropertyUtility.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); }
}
/// <summary>
/// font size.
/// 文字的字体大小。
/// </summary>
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetAllDirty(); }
}
/// <summary>
/// font style.
/// 文字的字体风格。
/// </summary>
public FontStyle fontStyle
{
get { return m_FontStyle; }
set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetAllDirty(); }
set { if (PropertyUtil.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); }
}
/// <summary>
/// Whether to show visual guide line.Will show when label position is set as 'outside'.
@@ -274,7 +221,7 @@ namespace XCharts
public bool line
{
get { return m_Line; }
set { if (PropertyUtility.SetStruct(ref m_Line, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Line, value)) SetComponentDirty(); }
}
/// <summary>
/// the type of visual guide line.
@@ -283,7 +230,7 @@ namespace XCharts
public LineType lineType
{
get { return m_LineType; }
set { if (PropertyUtility.SetStruct(ref m_LineType, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_LineType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of visual guild line.
@@ -292,7 +239,7 @@ namespace XCharts
public Color32 lineColor
{
get { return m_LineColor; }
set { if (PropertyUtility.SetStruct(ref m_LineColor, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_LineColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of visual guild line.
@@ -301,7 +248,7 @@ namespace XCharts
public float lineWidth
{
get { return m_LineWidth; }
set { if (PropertyUtility.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// The length of the first segment of visual guide line.
@@ -310,7 +257,7 @@ namespace XCharts
public float lineLength1
{
get { return m_LineLength1; }
set { if (PropertyUtility.SetStruct(ref m_LineLength1, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_LineLength1, value)) SetVerticesDirty(); }
}
/// <summary>
/// The length of the second segment of visual guide line.
@@ -319,7 +266,7 @@ namespace XCharts
public float lineLength2
{
get { return m_LineLength2; }
set { if (PropertyUtility.SetStruct(ref m_LineLength2, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_LineLength2, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show border.
@@ -328,7 +275,7 @@ namespace XCharts
public bool border
{
get { return m_Border; }
set { if (PropertyUtility.SetStruct(ref m_Border, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Border, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of border.
@@ -337,7 +284,7 @@ namespace XCharts
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtility.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of border.
@@ -346,7 +293,7 @@ namespace XCharts
public Color32 borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtility.SetStruct(ref m_BorderColor, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_BorderColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Standard numeric format strings.
@@ -358,7 +305,7 @@ namespace XCharts
public string numericFormatter
{
get { return m_NumericFormatter; }
set { if (PropertyUtility.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
}
/// <summary>
/// 是否开启自动偏移。当开启时Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。
@@ -366,7 +313,17 @@ namespace XCharts
public bool autoOffset
{
get { return m_AutoOffset; }
set { if (PropertyUtility.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); }
set { if (PropertyUtil.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); }
}
/// <summary>
/// the sytle of text.
/// 文本样式。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetAllDirty(); }
}
}
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
@@ -81,8 +81,8 @@ namespace XCharts
[SerializeField] private bool m_Show = true;
[SerializeField] private SerieSymbolType m_Type = SerieSymbolType.EmptyCircle;
[SerializeField] private SerieSymbolSizeType m_SizeType = SerieSymbolSizeType.Custom;
[SerializeField] private float m_Size = 6f;
[SerializeField] private float m_SelectedSize = 10f;
[SerializeField] private float m_Size = 0f;
[SerializeField] private float m_SelectedSize = 0f;
[SerializeField] private int m_DataIndex = 1;
[SerializeField] private float m_DataScale = 1;
[SerializeField] private float m_SelectedDataScale = 1.5f;
@@ -98,8 +98,8 @@ namespace XCharts
m_Show = false;
m_Type = SerieSymbolType.EmptyCircle;
m_SizeType = SerieSymbolSizeType.Custom;
m_Size = 6f;
m_SelectedDataScale = 10f;
m_Size = 0f;
m_SelectedSize = 0f;
m_DataIndex = 1;
m_DataScale = 1;
m_SelectedDataScale = 1.5f;
@@ -118,7 +118,7 @@ namespace XCharts
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetAllDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
}
/// <summary>
/// the type of symbol.
@@ -127,7 +127,7 @@ namespace XCharts
public SerieSymbolType type
{
get { return m_Type; }
set { if (PropertyUtility.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
}
/// <summary>
/// the type of symbol size.
@@ -136,7 +136,7 @@ namespace XCharts
public SerieSymbolSizeType sizeType
{
get { return m_SizeType; }
set { if (PropertyUtility.SetStruct(ref m_SizeType, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_SizeType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the size of symbol.
@@ -145,7 +145,7 @@ namespace XCharts
public float size
{
get { return m_Size; }
set { if (PropertyUtility.SetStruct(ref m_Size, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Size, value)) SetVerticesDirty(); }
}
/// <summary>
/// the size of selected symbol.
@@ -154,7 +154,7 @@ namespace XCharts
public float selectedSize
{
get { return m_SelectedSize; }
set { if (PropertyUtility.SetStruct(ref m_SelectedSize, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_SelectedSize, value)) SetVerticesDirty(); }
}
/// <summary>
/// whitch data index is when the sizeType assined as FromData.
@@ -163,7 +163,7 @@ namespace XCharts
public int dataIndex
{
get { return m_DataIndex; }
set { if (PropertyUtility.SetStruct(ref m_DataIndex, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_DataIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// the scale of data when sizeType assined as FromData.
@@ -172,7 +172,7 @@ namespace XCharts
public float dataScale
{
get { return m_DataScale; }
set { if (PropertyUtility.SetStruct(ref m_DataScale, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_DataScale, value)) SetVerticesDirty(); }
}
/// <summary>
/// the scale of selected data when sizeType assined as FromData.
@@ -181,7 +181,7 @@ namespace XCharts
public float selectedDataScale
{
get { return m_SelectedDataScale; }
set { if (PropertyUtility.SetStruct(ref m_SelectedDataScale, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_SelectedDataScale, value)) SetVerticesDirty(); }
}
/// <summary>
/// the callback of size when sizeType assined as Callback.
@@ -190,7 +190,7 @@ namespace XCharts
public SymbolSizeCallback sizeCallback
{
get { return m_SizeCallback; }
set { if (PropertyUtility.SetClass(ref m_SizeCallback, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetClass(ref m_SizeCallback, value)) SetVerticesDirty(); }
}
/// <summary>
/// the callback of size when sizeType assined as Callback.
@@ -199,7 +199,7 @@ namespace XCharts
public SymbolSizeCallback selectedSizeCallback
{
get { return m_SelectedSizeCallback; }
set { if (PropertyUtility.SetClass(ref m_SelectedSizeCallback, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetClass(ref m_SelectedSizeCallback, value)) SetVerticesDirty(); }
}
/// <summary>
/// the index start to show symbol.
@@ -208,7 +208,7 @@ namespace XCharts
public int startIndex
{
get { return m_StartIndex; }
set { if (PropertyUtility.SetStruct(ref m_StartIndex, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_StartIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// the interval of show symbol.
@@ -217,7 +217,7 @@ namespace XCharts
public int interval
{
get { return m_Interval; }
set { if (PropertyUtility.SetStruct(ref m_Interval, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetVerticesDirty(); }
}
/// <summary>
/// whether to show the last symbol.
@@ -226,7 +226,7 @@ namespace XCharts
public bool forceShowLast
{
get { return m_ForceShowLast; }
set { if (PropertyUtility.SetStruct(ref m_ForceShowLast, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_ForceShowLast, value)) SetVerticesDirty(); }
}
/// <summary>
/// the gap of symbol and line segment.
@@ -235,7 +235,7 @@ namespace XCharts
public float gap
{
get { return m_Gap; }
set { if (PropertyUtility.SetStruct(ref m_Gap, value)) SetVerticesDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetVerticesDirty(); }
}
private List<float> m_AnimationSize = new List<float>() { 0, 5, 10 };
/// <summary>
@@ -249,26 +249,25 @@ namespace XCharts
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public float GetSize(List<float> data)
public float GetSize(List<float> data, float themeSize)
{
if (data == null) return size;
switch (m_SizeType)
{
case SerieSymbolSizeType.Custom:
return size;
return size == 0 ? themeSize : size;
case SerieSymbolSizeType.FromData:
if (dataIndex >= 0 && dataIndex < data.Count)
if (data != null && dataIndex >= 0 && dataIndex < data.Count)
{
return data[dataIndex] * m_DataScale;
}
else
{
return size;
return size == 0 ? themeSize : size;
}
case SerieSymbolSizeType.Callback:
if (sizeCallback != null) return sizeCallback(data);
else return size;
default: return size;
if (data != null && sizeCallback != null) return sizeCallback(data);
else return size == 0 ? themeSize : size;
default: return size == 0 ? themeSize : size;
}
}
@@ -277,26 +276,25 @@ namespace XCharts
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public float GetSelectedSize(List<float> data)
public float GetSelectedSize(List<float> data, float themeSelectedSize)
{
if (data == null) return selectedSize;
switch (m_SizeType)
{
case SerieSymbolSizeType.Custom:
return selectedSize;
return selectedSize == 0 ? themeSelectedSize : selectedSize;
case SerieSymbolSizeType.FromData:
if (dataIndex >= 0 && dataIndex < data.Count)
if (data != null && dataIndex >= 0 && dataIndex < data.Count)
{
return data[dataIndex] * m_SelectedDataScale;
}
else
{
return selectedSize;
return selectedSize == 0 ? themeSelectedSize : selectedSize;
}
case SerieSymbolSizeType.Callback:
if (selectedSizeCallback != null) return selectedSizeCallback(data);
else return selectedSize;
default: return selectedSize;
if (data != null && selectedSizeCallback != null) return selectedSizeCallback(data);
else return selectedSize == 0 ? themeSelectedSize : selectedSize;
default: return selectedSize == 0 ? themeSelectedSize : selectedSize;
}
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
@@ -33,7 +33,7 @@ namespace XCharts
public bool enable
{
get { return m_Enable; }
set { if (PropertyUtility.SetStruct(ref m_Enable, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Enable, value)) SetComponentDirty(); }
}
/// <summary>
/// Set the maximum width. A default of 0 indicates automatic fetch; otherwise, custom.
@@ -43,7 +43,7 @@ namespace XCharts
public float maxWidth
{
get { return m_MaxWidth; }
set { if (PropertyUtility.SetStruct(ref m_MaxWidth, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_MaxWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// White pixel distance at both ends.
@@ -53,7 +53,7 @@ namespace XCharts
public float gap
{
get { return m_Gap; }
set { if (PropertyUtility.SetStruct(ref m_Gap, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetComponentDirty(); }
}
/// <summary>
/// Suffixes when the length exceeds.
@@ -63,11 +63,10 @@ namespace XCharts
public string suffix
{
get { return m_Suffix; }
set { if (PropertyUtility.SetClass(ref m_Suffix, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetClass(ref m_Suffix, value)) SetComponentDirty(); }
}
private Text m_RelatedText;
private TextGenerationSettings m_RelatedTextSettings;
private ChartText m_RelatedText;
private float m_RelatedTextWidth = 0;
public TextLimit Clone()
@@ -88,10 +87,9 @@ namespace XCharts
suffix = textLimit.suffix;
}
public void SetRelatedText(Text txt, float labelWidth)
public void SetRelatedText(ChartText txt, float labelWidth)
{
m_RelatedText = txt;
m_RelatedTextSettings = txt.GetGenerationSettings(Vector2.zero);
m_RelatedTextWidth = labelWidth;
}
@@ -104,8 +102,8 @@ namespace XCharts
{
if (m_Enable)
{
float len = m_RelatedText.cachedTextGenerator.GetPreferredWidth(content, m_RelatedTextSettings);
float suffixLen = m_RelatedText.cachedTextGenerator.GetPreferredWidth(suffix, m_RelatedTextSettings);
float len = m_RelatedText.GetPreferredWidth(content);
float suffixLen = m_RelatedText.GetPreferredWidth(suffix);
if (len >= checkWidth - m_Gap * 2)
{
return content.Substring(0, GetAdaptLength(content, suffixLen)) + suffix;
@@ -133,7 +131,7 @@ namespace XCharts
float len = 0;
while (len != limit && middle != start)
{
len = m_RelatedText.cachedTextGenerator.GetPreferredWidth(content.Substring(0, middle), m_RelatedTextSettings);
len = m_RelatedText.GetPreferredWidth(content.Substring(0, middle));
if (len < limit)
{
start = middle;

View File

@@ -1,12 +1,15 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
@@ -18,18 +21,20 @@ namespace XCharts
public class TextStyle : SubComponent
{
[SerializeField] private Font m_Font;
[SerializeField] private float m_Rotate = 0;
[SerializeField] private Vector2 m_Offset = Vector2.zero;
[SerializeField] private Color m_Color = Color.clear;
[SerializeField] private Color m_BackgroundColor = Color.clear;
[SerializeField] private int m_FontSize = 18;
[SerializeField] private int m_FontSize = 0;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private float m_LineSpacing = 1f;
// [SerializeField] private float m_PaddingLeft = 0f;
// [SerializeField] private float m_PaddingRight = 0f;
// [SerializeField] private float m_PaddingTop = 0f;
// [SerializeField] private float m_PaddingBottom = 0f;
[SerializeField] private TextAnchor m_Alignment = TextAnchor.MiddleCenter;
#if dUI_TextMeshPro
[SerializeField] private TMP_FontAsset m_TMPFont;
[SerializeField] private FontStyles m_TMPFontStyle = FontStyles.Normal;
[SerializeField] private TextAlignmentOptions m_TMPAlignment = TextAlignmentOptions.Left;
#endif
/// <summary>
/// Rotation of text.
/// 文本的旋转。
@@ -38,7 +43,7 @@ namespace XCharts
public float rotate
{
get { return m_Rotate; }
set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
}
/// <summary>
/// the offset of position.
@@ -48,7 +53,7 @@ namespace XCharts
public Vector2 offset
{
get { return m_Offset; }
set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetComponentDirty(); }
}
public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
@@ -61,7 +66,7 @@ namespace XCharts
public Color color
{
get { return m_Color; }
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of text.
@@ -71,7 +76,7 @@ namespace XCharts
public Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the font of text. When `null`, the theme's font is used by default.
@@ -81,7 +86,7 @@ namespace XCharts
public Font font
{
get { return m_Font; }
set { if (PropertyUtility.SetClass(ref m_Font, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetClass(ref m_Font, value)) SetComponentDirty(); }
}
/// <summary>
/// font size.
@@ -91,7 +96,7 @@ namespace XCharts
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
}
/// <summary>
/// font style.
@@ -101,7 +106,7 @@ namespace XCharts
public FontStyle fontStyle
{
get { return m_FontStyle; }
set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// text line spacing.
@@ -111,8 +116,34 @@ namespace XCharts
public float lineSpacing
{
get { return m_LineSpacing; }
set { if (PropertyUtility.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); }
}
/// <summary>
/// 对齐方式。
/// </summary>
public TextAnchor alignment
{
get { return m_Alignment; }
set { if (PropertyUtil.SetStruct(ref m_Alignment, value)) SetComponentDirty(); }
}
#if dUI_TextMeshPro
public TMP_FontAsset tmpFont
{
get { return m_TMPFont; }
set { if (PropertyUtil.SetClass(ref m_TMPFont, value)) SetComponentDirty(); }
}
public FontStyles tmpFontStyle
{
get { return m_TMPFontStyle; }
set { if (PropertyUtil.SetStruct(ref m_TMPFontStyle, value)) SetComponentDirty(); }
}
public TextAlignmentOptions tmpAlignment
{
get { return m_TMPAlignment; }
set { if (PropertyUtil.SetStruct(ref m_TMPAlignment, value)) SetComponentDirty(); }
}
#endif
public TextStyle()
{
@@ -143,5 +174,44 @@ namespace XCharts
this.color = color;
this.rotate = rotate;
}
public void Copy(TextStyle textStyle)
{
font = textStyle.font;
rotate = textStyle.rotate;
offset = textStyle.offset;
color = textStyle.color;
backgroundColor = textStyle.backgroundColor;
fontSize = textStyle.fontSize;
fontStyle = textStyle.fontStyle;
lineSpacing = textStyle.lineSpacing;
alignment = textStyle.alignment;
#if dUI_TextMeshPro
m_TMPFont = textStyle.tmpFont;
m_TMPAlignment = textStyle.tmpAlignment;
m_TMPFontStyle = textStyle.tmpFontStyle;
#endif
}
public void UpdateAlignmentByLocation(Location location)
{
#if dUI_TextMeshPro
m_TMPAlignment = location.runtimeTMPTextAlignment;
#else
m_Alignment = location.runtimeTextAlignment;
#endif
}
public Color GetColor(Color defaultColor)
{
if (ChartHelper.IsClearColor(color)) return defaultColor;
else return color;
}
public int GetFontSize(ComponentTheme defaultTheme)
{
if(fontSize == 0) return defaultTheme.fontSize;
else return fontSize;
}
}
}

View File

@@ -1,10 +1,10 @@
/*
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
@@ -22,7 +22,7 @@ namespace XCharts
{
[SerializeField] private bool m_Show;
[FormerlySerializedAs("m_textStyle")]
[SerializeField] private TextStyle m_TextStyle = new TextStyle(18);
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
/// <summary>
/// Whether to show title.
@@ -31,7 +31,7 @@ namespace XCharts
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
@@ -41,7 +41,7 @@ namespace XCharts
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtility.SetClass(ref m_TextStyle, value, true)) SetComponentDirty(); }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value, true)) SetComponentDirty(); }
}
public override bool componentDirty { get { return m_ComponentDirty || textStyle.componentDirty; } }
@@ -52,7 +52,7 @@ namespace XCharts
textStyle.ClearComponentDirty();
}
public Text runtimeText { get; set; }
public ChartText runtimeText { get; set; }
public bool IsInited()
{
@@ -61,26 +61,28 @@ namespace XCharts
public void SetActive(bool active)
{
if (runtimeText)
if (runtimeText != null)
{
ChartHelper.SetActive(runtimeText, active);
runtimeText.SetActive(active);
}
}
public void UpdatePosition(Vector3 pos)
{
if (runtimeText)
if (runtimeText != null)
{
runtimeText.transform.localPosition = pos + new Vector3(m_TextStyle.offset.x, m_TextStyle.offset.y);
runtimeText.SetLocalPosition(pos + new Vector3(m_TextStyle.offset.x, m_TextStyle.offset.y));
}
}
public void SetText(string text)
{
if (runtimeText && !runtimeText.text.Equals(text))
if (runtimeText == null) return;
var oldText = runtimeText.GetText();
if (oldText != null && !oldText.Equals(text))
{
if (!ChartHelper.IsClearColor(textStyle.color)) runtimeText.color = textStyle.color;
runtimeText.text = text;
if (!ChartHelper.IsClearColor(textStyle.color)) runtimeText.SetColor(textStyle.color);
runtimeText.SetText(text);
}
}
}