This commit is contained in:
monitor1394
2020-03-02 18:00:05 +08:00
51 changed files with 286632 additions and 77828 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``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`等参数不生效的问题

View File

@@ -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)
{

View File

@@ -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;

View File

@@ -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)
{

View File

@@ -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`

View File

@@ -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`:实线。

View File

@@ -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);

View File

@@ -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)
{

View File

@@ -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))

View File

@@ -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"));

View File

@@ -14,49 +14,57 @@ namespace XCharts
[CustomPropertyDrawer(typeof(TextStyle), true)]
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)
{
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;
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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<CanvasScaler>();
canvasObject.AddComponent<GraphicRaycaster>();
var eventSystem = new GameObject();
eventSystem.name = "EventSystem";
eventSystem.AddComponent<EventSystem>();
eventSystem.AddComponent<StandaloneInputModule>();
return canvas.transform;
}
}

View File

@@ -21,7 +21,7 @@ namespace XCharts
/// <summary>
/// The theme info.
/// </summary>
public ThemeInfo themeInfo { get { return m_ThemeInfo; } }
public ThemeInfo themeInfo { get { return m_ThemeInfo; } set { m_ThemeInfo = value; } }
/// <summary>
/// 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;
}
/// <summary>
/// 刷新Tooltip组件。
/// </summary>
public void RefreshTooltip()
{
InitTooltip();
}
/// <summary>
/// Update chart theme.
/// 切换图表主题。
@@ -515,32 +533,62 @@ namespace XCharts
m_Series.AnimationEnable(flag);
}
/// <summary>
/// Start play animation.
/// 开始初始动画。
/// </summary>
[Obsolete("Use BaseChart.AnimationFadeIn() instead.", true)]
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>
/// Stop play animation.
/// 停止初始化动画。
/// 继续动画。
/// </summary>
public void AnimationStop()
public void AnimationResume()
{
m_CheckAnimation = false;
m_Series.AnimationStop();
m_Series.AnimationResume();
RefreshChart();
}
/// <summary>
/// Reset animation to play.
/// 重置初始动画,重新播放
/// Reset animation.
/// 重置动画
/// </summary>
public void AnimationReset()
{
m_CheckAnimation = false;
m_Series.AnimationReset();
RefreshChart();
}

View File

@@ -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;
}

View File

@@ -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;
}
}
/// <summary>
@@ -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;
}
}
/// <summary>
@@ -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;

View File

@@ -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<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>
/// Whether to show legend component.
@@ -74,13 +76,13 @@ namespace XCharts
/// </summary>
public Location location { get { return m_Location; } set { m_Location = value; } }
/// <summary>
/// the width of legend item.
/// 每个图例项的宽度。
/// Image width of legend symbol.
/// 图例标记的图形宽度。
/// </summary>
public float itemWidth { get { return m_ItemWidth; } set { m_ItemWidth = value; } }
/// <summary>
/// the height of legend item.
/// 每个图例项的高度。
/// Image height of legend symbol.
/// 图例标记的图形高度。
/// </summary>
public float itemHeight { get { return m_ItemHeight; } set { m_ItemHeight = value; } }
/// <summary>
@@ -89,16 +91,21 @@ namespace XCharts
/// </summary>
public float itemGap { get { return m_ItemGap; } set { m_ItemGap = value; } }
/// <summary>
/// font size of item text.
/// 图例项的字体大小
/// Whether the legend symbol matches the color automatically.
/// 图例标记的图形是否自动匹配颜色
/// </summary>
public int itemFontSize { get { return m_ItemFontSize; } set { m_ItemFontSize = value; } }
public bool itemAutoColor { get { return m_ItemAutoColor; } set { m_ItemAutoColor = value; } }
/// <summary>
/// 图例内容字符串模版格式器。支持用 \n 换行。
/// 模板变量为图例名称 {name}
/// </summary>
public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }
/// <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,
/// 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
/// </summary>
public List<string> data { get { return m_Data; } }
/// <summary>
/// 自定义的图例标记图形。
/// </summary>
public List<Sprite> icons { get { return m_Icons; } }
/// <summary>
/// the button list of legend.
/// 图例按钮列表。
/// </summary>
/// <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>
/// 一个在顶部居中显示的默认图例。
@@ -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<string>(m_Data, legend.data);
ChartHelper.CopyList<Sprite>(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<string>(m_Data, other.data);
itemAutoColor == other.itemAutoColor &&
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)
@@ -285,13 +332,11 @@ namespace XCharts
/// <param name="name"></param>
/// <param name="btn"></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;
btn.transform.localPosition = GetButtonLocationPosition(total, index);
m_DataBtnList[name] = btn;
btn.gameObject.SetActive(show);
btn.GetComponentInChildren<Text>().text = name;
item.SetActive(show);
}
/// <summary>
@@ -303,7 +348,27 @@ namespace XCharts
{
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();
}
/// <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>
/// 从json字符串解析数据json格式如['邮件营销','联盟广告','视频广告','直接访问','搜索引擎']
/// </summary>

View File

@@ -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
/// </summary>
public float[] center { get { return m_Center; } set { m_Center = value; } }
/// <summary>
/// the line style of radar.
/// 线条样式
/// split line.
/// 分割线。
/// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
public AxisSplitLine splitLine { get { return m_SplitLine; } set { m_SplitLine = value; } }
/// <summary>
/// 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<Indicator>(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());
}

View File

@@ -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<SerieData> m_Data = new List<SerieData>();
@@ -501,6 +501,10 @@ namespace XCharts
/// </summary>
public int showDataDimension { get { return m_ShowDataDimension; } }
/// <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.
/// 是否裁剪超出坐标系部分的图形。
/// </summary>

View File

@@ -56,7 +56,7 @@ namespace XCharts
/// </summary>
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
/// </summary>
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
}
/// <summary>
/// 开始初始动画
/// 渐入动画
/// </summary>
public void AnimationStart()
public void AnimationFadeIn()
{
foreach (var serie in m_Series)
{
if (serie.animation.enable)
{
serie.animation.Start();
serie.animation.FadeIn();
}
}
}
/// <summary>
/// 停止初始动画
/// 渐出动画
/// </summary>
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();
}
}
/// <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>
public void AnimationReset()
{

View File

@@ -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;}}
/// <summary>
/// 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"),

View File

@@ -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。
/// </summary>
public float minHeight { get { return m_MinHeight; } set { m_MinHeight = value; } }
/// <summary>
/// font size.
/// 文字的字体大小。
/// </summary>
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; } }
[Obsolete("Use Tooltip.textStyle.fontSize instead.", true)]
public int fontSize { get; set; }
[Obsolete("Use Tooltip.textStyle.fontStyle instead.", true)]
public FontStyle fontStyle { get; set; }
/// <summary>
/// 是否强制使用科学计数法格式化显示数值。默认为false当小数精度大于3时才采用科学计数法。
/// </summary>
@@ -168,6 +164,10 @@ namespace XCharts
/// </summary>
public Sprite backgroundImage { get { return m_BackgroundImage; } set { m_BackgroundImage = value; SetBackground(m_BackgroundImage); } }
/// <summary>
/// 提示框内容文本样式。
/// </summary>
public TextStyle textStyle { get { return m_TextStyle; } set { if (value != null) m_TextStyle = value; } }
/// <summary>
/// 指示线样式。
/// </summary>
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)
{
return interval == 0 || index % (interval + 1) == 0;
return show && (interval == 0 || index % (interval + 1) == 0);
}
}
}

View File

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

View File

@@ -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;
/// <summary>
@@ -39,12 +41,17 @@ namespace XCharts
/// Easing method used for the first animation.
/// 动画的缓动效果。
/// </summary>
public Easing easing { get { return m_Easting; } set { m_Easting = value; } }
//public Easing easing { get { return m_Easting; } set { m_Easting = value; } }
/// <summary>
/// The milliseconds duration of the first animation.
/// 设定的动画时长(毫秒)。
/// The milliseconds duration of the fadeIn animation.
/// 设定的渐入动画时长(毫秒)。
/// </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>
/// The milliseconds actual duration of the first animation.
/// 实际的动画时长(毫秒)。
@@ -59,21 +66,24 @@ namespace XCharts
/// The milliseconds delay before updating the first animation.
/// 动画延时(毫秒)。
/// </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>
public bool updateAnimation { get { return m_UpdateAnimation; } set { m_UpdateAnimation = value; } }
public bool dataChangeEnable { get { return m_DataChangeEnable; } set { m_DataChangeEnable = value; } }
/// <summary>
/// The milliseconds duration of the first animation.
/// The milliseconds duration of the data change animation.
/// 数据变更的动画时长(毫秒)。
/// </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 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;
}
}
}

View File

@@ -1,4 +1,3 @@
using System.Threading;
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
@@ -18,11 +17,18 @@ namespace XCharts
[Serializable]
public class TextStyle : SubComponent, IEquatable<TextStyle>
{
[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;
/// <summary>
/// Rotation of text.
@@ -43,6 +49,16 @@ namespace XCharts
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <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.
/// 文本字体大小。
/// </summary>
@@ -52,6 +68,11 @@ namespace XCharts
/// 文本字体的风格。
/// </summary>
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()
{
@@ -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);
}

View File

@@ -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;

View File

@@ -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];

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_ReinitTitle = 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>();
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
@@ -92,8 +92,8 @@ namespace XCharts
InitSerieLabel();
InitSerieTitle();
InitTooltip();
m_Series.AnimationStop();
m_Series.AnimationStart();
m_Series.AnimationReset();
m_Series.AnimationFadeIn();
}
protected override void Start()
@@ -142,6 +142,11 @@ namespace XCharts
m_Series = Series.defaultSeries;
Awake();
}
protected override void OnValidate()
{
//TODO:
}
#endif
protected override void OnDestroy()
@@ -170,8 +175,8 @@ namespace XCharts
Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform,
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,
m_Title.textStyle.fontStyle);
new Vector2(titleWid, m_Title.textStyle.fontSize), m_Title.textStyle.fontSize,
m_Title.textStyle.rotate, m_Title.textStyle.fontStyle, m_Title.textStyle.lineSpacing);
titleText.alignment = anchor;
titleText.gameObject.SetActive(m_Title.show);
@@ -181,7 +186,7 @@ namespace XCharts
Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform,
m_ThemeInfo.font, m_ThemeInfo.titleSubTextColor, anchor, anchorMin, anchorMax, pivot,
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.gameObject.SetActive(m_Title.show && !string.IsNullOrEmpty(m_Title.subText));
@@ -230,21 +235,18 @@ namespace XCharts
string legendName = m_Legend.GetFormatterContent(datas[i]);
var readIndex = m_LegendRealShowName.IndexOf(datas[i]);
var objName = s_LegendObjectName + "_" + i + "_" + datas[i];
Button btn = ChartHelper.AddButtonObject(objName, legendObject.transform,
m_ThemeInfo.font, m_Legend.itemFontSize, m_ThemeInfo.legendTextColor, anchor,
anchorMin, anchorMax, pivot, new Vector2(m_Legend.itemWidth, m_Legend.itemHeight));
var bgColor = IsActiveByLegend(datas[i]) ?
m_ThemeInfo.GetColor(readIndex) : m_ThemeInfo.legendUnableColor;
m_Legend.SetButton(legendName, btn, totalLegend);
m_Legend.UpdateButtonColor(legendName, bgColor);
btn.GetComponentInChildren<Text>().text = legendName;
ChartHelper.ClearEventListener(btn.gameObject);
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
var active = IsActiveByLegend(datas[i]);
var bgColor = LegendHelper.GetIconColor(m_Legend, readIndex, themeInfo, active);
var item = LegendHelper.AddLegendItem(m_Legend, i, datas[i], legendObject.transform, m_ThemeInfo,
legendName, bgColor, active);
m_Legend.SetButton(legendName, item, totalLegend);
ChartHelper.ClearEventListener(item.button.gameObject);
ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) =>
{
if (data.selectedObject == null || m_Legend.selectedMode == Legend.SelectedMode.None) return;
var temp = data.selectedObject.name.Split('_');
string selectedName = temp[2];
int clickedIndex = int.Parse(temp[1]);
string selectedName = temp[1];
int clickedIndex = int.Parse(temp[0]);
if (m_Legend.selectedMode == Legend.SelectedMode.Multiple)
{
OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName));
@@ -261,27 +263,27 @@ namespace XCharts
for (int n = 0; n < btnList.Length; n++)
{
temp = btnList[n].name.Split('_');
selectedName = temp[2];
var index = int.Parse(temp[1]);
selectedName = btnList[n].legendName;
var index = btnList[n].index;
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;
var temp = btn.name.Split('_');
string selectedName = temp[2];
int index = int.Parse(temp[1]);
if (item.button == null) return;
var temp = item.button.name.Split('_');
string selectedName = temp[1];
int index = int.Parse(temp[0]);
OnLegendButtonEnter(index, selectedName);
});
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerExit, (data) =>
ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerExit, (data) =>
{
if (btn == null) return;
var temp = btn.name.Split('_');
string selectedName = temp[2];
int index = int.Parse(temp[1]);
if (item.button == null) return;
var temp = item.button.name.Split('_');
string selectedName = temp[1];
int index = int.Parse(temp[0]);
OnLegendButtonExit(index, selectedName);
});
}
@@ -292,6 +294,7 @@ namespace XCharts
OnLegendButtonClick(n, m_LegendRealShowName[n], n == 0 ? true : false);
}
}
LegendHelper.ResetItemPosition(m_Legend);
}
private void InitSerieLabel()
@@ -349,8 +352,9 @@ namespace XCharts
var pivot = new Vector2(0.5f, 0.5f);
var fontSize = 10;
var sizeDelta = new Vector2(50, fontSize + 2);
var txt = ChartHelper.AddTextObject("title_" + i, titleObject.transform, m_ThemeInfo.font, color, TextAnchor.MiddleCenter,
anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize, textStyle.rotate, textStyle.fontStyle);
var txt = ChartHelper.AddTextObject("title_" + i, titleObject.transform, m_ThemeInfo.font, color,
TextAnchor.MiddleCenter, anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize, textStyle.rotate,
textStyle.fontStyle, textStyle.lineSpacing);
txt.text = "";
txt.transform.localPosition = new Vector2(0, 0);
txt.transform.localEulerAngles = Vector2.zero;
@@ -372,9 +376,10 @@ namespace XCharts
tooltipObject.transform.localPosition = Vector3.zero;
DestroyImmediate(tooltipObject.GetComponent<Image>());
var parent = tooltipObject.transform;
var textStyle = m_Tooltip.textStyle;
ChartHelper.HideAllObject(tooltipObject.transform);
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.SetContentObj(content);
m_Tooltip.SetContentBackgroundColor(m_ThemeInfo.tooltipBackgroundColor);
@@ -562,7 +567,7 @@ namespace XCharts
if (!m_CheckAnimation)
{
m_CheckAnimation = true;
m_Series.AnimationStart();
m_Series.AnimationFadeIn();
}
}
@@ -687,7 +692,7 @@ namespace XCharts
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)
{
var labelHalfWid = serieData.GetLabelWidth() / 2;

View File

@@ -141,7 +141,7 @@ namespace XCharts
{
base.DrawChart(vh);
if (!m_CheckMinMaxValue) return;
m_IsPlayingStartAnimation = false;
m_IsPlayingAnimation = false;
bool yCategory = m_YAxises[0].IsCategory() || m_YAxises[1].IsCategory();
m_Series.GetStackSeries(ref m_StackSeries);
int seriesCount = m_StackSeries.Count;
@@ -194,7 +194,7 @@ namespace XCharts
if (!IsInCooridate(local))
{
m_Tooltip.ClearValue();
RefreshTooltip();
UpdateTooltip();
}
else
{
@@ -306,7 +306,7 @@ namespace XCharts
if (m_Tooltip.IsSelected())
{
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
RefreshTooltip();
UpdateTooltip();
if (m_Tooltip.IsDataIndexChanged() || m_Tooltip.type == Tooltip.Type.Corss)
{
m_Tooltip.UpdateLastDataIndex();
@@ -321,9 +321,9 @@ namespace XCharts
}
protected StringBuilder sb = new StringBuilder(100);
protected override void RefreshTooltip()
protected override void UpdateTooltip()
{
base.RefreshTooltip();
base.UpdateTooltip();
int index;
Axis tempAxis;
bool isCartesian = IsValue();
@@ -846,8 +846,8 @@ namespace XCharts
if (tempMinValue != axis.runtimeMinValue || tempMaxValue != axis.runtimeMaxValue)
{
m_CheckMinMaxValue = true;
axis.runtimeMinValue = tempMinValue;
axis.runtimeMaxValue = tempMaxValue;
axis.UpdateMinValue(tempMinValue, !m_IsPlayingAnimation);
axis.UpdateMaxValue(tempMaxValue, !m_IsPlayingAnimation);
axis.runtimeZeroXOffset = 0;
axis.runtimeZeroYOffset = 0;
if (tempMinValue != 0 || tempMaxValue != 0)
@@ -873,7 +873,7 @@ namespace XCharts
RefreshChart();
}
}
if (axis.IsValueChanging(500) && !m_IsPlayingStartAnimation)
if (axis.IsValueChanging(500) && !m_IsPlayingAnimation)
{
float coordinateWidth = axis is XAxis ? this.coordinateWidth : coordinateHeight;
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
@@ -980,7 +980,7 @@ namespace XCharts
{
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));
}
}
@@ -1070,7 +1070,7 @@ namespace XCharts
{
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));
}
}
@@ -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)
{
if (!m_Tooltip.show || !m_Tooltip.IsSelected()) return;
@@ -1275,12 +1250,12 @@ namespace XCharts
if (xAxis.IsValue()) pX = m_Tooltip.runtimePointerPos.x;
Vector2 sp = new Vector2(pX, coordinateY);
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)
{
sp = new Vector2(coordinateX, 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;
case Tooltip.Type.Shadow:
@@ -1318,12 +1293,12 @@ namespace XCharts
float pY = coordinateY + m_Tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0);
Vector2 sp = new Vector2(coordinateX, 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)
{
sp = new Vector2(coordinateX, 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;
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)
{
if (!IsActive(serie.name)) return;
if (serie.animation.HasFadeOut()) return;
var xAxis = m_XAxises[serie.axisIndex];
var yAxis = m_YAxises[serie.axisIndex];
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);
bool dataChanging = false;
float updateDuration = serie.animation.GetUpdateAnimationDuration();
float xMinValue = xAxis.GetCurrMinValue(updateDuration);
float xMaxValue = xAxis.GetCurrMaxValue(updateDuration);
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
for (int i = serie.minShow; i < maxCount; i++)
{
if (i >= seriesHig.Count)
@@ -55,7 +56,7 @@ namespace XCharts
}
var serieData = showData[i];
serieData.canShowLabel = true;
float value = showData[i].GetCurrData(1, updateDuration);
float value = showData[i].GetCurrData(1, dataChangeDuration);
if (showData[i].IsDataChanged()) dataChanging = true;
float pX = seriesHig[i] + coordinateX + xAxis.runtimeZeroXOffset + yAxis.axisLine.width;
float pY = coordinateY + +i * categoryWidth;
@@ -117,23 +118,11 @@ namespace XCharts
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.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();
m_IsPlayingStartAnimation = true;
m_IsPlayingAnimation = true;
}
return currHig;
}
@@ -141,6 +130,7 @@ namespace XCharts
protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
{
if (!IsActive(serie.name)) return;
if (serie.animation.HasFadeOut()) return;
var showData = serie.GetDataList(m_DataZoom);
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];
@@ -167,16 +157,16 @@ namespace XCharts
var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
bool dataChanging = false;
float updateDuration = serie.animation.GetUpdateAnimationDuration();
float yMinValue = yAxis.GetCurrMinValue(updateDuration);
float yMaxValue = yAxis.GetCurrMaxValue(updateDuration);
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
for (int i = serie.minShow; i < maxCount; i++)
{
if (i >= seriesHig.Count)
{
seriesHig.Add(0);
}
float value = showData[i].GetCurrData(1, updateDuration);
float value = showData[i].GetCurrData(1, dataChangeDuration);
if (showData[i].IsDataChanged()) dataChanging = true;
float pX = coordinateX + i * categoryWidth;
float zeroY = coordinateY + yAxis.runtimeZeroYOffset;

View File

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

View File

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

View File

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

View File

@@ -32,6 +32,7 @@ namespace XCharts
{
base.Reset();
m_Title.text = "PieChart";
m_Legend.show = true;
RemoveData();
AddSerie(SerieType.Pie, "serie1");
AddData(0, 70, "pie1");
@@ -58,7 +59,7 @@ namespace XCharts
serie.index = i;
var data = serie.data;
serie.animation.InitProgress(data.Count, 0, 360);
if (!serie.show)
if (!serie.show || serie.animation.HasFadeOut())
{
continue;
}
@@ -77,13 +78,12 @@ namespace XCharts
sd.canShowLabel = false;
}
bool dataChanging = false;
float updateDuration = serie.animation.GetUpdateAnimationDuration();
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
for (int n = 0; n < data.Count; n++)
{
if (!serie.animation.NeedAnimation(n)) break;
var serieData = data[n];
serieData.index = n;
float value = serieData.GetCurrData(1, updateDuration);
float value = serieData.GetCurrData(1, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true;
serieNameCount = m_LegendRealShowName.IndexOf(serieData.legendName);
Color color = m_ThemeInfo.GetColor(serieNameCount);
@@ -164,11 +164,8 @@ namespace XCharts
}
if (!serie.animation.IsFinish())
{
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
float speed = 360 / duration;
float symbolSpeed = serie.symbol.size / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size);
serie.animation.CheckProgress(360);
serie.animation.CheckSymbol(serie.symbol.size);
RefreshChart();
}
if (dataChanging)
@@ -488,9 +485,8 @@ namespace XCharts
protected override void OnLegendButtonClick(int index, string legendName, bool show)
{
bool active = CheckDataShow(legendName, show);
var bgColor1 = active ? m_ThemeInfo.GetColor(index) : m_ThemeInfo.legendUnableColor;
m_Legend.UpdateButtonColor(legendName, bgColor1);
CheckDataShow(legendName, show);
UpdateLegendColor(legendName, show);
RefreshChart();
}
@@ -531,7 +527,7 @@ namespace XCharts
if (selected)
{
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
RefreshTooltip();
UpdateTooltip();
}
else if (m_Tooltip.IsActive())
{
@@ -570,9 +566,9 @@ namespace XCharts
}
StringBuilder sb = new StringBuilder();
protected override void RefreshTooltip()
protected override void UpdateTooltip()
{
base.RefreshTooltip();
base.UpdateTooltip();
bool showTooltip = false;
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)
{
bool active = CheckDataShow(legendName, show);
var bgColor1 = active ? m_ThemeInfo.GetColor(index) : m_ThemeInfo.legendUnableColor;
m_Legend.UpdateButtonColor(legendName, bgColor1);
CheckDataShow(legendName, show);
UpdateLegendColor(legendName, show);
RefreshChart();
}
@@ -69,12 +68,13 @@ namespace XCharts
serie.symbol.type = SerieSymbolType.EmptyCircle;
serie.symbol.size = 4;
serie.symbol.selectedSize = 6;
serie.showDataName = true;
List<float> data = new List<float>();
for (int i = 0; i < 5; i++)
{
data.Add(Random.Range(20, 90));
}
AddData(0, data);
AddData(0, data, "legendName");
}
#endif
@@ -97,7 +97,7 @@ namespace XCharts
var textColor = textStyle.color == Color.clear ? (Color)m_ThemeInfo.axisTextColor : textStyle.color;
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),
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.gameObject.SetActive(radar.indicator);
var txtWidth = txt.preferredWidth;
@@ -198,13 +198,13 @@ namespace XCharts
var angle = 2 * Mathf.PI / indicatorNum;
Vector3 p = radar.runtimeCenterPos;
serie.animation.InitProgress(1, 0, 1);
if (!IsActive(i))
if (!IsActive(i) || serie.animation.HasFadeOut())
{
continue;
}
var rate = serie.animation.GetCurrRate();
var dataChanging = false;
var updateDuration = serie.animation.GetUpdateAnimationDuration();
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
@@ -249,7 +249,7 @@ namespace XCharts
if (n >= serieData.data.Count) break;
float min = radar.GetIndicatorMin(n);
float max = radar.GetIndicatorMax(n);
float value = serieData.GetCurrData(n, updateDuration);
float value = serieData.GetCurrData(n, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true;
if (max == 0)
{
@@ -276,7 +276,7 @@ namespace XCharts
}
if (serie.lineStyle.show)
{
ChartDrawer.DrawLine(vh, startPoint, toPoint, serie.lineStyle.width, lineColor);
DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor);
}
startPoint = toPoint;
}
@@ -288,7 +288,7 @@ namespace XCharts
}
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)
{
@@ -304,9 +304,7 @@ namespace XCharts
}
if (!serie.animation.IsFinish())
{
float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
float speed = 1 / duration;
serie.animation.CheckProgress(Time.deltaTime * speed);
serie.animation.CheckProgress(1);
RefreshChart();
}
if (dataChanging)
@@ -318,7 +316,7 @@ namespace XCharts
private void DrawRadar(VertexHelper vh, Radar radar)
{
if (!radar.lineStyle.show && !radar.splitArea.show)
if (!radar.splitLine.show && !radar.splitArea.show)
{
return;
}
@@ -346,9 +344,9 @@ namespace XCharts
{
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;
p2 = p3;
@@ -360,16 +358,16 @@ namespace XCharts
float currAngle = j * angle;
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(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)
{
if (!radar.lineStyle.show && !radar.splitArea.show)
if (!radar.splitLine.show && !radar.splitArea.show)
{
return;
}
@@ -389,9 +387,9 @@ namespace XCharts
ChartDrawer.DrawDoughnut(vh, p, insideRadius, outsideRadius, color, Color.clear,
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);
}
insideRadius = outsideRadius;
@@ -401,30 +399,18 @@ namespace XCharts
float currAngle = j * angle;
p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(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)
{
if (radar.lineStyle.color != Color.clear)
{
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;
}
return radar.splitLine.GetColor(m_ThemeInfo);
}
protected override void CheckTootipArea(Vector2 local)
{
if (m_IsEnterLegendButtom) return;
@@ -471,14 +457,14 @@ namespace XCharts
else
{
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
RefreshTooltip();
UpdateTooltip();
RefreshChart();
}
}
protected override void RefreshTooltip()
protected override void UpdateTooltip()
{
base.RefreshTooltip();
base.UpdateTooltip();
int serieIndex = m_Tooltip.runtimeDataIndex[0];
if (serieIndex < 0)
{

View File

@@ -161,12 +161,13 @@ namespace XCharts
rect.anchorMin = anchorMin;
rect.anchorMax = anchorMax;
rect.pivot = pivot;
rect.anchoredPosition3D = Vector3.zero;
return obj;
}
public static Text AddTextObject(string name, Transform parent, Font font, Color color,
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);
Text txt = GetOrAddComponent<Text>(txtObj);
@@ -178,6 +179,7 @@ namespace XCharts
txt.horizontalOverflow = HorizontalWrapMode.Overflow;
txt.verticalOverflow = VerticalWrapMode.Overflow;
txt.color = color;
txt.lineSpacing = lineSpacing;
txtObj.transform.localEulerAngles = new Vector3(0, 0, rotate);
RectTransform rect = GetOrAddComponent<RectTransform>(txtObj);
@@ -191,20 +193,21 @@ namespace XCharts
public static Button AddButtonObject(string name, Transform parent, Font font, int fontSize,
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);
GetOrAddComponent<Image>(btnObj);
GetOrAddComponent<Button>(btnObj);
Text txt = AddTextObject("Text", btnObj.transform, font, color, TextAnchor.MiddleCenter,
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.offsetMax = Vector2.zero;
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 anchorMin = new Vector2(0, 1);
@@ -214,7 +217,7 @@ namespace XCharts
var img = GetOrAddComponent<Image>(tooltipObj);
img.color = Color.black;
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.transform.localPosition = new Vector2(3, -3);
tooltipObj.transform.localPosition = Vector3.zero;
@@ -232,8 +235,9 @@ namespace XCharts
return iconObj;
}
internal static GameObject AddSerieLabel(string name, Transform parent, Font font, Color textColor, Color backgroundColor,
int fontSize, FontStyle fontStyle, float rotate, float width, float height)
internal static GameObject AddSerieLabel(string name, Transform parent, Font font, Color textColor,
Color backgroundColor, int fontSize, FontStyle fontStyle, float rotate, float width, float height,
float lineSpacing)
{
var anchorMin = new Vector2(0.5f, 0.5f);
var anchorMax = new Vector2(0.5f, 0.5f);
@@ -244,7 +248,7 @@ namespace XCharts
//img.color = backgroundColor;
labelObj.transform.localEulerAngles = new Vector3(0, 0, rotate);
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.transform.localPosition = new Vector2(0, 0);
txt.transform.localEulerAngles = Vector3.zero;
@@ -269,7 +273,6 @@ namespace XCharts
return labelObj;
}
public static void GetPointList(ref List<Vector3> posList, Vector3 sp, Vector3 ep, float k = 30f)
{
Vector3 dir = (ep - sp).normalized;
@@ -396,11 +399,30 @@ namespace XCharts
if (list1.Count != list2.Count) return false;
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;
}
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)
{
List<float> list = new List<float>();

View File

@@ -25,7 +25,7 @@ namespace XCharts
public class XChartsMgr : MonoBehaviour
{
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_NewVersion;

View File

@@ -67,6 +67,18 @@ namespace XChartsDemo
InitModuleButton();
}
void ResetParam()
{
var charts = transform.GetComponentsInChildren<BaseChart>();
foreach (var chart in charts)
{
chart.themeInfo.defaultLegendTextColor = ThemeInfo.GetColor("#514D4D");
chart.legend.itemWidth = 20f;
chart.legend.itemHeight = 10f;
chart.legend.textStyle.fontSize = 16;
}
}
void Update()
{
#if UNITY_EDITOR

View File

@@ -0,0 +1,177 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using XCharts;
namespace XChartsDemo
{
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Demo_Animation : MonoBehaviour
{
[SerializeField] private int m_FadeInDuration = 1000;
[SerializeField] private int m_FadeOutDuration = 1000;
[SerializeField] private int m_DataChangeDuration = 500;
void Awake()
{
InitCharts();
TryInitButton("buttons/btnFadeIn", AnimationFadeIn);
TryInitButton("buttons/btnFadeOut", AnimationFadeOut);
TryInitButton("buttons/btnDataAdd", AnimationDataAdd);
TryInitButton("buttons/btnDataChange", AnimationDataChange);
TryInitButton("buttons/btnPause", AnimationPause);
TryInitButton("buttons/btnResume", AnimationResume);
TryInitButton("buttons/btnReset", AnimationReset);
}
void InitCharts()
{
var charts = transform.GetComponentsInChildren<BaseChart>();
foreach (var chart in charts)
{
foreach (var serie in chart.series.list)
{
serie.animation.fadeInDuration = m_FadeInDuration;
serie.animation.fadeOutDuration = m_FadeOutDuration;
serie.animation.dataChangeDuration = m_DataChangeDuration;
}
}
SetInputField("settings/fadeIn/InputField", m_FadeInDuration, OnFadeInDurationChanged);
SetInputField("settings/fadeOut/InputField", m_FadeOutDuration, OnFadeOutDurationChanged);
SetInputField("settings/dataChange/InputField", m_DataChangeDuration, OnDataChangeDurationChanged);
}
void SetInputField(string path, int value, UnityAction<string> act)
{
var input = transform.Find(path).gameObject.GetComponent<InputField>();
input.onEndEdit.AddListener(act);
input.text = value.ToString();
}
Button TryInitButton(string name, UnityAction act)
{
var trans = transform.Find(name);
if (trans)
{
var btn = trans.gameObject.GetComponent<Button>();
btn.onClick.AddListener(act);
return btn;
}
else
{
return null;
}
}
void AnimationFadeIn()
{
var charts = transform.GetComponentsInChildren<BaseChart>();
foreach (var chart in charts)
{
chart.AnimationFadeIn();
}
}
void AnimationFadeOut()
{
var charts = transform.GetComponentsInChildren<BaseChart>();
foreach (var chart in charts)
{
chart.AnimationFadeOut();
}
}
void AnimationDataAdd()
{
var charts = transform.GetComponentsInChildren<BaseChart>();
foreach (var chart in charts)
{
chart.AnimationFadeOut();
}
}
void AnimationDataChange()
{
var charts = transform.GetComponentsInChildren<BaseChart>();
foreach (var chart in charts)
{
var dataCount = chart.series.list[0].dataCount;
var index = UnityEngine.Random.Range(0, dataCount);
chart.UpdateData(0, index, UnityEngine.Random.Range(1, 100));
}
}
void AnimationPause()
{
var charts = transform.GetComponentsInChildren<BaseChart>();
foreach (var chart in charts)
{
chart.AnimationPause();
}
}
void AnimationResume()
{
var charts = transform.GetComponentsInChildren<BaseChart>();
foreach (var chart in charts)
{
chart.AnimationResume();
}
}
void AnimationReset()
{
var charts = transform.GetComponentsInChildren<BaseChart>();
foreach (var chart in charts)
{
chart.AnimationReset();
}
}
void OnFadeInDurationChanged(string content)
{
var charts = transform.GetComponentsInChildren<BaseChart>();
m_FadeInDuration = int.Parse(content);
foreach (var chart in charts)
{
foreach (var serie in chart.series.list)
{
serie.animation.fadeInDuration = m_FadeInDuration;
}
}
}
void OnFadeOutDurationChanged(string content)
{
var charts = transform.GetComponentsInChildren<BaseChart>();
m_FadeOutDuration = int.Parse(content);
foreach (var chart in charts)
{
foreach (var serie in chart.series.list)
{
serie.animation.fadeOutDuration = m_FadeOutDuration;
}
}
}
void OnDataChangeDurationChanged(string content)
{
var charts = transform.GetComponentsInChildren<BaseChart>();
m_DataChangeDuration = int.Parse(content);
foreach (var chart in charts)
{
foreach (var serie in chart.series.list)
{
serie.animation.dataChangeDuration = m_DataChangeDuration;
}
}
}
}
}

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a8890fea0a5384d328f22e9738289cc9
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB