增加AnimationInteraction交互动画配置支持

This commit is contained in:
monitor1394
2023-07-14 08:14:00 +08:00
parent ccd71710ce
commit 58d6d52747
20 changed files with 156 additions and 66 deletions

View File

@@ -403,4 +403,27 @@ namespace XCharts.Runtime
public class AnimationAddition : AnimationInfo
{
}
/// <summary>
/// Interactive animation of charts.
/// |交互动画。
/// </summary>
[Since("v3.8.0")]
[System.Serializable]
public class AnimationInteraction : AnimationInfo
{
[SerializeField][Since("v3.8.0")] private float m_WidthRate = 1.3f;
[SerializeField][Since("v3.8.0")] private float m_RadiusRate = 1.3f;
/// <summary>
/// the size rate of the width.
/// |宽度的放大倍率。
/// </summary>
public float widthRate { get { return m_WidthRate; } set { m_WidthRate = value; } }
/// <summary>
/// the size rate of the radius.
/// |半径的放大倍率。
/// </summary>
public float radiusRate { get { return m_RadiusRate; } set { m_RadiusRate = value; } }
}
}

View File

@@ -45,7 +45,7 @@ namespace XCharts.Runtime
/// <summary>
/// the animation of serie. support animation type: fadeIn, fadeOut, change, addition.
/// |动画组件,用于控制图表的动画播放。支持配置种动画表现FadeIn渐入动画FadeOut渐出动画Change变更动画Addition新增动画
/// |动画组件,用于控制图表的动画播放。支持配置种动画表现FadeIn渐入动画FadeOut渐出动画Change变更动画Addition新增动画Interaction交互动画
/// 按作用的对象可以分为两类SerieAnimation系列动画和DataAnimation数据动画
/// </summary>
[System.Serializable]
@@ -60,6 +60,7 @@ namespace XCharts.Runtime
[SerializeField][Since("v3.8.0")] private AnimationFadeOut m_FadeOut = new AnimationFadeOut() { reverse = true };
[SerializeField][Since("v3.8.0")] private AnimationChange m_Change = new AnimationChange() { duration = 500 };
[SerializeField][Since("v3.8.0")] private AnimationAddition m_Addition = new AnimationAddition() { duration = 500 };
[SerializeField][Since("v3.8.0")] private AnimationInteraction m_Interaction = new AnimationInteraction() { duration = 250 };
[Obsolete("Use animation.fadeIn.delayFunction instead.", true)]
public AnimationDelayFunction fadeInDelayFunction;
@@ -99,12 +100,12 @@ namespace XCharts.Runtime
/// Fade in animation configuration.
/// |渐入动画配置。
/// </summary>
public AnimationFadeIn fadein { get { return m_FadeIn; } }
public AnimationFadeIn fadeIn { get { return m_FadeIn; } }
/// <summary>
/// Fade out animation configuration.
/// |渐出动画配置。
/// </summary>
public AnimationFadeOut fadeout { get { return m_FadeOut; } }
public AnimationFadeOut fadeOut { get { return m_FadeOut; } }
/// <summary>
/// Update data animation configuration.
/// |数据变更动画配置。
@@ -115,6 +116,11 @@ namespace XCharts.Runtime
/// |数据新增动画配置。
/// </summary>
public AnimationAddition addition { get { return m_Addition; } }
/// <summary>
/// Interaction animation configuration.
/// |交互动画配置。
/// </summary>
public AnimationInteraction interaction { get { return m_Interaction; } }
private Vector3 m_LinePathLastPos;
private List<AnimationInfo> m_Animations;
@@ -278,6 +284,7 @@ namespace XCharts.Runtime
startIndex = anim.context.currPointIndex == paths.Count - 1 ?
paths.Count - 2 :
anim.context.currPointIndex;
if (startIndex < 0 || startIndex > paths.Count - 2) startIndex = 0;
}
else
{
@@ -523,6 +530,14 @@ namespace XCharts.Runtime
return 0;
}
public float GetInteractionDuration()
{
if (m_Enable && m_Interaction.enable)
return m_Interaction.duration;
else
return 0;
}
public bool HasFadeOut()
{
return enable && m_FadeOut.context.end;

View File

@@ -18,7 +18,7 @@ namespace XCharts.Runtime
public void SetValue(ref bool needInteract, float size, bool highlight, float rate = 1.3f)
{
size = highlight ? size * rate : size;
size = highlight && rate != 0 ? size * rate : size;
SetValue(ref needInteract, size);
}
@@ -81,7 +81,7 @@ namespace XCharts.Runtime
public bool TryGetValue(ref float value, ref bool interacting, float animationDuration = 250)
{
if (!IsValueEnable() || m_PreviousValue == 0)
if (!IsValueEnable() || m_PreviousValue == 0 || animationDuration == 0)
return false;
if (m_UpdateFlag)
{
@@ -106,7 +106,7 @@ namespace XCharts.Runtime
public bool TryGetColor(ref Color32 color, ref bool interacting, float animationDuration = 250)
{
if (!IsValueEnable())
if (!IsValueEnable() || animationDuration == 0)
return false;
if (m_UpdateFlag)
{
@@ -131,7 +131,7 @@ namespace XCharts.Runtime
public bool TryGetColor(ref Color32 color, ref Color32 toColor, ref bool interacting, float animationDuration = 250)
{
if (!IsValueEnable())
if (!IsValueEnable() || animationDuration == 0)
return false;
if (m_UpdateFlag)
{
@@ -157,7 +157,7 @@ namespace XCharts.Runtime
}
public bool TryGetValueAndColor(ref float value, ref Color32 color, ref Color32 toColor, ref bool interacting, float animationDuration = 250)
{
if (!IsValueEnable())
if (!IsValueEnable() || animationDuration == 0)
return false;
if (m_UpdateFlag)
{

View File

@@ -53,7 +53,7 @@ namespace XCharts.Runtime
if (m_LegendEnter)
{
serie.context.pointerEnter = true;
serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate);
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
for (int i = 0; i < serie.dataCount; i++)
{
var serieData = serie.data[i];
@@ -139,6 +139,7 @@ namespace XCharts.Runtime
var areaColor = ColorUtil.clearColor32;
var areaToColor = ColorUtil.clearColor32;
var interacting = false;
var interactDuration = serie.animation.GetInteractionDuration();
float start, end;
float inside, outside;
@@ -184,7 +185,7 @@ namespace XCharts.Runtime
serieData.context.toAngle = end;
serieData.context.halfAngle = (start + end) / 2;
if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting))
if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting, interactDuration))
{
SerieHelper.GetItemColor(out areaColor, out areaToColor, serie, serieData, chart.theme);
serieData.interact.SetColor(ref interacting, areaColor, areaToColor);

View File

@@ -183,11 +183,12 @@ namespace XCharts.Runtime
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
showData.Count;
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series, serie.stack);
bool dataChanging = false;
float dataChangeDuration = serie.animation.GetChangeDuration();
var dataChanging = false;
var dataChangeDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetAdditionDuration();
double yMinValue = relativedAxis.context.minValue;
double yMaxValue = relativedAxis.context.maxValue;
var interactDuration = serie.animation.GetInteractionDuration();
var yMinValue = relativedAxis.context.minValue;
var yMaxValue = relativedAxis.context.maxValue;
var areaColor = ColorUtil.clearColor32;
var areaToColor = ColorUtil.clearColor32;
@@ -218,7 +219,7 @@ namespace XCharts.Runtime
var borderGapAndWidth = borderWidth + borderGap;
var backgroundColor = itemStyle.backgroundColor;
if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting))
if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting, interactDuration))
{
SerieHelper.GetItemColor(out areaColor, out areaToColor, serie, serieData, chart.theme);
serieData.interact.SetColor(ref interacting, areaColor, areaToColor);

View File

@@ -133,9 +133,10 @@ namespace XCharts.Runtime
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
showData.Count;
bool dataChanging = false;
float dataChangeDuration = serie.animation.GetChangeDuration();
var dataChanging = false;
var dataChangeDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetAdditionDuration();
var interactDuration = serie.animation.GetInteractionDuration();
double yMinValue = relativedAxis.context.minValue;
double yMaxValue = relativedAxis.context.maxValue;
@@ -165,7 +166,7 @@ namespace XCharts.Runtime
var relativedValue = serieData.GetCurrData(1, dataAddDuration, dataChangeDuration, relativedAxis.inverse, yMinValue, yMaxValue, serie.animation.unscaledTime);
var borderWidth = relativedValue == 0 ? 0 : itemStyle.runtimeBorderWidth;
if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting))
if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting, interactDuration))
{
SerieHelper.GetItemColor(out areaColor, out areaToColor, serie, serieData, chart.theme);
serieData.interact.SetColor(ref interacting, areaColor, areaToColor);
@@ -217,7 +218,7 @@ namespace XCharts.Runtime
else
{
if (axis.context.minMaxRange <= 0) pY = grid.context.y;
else pY = grid.context.y + (float) ((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.height - barWidth);
else pY = grid.context.y + (float)((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.height - barWidth);
}
pX = AxisHelper.GetAxisValuePosition(grid, relativedAxis, categoryWidth, 0);
}
@@ -230,7 +231,7 @@ namespace XCharts.Runtime
else
{
if (axis.context.minMaxRange <= 0) pX = grid.context.x;
else pX = grid.context.x + (float) ((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.width - barWidth);
else pX = grid.context.x + (float)((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.width - barWidth);
}
pY = AxisHelper.GetAxisValuePosition(grid, relativedAxis, categoryWidth, 0);
}

View File

@@ -53,7 +53,7 @@ namespace XCharts.Runtime
if (m_LegendEnter)
{
serie.context.pointerEnter = true;
serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate);
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
for (int i = 0; i < serie.dataCount; i++)
{
var serieData = serie.data[i];

View File

@@ -61,7 +61,7 @@ namespace XCharts.Runtime
if (m_LegendEnter)
{
serie.context.pointerEnter = true;
serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate);
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
for (int i = 0; i < serie.dataCount; i++)
{
var serieData = serie.data[i];
@@ -73,7 +73,7 @@ namespace XCharts.Runtime
else if (serie.context.isTriggerByAxis)
{
serie.context.pointerEnter = false;
serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate);
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
for (int i = 0; i < serie.dataCount; i++)
{
var serieData = serie.data[i];
@@ -116,7 +116,7 @@ namespace XCharts.Runtime
needInteract = true;
}
if (serie.context.pointerItemDataIndex >= 0)
serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate);
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
else
serie.interact.SetValue(ref needInteract, lineWidth);
}
@@ -144,6 +144,7 @@ namespace XCharts.Runtime
var lineArrow = serie.lineArrow;
var visualMap = chart.GetVisualMapOfSerie(serie);
var isVisualMapGradient = VisualMapHelper.IsNeedLineGradient(visualMap);
var interactDuration = serie.animation.GetInteractionDuration();
Axis axis;
Axis relativedAxis;
@@ -176,7 +177,7 @@ namespace XCharts.Runtime
continue;
var symbolSize = 0f;
if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting))
if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting, interactDuration))
{
symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, chart.theme.serie.lineSymbolSize, state);
serieData.interact.SetValue(ref interacting, symbolSize);

