This commit is contained in:
monitor1394
2020-03-02 18:00:05 +08:00
44 changed files with 1302 additions and 527 deletions

View File

@@ -1,6 +1,12 @@
# 更新日志 # 更新日志
* (2020.02.26) 重构`Legend`图例,改变样式,增加自定义图标等设置
* (2020.02.23) 增加`BaseChart.AnimationFadeOut()`渐出动画,重构动画系统
* (2020.02.13) 增加`BaseChart.RefreshTooltip()`接口立即重新初始化`Tooltip`组件
* (2020.02.13) 增加`Tooltip``textStyle`参数配置内容文本样式,去掉`fontSize``fontStyle`参数
* (2020.02.13) 增加`TextStyle``lineSpacing`参数配置行间距
* (2020.02.11) 增加`Radar``splitLine`参数配置分割线,去掉`lineStyle`参数
* (2020.02.11) 增加`Tooltip``backgroundImage`参数配置背景图 * (2020.02.11) 增加`Tooltip``backgroundImage`参数配置背景图
* (2020.02.11) 增加`Tooltip``paddingLeftRight``paddingTopBottom`参数配置文字和边框的间距 * (2020.02.11) 增加`Tooltip``paddingLeftRight``paddingTopBottom`参数配置文字和边框的间距
* (2020.02.11) 增加`Tooltip``lineStyle`参数配置指示线样式 * (2020.02.11) 增加`Tooltip``lineStyle`参数配置指示线样式
@@ -28,7 +34,7 @@
* (2019.12.06) 修复数据过小时`AxisLabel`直接科学计数法显示的问题 * (2019.12.06) 修复数据过小时`AxisLabel`直接科学计数法显示的问题
* (2019.12.04) 优化和完善数据更新`UpdateData`接口 * (2019.12.04) 优化和完善数据更新`UpdateData`接口
* (2019.12.03) 增加圆环饼图的圆角支持,参数:`serie.arcShaped` * (2019.12.03) 增加圆环饼图的圆角支持,参数:`serie.arcShaped`
* (2019.12.03) 增加数据更新动画,参数:`serie.animation.updateAnimation` * (2019.12.03) 增加数据更新动画,参数:`serie.animation.dataChangeEnable`
* (2019.11.30) 增加`GaugeChart`仪表盘 * (2019.11.30) 增加`GaugeChart`仪表盘
* (2019.11.22) 修复`BarChart`清空数据重新赋值后`SerieLabel`显示异常的问题 * (2019.11.22) 修复`BarChart`清空数据重新赋值后`SerieLabel`显示异常的问题
* (2019.11.16) 修复`SerieLabel`设置`color`等参数不生效的问题 * (2019.11.16) 修复`SerieLabel`设置`color`等参数不生效的问题

View File

