增加Axis的图标、自动换行、自定义长宽的支持

This commit is contained in:
monitor1394
2021-05-24 07:17:54 +08:00
parent d92640c49b
commit 057376882d
17 changed files with 416 additions and 106 deletions

View File

@@ -34,6 +34,10 @@
## master ## master
* (2021.05.23) 增加`TextStyle``wrap`设置是否自动换行
* (2021.05.23) 增加`AxisLabel``autoAlign`设置是否让系统自动设置对齐方式
* (2021.05.23) 增加`AxisLabel``width``height`支持自定义文本的长宽
* (2021.05.23) 增加`Axis``iconStyle``icons`支持设置坐标轴标签显示图标
* (2021.05.20) 增加`Serie``Axis``insertDataToHead`参数控制数据插入头部还是尾部 * (2021.05.20) 增加`Serie``Axis``insertDataToHead`参数控制数据插入头部还是尾部
* (2021.05.18) 优化`Editor`下的图表创建 #147 * (2021.05.18) 优化`Editor`下的图表创建 #147
* (2021.05.16) 抽离`GanttChart`甘特图,通过扩展模块的方式来提供 * (2021.05.16) 抽离`GanttChart`甘特图,通过扩展模块的方式来提供

View File

@@ -84,6 +84,9 @@
* `CoordinateChart.ClearAxisData()`清除所有x轴和y轴的类目数据。 * `CoordinateChart.ClearAxisData()`清除所有x轴和y轴的类目数据。
* `CoordinateChart.AddXAxisData(string category, int xAxisIndex = 0)`:添加一个类目数据到指定的 `X` 轴。 * `CoordinateChart.AddXAxisData(string category, int xAxisIndex = 0)`:添加一个类目数据到指定的 `X` 轴。
* `CoordinateChart.AddYAxisData(string category, int yAxisIndex = 0)`:添加一个类目数据到指定的 `Y` 轴。 * `CoordinateChart.AddYAxisData(string category, int yAxisIndex = 0)`:添加一个类目数据到指定的 `Y` 轴。
* `CoordinateChart.AddXAxisIcon(Sprite icon, int xAxisIndex = 0)`:添加一个类目数据到指定的 `X` 轴。
* `CoordinateChart.AddYAxisIcon(Sprite icon, int yAxisIndex = 0)`:添加一个类目数据到指定的 `Y` 轴。。
* `CoordinateChart.IsValue()`:是否是纯数值坐标。 * `CoordinateChart.IsValue()`:是否是纯数值坐标。
* `CoordinateChart.RefreshDataZoom()`在下一帧刷新DataZoom组件。 * `CoordinateChart.RefreshDataZoom()`在下一帧刷新DataZoom组件。
* `CoordinateChart.RefreshAxisMinMaxValue()`:立即刷新数值坐标轴的最大最小值(更新坐标轴标签并触发重绘)。 * `CoordinateChart.RefreshAxisMinMaxValue()`:立即刷新数值坐标轴的最大最小值(更新坐标轴标签并触发重绘)。

View File

