v3.0.0-preivew8

This commit is contained in:
monitor1394
2022-04-26 08:24:45 +08:00
parent f11ee84517
commit 9dedc1db68
80 changed files with 1189 additions and 1307 deletions

View File

@@ -86,14 +86,14 @@ namespace XCharts.Runtime
bool inside = axis.axisLabel.inside;
var labelName = AxisHelper.GetLabelName(axis, total, i, axis.context.minValue, axis.context.maxValue,
null, isPercentStack);
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(scaleAngle, txtHig), axis,
chart.theme.axis, labelName);
label.label.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter));
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform,
new Vector2(scaleAngle, txtHig), axis,
chart.theme.axis, labelName, Color.clear);
label.text.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter));
var pos = ChartHelper.GetPos(cenPos, radius + margin,
isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true);
AxisHelper.AdjustCircleLabelPos(label, pos, cenPos, txtHig, Vector3.zero);
if (i == 0) axis.axisLabel.SetRelatedText(label.label, scaleAngle);
if (i == 0) axis.axisLabel.SetRelatedText(label.text, scaleAngle);
axis.context.labelObjectList.Add(label);
totalAngle += scaleAngle;

View File

@@ -94,7 +94,6 @@ namespace XCharts.Runtime
[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;
@@ -362,14 +361,6 @@ namespace XCharts.Runtime
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
{
@@ -432,7 +423,6 @@ namespace XCharts.Runtime
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();
@@ -461,7 +451,6 @@ namespace XCharts.Runtime
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);

View File

@@ -104,7 +104,12 @@ namespace XCharts.Runtime
else
range = dataZoom.minShowNum;
}
filterData = data.GetRange(start, range);
if (range > data.Count - start - 1)
start = data.Count - range - 1;
if (start >= 0)
filterData = data.GetRange(start, range);
else
filterData = data;
}
else
{

View File

@@ -296,12 +296,12 @@ namespace XCharts
if (i == 0)
{
var dist = GetLabelPosition(0, 1).x - pos.x;
label.SetLabelActive(dist > label.label.GetPreferredWidth());
label.SetTextActive(dist > label.text.GetPreferredWidth());
}
else if (i == axis.context.labelValueList.Count - 1)
{
var dist = pos.x - GetLabelPosition(0, i - 1).x;
label.SetLabelActive(dist > label.label.GetPreferredWidth());
label.SetTextActive(dist > label.text.GetPreferredWidth());
}
}
else
@@ -309,12 +309,12 @@ namespace XCharts
if (i == 0)
{
var dist = GetLabelPosition(0, 1).y - pos.y;
label.SetLabelActive(dist > label.label.GetPreferredHeight());
label.SetTextActive(dist > label.text.GetPreferredHeight());
}
else if (i == axis.context.labelValueList.Count - 1)
{
var dist = pos.y - GetLabelPosition(0, i - 1).y;
label.SetLabelActive(dist > label.label.GetPreferredHeight());
label.SetTextActive(dist > label.text.GetPreferredHeight());
}
}
}
@@ -361,82 +361,36 @@ namespace XCharts
? axis.axisLabel.height
: 20f;
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series);
var inside = axis.axisLabel.inside;
var defaultAlignment = orient == Orient.Horizonal ? TextAnchor.MiddleCenter :
((inside && axis.IsLeft()) || (!inside && axis.IsRight())
? TextAnchor.MiddleLeft
: TextAnchor.MiddleRight);
if (axis.IsCategory() && axis.boundaryGap)
{
splitNumber -= 1;
}
for (int i = 0; i < splitNumber; i++)
{
ChartLabel label;
var labelWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom);
var inside = axis.axisLabel.inside;
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series);
var labelName = AxisHelper.GetLabelName(axis, axisLength, i,
axis.context.minValue,
axis.context.maxValue,
dataZoom, isPercentStack);
if (orient == Orient.Horizonal)
{
label = ChartHelper.AddAxisLabelObject(splitNumber, i,
ChartCached.GetAxisLabelName(i),
axisObj.transform,
new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f),
new Vector2(textWidth, textHeight),
axis, chart.theme.axis, labelName);
}
else
{
if ((inside && axis.IsLeft()) || (!inside && axis.IsRight()))
{
label = ChartHelper.AddAxisLabelObject(splitNumber, i,
ChartCached.GetAxisLabelName(i),
axisObj.transform,
Vector2.zero,
Vector2.zero,
new Vector2(0, 0.5f),
new Vector2(textWidth, textHeight),
axis, chart.theme.axis, labelName);
label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleLeft));
}
else
{
label = ChartHelper.AddAxisLabelObject(splitNumber, i,
ChartCached.GetAxisLabelName(i),
axisObj.transform,
Vector2.zero,
Vector2.zero,
new Vector2(1, 0.5f),
new Vector2(textWidth, textHeight),
axis, chart.theme.axis, labelName);
label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleRight));
}
}
var label = ChartHelper.AddAxisLabelObject(splitNumber, i,
ChartCached.GetAxisLabelName(i),
axisObj.transform,
new Vector2(textWidth, textHeight),
axis, chart.theme.axis, labelName,
Color.clear,
defaultAlignment);
if (i == 0)
axis.axisLabel.SetRelatedText(label.label, labelWidth);
axis.axisLabel.SetRelatedText(label.text, labelWidth);
var pos = handler.GetLabelPosition(totalWidth + gapWidth, i);
if (orient == Orient.Horizonal)
{
label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleCenter));
}
else
{
if (axis.IsRight())
label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleLeft));
else
label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleRight));
}
label.SetPosition(pos);
handler.CheckValueLabelActive(axis, i, label, pos);
@@ -446,59 +400,41 @@ namespace XCharts
}
if (axis.axisName.show)
{
ChartText axisName = null;
var axisNameTextStyle = axis.axisName.textStyle;
var offset = axisNameTextStyle.offset;
ChartLabel label = null;
var relativedDist = (relativedAxis == null ? 0 : relativedAxis.context.offset);
var zeroPos = new Vector3(axisStartX, axisStartY + relativedDist);
var offset = axis.axisName.labelStyle.offset;
var autoColor = axis.axisLine.GetColor(chart.theme.axis.lineColor);
if (orient == Orient.Horizonal)
{
switch (axis.axisName.location)
switch (axis.axisName.labelStyle.position)
{
case AxisName.Location.Start:
case LabelStyle.Position.Start:
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform,
new Vector2(1, 0.5f),
new Vector2(1, 0.5f),
new Vector2(1, 0.5f),
new Vector2(100, 20),
axisNameTextStyle, chart.theme.axis);
axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleRight));
axisName.SetLocalPosition(axis.position == Axis.AxisPosition.Top
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleRight);
label.SetActive(axis.axisName.labelStyle.show);
label.SetPosition(axis.position == Axis.AxisPosition.Top
? new Vector2(zeroPos.x - offset.x, axisStartY + relativedLength + offset.y + axis.offset)
: new Vector2(zeroPos.x - offset.x, zeroPos.y + offset.y + axis.offset));
break;
case AxisName.Location.Middle:
case LabelStyle.Position.Middle:
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform,
new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f),
new Vector2(100, 20),
axisNameTextStyle, chart.theme.axis);
axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleCenter));
axisName.SetLocalPosition(axis.position == Axis.AxisPosition.Top
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
label.SetActive(axis.axisName.labelStyle.show);
label.SetPosition(axis.position == Axis.AxisPosition.Top
? new Vector2(axisStartX + axisLength / 2 + offset.x, axisStartY + relativedLength - offset.y + axis.offset)
: new Vector2(axisStartX + axisLength / 2 + offset.x, axisStartY - offset.y + axis.offset));
break;
case AxisName.Location.End:
default:
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform,
new Vector2(0, 0.5f),
new Vector2(0, 0.5f),
new Vector2(0, 0.5f),
new Vector2(100, 20),
axisNameTextStyle, chart.theme.axis);
axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleLeft));
axisName.SetLocalPosition(axis.position == Axis.AxisPosition.Top
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleLeft);
label.SetActive(axis.axisName.labelStyle.show);
label.SetPosition(axis.position == Axis.AxisPosition.Top
? new Vector2(axisStartX + axisLength + offset.x, axisStartY + relativedLength + offset.y + axis.offset)
: new Vector2(axisStartX + axisLength + offset.x, zeroPos.y + offset.y + axis.offset));
break;
@@ -506,43 +442,39 @@ namespace XCharts
}
else
{
switch (axis.axisName.location)
switch (axis.axisName.labelStyle.position)
{
case AxisName.Location.Start:
case LabelStyle.Position.Start:
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), axisNameTextStyle,
chart.theme.axis);
axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleCenter));
axisName.SetLocalPosition(axis.position == Axis.AxisPosition.Right ?
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
label.SetActive(axis.axisName.labelStyle.show);
label.SetPosition(axis.position == Axis.AxisPosition.Right ?
new Vector2(axisStartX + relativedLength + offset.x + axis.offset, axisStartY - offset.y) :
new Vector2(zeroPos.x + offset.x + axis.offset, axisStartY - offset.y));
break;
case AxisName.Location.Middle:
case LabelStyle.Position.Middle:
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, new Vector2(1, 0.5f),
new Vector2(1, 0.5f), new Vector2(1, 0.5f), new Vector2(100, 20), axisNameTextStyle,
chart.theme.axis);
axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleRight));
axisName.SetLocalPosition(axis.position == Axis.AxisPosition.Right ?
new Vector2(axisStartX + relativedLength - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y) :
new Vector2(axisStartX - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y));
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
label.SetActive(axis.axisName.labelStyle.show);
label.SetPosition(axis.position == Axis.AxisPosition.Right ?
new Vector2(axisStartX + relativedLength - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y) :
new Vector2(axisStartX - offset.x + axis.offset, axisStartY + axisLength / 2 + offset.y));
break;
case AxisName.Location.End:
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform, new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), axisNameTextStyle,
chart.theme.axis);
axisName.SetAlignment(axisNameTextStyle.GetAlignment(TextAnchor.MiddleCenter));
axisName.SetLocalPosition(axis.position == Axis.AxisPosition.Right ?
default:
//LabelStyle.Position
label = ChartHelper.AddChartLabel(s_DefaultAxisName, axisObj.transform, axis.axisName.labelStyle,
chart.theme.axis, axis.axisName.name, autoColor, TextAnchor.MiddleCenter);
label.SetActive(axis.axisName.labelStyle.show);
label.SetPosition(axis.position == Axis.AxisPosition.Right ?
new Vector2(axisStartX + relativedLength + offset.x + axis.offset, axisStartY + axisLength + offset.y) :
new Vector2(zeroPos.x + offset.x + axis.offset, axisStartY + axisLength + offset.y));
break;
}
}
axisName.SetText(axis.axisName.name);
}
}
@@ -573,7 +505,7 @@ namespace XCharts
else
current += axisStartY - axis.axisLabel.distance - fontSize / 2;
return new Vector3(axisStartX + scaleWid, current) + axis.axisLabel.textStyle.offsetv3;
return new Vector3(axisStartX + scaleWid, current);
}
else
{
@@ -588,7 +520,7 @@ namespace XCharts
else
current += axisStartX - axis.axisLabel.distance;
return new Vector3(current, axisStartY + scaleWid) + axis.axisLabel.textStyle.offsetv3;
return new Vector3(current, axisStartY + scaleWid);
}
}