View File

@@ -53,7 +53,7 @@ namespace XCharts.Runtime
if (m_LegendEnter)
{
serie.context.pointerEnter = true;
serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate);
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
for (int i = 0; i < serie.dataCount; i++)
{
var serieData = serie.data[i];

View File

@@ -410,7 +410,7 @@ namespace XCharts.Runtime
public static float GetLineWidth(ref bool interacting, Serie serie, float defaultWidth)
{
var lineWidth = 0f;
if (!serie.interact.TryGetValue(ref lineWidth, ref interacting))
if (!serie.interact.TryGetValue(ref lineWidth, ref interacting, serie.animation.GetInteractionDuration()))
{
lineWidth = serie.lineStyle.GetWidth(defaultWidth);
serie.interact.SetValue(ref interacting, lineWidth);

View File

@@ -66,14 +66,13 @@ namespace XCharts.Runtime
}
m_LastCheckContextFlag = needCheck;
var themeSymbolSize = chart.theme.serie.lineSymbolSize;
var themeSymbolSelectedSize = chart.theme.serie.lineSymbolSelectedSize;
lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);
var needInteract = false;
if (m_LegendEnter)
{
serie.context.pointerEnter = true;
serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate);
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
for (int i = 0; i < serie.dataCount; i++)
{
var serieData = serie.data[i];
@@ -85,7 +84,7 @@ namespace XCharts.Runtime
else if (serie.context.isTriggerByAxis)
{
serie.context.pointerEnter = true;
serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate);
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
for (int i = 0; i < serie.dataCount; i++)
{
var serieData = serie.data[i];

View File

@@ -240,6 +240,7 @@ namespace XCharts.Runtime
SerieHelper.GetAllMinMaxData(serie, m_RadarCoord.ceilRate);
Color32 areaColor, areaToColor;
var startAngle = m_RadarCoord.startAngle * Mathf.PI / 180;
var interactDuration = serie.animation.GetInteractionDuration();
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
@@ -331,7 +332,7 @@ namespace XCharts.Runtime
{
var point = serieData.context.dataPoints[m];
var symbolSize = 0f;
if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting))
if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting, interactDuration))
{
symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, chart.theme.serie.lineSymbolSize, serieState);
serieData.interact.SetValue(ref interacting, symbolSize);