@@ -51,6 +51,7 @@
* [SerieSymbol 图形标记](#SerieSymbol) * [SerieSymbol 图形标记](#SerieSymbol)
* [TextLimit 文本自适应](#TextLimit) * [TextLimit 文本自适应](#TextLimit)
* [TextStyle 文本样式](#TextStyle) * [TextStyle 文本样式](#TextStyle)
* [IconStyle 图标样式](#IconStyle)
## `Theme` ## `Theme`
@@ -204,6 +205,7 @@
* `fontSize`:字体大小。 * `fontSize`:字体大小。
* `fontStyle`:字体风格。 * `fontStyle`:字体风格。
* `lineSpacing`:行间距。 * `lineSpacing`:行间距。
* `wrap`:是否自动换行。
## `Tooltip` ## `Tooltip`
@@ -399,12 +401,14 @@
* `inverse`:是否反向坐标轴。只在数值轴`Value`中有效。 * `inverse`:是否反向坐标轴。只在数值轴`Value`中有效。
* `insertDataToHead`:添加新数据时是在列表的头部还是尾部加入。 * `insertDataToHead`:添加新数据时是在列表的头部还是尾部加入。
* `data`:类目数据,在类目轴(`type: 'Category'`)中有效。 * `data`:类目数据,在类目轴(`type: 'Category'`)中有效。
* `icons`:刻度的图标,在类目轴(`type: 'Category'`)中有效。
* `axisLine`:坐标轴轴线相关配置 [AxisLine](#AxisLine)。 * `axisLine`:坐标轴轴线相关配置 [AxisLine](#AxisLine)。
* `axisName`:坐标轴名称相关配置 [AxisName](#AxisName)。 * `axisName`:坐标轴名称相关配置 [AxisName](#AxisName)。
* `axisTick`:坐标轴刻度相关配置 [AxisTick](#AxisTick)。 * `axisTick`:坐标轴刻度相关配置 [AxisTick](#AxisTick)。
* `axisLabel`:坐标轴刻度标签 [AxisLabel](#AxisLabel)。 * `axisLabel`:坐标轴刻度标签 [AxisLabel](#AxisLabel)。
* `splitLine`:坐标轴轴线坐标轴分割线 [AxisSplitLine](#SplitLine)。 * `splitLine`:坐标轴轴线坐标轴分割线 [AxisSplitLine](#SplitLine)。
* `splitArea`:坐标轴轴线坐标轴分割区域 [AxisSplitArea](#AxisSplitArea)。 * `splitArea`:坐标轴轴线坐标轴分割区域 [AxisSplitArea](#AxisSplitArea)。
* `iconStyle`:坐标轴刻度图标的样式 [IconStyle](#IconStyle)。
相关接口: 相关接口:
@@ -828,6 +832,9 @@ K线图系列。
* `numericFormatter`:标准数字格式字符串。用于将数值格式化显示为字符串。使用`Axx`的形式:`A`是格式说明符的单字符,支持`C`货币、`D`十进制、`E`指数、`F`顶点数、`G`常规、`N`数字、`P`百分比、`R`往返过程、`X`十六进制等九种。`xx`是精度说明,从`0`-`99` * `numericFormatter`:标准数字格式字符串。用于将数值格式化显示为字符串。使用`Axx`的形式:`A`是格式说明符的单字符,支持`C`货币、`D`十进制、`E`指数、`F`顶点数、`G`常规、`N`数字、`P`百分比、`R`往返过程、`X`十六进制等九种。`xx`是精度说明,从`0`-`99`
* `showAsPositiveNumber`:将负数数值显示为正数。一般和`Serie``showAsPositiveNumber`配合使用。 * `showAsPositiveNumber`:将负数数值显示为正数。一般和`Serie``showAsPositiveNumber`配合使用。
* `onZero`:刻度标签显示在`0`刻度上。 * `onZero`:刻度标签显示在`0`刻度上。
* `width`刻度标签的宽。当为0时系统自动设置。
* `height`刻度标签的高。当为0时系统自动设置。
* `autoAlign`是否让系统自动设置对齐方式。为true时系统自动选择对齐方式为false时用textStyle的对齐方式。
* `textLimit`:文本自适应 [TextLimit](#TextLimit)。只在类目轴中有效。 * `textLimit`:文本自适应 [TextLimit](#TextLimit)。只在类目轴中有效。
* `textStyle`:文本样式 [TextStyle](#TextStyle)。 * `textStyle`:文本样式 [TextStyle](#TextStyle)。
@@ -1018,6 +1025,16 @@ K线图系列。
* `interval`:显示图形标记的间隔。`0`表示显示所有标签,`1`表示隔一个隔显示一个标签,以此类推。 * `interval`:显示图形标记的间隔。`0`表示显示所有标签,`1`表示隔一个隔显示一个标签,以此类推。
* `forceShowLast`:是否强制显示最后一个图形标记。默认为 `false` * `forceShowLast`:是否强制显示最后一个图形标记。默认为 `false`
## `IconStyle`
* `show`:是否显示图标。
* `layer`:显示在上层还是在下层。
* `sprite`:图标。
* `color`:颜色。
* `width`:图标的宽。
* `height`:图标的高。
* `offset`:位置偏移。
[返回首页](https://github.com/monitor1394/unity-ugui-XCharts) [返回首页](https://github.com/monitor1394/unity-ugui-XCharts)
[XChartsAPI接口](XChartsAPI.md) [XChartsAPI接口](XChartsAPI.md)
[XCharts问答](XCharts问答.md) [XCharts问答](XCharts问答.md)

View File

@@ -54,6 +54,7 @@ __Sub component:__
* [SerieSymbol](#SerieSymbol) * [SerieSymbol](#SerieSymbol)
* [TextLimit](#TextLimit) * [TextLimit](#TextLimit)
* [TextStyle](#TextStyle) * [TextStyle](#TextStyle)
* [IconStyle](#IconStyle)
## `Theme` ## `Theme`
@@ -211,6 +212,7 @@ The component of settings related to text.
* `fontSize`: the size of text. [default: `18`]. * `fontSize`: the size of text. [default: `18`].
* `fontStyle`: the font style of text. [default: `FontStyle.Normal`]. * `fontStyle`: the font style of text. [default: `FontStyle.Normal`].
* `lineSpacing`: the space of text line. [default: `1f`]. * `lineSpacing`: the space of text line. [default: `1f`].
* `wrap`: Whether to wrap lines.
## `Tooltip` ## `Tooltip`
@@ -397,12 +399,14 @@ The x axis in cartesian(rectangular) coordinate. a grid component can place at m
* `inverse`: Whether the axis are reversed or not. Invalid in `Category` axis. * `inverse`: Whether the axis are reversed or not. Invalid in `Category` axis.
* `insertDataToHead`: Whether to add new data at the head or at the end of the list. * `insertDataToHead`: Whether to add new data at the head or at the end of the list.
* `data`: Category data, valid in the `Category` axis. * `data`: Category data, valid in the `Category` axis.
* `icons`: icon list.
* `axisLine`: the style of axis line [AxisLine](#AxisLine). * `axisLine`: the style of axis line [AxisLine](#AxisLine).
* `axisName`: the style of axis name [AxisName](#AxisName). * `axisName`: the style of axis name [AxisName](#AxisName).
* `axisTick`: the style of axis tick [AxisTick](#AxisTick). * `axisTick`: the style of axis tick [AxisTick](#AxisTick).
* `axisLabel`: the style of axis label [AxisLabel](#AxisLabel). * `axisLabel`: the style of axis label [AxisLabel](#AxisLabel).
* `splitLine`: the style of axis split line [AxisSplitLine](#SplitLine). * `splitLine`: the style of axis split line [AxisSplitLine](#SplitLine).
* `splitArea`: the style of axis split area [AxisSplitArea](#AxisSplitArea). * `splitArea`: the style of axis split area [AxisSplitArea](#AxisSplitArea).
* `iconStyle`: the style of the axis scale icon [IconStyle](#IconStyle).
## `Background` ## `Background`
@@ -722,6 +726,9 @@ K线图系列。
* `numericFormatter`: 标准数字格式字符串。用于将数值格式化显示为字符串。使用`Axx`的形式: `A`是格式说明符的单字符,支持`C`货币、`D`十进制、`E`指数、`F`顶点数、`G`常规、`N`数字、`P`百分比、`R`往返过程、`X`十六进制等九种。`xx`是精度说明,从`0`-`99` * `numericFormatter`: 标准数字格式字符串。用于将数值格式化显示为字符串。使用`Axx`的形式: `A`是格式说明符的单字符,支持`C`货币、`D`十进制、`E`指数、`F`顶点数、`G`常规、`N`数字、`P`百分比、`R`往返过程、`X`十六进制等九种。`xx`是精度说明,从`0`-`99`
* `showAsPositiveNumber`: 将负数数值显示为正数。一般和`Serie``showAsPositiveNumber`配合使用。 * `showAsPositiveNumber`: 将负数数值显示为正数。一般和`Serie``showAsPositiveNumber`配合使用。
* `onZero`: 刻度标签显示在`0`刻度上。 * `onZero`: 刻度标签显示在`0`刻度上。
* `width`刻度标签的宽。当为0时系统自动设置。
* `height`刻度标签的高。当为0时系统自动设置。
* `autoAlign`是否让系统自动设置对齐方式。为true时系统自动选择对齐方式为false时用textStyle的对齐方式。
* `textLimit`: 文本自适应 [TextLimit](#TextLimit)。只在类目轴中有效。 * `textLimit`: 文本自适应 [TextLimit](#TextLimit)。只在类目轴中有效。
* `textStyle`: The style of text [TextStyle](#TextStyle). * `textStyle`: The style of text [TextStyle](#TextStyle).
@@ -912,6 +919,16 @@ K线图系列。
* `interval`: 显示图形标记的间隔。`0`表示显示所有标签,`1`表示隔一个隔显示一个标签,以此类推。 * `interval`: 显示图形标记的间隔。`0`表示显示所有标签,`1`表示隔一个隔显示一个标签,以此类推。
* `forceShowLast`: 是否强制显示最后一个图形标记。默认为 `false` * `forceShowLast`: 是否强制显示最后一个图形标记。默认为 `false`
## `IconStyle`
* `show` : whether to show the icon.
* `Layer` : Shows on top or bottom.
* `Sprite` : Icon.
* `color` : color.
* `width` : The width of the icon.
* `height` : the height of the icon.
* `Offset` : Offset.
[返回首页](https://github.com/monitor1394/unity-ugui-XCharts) [返回首页](https://github.com/monitor1394/unity-ugui-XCharts)
[XChartsAPI接口](XChartsAPI.md) [XChartsAPI接口](XChartsAPI.md)
[XCharts问答](XCharts问答.md) [XCharts问答](XCharts问答.md)

View File

@@ -83,7 +83,8 @@ namespace XCharts
PropertyField(prop, "m_AxisLabel"); PropertyField(prop, "m_AxisLabel");
PropertyField(prop, "m_SplitLine"); PropertyField(prop, "m_SplitLine");
PropertyField(prop, "m_SplitArea"); PropertyField(prop, "m_SplitArea");
PropertyField(prop, "m_IconStyle");
PropertyListField(prop, "m_Icons", true);
if (type == Axis.AxisType.Category) if (type == Axis.AxisType.Category)
{ {
PropertyListField(prop, "m_Data", true); PropertyListField(prop, "m_Data", true);
@@ -133,13 +134,16 @@ namespace XCharts
if (MakeFoldout(prop, "m_Show")) if (MakeFoldout(prop, "m_Show"))
{ {
++EditorGUI.indentLevel; ++EditorGUI.indentLevel;
PropertyField(prop, "m_Formatter");
PropertyField(prop, "m_Inside"); PropertyField(prop, "m_Inside");
PropertyField(prop, "m_Interval"); PropertyField(prop, "m_Interval");
PropertyField(prop, "m_Margin"); PropertyField(prop, "m_Margin");
PropertyField(prop, "m_Width");
PropertyField(prop, "m_Height");
PropertyField(prop, "m_Formatter");
PropertyField(prop, "m_NumericFormatter"); PropertyField(prop, "m_NumericFormatter");
PropertyField(prop, "m_ShowAsPositiveNumber"); PropertyField(prop, "m_ShowAsPositiveNumber");
PropertyField(prop, "m_OnZero"); PropertyField(prop, "m_OnZero");
PropertyField(prop, "m_AutoAlign");
PropertyField(prop, "m_TextLimit"); PropertyField(prop, "m_TextLimit");
PropertyField(prop, "m_TextStyle"); PropertyField(prop, "m_TextStyle");
--EditorGUI.indentLevel; --EditorGUI.indentLevel;

View File

@@ -28,6 +28,7 @@ namespace XCharts
#else #else
PropertyField(prop, "m_Font"); PropertyField(prop, "m_Font");
#endif #endif
PropertyField(prop, "m_Wrap");
PropertyField(prop, "m_Rotate"); PropertyField(prop, "m_Rotate");
PropertyField(prop, "m_Offset"); PropertyField(prop, "m_Offset");
PropertyField(prop, "m_Color"); PropertyField(prop, "m_Color");

View File

@@ -100,7 +100,26 @@ namespace XCharts
/// <param name="xAxisIndex">which xAxis should category add to</param> /// <param name="xAxisIndex">which xAxis should category add to</param>
public void AddXAxisData(string category, int xAxisIndex = 0) public void AddXAxisData(string category, int xAxisIndex = 0)
{ {
m_XAxes[xAxisIndex].AddData(category); var xAxis = GetXAxis(xAxisIndex);
if (xAxis != null)
{
xAxis.AddData(category);
}
}
/// <summary>
/// Add an icon to xAxis.
/// 添加一个图标到指定的x轴。
/// </summary>
/// <param name="icon"></param>
/// <param name="xAxisIndex"></param>
public void AddXAxisIcon(Sprite icon, int xAxisIndex = 0)
{
var xAxis = GetXAxis(xAxisIndex);
if (xAxis != null)
{
xAxis.AddIcon(icon);
}
} }
/// <summary> /// <summary>
@@ -111,7 +130,26 @@ namespace XCharts
/// <param name="yAxisIndex">which yAxis should category add to</param> /// <param name="yAxisIndex">which yAxis should category add to</param>
public void AddYAxisData(string category, int yAxisIndex = 0) public void AddYAxisData(string category, int yAxisIndex = 0)
{ {
m_YAxes[yAxisIndex].AddData(category); var yAxis = GetYAxis(yAxisIndex);
if (yAxis != null)
{
yAxis.AddData(category);
}
}
/// <summary>
/// Add an icon to yAxis.
/// 添加一个图标到指定的y轴。
/// </summary>
/// <param name="icon"></param>
/// <param name="yAxisIndex"></param>
public void AddYAxisIcon(Sprite icon, int yAxisIndex = 0)
{
var yAxis = GetYAxis(yAxisIndex);
if (yAxis != null)
{
yAxis.AddIcon(icon);
}
} }
/// <summary> /// <summary>

View File

@@ -100,6 +100,8 @@ namespace XCharts
[SerializeField] protected bool m_Inverse = false; [SerializeField] protected bool m_Inverse = false;
[SerializeField] private bool m_Clockwise = true; [SerializeField] private bool m_Clockwise = true;
[SerializeField] private bool m_InsertDataToHead; [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 List<string> m_Data = new List<string>();
[SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine; [SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine;
[SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName; [SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName;
@@ -288,6 +290,14 @@ namespace XCharts
set { if (value != null) { m_Data = value; SetAllDirty(); } } set { if (value != null) { m_Data = value; SetAllDirty(); } }
} }
/// <summary> /// <summary>
/// 类目数据对应的图标。
/// </summary>
public List<Sprite> icons
{
get { return m_Icons; }
set { if (value != null) { m_Icons = value; SetAllDirty(); } }
}
/// <summary>
/// axis Line. /// axis Line.
/// 坐标轴轴线。 /// 坐标轴轴线。
/// /// </summary> /// /// </summary>
@@ -350,6 +360,14 @@ namespace XCharts
get { return m_InsertDataToHead; } get { return m_InsertDataToHead; }
set { if (PropertyUtil.SetStruct(ref m_InsertDataToHead, value)) SetAllDirty(); } 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 public override bool vertsDirty
{ {
get { return m_VertsDirty || axisLine.anyDirty || axisTick.anyDirty || splitLine.anyDirty || splitArea.anyDirty; } get { return m_VertsDirty || axisLine.anyDirty || axisTick.anyDirty || splitLine.anyDirty || splitArea.anyDirty; }
@@ -374,11 +392,7 @@ namespace XCharts
splitArea.ClearVerticesDirty(); splitArea.ClearVerticesDirty();
} }
public int index { get; internal set; } public int index { get; internal set; }
/// <summary> public List<ChartLabel> runtimeAxisLabelList { get { return m_AxisLabelList; } set { m_AxisLabelList = value; } }
/// the axis label text list.
/// 坐标轴刻度标签的Text列表。
/// </summary>
public List<ChartText> axisLabelTextList { get { return m_AxisLabelTextList; } set { m_AxisLabelTextList = value; } }
/// <summary> /// <summary>
/// the current minimun value. /// the current minimun value.
/// 当前最小值。 /// 当前最小值。
@@ -429,7 +443,7 @@ namespace XCharts
private int filterEnd; private int filterEnd;
private int filterMinShow; private int filterMinShow;
private List<string> filterData; private List<string> filterData;
private List<ChartText> m_AxisLabelTextList = new List<ChartText>(); private List<ChartLabel> m_AxisLabelList = new List<ChartLabel>();
private GameObject m_TooltipLabel; private GameObject m_TooltipLabel;
private ChartText m_TooltipLabelText; private ChartText m_TooltipLabelText;
private RectTransform m_TooltipLabelRect; private RectTransform m_TooltipLabelRect;
@@ -461,12 +475,15 @@ namespace XCharts
axis.logBase = logBase; axis.logBase = logBase;
axis.logBaseE = logBaseE; axis.logBaseE = logBaseE;
axis.ceilRate = ceilRate; axis.ceilRate = ceilRate;
axis.insertDataToHead = insertDataToHead;
axis.iconStyle = iconStyle.Clone();
axis.axisLine = axisLine.Clone(); axis.axisLine = axisLine.Clone();
axis.axisName = axisName.Clone(); axis.axisName = axisName.Clone();
axis.axisTick = axisTick.Clone(); axis.axisTick = axisTick.Clone();
axis.axisLabel = axisLabel.Clone(); axis.axisLabel = axisLabel.Clone();
axis.splitLine = splitLine.Clone(); axis.splitLine = splitLine.Clone();
axis.splitArea = splitArea.Clone(); axis.splitArea = splitArea.Clone();
axis.icons = new List<Sprite>();
axis.data = new List<string>(); axis.data = new List<string>();
ChartHelper.CopyList(axis.data, data); ChartHelper.CopyList(axis.data, data);
return axis; return axis;
@@ -487,6 +504,8 @@ namespace XCharts
logBase = axis.logBase; logBase = axis.logBase;
logBaseE = axis.logBaseE; logBaseE = axis.logBaseE;
ceilRate = axis.ceilRate; ceilRate = axis.ceilRate;
insertDataToHead = axis.insertDataToHead;
iconStyle.Copy(axis.iconStyle);
axisLine.Copy(axis.axisLine); axisLine.Copy(axis.axisLine);
axisName.Copy(axis.axisName); axisName.Copy(axis.axisName);
axisTick.Copy(axis.axisTick); axisTick.Copy(axis.axisTick);
@@ -494,6 +513,7 @@ namespace XCharts
splitLine.Copy(axis.splitLine); splitLine.Copy(axis.splitLine);
splitArea.Copy(axis.splitArea); splitArea.Copy(axis.splitArea);
ChartHelper.CopyList(data, axis.data); ChartHelper.CopyList(data, axis.data);
ChartHelper.CopyList<Sprite>(icons, axis.icons);
} }
/// <summary> /// <summary>
@@ -502,6 +522,7 @@ namespace XCharts
public void ClearData() public void ClearData()
{ {
m_Data.Clear(); m_Data.Clear();
m_Icons.Clear();
m_RuntimeData.Clear(); m_RuntimeData.Clear();
SetAllDirty(); SetAllDirty();
} }
@@ -552,6 +573,20 @@ namespace XCharts
SetAllDirty(); SetAllDirty();
} }
public void AddIcon(Sprite icon)
{
if (maxCache > 0)
{
while (m_Icons.Count > maxCache)
{
m_Icons.RemoveAt(m_InsertDataToHead ? m_Icons.Count - 1 : 0);
}
}
if (m_InsertDataToHead) m_Icons.Insert(0, icon);
else m_Icons.Add(icon);
SetAllDirty();
}
/// <summary> /// <summary>
/// 获得指定索引的类目数据 /// 获得指定索引的类目数据
/// </summary> /// </summary>
@@ -580,6 +615,14 @@ namespace XCharts
return ""; return "";
} }
public Sprite GetIcon(int index)
{
if (index >= 0 && index < m_Icons.Count)
return m_Icons[index];
else
return null;
}
/// <summary> /// <summary>
/// 获得指定区域缩放的类目数据列表 /// 获得指定区域缩放的类目数据列表
/// </summary> /// </summary>
@@ -667,12 +710,12 @@ namespace XCharts
{ {
var minValue = GetCurrMinValue(duration); var minValue = GetCurrMinValue(duration);
var maxValue = GetCurrMaxValue(duration); var maxValue = GetCurrMaxValue(duration);
for (int i = 0; i < axisLabelTextList.Count; i++) for (int i = 0; i < runtimeAxisLabelList.Count; i++)
{ {
if (axisLabelTextList[i] != null) if (runtimeAxisLabelList[i] != null)
{ {
var text = AxisHelper.GetLabelName(this, coordinateWidth, i, minValue, maxValue, dataZoom, forcePercent); var text = AxisHelper.GetLabelName(this, coordinateWidth, i, minValue, maxValue, dataZoom, forcePercent);
axisLabelTextList[i].SetText(text); runtimeAxisLabelList[i].SetText(text);
} }
} }
} }
@@ -876,7 +919,8 @@ namespace XCharts
m_Data = new List<string>() m_Data = new List<string>()
{ {
"x1","x2","x3","x4","x5" "x1","x2","x3","x4","x5"
} },
m_Icons = new List<Sprite>(5),
}; };
axis.splitLine.show = false; axis.splitLine.show = false;
axis.splitLine.lineStyle.type = LineStyle.Type.None; axis.splitLine.lineStyle.type = LineStyle.Type.None;
@@ -908,6 +952,7 @@ namespace XCharts
m_BoundaryGap = false, m_BoundaryGap = false,
m_Position = AxisPosition.Left, m_Position = AxisPosition.Left,
m_Data = new List<string>(5), m_Data = new List<string>(5),
}; };
axis.splitLine.show = true; axis.splitLine.show = true;
axis.splitLine.lineStyle.type = LineStyle.Type.None; axis.splitLine.lineStyle.type = LineStyle.Type.None;

View File

@@ -26,6 +26,9 @@ namespace XCharts
[SerializeField] private string m_NumericFormatter = ""; [SerializeField] private string m_NumericFormatter = "";
[SerializeField] private bool m_ShowAsPositiveNumber = false; [SerializeField] private bool m_ShowAsPositiveNumber = false;
[SerializeField] private bool m_OnZero = false; [SerializeField] private bool m_OnZero = false;
[SerializeField] private float m_Width = 0f;
[SerializeField] private float m_Height = 0f;
[SerializeField] private bool m_AutoAlign = true;
[SerializeField] private TextLimit m_TextLimit = new TextLimit(); [SerializeField] private TextLimit m_TextLimit = new TextLimit();
[SerializeField] private TextStyle m_TextStyle = new TextStyle(); [SerializeField] private TextStyle m_TextStyle = new TextStyle();
@@ -106,6 +109,30 @@ namespace XCharts
get { return m_OnZero; } get { return m_OnZero; }
set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetComponentDirty(); } set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetComponentDirty(); }
} }
/// <summary>
/// 文本的宽。为0时会自动匹配。
/// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetComponentDirty(); }
}
/// <summary>
/// 文本的高。为0时会自动匹配。
/// </summary>
public float height
{
get { return m_Height; }
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetComponentDirty(); }
}
/// <summary>
/// 文本是否自动选对齐方式。为false时会用TextStyle下的alignment。
/// </summary>
public bool autoAlign
{
get { return m_AutoAlign; }
set { if (PropertyUtil.SetStruct(ref m_AutoAlign, value)) SetComponentDirty(); }
}
/// <summary> /// <summary>
/// 文本限制。 /// 文本限制。
@@ -150,28 +177,34 @@ namespace XCharts
public AxisLabel Clone() public AxisLabel Clone()
{ {
var axisLable = new AxisLabel(); var axisLabel = new AxisLabel();
axisLable.show = show; axisLabel.show = show;
axisLable.formatter = formatter; axisLabel.formatter = formatter;
axisLable.interval = interval; axisLabel.interval = interval;
axisLable.inside = inside; axisLabel.inside = inside;
axisLable.margin = margin; axisLabel.margin = margin;
axisLable.numericFormatter = numericFormatter; axisLabel.numericFormatter = numericFormatter;
axisLable.textLimit = textLimit.Clone(); axisLabel.width = width;
axisLable.textStyle.Copy(textStyle); axisLabel.height = height;
return axisLable; axisLabel.autoAlign = autoAlign;
axisLabel.textLimit = textLimit.Clone();
axisLabel.textStyle.Copy(textStyle);
return axisLabel;
} }
public void Copy(AxisLabel axisLable) public void Copy(AxisLabel axisLabel)
{ {
show = axisLable.show; show = axisLabel.show;
formatter = axisLable.formatter; formatter = axisLabel.formatter;
interval = axisLable.interval; interval = axisLabel.interval;
inside = axisLable.inside; inside = axisLabel.inside;
margin = axisLable.margin; margin = axisLabel.margin;
numericFormatter = axisLable.numericFormatter; numericFormatter = axisLabel.numericFormatter;
textLimit.Copy(axisLable.textLimit); width = axisLabel.width;
textStyle.Copy(axisLable.textStyle); height = axisLabel.height;
autoAlign = axisLabel.autoAlign;
textLimit.Copy(axisLabel.textLimit);
textStyle.Copy(axisLabel.textStyle);
} }
public void SetRelatedText(ChartText txt, float labelWidth) public void SetRelatedText(ChartText txt, float labelWidth)

View File

@@ -10,9 +10,6 @@ using UnityEngine.UI;
namespace XCharts namespace XCharts
{ {
/// <summary>
/// 系列数据项的图标
/// </summary>
[System.Serializable] [System.Serializable]
public class IconStyle : SubComponent public class IconStyle : SubComponent
{ {
@@ -25,8 +22,8 @@ namespace XCharts
[SerializeField] private Layer m_Layer; [SerializeField] private Layer m_Layer;
[SerializeField] private Sprite m_Sprite; [SerializeField] private Sprite m_Sprite;
[SerializeField] private Color m_Color = Color.white; [SerializeField] private Color m_Color = Color.white;
[SerializeField] private float m_Width = 40; [SerializeField] private float m_Width = 20;
[SerializeField] private float m_Height = 40; [SerializeField] private float m_Height = 20;
[SerializeField] private Vector3 m_Offset; [SerializeField] private Vector3 m_Offset;
public void Reset() public void Reset()
@@ -35,8 +32,8 @@ namespace XCharts
m_Layer = Layer.UnderLabel; m_Layer = Layer.UnderLabel;
m_Sprite = null; m_Sprite = null;
m_Color = Color.white; m_Color = Color.white;
m_Width = 40; m_Width = 20;
m_Height = 40; m_Height = 20;
m_Offset = Vector3.zero; m_Offset = Vector3.zero;
} }
/// <summary> /// <summary>
@@ -70,6 +67,28 @@ namespace XCharts
/// </summary> /// </summary>
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } } public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
public IconStyle Clone()
{
var iconStyle = new IconStyle();
iconStyle.show = show;
iconStyle.layer = layer;
iconStyle.sprite = sprite;
iconStyle.color = color;
iconStyle.width = width;
iconStyle.height = height;
iconStyle.offset = offset;
return iconStyle;
}
public void Copy(IconStyle iconStyle)
{
show = iconStyle.show;
layer = iconStyle.layer;
sprite = iconStyle.sprite;
color = iconStyle.color;
width = iconStyle.width;
height = iconStyle.height;
offset = iconStyle.offset;
}
} }
} }

View File

@@ -22,6 +22,7 @@ namespace XCharts
{ {
[SerializeField] private Font m_Font; [SerializeField] private Font m_Font;
[SerializeField] private bool m_Wrap = true;
[SerializeField] private float m_Rotate = 0; [SerializeField] private float m_Rotate = 0;
[SerializeField] private Vector2 m_Offset = Vector2.zero; [SerializeField] private Vector2 m_Offset = Vector2.zero;
[SerializeField] private Color m_Color = Color.clear; [SerializeField] private Color m_Color = Color.clear;
@@ -119,6 +120,14 @@ namespace XCharts
set { if (PropertyUtil.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); } set { if (PropertyUtil.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); }
} }
/// <summary> /// <summary>
/// 是否自动换行。
/// </summary>
public bool wrap
{
get { return m_Wrap; }
set { if (PropertyUtil.SetStruct(ref m_Wrap, value)) SetComponentDirty(); }
}
/// <summary>
/// 对齐方式。 /// 对齐方式。
/// </summary> /// </summary>
public TextAnchor alignment public TextAnchor alignment
@@ -186,6 +195,7 @@ namespace XCharts
fontStyle = textStyle.fontStyle; fontStyle = textStyle.fontStyle;
lineSpacing = textStyle.lineSpacing; lineSpacing = textStyle.lineSpacing;
alignment = textStyle.alignment; alignment = textStyle.alignment;
wrap = textStyle.wrap;
#if dUI_TextMeshPro #if dUI_TextMeshPro
m_TMPFont = textStyle.tmpFont; m_TMPFont = textStyle.tmpFont;
m_TMPAlignment = textStyle.tmpAlignment; m_TMPAlignment = textStyle.tmpAlignment;
@@ -210,7 +220,7 @@ namespace XCharts
public int GetFontSize(ComponentTheme defaultTheme) public int GetFontSize(ComponentTheme defaultTheme)
{ {
if(fontSize == 0) return defaultTheme.fontSize; if (fontSize == 0) return defaultTheme.fontSize;
else return fontSize; else return fontSize;
} }
} }

View File

@@ -424,6 +424,28 @@ namespace XCharts
txt.SetLocalPosition(pos + offset); 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 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.SetPosition(pos + offset);
}
public static void AdjustRadiusAxisLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset) public static void AdjustRadiusAxisLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
{ {
var txtWidth = txt.GetPreferredWidth(); var txtWidth = txt.GetPreferredWidth();

View File

@@ -538,8 +538,8 @@ namespace XCharts
var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin, var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin,
graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
yAxis.gameObject = axisObj; yAxis.gameObject = axisObj;
yAxis.axisLabelTextList.Clear(); yAxis.runtimeAxisLabelList.Clear();
axisObj.SetActive(yAxis.show && yAxis.axisLabel.show); axisObj.SetActive(yAxis.show);
axisObj.hideFlags = chartHideFlags; axisObj.hideFlags = chartHideFlags;
ChartHelper.HideAllObject(axisObj); ChartHelper.HideAllObject(axisObj);
var grid = GetAxisGridOrDefault(yAxis); var grid = GetAxisGridOrDefault(yAxis);
@@ -549,34 +549,46 @@ namespace XCharts
float totalWidth = 0; float totalWidth = 0;
float eachWidth = AxisHelper.GetEachWidth(yAxis, grid.runtimeHeight, dataZoom); float eachWidth = AxisHelper.GetEachWidth(yAxis, grid.runtimeHeight, dataZoom);
float gapWidth = yAxis.boundaryGap ? eachWidth / 2 : 0; float gapWidth = yAxis.boundaryGap ? eachWidth / 2 : 0;
if (yAxis.IsCategory()) splitNumber += 1; float textWidth = yAxis.axisLabel.width > 0
? yAxis.axisLabel.width
: grid.left;
float textHeight = yAxis.axisLabel.height > 0
? yAxis.axisLabel.height
: 20f;
if (yAxis.IsCategory() && yAxis.boundaryGap)
{
splitNumber -= 1;
}
for (int i = 0; i < splitNumber; i++) for (int i = 0; i < splitNumber; i++)
{ {
ChartText txt; ChartLabel txt;
var inside = yAxis.axisLabel.inside; var inside = yAxis.axisLabel.inside;
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
var labelName = AxisHelper.GetLabelName(yAxis, grid.runtimeHeight, i, yAxis.runtimeMinValue, var labelName = AxisHelper.GetLabelName(yAxis, grid.runtimeHeight, i, yAxis.runtimeMinValue,
yAxis.runtimeMaxValue, dataZoom, isPercentStack); yAxis.runtimeMaxValue, dataZoom, isPercentStack);
if ((inside && yAxis.IsLeft()) || (!inside && yAxis.IsRight())) if ((inside && yAxis.IsLeft()) || (!inside && yAxis.IsRight()))
{ {
txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, Vector2.zero, txt = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, Vector2.zero,
Vector2.zero, new Vector2(0, 0.5f), new Vector2(grid.left, 20), axisLabelTextStyle, Vector2.zero, new Vector2(0, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis);
m_Theme.axis); if (yAxis.axisLabel.autoAlign)
txt.SetAlignment(TextAnchor.MiddleLeft); {
txt.label.SetAlignment(TextAnchor.MiddleLeft);
}
} }
else else
{ {
txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, Vector2.zero, txt = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, Vector2.zero,
Vector2.zero, new Vector2(1, 0.5f), new Vector2(grid.left, 20), axisLabelTextStyle, Vector2.zero, new Vector2(1, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis);
m_Theme.axis); if (yAxis.axisLabel.autoAlign)
txt.SetAlignment(TextAnchor.MiddleRight); {
txt.label.SetAlignment(TextAnchor.MiddleRight);
}
} }
var labelWidth = AxisHelper.GetScaleWidth(yAxis, grid.runtimeHeight, i + 1, dataZoom); var labelWidth = AxisHelper.GetScaleWidth(yAxis, grid.runtimeHeight, i + 1, dataZoom);
if (i == 0) yAxis.axisLabel.SetRelatedText(txt, labelWidth); if (i == 0) yAxis.axisLabel.SetRelatedText(txt.label, labelWidth);
txt.SetLocalPosition(GetLabelYPosition(totalWidth + gapWidth, i, yAxisIndex, yAxis)); txt.SetPosition(GetLabelYPosition(totalWidth + gapWidth, i, yAxisIndex, yAxis));
txt.SetText(labelName); txt.SetText(labelName);
txt.SetActive(yAxis.show && (yAxis.axisLabel.interval == 0 || i % (yAxis.axisLabel.interval + 1) == 0)); yAxis.runtimeAxisLabelList.Add(txt);
yAxis.axisLabelTextList.Add(txt);
totalWidth += labelWidth; totalWidth += labelWidth;
} }
if (yAxis.axisName.show) if (yAxis.axisName.show)
@@ -654,8 +666,8 @@ namespace XCharts
var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin, var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin,
graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
xAxis.gameObject = axisObj; xAxis.gameObject = axisObj;
xAxis.axisLabelTextList.Clear(); xAxis.runtimeAxisLabelList.Clear();
axisObj.SetActive(xAxis.show && xAxis.axisLabel.show); axisObj.SetActive(xAxis.show);
axisObj.hideFlags = chartHideFlags; axisObj.hideFlags = chartHideFlags;
ChartHelper.HideAllObject(axisObj); ChartHelper.HideAllObject(axisObj);
var grid = GetAxisGridOrDefault(xAxis); var grid = GetAxisGridOrDefault(xAxis);
@@ -666,22 +678,33 @@ namespace XCharts
float totalWidth = 0; float totalWidth = 0;
float eachWidth = AxisHelper.GetEachWidth(xAxis, grid.runtimeWidth, dataZoom); float eachWidth = AxisHelper.GetEachWidth(xAxis, grid.runtimeWidth, dataZoom);
float gapWidth = xAxis.boundaryGap ? eachWidth / 2 : 0; float gapWidth = xAxis.boundaryGap ? eachWidth / 2 : 0;
float textWidth = AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, 0, dataZoom); float textWidth = xAxis.axisLabel.width > 0
//if (xAxis.IsCategory() && xAxis.boundaryGap) splitNumber += 1; ? xAxis.axisLabel.width
: AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, 0, dataZoom);
float textHeight = xAxis.axisLabel.height > 0
? xAxis.axisLabel.height
: 20f;
if (xAxis.IsCategory() && xAxis.boundaryGap)
{
splitNumber -= 1;
}
for (int i = 0; i < splitNumber; i++) for (int i = 0; i < splitNumber; i++)
{ {
var labelWidth = AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, i + 1, dataZoom); var labelWidth = AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, i + 1, dataZoom);
var inside = xAxis.axisLabel.inside; var inside = xAxis.axisLabel.inside;
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
var txt = ChartHelper.AddTextObject(ChartCached.GetXAxisName(xAxisIndex, i), axisObj.transform, new Vector2(0, 1), var label = ChartHelper.AddAxisLabelObject(i, ChartCached.GetXAxisName(xAxisIndex, i), axisObj.transform,
new Vector2(0, 1), new Vector2(1, 0.5f), new Vector2(textWidth, 20), axisLabelTextStyle, theme.axis); new Vector2(0, 1), new Vector2(0, 1), new Vector2(1, 0.5f), new Vector2(textWidth, textHeight), xAxis, theme.axis);
if (i == 0) xAxis.axisLabel.SetRelatedText(txt, labelWidth);
txt.SetAlignment(TextAnchor.MiddleCenter); if (i == 0) xAxis.axisLabel.SetRelatedText(label.label, labelWidth);
txt.SetLocalPosition(GetLabelXPosition(totalWidth + textWidth / 2 + gapWidth, i, xAxisIndex, xAxis)); if (xAxis.axisLabel.autoAlign)
txt.SetText(AxisHelper.GetLabelName(xAxis, grid.runtimeWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, dataZoom, {
label.label.SetAlignment(TextAnchor.MiddleCenter);
}
label.SetPosition(GetLabelXPosition(totalWidth + textWidth / 2 + gapWidth, i, xAxisIndex, xAxis));
label.SetText(AxisHelper.GetLabelName(xAxis, grid.runtimeWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, dataZoom,
isPercentStack)); isPercentStack));
txt.SetActive(xAxis.show && (xAxis.axisLabel.interval == 0 || i % (xAxis.axisLabel.interval + 1) == 0)); xAxis.runtimeAxisLabelList.Add(label);
xAxis.axisLabelTextList.Add(txt);
totalWidth += labelWidth; totalWidth += labelWidth;
} }
if (xAxis.axisName.show) if (xAxis.axisName.show)
@@ -807,7 +830,7 @@ namespace XCharts
posX = startX - yAxis.axisLabel.margin; posX = startX - yAxis.axisLabel.margin;
} }
posX += yAxis.offset; posX += yAxis.offset;
return new Vector3(posX, grid.runtimeY + scaleWid, 0); return new Vector3(posX, grid.runtimeY + scaleWid, 0) + yAxis.axisLabel.textStyle.offsetv3;
} }
private Vector3 GetLabelXPosition(float scaleWid, int i, int xAxisIndex, XAxis xAxis) private Vector3 GetLabelXPosition(float scaleWid, int i, int xAxisIndex, XAxis xAxis)
@@ -827,7 +850,7 @@ namespace XCharts
posY = startY - xAxis.axisLabel.margin - fontSize / 2; posY = startY - xAxis.axisLabel.margin - fontSize / 2;
} }
posY += xAxis.offset; posY += xAxis.offset;
return new Vector3(grid.runtimeX + scaleWid, posY); return new Vector3(grid.runtimeX + scaleWid, posY) + xAxis.axisLabel.textStyle.offsetv3;
} }
protected virtual void CheckMinMaxValue() protected virtual void CheckMinMaxValue()