View File

@@ -403,33 +403,11 @@ namespace XCharts.Runtime
return true;
}
public static void AdjustCircleLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
{
var txtWidth = txt.GetPreferredWidth();
var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight());
txt.SetSizeDelta(sizeDelta);
var diff = pos.x - cenPos.x;
if (diff < -1f) //left
{
pos = new Vector3(pos.x - txtWidth / 2, pos.y);
}
else if (diff > 1f) //right
{
pos = new Vector3(pos.x + txtWidth / 2, pos.y);
}
else
{
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
pos = new Vector3(pos.x, y);
}
txt.SetLocalPosition(pos + offset);
}
public static void AdjustCircleLabelPos(ChartLabel txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
{
var txtWidth = txt.label.GetPreferredWidth();
var sizeDelta = new Vector2(txtWidth, txt.label.GetPreferredHeight());
txt.label.SetSizeDelta(sizeDelta);
var txtWidth = txt.text.GetPreferredWidth();
var sizeDelta = new Vector2(txtWidth, txt.text.GetPreferredHeight());
txt.text.SetSizeDelta(sizeDelta);
var diff = pos.x - cenPos.x;
if (diff < -1f) //left
{
@@ -447,11 +425,11 @@ namespace XCharts.Runtime
txt.SetPosition(pos + offset);
}
public static void AdjustRadiusAxisLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
public static void AdjustRadiusAxisLabelPos(ChartLabel txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
{
var txtWidth = txt.GetPreferredWidth();
var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight());
txt.SetSizeDelta(sizeDelta);
var txtWidth = txt.text.GetPreferredWidth();
var sizeDelta = new Vector2(txtWidth, txt.text.GetPreferredHeight());
txt.text.SetSizeDelta(sizeDelta);
var diff = pos.y - cenPos.y;
if (diff > 20f) //left
{
@@ -466,7 +444,7 @@ namespace XCharts.Runtime
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
pos = new Vector3(pos.x, y);
}
txt.SetLocalPosition(pos);
txt.SetPosition(pos);
}
public static float GetAxisPosition(GridCoord grid, Axis axis, double value, int dataCount = 0, DataZoom dataZoom = null)

View File

@@ -10,33 +10,16 @@ namespace XCharts.Runtime
/// |坐标轴刻度标签的相关设置。
/// </summary>
[Serializable]
public class AxisLabel : ChildComponent
public class AxisLabel : LabelStyle
{
[SerializeField] private bool m_Show = true;
[SerializeField] private string m_Formatter;
[SerializeField] private int m_Interval = 0;
[SerializeField] private bool m_Inside = false;
[SerializeField] private float m_Distance;
[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_ShowStartLabel = true;
[SerializeField] private bool m_ShowEndLabel = true;
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
private AxisLabelFormatterFunction m_FormatterFunction;
/// <summary>
/// Set this to false to prevent the axis label from appearing.
/// |是否显示刻度标签。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// The display interval of the axis label.
/// |坐标轴刻度标签的显示间隔在类目轴中有效。0表示显示所有标签1表示隔一个隔显示一个标签以此类推。
@@ -55,38 +38,6 @@ namespace XCharts.Runtime
get { return m_Inside; }
set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetComponentDirty(); }
}
/// <summary>
/// The distance between the axis label and the axis line.
/// |刻度标签与轴线之间的距离。
/// </summary>
public float distance
{
get { return m_Distance; }
set { if (PropertyUtil.SetStruct(ref m_Distance, value)) SetComponentDirty(); }
}
/// <summary>
/// 图例内容字符串模版格式器。支持用 \n 换行。
/// 模板变量为图例名称 {value}。
/// </summary>
public string formatter
{
get { return m_Formatter; }
set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); }
}
/// <summary>
/// Standard numeric format strings.
/// |标准数字格式字符串。用于将数值格式化显示为字符串。
/// 使用Axx的形式A是格式说明符的单字符支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明从0-99。
/// 参考https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
/// </summary>
/// <value></value>
public string numericFormatter
{
get { return m_NumericFormatter; }
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
}
/// <summary>
/// Show negative number as positive number.
/// |将负数数值显示为正数。一般和`Serie`的`showAsPositiveNumber`配合使用。
@@ -106,22 +57,6 @@ namespace XCharts.Runtime
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>
/// Whether to display the first label.
/// |是否显示第一个文本。
/// </summary>
@@ -148,21 +83,6 @@ namespace XCharts.Runtime
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 AxisLabelFormatterFunction formatterFunction
{
set { m_FormatterFunction = value; }
}
public override bool componentDirty { get { return m_ComponentDirty || m_TextLimit.componentDirty; } }
public override void ClearComponentDirty()
{
@@ -185,7 +105,7 @@ namespace XCharts.Runtime
}
}
public AxisLabel Clone()
public new AxisLabel Clone()
{
var axisLabel = new AxisLabel();
axisLabel.show = show;

View File

@@ -11,21 +11,9 @@ namespace XCharts.Runtime
[Serializable]
public class AxisName : ChildComponent
{
/// <summary>
/// the location of axis name.
/// |坐标轴名称显示位置。
/// </summary>
public enum Location
{
Start,
Middle,
End
}
[SerializeField] private bool m_Show;
[SerializeField] private string m_Name;
[SerializeField] private string m_Formatter;
[SerializeField] private Location m_Location;
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
/// <summary>
/// Whether to show axis name.
@@ -45,46 +33,28 @@ namespace XCharts.Runtime
get { return m_Name; }
set { if (PropertyUtil.SetClass(ref m_Name, value)) SetComponentDirty(); }
}
/// <summary>
/// The formatter of indicator's name.
/// |指示器名称显示的格式器。可用在雷达图。
/// </summary>
public string formatter
{
get { return m_Formatter; }
set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); }
}
/// <summary>
/// Location of axis name.
/// |坐标轴名称显示位置。
/// </summary>
public Location location
{
get { return m_Location; }
set { if (PropertyUtil.SetStruct(ref m_Location, value)) SetComponentDirty(); }
}
/// <summary>
/// The text style of axis name.
/// |文本样式。
/// </summary>
public TextStyle textStyle
public LabelStyle labelStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
get { return m_LabelStyle; }
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
}
public static AxisName defaultAxisName
{
get
{
return new AxisName()
var axisName = new AxisName()
{
m_Show = false,
m_Name = "axisName",
m_Location = Location.End,
m_TextStyle = new TextStyle(),
m_LabelStyle = new LabelStyle()
};
axisName.labelStyle.position = LabelStyle.Position.End;
return axisName;
}
}
@@ -93,8 +63,7 @@ namespace XCharts.Runtime
var axisName = new AxisName();
axisName.show = show;
axisName.name = name;
axisName.location = location;
axisName.textStyle.Copy(textStyle);
axisName.m_LabelStyle.Copy(m_LabelStyle);
return axisName;
}
@@ -102,8 +71,7 @@ namespace XCharts.Runtime
{
show = axisName.show;
name = axisName.name;
location = axisName.location;
textStyle.Copy(axisName.textStyle);
m_LabelStyle.Copy(axisName.labelStyle);
}
}
}