View File

@@ -77,7 +77,6 @@ namespace XCharts.Runtime
serie.context.pointerItemDataIndex = -1;
serie.context.pointerEnter = false;
var themeSymbolSize = chart.theme.serie.scatterSymbolSize;
var themeSymbolSelectedSize = chart.theme.serie.scatterSymbolSelectedSize;
var needInteract = false;
for (int i = serie.dataCount - 1; i >= 0; i--)
{
@@ -134,6 +133,7 @@ namespace XCharts.Runtime
serie.animation.InitProgress(0, 1);
var rate = serie.animation.GetCurrRate();
var dataChangeDuration = serie.animation.GetChangeDuration();
var interactDuration = serie.animation.GetInteractionDuration();
var unscaledTime = serie.animation.unscaledTime;
var dataChanging = false;
var interacting = false;
@@ -177,7 +177,7 @@ namespace XCharts.Runtime
serieData.context.position = pos;
var datas = serieData.data;
var symbolSize = 0f;
if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting))
if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting, interactDuration))
{
symbolSize = SerieHelper.GetSysmbolSize(serie, serieData, chart.theme, chart.theme.serie.scatterSymbolSize, state);
serieData.interact.SetValue(ref interacting, symbolSize);

View File

@@ -675,6 +675,7 @@ namespace XCharts.Runtime
public static float GetSysmbolSize(Serie serie, SerieData serieData, ThemeStyle theme, float defaultSize, SerieState state = SerieState.Auto)
{
if (serie == null) return defaultSize;
if (state == SerieState.Auto)
state = GetSerieState(serie, serieData);
var stateStyle = GetStateStyle(serie, serieData, state);
@@ -687,7 +688,7 @@ namespace XCharts.Runtime
{
case SerieState.Emphasis:
case SerieState.Select:
size *= theme.serie.selectedRate;
size *= serie.animation.interaction.radiusRate;
break;
default:
break;
@@ -698,7 +699,10 @@ namespace XCharts.Runtime
var symbol = stateStyle.symbol;
size = symbol.GetSize(serieData == null ? null : serieData.data, defaultSize);
}
size = (float)serieData.GetAddAnimationData(0, size, serie.animation.GetAdditionDuration());
if (serieData != null)
{
size = (float)serieData.GetAddAnimationData(0, size, serie.animation.GetAdditionDuration());
}
return size;
}

View File

@@ -10,7 +10,6 @@ namespace XCharts.Runtime
[SerializeField] protected float m_LineSymbolSize;
[SerializeField] protected float m_ScatterSymbolSize;
[SerializeField] protected float m_PieTooltipExtraRadius;
[SerializeField] protected float m_SelectedRate = 1.3f;
[SerializeField] protected float m_PieSelectedOffset;
[SerializeField] protected Color32 m_CandlestickColor = new Color32(235, 84, 84, 255);
[SerializeField] protected Color32 m_CandlestickColor0 = new Color32(71, 178, 98, 255);
@@ -37,11 +36,6 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_LineSymbolSize, value)) SetVerticesDirty(); }
}
/// <summary>
/// the selected symbol size of line serie.
/// |折线图Symbol在被选中状态时的大小。
/// </summary>
public float lineSymbolSelectedSize { get { return lineSymbolSize * selectedRate; } }
/// <summary>
/// the symbol size of scatter serie.
/// |散点图的Symbol大小。
/// </summary>
@@ -50,21 +44,6 @@ namespace XCharts.Runtime
get { return m_ScatterSymbolSize; }
set { if (PropertyUtil.SetStruct(ref m_ScatterSymbolSize, value)) SetVerticesDirty(); }
}
/// <summary>
/// the selected symbol size of scatter serie.
/// |散点图的Symbol在被选中状态时的大小。
/// </summary>
public float scatterSymbolSelectedSize { get { return scatterSymbolSize * selectedRate; } }
/// <summary>
/// the rate of symbol size of line or scatter serie.
/// |折线图或散点图在被选中时的放大倍数。
/// </summary>
public float selectedRate
{
get { return m_SelectedRate; }
set { if (PropertyUtil.SetStruct(ref m_SelectedRate, value)) SetVerticesDirty(); }
}
/// <summary>
/// the extra radius of pie when actived by tooltip.
/// |饼图鼠标移到高亮时的额外半径
@@ -130,7 +109,6 @@ namespace XCharts.Runtime
m_LineWidth = theme.lineWidth;
m_LineSymbolSize = theme.lineSymbolSize;
m_ScatterSymbolSize = theme.scatterSymbolSize;
selectedRate = theme.selectedRate;
m_PieTooltipExtraRadius = theme.pieTooltipExtraRadius;
m_PieSelectedOffset = theme.pieSelectedOffset;
m_CandlestickColor = theme.candlestickColor;