@@ -27,7 +27,7 @@ namespace XCharts
{ {
updateTime = 0; updateTime = 0;
var serie = chart.series.GetSerie(0); var serie = chart.series.GetSerie(0);
//serie.animation.updateAnimation = true; //serie.animation.dataChangeEnable = true;
var dataCount = serie.dataCount; var dataCount = serie.dataCount;
if (chart is RadarChart) if (chart is RadarChart)
{ {

View File

@@ -37,7 +37,7 @@ namespace XCharts
serie.center[1] = 0.5f; serie.center[1] = 0.5f;
serie.radius[0] = 80; serie.radius[0] = 80;
serie.splitNumber = 5; serie.splitNumber = 5;
serie.animation.updateAnimation = true; serie.animation.dataChangeEnable = true;
serie.arcShaped = true; serie.arcShaped = true;
serie.titleStyle.show = true; serie.titleStyle.show = true;

View File

@@ -28,7 +28,7 @@ namespace XCharts
{ {
updateTime = 0; updateTime = 0;
var serie = chart.series.GetSerie(0); var serie = chart.series.GetSerie(0);
serie.animation.updateAnimation = true; serie.animation.dataChangeEnable = true;
var dataCount = serie.dataCount; var dataCount = serie.dataCount;
if (chart is HeatmapChart) if (chart is HeatmapChart)
{ {

View File

@@ -40,11 +40,14 @@
* `BaseChart.IsActiveByLegend(string legendName)`:获得指定图例名字的系列是否显示。 * `BaseChart.IsActiveByLegend(string legendName)`:获得指定图例名字的系列是否显示。
* `BaseChart.RefreshChart()`:在下一帧刷新图表。 * `BaseChart.RefreshChart()`:在下一帧刷新图表。
* `BaseChart.RefreshLabel()`:在下一帧刷新文本标签。 * `BaseChart.RefreshLabel()`:在下一帧刷新文本标签。
* `BaseChart.RefreshTooltip()`:立即刷新`Tooltip`组件。
* `BaseChart.UpdateTheme(Theme theme)`:切换图表主题。 * `BaseChart.UpdateTheme(Theme theme)`:切换图表主题。
* `BaseChart.AnimationEnable(bool flag)`:启用或关闭起始动画。 * `BaseChart.AnimationEnable(bool flag)`:启用或关闭动画。
* `BaseChart.AnimationStart()`开始初始动画。 * `BaseChart.AnimationFadeIn()`渐入动画。
* `BaseChart.AnimationStop()`:停止初始化动画。 * `BaseChart.AnimationFadeOut()`:渐出动画。
* `BaseChart.AnimationReset()`重置初始动画,重新播放 * `BaseChart.AnimationPause()`暂停动画
* `BaseChart.AnimationResume()`:继续动画。
* `BaseChart.AnimationReset()`:重置动画。
* `BaseChart.ClickLegendButton(int legendIndex, string legendName, bool show)`:点击图例按钮。 * `BaseChart.ClickLegendButton(int legendIndex, string legendName, bool show)`:点击图例按钮。
## `CoordinateChart` ## `CoordinateChart`

View File

@@ -31,6 +31,7 @@
* [AxisLabel 坐标轴刻度标签](#AxisLabel) * [AxisLabel 坐标轴刻度标签](#AxisLabel)
* [AxisLine 坐标轴轴线](#AxisLine) * [AxisLine 坐标轴轴线](#AxisLine)
* [AxisName 坐标轴名称](#AxisName) * [AxisName 坐标轴名称](#AxisName)
* [AxisSplitLine 坐标轴分割线条](#AxisSplitLine)
* [AxisSplitArea 坐标轴分割区域](#AxisSplitArea) * [AxisSplitArea 坐标轴分割区域](#AxisSplitArea)
* [AxisTick 坐标轴刻度](#AxisTick) * [AxisTick 坐标轴刻度](#AxisTick)
* [Emphasis 高亮样式](#Emphasis) * [Emphasis 高亮样式](#Emphasis)
@@ -117,12 +118,14 @@
* `Horizonal`:水平。 * `Horizonal`:水平。
* `Vertical`:垂直。 * `Vertical`:垂直。
* `location`:图例的显示位置 [Location](#Location)。 * `location`:图例的显示位置 [Location](#Location)。
* `itemWidth`每个图例项的宽度。 * `itemWidth`图例标记的图形宽度。
* `itemHeight`每个图例项的高度。 * `itemHeight`图例标记的图形高度。
* `itemGap`:图例每项之间的间隔。横向布局时为水平间隔,纵向布局时为纵向间隔。 * `itemGap`:图例每项之间的间隔。横向布局时为水平间隔,纵向布局时为纵向间隔。
* `itemFontSize`:图例项的字体大小 * `itemAutoColor`:图例标记的图形是否自动匹配颜色
* `formatter`:图例内容字符串模版格式器。支持用 `\n` 换行。模板变量为图例名称 `{name}` * `formatter`:图例内容字符串模版格式器。支持用 `\n` 换行。模板变量为图例名称 `{name}`
* `data`:图例的数据数组。数组项通常为一个字符串,每一项代表一个系列的 `name`(如果是饼图,也可以是饼图单个数据的 `name`)。如果 `data` 没有被指定,会自动从当前系列中获取。指定 `data` 时里面的数据项和 `serie` 匹配时才会生效。 * `data`:图例的数据数组。数组项通常为一个字符串,每一项代表一个系列的 `name`(如果是饼图,也可以是饼图单个数据的 `name`)。如果 `data` 没有被指定,会自动从当前系列中获取。指定 `data` 时里面的数据项和 `serie` 匹配时才会生效。
* `icons`:自定义的图例标记图形。
* `textStyle`:图例的内容文本样式 [TextStyle](#TextStyle)。
相关接口: 相关接口:
@@ -143,7 +146,7 @@
* `Between`:显示在顶点之间。 * `Between`:显示在顶点之间。
* `radius`:雷达图的半径。 * `radius`:雷达图的半径。
* `center`雷达图的中心点。数组的第一项是横坐标第二项是纵坐标。当值为0-1之间时表示百分比设置成百分比时第一项是相对于容器宽度第二项是相对于容器高度。 * `center`雷达图的中心点。数组的第一项是横坐标第二项是纵坐标。当值为0-1之间时表示百分比设置成百分比时第一项是相对于容器宽度第二项是相对于容器高度。
* `lineStyle`:线条样式 [LineStyle](#LineStyle)。 * `splitLine`:分割线条 [AxisSplitLine](#AxisSplitLine)。
* `splitArea`:分割区域 [AxisSplitArea](#AxisSplitArea)。 * `splitArea`:分割区域 [AxisSplitArea](#AxisSplitArea)。
* `indicator`:是否显示指示器。 * `indicator`:是否显示指示器。
* `indicatorGap`:指示器和雷达的间距。 * `indicatorGap`:指示器和雷达的间距。
@@ -168,8 +171,11 @@
* `rotate`:旋转。 * `rotate`:旋转。
* `offset`:偏移。 * `offset`:偏移。
* `color`:颜色。 * `color`:颜色。
* `backgroundColor`:背景颜色。
* `font`:字体。
* `fontSize`:字体大小。 * `fontSize`:字体大小。
* `fontStyle`:字体风格。 * `fontStyle`:字体风格。
* `lineSpacing`:行间距。
## `Tooltip` ## `Tooltip`
@@ -196,11 +202,10 @@
* `minHeight`:最小高度。当同时设置 f`ixedHeight``minHeight` 时,`fixedHeight``minHeight` 优先级高。 * `minHeight`:最小高度。当同时设置 f`ixedHeight``minHeight` 时,`fixedHeight``minHeight` 优先级高。
* `paddingLeftRight`:文字和边框的左右边距。 * `paddingLeftRight`:文字和边框的左右边距。
* `paddingTopBottom`:文字和边框的上下边距。 * `paddingTopBottom`:文字和边框的上下边距。
* `fontSize`:文字的字体大小。
* `fontStyle`:文字的字体风格。
* `backgroundImage`:提示框的背景图。 * `backgroundImage`:提示框的背景图。
* `forceENotation`是否强制使用科学计数法格式化显示数值。默认为false当小数精度大于3时才采用科学计数法。 * `forceENotation`是否强制使用科学计数法格式化显示数值。默认为false当小数精度大于3时才采用科学计数法。
* `lineStyle`:指示器线条样式 [LineStyle](#LineStyle)。 * `lineStyle`:指示器线条样式 [LineStyle](#LineStyle)。
* `textStyle`:显示内容文本样式 [TextStyle](#TextStyle)。
## `DataZoom` ## `DataZoom`
@@ -539,6 +544,7 @@
* `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。 * `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。
* `radarIndex`:雷达图所使用的 `radar` 组件的 `index` * `radarIndex`:雷达图所使用的 `radar` 组件的 `index`
* `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。 * `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。
* `lineStyle`:线条样式 [LineStyle](#LineStyle)。
* `animation`:起始动画 [SerieAnimation](#SerieAnimation)。 * `animation`:起始动画 [SerieAnimation](#SerieAnimation)。
* `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。 * `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1``n`维数据。
@@ -606,14 +612,13 @@
## `SerieAnimation` ## `SerieAnimation`
* `enable`:是否开起始画效果 * `enable`:是否开启动画系统
* `easing`:动画的缓动效果。支持以下动画效果: * ~~`threshold`:是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画。~~
* `Linear`:线性效果 * `fadeInDelay`:设定的渐入动画延时,单位毫秒
* `duration`:设定的动画时长,单位毫秒。 * `fadeInDuration`:设定的渐入动画时长,单位毫秒。
* `updateAnimation`:是否开启数据变更动画 * `fadeOutDuration`:设定的渐出动画时长,单位毫秒
* `updateDuration`:数据变更动画时长,单位毫秒 * `dataChangeEnable`:是否开启数据变更动画
* `threshold`:是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画 * `dataChangeDuration`:数据变更动画时长,单位毫秒
* `delay`:动画延时,单位毫秒。
## `AreaStyle` ## `AreaStyle`
@@ -714,7 +719,7 @@
## `LineStyle` ## `LineStyle`
* `show`:是否显示线条。在折线图中无效。 * `show`:是否显示线条。当作为子组件,它的父组件有参数控制是否显示时,改参数无效。
* `type`:线条类型。支持以下五种类型: * `type`:线条类型。支持以下五种类型:
* `None`:不显示分割线。 * `None`:不显示分割线。
* `Solid`:实线。 * `Solid`:实线。

View File

@@ -22,11 +22,12 @@ namespace XCharts
drawRect.height = EditorGUIUtility.singleLineHeight; drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty m_Enable = prop.FindPropertyRelative("m_Enable"); SerializedProperty m_Enable = prop.FindPropertyRelative("m_Enable");
SerializedProperty m_Easting = prop.FindPropertyRelative("m_Easting"); //SerializedProperty m_Easting = prop.FindPropertyRelative("m_Easting");
SerializedProperty m_Duration = prop.FindPropertyRelative("m_Duration"); SerializedProperty m_FadeInDuration = prop.FindPropertyRelative("m_FadeInDuration");
SerializedProperty m_UpdateAnimation = prop.FindPropertyRelative("m_UpdateAnimation"); SerializedProperty m_FadeOutDuration = prop.FindPropertyRelative("m_FadeOutDuration");
SerializedProperty m_UpdateDuration = prop.FindPropertyRelative("m_UpdateDuration"); SerializedProperty m_DataChangeEnable = prop.FindPropertyRelative("m_DataChangeEnable");
SerializedProperty m_Delay = prop.FindPropertyRelative("m_Delay"); SerializedProperty m_DataChangeDuration = prop.FindPropertyRelative("m_DataChangeDuration");
SerializedProperty m_FadeInDelay = prop.FindPropertyRelative("m_FadeInDelay");
SerializedProperty m_Threshold = prop.FindPropertyRelative("m_Threshold"); SerializedProperty m_Threshold = prop.FindPropertyRelative("m_Threshold");
SerializedProperty m_ActualDuration = prop.FindPropertyRelative("m_ActualDuration"); SerializedProperty m_ActualDuration = prop.FindPropertyRelative("m_ActualDuration");
// SerializedProperty m_CurrDetailProgress = prop.FindPropertyRelative("m_CurrDetailProgress"); // SerializedProperty m_CurrDetailProgress = prop.FindPropertyRelative("m_CurrDetailProgress");
@@ -37,23 +38,26 @@ namespace XCharts
if (ChartEditorHelper.IsToggle(m_AnimationModuleToggle, prop)) if (ChartEditorHelper.IsToggle(m_AnimationModuleToggle, prop))
{ {
++EditorGUI.indentLevel; ++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Easting); //EditorGUI.PropertyField(drawRect, m_Easting);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; //drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Threshold); EditorGUI.PropertyField(drawRect, m_Threshold);
if (m_Threshold.intValue < 0) m_Threshold.intValue = 0; if (m_Threshold.intValue < 0) m_Threshold.intValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Delay); EditorGUI.PropertyField(drawRect, m_FadeInDelay);
if (m_Delay.floatValue < 0) m_Delay.floatValue = 0; if (m_FadeInDelay.floatValue < 0) m_FadeInDelay.floatValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Duration); EditorGUI.PropertyField(drawRect, m_FadeInDuration);
if (m_Duration.floatValue < 0) m_Duration.floatValue = 0; if (m_FadeInDuration.floatValue < 0) m_FadeInDuration.floatValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_UpdateAnimation); EditorGUI.PropertyField(drawRect, m_FadeOutDuration);
if (m_FadeOutDuration.floatValue < 0) m_FadeOutDuration.floatValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_UpdateDuration); EditorGUI.PropertyField(drawRect, m_DataChangeEnable);
if (m_UpdateDuration.floatValue < 0) m_UpdateDuration.floatValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_DataChangeDuration);
if (m_DataChangeDuration.floatValue < 0) m_DataChangeDuration.floatValue = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// EditorGUI.LabelField(drawRect, "CurrDetailProgress:" + m_CurrDetailProgress.floatValue); // EditorGUI.LabelField(drawRect, "CurrDetailProgress:" + m_CurrDetailProgress.floatValue);
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// EditorGUI.LabelField(drawRect, "DestDetailProgress:" + m_DestDetailProgress.floatValue); // EditorGUI.LabelField(drawRect, "DestDetailProgress:" + m_DestDetailProgress.floatValue);

View File

@@ -14,7 +14,9 @@ namespace XCharts
public class LegendDrawer : PropertyDrawer public class LegendDrawer : PropertyDrawer
{ {
private bool m_DataFoldout = false; private bool m_DataFoldout = false;
private bool m_IconsFoldout = false;
private int m_DataSize = 0; private int m_DataSize = 0;
private int m_IconsSize = 0;
private bool m_ShowJsonDataArea = false; private bool m_ShowJsonDataArea = false;
private string m_JsonDataAreaText; private string m_JsonDataAreaText;
private bool m_LegendModuleToggle = false; private bool m_LegendModuleToggle = false;
@@ -30,9 +32,11 @@ namespace XCharts
SerializedProperty itemWidth = prop.FindPropertyRelative("m_ItemWidth"); SerializedProperty itemWidth = prop.FindPropertyRelative("m_ItemWidth");
SerializedProperty itemHeight = prop.FindPropertyRelative("m_ItemHeight"); SerializedProperty itemHeight = prop.FindPropertyRelative("m_ItemHeight");
SerializedProperty itemGap = prop.FindPropertyRelative("m_ItemGap"); SerializedProperty itemGap = prop.FindPropertyRelative("m_ItemGap");
SerializedProperty itemFontSize = prop.FindPropertyRelative("m_ItemFontSize"); SerializedProperty m_ItemAutoColor = prop.FindPropertyRelative("m_ItemAutoColor");
SerializedProperty m_Formatter = prop.FindPropertyRelative("m_Formatter"); SerializedProperty m_Formatter = prop.FindPropertyRelative("m_Formatter");
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data"); SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
SerializedProperty m_Icons = prop.FindPropertyRelative("m_Icons");
SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_LegendModuleToggle, "Legend", show); ChartEditorHelper.MakeFoldout(ref drawRect, ref m_LegendModuleToggle, "Legend", show);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -45,7 +49,7 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, itemGap); EditorGUI.PropertyField(drawRect, itemGap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, itemFontSize); EditorGUI.PropertyField(drawRect, m_ItemAutoColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SelectedMode); EditorGUI.PropertyField(drawRect, m_SelectedMode);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -57,12 +61,20 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.width = EditorGUIUtility.labelWidth + 10; drawRect.width = EditorGUIUtility.labelWidth + 10;
m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Data"); m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Data");
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop,pos.width); ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop, pos.width);
drawRect.width = pos.width; drawRect.width = pos.width;
if (m_DataFoldout) if (m_DataFoldout)
{ {
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Data); ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Data);
} }
m_IconsFoldout = EditorGUI.Foldout(drawRect, m_IconsFoldout, "Icons");
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_IconsFoldout)
{
ChartEditorHelper.MakeList(ref drawRect, ref m_IconsSize, m_Icons);
}
EditorGUI.PropertyField(drawRect, m_TextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
--EditorGUI.indentLevel; --EditorGUI.indentLevel;
} }
} }
@@ -73,7 +85,7 @@ namespace XCharts
if (m_LegendModuleToggle) if (m_LegendModuleToggle)
{ {
SerializedProperty location = prop.FindPropertyRelative("m_Location"); SerializedProperty location = prop.FindPropertyRelative("m_Location");
height += 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing; height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(location); height += EditorGUI.GetPropertyHeight(location);
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_DataFoldout) if (m_DataFoldout)
@@ -83,6 +95,14 @@ namespace XCharts
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing; height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUIUtility.standardVerticalSpacing; height += EditorGUIUtility.standardVerticalSpacing;
} }
if (m_IconsFoldout)
{
SerializedProperty m_Icons = prop.FindPropertyRelative("m_Icons");
int num = m_Icons.arraySize + 1;
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUIUtility.standardVerticalSpacing;
}
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle"));
} }
if (m_ShowJsonDataArea) if (m_ShowJsonDataArea)
{ {

View File

@@ -19,7 +19,7 @@ namespace XCharts
SerializedProperty m_Radius; SerializedProperty m_Radius;
SerializedProperty m_SplitNumber; SerializedProperty m_SplitNumber;
SerializedProperty m_Center; SerializedProperty m_Center;
SerializedProperty m_LineStyle; SerializedProperty m_SplitLine;
SerializedProperty m_SplitArea; SerializedProperty m_SplitArea;
SerializedProperty m_Indicator; SerializedProperty m_Indicator;
SerializedProperty m_IndicatorGap; SerializedProperty m_IndicatorGap;
@@ -39,7 +39,7 @@ namespace XCharts
m_Radius = prop.FindPropertyRelative("m_Radius"); m_Radius = prop.FindPropertyRelative("m_Radius");
m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber"); m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber");
m_Center = prop.FindPropertyRelative("m_Center"); m_Center = prop.FindPropertyRelative("m_Center");
m_LineStyle = prop.FindPropertyRelative("m_LineStyle"); m_SplitLine = prop.FindPropertyRelative("m_SplitLine");
m_SplitArea = prop.FindPropertyRelative("m_SplitArea"); m_SplitArea = prop.FindPropertyRelative("m_SplitArea");
m_Indicator = prop.FindPropertyRelative("m_Indicator"); m_Indicator = prop.FindPropertyRelative("m_Indicator");
m_IndicatorGap = prop.FindPropertyRelative("m_IndicatorGap"); m_IndicatorGap = prop.FindPropertyRelative("m_IndicatorGap");
@@ -85,8 +85,8 @@ namespace XCharts
EditorGUI.PropertyField(drawRect, m_SplitNumber); EditorGUI.PropertyField(drawRect, m_SplitNumber);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LineStyle); EditorGUI.PropertyField(drawRect, m_SplitLine);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle); drawRect.y += EditorGUI.GetPropertyHeight(m_SplitLine);
EditorGUI.PropertyField(drawRect, m_SplitArea); EditorGUI.PropertyField(drawRect, m_SplitArea);
drawRect.y += EditorGUI.GetPropertyHeight(m_SplitArea); drawRect.y += EditorGUI.GetPropertyHeight(m_SplitArea);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -112,7 +112,7 @@ namespace XCharts
propNum += 7; propNum += 7;
if (m_IndicatorJsonAreaToggle) propNum += 4; if (m_IndicatorJsonAreaToggle) propNum += 4;
float height = propNum * EditorGUIUtility.singleLineHeight + (propNum - 1) * EditorGUIUtility.standardVerticalSpacing; float height = propNum * EditorGUIUtility.singleLineHeight + (propNum - 1) * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SplitLine"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SplitArea")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SplitArea"));
if (ChartEditorHelper.IsToggle(m_IndicatorToggle, prop)) if (ChartEditorHelper.IsToggle(m_IndicatorToggle, prop))

View File

@@ -194,6 +194,8 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Symbol); EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol); drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol);
EditorGUI.PropertyField(drawRect, m_LineStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
EditorGUI.PropertyField(drawRect, m_AreaStyle); EditorGUI.PropertyField(drawRect, m_AreaStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle); drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle);
break; break;
@@ -451,6 +453,7 @@ namespace XCharts
case SerieType.Radar: case SerieType.Radar:
height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing; height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Symbol"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AreaStyle")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_AreaStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Emphasis"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation"));

View File

@@ -14,49 +14,57 @@ namespace XCharts
[CustomPropertyDrawer(typeof(TextStyle), true)] [CustomPropertyDrawer(typeof(TextStyle), true)]
public class TextStyleDrawer : PropertyDrawer public class TextStyleDrawer : PropertyDrawer
{ {
//private Dictionary<string, bool> m_TextStyleToggle = new Dictionary<string, bool>(); private Dictionary<string, bool> m_TextStyleToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{ {
Rect drawRect = pos; Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight; drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty m_Font = prop.FindPropertyRelative("m_Font");
SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate"); SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor");
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize"); SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle"); SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset"); SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset");
// ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TextStyleToggle, prop, "Text Style"); SerializedProperty m_LineSpacing = prop.FindPropertyRelative("m_LineSpacing");
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TextStyleToggle, prop, null,null,false);
// if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop))
// {
// ++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Rotate);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Offset); if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop))
drawRect.y += EditorGUI.GetPropertyHeight(m_Offset); {
EditorGUI.PropertyField(drawRect, m_Color); ++EditorGUI.indentLevel;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_Font);
EditorGUI.PropertyField(drawRect, m_FontSize); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_Rotate);
EditorGUI.PropertyField(drawRect, m_FontStyle); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_Offset);
// --EditorGUI.indentLevel; drawRect.y += EditorGUI.GetPropertyHeight(m_Offset);
// } EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BackgroundColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontSize);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontStyle);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LineSpacing);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
--EditorGUI.indentLevel;
}
} }
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{ {
// float height = 0; float height = 0;
// if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop)) if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop))
// { {
// height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing; height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing;
// } height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset"));
// else }
// { else
// height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; {
// } height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
float height = 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing; }
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset"));
return height; return height;
} }
} }

View File

@@ -34,19 +34,16 @@ namespace XCharts
{ {
EditorGUI.PropertyField(drawRect, text); EditorGUI.PropertyField(drawRect, text);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_TextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
--EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, subText); EditorGUI.PropertyField(drawRect, subText);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_SubTextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_SubTextStyle);
--EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_ItemGap, new GUIContent("Item Gap")); EditorGUI.PropertyField(drawRect, m_ItemGap, new GUIContent("Item Gap"));
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, location); EditorGUI.PropertyField(drawRect, location);
drawRect.y += EditorGUI.GetPropertyHeight(location);
EditorGUI.PropertyField(drawRect, m_TextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
EditorGUI.PropertyField(drawRect, m_SubTextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_SubTextStyle);
} }
--EditorGUI.indentLevel; --EditorGUI.indentLevel;
} }

View File

@@ -28,13 +28,12 @@ namespace XCharts
SerializedProperty m_FixedHeight = prop.FindPropertyRelative("m_FixedHeight"); SerializedProperty m_FixedHeight = prop.FindPropertyRelative("m_FixedHeight");
SerializedProperty m_MinWidth = prop.FindPropertyRelative("m_MinWidth"); SerializedProperty m_MinWidth = prop.FindPropertyRelative("m_MinWidth");
SerializedProperty m_MinHeight = prop.FindPropertyRelative("m_MinHeight"); SerializedProperty m_MinHeight = prop.FindPropertyRelative("m_MinHeight");
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
SerializedProperty m_ForceENotation = prop.FindPropertyRelative("m_ForceENotation"); SerializedProperty m_ForceENotation = prop.FindPropertyRelative("m_ForceENotation");
SerializedProperty m_PaddingLeftRight = prop.FindPropertyRelative("m_PaddingLeftRight"); SerializedProperty m_PaddingLeftRight = prop.FindPropertyRelative("m_PaddingLeftRight");
SerializedProperty m_PaddingTopBottom = prop.FindPropertyRelative("m_PaddingTopBottom"); SerializedProperty m_PaddingTopBottom = prop.FindPropertyRelative("m_PaddingTopBottom");
SerializedProperty m_BackgroundImage = prop.FindPropertyRelative("m_BackgroundImage"); SerializedProperty m_BackgroundImage = prop.FindPropertyRelative("m_BackgroundImage");
SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle"); SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle");
SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TooltipModuleToggle, "Tooltip", show); ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TooltipModuleToggle, "Tooltip", show);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -61,16 +60,14 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_PaddingTopBottom); EditorGUI.PropertyField(drawRect, m_PaddingTopBottom);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontSize);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontStyle);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BackgroundImage); EditorGUI.PropertyField(drawRect, m_BackgroundImage);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_ForceENotation); EditorGUI.PropertyField(drawRect, m_ForceENotation);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LineStyle); EditorGUI.PropertyField(drawRect, m_LineStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle); drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
EditorGUI.PropertyField(drawRect, m_TextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
EditorGUI.indentLevel--; EditorGUI.indentLevel--;
} }
} }
@@ -78,8 +75,9 @@ namespace XCharts
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{ {
if (m_TooltipModuleToggle) if (m_TooltipModuleToggle)
return 15 * EditorGUIUtility.singleLineHeight + 14 * EditorGUIUtility.standardVerticalSpacing + return 13 * EditorGUIUtility.singleLineHeight + 12 * EditorGUIUtility.standardVerticalSpacing +
EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle")); EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle")) +
EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle"));
else else
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
} }

View File

@@ -8,6 +8,7 @@
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace XCharts namespace XCharts
{ {
@@ -28,6 +29,10 @@ namespace XCharts
canvas.renderMode = RenderMode.ScreenSpaceOverlay; canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvasObject.AddComponent<CanvasScaler>(); canvasObject.AddComponent<CanvasScaler>();
canvasObject.AddComponent<GraphicRaycaster>(); canvasObject.AddComponent<GraphicRaycaster>();
var eventSystem = new GameObject();
eventSystem.name = "EventSystem";
eventSystem.AddComponent<EventSystem>();
eventSystem.AddComponent<StandaloneInputModule>();
return canvas.transform; return canvas.transform;
} }
} }

View File

@@ -21,7 +21,7 @@ namespace XCharts
/// <summary> /// <summary>
/// The theme info. /// The theme info.
/// </summary> /// </summary>
public ThemeInfo themeInfo { get { return m_ThemeInfo; } } public ThemeInfo themeInfo { get { return m_ThemeInfo; } set { m_ThemeInfo = value; } }
/// <summary> /// <summary>
/// The title setting of chart. /// The title setting of chart.
/// 标题组件 /// 标题组件
@@ -402,9 +402,19 @@ namespace XCharts
var serie = m_Series.GetSerie(serieIndex); var serie = m_Series.GetSerie(serieIndex);
if (serie != null && !string.IsNullOrEmpty(serie.name)) if (serie != null && !string.IsNullOrEmpty(serie.name))
{ {
var legendIndex = m_LegendRealShowName.IndexOf(serie.name); UpdateLegendColor(serie.name, active);
var bgColor1 = active ? m_ThemeInfo.GetColor(legendIndex) : m_ThemeInfo.legendUnableColor; }
m_Legend.UpdateButtonColor(serie.name, bgColor1); }
protected virtual void UpdateLegendColor(string legendName, bool active)
{
var legendIndex = m_LegendRealShowName.IndexOf(legendName);
if (legendIndex >= 0)
{
var iconColor = LegendHelper.GetIconColor(legend, legendIndex, m_ThemeInfo, active);
var contentColor = LegendHelper.GetContentColor(legend, m_ThemeInfo, active);
m_Legend.UpdateButtonColor(legendName, iconColor);
m_Legend.UpdateContentColor(legendName, contentColor);
} }
} }
@@ -482,6 +492,14 @@ namespace XCharts
m_ReinitLabel = true; m_ReinitLabel = true;
} }
/// <summary>
/// 刷新Tooltip组件。
/// </summary>
public void RefreshTooltip()
{
InitTooltip();
}
/// <summary> /// <summary>
/// Update chart theme. /// Update chart theme.
/// 切换图表主题。 /// 切换图表主题。
@@ -515,32 +533,62 @@ namespace XCharts
m_Series.AnimationEnable(flag); m_Series.AnimationEnable(flag);
} }
/// <summary> [Obsolete("Use BaseChart.AnimationFadeIn() instead.", true)]
/// Start play animation.
/// 开始初始动画。
/// </summary>
public void AnimationStart() public void AnimationStart()
{ {
m_Series.AnimationStart(); }
[Obsolete("Use BaseChart.AnimationFadeOut() instead.", true)]
public void MissAnimationStart()
{
}
/// <summary>
/// fadeIn animation.
/// 开始渐入动画。
/// </summary>
public void AnimationFadeIn()
{
m_Series.AnimationFadeIn();
RefreshChart();
}
/// <summary>
/// fadeIn animation.
/// 开始渐出动画。
/// </summary>
public void AnimationFadeOut()
{
m_Series.AnimationFadeOut();
RefreshChart();
}
/// <summary>
/// Pause animation.
/// 暂停动画。
/// </summary>
public void AnimationPause()
{
m_Series.AnimationPause();
RefreshChart();
} }
/// <summary> /// <summary>
/// Stop play animation. /// Stop play animation.
/// 停止初始化动画。 /// 继续动画。
/// </summary> /// </summary>
public void AnimationStop() public void AnimationResume()
{ {
m_CheckAnimation = false; m_Series.AnimationResume();
m_Series.AnimationStop(); RefreshChart();
} }
/// <summary> /// <summary>
/// Reset animation to play. /// Reset animation.
/// 重置初始动画,重新播放 /// 重置动画
/// </summary> /// </summary>
public void AnimationReset() public void AnimationReset()
{ {
m_CheckAnimation = false;
m_Series.AnimationReset(); m_Series.AnimationReset();
RefreshChart(); RefreshChart();
} }

View File

@@ -68,7 +68,7 @@ namespace XCharts
radar.center[0] = center.x; radar.center[0] = center.x;
radar.center[1] = center.y; radar.center[1] = center.y;
radar.splitArea.show = showSplitArea; radar.splitArea.show = showSplitArea;
radar.lineStyle.width = lineWidth; radar.splitLine.lineStyle.width = lineWidth;
m_Radars.Add(radar); m_Radars.Add(radar);
return radar; return radar;
} }

View File

@@ -191,20 +191,10 @@ namespace XCharts
get { return m_RuntimeMinValue; } get { return m_RuntimeMinValue; }
internal set internal set
{ {
if (value != m_RuntimeMinValue) m_RuntimeMinValue = value;
{ m_RuntimeLastMinValue = value;
if (m_RuntimeMinValueFirstChanged) m_RuntimeMinValueUpdateTime = Time.time;
{ m_RuntimeMinValueChanged = true;
m_RuntimeMinValueFirstChanged = false;
}
else
{
m_RuntimeLastMinValue = m_RuntimeMinValue;
m_RuntimeMinValueChanged = true;
m_RuntimeMinValueUpdateTime = Time.time;
}
m_RuntimeMinValue = value;
}
} }
} }
/// <summary> /// <summary>
@@ -216,20 +206,10 @@ namespace XCharts
get { return m_RuntimeMaxValue; } get { return m_RuntimeMaxValue; }
internal set internal set
{ {
if (value != m_RuntimeMaxValue) m_RuntimeMaxValue = value;
{ m_RuntimeLastMaxValue = value;
if (m_RuntimeMaxValueFirstChanged) m_RuntimeMaxValueUpdateTime = Time.time;
{ m_RuntimeMaxValueChanged = false;
m_RuntimeMaxValueFirstChanged = false;
}
else
{
m_RuntimeLastMaxValue = m_RuntimeMaxValue;
m_RuntimeMaxValueChanged = true;
m_RuntimeMaxValueUpdateTime = Time.time;
}
m_RuntimeMaxValue = value;
}
} }
} }
/// <summary> /// <summary>
@@ -708,6 +688,62 @@ namespace XCharts
m_ValueRange = maxValue - minValue; m_ValueRange = maxValue - minValue;
} }
internal void UpdateMinValue(float value, bool check)
{
if (value != m_RuntimeMaxValue)
{
if (check)
{
if (m_RuntimeMinValueFirstChanged)
{
m_RuntimeMinValueFirstChanged = false;
}
else
{
m_RuntimeLastMinValue = m_RuntimeMinValue;
m_RuntimeMinValueChanged = true;
m_RuntimeMinValueUpdateTime = Time.time;
}
m_RuntimeMinValue = value;
}
else
{
m_RuntimeMinValue = value;
m_RuntimeLastMinValue = value;
m_RuntimeMinValueUpdateTime = Time.time;
m_RuntimeMinValueChanged = true;
}
}
}
internal void UpdateMaxValue(float value, bool check)
{
if (value != m_RuntimeMaxValue)
{
if (check)
{
if (m_RuntimeMaxValueFirstChanged)
{
m_RuntimeMaxValueFirstChanged = false;
}
else
{
m_RuntimeLastMaxValue = m_RuntimeMaxValue;
m_RuntimeMaxValueChanged = true;
m_RuntimeMaxValueUpdateTime = Time.time;
}
m_RuntimeMaxValue = value;
}
else
{
m_RuntimeMaxValue = value;
m_RuntimeLastMaxValue = value;
m_RuntimeMaxValueUpdateTime = Time.time;
m_RuntimeMaxValueChanged = false;
}
}
}
internal float GetCurrMinValue(float duration) internal float GetCurrMinValue(float duration)
{ {
if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0; if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0;

View File

@@ -43,14 +43,16 @@ namespace XCharts
[SerializeField] private SelectedMode m_SelectedMode; [SerializeField] private SelectedMode m_SelectedMode;
[SerializeField] private Orient m_Orient = Orient.Horizonal; [SerializeField] private Orient m_Orient = Orient.Horizonal;
[SerializeField] private Location m_Location = Location.defaultRight; [SerializeField] private Location m_Location = Location.defaultRight;
[SerializeField] private float m_ItemWidth = 50.0f; [SerializeField] private float m_ItemWidth = 24.0f;
[SerializeField] private float m_ItemHeight = 20.0f; [SerializeField] private float m_ItemHeight = 12.0f;
[SerializeField] private float m_ItemGap = 5; [SerializeField] private float m_ItemGap = 10f;
[SerializeField] private int m_ItemFontSize = 18; [SerializeField] private bool m_ItemAutoColor = true;
[SerializeField] private string m_Formatter; [SerializeField] private string m_Formatter;
[SerializeField] private TextStyle m_TextStyle = new TextStyle(18);
[SerializeField] private List<string> m_Data = new List<string>(); [SerializeField] private List<string> m_Data = new List<string>();
[SerializeField] private List<Sprite> m_Icons = new List<Sprite>();
private Dictionary<string, Button> m_DataBtnList = new Dictionary<string, Button>(); private Dictionary<string, LegendItem> m_DataBtnList = new Dictionary<string, LegendItem>();
/// <summary> /// <summary>
/// Whether to show legend component. /// Whether to show legend component.
@@ -74,13 +76,13 @@ namespace XCharts
/// </summary> /// </summary>
public Location location { get { return m_Location; } set { m_Location = value; } } public Location location { get { return m_Location; } set { m_Location = value; } }
/// <summary> /// <summary>
/// the width of legend item. /// Image width of legend symbol.
/// 每个图例项的宽度。 /// 图例标记的图形宽度。
/// </summary> /// </summary>
public float itemWidth { get { return m_ItemWidth; } set { m_ItemWidth = value; } } public float itemWidth { get { return m_ItemWidth; } set { m_ItemWidth = value; } }
/// <summary> /// <summary>
/// the height of legend item. /// Image height of legend symbol.
/// 每个图例项的高度。 /// 图例标记的图形高度。
/// </summary> /// </summary>
public float itemHeight { get { return m_ItemHeight; } set { m_ItemHeight = value; } } public float itemHeight { get { return m_ItemHeight; } set { m_ItemHeight = value; } }
/// <summary> /// <summary>
@@ -89,16 +91,21 @@ namespace XCharts
/// </summary> /// </summary>
public float itemGap { get { return m_ItemGap; } set { m_ItemGap = value; } } public float itemGap { get { return m_ItemGap; } set { m_ItemGap = value; } }
/// <summary> /// <summary>
/// font size of item text. /// Whether the legend symbol matches the color automatically.
/// 图例项的字体大小 /// 图例标记的图形是否自动匹配颜色
/// </summary> /// </summary>
public int itemFontSize { get { return m_ItemFontSize; } set { m_ItemFontSize = value; } } public bool itemAutoColor { get { return m_ItemAutoColor; } set { m_ItemAutoColor = value; } }
/// <summary> /// <summary>
/// 图例内容字符串模版格式器。支持用 \n 换行。 /// 图例内容字符串模版格式器。支持用 \n 换行。
/// 模板变量为图例名称 {name} /// 模板变量为图例名称 {name}
/// </summary> /// </summary>
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } } public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
/// <summary> /// <summary>
/// the style of text.
/// 文本样式。
/// </summary>
public TextStyle textStyle { get { return m_TextStyle; } set { m_TextStyle = value; } }
/// <summary>
/// Data array of legend. An array item is usually a name representing string. (If it is a pie chart, /// Data array of legend. An array item is usually a name representing string. (If it is a pie chart,
/// it could also be the name of a single data in the pie chart) of a series. /// it could also be the name of a single data in the pie chart) of a series.
/// If data is not specified, it will be auto collected from series. /// If data is not specified, it will be auto collected from series.
@@ -107,11 +114,47 @@ namespace XCharts
/// </summary> /// </summary>
public List<string> data { get { return m_Data; } } public List<string> data { get { return m_Data; } }
/// <summary> /// <summary>
/// 自定义的图例标记图形。
/// </summary>
public List<Sprite> icons { get { return m_Icons; } }
/// <summary>
/// the button list of legend. /// the button list of legend.
/// 图例按钮列表。 /// 图例按钮列表。
/// </summary> /// </summary>
/// <value></value> /// <value></value>
public Dictionary<string, Button> buttonList { get { return m_DataBtnList; } } public Dictionary<string, LegendItem> buttonList { get { return m_DataBtnList; } }
public float runtimeWidth
{
get
{
var width = 0f;
foreach (var kv in buttonList)
{
if (orient == Orient.Horizonal)
width += kv.Value.width + m_ItemGap;
else if (kv.Value.width > width)
width = kv.Value.width;
}
return orient == Orient.Horizonal ? width - m_ItemGap : width;
}
}
public float runtimeHeight
{
get
{
var height = 0f;
foreach (var kv in buttonList)
{
if (orient == Orient.Vertical)
height += kv.Value.height + m_ItemGap;
else if (kv.Value.height > height)
height = kv.Value.height;
}
return orient == Orient.Vertical ? height - m_ItemGap : height;
}
}
/// <summary> /// <summary>
/// 一个在顶部居中显示的默认图例。 /// 一个在顶部居中显示的默认图例。
@@ -126,12 +169,13 @@ namespace XCharts
m_SelectedMode = SelectedMode.Multiple, m_SelectedMode = SelectedMode.Multiple,
m_Orient = Orient.Horizonal, m_Orient = Orient.Horizonal,
m_Location = Location.defaultTop, m_Location = Location.defaultTop,
m_ItemWidth = 60.0f, m_ItemWidth = 24.0f,
m_ItemHeight = 20.0f, m_ItemHeight = 12.0f,
m_ItemGap = 5, m_ItemGap = 10f,
m_ItemFontSize = 16
}; };
legend.location.top = 30; legend.location.top = 30;
legend.textStyle.offset = new Vector2(2, 0);
legend.textStyle.fontSize = 18;
return legend; return legend;
} }
} }
@@ -144,9 +188,10 @@ namespace XCharts
m_ItemWidth = legend.itemWidth; m_ItemWidth = legend.itemWidth;
m_ItemHeight = legend.itemHeight; m_ItemHeight = legend.itemHeight;
m_ItemGap = legend.itemGap; m_ItemGap = legend.itemGap;
m_ItemFontSize = legend.itemFontSize; itemAutoColor = legend.itemAutoColor;
m_Data.Clear(); m_TextStyle.Copy(legend.textStyle);
foreach (var d in legend.data) m_Data.Add(d); ChartHelper.CopyList<string>(m_Data, legend.data);
ChartHelper.CopyList<Sprite>(m_Icons, legend.icons);
} }
public override bool Equals(object obj) public override bool Equals(object obj)
@@ -178,8 +223,10 @@ namespace XCharts
itemWidth == other.itemWidth && itemWidth == other.itemWidth &&
itemHeight == other.itemHeight && itemHeight == other.itemHeight &&
itemGap == other.itemGap && itemGap == other.itemGap &&
itemFontSize == other.itemFontSize && itemAutoColor == other.itemAutoColor &&
ChartHelper.IsValueEqualsList<string>(m_Data, other.data); textStyle.Equals(other.textStyle) &&
ChartHelper.IsValueEqualsList<string>(m_Data, other.data) &&
ChartHelper.IsValueEqualsList<Sprite>(m_Icons, other.icons);
} }
public static bool operator ==(Legend left, Legend right) public static bool operator ==(Legend left, Legend right)
@@ -285,13 +332,11 @@ namespace XCharts
/// <param name="name"></param> /// <param name="name"></param>
/// <param name="btn"></param> /// <param name="btn"></param>
/// <param name="total"></param> /// <param name="total"></param>
public void SetButton(string name, Button btn, int total) public void SetButton(string name, LegendItem item, int total)
{ {
m_DataBtnList[name] = item;
int index = m_DataBtnList.Values.Count; int index = m_DataBtnList.Values.Count;
btn.transform.localPosition = GetButtonLocationPosition(total, index); item.SetActive(show);
m_DataBtnList[name] = btn;
btn.gameObject.SetActive(show);
btn.GetComponentInChildren<Text>().text = name;
} }
/// <summary> /// <summary>
@@ -303,7 +348,27 @@ namespace XCharts
{ {
if (m_DataBtnList.ContainsKey(name)) if (m_DataBtnList.ContainsKey(name))
{ {
m_DataBtnList[name].GetComponent<Image>().color = color; m_DataBtnList[name].SetIconColor(color);
}
}
public void UpdateContentColor(string name, Color color)
{
if (m_DataBtnList.ContainsKey(name))
{
m_DataBtnList[name].SetContentColor(color);
}
}
public Sprite GetIcon(int index)
{
if (index >= 0 && index < m_Icons.Count)
{
return m_Icons[index];
}
else
{
return null;
} }
} }
@@ -314,63 +379,7 @@ namespace XCharts
{ {
m_Location.OnChanged(); m_Location.OnChanged();
} }
/// <summary>
/// 根据图例的布局和位置类型获得具体位置
/// </summary>
/// <param name="size"></param>
/// <param name="index"></param>
/// <returns></returns>
private Vector2 GetButtonLocationPosition(int size, int index)
{
switch (m_Orient)
{
case Orient.Vertical:
switch (m_Location.align)
{
case Location.Align.TopCenter:
case Location.Align.TopLeft:
case Location.Align.TopRight:
return new Vector2(0, -index * (itemHeight + itemGap));
case Location.Align.Center:
case Location.Align.CenterLeft:
case Location.Align.CenterRight:
float totalHeight = size * itemHeight + (size - 1) * itemGap;
float startY = totalHeight / 2;
return new Vector2(0, startY - index * (itemHeight + itemGap));
case Location.Align.BottomCenter:
case Location.Align.BottomLeft:
case Location.Align.BottomRight:
return new Vector2(0, (size - index - 1) * (itemHeight + itemGap));
}
return Vector2.zero;
case Orient.Horizonal:
switch (m_Location.align)
{
case Location.Align.TopLeft:
case Location.Align.CenterLeft:
case Location.Align.BottomLeft:
return new Vector2(index * (itemWidth + itemGap), 0);
case Location.Align.TopCenter:
case Location.Align.Center:
case Location.Align.BottomCenter:
float totalWidth = size * itemWidth + (size - 1) * itemGap;
float startX = totalWidth / 2;
return new Vector2(-startX + itemWidth / 2 + index * (itemWidth + itemGap), 0);
case Location.Align.TopRight:
case Location.Align.CenterRight:
case Location.Align.BottomRight:
return new Vector2(-(size - index - 1) * (itemWidth + itemGap), 0);
}
return Vector2.zero;
}
return Vector2.zero;
}
/// <summary> /// <summary>
/// 从json字符串解析数据json格式如['邮件营销','联盟广告','视频广告','直接访问','搜索引擎'] /// 从json字符串解析数据json格式如['邮件营销','联盟广告','视频广告','直接访问','搜索引擎']
/// </summary> /// </summary>

View File

@@ -126,7 +126,7 @@ namespace XCharts
[SerializeField] private float m_Radius = 100; [SerializeField] private float m_Radius = 100;
[SerializeField] private int m_SplitNumber = 5; [SerializeField] private int m_SplitNumber = 5;
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f }; [SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
[SerializeField] private LineStyle m_LineStyle = new LineStyle(); [SerializeField] private AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine;
[SerializeField] private AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea; [SerializeField] private AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
[SerializeField] private bool m_Indicator = true; [SerializeField] private bool m_Indicator = true;
[SerializeField] private PositionType m_PositionType = PositionType.Vertice; [SerializeField] private PositionType m_PositionType = PositionType.Vertice;
@@ -155,10 +155,10 @@ namespace XCharts
/// </summary> /// </summary>
public float[] center { get { return m_Center; } set { m_Center = value; } } public float[] center { get { return m_Center; } set { m_Center = value; } }
/// <summary> /// <summary>
/// the line style of radar. /// split line.
/// 线条样式 /// 分割线。
/// </summary> /// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } } public AxisSplitLine splitLine { get { return m_SplitLine; } set { m_SplitLine = value; } }
/// <summary> /// <summary>
/// Split area of axis in grid area. /// Split area of axis in grid area.
/// 分割区域。 /// 分割区域。
@@ -207,7 +207,7 @@ namespace XCharts
var radar = new Radar var radar = new Radar
{ {
m_Shape = Shape.Polygon, m_Shape = Shape.Polygon,
m_Radius = 0.4f, m_Radius = 0.35f,
m_SplitNumber = 5, m_SplitNumber = 5,
m_Indicator = true, m_Indicator = true,
m_IndicatorList = new List<Indicator>(5){ m_IndicatorList = new List<Indicator>(5){
@@ -219,9 +219,10 @@ namespace XCharts
} }
}; };
radar.center[0] = 0.5f; radar.center[0] = 0.5f;
radar.center[1] = 0.45f; radar.center[1] = 0.4f;
radar.splitLine.show = true;
radar.splitArea.show = true; radar.splitArea.show = true;
radar.lineStyle.width = 0.6f; radar.splitLine.lineStyle.width = 0.6f;
return radar; return radar;
} }
} }
@@ -234,6 +235,8 @@ namespace XCharts
m_Center[0] = other.center[0]; m_Center[0] = other.center[0];
m_Center[1] = other.center[1]; m_Center[1] = other.center[1];
m_Indicator = other.indicator; m_Indicator = other.indicator;
//m_SplitLine.Copy(other.splitLine);
//m_SplitArea.Copy(other.splitArea);
indicatorList.Clear(); indicatorList.Clear();
foreach (var d in other.indicatorList) indicatorList.Add(d.Clone()); foreach (var d in other.indicatorList) indicatorList.Add(d.Clone());
} }

View File

@@ -194,7 +194,7 @@ namespace XCharts
[System.Serializable] [System.Serializable]
public class Serie : MainComponent public class Serie : MainComponent
{ {
[SerializeField] [DefaultValue("true")] private bool m_Show = true; [SerializeField] private bool m_Show = true;
[SerializeField] private SerieType m_Type; [SerializeField] private SerieType m_Type;
[SerializeField] private string m_Name; [SerializeField] private string m_Name;
[SerializeField] private string m_Stack; [SerializeField] private string m_Stack;
@@ -246,7 +246,7 @@ namespace XCharts
[SerializeField] [Range(1, 10)] private int m_ShowDataDimension; [SerializeField] [Range(1, 10)] private int m_ShowDataDimension;
[SerializeField] private bool m_ShowDataName; [SerializeField] private bool m_ShowDataName;
[SerializeField] private bool m_ShowDataIcon; [SerializeField] private bool m_ShowDataIcon;
[SerializeField] private bool m_Clip = false; [SerializeField] private bool m_Clip = true;
[SerializeField] private List<SerieData> m_Data = new List<SerieData>(); [SerializeField] private List<SerieData> m_Data = new List<SerieData>();
@@ -501,6 +501,10 @@ namespace XCharts
/// </summary> /// </summary>
public int showDataDimension { get { return m_ShowDataDimension; } } public int showDataDimension { get { return m_ShowDataDimension; } }
/// <summary> /// <summary>
/// 在Editor的inpsector上是否显示name参数
/// </summary>
public bool showDataName { get { return m_ShowDataName; } set { m_ShowDataName = value; } }
/// <summary>
/// If clip the overflow on the coordinate system. /// If clip the overflow on the coordinate system.
/// 是否裁剪超出坐标系部分的图形。 /// 是否裁剪超出坐标系部分的图形。
/// </summary> /// </summary>

View File

@@ -56,7 +56,7 @@ namespace XCharts
/// </summary> /// </summary>
public void ClearData() public void ClearData()
{ {
AnimationStop(); AnimationPause();
foreach (var serie in m_Series) foreach (var serie in m_Series)
{ {
serie.ClearData(); serie.ClearData();
@@ -196,7 +196,7 @@ namespace XCharts
{ {
foreach (var serie in m_Series) foreach (var serie in m_Series)
{ {
if (serie.animation.enable && serie.animation.updateAnimation) if (serie.animation.enable && serie.animation.dataChangeEnable)
{ {
return true; return true;
} }
@@ -257,7 +257,7 @@ namespace XCharts
/// </summary> /// </summary>
public void RemoveAll() public void RemoveAll()
{ {
AnimationStop(); AnimationPause();
m_Series.Clear(); m_Series.Clear();
} }
@@ -292,7 +292,7 @@ namespace XCharts
{ {
serie.symbol.type = SerieSymbolType.None; serie.symbol.type = SerieSymbolType.None;
} }
serie.animation.Reset(); serie.animation.Restart();
m_Series.Add(serie); m_Series.Add(serie);
return serie; return serie;
} }
@@ -615,6 +615,8 @@ namespace XCharts
if (serie != null) if (serie != null)
{ {
serie.show = active; serie.show = active;
serie.animation.Reset();
if (active) serie.animation.FadeIn();
} }
} }
@@ -1006,32 +1008,54 @@ namespace XCharts
} }
/// <summary> /// <summary>
/// 开始初始动画 /// 渐入动画
/// </summary> /// </summary>
public void AnimationStart() public void AnimationFadeIn()
{ {
foreach (var serie in m_Series) foreach (var serie in m_Series)
{ {
if (serie.animation.enable) if (serie.animation.enable)
{ {
serie.animation.Start(); serie.animation.FadeIn();
} }
} }
} }
/// <summary> /// <summary>
/// 停止初始动画 /// 渐出动画
/// </summary> /// </summary>
public void AnimationStop() public void AnimationFadeOut()
{ {
foreach (var serie in m_Series) foreach (var serie in m_Series)
{ {
if (serie.animation.enable) serie.animation.Stop(); if (serie.animation.enable) serie.animation.FadeOut();
} }
} }
/// <summary> /// <summary>
/// 重置初始动画 /// 暂停动画
/// </summary>
public void AnimationPause()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable) serie.animation.Pause();
}
}
/// <summary>
/// 继续动画
/// </summary>
public void AnimationResume()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable) serie.animation.Resume();
}
}
/// <summary>
/// 重置动画
/// </summary> /// </summary>
public void AnimationReset() public void AnimationReset()
{ {

View File

@@ -132,6 +132,8 @@ namespace XCharts
get { return m_CustomLegendTextColor != Color.clear ? m_CustomLegendTextColor : m_LegendTextColor; } get { return m_CustomLegendTextColor != Color.clear ? m_CustomLegendTextColor : m_LegendTextColor; }
set { m_CustomLegendTextColor = value; } set { m_CustomLegendTextColor = value; }
} }
public Color32 defaultLegendTextColor{get{return m_LegendTextColor;}set{m_LegendTextColor=value;}}
/// <summary> /// <summary>
/// the legend unable text color. /// the legend unable text color.
/// 图例变为不可用时的按钮颜色。 /// 图例变为不可用时的按钮颜色。
@@ -391,7 +393,7 @@ namespace XCharts
m_LegendUnableColor = GetColor("#cccccc"), m_LegendUnableColor = GetColor("#cccccc"),
m_TitleTextColor = GetColor("#514D4D"), m_TitleTextColor = GetColor("#514D4D"),
m_TitleSubTextColor = GetColor("#514D4D"), m_TitleSubTextColor = GetColor("#514D4D"),
m_LegendTextColor = GetColor("#eee"), m_LegendTextColor = GetColor("#514D4D"),
m_AxisTextColor = GetColor("#514D4D"), m_AxisTextColor = GetColor("#514D4D"),
m_AxisLineColor = GetColor("#514D4D"), m_AxisLineColor = GetColor("#514D4D"),
m_AxisSplitLineColor = GetColor("#51515120"), m_AxisSplitLineColor = GetColor("#51515120"),

View File

@@ -1,4 +1,5 @@
/******************************************/ using System.Collections.ObjectModel;
/******************************************/
/* */ /* */
/* Copyright (c) 2018 monitor1394 */ /* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */ /* https://github.com/monitor1394 */
@@ -8,6 +9,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System;
using UnityEngine.EventSystems;
namespace XCharts namespace XCharts
{ {
@@ -55,12 +58,11 @@ namespace XCharts
[SerializeField] private float m_FixedHeight = 0; [SerializeField] private float m_FixedHeight = 0;
[SerializeField] private float m_MinWidth = 0; [SerializeField] private float m_MinWidth = 0;
[SerializeField] private float m_MinHeight = 0; [SerializeField] private float m_MinHeight = 0;
[SerializeField] private int m_FontSize = 18;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private bool m_ForceENotation = false; [SerializeField] private bool m_ForceENotation = false;
[SerializeField] private float m_PaddingLeftRight = 5f; [SerializeField] private float m_PaddingLeftRight = 5f;
[SerializeField] private float m_PaddingTopBottom = 5f; [SerializeField] private float m_PaddingTopBottom = 5f;
[SerializeField] private Sprite m_BackgroundImage; [SerializeField] private Sprite m_BackgroundImage;
[SerializeField] private TextStyle m_TextStyle = new TextStyle(18, FontStyle.Normal);
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid, 0.7f); [SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid, 0.7f);
private GameObject m_GameObject; private GameObject m_GameObject;
@@ -138,16 +140,10 @@ namespace XCharts
/// 最小高度。如若 fixedHeight 设有值,优先取 fixedHeight。 /// 最小高度。如若 fixedHeight 设有值,优先取 fixedHeight。
/// </summary> /// </summary>
public float minHeight { get { return m_MinHeight; } set { m_MinHeight = value; } } public float minHeight { get { return m_MinHeight; } set { m_MinHeight = value; } }
/// <summary> [Obsolete("Use Tooltip.textStyle.fontSize instead.", true)]
/// font size. public int fontSize { get; set; }
/// 文字的字体大小。 [Obsolete("Use Tooltip.textStyle.fontStyle instead.", true)]
/// </summary> public FontStyle fontStyle { get; set; }
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
/// <summary>
/// font style.
/// 文字的字体风格。
/// </summary>
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
/// <summary> /// <summary>
/// 是否强制使用科学计数法格式化显示数值。默认为false当小数精度大于3时才采用科学计数法。 /// 是否强制使用科学计数法格式化显示数值。默认为false当小数精度大于3时才采用科学计数法。
/// </summary> /// </summary>
@@ -168,6 +164,10 @@ namespace XCharts
/// </summary> /// </summary>
public Sprite backgroundImage { get { return m_BackgroundImage; } set { m_BackgroundImage = value; SetBackground(m_BackgroundImage); } } public Sprite backgroundImage { get { return m_BackgroundImage; } set { m_BackgroundImage = value; SetBackground(m_BackgroundImage); } }
/// <summary> /// <summary>
/// 提示框内容文本样式。
/// </summary>
public TextStyle textStyle { get { return m_TextStyle; } set { if (value != null) m_TextStyle = value; } }
/// <summary>
/// 指示线样式。 /// 指示线样式。
/// </summary> /// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { if (value != null) m_LineStyle = value; } } public LineStyle lineStyle { get { return m_LineStyle; } set { if (value != null) m_LineStyle = value; } }

View File

@@ -85,7 +85,7 @@ namespace XCharts
internal bool NeedShow(int index) internal bool NeedShow(int index)
{ {
return interval == 0 || index % (interval + 1) == 0; return show && (interval == 0 || index % (interval + 1) == 0);
} }
} }
} }

View File

@@ -52,7 +52,7 @@ namespace XCharts
/// <summary> /// <summary>
/// Whether show line. /// Whether show line.
/// 是否显示线条。在折线图中无效。 /// 是否显示线条。当作为子组件,它的父组件有参数控制是否显示时,改参数无效。
/// </summary> /// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } } public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary> /// <summary>

View File

@@ -1,4 +1,5 @@
/******************************************/ using System.Threading;
/******************************************/
/* */ /* */
/* Copyright (c) 2018 monitor1394 */ /* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */ /* https://github.com/monitor1394 */
@@ -23,11 +24,12 @@ namespace XCharts
} }
[SerializeField] private bool m_Enable = true; [SerializeField] private bool m_Enable = true;
[SerializeField] private Easing m_Easting; [SerializeField] private Easing m_Easting;
[SerializeField] private float m_Duration = 1000;
[SerializeField] private int m_Threshold = 2000; [SerializeField] private int m_Threshold = 2000;
[SerializeField] private float m_Delay = 0; [SerializeField] private float m_FadeInDuration = 1000;
[SerializeField] private bool m_UpdateAnimation = true; [SerializeField] private float m_FadeInDelay = 0;
[SerializeField] private float m_UpdateDuration = 500; [SerializeField] private float m_FadeOutDuration = 1000f;
[SerializeField] private bool m_DataChangeEnable = true;
[SerializeField] private float m_DataChangeDuration = 500;
[SerializeField] private float m_ActualDuration; [SerializeField] private float m_ActualDuration;
/// <summary> /// <summary>
@@ -39,12 +41,17 @@ namespace XCharts
/// Easing method used for the first animation. /// Easing method used for the first animation.
/// 动画的缓动效果。 /// 动画的缓动效果。
/// </summary> /// </summary>
public Easing easing { get { return m_Easting; } set { m_Easting = value; } } //public Easing easing { get { return m_Easting; } set { m_Easting = value; } }
/// <summary> /// <summary>
/// The milliseconds duration of the first animation. /// The milliseconds duration of the fadeIn animation.
/// 设定的动画时长(毫秒)。 /// 设定的渐入动画时长(毫秒)。
/// </summary> /// </summary>
public float duration { get { return m_Duration; } set { m_Duration = value < 0 ? 0 : value; } } public float fadeInDuration { get { return m_FadeInDuration; } set { m_FadeInDuration = value < 0 ? 0 : value; } }
/// <summary>
/// The milliseconds duration of the fadeOut animation.
/// 设定的渐出动画时长(毫秒)。
/// </summary>
public float fadeOutDuration { get { return m_FadeOutDuration; } set { m_FadeOutDuration = value < 0 ? 0 : value; } }
/// <summary> /// <summary>
/// The milliseconds actual duration of the first animation. /// The milliseconds actual duration of the first animation.
/// 实际的动画时长(毫秒)。 /// 实际的动画时长(毫秒)。
@@ -59,21 +66,24 @@ namespace XCharts
/// The milliseconds delay before updating the first animation. /// The milliseconds delay before updating the first animation.
/// 动画延时(毫秒)。 /// 动画延时(毫秒)。
/// </summary> /// </summary>
public float delay { get { return m_Delay; } set { m_Delay = value < 0 ? 0 : value; } } public float delay { get { return m_FadeInDelay; } set { m_FadeInDelay = value < 0 ? 0 : value; } }
/// <summary> /// <summary>
/// 是否开启数据变更动画。 /// 是否开启数据变更动画。
/// </summary> /// </summary>
public bool updateAnimation { get { return m_UpdateAnimation; } set { m_UpdateAnimation = value; } } public bool dataChangeEnable { get { return m_DataChangeEnable; } set { m_DataChangeEnable = value; } }
/// <summary> /// <summary>
/// The milliseconds duration of the first animation. /// The milliseconds duration of the data change animation.
/// 数据变更的动画时长(毫秒)。 /// 数据变更的动画时长(毫秒)。
/// </summary> /// </summary>
public float updateDuration { get { return m_UpdateDuration; } set { m_UpdateDuration = value < 0 ? 0 : value; } } public float dataChangeDuration { get { return m_DataChangeDuration; } set { m_DataChangeDuration = value < 0 ? 0 : value; } }
private Dictionary<int, float> m_DataAnimationState = new Dictionary<int, float>(); private Dictionary<int, float> m_DataAnimationState = new Dictionary<int, float>();
private bool m_IsStart = false; private bool m_FadeIn = false;
private bool m_IsEnd = true; private bool m_IsEnd = true;
private bool m_Inited = false; private bool m_IsPause = false;
private bool m_FadeOut = false;
private bool m_FadeOuted = false;
private bool m_IsInit = false;
private float startTime { get; set; } private float startTime { get; set; }
private int m_CurrDataProgress { get; set; } private int m_CurrDataProgress { get; set; }
@@ -82,13 +92,21 @@ namespace XCharts
[SerializeField] private float m_DestDetailProgress; [SerializeField] private float m_DestDetailProgress;
private float m_CurrSymbolProgress; private float m_CurrSymbolProgress;
public void Start() public void FadeIn()
{ {
if (m_IsStart) return; if (m_FadeOut) return;
if (m_IsPause)
{
m_IsPause = false;
return;
}
if (m_FadeIn) return;
startTime = Time.time; startTime = Time.time;
m_IsStart = true; m_FadeIn = true;
m_IsEnd = false; m_IsEnd = false;
m_Inited = false; m_IsInit = false;
m_IsPause = false;
m_FadeOuted = false;
m_CurrDataProgress = 1; m_CurrDataProgress = 1;
m_DestDataProgress = 1; m_DestDataProgress = 1;
m_CurrDetailProgress = 0; m_CurrDetailProgress = 0;
@@ -97,34 +115,89 @@ namespace XCharts
m_DataAnimationState.Clear(); m_DataAnimationState.Clear();
} }
public void Stop() public void Restart()
{ {
m_IsStart = false; Reset();
m_IsEnd = true; FadeIn();
m_Inited = false; }
public void FadeOut()
{
if (m_IsPause)
{
m_IsPause = false;
return;
}
m_FadeOut = true;
startTime = Time.time;
m_FadeIn = true;
m_IsEnd = false;
m_IsInit = false;
m_IsPause = false;
m_CurrDataProgress = 0;
m_DestDataProgress = 0;
m_CurrDetailProgress = 0;
m_DestDetailProgress = 1;
m_CurrSymbolProgress = 0;
m_DataAnimationState.Clear(); m_DataAnimationState.Clear();
} }
public void End() public void Pause()
{
if (!m_IsPause)
{
m_IsPause = true;
}
}
public void Resume()
{
if (m_IsPause)
{
m_IsPause = false;
}
}
private void End()
{ {
if (m_IsEnd) return; if (m_IsEnd) return;
m_ActualDuration = (int)((Time.time - startTime) * 1000) - delay; m_ActualDuration = (int)((Time.time - startTime) * 1000) - delay;
m_CurrDataProgress = m_DestDataProgress + 1; m_CurrDataProgress = m_DestDataProgress + (m_FadeOut ? -1 : 1);
m_FadeIn = false;
m_IsEnd = true; m_IsEnd = true;
m_IsInit = false;
if (m_FadeOut)
{
m_FadeOut = false;
m_FadeOuted = true;
}
} }
public void Reset() public void Reset()
{ {
Stop(); m_FadeIn = false;
Start(); m_IsEnd = true;
m_IsInit = false;
m_IsPause = false;
m_FadeOut = false;
m_FadeOuted = false;
m_DataAnimationState.Clear();
} }
public void InitProgress(int data, float curr, float dest) public void InitProgress(int data, float curr, float dest)
{ {
if (!m_Inited && !m_IsEnd) if (m_IsInit || m_IsEnd) return;
if (curr > dest) return;
m_IsInit = true;
m_DestDataProgress = data;
if (m_FadeOut)
{
m_CurrDetailProgress = dest;
m_DestDetailProgress = curr;
}
else
{ {
m_Inited = true;
m_DestDataProgress = data;
m_CurrDetailProgress = curr; m_CurrDetailProgress = curr;
m_DestDetailProgress = dest; m_DestDetailProgress = dest;
} }
@@ -132,23 +205,21 @@ namespace XCharts
public void SetDataFinish(int dataIndex) public void SetDataFinish(int dataIndex)
{ {
if (!m_IsEnd) if (m_IsEnd) return;
{ m_CurrDataProgress = dataIndex + (m_FadeOut ? -1 : 1);
m_CurrDataProgress = dataIndex + 1;
}
} }
public void SetDataState(int index, float state) private void SetDataState(int index, float state)
{ {
m_DataAnimationState[index] = state; m_DataAnimationState[index] = state;
} }
public float GetDataState(int index) private float GetDataState(int index, float dest)
{ {
if (IsInDelay()) return 0; if (IsInDelay()) return dest;
if (!m_DataAnimationState.ContainsKey(index)) if (!m_DataAnimationState.ContainsKey(index))
{ {
m_DataAnimationState.Add(index, 0); m_DataAnimationState.Add(index, dest);
} }
return m_DataAnimationState[index]; return m_DataAnimationState[index];
} }
@@ -182,29 +253,95 @@ namespace XCharts
{ {
if (!m_Enable || m_IsEnd) return true; if (!m_Enable || m_IsEnd) return true;
if (IsInDelay()) return false; if (IsInDelay()) return false;
return dataIndex <= m_CurrDataProgress; if (m_FadeOut) return dataIndex > 0;
else return dataIndex <= m_CurrDataProgress;
} }
internal void CheckProgress(float delta) internal void CheckProgress(float total)
{ {
if (!enable) return; if (IsFinish()) return;
if (!m_IsInit || m_IsPause || m_IsEnd) return;
if (IsInDelay()) return; if (IsInDelay()) return;
if (m_IsEnd) return; m_ActualDuration = (int)((Time.time - startTime) * 1000) - delay;
if (m_CurrDetailProgress > m_DestDetailProgress) var duration = GetCurrAnimationDuration();
var delta = total / duration * Time.deltaTime;
if (m_FadeOut)
{ {
End(); m_CurrDetailProgress -= delta;
if (m_CurrDetailProgress <= m_DestDetailProgress)
{
m_CurrDetailProgress = m_DestDetailProgress;
End();
}
} }
else else
{ {
m_ActualDuration = (int)((Time.time - startTime) * 1000) - delay;
m_CurrDetailProgress += delta; m_CurrDetailProgress += delta;
if (m_CurrDetailProgress >= m_DestDetailProgress)
{
m_CurrDetailProgress = m_DestDetailProgress;
End();
}
} }
} }
internal void CheckSymbol(float delta, float dest) internal float GetCurrAnimationDuration()
{ {
m_CurrSymbolProgress += delta; if (m_FadeOut) return m_FadeOutDuration > 0 ? m_FadeOutDuration / 1000 : 1;
if (m_CurrSymbolProgress > dest) m_CurrSymbolProgress = dest; else return m_FadeInDuration > 0 ? m_FadeInDuration / 1000 : 1;
}
internal float CheckBarProgress(int dataIndex, float barHig)
{
//if (!m_IsInit) return barHig;
var destHig = m_FadeOut ? barHig : 0;
if (IsInDelay() || IsFinish() || m_IsEnd)
{
return m_FadeOuted ? 0 : barHig;
}
else if (m_IsPause)
{
return GetDataState(dataIndex, destHig);
}
else
{
var duration = GetCurrAnimationDuration();
var delta = barHig / duration * Time.deltaTime;
var currHig = GetDataState(dataIndex, destHig) + (m_FadeOut ? -delta : delta);
SetDataState(dataIndex, currHig);
if (m_FadeOut)
{
if (currHig <= 0)
{
End();
currHig = 0;
}
}
else if (Mathf.Abs(currHig) >= Mathf.Abs(barHig))
{
End();
currHig = barHig;
}
return currHig;
}
}
internal void CheckSymbol(float dest)
{
if (!enable || m_IsEnd || m_IsPause || !m_IsInit) return;
if (IsInDelay()) return;
var duration = GetCurrAnimationDuration();
var delta = dest / duration * Time.deltaTime;
if (m_FadeOut)
{
m_CurrSymbolProgress -= delta;
if (m_CurrSymbolProgress < 0) m_CurrSymbolProgress = 0;
}
else
{
m_CurrSymbolProgress += delta;
if (m_CurrSymbolProgress > dest) m_CurrSymbolProgress = dest;
}
} }
public float GetSysmbolSize(float dest) public float GetSysmbolSize(float dest)
@@ -212,7 +349,8 @@ namespace XCharts
#if UNITY_EDITOR #if UNITY_EDITOR
if (!Application.isPlaying) return dest; if (!Application.isPlaying) return dest;
#endif #endif
if (!enable || m_IsEnd) return dest; if (!enable) return dest;
if (m_IsEnd) return m_FadeOut ? 0 : dest;
return m_CurrSymbolProgress; return m_CurrSymbolProgress;
} }
@@ -246,8 +384,13 @@ namespace XCharts
public float GetUpdateAnimationDuration() public float GetUpdateAnimationDuration()
{ {
if (m_Enable && m_UpdateAnimation && IsFinish()) return m_UpdateDuration; if (m_Enable && m_DataChangeEnable && IsFinish()) return m_DataChangeDuration;
else return 0; else return 0;
} }
public bool HasFadeOut()
{
return enable && m_FadeOuted && m_IsEnd;
}
} }
} }

View File

@@ -1,4 +1,3 @@
using System.Threading;
/******************************************/ /******************************************/
/* */ /* */
/* Copyright (c) 2018 monitor1394 */ /* Copyright (c) 2018 monitor1394 */
@@ -18,11 +17,18 @@ namespace XCharts
[Serializable] [Serializable]
public class TextStyle : SubComponent, IEquatable<TextStyle> public class TextStyle : SubComponent, IEquatable<TextStyle>
{ {
[SerializeField] private Font m_Font;
[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;
[SerializeField] private Color m_BackgroundColor = Color.clear;
[SerializeField] private int m_FontSize = 18; [SerializeField] private int m_FontSize = 18;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal; [SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private float m_LineSpacing = 1f;
[SerializeField] private float m_PaddingLeft = 0f;
[SerializeField] private float m_PaddingRight = 0f;
[SerializeField] private float m_PaddingTop = 0f;
[SerializeField] private float m_PaddingBottom = 0f;
/// <summary> /// <summary>
/// Rotation of text. /// Rotation of text.
@@ -43,6 +49,16 @@ namespace XCharts
/// </summary> /// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } } public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary> /// <summary>
/// the color of text.
/// 文本的背景颜色。
/// </summary>
public Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
/// <summary>
/// the font of text.
/// 文本字体
/// </summary>
public Font font { get { return m_Font; } set { m_Font = value; } }
/// <summary>
/// font size. /// font size.
/// 文本字体大小。 /// 文本字体大小。
/// </summary> /// </summary>
@@ -52,6 +68,11 @@ namespace XCharts
/// 文本字体的风格。 /// 文本字体的风格。
/// </summary> /// </summary>
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } } public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
/// <summary>
/// text line spacing.
/// 行间距。
/// </summary>
public float lineSpacing { get { return m_LineSpacing; } set { m_LineSpacing = value; } }
public TextStyle() public TextStyle()
{ {
@@ -88,8 +109,10 @@ namespace XCharts
this.fontSize = style.fontSize; this.fontSize = style.fontSize;
this.fontStyle = style.fontStyle; this.fontStyle = style.fontStyle;
this.color = style.color; this.color = style.color;
this.backgroundColor = style.backgroundColor;
this.rotate = style.rotate; this.rotate = style.rotate;
this.offset = style.offset; this.offset = style.offset;
this.lineSpacing = style.lineSpacing;
} }
public TextStyle Clone() public TextStyle Clone()
@@ -97,9 +120,11 @@ namespace XCharts
var textStyle = new TextStyle(); var textStyle = new TextStyle();
textStyle.rotate = rotate; textStyle.rotate = rotate;
textStyle.color = color; textStyle.color = color;
textStyle.backgroundColor = backgroundColor;
textStyle.fontSize = fontSize; textStyle.fontSize = fontSize;
textStyle.fontStyle = fontStyle; textStyle.fontStyle = fontStyle;
textStyle.offset = offset; textStyle.offset = offset;
textStyle.lineSpacing = lineSpacing;
return textStyle; return textStyle;
} }
@@ -129,6 +154,8 @@ namespace XCharts
fontSize == other.fontSize && fontSize == other.fontSize &&
fontStyle == other.fontStyle && fontStyle == other.fontStyle &&
offset == other.offset && offset == other.offset &&
lineSpacing == other.lineSpacing &&
ChartHelper.IsValueEqualsColor(m_BackgroundColor, other.backgroundColor) &&
ChartHelper.IsValueEqualsColor(m_Color, other.color); ChartHelper.IsValueEqualsColor(m_Color, other.color);
} }

View File

@@ -64,7 +64,7 @@ namespace XCharts
serie.center[1] = 0.5f; serie.center[1] = 0.5f;
serie.radius[0] = 80; serie.radius[0] = 80;
serie.splitNumber = 5; serie.splitNumber = 5;
serie.animation.updateAnimation = true; serie.animation.dataChangeEnable = true;
serie.titleStyle.show = true; serie.titleStyle.show = true;
serie.titleStyle.textStyle.offset = new Vector2(0, 20); serie.titleStyle.textStyle.offset = new Vector2(0, 20);
serie.label.show = true; serie.label.show = true;
@@ -85,7 +85,7 @@ namespace XCharts
for (int i = 0; i < m_Series.Count; i++) for (int i = 0; i < m_Series.Count; i++)
{ {
var serie = m_Series.list[i]; var serie = m_Series.list[i];
var serieLabel = serie.gaugeAxis.axisLabel; var serieLabel = serie.gaugeAxis.axisLabel;
serie.gaugeAxis.ClearLabelObject(); serie.gaugeAxis.ClearLabelObject();
var count = serie.splitNumber > 36 ? 36 : (serie.splitNumber + 1); var count = serie.splitNumber > 36 ? 36 : (serie.splitNumber + 1);
@@ -103,7 +103,7 @@ namespace XCharts
item.SetIconActive(false); item.SetIconActive(false);
serie.gaugeAxis.AddLabelObject(item); serie.gaugeAxis.AddLabelObject(item);
} }
UpdateAxisLabel(serie); UpdateAxisLabel(serie);
} }
} }
@@ -130,14 +130,15 @@ namespace XCharts
private void DrawGauge(VertexHelper vh, Serie serie) private void DrawGauge(VertexHelper vh, Serie serie)
{ {
serie.UpdateCenter(chartWidth, chartHeight); serie.UpdateCenter(chartWidth, chartHeight);
var destAngle = GetCurrAngle(serie, true); var destAngle = GetCurrAngle(serie, true);
serie.animation.InitProgress(0, serie.startAngle, destAngle); serie.animation.InitProgress(0, serie.startAngle, destAngle);
//var currAngle = serie.animation.GetCurrDetail();
var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail(); var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail();
DrawProgressBar(vh, serie, currAngle); DrawProgressBar(vh, serie, currAngle);
DrawStageColor(vh, serie); DrawStageColor(vh, serie);
DrawSplitLine(vh, serie); DrawLineStyle(vh, serie);
DrawAxisTick(vh, serie); DrawAxisTick(vh, serie);
DrawPointer(vh, serie, currAngle); DrawPointer(vh, serie, currAngle);
UpdateTitle(serie); UpdateTitle(serie);
@@ -147,9 +148,7 @@ namespace XCharts
CheckAnimation(serie); CheckAnimation(serie);
if (!serie.animation.IsFinish()) if (!serie.animation.IsFinish())
{ {
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1; serie.animation.CheckProgress(destAngle - serie.startAngle);
float speed = (destAngle - serie.startAngle) / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
RefreshChart(); RefreshChart();
} }
else if (NeedRefresh(serie)) else if (NeedRefresh(serie))
@@ -215,7 +214,7 @@ namespace XCharts
ChartDrawer.DrawPolygon(vh, p1, p3, p2, p4, pointerColor); ChartDrawer.DrawPolygon(vh, p1, p3, p2, p4, pointerColor);
} }
private void DrawSplitLine(VertexHelper vh, Serie serie) private void DrawLineStyle(VertexHelper vh, Serie serie)
{ {
if (serie.gaugeType != GaugeType.Pointer) return; if (serie.gaugeType != GaugeType.Pointer) return;
if (!serie.gaugeAxis.show || !serie.gaugeAxis.splitLine.show) return; if (!serie.gaugeAxis.show || !serie.gaugeAxis.splitLine.show) return;
@@ -405,6 +404,10 @@ namespace XCharts
private float GetCurrAngle(Serie serie, bool dest) private float GetCurrAngle(Serie serie, bool dest)
{ {
if (serie.animation.HasFadeOut())
{
return serie.animation.GetCurrDetail();
}
float rangeValue = serie.max - serie.min; float rangeValue = serie.max - serie.min;
float rangeAngle = serie.endAngle - serie.startAngle; float rangeAngle = serie.endAngle - serie.startAngle;
float value = 0; float value = 0;

View File

@@ -85,7 +85,7 @@ namespace XCharts
} }
#endif #endif
protected override void RefreshTooltip() protected override void UpdateTooltip()
{ {
var xData = m_Tooltip.runtimeXValues[0]; var xData = m_Tooltip.runtimeXValues[0];
var yData = m_Tooltip.runtimeYValues[0]; var yData = m_Tooltip.runtimeYValues[0];

View File

@@ -0,0 +1,220 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
internal static class LegendHelper
{
public static Color GetContentColor(Legend legend, ThemeInfo themeInfo, bool active)
{
var textStyle = legend.textStyle;
if (active) return textStyle.color != Color.clear ? textStyle.color : (Color)themeInfo.legendTextColor;
else return (Color)themeInfo.legendUnableColor;
}
public static Color GetIconColor(Legend legend, int readIndex, ThemeInfo themeInfo, bool active)
{
if (active)
{
if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
return (Color)themeInfo.GetColor(readIndex);
else
return Color.white;
}
else return (Color)themeInfo.legendUnableColor;
}
public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent, ThemeInfo themeInfo,
string content, Color itemColor, bool active)
{
var objName = i + "_" + legendName;
var anchorMin = new Vector2(0, 0.5f);
var anchorMax = new Vector2(0, 0.5f);
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 font = textStyle.font ? textStyle.font : themeInfo.font;
var contentColor = GetContentColor(legend, themeInfo, active);
var objAnchorMin = legend.location.runtimeAnchorMin;
var objAnchorMax = legend.location.runtimeAnchorMax;
var objPivot = legend.location.runtimePivot;
var btnObj = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta);
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);
Text txt = ChartHelper.AddTextObject("Text", contentObj.transform, font, contentColor,
TextAnchor.MiddleLeft, anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize,
textStyle.rotate, textStyle.fontStyle, textStyle.lineSpacing);
var item = new LegendItem();
item.index = i;
item.name = objName;
item.legendName = legendName;
item.SetObject(btnObj);
item.SetIconSize(legend.itemWidth, legend.itemHeight);
item.SetIconColor(itemColor);
item.SetIconImage(legend.GetIcon(i));
item.SetContentPosition(textStyle.offsetv3);
item.SetContent(content);
item.SetContentBackgroundColor(textStyle.backgroundColor);
return item;
}
public static void ResetItemPosition(Legend legend)
{
var startX = 0f;
var startY = 0f;
var currWidth = 0f;
var currHeight = 0f;
switch (legend.orient)
{
case Orient.Vertical:
switch (legend.location.align)
{
case Location.Align.TopCenter:
startX = legend.runtimeWidth / 2;
currHeight = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(-startX + item.width / 2, -currHeight));
currHeight += item.height + legend.itemGap;
}
break;
case Location.Align.TopLeft:
currHeight = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(0, -currHeight));
currHeight += item.height + legend.itemGap;
}
break;
case Location.Align.TopRight:
currHeight = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(item.width - legend.runtimeWidth, -currHeight));
currHeight += item.height + legend.itemGap;
}
break;
case Location.Align.Center:
startX = legend.runtimeWidth / 2;
currHeight = legend.runtimeHeight;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(-startX + item.width / 2, currHeight - item.height));
currHeight -= item.height + legend.itemGap;
}
break;
case Location.Align.CenterLeft:
currHeight = legend.runtimeHeight;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(0, currHeight - item.height));
currHeight -= item.height + legend.itemGap;
}
break;
case Location.Align.CenterRight:
currHeight = legend.runtimeHeight;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(item.width - legend.runtimeWidth, currHeight - item.height));
currHeight -= item.height + legend.itemGap;
}
break;
case Location.Align.BottomCenter:
startX = legend.runtimeWidth / 2;
currHeight = legend.runtimeHeight;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(-startX + item.width / 2, currHeight - item.height));
currHeight -= item.height + legend.itemGap;
}
break;
case Location.Align.BottomLeft:
currHeight = legend.runtimeHeight;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(0, currHeight - item.height));
currHeight -= item.height + legend.itemGap;
}
break;
case Location.Align.BottomRight:
currHeight = legend.runtimeHeight;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(item.width - legend.runtimeWidth, currHeight - item.height));
currHeight -= item.height + legend.itemGap;
}
break;
}
break;
case Orient.Horizonal:
switch (legend.location.align)
{
case Location.Align.TopLeft:
case Location.Align.CenterLeft:
case Location.Align.BottomLeft:
currWidth = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(currWidth, 0));
currWidth += item.width + legend.itemGap;
}
break;
case Location.Align.TopCenter:
case Location.Align.Center:
case Location.Align.BottomCenter:
startX = legend.runtimeWidth / 2;
currWidth = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(-startX + item.width / 2 + currWidth, 0));
currWidth += item.width + legend.itemGap;
}
break;
case Location.Align.TopRight:
case Location.Align.CenterRight:
case Location.Align.BottomRight:
startX = -legend.runtimeWidth;
currWidth = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
item.SetPosition(new Vector3(startX + currWidth + item.width, 0));
currWidth += item.width + legend.itemGap;
}
break;
break;
}
break;
}
}
}
}

View File

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

View File

@@ -65,7 +65,7 @@ namespace XCharts
[NonSerialized] protected bool m_ReinitLabel = false; [NonSerialized] protected bool m_ReinitLabel = false;
[NonSerialized] protected bool m_ReinitTitle = false; [NonSerialized] protected bool m_ReinitTitle = false;
[NonSerialized] protected bool m_CheckAnimation = false; [NonSerialized] protected bool m_CheckAnimation = false;
[NonSerialized] protected bool m_IsPlayingStartAnimation = false; [NonSerialized] protected bool m_IsPlayingAnimation = false;
[NonSerialized] protected List<string> m_LegendRealShowName = new List<string>(); [NonSerialized] protected List<string> m_LegendRealShowName = new List<string>();
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } } protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
@@ -92,8 +92,8 @@ namespace XCharts
InitSerieLabel(); InitSerieLabel();
InitSerieTitle(); InitSerieTitle();
InitTooltip(); InitTooltip();
m_Series.AnimationStop(); m_Series.AnimationReset();
m_Series.AnimationStart(); m_Series.AnimationFadeIn();
} }
protected override void Start() protected override void Start()
@@ -142,6 +142,11 @@ namespace XCharts
m_Series = Series.defaultSeries; m_Series = Series.defaultSeries;
Awake(); Awake();
} }
protected override void OnValidate()
{
//TODO:
}
#endif #endif
protected override void OnDestroy() protected override void OnDestroy()
@@ -170,8 +175,8 @@ namespace XCharts
Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform, Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform,
m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot, m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot,
new Vector2(titleWid, m_Title.textStyle.fontSize), m_Title.textStyle.fontSize, m_Title.textStyle.rotate, new Vector2(titleWid, m_Title.textStyle.fontSize), m_Title.textStyle.fontSize,
m_Title.textStyle.fontStyle); m_Title.textStyle.rotate, m_Title.textStyle.fontStyle, m_Title.textStyle.lineSpacing);
titleText.alignment = anchor; titleText.alignment = anchor;
titleText.gameObject.SetActive(m_Title.show); titleText.gameObject.SetActive(m_Title.show);
@@ -181,7 +186,7 @@ namespace XCharts
Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform, Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform,
m_ThemeInfo.font, m_ThemeInfo.titleSubTextColor, anchor, anchorMin, anchorMax, pivot, m_ThemeInfo.font, m_ThemeInfo.titleSubTextColor, anchor, anchorMin, anchorMax, pivot,
new Vector2(titleWid, m_Title.subTextStyle.fontSize), m_Title.subTextStyle.fontSize, new Vector2(titleWid, m_Title.subTextStyle.fontSize), m_Title.subTextStyle.fontSize,
m_Title.subTextStyle.rotate, m_Title.subTextStyle.fontStyle); m_Title.subTextStyle.rotate, m_Title.subTextStyle.fontStyle, m_Title.subTextStyle.lineSpacing);
subText.alignment = anchor; subText.alignment = anchor;
subText.gameObject.SetActive(m_Title.show && !string.IsNullOrEmpty(m_Title.subText)); subText.gameObject.SetActive(m_Title.show && !string.IsNullOrEmpty(m_Title.subText));
@@ -230,21 +235,18 @@ namespace XCharts
string legendName = m_Legend.GetFormatterContent(datas[i]); string legendName = m_Legend.GetFormatterContent(datas[i]);
var readIndex = m_LegendRealShowName.IndexOf(datas[i]); var readIndex = m_LegendRealShowName.IndexOf(datas[i]);
var objName = s_LegendObjectName + "_" + i + "_" + datas[i]; var objName = s_LegendObjectName + "_" + i + "_" + datas[i];
Button btn = ChartHelper.AddButtonObject(objName, legendObject.transform, var active = IsActiveByLegend(datas[i]);
m_ThemeInfo.font, m_Legend.itemFontSize, m_ThemeInfo.legendTextColor, anchor, var bgColor = LegendHelper.GetIconColor(m_Legend, readIndex, themeInfo, active);
anchorMin, anchorMax, pivot, new Vector2(m_Legend.itemWidth, m_Legend.itemHeight)); var item = LegendHelper.AddLegendItem(m_Legend, i, datas[i], legendObject.transform, m_ThemeInfo,
var bgColor = IsActiveByLegend(datas[i]) ? legendName, bgColor, active);
m_ThemeInfo.GetColor(readIndex) : m_ThemeInfo.legendUnableColor; m_Legend.SetButton(legendName, item, totalLegend);
m_Legend.SetButton(legendName, btn, totalLegend); ChartHelper.ClearEventListener(item.button.gameObject);
m_Legend.UpdateButtonColor(legendName, bgColor); ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) =>
btn.GetComponentInChildren<Text>().text = legendName;
ChartHelper.ClearEventListener(btn.gameObject);
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
{ {
if (data.selectedObject == null || m_Legend.selectedMode == Legend.SelectedMode.None) return; if (data.selectedObject == null || m_Legend.selectedMode == Legend.SelectedMode.None) return;
var temp = data.selectedObject.name.Split('_'); var temp = data.selectedObject.name.Split('_');
string selectedName = temp[2]; string selectedName = temp[1];
int clickedIndex = int.Parse(temp[1]); int clickedIndex = int.Parse(temp[0]);
if (m_Legend.selectedMode == Legend.SelectedMode.Multiple) if (m_Legend.selectedMode == Legend.SelectedMode.Multiple)
{ {
OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName)); OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName));
@@ -261,27 +263,27 @@ namespace XCharts
for (int n = 0; n < btnList.Length; n++) for (int n = 0; n < btnList.Length; n++)
{ {
temp = btnList[n].name.Split('_'); temp = btnList[n].name.Split('_');
selectedName = temp[2]; selectedName = btnList[n].legendName;
var index = int.Parse(temp[1]); var index = btnList[n].index;
OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false); OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false);
} }
} }
} }
}); });
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerEnter, (data) => ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerEnter, (data) =>
{ {
if (btn == null) return; if (item.button == null) return;
var temp = btn.name.Split('_'); var temp = item.button.name.Split('_');
string selectedName = temp[2]; string selectedName = temp[1];
int index = int.Parse(temp[1]); int index = int.Parse(temp[0]);
OnLegendButtonEnter(index, selectedName); OnLegendButtonEnter(index, selectedName);
}); });
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerExit, (data) => ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerExit, (data) =>
{ {
if (btn == null) return; if (item.button == null) return;
var temp = btn.name.Split('_'); var temp = item.button.name.Split('_');
string selectedName = temp[2]; string selectedName = temp[1];
int index = int.Parse(temp[1]); int index = int.Parse(temp[0]);
OnLegendButtonExit(index, selectedName); OnLegendButtonExit(index, selectedName);
}); });
} }
@@ -292,6 +294,7 @@ namespace XCharts
OnLegendButtonClick(n, m_LegendRealShowName[n], n == 0 ? true : false); OnLegendButtonClick(n, m_LegendRealShowName[n], n == 0 ? true : false);
} }
} }
LegendHelper.ResetItemPosition(m_Legend);
} }
private void InitSerieLabel() private void InitSerieLabel()
@@ -349,8 +352,9 @@ namespace XCharts
var pivot = new Vector2(0.5f, 0.5f); var pivot = new Vector2(0.5f, 0.5f);
var fontSize = 10; var fontSize = 10;
var sizeDelta = new Vector2(50, fontSize + 2); var sizeDelta = new Vector2(50, fontSize + 2);
var txt = ChartHelper.AddTextObject("title_" + i, titleObject.transform, m_ThemeInfo.font, color, TextAnchor.MiddleCenter, var txt = ChartHelper.AddTextObject("title_" + i, titleObject.transform, m_ThemeInfo.font, color,
anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize, textStyle.rotate, textStyle.fontStyle); TextAnchor.MiddleCenter, anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize, textStyle.rotate,
textStyle.fontStyle, textStyle.lineSpacing);
txt.text = ""; txt.text = "";
txt.transform.localPosition = new Vector2(0, 0); txt.transform.localPosition = new Vector2(0, 0);
txt.transform.localEulerAngles = Vector2.zero; txt.transform.localEulerAngles = Vector2.zero;
@@ -372,9 +376,10 @@ namespace XCharts
tooltipObject.transform.localPosition = Vector3.zero; tooltipObject.transform.localPosition = Vector3.zero;
DestroyImmediate(tooltipObject.GetComponent<Image>()); DestroyImmediate(tooltipObject.GetComponent<Image>());
var parent = tooltipObject.transform; var parent = tooltipObject.transform;
var textStyle = m_Tooltip.textStyle;
ChartHelper.HideAllObject(tooltipObject.transform); ChartHelper.HideAllObject(tooltipObject.transform);
GameObject content = ChartHelper.AddTooltipContent("content", parent, m_ThemeInfo.font, GameObject content = ChartHelper.AddTooltipContent("content", parent, m_ThemeInfo.font,
m_Tooltip.fontSize, m_Tooltip.fontStyle); textStyle.fontSize, textStyle.fontStyle, textStyle.lineSpacing);
m_Tooltip.SetObj(tooltipObject); m_Tooltip.SetObj(tooltipObject);
m_Tooltip.SetContentObj(content); m_Tooltip.SetContentObj(content);
m_Tooltip.SetContentBackgroundColor(m_ThemeInfo.tooltipBackgroundColor); m_Tooltip.SetContentBackgroundColor(m_ThemeInfo.tooltipBackgroundColor);
@@ -562,7 +567,7 @@ namespace XCharts
if (!m_CheckAnimation) if (!m_CheckAnimation)
{ {
m_CheckAnimation = true; m_CheckAnimation = true;
m_Series.AnimationStart(); m_Series.AnimationFadeIn();
} }
} }
@@ -687,7 +692,7 @@ namespace XCharts
return show; return show;
} }
protected virtual void RefreshTooltip() protected virtual void UpdateTooltip()
{ {
} }
@@ -787,6 +792,31 @@ namespace XCharts
} }
} }
protected void DrawLineStyle(VertexHelper vh, LineStyle lineStyle,
Vector3 startPos, Vector3 endPos, Color color)
{
var type = lineStyle.type;
var width = lineStyle.width;
switch (type)
{
case LineStyle.Type.Dashed:
ChartDrawer.DrawDashLine(vh, startPos, endPos, width, color);
break;
case LineStyle.Type.Dotted:
ChartDrawer.DrawDotLine(vh, startPos, endPos, width, color);
break;
case LineStyle.Type.Solid:
ChartDrawer.DrawLine(vh, startPos, endPos, width, color);
break;
case LineStyle.Type.DashDot:
ChartDrawer.DrawDashDotLine(vh, startPos, endPos, width, color);
break;
case LineStyle.Type.DashDotDot:
ChartDrawer.DrawDashDotDotLine(vh, startPos, endPos, width, color);
break;
}
}
protected void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData) protected void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData)
{ {
var labelHalfWid = serieData.GetLabelWidth() / 2; var labelHalfWid = serieData.GetLabelWidth() / 2;

View File

@@ -141,7 +141,7 @@ namespace XCharts
{ {
base.DrawChart(vh); base.DrawChart(vh);
if (!m_CheckMinMaxValue) return; if (!m_CheckMinMaxValue) return;
m_IsPlayingStartAnimation = false; m_IsPlayingAnimation = false;
bool yCategory = m_YAxises[0].IsCategory() || m_YAxises[1].IsCategory(); bool yCategory = m_YAxises[0].IsCategory() || m_YAxises[1].IsCategory();
m_Series.GetStackSeries(ref m_StackSeries); m_Series.GetStackSeries(ref m_StackSeries);
int seriesCount = m_StackSeries.Count; int seriesCount = m_StackSeries.Count;
@@ -194,7 +194,7 @@ namespace XCharts
if (!IsInCooridate(local)) if (!IsInCooridate(local))
{ {
m_Tooltip.ClearValue(); m_Tooltip.ClearValue();
RefreshTooltip(); UpdateTooltip();
} }
else else
{ {
@@ -306,7 +306,7 @@ namespace XCharts
if (m_Tooltip.IsSelected()) if (m_Tooltip.IsSelected())
{ {
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25)); m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
RefreshTooltip(); UpdateTooltip();
if (m_Tooltip.IsDataIndexChanged() || m_Tooltip.type == Tooltip.Type.Corss) if (m_Tooltip.IsDataIndexChanged() || m_Tooltip.type == Tooltip.Type.Corss)
{ {
m_Tooltip.UpdateLastDataIndex(); m_Tooltip.UpdateLastDataIndex();
@@ -321,9 +321,9 @@ namespace XCharts
} }
protected StringBuilder sb = new StringBuilder(100); protected StringBuilder sb = new StringBuilder(100);
protected override void RefreshTooltip() protected override void UpdateTooltip()
{ {
base.RefreshTooltip(); base.UpdateTooltip();
int index; int index;
Axis tempAxis; Axis tempAxis;
bool isCartesian = IsValue(); bool isCartesian = IsValue();
@@ -846,8 +846,8 @@ namespace XCharts
if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue) if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue)
{ {
m_CheckMinMaxValue = true; m_CheckMinMaxValue = true;
axis.runtimeMinValue = tempMinValue; axis.UpdateMinValue(tempMinValue, !m_IsPlayingAnimation);
axis.runtimeMaxValue = tempMaxValue; axis.UpdateMaxValue(tempMaxValue, !m_IsPlayingAnimation);
axis.runtimeZeroXOffset = 0; axis.runtimeZeroXOffset = 0;
axis.runtimeZeroYOffset = 0; axis.runtimeZeroYOffset = 0;
if (tempMinValue != 0 || tempMaxValue != 0) if (tempMinValue != 0 || tempMaxValue != 0)
@@ -873,7 +873,7 @@ namespace XCharts
RefreshChart(); RefreshChart();
} }
} }
if (axis.IsValueChanging(500) && !m_IsPlayingStartAnimation) if (axis.IsValueChanging(500) && !m_IsPlayingAnimation)
{ {
float coordinateWidth = axis is XAxis ? this.coordinateWidth : coordinateHeight; float coordinateWidth = axis is XAxis ? this.coordinateWidth : coordinateHeight;
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar); var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
@@ -980,7 +980,7 @@ namespace XCharts
{ {
if (yAxis.splitLine.NeedShow(i)) if (yAxis.splitLine.NeedShow(i))
{ {
DrawSplitLine(vh, yAxis.splitLine.lineStyle, new Vector3(coordinateX, pY), DrawLineStyle(vh, yAxis.splitLine.lineStyle, new Vector3(coordinateX, pY),
new Vector3(coordinateX + coordinateWidth, pY), yAxis.splitLine.GetColor(m_ThemeInfo)); new Vector3(coordinateX + coordinateWidth, pY), yAxis.splitLine.GetColor(m_ThemeInfo));
} }
} }
@@ -1070,7 +1070,7 @@ namespace XCharts
{ {
if (xAxis.splitLine.NeedShow(i)) if (xAxis.splitLine.NeedShow(i))
{ {
DrawSplitLine(vh, xAxis.splitLine.lineStyle, new Vector3(pX, coordinateY), DrawLineStyle(vh, xAxis.splitLine.lineStyle, new Vector3(pX, coordinateY),
new Vector3(pX, coordinateY + coordinateHeight), xAxis.splitLine.GetColor(m_ThemeInfo)); new Vector3(pX, coordinateY + coordinateHeight), xAxis.splitLine.GetColor(m_ThemeInfo));
} }
} }
@@ -1230,31 +1230,6 @@ namespace XCharts
} }
} }
protected void DrawSplitLine(VertexHelper vh, LineStyle lineStyle,
Vector3 startPos, Vector3 endPos, Color color)
{
var type = lineStyle.type;
var width = lineStyle.width;
switch (type)
{
case LineStyle.Type.Dashed:
ChartDrawer.DrawDashLine(vh, startPos, endPos, width, color);
break;
case LineStyle.Type.Dotted:
ChartDrawer.DrawDotLine(vh, startPos, endPos, width, color);
break;
case LineStyle.Type.Solid:
ChartDrawer.DrawLine(vh, startPos, endPos, width, color);
break;
case LineStyle.Type.DashDot:
ChartDrawer.DrawDashDotLine(vh, startPos, endPos, width, color);
break;
case LineStyle.Type.DashDotDot:
ChartDrawer.DrawDashDotDotLine(vh, startPos, endPos, width, color);
break;
}
}
protected void DrawXTooltipIndicator(VertexHelper vh) protected void DrawXTooltipIndicator(VertexHelper vh)
{ {
if (!m_Tooltip.show || !m_Tooltip.IsSelected()) return; if (!m_Tooltip.show || !m_Tooltip.IsSelected()) return;
@@ -1275,12 +1250,12 @@ namespace XCharts
if (xAxis.IsValue()) pX = m_Tooltip.runtimePointerPos.x; if (xAxis.IsValue()) pX = m_Tooltip.runtimePointerPos.x;
Vector2 sp = new Vector2(pX, coordinateY); Vector2 sp = new Vector2(pX, coordinateY);
Vector2 ep = new Vector2(pX, coordinateY + coordinateHeight); Vector2 ep = new Vector2(pX, coordinateY + coordinateHeight);
DrawSplitLine(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo)); DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo));
if (m_Tooltip.type == Tooltip.Type.Corss) if (m_Tooltip.type == Tooltip.Type.Corss)
{ {
sp = new Vector2(coordinateX, m_Tooltip.runtimePointerPos.y); sp = new Vector2(coordinateX, m_Tooltip.runtimePointerPos.y);
ep = new Vector2(coordinateX + coordinateWidth, m_Tooltip.runtimePointerPos.y); ep = new Vector2(coordinateX + coordinateWidth, m_Tooltip.runtimePointerPos.y);
DrawSplitLine(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo)); DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo));
} }
break; break;
case Tooltip.Type.Shadow: case Tooltip.Type.Shadow:
@@ -1318,12 +1293,12 @@ namespace XCharts
float pY = coordinateY + m_Tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0); float pY = coordinateY + m_Tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0);
Vector2 sp = new Vector2(coordinateX, pY); Vector2 sp = new Vector2(coordinateX, pY);
Vector2 ep = new Vector2(coordinateX + coordinateWidth, pY); Vector2 ep = new Vector2(coordinateX + coordinateWidth, pY);
DrawSplitLine(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo)); DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo));
if (m_Tooltip.type == Tooltip.Type.Corss) if (m_Tooltip.type == Tooltip.Type.Corss)
{ {
sp = new Vector2(coordinateX, m_Tooltip.runtimePointerPos.y); sp = new Vector2(coordinateX, m_Tooltip.runtimePointerPos.y);
ep = new Vector2(coordinateX + coordinateWidth, m_Tooltip.runtimePointerPos.y); ep = new Vector2(coordinateX + coordinateWidth, m_Tooltip.runtimePointerPos.y);
DrawSplitLine(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo)); DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo));
} }
break; break;
case Tooltip.Type.Shadow: case Tooltip.Type.Shadow:

View File

@@ -18,6 +18,7 @@ namespace XCharts
protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig) protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
{ {
if (!IsActive(serie.name)) return; if (!IsActive(serie.name)) return;
if (serie.animation.HasFadeOut()) return;
var xAxis = m_XAxises[serie.axisIndex]; var xAxis = m_XAxises[serie.axisIndex];
var yAxis = m_YAxises[serie.axisIndex]; var yAxis = m_YAxises[serie.axisIndex];
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count]; if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
@@ -44,9 +45,9 @@ namespace XCharts
} }
var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar); var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
bool dataChanging = false; bool dataChanging = false;
float updateDuration = serie.animation.GetUpdateAnimationDuration(); float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
float xMinValue = xAxis.GetCurrMinValue(updateDuration); float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
float xMaxValue = xAxis.GetCurrMaxValue(updateDuration); float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
for (int i = serie.minShow; i < maxCount; i++) for (int i = serie.minShow; i < maxCount; i++)
{ {
if (i >= seriesHig.Count) if (i >= seriesHig.Count)
@@ -55,7 +56,7 @@ namespace XCharts
} }
var serieData = showData[i]; var serieData = showData[i];
serieData.canShowLabel = true; serieData.canShowLabel = true;
float value = showData[i].GetCurrData(1, updateDuration); float value = showData[i].GetCurrData(1, dataChangeDuration);
if (showData[i].IsDataChanged()) dataChanging = true; if (showData[i].IsDataChanged()) dataChanging = true;
float pX = seriesHig[i] + coordinateX + xAxis.runtimeZeroXOffset + yAxis.axisLine.width; float pX = seriesHig[i] + coordinateX + xAxis.runtimeZeroXOffset + yAxis.axisLine.width;
float pY = coordinateY + +i * categoryWidth; float pY = coordinateY + +i * categoryWidth;
@@ -117,23 +118,11 @@ namespace XCharts
private float CheckAnimation(Serie serie, int dataIndex, float barHig) private float CheckAnimation(Serie serie, int dataIndex, float barHig)
{ {
float currHig = barHig; float currHig = serie.animation.CheckBarProgress(dataIndex,barHig);
if (!serie.animation.IsFinish()) if (!serie.animation.IsFinish())
{ {
if (serie.animation.IsInDelay()) currHig = 0;
else
{
var speed = serie.animation.duration > 0 ? barHig / serie.animation.duration * 1000 : barHig;
currHig = serie.animation.GetDataState(dataIndex) + speed * Time.deltaTime;
serie.animation.SetDataState(dataIndex, currHig);
if (Mathf.Abs(currHig) >= Mathf.Abs(barHig))
{
serie.animation.End();
currHig = barHig;
}
}
RefreshChart(); RefreshChart();
m_IsPlayingStartAnimation = true; m_IsPlayingAnimation = true;
} }
return currHig; return currHig;
} }
@@ -141,6 +130,7 @@ namespace XCharts
protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig) protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
{ {
if (!IsActive(serie.name)) return; if (!IsActive(serie.name)) return;
if (serie.animation.HasFadeOut()) return;
var showData = serie.GetDataList(m_DataZoom); var showData = serie.GetDataList(m_DataZoom);
var yAxis = m_YAxises[serie.axisIndex]; var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex]; var xAxis = m_XAxises[serie.axisIndex];
@@ -167,16 +157,16 @@ namespace XCharts
var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar); var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
bool dataChanging = false; bool dataChanging = false;
float updateDuration = serie.animation.GetUpdateAnimationDuration(); float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
float yMinValue = yAxis.GetCurrMinValue(updateDuration); float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
float yMaxValue = yAxis.GetCurrMaxValue(updateDuration); float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
for (int i = serie.minShow; i < maxCount; i++) for (int i = serie.minShow; i < maxCount; i++)
{ {
if (i >= seriesHig.Count) if (i >= seriesHig.Count)
{ {
seriesHig.Add(0); seriesHig.Add(0);
} }
float value = showData[i].GetCurrData(1, updateDuration); float value = showData[i].GetCurrData(1, dataChangeDuration);
if (showData[i].IsDataChanged()) dataChanging = true; if (showData[i].IsDataChanged()) dataChanging = true;
float pX = coordinateX + i * categoryWidth; float pX = coordinateX + i * categoryWidth;
float zeroY = coordinateY + yAxis.runtimeZeroYOffset; float zeroY = coordinateY + yAxis.runtimeZeroYOffset;

View File

@@ -116,6 +116,7 @@ namespace XCharts
protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie) protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
{ {
if (serie.animation.HasFadeOut()) return;
var yAxis = m_YAxises[serie.axisIndex]; var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex]; var xAxis = m_XAxises[serie.axisIndex];
var xCount = xAxis.data.Count; var xCount = xAxis.data.Count;
@@ -135,7 +136,7 @@ namespace XCharts
serie.dataPoints.Clear(); serie.dataPoints.Clear();
serie.animation.InitProgress(1, 0, xCount); serie.animation.InitProgress(1, 0, xCount);
var animationIndex = serie.animation.GetCurrIndex(); var animationIndex = serie.animation.GetCurrIndex();
var updateDuration = serie.animation.GetUpdateAnimationDuration(); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var dataChanging = false; var dataChanging = false;
for (int i = 0; i < xCount; i++) for (int i = 0; i < xCount; i++)
{ {
@@ -146,7 +147,7 @@ namespace XCharts
var serieData = dataList[dataIndex]; var serieData = dataList[dataIndex];
var dimension = m_VisualMap.enable && m_VisualMap.dimension > 0 ? m_VisualMap.dimension - 1 : var dimension = m_VisualMap.enable && m_VisualMap.dimension > 0 ? m_VisualMap.dimension - 1 :
serieData.data.Count - 1; serieData.data.Count - 1;
var value = serieData.GetCurrData(dimension, updateDuration); var value = serieData.GetCurrData(dimension, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true; if (serieData.IsDataChanged()) dataChanging = true;
var pos = new Vector3(zeroX + (i + 0.5f) * xWidth, zeroY + (j + 0.5f) * yWidth); var pos = new Vector3(zeroX + (i + 0.5f) * xWidth, zeroY + (j + 0.5f) * yWidth);
serie.dataPoints.Add(pos); serie.dataPoints.Add(pos);
@@ -183,10 +184,8 @@ namespace XCharts
} }
if (!serie.animation.IsFinish()) if (!serie.animation.IsFinish())
{ {
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1; serie.animation.CheckProgress(xCount);
float speed = xCount / duration; m_IsPlayingAnimation = true;
serie.animation.CheckProgress(Time.deltaTime * speed);
m_IsPlayingStartAnimation = true;
RefreshChart(); RefreshChart();
} }
if (dataChanging) if (dataChanging)

View File

@@ -79,6 +79,7 @@ namespace XCharts
protected void DrawXLineSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig) protected void DrawXLineSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
{ {
if (!IsActive(serie.index)) return; if (!IsActive(serie.index)) return;
if (serie.animation.HasFadeOut()) return;
var showData = serie.GetDataList(m_DataZoom); var showData = serie.GetDataList(m_DataZoom);
if (showData.Count <= 0) return; if (showData.Count <= 0) return;
Color lineColor = serie.GetLineColor(m_ThemeInfo, colorIndex, false); Color lineColor = serie.GetLineColor(m_ThemeInfo, colorIndex, false);
@@ -114,7 +115,7 @@ namespace XCharts
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage : var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate); DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false; var dataChanging = false;
var updateDuration = serie.animation.GetUpdateAnimationDuration(); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
for (i = serie.minShow; i < maxCount; i += rate) for (i = serie.minShow; i < maxCount; i += rate)
{ {
if (i == maxCount - 1) includeLastData = true; if (i == maxCount - 1) includeLastData = true;
@@ -123,9 +124,9 @@ namespace XCharts
for (int j = 0; j < rate; j++) seriesHig.Add(0); for (int j = 0; j < rate; j++) seriesHig.Add(0);
} }
float yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, float yValue = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage,
i, updateDuration, ref dataChanging); i, dataChangeDuration, ref dataChanging);
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np, seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np,
updateDuration); dataChangeDuration);
serie.dataPoints.Add(np); serie.dataPoints.Add(np);
} }
if (dataChanging) if (dataChanging)
@@ -136,9 +137,9 @@ namespace XCharts
{ {
i = maxCount - 1; i = maxCount - 1;
seriesHig.Add(0); seriesHig.Add(0);
float yValue = showData[i].GetCurrData(1, updateDuration); float yValue = showData[i].GetCurrData(1, dataChangeDuration);
seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np, seriesHig[i] += GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, seriesHig[i], ref np,
updateDuration); dataChangeDuration);
serie.dataPoints.Add(np); serie.dataPoints.Add(np);
} }
if (serie.dataPoints.Count <= 0) if (serie.dataPoints.Count <= 0)
@@ -155,8 +156,8 @@ namespace XCharts
if (serie.minShow > 0 && serie.minShow < showData.Count) if (serie.minShow > 0 && serie.minShow < showData.Count)
{ {
i = serie.minShow - 1; i = serie.minShow - 1;
float yValue = showData[i].GetCurrData(1, updateDuration); float yValue = showData[i].GetCurrData(1, dataChangeDuration);
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref firstLastPos, updateDuration); GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref firstLastPos, dataChangeDuration);
} }
else else
{ {
@@ -165,8 +166,8 @@ namespace XCharts
if (serie.maxShow > 0 && serie.maxShow < showData.Count) if (serie.maxShow > 0 && serie.maxShow < showData.Count)
{ {
i = serie.maxShow; i = serie.maxShow;
float yValue = showData[i].GetCurrData(1, updateDuration); float yValue = showData[i].GetCurrData(1, dataChangeDuration);
GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref lastNextPos, updateDuration); GetDataPoint(xAxis, yAxis, showData, yValue, startX, i, scaleWid, 0, ref lastNextPos, dataChangeDuration);
} }
else else
{ {
@@ -221,12 +222,9 @@ namespace XCharts
} }
if (!serie.animation.IsFinish()) if (!serie.animation.IsFinish())
{ {
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1; serie.animation.CheckProgress(totalDetailProgress);
float speed = totalDetailProgress / duration; serie.animation.CheckSymbol(serie.symbol.size);
float symbolSpeed = serie.symbol.size / duration; m_IsPlayingAnimation = true;
serie.animation.CheckProgress(Time.deltaTime * speed);
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
m_IsPlayingStartAnimation = true;
RefreshChart(); RefreshChart();
} }
} }
@@ -247,12 +245,12 @@ namespace XCharts
} }
private float SampleValue(ref List<SerieData> showData, SampleType sampleType, int rate, private float SampleValue(ref List<SerieData> showData, SampleType sampleType, int rate,
int minCount, int maxCount, float totalAverage, int index, float updateDuration, ref bool dataChanging) int minCount, int maxCount, float totalAverage, int index, float dataChangeDuration, ref bool dataChanging)
{ {
if (rate <= 1 || index == minCount) if (rate <= 1 || index == minCount)
{ {
if (showData[index].IsDataChanged()) dataChanging = true; if (showData[index].IsDataChanged()) dataChanging = true;
return showData[index].GetCurrData(1, updateDuration); return showData[index].GetCurrData(1, dataChangeDuration);
} }
switch (sampleType) switch (sampleType)
{ {
@@ -261,7 +259,7 @@ namespace XCharts
float total = 0; float total = 0;
for (int i = index; i > index - rate; i--) for (int i = index; i > index - rate; i--)
{ {
total += showData[i].GetCurrData(1, updateDuration); total += showData[i].GetCurrData(1, dataChangeDuration);
if (showData[i].IsDataChanged()) dataChanging = true; if (showData[i].IsDataChanged()) dataChanging = true;
} }
if (sampleType == SampleType.Average) return total / rate; if (sampleType == SampleType.Average) return total / rate;
@@ -270,7 +268,7 @@ namespace XCharts
float max = float.MinValue; float max = float.MinValue;
for (int i = index; i > index - rate; i--) for (int i = index; i > index - rate; i--)
{ {
var value = showData[i].GetCurrData(1, updateDuration); var value = showData[i].GetCurrData(1, dataChangeDuration);
if (value > max) max = value; if (value > max) max = value;
if (showData[i].IsDataChanged()) dataChanging = true; if (showData[i].IsDataChanged()) dataChanging = true;
} }
@@ -279,7 +277,7 @@ namespace XCharts
float min = float.MaxValue; float min = float.MaxValue;
for (int i = index; i > index - rate; i--) for (int i = index; i > index - rate; i--)
{ {
var value = showData[i].GetCurrData(1, updateDuration); var value = showData[i].GetCurrData(1, dataChangeDuration);
if (value < min) min = value; if (value < min) min = value;
if (showData[i].IsDataChanged()) dataChanging = true; if (showData[i].IsDataChanged()) dataChanging = true;
} }
@@ -290,7 +288,7 @@ namespace XCharts
total = 0; total = 0;
for (int i = index; i > index - rate; i--) for (int i = index; i > index - rate; i--)
{ {
var value = showData[i].GetCurrData(1, updateDuration); var value = showData[i].GetCurrData(1, dataChangeDuration);
total += value; total += value;
if (value < min) min = value; if (value < min) min = value;
if (value > max) max = value; if (value > max) max = value;
@@ -301,7 +299,7 @@ namespace XCharts
else return min; else return min;
} }
if (showData[index].IsDataChanged()) dataChanging = true; if (showData[index].IsDataChanged()) dataChanging = true;
return showData[index].GetCurrData(1, updateDuration); return showData[index].GetCurrData(1, dataChangeDuration);
} }
private float GetDataPoint(Axis xAxis, Axis yAxis, List<SerieData> showData, float yValue, float startX, int i, private float GetDataPoint(Axis xAxis, Axis yAxis, List<SerieData> showData, float yValue, float startX, int i,
@@ -365,6 +363,7 @@ namespace XCharts
protected void DrawYLineSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig) protected void DrawYLineSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
{ {
if (!IsActive(serie.index)) return; if (!IsActive(serie.index)) return;
if (serie.animation.HasFadeOut()) return;
var showData = serie.GetDataList(m_DataZoom); var showData = serie.GetDataList(m_DataZoom);
Vector3 lp = Vector3.zero; Vector3 lp = Vector3.zero;
Vector3 np = Vector3.zero; Vector3 np = Vector3.zero;
@@ -399,16 +398,16 @@ namespace XCharts
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (coordinateWidth / sampleDist)); if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (coordinateWidth / sampleDist));
if (rate < 1) rate = 1; if (rate < 1) rate = 1;
var dataChanging = false; var dataChanging = false;
float updateDuration = serie.animation.GetUpdateAnimationDuration(); float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
float xMinValue = xAxis.GetCurrMinValue(updateDuration); float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
float xMaxValue = xAxis.GetCurrMaxValue(updateDuration); float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
for (i = serie.minShow; i < maxCount; i += rate) for (i = serie.minShow; i < maxCount; i += rate)
{ {
if (i >= seriesHig.Count) if (i >= seriesHig.Count)
{ {
for (int j = 0; j < rate; j++) seriesHig.Add(0); for (int j = 0; j < rate; j++) seriesHig.Add(0);
} }
float value = showData[i].GetCurrData(1, updateDuration); float value = showData[i].GetCurrData(1, dataChangeDuration);
float pY = startY + i * scaleWid; float pY = startY + i * scaleWid;
float pX = seriesHig[i] + coordinateX + yAxis.axisLine.width; float pX = seriesHig[i] + coordinateX + yAxis.axisLine.width;
float dataHig = 0; float dataHig = 0;
@@ -435,7 +434,7 @@ namespace XCharts
{ {
i = maxCount - 1; i = maxCount - 1;
seriesHig.Add(0); seriesHig.Add(0);
float value = showData[i].GetCurrData(1, updateDuration); float value = showData[i].GetCurrData(1, dataChangeDuration);
float pY = startY + i * scaleWid; float pY = startY + i * scaleWid;
float pX = seriesHig[i] + coordinateX + yAxis.axisLine.width; float pX = seriesHig[i] + coordinateX + yAxis.axisLine.width;
float dataHig = 0; float dataHig = 0;
@@ -517,12 +516,10 @@ namespace XCharts
} }
if (!serie.animation.IsFinish()) if (!serie.animation.IsFinish())
{ {
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1; float total = totalDetailProgress - dataCount * serie.lineStyle.width * 0.5f;
float speed = (totalDetailProgress - dataCount * serie.lineStyle.width * 0.5f) / duration; serie.animation.CheckProgress(total);
float symbolSpeed = serie.symbol.size / duration; serie.animation.CheckSymbol(serie.symbol.size);
serie.animation.CheckProgress(Time.deltaTime * speed); m_IsPlayingAnimation = true;
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
m_IsPlayingStartAnimation = true;
RefreshChart(); RefreshChart();
} }
} }

View File

@@ -14,6 +14,7 @@ namespace XCharts
{ {
protected void DrawScatterSerie(VertexHelper vh, int colorIndex, Serie serie) protected void DrawScatterSerie(VertexHelper vh, int colorIndex, Serie serie)
{ {
if (serie.animation.HasFadeOut()) return;
var yAxis = m_YAxises[serie.axisIndex]; var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex]; var xAxis = m_XAxises[serie.axisIndex];
var color = serie.symbol.color != Color.clear ? serie.symbol.color : (Color)m_ThemeInfo.GetColor(colorIndex); var color = serie.symbol.color != Color.clear ? serie.symbol.color : (Color)m_ThemeInfo.GetColor(colorIndex);
@@ -23,13 +24,13 @@ namespace XCharts
: serie.dataCount; : serie.dataCount;
serie.animation.InitProgress(1, 0, 1); serie.animation.InitProgress(1, 0, 1);
var rate = serie.animation.GetCurrRate(); var rate = serie.animation.GetCurrRate();
var updateDuration = serie.animation.GetUpdateAnimationDuration(); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var dataChanging = false; var dataChanging = false;
for (int n = serie.minShow; n < maxCount; n++) for (int n = serie.minShow; n < maxCount; n++)
{ {
var serieData = serie.GetDataList(m_DataZoom)[n]; var serieData = serie.GetDataList(m_DataZoom)[n];
float xValue = serieData.GetCurrData(0, updateDuration); float xValue = serieData.GetCurrData(0, dataChangeDuration);
float yValue = serieData.GetCurrData(1, updateDuration); float yValue = serieData.GetCurrData(1, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true; if (serieData.IsDataChanged()) dataChanging = true;
float pX = coordinateX + xAxis.axisLine.width; float pX = coordinateX + xAxis.axisLine.width;
float pY = coordinateY + yAxis.axisLine.width; float pY = coordinateY + yAxis.axisLine.width;
@@ -66,10 +67,8 @@ namespace XCharts
} }
if (!serie.animation.IsFinish()) if (!serie.animation.IsFinish())
{ {
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1; serie.animation.CheckProgress(1);
float speed = 1 / duration; m_IsPlayingAnimation = true;
serie.animation.CheckProgress(Time.deltaTime * speed);
m_IsPlayingStartAnimation = true;
RefreshChart(); RefreshChart();
} }
if (dataChanging) if (dataChanging)

View File

@@ -0,0 +1,190 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
public class LegendItem
{
private int m_Index;
private string m_Name;
private string m_LegendName;
private GameObject m_GameObject;
private Button m_Button;
private Image m_Icon;
private Text m_Text;
private Image m_TextBackground;
private RectTransform m_Rect;
private RectTransform m_IconRect;
private RectTransform m_TextRect;
private RectTransform m_TextBackgroundRect;
private float m_Gap = 0f;
private float m_LabelPaddingLeftRight = 0f;
private float m_LabelPaddingTopBottom = 0f;
private bool m_LabelAutoSize = true;
public int index { get { return m_Index; } set { m_Index = value; } }
public string name { get { return m_Name; } set { m_Name = value; } }
public string legendName { get { return m_LegendName; } set { m_LegendName = value; } }
public GameObject gameObject { get { return m_GameObject; } }
public Button button { get { return m_Button; } }
public float width
{
get
{
if (m_IconRect && m_TextBackgroundRect)
{
return m_IconRect.sizeDelta.x + m_Gap + m_TextBackgroundRect.sizeDelta.x;
}
else
{
return 0;
}
}
}
public float height
{
get
{
if (m_IconRect && m_TextBackgroundRect)
{
return Mathf.Max(m_IconRect.sizeDelta.y, m_TextBackgroundRect.sizeDelta.y);
}
else
{
return 0;
}
}
}
public void SetObject(GameObject obj)
{
m_GameObject = obj;
m_Button = obj.GetComponent<Button>();
m_Rect = obj.GetComponent<RectTransform>();
m_Icon = obj.transform.Find("icon").gameObject.GetComponent<Image>();
m_TextBackground = obj.transform.Find("content").gameObject.GetComponent<Image>();
m_Text = obj.transform.Find("content/Text").gameObject.GetComponent<Text>();
m_IconRect = m_Icon.gameObject.GetComponent<RectTransform>();
m_TextRect = m_Text.gameObject.GetComponent<RectTransform>();
m_TextBackgroundRect = m_TextBackground.gameObject.GetComponent<RectTransform>();
}
public void SetButton(Button button)
{
m_Button = button;
}
public void SetIcon(Image icon)
{
m_Icon = icon;
}
public void SetText(Text text)
{
m_Text = text;
}
public void SetTextBackground(Image image)
{
m_TextBackground = image;
}
public void SetIconSize(float width, float height)
{
if (m_IconRect)
{
m_IconRect.sizeDelta = new Vector2(width, height);
}
}
public void SetIconColor(Color color)
{
if (m_Icon)
{
m_Icon.color = color;
}
}
public void SetIconImage(Sprite image)
{
if (m_Icon)
{
m_Icon.sprite = image;
}
}
public void SetContentColor(Color color)
{
if (m_Text)
{
m_Text.color = color;
}
}
public void SetContentBackgroundColor(Color color)
{
if (m_TextBackground)
{
m_TextBackground.color = color;
}
}
public void SetContentPosition(Vector3 offset)
{
m_Gap = offset.x;
if (m_TextBackgroundRect)
{
var posX = m_IconRect.sizeDelta.x + offset.x;
m_TextBackgroundRect.anchoredPosition3D = new Vector3(posX, offset.y, 0);
}
}
public bool SetContent(string content)
{
if (m_Text && !m_Text.text.Equals(content))
{
m_Text.text = content;
if (m_LabelAutoSize)
{
var newSize = string.IsNullOrEmpty(content) ? Vector2.zero :
new Vector2(m_Text.preferredWidth, m_Text.preferredHeight);
var sizeChange = newSize.x != m_TextRect.sizeDelta.x || newSize.y != m_TextRect.sizeDelta.y;
if (sizeChange)
{
m_TextRect.sizeDelta = newSize;
m_TextRect.anchoredPosition3D = new Vector3(m_LabelPaddingLeftRight, 0);
m_TextBackgroundRect.sizeDelta = new Vector2(m_Text.preferredWidth + m_LabelPaddingLeftRight * 2,
m_Text.preferredHeight + m_LabelPaddingTopBottom * 2 - 4);
m_Rect.sizeDelta = new Vector3(width, height);
}
return sizeChange;
}
}
return false;
}
public void SetPosition(Vector3 position)
{
if (m_GameObject)
{
m_GameObject.transform.localPosition = position;
}
}
public void SetActive(bool active)
{
if (m_GameObject)
{
m_GameObject.SetActive(active);
}
}
}
}

View File

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

View File

@@ -15,14 +15,15 @@ namespace XCharts
{ {
private static readonly Stack<GameObject> m_Stack = new Stack<GameObject>(200); private static readonly Stack<GameObject> m_Stack = new Stack<GameObject>(200);
public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color, float iconWidth, float iconHeight) public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color,
float iconWidth, float iconHeight)
{ {
GameObject element; GameObject element;
if (m_Stack.Count == 0 || !Application.isPlaying) if (m_Stack.Count == 0 || !Application.isPlaying)
{ {
element = ChartHelper.AddSerieLabel(name, parent, font, element = ChartHelper.AddSerieLabel(name, parent, font,
color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate, color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
label.backgroundWidth, label.backgroundHeight); label.backgroundWidth, label.backgroundHeight, 1);
ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight); ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight);
} }
else else

View File

@@ -32,6 +32,7 @@ namespace XCharts
{ {
base.Reset(); base.Reset();
m_Title.text = "PieChart"; m_Title.text = "PieChart";
m_Legend.show = true;
RemoveData(); RemoveData();
AddSerie(SerieType.Pie, "serie1"); AddSerie(SerieType.Pie, "serie1");
AddData(0, 70, "pie1"); AddData(0, 70, "pie1");
@@ -58,7 +59,7 @@ namespace XCharts
serie.index = i; serie.index = i;
var data = serie.data; var data = serie.data;
serie.animation.InitProgress(data.Count, 0, 360); serie.animation.InitProgress(data.Count, 0, 360);
if (!serie.show) if (!serie.show || serie.animation.HasFadeOut())
{ {
continue; continue;
} }
@@ -77,13 +78,12 @@ namespace XCharts
sd.canShowLabel = false; sd.canShowLabel = false;
} }
bool dataChanging = false; bool dataChanging = false;
float updateDuration = serie.animation.GetUpdateAnimationDuration(); float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
for (int n = 0; n < data.Count; n++) for (int n = 0; n < data.Count; n++)
{ {
if (!serie.animation.NeedAnimation(n)) break;
var serieData = data[n]; var serieData = data[n];
serieData.index = n; serieData.index = n;
float value = serieData.GetCurrData(1, updateDuration); float value = serieData.GetCurrData(1, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true; if (serieData.IsDataChanged()) dataChanging = true;
serieNameCount = m_LegendRealShowName.IndexOf(serieData.legendName); serieNameCount = m_LegendRealShowName.IndexOf(serieData.legendName);
Color color = m_ThemeInfo.GetColor(serieNameCount); Color color = m_ThemeInfo.GetColor(serieNameCount);
@@ -164,11 +164,8 @@ namespace XCharts
} }
if (!serie.animation.IsFinish()) if (!serie.animation.IsFinish())
{ {
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1; serie.animation.CheckProgress(360);
float speed = 360 / duration; serie.animation.CheckSymbol(serie.symbol.size);
float symbolSpeed = serie.symbol.size / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
RefreshChart(); RefreshChart();
} }
if (dataChanging) if (dataChanging)
@@ -488,9 +485,8 @@ namespace XCharts
protected override void OnLegendButtonClick(int index, string legendName, bool show) protected override void OnLegendButtonClick(int index, string legendName, bool show)
{ {
bool active = CheckDataShow(legendName, show); CheckDataShow(legendName, show);
var bgColor1 = active ? m_ThemeInfo.GetColor(index) : m_ThemeInfo.legendUnableColor; UpdateLegendColor(legendName, show);
m_Legend.UpdateButtonColor(legendName, bgColor1);
RefreshChart(); RefreshChart();
} }
@@ -531,7 +527,7 @@ namespace XCharts
if (selected) if (selected)
{ {
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25)); m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
RefreshTooltip(); UpdateTooltip();
} }
else if (m_Tooltip.IsActive()) else if (m_Tooltip.IsActive())
{ {
@@ -570,9 +566,9 @@ namespace XCharts
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
protected override void RefreshTooltip() protected override void UpdateTooltip()
{ {
base.RefreshTooltip(); base.UpdateTooltip();
bool showTooltip = false; bool showTooltip = false;
foreach (var serie in m_Series.list) foreach (var serie in m_Series.list)
{ {

View File

@@ -26,9 +26,8 @@ namespace XCharts
protected override void OnLegendButtonClick(int index, string legendName, bool show) protected override void OnLegendButtonClick(int index, string legendName, bool show)
{ {
bool active = CheckDataShow(legendName, show); CheckDataShow(legendName, show);
var bgColor1 = active ? m_ThemeInfo.GetColor(index) : m_ThemeInfo.legendUnableColor; UpdateLegendColor(legendName, show);
m_Legend.UpdateButtonColor(legendName, bgColor1);
RefreshChart(); RefreshChart();
} }
@@ -69,12 +68,13 @@ namespace XCharts
serie.symbol.type = SerieSymbolType.EmptyCircle; serie.symbol.type = SerieSymbolType.EmptyCircle;
serie.symbol.size = 4; serie.symbol.size = 4;
serie.symbol.selectedSize = 6; serie.symbol.selectedSize = 6;
serie.showDataName = true;
List<float> data = new List<float>(); List<float> data = new List<float>();
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
data.Add(Random.Range(20, 90)); data.Add(Random.Range(20, 90));
} }
AddData(0, data); AddData(0, data, "legendName");
} }
#endif #endif
@@ -97,7 +97,7 @@ namespace XCharts
var textColor = textStyle.color == Color.clear ? (Color)m_ThemeInfo.axisTextColor : textStyle.color; var textColor = textStyle.color == Color.clear ? (Color)m_ThemeInfo.axisTextColor : textStyle.color;
var txt = ChartHelper.AddTextObject(INDICATOR_TEXT + "_" + n + "_" + i, transform, m_ThemeInfo.font, var txt = ChartHelper.AddTextObject(INDICATOR_TEXT + "_" + n + "_" + i, transform, m_ThemeInfo.font,
textColor, anchor, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), textColor, anchor, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
new Vector2(txtWid, txtHig), textStyle.fontSize, textStyle.rotate, textStyle.fontStyle); new Vector2(txtWid, txtHig), textStyle.fontSize, textStyle.rotate, textStyle.fontStyle, textStyle.lineSpacing);
txt.text = radar.indicatorList[i].name; txt.text = radar.indicatorList[i].name;
txt.gameObject.SetActive(radar.indicator); txt.gameObject.SetActive(radar.indicator);
var txtWidth = txt.preferredWidth; var txtWidth = txt.preferredWidth;
@@ -198,13 +198,13 @@ namespace XCharts
var angle = 2 * Mathf.PI / indicatorNum; var angle = 2 * Mathf.PI / indicatorNum;
Vector3 p = radar.runtimeCenterPos; Vector3 p = radar.runtimeCenterPos;
serie.animation.InitProgress(1, 0, 1); serie.animation.InitProgress(1, 0, 1);
if (!IsActive(i)) if (!IsActive(i) || serie.animation.HasFadeOut())
{ {
continue; continue;
} }
var rate = serie.animation.GetCurrRate(); var rate = serie.animation.GetCurrRate();
var dataChanging = false; var dataChanging = false;
var updateDuration = serie.animation.GetUpdateAnimationDuration(); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
for (int j = 0; j < serie.data.Count; j++) for (int j = 0; j < serie.data.Count; j++)
{ {
var serieData = serie.data[j]; var serieData = serie.data[j];
@@ -249,7 +249,7 @@ namespace XCharts
if (n >= serieData.data.Count) break; if (n >= serieData.data.Count) break;
float min = radar.GetIndicatorMin(n); float min = radar.GetIndicatorMin(n);
float max = radar.GetIndicatorMax(n); float max = radar.GetIndicatorMax(n);
float value = serieData.GetCurrData(n, updateDuration); float value = serieData.GetCurrData(n, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true; if (serieData.IsDataChanged()) dataChanging = true;
if (max == 0) if (max == 0)
{ {
@@ -276,7 +276,7 @@ namespace XCharts
} }
if (serie.lineStyle.show) if (serie.lineStyle.show)
{ {
ChartDrawer.DrawLine(vh, startPoint, toPoint, serie.lineStyle.width, lineColor); DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor);
} }
startPoint = toPoint; startPoint = toPoint;
} }
@@ -288,7 +288,7 @@ namespace XCharts
} }
if (serie.lineStyle.show) if (serie.lineStyle.show)
{ {
ChartDrawer.DrawLine(vh, startPoint, firstPoint, serie.lineStyle.width, lineColor); DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor);
} }
if (serie.symbol.type != SerieSymbolType.None) if (serie.symbol.type != SerieSymbolType.None)
{ {
@@ -304,9 +304,7 @@ namespace XCharts
} }
if (!serie.animation.IsFinish()) if (!serie.animation.IsFinish())
{ {
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1; serie.animation.CheckProgress(1);
float speed = 1 / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
RefreshChart(); RefreshChart();
} }
if (dataChanging) if (dataChanging)
@@ -318,7 +316,7 @@ namespace XCharts
private void DrawRadar(VertexHelper vh, Radar radar) private void DrawRadar(VertexHelper vh, Radar radar)
{ {
if (!radar.lineStyle.show && !radar.splitArea.show) if (!radar.splitLine.show && !radar.splitArea.show)
{ {
return; return;
} }
@@ -346,9 +344,9 @@ namespace XCharts
{ {
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, color); ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, color);
} }
if (radar.lineStyle.show) if (radar.splitLine.NeedShow(i))
{ {
ChartDrawer.DrawLine(vh, p2, p3, radar.lineStyle.width, lineColor); DrawLineStyle(vh, radar.splitLine.lineStyle, p2, p3, lineColor);
} }
p1 = p4; p1 = p4;
p2 = p3; p2 = p3;
@@ -360,16 +358,16 @@ namespace XCharts
float currAngle = j * angle; float currAngle = j * angle;
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
p.y + outsideRadius * Mathf.Cos(currAngle)); p.y + outsideRadius * Mathf.Cos(currAngle));
if (radar.lineStyle.show) if (radar.splitLine.show)
{ {
ChartDrawer.DrawLine(vh, p, p3, radar.lineStyle.width / 2, lineColor); DrawLineStyle(vh, radar.splitLine.lineStyle, p, p3, lineColor);
} }
} }
} }
private void DrawCricleRadar(VertexHelper vh, Radar radar) private void DrawCricleRadar(VertexHelper vh, Radar radar)
{ {
if (!radar.lineStyle.show && !radar.splitArea.show) if (!radar.splitLine.show && !radar.splitArea.show)
{ {
return; return;
} }
@@ -389,9 +387,9 @@ namespace XCharts
ChartDrawer.DrawDoughnut(vh, p, insideRadius, outsideRadius, color, Color.clear, ChartDrawer.DrawDoughnut(vh, p, insideRadius, outsideRadius, color, Color.clear,
m_Settings.cicleSmoothness, 0, 360); m_Settings.cicleSmoothness, 0, 360);
} }
if (radar.lineStyle.show) if (radar.splitLine.show)
{ {
ChartDrawer.DrawEmptyCricle(vh, p, outsideRadius, radar.lineStyle.width, lineColor, ChartDrawer.DrawEmptyCricle(vh, p, outsideRadius, radar.splitLine.lineStyle.width, lineColor,
Color.clear, m_Settings.cicleSmoothness); Color.clear, m_Settings.cicleSmoothness);
} }
insideRadius = outsideRadius; insideRadius = outsideRadius;
@@ -401,30 +399,18 @@ namespace XCharts
float currAngle = j * angle; float currAngle = j * angle;
p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
p.y + outsideRadius * Mathf.Cos(currAngle)); p.y + outsideRadius * Mathf.Cos(currAngle));
if (radar.lineStyle.show) if (radar.splitLine.show)
{ {
ChartDrawer.DrawLine(vh, p, p1, radar.lineStyle.width / 2, lineColor); ChartDrawer.DrawLine(vh, p, p1, radar.splitLine.lineStyle.width / 2, lineColor);
} }
} }
} }
private Color GetLineColor(Radar radar) private Color GetLineColor(Radar radar)
{ {
if (radar.lineStyle.color != Color.clear) return radar.splitLine.GetColor(m_ThemeInfo);
{
var color = radar.lineStyle.color;
color.a *= radar.lineStyle.opacity;
return color;
}
else
{
var color = (Color)m_ThemeInfo.axisLineColor;
color.a *= radar.lineStyle.opacity;
return color;
}
} }
protected override void CheckTootipArea(Vector2 local) protected override void CheckTootipArea(Vector2 local)
{ {
if (m_IsEnterLegendButtom) return; if (m_IsEnterLegendButtom) return;
@@ -471,14 +457,14 @@ namespace XCharts
else else
{ {
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25)); m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
RefreshTooltip(); UpdateTooltip();
RefreshChart(); RefreshChart();
} }
} }
protected override void RefreshTooltip() protected override void UpdateTooltip()
{ {
base.RefreshTooltip(); base.UpdateTooltip();
int serieIndex = m_Tooltip.runtimeDataIndex[0]; int serieIndex = m_Tooltip.runtimeDataIndex[0];
if (serieIndex < 0) if (serieIndex < 0)
{ {

View File

@@ -161,12 +161,13 @@ namespace XCharts
rect.anchorMin = anchorMin; rect.anchorMin = anchorMin;
rect.anchorMax = anchorMax; rect.anchorMax = anchorMax;
rect.pivot = pivot; rect.pivot = pivot;
rect.anchoredPosition3D = Vector3.zero;
return obj; return obj;
} }
public static Text AddTextObject(string name, Transform parent, Font font, Color color, public static Text AddTextObject(string name, Transform parent, Font font, Color color,
TextAnchor anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, TextAnchor anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta,
int fontSize = 14, float rotate = 0, FontStyle fontStyle = FontStyle.Normal) int fontSize = 14, float rotate = 0, FontStyle fontStyle = FontStyle.Normal, float lineSpacing = 1)
{ {
GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
Text txt = GetOrAddComponent<Text>(txtObj); Text txt = GetOrAddComponent<Text>(txtObj);
@@ -178,6 +179,7 @@ namespace XCharts
txt.horizontalOverflow = HorizontalWrapMode.Overflow; txt.horizontalOverflow = HorizontalWrapMode.Overflow;
txt.verticalOverflow = VerticalWrapMode.Overflow; txt.verticalOverflow = VerticalWrapMode.Overflow;
txt.color = color; txt.color = color;
txt.lineSpacing = lineSpacing;
txtObj.transform.localEulerAngles = new Vector3(0, 0, rotate); txtObj.transform.localEulerAngles = new Vector3(0, 0, rotate);
RectTransform rect = GetOrAddComponent<RectTransform>(txtObj); RectTransform rect = GetOrAddComponent<RectTransform>(txtObj);
@@ -191,20 +193,21 @@ namespace XCharts
public static Button AddButtonObject(string name, Transform parent, Font font, int fontSize, public static Button AddButtonObject(string name, Transform parent, Font font, int fontSize,
Color color, TextAnchor anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Color color, TextAnchor anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot,
Vector2 sizeDelta) Vector2 sizeDelta, float lineSpacing)
{ {
GameObject btnObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); GameObject btnObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
GetOrAddComponent<Image>(btnObj); GetOrAddComponent<Image>(btnObj);
GetOrAddComponent<Button>(btnObj); GetOrAddComponent<Button>(btnObj);
Text txt = AddTextObject("Text", btnObj.transform, font, color, TextAnchor.MiddleCenter, Text txt = AddTextObject("Text", btnObj.transform, font, color, TextAnchor.MiddleCenter,
new Vector2(0, 0), new Vector2(1, 1), new Vector2(0.5f, 0.5f), new Vector2(0, 0), new Vector2(1, 1), new Vector2(0.5f, 0.5f),
sizeDelta, fontSize); sizeDelta, fontSize, lineSpacing);
txt.rectTransform.offsetMin = Vector2.zero; txt.rectTransform.offsetMin = Vector2.zero;
txt.rectTransform.offsetMax = Vector2.zero; txt.rectTransform.offsetMax = Vector2.zero;
return btnObj.GetComponent<Button>(); return btnObj.GetComponent<Button>();
} }
internal static GameObject AddTooltipContent(string name, Transform parent, Font font, int fontSize, FontStyle fontStyle) internal static GameObject AddTooltipContent(string name, Transform parent, Font font, int fontSize,
FontStyle fontStyle, float lineSpacing)
{ {
var anchorMax = new Vector2(0, 1); var anchorMax = new Vector2(0, 1);
var anchorMin = new Vector2(0, 1); var anchorMin = new Vector2(0, 1);
@@ -214,7 +217,7 @@ namespace XCharts
var img = GetOrAddComponent<Image>(tooltipObj); var img = GetOrAddComponent<Image>(tooltipObj);
img.color = Color.black; img.color = Color.black;
Text txt = AddTextObject("Text", tooltipObj.transform, font, Color.white, TextAnchor.UpperLeft, Text txt = AddTextObject("Text", tooltipObj.transform, font, Color.white, TextAnchor.UpperLeft,
anchorMin, anchorMax, pivot, sizeDelta, fontSize, 0, fontStyle); anchorMin, anchorMax, pivot, sizeDelta, fontSize, 0, fontStyle, lineSpacing);
txt.text = "Text"; txt.text = "Text";
txt.transform.localPosition = new Vector2(3, -3); txt.transform.localPosition = new Vector2(3, -3);
tooltipObj.transform.localPosition = Vector3.zero; tooltipObj.transform.localPosition = Vector3.zero;
@@ -232,8 +235,9 @@ namespace XCharts
return iconObj; return iconObj;
} }
internal static GameObject AddSerieLabel(string name, Transform parent, Font font, Color textColor, Color backgroundColor, internal static GameObject AddSerieLabel(string name, Transform parent, Font font, Color textColor,
int fontSize, FontStyle fontStyle, float rotate, float width, float height) Color backgroundColor, int fontSize, FontStyle fontStyle, float rotate, float width, float height,
float lineSpacing)
{ {
var anchorMin = new Vector2(0.5f, 0.5f); var anchorMin = new Vector2(0.5f, 0.5f);
var anchorMax = new Vector2(0.5f, 0.5f); var anchorMax = new Vector2(0.5f, 0.5f);
@@ -244,7 +248,7 @@ namespace XCharts
//img.color = backgroundColor; //img.color = backgroundColor;
labelObj.transform.localEulerAngles = new Vector3(0, 0, rotate); labelObj.transform.localEulerAngles = new Vector3(0, 0, rotate);
Text txt = AddTextObject("Text", labelObj.transform, font, textColor, TextAnchor.MiddleCenter, Text txt = AddTextObject("Text", labelObj.transform, font, textColor, TextAnchor.MiddleCenter,
anchorMin, anchorMax, pivot, sizeDelta, fontSize, 0, fontStyle); anchorMin, anchorMax, pivot, sizeDelta, fontSize, 0, fontStyle, lineSpacing);
txt.text = "Text"; txt.text = "Text";
txt.transform.localPosition = new Vector2(0, 0); txt.transform.localPosition = new Vector2(0, 0);
txt.transform.localEulerAngles = Vector3.zero; txt.transform.localEulerAngles = Vector3.zero;
@@ -269,7 +273,6 @@ namespace XCharts
return labelObj; return labelObj;
} }
public static void GetPointList(ref List<Vector3> posList, Vector3 sp, Vector3 ep, float k = 30f) public static void GetPointList(ref List<Vector3> posList, Vector3 sp, Vector3 ep, float k = 30f)
{ {
Vector3 dir = (ep - sp).normalized; Vector3 dir = (ep - sp).normalized;
@@ -396,11 +399,30 @@ namespace XCharts
if (list1.Count != list2.Count) return false; if (list1.Count != list2.Count) return false;
for (int i = 0; i < list1.Count; i++) for (int i = 0; i < list1.Count; i++)
{ {
if (!list1[i].Equals(list2[i])) return false; if (list1[i] == null && list2[i] == null) { }
else
{
if (list1[i] != null)
{
if (!list1[i].Equals(list2[i])) return false;
}
else
{
if (!list2[i].Equals(list1[i])) return false;
}
}
} }
return true; return true;
} }
public static bool CopyList<T>(List<T> toList, List<T> fromList)
{
if (toList == null || fromList == null) return false;
toList.Clear();
foreach (var item in fromList) toList.Add(item);
return true;
}
public static List<float> ParseFloatFromString(string jsonData) public static List<float> ParseFloatFromString(string jsonData)
{ {
List<float> list = new List<float>(); List<float> list = new List<float>();

View File

@@ -25,7 +25,7 @@ namespace XCharts
public class XChartsMgr : MonoBehaviour public class XChartsMgr : MonoBehaviour
{ {
public const string version = "1.2.0"; public const string version = "1.2.0";
public const int date = 20200211; public const int date = 20200226;
[SerializeField] private string m_NowVersion; [SerializeField] private string m_NowVersion;
[SerializeField] private string m_NewVersion; [SerializeField] private string m_NewVersion;