View File

@@ -24,7 +24,6 @@ namespace XCharts.Runtime
splitLine.show = false;
splitLine.lineStyle.type = LineStyle.Type.None;
axisLabel.textLimit.enable = true;
iconStyle.show = false;
}

View File

@@ -109,18 +109,17 @@ namespace XCharts.Runtime
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series);
var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.context.minValue, axis.context.maxValue,
null, isPercentStack);
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(labelWidth, txtHig), axis, chart.theme.axis,
labelName);
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform,
new Vector2(labelWidth, txtHig), axis, chart.theme.axis, labelName, Color.clear);
if (i == 0)
axis.axisLabel.SetRelatedText(label.label, labelWidth);
axis.axisLabel.SetRelatedText(label.text, labelWidth);
label.label.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleCenter));
label.text.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleCenter));
label.SetText(labelName);
label.SetPosition(GetLabelPosition(polar, axis, angleAxis.context.startAngle, totalWidth));
label.SetActive(true);
label.SetLabelActive(true);
label.SetTextActive(true);
axis.context.labelObjectList.Add(label);

View File

@@ -140,7 +140,6 @@ namespace XCharts.Runtime
axisLabel.textLimit.enable = true;
axisTick.showStartTick = true;
axisTick.showEndTick = true;
iconStyle.show = false;
}
}
}

View File

@@ -28,7 +28,6 @@ namespace XCharts.Runtime
splitLine.show = false;
splitLine.lineStyle.type = LineStyle.Type.None;
axisLabel.textLimit.enable = true;
iconStyle.show = false;
}
}
}

View File

@@ -26,7 +26,6 @@ namespace XCharts.Runtime
splitLine.lineStyle.type = LineStyle.Type.None;
axisLabel.textLimit.enable = false;
axisTick.showStartTick = true;
iconStyle.show = false;
}
}
}

View File

@@ -5,17 +5,26 @@ using UnityEngine.UI;
namespace XCharts.Runtime
{
[System.Serializable]
public class IconStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent
public class IconStyle : ChildComponent
{
public enum Layer
{
UnderLabel,
AboveLabel
/// <summary>
/// The icon is display under the label text.
/// 图标在标签文字下
/// </summary>
UnderText,
/// <summary>
/// The icon is display above the label text.
/// 图标在标签文字上
/// </summary>
AboveText
}
[SerializeField] private bool m_Show = false;
[SerializeField] private Layer m_Layer;
[SerializeField] private Align m_Align = Align.Left;
[SerializeField] private Sprite m_Sprite;
[SerializeField] private Image.Type m_Type;
[SerializeField] private Color m_Color = Color.white;
[SerializeField] private float m_Width = 20;
[SerializeField] private float m_Height = 20;
@@ -25,7 +34,7 @@ namespace XCharts.Runtime
public void Reset()
{
m_Show = false;
m_Layer = Layer.UnderLabel;
m_Layer = Layer.UnderText;
m_Sprite = null;
m_Color = Color.white;
m_Width = 20;
@@ -48,6 +57,11 @@ namespace XCharts.Runtime
/// </summary>
public Sprite sprite { get { return m_Sprite; } set { m_Sprite = value; } }
/// <summary>
/// How to display the icon.
/// |图片的显示类型。
/// </summary>
public Image.Type type { get { return m_Type; } set { m_Type = value; } }
/// <summary>
/// 图标颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
@@ -77,6 +91,7 @@ namespace XCharts.Runtime
iconStyle.show = show;
iconStyle.layer = layer;
iconStyle.sprite = sprite;
iconStyle.type = type;
iconStyle.color = color;
iconStyle.width = width;
iconStyle.height = height;
@@ -91,6 +106,7 @@ namespace XCharts.Runtime
show = iconStyle.show;
layer = iconStyle.layer;
sprite = iconStyle.sprite;
type = iconStyle.type;
color = iconStyle.color;
width = iconStyle.width;
height = iconStyle.height;

View File

@@ -0,0 +1,82 @@

using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime
{
[System.Serializable]
public class ImageStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private Sprite m_Sprite;
[SerializeField] private Image.Type m_Type;
[SerializeField] private bool m_AutoColor;
[SerializeField] private Color m_Color = Color.clear;
[SerializeField] private float m_Width = 0;
[SerializeField] private float m_Height = 0;
public void Reset()
{
m_Show = false;
m_Type = Image.Type.Simple;
m_Sprite = null;
m_AutoColor = false;
m_Color = Color.white;
m_Width = 0;
m_Height = 0;
}
/// <summary>
/// Whether the data icon is show.
/// |是否显示图标。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// The image of icon.
/// |图标的图片。
/// </summary>
public Sprite sprite { get { return m_Sprite; } set { m_Sprite = value; } }
/// <summary>
/// How to display the image.
/// |图片的显示类型。
/// </summary>
public Image.Type type { get { return m_Type; } set { m_Type = value; } }
/// <summary>
/// 是否自动颜色。
/// </summary>
public bool autoColor { get { return m_AutoColor; } set { m_AutoColor = value; } }
/// <summary>
/// 图标颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// 图标宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// 图标高。
/// </summary>
public float height { get { return m_Height; } set { m_Height = value; } }
public ImageStyle Clone()
{
var imageStyle = new ImageStyle();
imageStyle.type = type;
imageStyle.sprite = sprite;
imageStyle.autoColor = autoColor;
imageStyle.color = color;
imageStyle.width = width;
imageStyle.height = height;
return imageStyle;
}
public void Copy(ImageStyle imageStyle)
{
type = imageStyle.type;
sprite = imageStyle.sprite;
autoColor = imageStyle.autoColor;
color = imageStyle.color;
width = imageStyle.width;
height = imageStyle.height;
}
}
}

View File

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

View File

@@ -15,6 +15,7 @@ namespace XCharts.Runtime
/// </summary>
public enum Position
{
Default,
/// <summary>
/// Outside of sectors of pie chart, which relates to corresponding sector through visual guide line.
/// |饼图扇区外侧,通过视觉引导线连到相应的扇区。
@@ -68,32 +69,31 @@ namespace XCharts.Runtime
}
[SerializeField] protected bool m_Show = true;
[SerializeField] Position m_Position = Position.Outside;
[SerializeField] Position m_Position = Position.Default;
[SerializeField] protected bool m_AutoOffset = false;
[SerializeField] protected Vector3 m_Offset;
[SerializeField] protected float m_Rotate;
[SerializeField] protected float m_Distance;
[SerializeField] protected string m_Formatter;
[SerializeField] protected float m_PaddingLeftRight = 2f;
[SerializeField] protected float m_PaddingTopBottom = 2f;
[SerializeField] protected float m_BackgroundWidth = 0;
[SerializeField] protected float m_BackgroundHeight = 0;
[SerializeField] protected string m_NumericFormatter = "";
[SerializeField] protected bool m_AutoOffset = false;
[SerializeField] protected float m_Width = 0;
[SerializeField] protected float m_Height = 0;
[SerializeField] protected IconStyle m_Icon = new IconStyle();
[SerializeField] protected ImageStyle m_Background = new ImageStyle();
[SerializeField] protected TextPadding m_TextPadding = new TextPadding();
[SerializeField] protected TextStyle m_TextStyle = new TextStyle();
protected SerieLabelFormatterFunction m_FormatterFunction;
protected LabelFormatterFunction m_FormatterFunction;
public void Reset()
{
m_Show = false;
m_Position = Position.Outside;
m_Position = Position.Default;
m_Offset = Vector3.zero;
m_Distance = 0;
m_Rotate = 0;
m_PaddingLeftRight = 2f;
m_PaddingTopBottom = 2f;
m_BackgroundWidth = 0;
m_BackgroundHeight = 0;
m_Width = 0;
m_Height = 0;
m_NumericFormatter = "";
m_AutoOffset = false;
}
@@ -161,42 +161,33 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_Distance, 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.
/// |标签的背景宽度。一般不用指定,不指定时则自动是文字的宽度。
/// the width of label. If set as default value 0, it means than the label width auto set as the text width.
/// |标签的宽度。一般不用指定,不指定时则自动是文字的宽度。
/// </summary>
/// <value></value>
public float backgroundWidth
public float width
{
get { return m_BackgroundWidth; }
set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); }
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, 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.
/// |标签的背景高度。一般不用指定,不指定时则自动是文字的高度。
/// the height of label. If set as default value 0, it means than the label height auto set as the text height.
/// |标签的高度。一般不用指定,不指定时则自动是文字的高度。
/// </summary>
/// <value></value>
public float backgroundHeight
public float height
{
get { return m_BackgroundHeight; }
set { if (PropertyUtil.SetStruct(ref m_BackgroundHeight, value)) SetComponentDirty(); }
get { return m_Height; }
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetComponentDirty(); }
}
/// <summary>
/// the text padding of left and right. defaut:2.
/// |左右边距。
/// the text padding of label.
/// |文本的边距。
/// </summary>
public float paddingLeftRight
public TextPadding textPadding
{
get { return m_PaddingLeftRight; }
set { if (PropertyUtil.SetStruct(ref m_PaddingLeftRight, value)) SetComponentDirty(); }
}
/// <summary>
/// the text padding of top and bottom. defaut:2.
/// |上下边距。
/// </summary>
public float paddingTopBottom
{
get { return m_PaddingTopBottom; }
set { if (PropertyUtil.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); }
get { return m_TextPadding; }
set { if (PropertyUtil.SetClass(ref m_TextPadding, value)) SetComponentDirty(); }
}
/// <summary>
/// Standard numeric format strings.
@@ -218,8 +209,24 @@ namespace XCharts.Runtime
get { return m_AutoOffset; }
set { if (PropertyUtil.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); }
}
/// <summary>
/// the sytle of background.
/// |背景图样式。
/// </summary>
public ImageStyle background
{
get { return m_Background; }
set { if (PropertyUtil.SetClass(ref m_Background, value)) SetAllDirty(); }
}
/// <summary>
/// the sytle of icon.
/// |图标样式。
/// </summary>
public IconStyle icon
{
get { return m_Icon; }
set { if (PropertyUtil.SetClass(ref m_Icon, value)) SetAllDirty(); }
}
/// <summary>
/// the sytle of text.
/// |文本样式。
@@ -229,8 +236,7 @@ namespace XCharts.Runtime
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetAllDirty(); }
}
public SerieLabelFormatterFunction formatterFunction
public LabelFormatterFunction formatterFunction
{
get { return m_FormatterFunction; }
set { m_FormatterFunction = value; }
@@ -241,6 +247,11 @@ namespace XCharts.Runtime
return position == Position.Inside || position == Position.Center;
}
public bool IsAutoSize()
{
return width == 0 && height == 0;
}
public Vector3 GetOffset(float radius)
{
var x = ChartHelper.GetActualValue(m_Offset.x, radius);
@@ -261,29 +272,42 @@ namespace XCharts.Runtime
}
}
public TextAnchor GetAutoAlignment()
public virtual LabelStyle Clone()
{
if (textStyle.autoAlign) return textStyle.alignment;
else
{
switch (position)
{
case LabelStyle.Position.Inside:
case LabelStyle.Position.Center:
case LabelStyle.Position.Top:
case LabelStyle.Position.Bottom:
return TextAnchor.MiddleCenter;
case LabelStyle.Position.Outside:
case LabelStyle.Position.Right:
return TextAnchor.MiddleLeft;
case LabelStyle.Position.Left:
return TextAnchor.MiddleRight;
default:
return TextAnchor.MiddleCenter;
}
}
var label = new LabelStyle();
label.m_Show = m_Show;
label.m_Position = m_Position;
label.m_Offset = m_Offset;
label.m_Rotate = m_Rotate;
label.m_Distance = m_Distance;
label.m_Formatter = m_Formatter;
label.m_Width = m_Width;
label.m_Height = m_Height;
label.m_NumericFormatter = m_NumericFormatter;
label.m_AutoOffset = m_AutoOffset;
label.m_Icon.Copy(m_Icon);
label.m_Background.Copy(m_Background);
label.m_TextPadding = m_TextPadding;
label.m_TextStyle.Copy(m_TextStyle);
return label;
}
public virtual void Copy(LabelStyle label)
{
m_Show = label.m_Show;
m_Position = label.m_Position;
m_Offset = label.m_Offset;
m_Rotate = label.m_Rotate;
m_Distance = label.m_Distance;
m_Formatter = label.m_Formatter;
m_Width = label.m_Width;
m_Height = label.m_Height;
m_NumericFormatter = label.m_NumericFormatter;
m_AutoOffset = label.m_AutoOffset;
m_Icon.Copy(label.m_Icon);
m_Background.Copy(label.m_Background);
m_TextPadding = label.m_TextPadding;
m_TextStyle.Copy(label.m_TextStyle);
}
}
}