View File

@@ -19,12 +19,33 @@ namespace XCharts
private RectTransform m_LabelRect; private RectTransform m_LabelRect;
private RectTransform m_IconRect; private RectTransform m_IconRect;
private RectTransform m_ObjectRect; private RectTransform m_ObjectRect;
private Vector3 m_IconOffest;
private Image m_IconImage; private Image m_IconImage;
public GameObject gameObject { get { return m_GameObject; } } public GameObject gameObject
public Image icon { get { return m_IconImage; } } {
public ChartText label { get { return m_LabelText; } } get { return m_GameObject; }
set
{
m_GameObject = value;
m_ObjectRect = value.GetComponent<RectTransform>();
}
}
public Image icon
{
get { return m_IconImage; }
set { SetIcon(value); }
}
public ChartText label
{
get { return m_LabelText; }
set
{
m_LabelText = value;
if (value != null) m_LabelRect = m_LabelText.gameObject.GetComponent<RectTransform>();
}
}
public ChartLabel() public ChartLabel()
{ {
@@ -41,6 +62,11 @@ namespace XCharts
m_ObjectRect = labelObj.GetComponent<RectTransform>(); m_ObjectRect = labelObj.GetComponent<RectTransform>();
} }
public void SetAutoSize(bool flag)
{
m_LabelAutoSize = flag;
}
public void SetIcon(Image image) public void SetIcon(Image image)
{ {
m_IconImage = image; m_IconImage = image;
@@ -60,16 +86,17 @@ namespace XCharts
if (m_IconRect != null) m_IconRect.sizeDelta = new Vector3(width, height); if (m_IconRect != null) m_IconRect.sizeDelta = new Vector3(width, height);
} }
public void UpdateIcon(IconStyle iconStyle) public void UpdateIcon(IconStyle iconStyle, Sprite sprite = null)
{ {
if (m_IconImage == null) return; if (m_IconImage == null) return;
if (iconStyle.show) if (iconStyle.show)
{ {
ChartHelper.SetActive(m_IconImage.gameObject, true); ChartHelper.SetActive(m_IconImage.gameObject, true);
m_IconImage.sprite = iconStyle.sprite; m_IconImage.sprite = sprite == null ? iconStyle.sprite : sprite;
m_IconImage.color = iconStyle.color; m_IconImage.color = iconStyle.color;
m_IconRect.sizeDelta = new Vector2(iconStyle.width, iconStyle.height); m_IconRect.sizeDelta = new Vector2(iconStyle.width, iconStyle.height);
m_IconImage.transform.localPosition = iconStyle.offset; m_IconOffest = iconStyle.offset;
AdjustIconPos();
if (iconStyle.layer == IconStyle.Layer.UnderLabel) if (iconStyle.layer == IconStyle.Layer.UnderLabel)
m_IconRect.SetSiblingIndex(0); m_IconRect.SetSiblingIndex(0);
else else
@@ -144,12 +171,40 @@ namespace XCharts
if (sizeChange) if (sizeChange)
{ {
m_LabelRect.sizeDelta = newSize; m_LabelRect.sizeDelta = newSize;
m_ObjectRect.sizeDelta = newSize; AdjustIconPos();
} }
return sizeChange; return sizeChange;
} }
AdjustIconPos();
} }
return false; return false;
} }
private void AdjustIconPos()
{
if (m_IconImage && m_IconImage.sprite != null && m_IconRect)
{
var iconX = 0f;
switch (m_LabelText.text.alignment)
{
case TextAnchor.LowerLeft:
case TextAnchor.UpperLeft:
case TextAnchor.MiddleLeft:
iconX = -m_ObjectRect.sizeDelta.x / 2 - m_IconRect.sizeDelta.x / 2;
break;
case TextAnchor.LowerRight:
case TextAnchor.UpperRight:
case TextAnchor.MiddleRight:
iconX = m_ObjectRect.sizeDelta.x / 2 - m_LabelText.GetPreferredWidth() - m_IconRect.sizeDelta.x / 2;
break;
case TextAnchor.LowerCenter:
case TextAnchor.UpperCenter:
case TextAnchor.MiddleCenter:
iconX = -m_LabelText.GetPreferredWidth() / 2 - m_IconRect.sizeDelta.x / 2;
break;
}
m_IconRect.anchoredPosition = m_IconOffest + new Vector3(iconX, 0);
}
}
} }
} }

