diff --git a/Assets/XCharts/CHANGELOG.md b/Assets/XCharts/CHANGELOG.md index e8fc55ab..ba40b0db 100644 --- a/Assets/XCharts/CHANGELOG.md +++ b/Assets/XCharts/CHANGELOG.md @@ -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`的`paddingLeftRight`和`paddingTopBottom`参数配置文字和边框的间距 * (2020.02.11) 增加`Tooltip`的`lineStyle`参数配置指示线样式 @@ -28,7 +34,7 @@ * (2019.12.06) 修复数据过小时`AxisLabel`直接科学计数法显示的问题 * (2019.12.04) 优化和完善数据更新`UpdateData`接口 * (2019.12.03) 增加圆环饼图的圆角支持,参数:`serie.arcShaped` -* (2019.12.03) 增加数据更新动画,参数:`serie.animation.updateAnimation` +* (2019.12.03) 增加数据更新动画,参数:`serie.animation.dataChangeEnable` * (2019.11.30) 增加`GaugeChart`仪表盘 * (2019.11.22) 修复`BarChart`清空数据重新赋值后`SerieLabel`显示异常的问题 * (2019.11.16) 修复`SerieLabel`设置`color`等参数不生效的问题 diff --git a/Assets/XCharts/Demo/Runtime/Demo01_UpdateData.cs b/Assets/XCharts/Demo/Runtime/Demo01_UpdateData.cs index b90b50d7..63bf137a 100644 --- a/Assets/XCharts/Demo/Runtime/Demo01_UpdateData.cs +++ b/Assets/XCharts/Demo/Runtime/Demo01_UpdateData.cs @@ -27,7 +27,7 @@ namespace XCharts { updateTime = 0; var serie = chart.series.GetSerie(0); - //serie.animation.updateAnimation = true; + //serie.animation.dataChangeEnable = true; var dataCount = serie.dataCount; if (chart is RadarChart) { diff --git a/Assets/XCharts/Demo/Runtime/Demo70_Gauge.cs b/Assets/XCharts/Demo/Runtime/Demo70_Gauge.cs index d97a90f9..193af8b9 100644 --- a/Assets/XCharts/Demo/Runtime/Demo70_Gauge.cs +++ b/Assets/XCharts/Demo/Runtime/Demo70_Gauge.cs @@ -37,7 +37,7 @@ namespace XCharts serie.center[1] = 0.5f; serie.radius[0] = 80; serie.splitNumber = 5; - serie.animation.updateAnimation = true; + serie.animation.dataChangeEnable = true; serie.arcShaped = true; serie.titleStyle.show = true; diff --git a/Assets/XCharts/Demo/Runtime/Demo_Test.cs b/Assets/XCharts/Demo/Runtime/Demo_Test.cs index 40909f0c..a7c32bcc 100644 --- a/Assets/XCharts/Demo/Runtime/Demo_Test.cs +++ b/Assets/XCharts/Demo/Runtime/Demo_Test.cs @@ -28,7 +28,7 @@ namespace XCharts { updateTime = 0; var serie = chart.series.GetSerie(0); - serie.animation.updateAnimation = true; + serie.animation.dataChangeEnable = true; var dataCount = serie.dataCount; if (chart is HeatmapChart) { diff --git a/Assets/XCharts/Documentation/XChartsAPI.md b/Assets/XCharts/Documentation/XChartsAPI.md index 2d0a464b..09070165 100644 --- a/Assets/XCharts/Documentation/XChartsAPI.md +++ b/Assets/XCharts/Documentation/XChartsAPI.md @@ -40,11 +40,14 @@ * `BaseChart.IsActiveByLegend(string legendName)`:获得指定图例名字的系列是否显示。 * `BaseChart.RefreshChart()`:在下一帧刷新图表。 * `BaseChart.RefreshLabel()`:在下一帧刷新文本标签。 +* `BaseChart.RefreshTooltip()`:立即刷新`Tooltip`组件。 * `BaseChart.UpdateTheme(Theme theme)`:切换图表主题。 -* `BaseChart.AnimationEnable(bool flag)`:启用或关闭起始动画。 -* `BaseChart.AnimationStart()`:开始初始动画。 -* `BaseChart.AnimationStop()`:停止初始化动画。 -* `BaseChart.AnimationReset()`:重置初始动画,重新播放。 +* `BaseChart.AnimationEnable(bool flag)`:启用或关闭动画。 +* `BaseChart.AnimationFadeIn()`:渐入动画。 +* `BaseChart.AnimationFadeOut()`:渐出动画。 +* `BaseChart.AnimationPause()`:暂停动画。 +* `BaseChart.AnimationResume()`:继续动画。 +* `BaseChart.AnimationReset()`:重置动画。 * `BaseChart.ClickLegendButton(int legendIndex, string legendName, bool show)`:点击图例按钮。 ## `CoordinateChart` diff --git a/Assets/XCharts/Documentation/XCharts配置项手册.md b/Assets/XCharts/Documentation/XCharts配置项手册.md index 89ecafd9..72ee87b0 100644 --- a/Assets/XCharts/Documentation/XCharts配置项手册.md +++ b/Assets/XCharts/Documentation/XCharts配置项手册.md @@ -31,6 +31,7 @@ * [AxisLabel 坐标轴刻度标签](#AxisLabel) * [AxisLine 坐标轴轴线](#AxisLine) * [AxisName 坐标轴名称](#AxisName) +* [AxisSplitLine 坐标轴分割线条](#AxisSplitLine) * [AxisSplitArea 坐标轴分割区域](#AxisSplitArea) * [AxisTick 坐标轴刻度](#AxisTick) * [Emphasis 高亮样式](#Emphasis) @@ -117,12 +118,14 @@ * `Horizonal`:水平。 * `Vertical`:垂直。 * `location`:图例的显示位置 [Location](#Location)。 -* `itemWidth`:每个图例项的宽度。 -* `itemHeight`:每个图例项的高度。 +* `itemWidth`:图例标记的图形宽度。 +* `itemHeight`:图例标记的图形高度。 * `itemGap`:图例每项之间的间隔。横向布局时为水平间隔,纵向布局时为纵向间隔。 -* `itemFontSize`:图例项的字体大小。 +* `itemAutoColor`:图例标记的图形是否自动匹配颜色。 * `formatter`:图例内容字符串模版格式器。支持用 `\n` 换行。模板变量为图例名称 `{name}` * `data`:图例的数据数组。数组项通常为一个字符串,每一项代表一个系列的 `name`(如果是饼图,也可以是饼图单个数据的 `name`)。如果 `data` 没有被指定,会自动从当前系列中获取。指定 `data` 时里面的数据项和 `serie` 匹配时才会生效。 +* `icons`:自定义的图例标记图形。 +* `textStyle`:图例的内容文本样式 [TextStyle](#TextStyle)。 相关接口: @@ -143,7 +146,7 @@ * `Between`:显示在顶点之间。 * `radius`:雷达图的半径。 * `center`:雷达图的中心点。数组的第一项是横坐标,第二项是纵坐标。当值为0-1之间时表示百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度。 -* `lineStyle`:线条样式 [LineStyle](#LineStyle)。 +* `splitLine`:分割线条 [AxisSplitLine](#AxisSplitLine)。 * `splitArea`:分割区域 [AxisSplitArea](#AxisSplitArea)。 * `indicator`:是否显示指示器。 * `indicatorGap`:指示器和雷达的间距。 @@ -168,8 +171,11 @@ * `rotate`:旋转。 * `offset`:偏移。 * `color`:颜色。 +* `backgroundColor`:背景颜色。 +* `font`:字体。 * `fontSize`:字体大小。 * `fontStyle`:字体风格。 +* `lineSpacing`:行间距。 ## `Tooltip` @@ -196,11 +202,10 @@ * `minHeight`:最小高度。当同时设置 f`ixedHeight` 和 `minHeight` 时,`fixedHeight` 比 `minHeight` 优先级高。 * `paddingLeftRight`:文字和边框的左右边距。 * `paddingTopBottom`:文字和边框的上下边距。 -* `fontSize`:文字的字体大小。 -* `fontStyle`:文字的字体风格。 * `backgroundImage`:提示框的背景图。 * `forceENotation`:是否强制使用科学计数法格式化显示数值。默认为false,当小数精度大于3时才采用科学计数法。 * `lineStyle`:指示器线条样式 [LineStyle](#LineStyle)。 +* `textStyle`:显示内容文本样式 [TextStyle](#TextStyle)。 ## `DataZoom` @@ -539,6 +544,7 @@ * `name`:系列名称。用于 `tooltip` 的显示,`legend` 的图例筛选。 * `radarIndex`:雷达图所使用的 `radar` 组件的 `index`。 * `symbol`:标记的图形 [SerieSymbol](#SerieSymbol)。 +* `lineStyle`:线条样式 [LineStyle](#LineStyle)。 * `animation`:起始动画 [SerieAnimation](#SerieAnimation)。 * `data`:系列中的数据项 [SerieData](#SerieData) 数组,可以设置`1`到`n`维数据。 @@ -606,14 +612,13 @@ ## `SerieAnimation` -* `enable`:是否开起始画效果。 -* `easing`:动画的缓动效果。支持以下动画效果: - * `Linear`:线性效果。 -* `duration`:设定的动画时长,单位毫秒。 -* `updateAnimation`:是否开启数据变更动画。 -* `updateDuration`:数据变更动画时长,单位毫秒。 -* `threshold`:是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画。 -* `delay`:动画延时,单位毫秒。 +* `enable`:是否开启动画系统。 +* ~~`threshold`:是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画。~~ +* `fadeInDelay`:设定的渐入动画延时,单位毫秒。 +* `fadeInDuration`:设定的渐入动画时长,单位毫秒。 +* `fadeOutDuration`:设定的渐出动画时长,单位毫秒。 +* `dataChangeEnable`:是否开启数据变更动画。 +* `dataChangeDuration`:数据变更动画时长,单位毫秒。 ## `AreaStyle` @@ -714,7 +719,7 @@ ## `LineStyle` -* `show`:是否显示线条。在折线图中无效。 +* `show`:是否显示线条。当作为子组件,它的父组件有参数控制是否显示时,改参数无效。 * `type`:线条类型。支持以下五种类型: * `None`:不显示分割线。 * `Solid`:实线。 diff --git a/Assets/XCharts/Editor/PropertyDrawers/AnimationDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/AnimationDrawer.cs index 14b3d1c3..d7f66ef3 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/AnimationDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/AnimationDrawer.cs @@ -22,11 +22,12 @@ namespace XCharts drawRect.height = EditorGUIUtility.singleLineHeight; SerializedProperty m_Enable = prop.FindPropertyRelative("m_Enable"); - SerializedProperty m_Easting = prop.FindPropertyRelative("m_Easting"); - SerializedProperty m_Duration = prop.FindPropertyRelative("m_Duration"); - SerializedProperty m_UpdateAnimation = prop.FindPropertyRelative("m_UpdateAnimation"); - SerializedProperty m_UpdateDuration = prop.FindPropertyRelative("m_UpdateDuration"); - SerializedProperty m_Delay = prop.FindPropertyRelative("m_Delay"); + //SerializedProperty m_Easting = prop.FindPropertyRelative("m_Easting"); + SerializedProperty m_FadeInDuration = prop.FindPropertyRelative("m_FadeInDuration"); + SerializedProperty m_FadeOutDuration = prop.FindPropertyRelative("m_FadeOutDuration"); + SerializedProperty m_DataChangeEnable = prop.FindPropertyRelative("m_DataChangeEnable"); + SerializedProperty m_DataChangeDuration = prop.FindPropertyRelative("m_DataChangeDuration"); + SerializedProperty m_FadeInDelay = prop.FindPropertyRelative("m_FadeInDelay"); SerializedProperty m_Threshold = prop.FindPropertyRelative("m_Threshold"); SerializedProperty m_ActualDuration = prop.FindPropertyRelative("m_ActualDuration"); // SerializedProperty m_CurrDetailProgress = prop.FindPropertyRelative("m_CurrDetailProgress"); @@ -37,23 +38,26 @@ namespace XCharts if (ChartEditorHelper.IsToggle(m_AnimationModuleToggle, prop)) { ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Easting); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + //EditorGUI.PropertyField(drawRect, m_Easting); + //drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_Threshold); if (m_Threshold.intValue < 0) m_Threshold.intValue = 0; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Delay); - if (m_Delay.floatValue < 0) m_Delay.floatValue = 0; + EditorGUI.PropertyField(drawRect, m_FadeInDelay); + if (m_FadeInDelay.floatValue < 0) m_FadeInDelay.floatValue = 0; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Duration); - if (m_Duration.floatValue < 0) m_Duration.floatValue = 0; + EditorGUI.PropertyField(drawRect, m_FadeInDuration); + if (m_FadeInDuration.floatValue < 0) m_FadeInDuration.floatValue = 0; 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; - EditorGUI.PropertyField(drawRect, m_UpdateDuration); - if (m_UpdateDuration.floatValue < 0) m_UpdateDuration.floatValue = 0; + EditorGUI.PropertyField(drawRect, m_DataChangeEnable); 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); // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; // EditorGUI.LabelField(drawRect, "DestDetailProgress:" + m_DestDetailProgress.floatValue); diff --git a/Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs index 5a893c4e..87ec617f 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs @@ -14,7 +14,9 @@ namespace XCharts public class LegendDrawer : PropertyDrawer { private bool m_DataFoldout = false; + private bool m_IconsFoldout = false; private int m_DataSize = 0; + private int m_IconsSize = 0; private bool m_ShowJsonDataArea = false; private string m_JsonDataAreaText; private bool m_LegendModuleToggle = false; @@ -30,9 +32,11 @@ namespace XCharts SerializedProperty itemWidth = prop.FindPropertyRelative("m_ItemWidth"); SerializedProperty itemHeight = prop.FindPropertyRelative("m_ItemHeight"); 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_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); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; @@ -45,7 +49,7 @@ namespace XCharts drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, itemGap); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, itemFontSize); + EditorGUI.PropertyField(drawRect, m_ItemAutoColor); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_SelectedMode); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; @@ -57,12 +61,20 @@ namespace XCharts drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.width = EditorGUIUtility.labelWidth + 10; 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; if (m_DataFoldout) { 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; } } @@ -73,7 +85,7 @@ namespace XCharts if (m_LegendModuleToggle) { 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 += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; if (m_DataFoldout) @@ -83,6 +95,14 @@ namespace XCharts height += num * EditorGUIUtility.singleLineHeight + (num - 1) * 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) { diff --git a/Assets/XCharts/Editor/PropertyDrawers/RadarDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/RadarDrawer.cs index f1132d85..994cb1b0 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/RadarDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/RadarDrawer.cs @@ -19,7 +19,7 @@ namespace XCharts SerializedProperty m_Radius; SerializedProperty m_SplitNumber; SerializedProperty m_Center; - SerializedProperty m_LineStyle; + SerializedProperty m_SplitLine; SerializedProperty m_SplitArea; SerializedProperty m_Indicator; SerializedProperty m_IndicatorGap; @@ -39,7 +39,7 @@ namespace XCharts m_Radius = prop.FindPropertyRelative("m_Radius"); m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber"); 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_Indicator = prop.FindPropertyRelative("m_Indicator"); m_IndicatorGap = prop.FindPropertyRelative("m_IndicatorGap"); @@ -85,8 +85,8 @@ namespace XCharts EditorGUI.PropertyField(drawRect, m_SplitNumber); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_LineStyle); - drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle); + EditorGUI.PropertyField(drawRect, m_SplitLine); + drawRect.y += EditorGUI.GetPropertyHeight(m_SplitLine); EditorGUI.PropertyField(drawRect, m_SplitArea); drawRect.y += EditorGUI.GetPropertyHeight(m_SplitArea); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; @@ -112,7 +112,7 @@ namespace XCharts propNum += 7; if (m_IndicatorJsonAreaToggle) propNum += 4; 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")); if (ChartEditorHelper.IsToggle(m_IndicatorToggle, prop)) diff --git a/Assets/XCharts/Editor/PropertyDrawers/SerieDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/SerieDrawer.cs index abe0624b..476f8064 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/SerieDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/SerieDrawer.cs @@ -194,6 +194,8 @@ namespace XCharts drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_Symbol); drawRect.y += EditorGUI.GetPropertyHeight(m_Symbol); + EditorGUI.PropertyField(drawRect, m_LineStyle); + drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle); EditorGUI.PropertyField(drawRect, m_AreaStyle); drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle); break; @@ -451,6 +453,7 @@ namespace XCharts case SerieType.Radar: height += 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing; 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_Emphasis")); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Animation")); diff --git a/Assets/XCharts/Editor/PropertyDrawers/TextStyleDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/TextStyleDrawer.cs index 38f9713e..1aa7831c 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/TextStyleDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/TextStyleDrawer.cs @@ -14,49 +14,57 @@ namespace XCharts [CustomPropertyDrawer(typeof(TextStyle), true)] public class TextStyleDrawer : PropertyDrawer { - //private Dictionary m_TextStyleToggle = new Dictionary(); + private Dictionary m_TextStyleToggle = new Dictionary(); public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { Rect drawRect = pos; drawRect.height = EditorGUIUtility.singleLineHeight; + SerializedProperty m_Font = prop.FindPropertyRelative("m_Font"); SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate"); SerializedProperty m_Color = prop.FindPropertyRelative("m_Color"); + SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor"); SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize"); SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle"); SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset"); - // ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TextStyleToggle, prop, "Text Style"); - // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - // if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop)) - // { - // ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_Rotate); + SerializedProperty m_LineSpacing = prop.FindPropertyRelative("m_LineSpacing"); + ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TextStyleToggle, prop, null,null,false); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.PropertyField(drawRect, m_Offset); - drawRect.y += EditorGUI.GetPropertyHeight(m_Offset); - EditorGUI.PropertyField(drawRect, m_Color); - 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.indentLevel; - // } + if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop)) + { + ++EditorGUI.indentLevel; + EditorGUI.PropertyField(drawRect, m_Font); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_Rotate); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_Offset); + 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) { - // float height = 0; - // if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop)) - // { - // height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing; - // } - // else - // { - // height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; - // } - float height = 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing; - height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset")); + float height = 0; + if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop)) + { + height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing; + height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset")); + } + else + { + height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; + } return height; } } diff --git a/Assets/XCharts/Editor/PropertyDrawers/TitleDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/TitleDrawer.cs index 7e7cb324..0b774860 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/TitleDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/TitleDrawer.cs @@ -34,19 +34,16 @@ namespace XCharts { EditorGUI.PropertyField(drawRect, text); 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); 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")); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; 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; } diff --git a/Assets/XCharts/Editor/PropertyDrawers/TooltipDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/TooltipDrawer.cs index 50fe7255..77edf907 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/TooltipDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/TooltipDrawer.cs @@ -28,13 +28,12 @@ namespace XCharts SerializedProperty m_FixedHeight = prop.FindPropertyRelative("m_FixedHeight"); SerializedProperty m_MinWidth = prop.FindPropertyRelative("m_MinWidth"); 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_PaddingLeftRight = prop.FindPropertyRelative("m_PaddingLeftRight"); SerializedProperty m_PaddingTopBottom = prop.FindPropertyRelative("m_PaddingTopBottom"); SerializedProperty m_BackgroundImage = prop.FindPropertyRelative("m_BackgroundImage"); SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle"); + SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle"); ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TooltipModuleToggle, "Tooltip", show); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; @@ -61,16 +60,14 @@ namespace XCharts drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_PaddingTopBottom); 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); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_ForceENotation); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_LineStyle); drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle); + EditorGUI.PropertyField(drawRect, m_TextStyle); + drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle); EditorGUI.indentLevel--; } } @@ -78,8 +75,9 @@ namespace XCharts public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) { if (m_TooltipModuleToggle) - return 15 * EditorGUIUtility.singleLineHeight + 14 * EditorGUIUtility.standardVerticalSpacing + - EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle")); + return 13 * EditorGUIUtility.singleLineHeight + 12 * EditorGUIUtility.standardVerticalSpacing + + EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle")) + + EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle")); else return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } diff --git a/Assets/XCharts/Editor/XChartEditor.cs b/Assets/XCharts/Editor/XChartEditor.cs index 0a2a4ff0..fbfac0a8 100644 --- a/Assets/XCharts/Editor/XChartEditor.cs +++ b/Assets/XCharts/Editor/XChartEditor.cs @@ -8,6 +8,7 @@ using UnityEditor; using UnityEngine; using UnityEngine.UI; +using UnityEngine.EventSystems; namespace XCharts { @@ -28,6 +29,10 @@ namespace XCharts canvas.renderMode = RenderMode.ScreenSpaceOverlay; canvasObject.AddComponent(); canvasObject.AddComponent(); + var eventSystem = new GameObject(); + eventSystem.name = "EventSystem"; + eventSystem.AddComponent(); + eventSystem.AddComponent(); return canvas.transform; } } diff --git a/Assets/XCharts/Runtime/API/BaseChart_API.cs b/Assets/XCharts/Runtime/API/BaseChart_API.cs index faf23efd..9d364671 100644 --- a/Assets/XCharts/Runtime/API/BaseChart_API.cs +++ b/Assets/XCharts/Runtime/API/BaseChart_API.cs @@ -21,7 +21,7 @@ namespace XCharts /// /// The theme info. /// - public ThemeInfo themeInfo { get { return m_ThemeInfo; } } + public ThemeInfo themeInfo { get { return m_ThemeInfo; } set { m_ThemeInfo = value; } } /// /// The title setting of chart. /// 标题组件 @@ -402,9 +402,19 @@ namespace XCharts var serie = m_Series.GetSerie(serieIndex); if (serie != null && !string.IsNullOrEmpty(serie.name)) { - var legendIndex = m_LegendRealShowName.IndexOf(serie.name); - var bgColor1 = active ? m_ThemeInfo.GetColor(legendIndex) : m_ThemeInfo.legendUnableColor; - m_Legend.UpdateButtonColor(serie.name, bgColor1); + UpdateLegendColor(serie.name, active); + } + } + + 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; } + /// + /// 刷新Tooltip组件。 + /// + public void RefreshTooltip() + { + InitTooltip(); + } + /// /// Update chart theme. /// 切换图表主题。 @@ -515,32 +533,62 @@ namespace XCharts m_Series.AnimationEnable(flag); } - /// - /// Start play animation. - /// 开始初始动画。 - /// + [Obsolete("Use BaseChart.AnimationFadeIn() instead.", true)] public void AnimationStart() { - m_Series.AnimationStart(); + } + + [Obsolete("Use BaseChart.AnimationFadeOut() instead.", true)] + public void MissAnimationStart() + { + } + + /// + /// fadeIn animation. + /// 开始渐入动画。 + /// + public void AnimationFadeIn() + { + m_Series.AnimationFadeIn(); + RefreshChart(); + } + + /// + /// fadeIn animation. + /// 开始渐出动画。 + /// + public void AnimationFadeOut() + { + m_Series.AnimationFadeOut(); + RefreshChart(); + } + + /// + /// Pause animation. + /// 暂停动画。 + /// + public void AnimationPause() + { + m_Series.AnimationPause(); + RefreshChart(); } /// /// Stop play animation. - /// 停止初始化动画。 + /// 继续动画。 /// - public void AnimationStop() + public void AnimationResume() { - m_CheckAnimation = false; - m_Series.AnimationStop(); + m_Series.AnimationResume(); + RefreshChart(); } /// - /// Reset animation to play. - /// 重置初始动画,重新播放。 + /// Reset animation. + /// 重置动画。 /// public void AnimationReset() { - m_CheckAnimation = false; m_Series.AnimationReset(); RefreshChart(); } diff --git a/Assets/XCharts/Runtime/API/RadarChart_API.cs b/Assets/XCharts/Runtime/API/RadarChart_API.cs index df8908fa..1c42afac 100644 --- a/Assets/XCharts/Runtime/API/RadarChart_API.cs +++ b/Assets/XCharts/Runtime/API/RadarChart_API.cs @@ -68,7 +68,7 @@ namespace XCharts radar.center[0] = center.x; radar.center[1] = center.y; radar.splitArea.show = showSplitArea; - radar.lineStyle.width = lineWidth; + radar.splitLine.lineStyle.width = lineWidth; m_Radars.Add(radar); return radar; } diff --git a/Assets/XCharts/Runtime/Component/Main/Axis.cs b/Assets/XCharts/Runtime/Component/Main/Axis.cs index 1da0f692..fa02cff1 100644 --- a/Assets/XCharts/Runtime/Component/Main/Axis.cs +++ b/Assets/XCharts/Runtime/Component/Main/Axis.cs @@ -191,20 +191,10 @@ namespace XCharts get { return m_RuntimeMinValue; } internal set { - if (value != m_RuntimeMinValue) - { - if (m_RuntimeMinValueFirstChanged) - { - m_RuntimeMinValueFirstChanged = false; - } - else - { - m_RuntimeLastMinValue = m_RuntimeMinValue; - m_RuntimeMinValueChanged = true; - m_RuntimeMinValueUpdateTime = Time.time; - } - m_RuntimeMinValue = value; - } + m_RuntimeMinValue = value; + m_RuntimeLastMinValue = value; + m_RuntimeMinValueUpdateTime = Time.time; + m_RuntimeMinValueChanged = true; } } /// @@ -216,20 +206,10 @@ namespace XCharts get { return m_RuntimeMaxValue; } internal set { - if (value != m_RuntimeMaxValue) - { - if (m_RuntimeMaxValueFirstChanged) - { - m_RuntimeMaxValueFirstChanged = false; - } - else - { - m_RuntimeLastMaxValue = m_RuntimeMaxValue; - m_RuntimeMaxValueChanged = true; - m_RuntimeMaxValueUpdateTime = Time.time; - } - m_RuntimeMaxValue = value; - } + m_RuntimeMaxValue = value; + m_RuntimeLastMaxValue = value; + m_RuntimeMaxValueUpdateTime = Time.time; + m_RuntimeMaxValueChanged = false; } } /// @@ -708,6 +688,62 @@ namespace XCharts 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) { if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0; diff --git a/Assets/XCharts/Runtime/Component/Main/Legend.cs b/Assets/XCharts/Runtime/Component/Main/Legend.cs index 3eb9dc5a..2b8a2278 100644 --- a/Assets/XCharts/Runtime/Component/Main/Legend.cs +++ b/Assets/XCharts/Runtime/Component/Main/Legend.cs @@ -43,14 +43,16 @@ namespace XCharts [SerializeField] private SelectedMode m_SelectedMode; [SerializeField] private Orient m_Orient = Orient.Horizonal; [SerializeField] private Location m_Location = Location.defaultRight; - [SerializeField] private float m_ItemWidth = 50.0f; - [SerializeField] private float m_ItemHeight = 20.0f; - [SerializeField] private float m_ItemGap = 5; - [SerializeField] private int m_ItemFontSize = 18; + [SerializeField] private float m_ItemWidth = 24.0f; + [SerializeField] private float m_ItemHeight = 12.0f; + [SerializeField] private float m_ItemGap = 10f; + [SerializeField] private bool m_ItemAutoColor = true; [SerializeField] private string m_Formatter; + [SerializeField] private TextStyle m_TextStyle = new TextStyle(18); [SerializeField] private List m_Data = new List(); + [SerializeField] private List m_Icons = new List(); - private Dictionary m_DataBtnList = new Dictionary(); + private Dictionary m_DataBtnList = new Dictionary(); /// /// Whether to show legend component. @@ -74,13 +76,13 @@ namespace XCharts /// public Location location { get { return m_Location; } set { m_Location = value; } } /// - /// the width of legend item. - /// 每个图例项的宽度。 + /// Image width of legend symbol. + /// 图例标记的图形宽度。 /// public float itemWidth { get { return m_ItemWidth; } set { m_ItemWidth = value; } } /// - /// the height of legend item. - /// 每个图例项的高度。 + /// Image height of legend symbol. + /// 图例标记的图形高度。 /// public float itemHeight { get { return m_ItemHeight; } set { m_ItemHeight = value; } } /// @@ -89,16 +91,21 @@ namespace XCharts /// public float itemGap { get { return m_ItemGap; } set { m_ItemGap = value; } } /// - /// font size of item text. - /// 图例项的字体大小。 + /// Whether the legend symbol matches the color automatically. + /// 图例标记的图形是否自动匹配颜色。 /// - public int itemFontSize { get { return m_ItemFontSize; } set { m_ItemFontSize = value; } } + public bool itemAutoColor { get { return m_ItemAutoColor; } set { m_ItemAutoColor = value; } } /// /// 图例内容字符串模版格式器。支持用 \n 换行。 /// 模板变量为图例名称 {name} /// public string formatter { get { return m_Formatter; } set { m_Formatter = value; } } /// + /// the style of text. + /// 文本样式。 + /// + public TextStyle textStyle { get { return m_TextStyle; } set { m_TextStyle = value; } } + /// /// 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. /// If data is not specified, it will be auto collected from series. @@ -107,11 +114,47 @@ namespace XCharts /// public List data { get { return m_Data; } } /// + /// 自定义的图例标记图形。 + /// + public List icons { get { return m_Icons; } } + /// /// the button list of legend. /// 图例按钮列表。 /// /// - public Dictionary buttonList { get { return m_DataBtnList; } } + public Dictionary 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; + } + } /// /// 一个在顶部居中显示的默认图例。 @@ -126,12 +169,13 @@ namespace XCharts m_SelectedMode = SelectedMode.Multiple, m_Orient = Orient.Horizonal, m_Location = Location.defaultTop, - m_ItemWidth = 60.0f, - m_ItemHeight = 20.0f, - m_ItemGap = 5, - m_ItemFontSize = 16 + m_ItemWidth = 24.0f, + m_ItemHeight = 12.0f, + m_ItemGap = 10f, }; legend.location.top = 30; + legend.textStyle.offset = new Vector2(2, 0); + legend.textStyle.fontSize = 18; return legend; } } @@ -144,9 +188,10 @@ namespace XCharts m_ItemWidth = legend.itemWidth; m_ItemHeight = legend.itemHeight; m_ItemGap = legend.itemGap; - m_ItemFontSize = legend.itemFontSize; - m_Data.Clear(); - foreach (var d in legend.data) m_Data.Add(d); + itemAutoColor = legend.itemAutoColor; + m_TextStyle.Copy(legend.textStyle); + ChartHelper.CopyList(m_Data, legend.data); + ChartHelper.CopyList(m_Icons, legend.icons); } public override bool Equals(object obj) @@ -178,8 +223,10 @@ namespace XCharts itemWidth == other.itemWidth && itemHeight == other.itemHeight && itemGap == other.itemGap && - itemFontSize == other.itemFontSize && - ChartHelper.IsValueEqualsList(m_Data, other.data); + itemAutoColor == other.itemAutoColor && + textStyle.Equals(other.textStyle) && + ChartHelper.IsValueEqualsList(m_Data, other.data) && + ChartHelper.IsValueEqualsList(m_Icons, other.icons); } public static bool operator ==(Legend left, Legend right) @@ -285,13 +332,11 @@ namespace XCharts /// /// /// - 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; - btn.transform.localPosition = GetButtonLocationPosition(total, index); - m_DataBtnList[name] = btn; - btn.gameObject.SetActive(show); - btn.GetComponentInChildren().text = name; + item.SetActive(show); } /// @@ -303,7 +348,27 @@ namespace XCharts { if (m_DataBtnList.ContainsKey(name)) { - m_DataBtnList[name].GetComponent().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(); } - - /// - /// 根据图例的布局和位置类型获得具体位置 - /// - /// - /// - /// - 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; - } - + /// /// 从json字符串解析数据,json格式如:['邮件营销','联盟广告','视频广告','直接访问','搜索引擎'] /// diff --git a/Assets/XCharts/Runtime/Component/Main/Radar.cs b/Assets/XCharts/Runtime/Component/Main/Radar.cs index a2e629c1..7ec5f4e2 100644 --- a/Assets/XCharts/Runtime/Component/Main/Radar.cs +++ b/Assets/XCharts/Runtime/Component/Main/Radar.cs @@ -126,7 +126,7 @@ namespace XCharts [SerializeField] private float m_Radius = 100; [SerializeField] private int m_SplitNumber = 5; [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 bool m_Indicator = true; [SerializeField] private PositionType m_PositionType = PositionType.Vertice; @@ -155,10 +155,10 @@ namespace XCharts /// public float[] center { get { return m_Center; } set { m_Center = value; } } /// - /// the line style of radar. - /// 线条样式。 + /// split line. + /// 分割线。 /// - public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } } + public AxisSplitLine splitLine { get { return m_SplitLine; } set { m_SplitLine = value; } } /// /// Split area of axis in grid area. /// 分割区域。 @@ -207,7 +207,7 @@ namespace XCharts var radar = new Radar { m_Shape = Shape.Polygon, - m_Radius = 0.4f, + m_Radius = 0.35f, m_SplitNumber = 5, m_Indicator = true, m_IndicatorList = new List(5){ @@ -219,9 +219,10 @@ namespace XCharts } }; radar.center[0] = 0.5f; - radar.center[1] = 0.45f; + radar.center[1] = 0.4f; + radar.splitLine.show = true; radar.splitArea.show = true; - radar.lineStyle.width = 0.6f; + radar.splitLine.lineStyle.width = 0.6f; return radar; } } @@ -234,6 +235,8 @@ namespace XCharts m_Center[0] = other.center[0]; m_Center[1] = other.center[1]; m_Indicator = other.indicator; + //m_SplitLine.Copy(other.splitLine); + //m_SplitArea.Copy(other.splitArea); indicatorList.Clear(); foreach (var d in other.indicatorList) indicatorList.Add(d.Clone()); } diff --git a/Assets/XCharts/Runtime/Component/Main/Serie.cs b/Assets/XCharts/Runtime/Component/Main/Serie.cs index 737983f7..4e33ab0a 100644 --- a/Assets/XCharts/Runtime/Component/Main/Serie.cs +++ b/Assets/XCharts/Runtime/Component/Main/Serie.cs @@ -194,7 +194,7 @@ namespace XCharts [System.Serializable] 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 string m_Name; [SerializeField] private string m_Stack; @@ -246,7 +246,7 @@ namespace XCharts [SerializeField] [Range(1, 10)] private int m_ShowDataDimension; [SerializeField] private bool m_ShowDataName; [SerializeField] private bool m_ShowDataIcon; - [SerializeField] private bool m_Clip = false; + [SerializeField] private bool m_Clip = true; [SerializeField] private List m_Data = new List(); @@ -501,6 +501,10 @@ namespace XCharts /// public int showDataDimension { get { return m_ShowDataDimension; } } /// + /// 在Editor的inpsector上是否显示name参数 + /// + public bool showDataName { get { return m_ShowDataName; } set { m_ShowDataName = value; } } + /// /// If clip the overflow on the coordinate system. /// 是否裁剪超出坐标系部分的图形。 /// diff --git a/Assets/XCharts/Runtime/Component/Main/Series.cs b/Assets/XCharts/Runtime/Component/Main/Series.cs index 5d55b39a..b7ba8f24 100644 --- a/Assets/XCharts/Runtime/Component/Main/Series.cs +++ b/Assets/XCharts/Runtime/Component/Main/Series.cs @@ -56,7 +56,7 @@ namespace XCharts /// public void ClearData() { - AnimationStop(); + AnimationPause(); foreach (var serie in m_Series) { serie.ClearData(); @@ -196,7 +196,7 @@ namespace XCharts { foreach (var serie in m_Series) { - if (serie.animation.enable && serie.animation.updateAnimation) + if (serie.animation.enable && serie.animation.dataChangeEnable) { return true; } @@ -257,7 +257,7 @@ namespace XCharts /// public void RemoveAll() { - AnimationStop(); + AnimationPause(); m_Series.Clear(); } @@ -292,7 +292,7 @@ namespace XCharts { serie.symbol.type = SerieSymbolType.None; } - serie.animation.Reset(); + serie.animation.Restart(); m_Series.Add(serie); return serie; } @@ -615,6 +615,8 @@ namespace XCharts if (serie != null) { serie.show = active; + serie.animation.Reset(); + if (active) serie.animation.FadeIn(); } } @@ -1006,32 +1008,54 @@ namespace XCharts } /// - /// 开始初始动画 + /// 渐入动画 /// - public void AnimationStart() + public void AnimationFadeIn() { foreach (var serie in m_Series) { if (serie.animation.enable) { - serie.animation.Start(); + serie.animation.FadeIn(); } } } /// - /// 停止初始动画 + /// 渐出动画 /// - public void AnimationStop() + public void AnimationFadeOut() { foreach (var serie in m_Series) { - if (serie.animation.enable) serie.animation.Stop(); + if (serie.animation.enable) serie.animation.FadeOut(); } } /// - /// 重置初始动画 + /// 暂停动画 + /// + public void AnimationPause() + { + foreach (var serie in m_Series) + { + if (serie.animation.enable) serie.animation.Pause(); + } + } + + /// + /// 继续动画 + /// + public void AnimationResume() + { + foreach (var serie in m_Series) + { + if (serie.animation.enable) serie.animation.Resume(); + } + } + + /// + /// 重置动画 /// public void AnimationReset() { diff --git a/Assets/XCharts/Runtime/Component/Main/Theme.cs b/Assets/XCharts/Runtime/Component/Main/Theme.cs index d65ac0aa..5c82bf74 100644 --- a/Assets/XCharts/Runtime/Component/Main/Theme.cs +++ b/Assets/XCharts/Runtime/Component/Main/Theme.cs @@ -132,6 +132,8 @@ namespace XCharts get { return m_CustomLegendTextColor != Color.clear ? m_CustomLegendTextColor : m_LegendTextColor; } set { m_CustomLegendTextColor = value; } } + + public Color32 defaultLegendTextColor{get{return m_LegendTextColor;}set{m_LegendTextColor=value;}} /// /// the legend unable text color. /// 图例变为不可用时的按钮颜色。 @@ -391,7 +393,7 @@ namespace XCharts m_LegendUnableColor = GetColor("#cccccc"), m_TitleTextColor = GetColor("#514D4D"), m_TitleSubTextColor = GetColor("#514D4D"), - m_LegendTextColor = GetColor("#eee"), + m_LegendTextColor = GetColor("#514D4D"), m_AxisTextColor = GetColor("#514D4D"), m_AxisLineColor = GetColor("#514D4D"), m_AxisSplitLineColor = GetColor("#51515120"), diff --git a/Assets/XCharts/Runtime/Component/Main/Tooltip.cs b/Assets/XCharts/Runtime/Component/Main/Tooltip.cs index e7b081ed..6661c454 100644 --- a/Assets/XCharts/Runtime/Component/Main/Tooltip.cs +++ b/Assets/XCharts/Runtime/Component/Main/Tooltip.cs @@ -1,4 +1,5 @@ -/******************************************/ +using System.Collections.ObjectModel; +/******************************************/ /* */ /* Copyright (c) 2018 monitor1394 */ /* https://github.com/monitor1394 */ @@ -8,6 +9,8 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; +using System; +using UnityEngine.EventSystems; namespace XCharts { @@ -55,12 +58,11 @@ namespace XCharts [SerializeField] private float m_FixedHeight = 0; [SerializeField] private float m_MinWidth = 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 float m_PaddingLeftRight = 5f; [SerializeField] private float m_PaddingTopBottom = 5f; [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); private GameObject m_GameObject; @@ -138,16 +140,10 @@ namespace XCharts /// 最小高度。如若 fixedHeight 设有值,优先取 fixedHeight。 /// public float minHeight { get { return m_MinHeight; } set { m_MinHeight = value; } } - /// - /// font size. - /// 文字的字体大小。 - /// - public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } } - /// - /// font style. - /// 文字的字体风格。 - /// - public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } } + [Obsolete("Use Tooltip.textStyle.fontSize instead.", true)] + public int fontSize { get; set; } + [Obsolete("Use Tooltip.textStyle.fontStyle instead.", true)] + public FontStyle fontStyle { get; set; } /// /// 是否强制使用科学计数法格式化显示数值。默认为false,当小数精度大于3时才采用科学计数法。 /// @@ -168,6 +164,10 @@ namespace XCharts /// public Sprite backgroundImage { get { return m_BackgroundImage; } set { m_BackgroundImage = value; SetBackground(m_BackgroundImage); } } /// + /// 提示框内容文本样式。 + /// + public TextStyle textStyle { get { return m_TextStyle; } set { if (value != null) m_TextStyle = value; } } + /// /// 指示线样式。 /// public LineStyle lineStyle { get { return m_LineStyle; } set { if (value != null) m_LineStyle = value; } } diff --git a/Assets/XCharts/Runtime/Component/Sub/AxisSplitLine.cs b/Assets/XCharts/Runtime/Component/Sub/AxisSplitLine.cs index 3ddb9062..6acd95d0 100644 --- a/Assets/XCharts/Runtime/Component/Sub/AxisSplitLine.cs +++ b/Assets/XCharts/Runtime/Component/Sub/AxisSplitLine.cs @@ -85,7 +85,7 @@ namespace XCharts internal bool NeedShow(int index) { - return interval == 0 || index % (interval + 1) == 0; + return show && (interval == 0 || index % (interval + 1) == 0); } } } \ No newline at end of file diff --git a/Assets/XCharts/Runtime/Component/Sub/LineStyle.cs b/Assets/XCharts/Runtime/Component/Sub/LineStyle.cs index 67064716..aa0a1dd9 100644 --- a/Assets/XCharts/Runtime/Component/Sub/LineStyle.cs +++ b/Assets/XCharts/Runtime/Component/Sub/LineStyle.cs @@ -52,7 +52,7 @@ namespace XCharts /// /// Whether show line. - /// 是否显示线条。在折线图中无效。 + /// 是否显示线条。当作为子组件,它的父组件有参数控制是否显示时,改参数无效。 /// public bool show { get { return m_Show; } set { m_Show = value; } } /// diff --git a/Assets/XCharts/Runtime/Component/Sub/SerieAnimation.cs b/Assets/XCharts/Runtime/Component/Sub/SerieAnimation.cs index 4a6b95a4..c548e1f9 100644 --- a/Assets/XCharts/Runtime/Component/Sub/SerieAnimation.cs +++ b/Assets/XCharts/Runtime/Component/Sub/SerieAnimation.cs @@ -1,4 +1,5 @@ -/******************************************/ +using System.Threading; +/******************************************/ /* */ /* Copyright (c) 2018 monitor1394 */ /* https://github.com/monitor1394 */ @@ -23,11 +24,12 @@ namespace XCharts } [SerializeField] private bool m_Enable = true; [SerializeField] private Easing m_Easting; - [SerializeField] private float m_Duration = 1000; [SerializeField] private int m_Threshold = 2000; - [SerializeField] private float m_Delay = 0; - [SerializeField] private bool m_UpdateAnimation = true; - [SerializeField] private float m_UpdateDuration = 500; + [SerializeField] private float m_FadeInDuration = 1000; + [SerializeField] private float m_FadeInDelay = 0; + [SerializeField] private float m_FadeOutDuration = 1000f; + [SerializeField] private bool m_DataChangeEnable = true; + [SerializeField] private float m_DataChangeDuration = 500; [SerializeField] private float m_ActualDuration; /// @@ -39,12 +41,17 @@ namespace XCharts /// Easing method used for the first animation. /// 动画的缓动效果。 /// - public Easing easing { get { return m_Easting; } set { m_Easting = value; } } + //public Easing easing { get { return m_Easting; } set { m_Easting = value; } } /// - /// The milliseconds duration of the first animation. - /// 设定的动画时长(毫秒)。 + /// The milliseconds duration of the fadeIn animation. + /// 设定的渐入动画时长(毫秒)。 /// - 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; } } + /// + /// The milliseconds duration of the fadeOut animation. + /// 设定的渐出动画时长(毫秒)。 + /// + public float fadeOutDuration { get { return m_FadeOutDuration; } set { m_FadeOutDuration = value < 0 ? 0 : value; } } /// /// The milliseconds actual duration of the first animation. /// 实际的动画时长(毫秒)。 @@ -59,21 +66,24 @@ namespace XCharts /// The milliseconds delay before updating the first animation. /// 动画延时(毫秒)。 /// - 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; } } /// /// 是否开启数据变更动画。 /// - public bool updateAnimation { get { return m_UpdateAnimation; } set { m_UpdateAnimation = value; } } + public bool dataChangeEnable { get { return m_DataChangeEnable; } set { m_DataChangeEnable = value; } } /// - /// The milliseconds duration of the first animation. + /// The milliseconds duration of the data change animation. /// 数据变更的动画时长(毫秒)。 /// - 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 m_DataAnimationState = new Dictionary(); - private bool m_IsStart = false; + private bool m_FadeIn = false; 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 int m_CurrDataProgress { get; set; } @@ -82,13 +92,21 @@ namespace XCharts [SerializeField] private float m_DestDetailProgress; 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; - m_IsStart = true; + m_FadeIn = true; m_IsEnd = false; - m_Inited = false; + m_IsInit = false; + m_IsPause = false; + m_FadeOuted = false; m_CurrDataProgress = 1; m_DestDataProgress = 1; m_CurrDetailProgress = 0; @@ -97,34 +115,89 @@ namespace XCharts m_DataAnimationState.Clear(); } - public void Stop() + public void Restart() { - m_IsStart = false; - m_IsEnd = true; - m_Inited = false; + Reset(); + FadeIn(); + } + + 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(); } - 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; 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_IsInit = false; + if (m_FadeOut) + { + m_FadeOut = false; + m_FadeOuted = true; + } } public void Reset() { - Stop(); - Start(); + m_FadeIn = false; + 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) { - 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_DestDetailProgress = dest; } @@ -132,23 +205,21 @@ namespace XCharts public void SetDataFinish(int dataIndex) { - if (!m_IsEnd) - { - m_CurrDataProgress = dataIndex + 1; - } + if (m_IsEnd) return; + m_CurrDataProgress = dataIndex + (m_FadeOut ? -1 : 1); } - public void SetDataState(int index, float state) + private void SetDataState(int index, float 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)) { - m_DataAnimationState.Add(index, 0); + m_DataAnimationState.Add(index, dest); } return m_DataAnimationState[index]; } @@ -182,29 +253,95 @@ namespace XCharts { if (!m_Enable || m_IsEnd) return true; 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 (m_IsEnd) return; - if (m_CurrDetailProgress > m_DestDetailProgress) + m_ActualDuration = (int)((Time.time - startTime) * 1000) - delay; + 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 { - m_ActualDuration = (int)((Time.time - startTime) * 1000) - delay; 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_CurrSymbolProgress > dest) m_CurrSymbolProgress = dest; + if (m_FadeOut) return m_FadeOutDuration > 0 ? m_FadeOutDuration / 1000 : 1; + 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) @@ -212,7 +349,8 @@ namespace XCharts #if UNITY_EDITOR if (!Application.isPlaying) return dest; #endif - if (!enable || m_IsEnd) return dest; + if (!enable) return dest; + if (m_IsEnd) return m_FadeOut ? 0 : dest; return m_CurrSymbolProgress; } @@ -246,8 +384,13 @@ namespace XCharts public float GetUpdateAnimationDuration() { - if (m_Enable && m_UpdateAnimation && IsFinish()) return m_UpdateDuration; + if (m_Enable && m_DataChangeEnable && IsFinish()) return m_DataChangeDuration; else return 0; } + + public bool HasFadeOut() + { + return enable && m_FadeOuted && m_IsEnd; + } } } \ No newline at end of file diff --git a/Assets/XCharts/Runtime/Component/Sub/TextStyle.cs b/Assets/XCharts/Runtime/Component/Sub/TextStyle.cs index 79518a4a..4837eb66 100644 --- a/Assets/XCharts/Runtime/Component/Sub/TextStyle.cs +++ b/Assets/XCharts/Runtime/Component/Sub/TextStyle.cs @@ -1,4 +1,3 @@ -using System.Threading; /******************************************/ /* */ /* Copyright (c) 2018 monitor1394 */ @@ -18,11 +17,18 @@ namespace XCharts [Serializable] public class TextStyle : SubComponent, IEquatable { + [SerializeField] private Font m_Font; [SerializeField] private float m_Rotate = 0; [SerializeField] private Vector2 m_Offset = Vector2.zero; [SerializeField] private Color m_Color = Color.clear; + [SerializeField] private Color m_BackgroundColor = Color.clear; [SerializeField] private int m_FontSize = 18; [SerializeField] private 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; /// /// Rotation of text. @@ -43,6 +49,16 @@ namespace XCharts /// public Color color { get { return m_Color; } set { m_Color = value; } } /// + /// the color of text. + /// 文本的背景颜色。 + /// + public Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } } + /// + /// the font of text. + /// 文本字体 + /// + public Font font { get { return m_Font; } set { m_Font = value; } } + /// /// font size. /// 文本字体大小。 /// @@ -52,6 +68,11 @@ namespace XCharts /// 文本字体的风格。 /// public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } } + /// + /// text line spacing. + /// 行间距。 + /// + public float lineSpacing { get { return m_LineSpacing; } set { m_LineSpacing = value; } } public TextStyle() { @@ -88,8 +109,10 @@ namespace XCharts this.fontSize = style.fontSize; this.fontStyle = style.fontStyle; this.color = style.color; + this.backgroundColor = style.backgroundColor; this.rotate = style.rotate; this.offset = style.offset; + this.lineSpacing = style.lineSpacing; } public TextStyle Clone() @@ -97,9 +120,11 @@ namespace XCharts var textStyle = new TextStyle(); textStyle.rotate = rotate; textStyle.color = color; + textStyle.backgroundColor = backgroundColor; textStyle.fontSize = fontSize; textStyle.fontStyle = fontStyle; textStyle.offset = offset; + textStyle.lineSpacing = lineSpacing; return textStyle; } @@ -129,6 +154,8 @@ namespace XCharts fontSize == other.fontSize && fontStyle == other.fontStyle && offset == other.offset && + lineSpacing == other.lineSpacing && + ChartHelper.IsValueEqualsColor(m_BackgroundColor, other.backgroundColor) && ChartHelper.IsValueEqualsColor(m_Color, other.color); } diff --git a/Assets/XCharts/Runtime/GaugeChart.cs b/Assets/XCharts/Runtime/GaugeChart.cs index 0ade3e77..8180e258 100644 --- a/Assets/XCharts/Runtime/GaugeChart.cs +++ b/Assets/XCharts/Runtime/GaugeChart.cs @@ -64,7 +64,7 @@ namespace XCharts serie.center[1] = 0.5f; serie.radius[0] = 80; serie.splitNumber = 5; - serie.animation.updateAnimation = true; + serie.animation.dataChangeEnable = true; serie.titleStyle.show = true; serie.titleStyle.textStyle.offset = new Vector2(0, 20); serie.label.show = true; @@ -85,7 +85,7 @@ namespace XCharts for (int i = 0; i < m_Series.Count; i++) { var serie = m_Series.list[i]; - + var serieLabel = serie.gaugeAxis.axisLabel; serie.gaugeAxis.ClearLabelObject(); var count = serie.splitNumber > 36 ? 36 : (serie.splitNumber + 1); @@ -103,7 +103,7 @@ namespace XCharts item.SetIconActive(false); serie.gaugeAxis.AddLabelObject(item); } - UpdateAxisLabel(serie); + UpdateAxisLabel(serie); } } @@ -130,14 +130,15 @@ namespace XCharts private void DrawGauge(VertexHelper vh, Serie serie) { + serie.UpdateCenter(chartWidth, chartHeight); var destAngle = GetCurrAngle(serie, true); serie.animation.InitProgress(0, serie.startAngle, destAngle); + //var currAngle = serie.animation.GetCurrDetail(); var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail(); - DrawProgressBar(vh, serie, currAngle); DrawStageColor(vh, serie); - DrawSplitLine(vh, serie); + DrawLineStyle(vh, serie); DrawAxisTick(vh, serie); DrawPointer(vh, serie, currAngle); UpdateTitle(serie); @@ -147,9 +148,7 @@ namespace XCharts CheckAnimation(serie); if (!serie.animation.IsFinish()) { - float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1; - float speed = (destAngle - serie.startAngle) / duration; - serie.animation.CheckProgress(Time.deltaTime * speed); + serie.animation.CheckProgress(destAngle - serie.startAngle); RefreshChart(); } else if (NeedRefresh(serie)) @@ -215,7 +214,7 @@ namespace XCharts 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.gaugeAxis.show || !serie.gaugeAxis.splitLine.show) return; @@ -405,6 +404,10 @@ namespace XCharts private float GetCurrAngle(Serie serie, bool dest) { + if (serie.animation.HasFadeOut()) + { + return serie.animation.GetCurrDetail(); + } float rangeValue = serie.max - serie.min; float rangeAngle = serie.endAngle - serie.startAngle; float value = 0; diff --git a/Assets/XCharts/Runtime/HeatmapChart.cs b/Assets/XCharts/Runtime/HeatmapChart.cs index a38c40ae..edb1fd21 100644 --- a/Assets/XCharts/Runtime/HeatmapChart.cs +++ b/Assets/XCharts/Runtime/HeatmapChart.cs @@ -85,7 +85,7 @@ namespace XCharts } #endif - protected override void RefreshTooltip() + protected override void UpdateTooltip() { var xData = m_Tooltip.runtimeXValues[0]; var yData = m_Tooltip.runtimeYValues[0]; diff --git a/Assets/XCharts/Runtime/Helper/LegendHelper.cs b/Assets/XCharts/Runtime/Helper/LegendHelper.cs new file mode 100644 index 00000000..96c81151 --- /dev/null +++ b/Assets/XCharts/Runtime/Helper/LegendHelper.cs @@ -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(btnObj); + img.color = Color.clear; + ChartHelper.GetOrAddComponent