View File

@@ -0,0 +1,61 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// Settings related to text.
/// |文本的内边距设置。
/// </summary>
[Serializable]
public class TextPadding : ChildComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Top = 2;
[SerializeField] private float m_Right = 4;
[SerializeField] private float m_Left = 4;
[SerializeField] private float m_Bottom = 2;
public TextPadding() { }
public TextPadding(float top, float right, float bottom, float left)
{
SetPadding(top, right, bottom, left);
}
public void SetPadding(float top, float right, float bottom, float left)
{
m_Top = top; ;
m_Right = right;
m_Bottom = bottom;
m_Left = left;
}
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
public float top
{
get { return m_Top; }
set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetComponentDirty(); }
}
public float right
{
get { return m_Right; }
set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetComponentDirty(); }
}
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetComponentDirty(); }
}
public float left
{
get { return m_Left; }
set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetComponentDirty(); }
}
}
}

View File

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

View File

@@ -14,16 +14,13 @@ namespace XCharts.Runtime
[Serializable]
public class TextStyle : ChildComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private Font m_Font;
[SerializeField] private bool m_AutoWrap = false;
[SerializeField] private bool m_AutoAlign = true;
[SerializeField] private float m_Rotate = 0;
[SerializeField] private float m_ExtraWidth = 0;
[SerializeField] private Vector2 m_Offset = Vector2.zero;
[SerializeField] private bool m_AutoColor = false;
[SerializeField] private Color m_Color = Color.clear;
[SerializeField] private bool m_AutoBackgroundColor = false;
[SerializeField] private Color m_BackgroundColor = Color.clear;
[SerializeField] private int m_FontSize = 0;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private float m_LineSpacing = 1f;
@@ -33,6 +30,11 @@ namespace XCharts.Runtime
[SerializeField] private FontStyles m_TMPFontStyle = FontStyles.Normal;
[SerializeField] private TextAlignmentOptions m_TMPAlignment = TextAlignmentOptions.Left;
#endif
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// Rotation of text.
/// |文本的旋转。
@@ -44,26 +46,6 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
}
/// <summary>
/// Extra width of text preferred width.
/// |额外的宽度
/// </summary>
public float extraWidth
{
get { return m_ExtraWidth; }
set { if (PropertyUtil.SetStruct(ref m_ExtraWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// the offset of position.
/// |坐标偏移。
/// [Default: `Vector2.zero`]
/// </summary>
public Vector2 offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetComponentDirty(); }
}
public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
/// <summary>
/// 是否开启自动颜色。当开启时,会自动设置颜色。
/// </summary>
public bool autoColor
@@ -81,21 +63,6 @@ namespace XCharts.Runtime
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetComponentDirty(); }
}
public bool autoBackgroundColor
{
get { return m_AutoBackgroundColor; }
set { if (PropertyUtil.SetStruct(ref m_AutoBackgroundColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of text.
/// |文本的背景颜色。
/// [default: `Color.clear`]
/// </summary>
public Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the font of text. When `null`, the theme's font is used by default.
/// |文本字体。
@@ -172,11 +139,6 @@ namespace XCharts.Runtime
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()
@@ -213,11 +175,7 @@ namespace XCharts.Runtime
{
font = textStyle.font;
rotate = textStyle.rotate;
offset = textStyle.offset;
autoColor = textStyle.autoColor;
color = textStyle.color;
autoBackgroundColor = textStyle.autoBackgroundColor;
backgroundColor = textStyle.backgroundColor;
fontSize = textStyle.fontSize;
fontStyle = textStyle.fontStyle;
lineSpacing = textStyle.lineSpacing;
@@ -226,7 +184,6 @@ namespace XCharts.Runtime
autoAlign = textStyle.autoAlign;
#if dUI_TextMeshPro
m_TMPFont = textStyle.tmpFont;
m_TMPAlignment = textStyle.tmpAlignment;
m_TMPFontStyle = textStyle.tmpFontStyle;
#endif
}
@@ -256,17 +213,9 @@ namespace XCharts.Runtime
return fontSize;
}
public TextAnchor GetAlignment(TextAnchor systemAlignment)
public TextAnchor GetAlignment(TextAnchor defaultAlignment)
{
return m_AutoAlign ? systemAlignment : alignment;
}
public Color32 GetBackgroundColor(Color32 chartBackgroundColor)
{
if (m_AutoColor || ChartHelper.IsClearColor(m_BackgroundColor))
return chartBackgroundColor;
else
return m_BackgroundColor;
return m_AutoAlign ? defaultAlignment : alignment;
}
}
}

View File

@@ -87,7 +87,7 @@ namespace XCharts.Runtime
[Range(1f, 20f)]
[SerializeField] private float m_ScrollSensitivity = 1.1f;
[SerializeField] private Orient m_Orient = Orient.Horizonal;
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid);
[SerializeField] private AreaStyle m_AreaStyle = new AreaStyle();
@@ -339,13 +339,13 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetVerticesDirty(); }
}
/// <summary>
/// font style.
/// |文格式。
/// label style.
/// |文本标签格式。
/// </summary>
public TextStyle textStyle
public LabelStyle labelStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
get { return m_LabelStyle; }
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// 阴影线条样式。
@@ -376,12 +376,12 @@ namespace XCharts.Runtime
/// The start label.
/// |组件的开始信息文本。
/// </summary>
private ChartText m_StartLabel { get; set; }
private ChartLabel m_StartLabel { get; set; }
/// <summary>
/// The end label.
/// |组件的结束信息文本。
/// </summary>
private ChartText m_EndLabel { get; set; }
private ChartLabel m_EndLabel { get; set; }
public override void SetDefaultValue()
{
@@ -402,7 +402,7 @@ namespace XCharts.Runtime
end = 70;
m_Orient = Orient.Horizonal;
m_ScrollSensitivity = 10;
m_TextStyle = new TextStyle();
m_LabelStyle = new LabelStyle();
m_LineStyle = new LineStyle(LineStyle.Type.Solid)
{
opacity = 0.3f
@@ -562,14 +562,8 @@ namespace XCharts.Runtime
/// <param name="flag"></param>
internal void SetLabelActive(bool flag)
{
if (m_StartLabel != null && m_StartLabel.gameObject.activeInHierarchy != flag)
{
m_StartLabel.gameObject.SetActive(flag);
}
if (m_EndLabel != null && m_EndLabel.gameObject.activeInHierarchy != flag)
{
m_EndLabel.gameObject.SetActive(flag);
}
m_StartLabel.SetActive(flag);
m_EndLabel.SetActive(flag);
}
/// <summary>
@@ -590,24 +584,24 @@ namespace XCharts.Runtime
if (m_EndLabel != null) m_EndLabel.SetText(text);
}
internal void SetStartLabel(ChartText startLabel)
internal void SetStartLabel(ChartLabel startLabel)
{
m_StartLabel = startLabel;
}
internal void SetEndLabel(ChartText endLabel)
internal void SetEndLabel(ChartLabel endLabel)
{
m_EndLabel = endLabel;
}
internal void UpdateStartLabelPosition(Vector3 pos)
{
m_StartLabel.SetLocalPosition(pos);
m_StartLabel.SetPosition(pos);
}
internal void UpdateEndLabelPosition(Vector3 pos)
{
m_EndLabel.SetLocalPosition(pos);
m_EndLabel.SetPosition(pos);
}
public void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)