View File

@@ -5,7 +5,6 @@
/* */ /* */
/************************************************/ /************************************************/
using System;
using UnityEngine; using UnityEngine;
namespace XCharts namespace XCharts

View File

@@ -247,13 +247,13 @@ namespace XCharts
chartText.tmpText.alignment = textStyle.tmpAlignment; chartText.tmpText.alignment = textStyle.tmpAlignment;
chartText.tmpText.richText = true; chartText.tmpText.richText = true;
chartText.tmpText.raycastTarget = false; chartText.tmpText.raycastTarget = false;
chartText.tmpText.enableWordWrapping = false; chartText.tmpText.enableWordWrapping = textStyle.wrap;
#else #else
chartText.text = GetOrAddComponent<Text>(txtObj); chartText.text = GetOrAddComponent<Text>(txtObj);
chartText.text.font = textStyle.font == null ? theme.font : textStyle.font; chartText.text.font = textStyle.font == null ? theme.font : textStyle.font;
chartText.text.fontStyle = textStyle.fontStyle; chartText.text.fontStyle = textStyle.fontStyle;
chartText.text.alignment = textStyle.alignment; chartText.text.alignment = textStyle.alignment;
chartText.text.horizontalOverflow = HorizontalWrapMode.Overflow; chartText.text.horizontalOverflow = textStyle.wrap ? HorizontalWrapMode.Wrap : HorizontalWrapMode.Overflow;
chartText.text.verticalOverflow = VerticalWrapMode.Overflow; chartText.text.verticalOverflow = VerticalWrapMode.Overflow;
chartText.text.supportRichText = true; chartText.text.supportRichText = true;
chartText.text.raycastTarget = false; chartText.text.raycastTarget = false;
@@ -387,7 +387,7 @@ namespace XCharts
return ChartHelper.GetOrAddComponent<Painter>(painterObj); return ChartHelper.GetOrAddComponent<Painter>(painterObj);
} }
public static GameObject AddIcon(string name, Transform parent, float width, float height) public static Image AddIcon(string name, Transform parent, float width, float height)
{ {
var anchorMax = new Vector2(0.5f, 0.5f); var anchorMax = new Vector2(0.5f, 0.5f);
var anchorMin = new Vector2(0.5f, 0.5f); var anchorMin = new Vector2(0.5f, 0.5f);
@@ -396,7 +396,29 @@ namespace XCharts
GameObject iconObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); GameObject iconObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
var img = GetOrAddComponent<Image>(iconObj); var img = GetOrAddComponent<Image>(iconObj);
img.raycastTarget = false; img.raycastTarget = false;
return iconObj; return img;
}
public static ChartLabel AddAxisLabelObject(int index, string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax,
Vector2 pivot, Vector2 sizeDelta, Axis axis, ComponentTheme theme)
{
var textStyle = axis.axisLabel.textStyle;
var iconStyle = axis.iconStyle;
var label = new ChartLabel();
label.gameObject = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
// TODO: 为了兼容旧版本,这里后面版本可以去掉
var oldText = label.gameObject.GetComponent<Text>();
if (oldText != null)
{
GameObject.DestroyImmediate(oldText);
}
label.label = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme);
label.icon = ChartHelper.AddIcon("Icon", label.gameObject.transform, iconStyle.width, iconStyle.height);
label.SetAutoSize(false);
label.UpdateIcon(iconStyle, axis.GetIcon(index));
label.label.SetActive(axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0));
return label;
} }
internal static GameObject AddSerieLabel(string name, Transform parent, float width, float height, internal static GameObject AddSerieLabel(string name, Transform parent, float width, float height,

View File

@@ -46,6 +46,7 @@ namespace XCharts
m_Polars.Clear(); m_Polars.Clear();
m_RadiusAxes.Clear(); m_RadiusAxes.Clear();
m_AngleAxes.Clear(); m_AngleAxes.Clear();
InitComponent();
title.text = "PolarChart"; title.text = "PolarChart";
tooltip.type = Tooltip.Type.Corss; tooltip.type = Tooltip.Type.Corss;
RemoveData(); RemoveData();
@@ -121,7 +122,7 @@ namespace XCharts
var m_AngleAxis = GetAngleAxis(m_Polar.index); var m_AngleAxis = GetAngleAxis(m_Polar.index);
if (m_AngleAxis == null) return; if (m_AngleAxis == null) return;
PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight); PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight);
axis.axisLabelTextList.Clear(); axis.runtimeAxisLabelList.Clear();
var radius = m_Polar.runtimeRadius; var radius = m_Polar.runtimeRadius;
var objName = "axis_radius" + axis.index; var objName = "axis_radius" + axis.index;
var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin, var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin,
@@ -144,21 +145,18 @@ namespace XCharts
{ {
float labelWidth = AxisHelper.GetScaleWidth(axis, radius, i, null); float labelWidth = AxisHelper.GetScaleWidth(axis, radius, i, null);
bool inside = axis.axisLabel.inside; bool inside = axis.axisLabel.inside;
var txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, new Vector2(0.5f, 0.5f), var label = ChartHelper.AddAxisLabelObject(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), textStyle, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(labelWidth, txtHig), axis, theme.axis);
m_Theme.axis); if (i == 0) axis.axisLabel.SetRelatedText(label.label, labelWidth);
if (i == 0) axis.axisLabel.SetRelatedText(txt, labelWidth);
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue, var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue,
null, isPercentStack); null, isPercentStack);
txt.SetAlignment(TextAnchor.MiddleCenter); label.label.SetAlignment(TextAnchor.MiddleCenter);
txt.SetText(labelName); label.SetText(labelName);
txt.SetActive(axis.show &&
(axis.axisLabel.interval == 0 || i % (axis.axisLabel.interval + 1) == 0));
var pos = ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVetor; var pos = ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVetor;
txt.SetLocalPosition(pos); label.SetPosition(pos);
AxisHelper.AdjustRadiusAxisLabelPos(txt, pos, cenPos, txtHig, Vector3.zero); AxisHelper.AdjustRadiusAxisLabelPos(label.label, pos, cenPos, txtHig, Vector3.zero);
axis.axisLabelTextList.Add(txt); axis.runtimeAxisLabelList.Add(label);
totalWidth += labelWidth; totalWidth += labelWidth;
} }
@@ -207,13 +205,13 @@ namespace XCharts
if (m_Polars == null) return; if (m_Polars == null) return;
PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight); PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight);
var radius = m_Polar.runtimeRadius; var radius = m_Polar.runtimeRadius;
axis.axisLabelTextList.Clear(); axis.runtimeAxisLabelList.Clear();
string objName = "axis_angle" + axis.index; string objName = "axis_angle" + axis.index;
var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin, var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin,
graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
axisObj.transform.localPosition = Vector3.zero; axisObj.transform.localPosition = Vector3.zero;
axisObj.SetActive(axis.show && axis.axisLabel.show); axisObj.SetActive(axis.show);
axisObj.hideFlags = chartHideFlags; axisObj.hideFlags = chartHideFlags;
ChartHelper.HideAllObject(axisObj); ChartHelper.HideAllObject(axisObj);
var splitNumber = AxisHelper.GetSplitNumber(axis, radius, null); var splitNumber = AxisHelper.GetSplitNumber(axis, radius, null);
@@ -228,18 +226,18 @@ namespace XCharts
{ {
float scaleAngle = AxisHelper.GetScaleWidth(axis, total, i, null); float scaleAngle = AxisHelper.GetScaleWidth(axis, total, i, null);
bool inside = axis.axisLabel.inside; bool inside = axis.axisLabel.inside;
var txt = ChartHelper.AddTextObject(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), var label = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
axis.axisLabel.textStyle, m_Theme.axis); new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(scaleAngle, txtHig), axis, theme.axis);
txt.SetAlignment(TextAnchor.MiddleCenter);
txt.SetText(AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue, label.label.SetAlignment(TextAnchor.MiddleCenter);
label.SetText(AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue,
null, isPercentStack)); null, isPercentStack));
txt.SetActive(axis.show && (axis.axisLabel.interval == 0 || i % (axis.axisLabel.interval + 1) == 0));
var pos = ChartHelper.GetPos(cenPos, radius + margin, var pos = ChartHelper.GetPos(cenPos, radius + margin,
isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true); isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true);
AxisHelper.AdjustCircleLabelPos(txt, pos, cenPos, txtHig, Vector3.zero); AxisHelper.AdjustCircleLabelPos(label, pos, cenPos, txtHig, Vector3.zero);
if (i == 0) axis.axisLabel.SetRelatedText(txt, scaleAngle); if (i == 0) axis.axisLabel.SetRelatedText(label.label, scaleAngle);
axis.axisLabelTextList.Add(txt); axis.runtimeAxisLabelList.Add(label);
totalAngle += scaleAngle; totalAngle += scaleAngle;
} }