View File

@@ -29,15 +29,13 @@ namespace XCharts.Runtime
dataZoomObject.hideFlags = chart.chartHideFlags;
ChartHelper.HideAllObject(dataZoomObject);
var startLabel = ChartHelper.AddTextObject(s_DefaultDataZoom + "start", dataZoomObject.transform,
Vector2.zero, Vector2.zero, new Vector2(1, 0.5f), new Vector2(200, 20), dataZoom.textStyle,
chart.theme.dataZoom);
startLabel.SetAlignment(TextAnchor.MiddleRight);
var startLabel = ChartHelper.AddChartLabel(s_DefaultDataZoom + "start", dataZoomObject.transform,
dataZoom.labelStyle, chart.theme.dataZoom, "", Color.clear, TextAnchor.MiddleRight);
startLabel.gameObject.SetActive(true);
var endLabel = ChartHelper.AddTextObject(s_DefaultDataZoom + "end", dataZoomObject.transform,
Vector2.zero, Vector2.zero, new Vector2(0, 0.5f), new Vector2(200, 20), dataZoom.textStyle,
chart.theme.dataZoom);
endLabel.SetAlignment(TextAnchor.MiddleLeft);
var endLabel = ChartHelper.AddChartLabel(s_DefaultDataZoom + "end", dataZoomObject.transform,
dataZoom.labelStyle, chart.theme.dataZoom, "", Color.clear, TextAnchor.MiddleLeft);
endLabel.gameObject.SetActive(true);
dataZoom.SetStartLabel(startLabel);
dataZoom.SetEndLabel(endLabel);

View File

@@ -9,18 +9,24 @@ namespace XCharts.Runtime
[Serializable]
public class DebugInfo
{
#pragma warning disable 0414
#pragma warning disable 0414
[SerializeField] private bool m_Show = true;
#pragma warning restore 0414
#pragma warning restore 0414
[SerializeField] private bool m_ShowDebugInfo = false;
[SerializeField] protected bool m_ShowAllChartObject = false;
[SerializeField] protected bool m_FoldSeries = false;
[SerializeField]
private TextStyle m_DebugInfoTextStyle = new TextStyle()
private LabelStyle m_LabelStyle = new LabelStyle()
{
fontSize = 18,
backgroundColor = new Color32(32, 32, 32, 170),
color = Color.white
background = new ImageStyle()
{
color = new Color32(32, 32, 32, 170)
},
textStyle = new TextStyle()
{
fontSize = 18,
color = Color.white
}
};
private static StringBuilder s_Sb = new StringBuilder();
@@ -45,7 +51,7 @@ namespace XCharts.Runtime
public void Init(BaseChart chart)
{
m_Chart = chart;
m_Label = AddDebugInfoObject("debug", chart.transform, m_DebugInfoTextStyle, chart.theme);
m_Label = AddDebugInfoObject("debug", chart.transform, m_LabelStyle, chart.theme);
}
public void Update()
@@ -124,7 +130,7 @@ namespace XCharts.Runtime
return total / list.Count;
}
private ChartLabel AddDebugInfoObject(string name, Transform parent, TextStyle textStyle,
private ChartLabel AddDebugInfoObject(string name, Transform parent, LabelStyle labelStyle,
ThemeStyle theme)
{
var anchorMax = new Vector2(0, 1);
@@ -137,16 +143,9 @@ namespace XCharts.Runtime
labelGameObject.hideFlags = m_Chart.chartHideFlags;
ChartHelper.SetActive(labelGameObject, m_ShowDebugInfo);
var label = ChartHelper.GetOrAddComponent<ChartLabel>(labelGameObject);
label.labelBackground = label;
label.labelBackground.color = textStyle.backgroundColor;
label.labelBackground.raycastTarget = false;
label.label = ChartHelper.AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme.common);
label.SetAutoSize(true);
label.label.SetAlignment(textStyle.GetAlignment(TextAnchor.UpperLeft));
label.label.SetLocalPosition(new Vector2(3, -3));
label.SetText("30");
label.SetTextColor(textStyle.color);
var label = ChartHelper.AddChartLabel("info", labelGameObject.transform, labelStyle, theme.common,
"", Color.clear, TextAnchor.UpperLeft);
label.SetActive(labelStyle.show);
return label;
}
}

View File

@@ -75,7 +75,7 @@ namespace XCharts.Runtime
[SerializeField] private bool m_ItemAutoColor = true;
[SerializeField] private bool m_TextAutoColor = false;
[SerializeField] private string m_Formatter;
[SerializeField] private TextStyle m_TextStyle = new TextStyle() { offset = new Vector2(2f, 0), fontSize = 0 };
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
[SerializeField] private List<string> m_Data = new List<string>();
[SerializeField] private List<Sprite> m_Icons = new List<Sprite>();
@@ -195,10 +195,10 @@ namespace XCharts.Runtime
/// the style of text.
/// |文本样式。
/// </summary>
public TextStyle textStyle
public LabelStyle labelStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
get { return m_LabelStyle; }
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// Data array of legend. An array item is usually a name representing string. (If it is a pie chart,
@@ -229,14 +229,14 @@ namespace XCharts.Runtime
/// </summary>
public override bool componentDirty
{
get { return m_ComponentDirty || location.componentDirty || textStyle.componentDirty; }
get { return m_ComponentDirty || location.componentDirty || labelStyle.componentDirty; }
}
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
location.ClearComponentDirty();
textStyle.ClearComponentDirty();
labelStyle.ClearComponentDirty();
}
/// <summary>

View File

@@ -21,7 +21,7 @@ namespace XCharts.Runtime
public override void CheckComponent(System.Text.StringBuilder sb)
{
var legend = component;
if (ChartHelper.IsColorAlphaZero(legend.textStyle.color))
if (ChartHelper.IsColorAlphaZero(legend.labelStyle.textStyle.color))
sb.AppendFormat("warning:legend{0}->textStyle->color alpha is 0\n", legend.index);
var serieNameList = SeriesHelper.GetLegalSerieNameList(chart.series);
if (serieNameList.Count == 0)

View File

@@ -8,7 +8,7 @@ namespace XCharts.Runtime
{
public static Color GetContentColor(int legendIndex, Legend legend, ThemeStyle theme, bool active)
{
var textStyle = legend.textStyle;
var textStyle = legend.labelStyle.textStyle;
if (active)
{
if (legend.textAutoColor) return theme.GetColor(legendIndex);
@@ -40,7 +40,7 @@ namespace XCharts.Runtime
var pivot = new Vector2(0, 0.5f);
var sizeDelta = new Vector2(100, 30);
var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
var textStyle = legend.textStyle;
var textStyle = legend.labelStyle.textStyle;
var contentColor = GetContentColor(legendIndex, legend, theme, active);
var objAnchorMin = new Vector2(0, 1);
@@ -48,16 +48,15 @@ namespace XCharts.Runtime
var objPivot = new Vector2(0, 1);
var btnObj = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta, i);
var iconObj = ChartHelper.AddObject("icon", btnObj.transform, anchorMin, anchorMax, pivot, iconSizeDelta);
var contentObj = ChartHelper.AddObject("content", btnObj.transform, anchorMin, anchorMax, pivot, sizeDelta);
var img = ChartHelper.GetOrAddComponent<Image>(btnObj);
img.color = Color.clear;
ChartHelper.GetOrAddComponent<Button>(btnObj);
ChartHelper.GetOrAddComponent<Image>(iconObj);
ChartHelper.GetOrAddComponent<Image>(contentObj);
var txt = ChartHelper.AddTextObject("Text", contentObj.transform, anchorMin, anchorMax, pivot, sizeDelta,
textStyle, theme.legend);
txt.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleLeft));
txt.SetColor(contentColor);
var label = ChartHelper.AddChartLabel("content", btnObj.transform, legend.labelStyle, theme.legend,
content, contentColor, TextAnchor.MiddleLeft);
label.SetActive(true);
var item = new LegendItem();
item.index = i;
item.name = objName;
@@ -66,9 +65,8 @@ namespace XCharts.Runtime
item.SetIconSize(legend.itemWidth, legend.itemHeight);
item.SetIconColor(itemColor);
item.SetIconImage(legend.GetIcon(i));
item.SetContentPosition(textStyle.offsetv3);
item.SetContentPosition(legend.labelStyle.offset);
item.SetContent(content);
item.SetContentBackgroundColor(textStyle.backgroundColor);
return item;
}

View File

@@ -10,7 +10,6 @@ namespace XCharts.Runtime
internal sealed class MarkAreaHandler : MainComponentHandler<MarkArea>
{
private GameObject m_MarkLineLabelRoot;
private bool m_LabelShow;
private bool m_NeedUpdateLabelPosition;
public override void InitComponent()
@@ -41,23 +40,16 @@ namespace XCharts.Runtime
private void InitMarkArea(MarkArea markArea)
{
m_LabelShow = markArea.label.show && !string.IsNullOrEmpty(component.text);
markArea.painter = chart.m_PainterTop;
markArea.refreshComponent = delegate ()
{
var label = markArea.label;
var color = !ChartHelper.IsClearColor(label.textStyle.color) ? label.textStyle.color : chart.theme.axis.textColor;
var element = ChartHelper.AddSerieLabel("label", m_MarkLineLabelRoot.transform, label.backgroundWidth,
label.backgroundHeight, color, label.textStyle, chart.theme);
var isAutoSize = label.backgroundWidth == 0 || label.backgroundHeight == 0;
var item = ChartHelper.GetOrAddComponent<ChartLabel>(element);
var label = ChartHelper.AddChartLabel("label", m_MarkLineLabelRoot.transform, markArea.label, chart.theme.axis,
component.text, Color.clear, TextAnchor.MiddleCenter);
UpdateRuntimeData(component);
item.SetLabel(element, isAutoSize, label.paddingLeftRight, label.paddingTopBottom);
item.SetIconActive(false);
item.SetActive(m_LabelShow);
item.SetPosition(component.runtimeLabelPosition);
item.SetText(component.text);
markArea.runtimeLabel = item;
label.SetActive(markArea.label.show);
label.SetPosition(component.runtimeLabelPosition);
label.SetText(component.text);
markArea.runtimeLabel = label;
};
markArea.refreshComponent();
}
@@ -96,7 +88,7 @@ namespace XCharts.Runtime
private void UpdateLabelPosition(MarkArea markArea)
{
if (!m_LabelShow) return;
if (!markArea.label.show) return;
m_NeedUpdateLabelPosition = true;
var rect = markArea.runtimeRect;
switch (markArea.label.position)
@@ -120,7 +112,7 @@ namespace XCharts.Runtime
markArea.runtimeLabelPosition = rect.center + new Vector2(0, rect.height / 2);
break;
}
markArea.runtimeLabelPosition += markArea.label.offset + markArea.label.textStyle.offsetv3;
markArea.runtimeLabelPosition += markArea.label.offset;
}
private Vector3 GetPosition(MarkAreaData data, Serie serie, DataZoom dataZoom, XAxis xAxis, YAxis yAxis,

View File

@@ -72,21 +72,16 @@ namespace XCharts.Runtime
data.painter = chart.m_PainterTop;
data.refreshComponent = delegate ()
{
var label = data.label;
var textName = string.Format("markLine_{0}_{1}", serie.index, data.index);
var color = !ChartHelper.IsClearColor(label.textStyle.color) ? label.textStyle.color : chart.theme.axis.textColor;
var element = ChartHelper.AddSerieLabel(textName, m_MarkLineLabelRoot.transform, label.backgroundWidth,
label.backgroundHeight, color, label.textStyle, chart.theme);
var isAutoSize = label.backgroundWidth == 0 || label.backgroundHeight == 0;
var backgroundColor = label.textStyle.GetBackgroundColor(chart.GetChartBackgroundColor());
var item = ChartHelper.GetOrAddComponent<ChartLabel>(element);
item.SetLabel(element, isAutoSize, label.paddingLeftRight, label.paddingTopBottom);
item.SetIconActive(false);
item.SetActive(data.label.show);
item.SetPosition(MarkLineHelper.GetLabelPosition(data));
item.SetText(MarkLineHelper.GetFormatterContent(serie, data));
item.color = backgroundColor;
data.runtimeLabel = item;
var content = MarkLineHelper.GetFormatterContent(serie, data);
var label = ChartHelper.AddChartLabel(textName, m_MarkLineLabelRoot.transform, data.label, chart.theme.axis,
content, Color.clear, TextAnchor.MiddleCenter);
label.SetActive(data.label.show);
label.SetIconActive(false);
label.SetActive(data.label.show);
label.SetPosition(MarkLineHelper.GetLabelPosition(data));
data.runtimeLabel = label;
};
data.refreshComponent();
}

View File

@@ -11,7 +11,7 @@ namespace XCharts.Runtime
var numericFormatter = serieLabel.numericFormatter;
if (serieLabel.formatterFunction != null)
{
return serieLabel.formatterFunction(data.index, data.runtimeValue);
return serieLabel.formatterFunction(data.index, data.runtimeValue, null);
}
if (string.IsNullOrEmpty(serieLabel.formatter))
return ChartCached.NumberToStr(data.runtimeValue, numericFormatter);
@@ -29,8 +29,8 @@ namespace XCharts.Runtime
if (!data.label.show) return Vector3.zero;
var dir = (data.runtimeEndPosition - data.runtimeStartPosition).normalized;
var horizontal = Mathf.Abs(Vector3.Dot(dir, Vector3.right)) == 1;
var labelWidth = data.runtimeLabel == null ? 50 : data.runtimeLabel.GetLabelWidth();
var labelHeight = data.runtimeLabel == null ? 20 : data.runtimeLabel.GetLabelHeight();
var labelWidth = data.runtimeLabel == null ? 50 : data.runtimeLabel.GetTextWidth();
var labelHeight = data.runtimeLabel == null ? 20 : data.runtimeLabel.GetTextHeight();
switch (data.label.position)
{
case LabelStyle.Position.Start:

View File

@@ -431,13 +431,13 @@ namespace XCharts.Runtime
if (string.IsNullOrEmpty(indicatorName))
return indicatorName;
if (string.IsNullOrEmpty(m_AxisName.formatter))
if (string.IsNullOrEmpty(m_AxisName.labelStyle.formatter))
{
return indicatorName;
}
else
{
var content = m_AxisName.formatter;
var content = m_AxisName.labelStyle.formatter;
FormatterHelper.ReplaceAxisLabelContent(ref content, indicatorName);
return content;
}

View File

@@ -35,7 +35,6 @@ namespace XCharts.Runtime
private void InitRadarCoord(RadarCoord radar)
{
float txtWid = 100;
float txtHig = 20;
radar.painter = chart.GetPainter(radar.index);
radar.refreshComponent = delegate ()
@@ -45,7 +44,6 @@ namespace XCharts.Runtime
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
radar.gameObject = radarObject;
radar.gameObject.hideFlags = chart.chartHideFlags;
var textStyle = radar.axisName.textStyle;
ChartHelper.HideAllObject(radarObject.transform, INDICATOR_TEXT);
for (int i = 0; i < radar.indicatorList.Count; i++)
{
@@ -53,19 +51,10 @@ namespace XCharts.Runtime
var pos = radar.GetIndicatorPosition(i);
var objName = INDICATOR_TEXT + "_" + i;
var labelGameObject = ChartHelper.AddObject(objName, radarObject.transform, new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(txtWid, txtHig));
var label = ChartHelper.GetOrAddComponent<ChartLabel>(labelGameObject);
label.label = ChartHelper.AddTextObject("Text", label.gameObject.transform, new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(txtWid, txtHig), textStyle, chart.theme.common);
label.SetAutoSize(true);
label.label.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleCenter));
label.SetText(radar.GetFormatterIndicatorContent(i));
label.SetActive(radar.indicator);
label.color = textStyle.backgroundColor;
var offset = new Vector3(textStyle.offset.x, textStyle.offset.y);
AxisHelper.AdjustCircleLabelPos(label, pos, radar.context.center, txtHig, offset);
var label = ChartHelper.AddChartLabel(objName, radarObject.transform, radar.axisName.labelStyle,
chart.theme.common, radar.GetFormatterIndicatorContent(i), Color.clear, TextAnchor.MiddleCenter);
label.SetActive(radar.indicator && radar.axisName.labelStyle.show);
AxisHelper.AdjustCircleLabelPos(label, pos, radar.context.center, txtHig, radar.axisName.labelStyle.offset);
}
chart.RefreshBasePainter();
};

View File

@@ -14,9 +14,9 @@ namespace XCharts.Runtime
{
[SerializeField] private bool m_Show = true;
[SerializeField] private string m_Text = "Chart Title";
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
[SerializeField] private string m_SubText = "";
[SerializeField] private TextStyle m_SubTextStyle = new TextStyle();
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
[SerializeField] private LabelStyle m_SubLabelStyle = new LabelStyle();
[SerializeField] private float m_ItemGap = 0;
[SerializeField] private Location m_Location = Location.defaultTop;
@@ -35,10 +35,10 @@ namespace XCharts.Runtime
/// The text style of main title.
/// |主标题文本样式。
/// </summary>
public TextStyle textStyle
public LabelStyle labelStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetComponentDirty(); }
get { return m_LabelStyle; }
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// Subtitle text, supporting for \n for newlines.
@@ -53,10 +53,10 @@ namespace XCharts.Runtime
/// The text style of sub title.
/// |副标题文本样式。
/// </summary>
public TextStyle subTextStyle
public LabelStyle subLabelStyle
{
get { return m_SubTextStyle; }
set { if (PropertyUtil.SetClass(ref m_SubTextStyle, value)) SetComponentDirty(); }
get { return m_SubLabelStyle; }
set { if (PropertyUtil.SetClass(ref m_SubLabelStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// [default:8]
@@ -85,8 +85,8 @@ namespace XCharts.Runtime
{
return m_ComponentDirty
|| location.componentDirty
|| textStyle.componentDirty
|| subTextStyle.componentDirty;
|| m_LabelStyle.componentDirty
|| m_SubLabelStyle.componentDirty;
}
}
@@ -94,8 +94,8 @@ namespace XCharts.Runtime
{
base.ClearComponentDirty();
location.ClearComponentDirty();
textStyle.ClearComponentDirty();
subTextStyle.ClearComponentDirty();
m_LabelStyle.ClearComponentDirty();
m_SubLabelStyle.ClearComponentDirty();
}
public void OnChanged()

View File

@@ -27,30 +27,23 @@ namespace XCharts.Runtime
anchorMin = title.location.runtimeAnchorMin;
anchorMax = title.location.runtimeAnchorMax;
pivot = title.location.runtimePivot;
title.textStyle.UpdateAlignmentByLocation(title.location);
title.subTextStyle.UpdateAlignmentByLocation(title.location);
var fontSize = title.textStyle.GetFontSize(chart.theme.title);
var fontSize = title.labelStyle.textStyle.GetFontSize(chart.theme.title);
ChartHelper.UpdateRectTransform(titleObject, anchorMin, anchorMax, pivot, new Vector2(chart.chartWidth, chart.chartHeight));
var titlePosition = chart.GetTitlePosition(title);
var subTitlePosition = -new Vector3(0, fontSize + title.itemGap, 0);
var titleWid = chart.chartWidth;
titleObject.transform.localPosition = titlePosition;
titleObject.hideFlags = chart.chartHideFlags;
ChartHelper.HideAllObject(titleObject);
var titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform, anchorMin, anchorMax,
pivot, new Vector2(titleWid, fontSize), title.textStyle, chart.theme.title);
titleText.SetActive(title.show);
titleText.SetLocalPosition(Vector3.zero + title.textStyle.offsetv3);
titleText.SetText(title.text);
var label = ChartHelper.AddChartLabel(s_TitleObjectName, titleObject.transform, title.labelStyle, chart.theme.title,
title.text, Color.clear, title.location.runtimeTextAlignment);
label.SetActive(title.show && title.labelStyle.show);
var subText = ChartHelper.AddTextObject(s_SubTitleObjectName, titleObject.transform, anchorMin, anchorMax,
pivot, new Vector2(titleWid, title.subTextStyle.GetFontSize(chart.theme.subTitle)), title.subTextStyle,
chart.theme.subTitle);
subText.SetActive(title.show && !string.IsNullOrEmpty(title.subText));
subText.SetLocalPosition(subTitlePosition + title.subTextStyle.offsetv3);
subText.SetText(title.subText);
var subLabel = ChartHelper.AddChartLabel(s_SubTitleObjectName, titleObject.transform, title.subLabelStyle, chart.theme.subTitle,
title.subText, Color.clear, title.location.runtimeTextAlignment);
subLabel.SetActive(title.show && title.subLabelStyle.show);
subLabel.transform.localPosition = subTitlePosition + title.subLabelStyle.offset;
};
title.refreshComponent();
}

View File

@@ -9,54 +9,8 @@ namespace XCharts.Runtime
/// |标题相关设置。
/// </summary>
[Serializable]
public class TitleStyle : ChildComponent, ISerieDataComponent, ISerieExtraComponent
public class TitleStyle : LabelStyle, ISerieDataComponent, ISerieExtraComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private Vector2 m_OffsetCenter = new Vector2(0, -0.2f);
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
/// <summary>
/// Whether to show title.
/// |是否显示标题。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// The offset position relative to the center.
/// |相对于中心的偏移位置。
/// </summary>
public Vector2 offsetCenter
{
get { return m_OffsetCenter; }
set { if (PropertyUtil.SetStruct(ref m_OffsetCenter, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of text.
/// |文本的颜色。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value, true)) SetComponentDirty(); }
}
public override bool componentDirty { get { return m_ComponentDirty || textStyle.componentDirty; } }
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
textStyle.ClearComponentDirty();
}
public Vector3 GetOffset(float radius)
{
var x = ChartHelper.GetActualValue(m_OffsetCenter.x, radius);
var y = ChartHelper.GetActualValue(m_OffsetCenter.y, radius);
return new Vector3(x, y, 0);
}
}
}

View File

@@ -91,13 +91,18 @@ namespace XCharts.Runtime
[SerializeField] private float m_ItemHeight = 25f;
[SerializeField] private Color32 m_BorderColor = new Color32(230, 230, 230, 255);
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.None);
[SerializeField] private TextStyle m_LabelTextStyle = new TextStyle();
[SerializeField] private TextStyle m_TitleTextStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft };
[SerializeField] private LabelStyle m_IndicatorLabelStyle = new LabelStyle();
[SerializeField]
private List<TextStyle> m_ColumnsTextStyle = new List<TextStyle>() {
new TextStyle() { alignment = TextAnchor.MiddleLeft, extraWidth = 5 },
new TextStyle() { alignment = TextAnchor.MiddleLeft, extraWidth = 20 },
new TextStyle() { alignment = TextAnchor.MiddleRight, extraWidth = 5 }
private LabelStyle m_TitleLabelStyle = new LabelStyle()
{
textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft }
};
[SerializeField]
private List<LabelStyle> m_ContentLabelStyles = new List<LabelStyle>()
{
new LabelStyle(){ textPadding = new TextPadding(0,5,0,0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft }},
new LabelStyle(){ textPadding = new TextPadding(0,20,0,0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft }},
new LabelStyle(){ textPadding = new TextPadding(0,0,0,0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleRight }}
};
public TooltipContext context = new TooltipContext();
@@ -305,27 +310,27 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); }
}
/// <summary>
/// the text style of content.
/// |提示框标签的文本样式。
/// the label style of tooltip axis indicator label.
/// |提示框的坐标轴指示器文本样式。
/// </summary>
public TextStyle labelTextStyle
public LabelStyle indicatorLabelStyle
{
get { return m_LabelTextStyle; }
set { if (value != null) { m_LabelTextStyle = value; SetComponentDirty(); } }
get { return m_IndicatorLabelStyle; }
set { if (value != null) { m_IndicatorLabelStyle = value; SetComponentDirty(); } }
}
/// <summary>
/// 标题的文本样式。
/// </summary>
public TextStyle titleTextStyle
public LabelStyle titleLabelStyle
{
get { return m_TitleTextStyle; }
set { if (value != null) { m_TitleTextStyle = value; SetComponentDirty(); } }
get { return m_TitleLabelStyle; }
set { if (value != null) { m_TitleLabelStyle = value; SetComponentDirty(); } }
}
public List<TextStyle> columnsTextStyle
public List<LabelStyle> contentLabelStyles
{
get { return m_ColumnsTextStyle; }
set { if (value != null) { m_ColumnsTextStyle = value; SetComponentDirty(); } }
get { return m_ContentLabelStyles; }
set { if (value != null) { m_ContentLabelStyles = value; SetComponentDirty(); } }
}
/// <summary>
@@ -343,14 +348,14 @@ namespace XCharts.Runtime
/// </summary>
public override bool componentDirty
{
get { return m_ComponentDirty || lineStyle.componentDirty || labelTextStyle.componentDirty; }
get { return m_ComponentDirty || lineStyle.componentDirty || indicatorLabelStyle.componentDirty; }
}
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
lineStyle.ClearComponentDirty();
labelTextStyle.ClearComponentDirty();
indicatorLabelStyle.ClearComponentDirty();
}
/// <summary>
/// 当前提示框所指示的Serie索引目前只对散点图有效
@@ -429,7 +434,7 @@ namespace XCharts.Runtime
{
if (view == null)
return;
view.SetActive(alwayShowContent ? true : flag);
}
@@ -492,17 +497,17 @@ namespace XCharts.Runtime
return trigger == Trigger.Axis;
}
public TextStyle GetColumnTextStyle(int index)
public LabelStyle GetContentLabelStyle(int index)
{
if (m_ColumnsTextStyle.Count == 0)
if (m_ContentLabelStyles.Count == 0)
return null;
if (index < 0)
index = 0;
else if (index > m_ColumnsTextStyle.Count - 1)
index = m_ColumnsTextStyle.Count - 1;
else if (index > m_ContentLabelStyles.Count - 1)
index = m_ContentLabelStyles.Count - 1;
return m_ColumnsTextStyle[index];
return m_ContentLabelStyles[index];
}
}
}

View File

@@ -56,7 +56,8 @@ namespace XCharts.Runtime
for (int i = 0; i < 2; i++)
{
var labelName = "label_" + i;
var item = ChartHelper.AddTooltipLabel(component, labelName, m_LabelRoot.transform, chart.theme, new Vector2(0.5f, 0.5f));
var item = ChartHelper.AddTooltipIndicatorLabel(component, labelName, m_LabelRoot.transform,
chart.theme, TextAnchor.MiddleCenter);
item.SetActive(false);
m_IndicatorLabels.Add(item);
}
@@ -71,7 +72,8 @@ namespace XCharts.Runtime
else
{
var labelName = "label_" + index;
var item = ChartHelper.AddTooltipLabel(component, labelName, m_LabelRoot.transform, chart.theme, new Vector2(0.5f, 0.5f));
var item = ChartHelper.AddTooltipIndicatorLabel(component, labelName, m_LabelRoot.transform,
chart.theme, TextAnchor.MiddleCenter);
m_IndicatorLabels.Add(item);
return item;
}
@@ -150,7 +152,7 @@ namespace XCharts.Runtime
if (axis.gridIndex == grid.index)
{
var label = GetIndicatorLabel(labelCount++);
SetTooltipIndicatorLabel(axis, label);
SetTooltipIndicatorLabel(tooltip, axis, label);
}
}
}
@@ -167,7 +169,7 @@ namespace XCharts.Runtime
if (axis.polarIndex == polar.index)
{
var label = GetIndicatorLabel(labelCount++);
SetTooltipIndicatorLabel(axis, label);
SetTooltipIndicatorLabel(tooltip, axis, label);
}
}
}
@@ -176,19 +178,22 @@ namespace XCharts.Runtime
}
}
private void SetTooltipIndicatorLabel(Axis axis, ChartLabel label)
private void SetTooltipIndicatorLabel(Tooltip tooltip, Axis axis, ChartLabel label)
{
if (label == null) return;
if (double.IsPositiveInfinity(axis.context.pointerValue)) return;
label.SetActive(true);
label.SetLabelActive(true);
label.SetTextActive(true);
label.SetPosition(axis.context.pointerLabelPosition);
if (axis.IsCategory())
label.SetText(axis.GetData((int)axis.context.pointerValue));
else
label.SetText(axis.context.pointerValue.ToString("f2"));
var textColor = axis.axisLabel.textStyle.GetColor(chart.theme.axis.textColor);
label.labelBackground.color = textColor;
if (ChartHelper.IsClearColor(tooltip.indicatorLabelStyle.background.color))
label.color = textColor;
else
label.color = tooltip.indicatorLabelStyle.background.color;
label.SetTextColor(Color.white);
}
@@ -415,7 +420,8 @@ namespace XCharts.Runtime
if (tooltip.context.data.param.Count > 0)
{
tooltip.SetActive(true);
tooltip.view.Refresh();
if (tooltip.view != null)
tooltip.view.Refresh();
TooltipHelper.LimitInRect(tooltip, chart.chartRect);
return true;
}

View File

@@ -10,7 +10,7 @@ namespace XCharts.Runtime
public class TooltipViewItem
{
public GameObject gameObject;
public List<ChartText> columns = new List<ChartText>();
public List<ChartLabel> columns = new List<ChartLabel>();
}
public class TooltipView
{
@@ -26,7 +26,7 @@ namespace XCharts.Runtime
public Image background;
public Outline border;
public VerticalLayoutGroup layout;
public ChartText title;
public ChartLabel title;
private List<TooltipViewItem> m_Items = new List<TooltipViewItem>();
private List<float> m_ColumnMaxWidth = new List<float>();
private bool m_Active = false;
@@ -89,12 +89,12 @@ namespace XCharts.Runtime
column.SetText(param.columns[j]);
if (j == 0)
column.SetColor(param.color);
column.text.SetColor(param.color);
if (j >= m_ColumnMaxWidth.Count)
m_ColumnMaxWidth.Add(0);
var columnWidth = column.GetPreferredWidth();
var columnWidth = column.GetWidth();
if (m_ColumnMaxWidth[j] < columnWidth)
m_ColumnMaxWidth[j] = columnWidth;
}
@@ -128,7 +128,7 @@ namespace XCharts.Runtime
else
{
maxWid = TotalMaxWidth();
var titleWid = title.GetPreferredWidth();
var titleWid = title.GetTextWidth();
if (maxWid < titleWid)
maxWid = titleWid;
}
@@ -139,7 +139,7 @@ namespace XCharts.Runtime
}
else
{
if (!string.IsNullOrEmpty(title.GetText()))
if (!string.IsNullOrEmpty(title.text.GetText()))
maxHig += tooltip.titleHeight;
maxHig += tooltip.itemHeight * tooltip.context.data.param.Count;
maxHig += tooltip.paddingTopBottom * 2;
@@ -159,7 +159,7 @@ namespace XCharts.Runtime
for (int j = 0; j < m_ColumnMaxWidth.Count; j++)
{
var deltaX = j == m_ColumnMaxWidth.Count - 1 ? maxWid - xPos : m_ColumnMaxWidth[j];
item.columns[j].SetSizeDelta(new Vector2(deltaX, tooltip.itemHeight));
item.columns[j].text.SetSizeDelta(new Vector2(deltaX, tooltip.itemHeight));
item.columns[j].SetRectPosition(new Vector3(xPos, 0));
xPos += m_ColumnMaxWidth[j];
}
@@ -192,7 +192,7 @@ namespace XCharts.Runtime
}
}
private ChartText GetItemColumn(TooltipViewItem item, int i)
private ChartLabel GetItemColumn(TooltipViewItem item, int i)
{
if (i < 0) i = 0;
if (i < item.columns.Count)
@@ -236,10 +236,8 @@ namespace XCharts.Runtime
tooltip.paddingTopBottom,
tooltip.paddingTopBottom);
view.title = ChartHelper.AddTextObject("title", view.gameObject.transform, anchorMin, anchorMax, v2_0_05,
new Vector2(10, tooltip.titleHeight), tooltip.titleTextStyle, theme.tooltip);
view.title.SetText("");
view.title.SetLocalPosition(new Vector2(3, -3));
view.title = ChartHelper.AddChartLabel("title", view.gameObject.transform, tooltip.titleLabelStyle, theme.tooltip,
"", Color.clear, TextAnchor.MiddleLeft);
var item = CreateViewItem(0, view.gameObject.transform, tooltip, theme.tooltip);
view.m_Items.Add(item);
@@ -261,14 +259,12 @@ namespace XCharts.Runtime
return item;
}
private static ChartText CreateViewItemColumn(int i, Transform parent, Tooltip tooltip, ComponentTheme theme)
private static ChartLabel CreateViewItemColumn(int i, Transform parent, Tooltip tooltip, ComponentTheme theme)
{
var value = ChartHelper.AddTextObject("column" + i, parent,
v2_0_05, v2_0_05, v2_0_05, new Vector2(100, tooltip.itemHeight),
tooltip.GetColumnTextStyle(i), theme);
value.SetRectPosition(new Vector3(0, 0));
value.SetText("");
return value;
var labelStyle = tooltip.GetContentLabelStyle(i);
var label = ChartHelper.AddChartLabel("column" + i, parent, labelStyle, theme,
"", Color.clear, TextAnchor.MiddleLeft);
return label;
}
}
}