Skip to content

Commit

Permalink
[feature][animation] add UnscaledTime for animation #223
Browse files Browse the repository at this point in the history
  • Loading branch information
monitor1394 committed Oct 12, 2022
1 parent ab8ced4 commit e1f20e0
Show file tree
Hide file tree
Showing 21 changed files with 88 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

## master

* (2022.10.12) 增加`Animation``UnscaledTime`支持设置动画是否受TimeScale的影响 (#223)
* (2022.10.10) 调整文档格式
* (2022.10.10) 增加`Line``SmoothLimit`可控制平滑曲线不同效果
* (2022.10.05) 修复`Serie`隐藏时`Tooltip`还显示信息的问题
Expand Down
6 changes: 5 additions & 1 deletion Editor/ChildComponents/AnimationDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
PropertyField(prop, "m_FadeOutDelay");
PropertyField(prop, "m_DataChangeEnable");
PropertyField(prop, "m_DataChangeDuration");
PropertyField(prop, "m_ActualDuration");
PropertyField(prop, "m_UnscaledTime");
// using(new EditorGUI.DisabledGroupScope(true))
// {
// PropertyField(prop, "m_ActualDuration");
// }
--EditorGUI.indentLevel;
}
}
Expand Down
12 changes: 9 additions & 3 deletions Runtime/Component/Animation/AnimationStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class AnimationStyle : ChildComponent
[SerializeField] private bool m_DataChangeEnable = true;
[SerializeField] private float m_DataChangeDuration = 500;
[SerializeField] private float m_ActualDuration;
[SerializeField][Since("v3.4.0")] private bool m_UnscaledTime;
/// <summary>
/// 自定义渐入动画延时函数。返回ms值。
/// </summary>
Expand Down Expand Up @@ -133,6 +134,11 @@ public class AnimationStyle : ChildComponent
/// </summary>
public float dataChangeDuration { get { return m_DataChangeDuration; } set { m_DataChangeDuration = value < 0 ? 0 : value; } }
/// <summary>
/// Animation updates independently of Time.timeScale.
/// |动画是否受TimeScaled的影响。默认为 false 受TimeScaled的影响。
/// </summary>
public bool unscaledTime { get { return m_UnscaledTime; } set { m_UnscaledTime = value; } }
/// <summary>
/// 渐入动画完成回调
/// </summary>
public Action fadeInFinishCallback { get; set; }
Expand Down Expand Up @@ -464,7 +470,7 @@ public void CheckProgress(double total)

m_ActualDuration = (int) ((Time.time - startTime) * 1000) - fadeInDelay;
var duration = GetCurrAnimationDuration();
var delta = (float) (total / duration * Time.deltaTime);
var delta = (float) (total / duration * (m_UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime));
if (m_FadeOut)
{
m_CurrDetailProgress -= delta;
Expand Down Expand Up @@ -522,7 +528,7 @@ internal float CheckItemProgress(int dataIndex, float destProgress, ref bool isE
else
{
var duration = GetCurrAnimationDuration(dataIndex);
var delta = (destProgress - startProgress) / duration * Time.deltaTime;
var delta = (destProgress - startProgress) / duration * (m_UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime);
currHig = currHig + (m_FadeOut ? -delta : delta);
if (m_FadeOut)
{
Expand Down Expand Up @@ -555,7 +561,7 @@ public void CheckSymbol(float dest)
return;

var duration = GetCurrAnimationDuration();
var delta = dest / duration * Time.deltaTime;
var delta = dest / duration * (m_UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime);
if (m_FadeOut)
{
m_CurrSymbolProgress -= delta;
Expand Down
8 changes: 6 additions & 2 deletions Runtime/Component/DataZoom/DataZoomHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,13 @@ private void DrawHorizonalDataZoomSlider(VertexHelper vh, DataZoom dataZoom)
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false;
var animationDuration = serie.animation.GetUpdateAnimationDuration();
var unscaledTime = serie.animation.unscaledTime;

for (int i = 0; i < maxCount; i += rate)
{
double value = DataHelper.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis);
animationDuration, ref dataChanging, axis, unscaledTime);
float pX = dataZoom.context.x + i * scaleWid;
float dataHig = (float) ((maxValue - minValue) == 0 ? 0 :
(value - minValue) / (maxValue - minValue) * dataZoom.context.height);
Expand Down Expand Up @@ -567,11 +569,13 @@ private void DrawVerticalDataZoomSlider(VertexHelper vh, DataZoom dataZoom)
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false;
var animationDuration = serie.animation.GetUpdateAnimationDuration();
var unscaledTime = serie.animation.unscaledTime;

for (int i = 0; i < maxCount; i += rate)
{
double value = DataHelper.SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis);
animationDuration, ref dataChanging, axis, unscaledTime);
float pY = dataZoom.context.y + i * scaleWid;
float dataHig = (maxValue - minValue) == 0 ? 0 :
(float) ((value - minValue) / (maxValue - minValue) * dataZoom.context.width);
Expand Down
14 changes: 7 additions & 7 deletions Runtime/Internal/Utilities/DataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static double DataAverage(ref List<SerieData> showData, SampleType sample

public static double SampleValue(ref List<SerieData> showData, SampleType sampleType, int rate,
int minCount, int maxCount, double totalAverage, int index, float dataChangeDuration,
ref bool dataChanging, Axis axis)
ref bool dataChanging, Axis axis, bool unscaledTime)
{
var inverse = axis.inverse;
var minValue = axis.context.minValue;
Expand All @@ -33,7 +33,7 @@ public static double SampleValue(ref List<SerieData> showData, SampleType sample
if (showData[index].IsDataChanged())
dataChanging = true;

return showData[index].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue);
return showData[index].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue, unscaledTime);
}
switch (sampleType)
{
Expand All @@ -44,7 +44,7 @@ public static double SampleValue(ref List<SerieData> showData, SampleType sample
for (int i = index; i > index - rate; i--)
{
count++;
total += showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue);
total += showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue, unscaledTime);
if (showData[i].IsDataChanged())
dataChanging = true;
}
Expand All @@ -57,7 +57,7 @@ public static double SampleValue(ref List<SerieData> showData, SampleType sample
double max = double.MinValue;
for (int i = index; i > index - rate; i--)
{
var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue);
var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue, unscaledTime);
if (value > max)
max = value;

Expand All @@ -70,7 +70,7 @@ public static double SampleValue(ref List<SerieData> showData, SampleType sample
double min = double.MaxValue;
for (int i = index; i > index - rate; i--)
{
var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue);
var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue, unscaledTime);
if (value < min)
min = value;

Expand All @@ -85,7 +85,7 @@ public static double SampleValue(ref List<SerieData> showData, SampleType sample
total = 0;
for (int i = index; i > index - rate; i--)
{
var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue);
var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue, unscaledTime);
total += value;
if (value < min)
min = value;
Expand All @@ -104,7 +104,7 @@ public static double SampleValue(ref List<SerieData> showData, SampleType sample
if (showData[index].IsDataChanged())
dataChanging = true;

return showData[index].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue);
return showData[index].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue, unscaledTime);
}
}
}
2 changes: 1 addition & 1 deletion Runtime/Serie/Bar/BarHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private void DrawBarSerie(VertexHelper vh, Bar serie)
var state = SerieHelper.GetSerieState(serie, serieData);
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, state);
var value = axis.IsCategory() ? i : serieData.GetData(0, axis.inverse);
var relativedValue = serieData.GetCurrData(1, dataChangeDuration, relativedAxis.inverse, yMinValue, yMaxValue);
var relativedValue = serieData.GetCurrData(1, dataChangeDuration, relativedAxis.inverse, yMinValue, yMaxValue, serie.animation.unscaledTime);
var borderWidth = relativedValue == 0 ? 0 : itemStyle.runtimeBorderWidth;
var borderGap = relativedValue == 0 ? 0 : itemStyle.borderGap;
var borderGapAndWidth = borderWidth + borderGap;
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Serie/Bar/SimplifiedBarHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void DrawBarSerie(VertexHelper vh, SimplifiedBar serie, int colorIndex)
var highlight = serieData.context.highlight || serie.highlight;
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
var value = axis.IsCategory() ? i : serieData.GetData(0, axis.inverse);
var relativedValue = serieData.GetCurrData(1, dataChangeDuration, relativedAxis.inverse, yMinValue, yMaxValue);
var relativedValue = serieData.GetCurrData(1, 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))
Expand Down
11 changes: 6 additions & 5 deletions Runtime/Serie/Candlestick/CandlestickHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override void UpdateTooltipSerieParams(int dataIndex, bool showCategory,
param.columns.Clear();

param.columns.Add(param.marker);
param.columns.Add(XCSettings.lang.GetCandlestickDimensionName(i-1));
param.columns.Add(XCSettings.lang.GetCandlestickDimensionName(i - 1));
param.columns.Add(ChartCached.NumberToStr(param.value, param.numericFormatter));

paramList.Add(param);
Expand Down Expand Up @@ -100,6 +100,7 @@ private void DrawCandlestickSerie(VertexHelper vh, Candlestick serie)

bool dataChanging = false;
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var unscaledTime = serie.animation.unscaledTime;
double yMinValue = yAxis.context.minValue;
double yMaxValue = yAxis.context.maxValue;
var isYAxis = false;
Expand All @@ -118,10 +119,10 @@ private void DrawCandlestickSerie(VertexHelper vh, Candlestick serie)
var state = SerieHelper.GetSerieState(serie, serieData);
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, state);
var startDataIndex = serieData.data.Count > 4 ? 1 : 0;
var open = serieData.GetCurrData(startDataIndex, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var close = serieData.GetCurrData(startDataIndex + 1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var lowest = serieData.GetCurrData(startDataIndex + 2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var heighest = serieData.GetCurrData(startDataIndex + 3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var open = serieData.GetCurrData(startDataIndex, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue, unscaledTime);
var close = serieData.GetCurrData(startDataIndex + 1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue, unscaledTime);
var lowest = serieData.GetCurrData(startDataIndex + 2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue, unscaledTime);
var heighest = serieData.GetCurrData(startDataIndex + 3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue, unscaledTime);
var isRise = yAxis.inverse ? close<open : close> open;
var borderWidth = open == 0 ? 0f :
(itemStyle.runtimeBorderWidth == 0 ? theme.serie.candlestickBorderWidth :
Expand Down
9 changes: 5 additions & 4 deletions Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private void DrawCandlestickSerie(VertexHelper vh, SimplifiedCandlestick serie)

bool dataChanging = false;
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var unscaledTime = serie.animation.unscaledTime;
double yMinValue = yAxis.context.minValue;
double yMaxValue = yAxis.context.maxValue;
var isYAxis = false;
Expand All @@ -117,10 +118,10 @@ private void DrawCandlestickSerie(VertexHelper vh, SimplifiedCandlestick serie)
continue;
}
var startDataIndex = serieData.data.Count > 4 ? 1 : 0;
var open = serieData.GetCurrData(startDataIndex, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var close = serieData.GetCurrData(startDataIndex + 1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var lowest = serieData.GetCurrData(startDataIndex + 2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var heighest = serieData.GetCurrData(startDataIndex + 3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
var open = serieData.GetCurrData(startDataIndex, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue, unscaledTime);
var close = serieData.GetCurrData(startDataIndex + 1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue, unscaledTime);
var lowest = serieData.GetCurrData(startDataIndex + 2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue, unscaledTime);
var heighest = serieData.GetCurrData(startDataIndex + 3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue, unscaledTime);
var isRise = yAxis.inverse ? close<open : close> open;
var borderWidth = open == 0 ? 0f :
(itemStyle.runtimeBorderWidth == 0 ? theme.serie.candlestickBorderWidth :
Expand Down
3 changes: 2 additions & 1 deletion Runtime/Serie/Heatmap/HeatmapHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ private void DrawDataHeatmapSerie(VertexHelper vh, Heatmap serie)
serie.animation.InitProgress(0, xCount);
var animationIndex = serie.animation.GetCurrIndex();
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var unscaledTime = serie.animation.unscaledTime;
var dataChanging = false;
serie.containerIndex = m_SerieGrid.index;
serie.containterInstanceId = m_SerieGrid.instanceId;
Expand Down Expand Up @@ -242,7 +243,7 @@ private void DrawDataHeatmapSerie(VertexHelper vh, Heatmap serie)
var isRectSymbol = symbol.type == SymbolType.Rect;
SerieHelper.GetSymbolInfo(out borderColor, out symbolBorder, out cornerRadius, serie, serieData, chart.theme, state);
var value = serieData.GetCurrData(dimension, dataChangeDuration, yAxis.inverse,
yAxis.context.minValue, yAxis.context.maxValue);
yAxis.context.minValue, yAxis.context.maxValue, unscaledTime);
if (serieData.IsDataChanged()) dataChanging = true;
var pos = new Vector3(zeroX + (i + 0.5f) * xWidth,
zeroY + (j + 0.5f) * yWidth);
Expand Down
3 changes: 2 additions & 1 deletion Runtime/Serie/Line/LineHandler.GridCoord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ private void DrawLineSerie(VertexHelper vh, Line serie)
DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false;
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var unscaledTime = serie.animation.unscaledTime;

var interacting = false;
var lineWidth = LineHelper.GetLineWidth(ref interacting, serie, chart.theme.serie.lineWidth);
Expand Down Expand Up @@ -321,7 +322,7 @@ private void DrawLineSerie(VertexHelper vh, Line serie)
var np = Vector3.zero;
var xValue = axis.IsCategory() ? i : serieData.GetData(0, axis.inverse);
var relativedValue = DataHelper.SampleValue(ref showData, serie.sampleType, rate, serie.minShow,
maxCount, totalAverage, i, dataChangeDuration, ref dataChanging, relativedAxis);
maxCount, totalAverage, i, dataChangeDuration, ref dataChanging, relativedAxis, unscaledTime);

serieData.context.stackHeight = GetDataPoint(isY, axis, relativedAxis, m_SerieGrid, xValue, relativedValue,
i, scaleWid, isStack, ref np);
Expand Down
3 changes: 2 additions & 1 deletion Runtime/Serie/Line/SimplifiedLineHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ private void DrawLineSerie(VertexHelper vh, SimplifiedLine serie)
DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false;
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var unscaledTime = serie.animation.unscaledTime;

var interacting = false;
var lineWidth = LineHelper.GetLineWidth(ref interacting, serie, chart.theme.serie.lineWidth);
Expand All @@ -200,7 +201,7 @@ private void DrawLineSerie(VertexHelper vh, SimplifiedLine serie)
var np = Vector3.zero;
var xValue = axis.IsCategory() ? i : serieData.GetData(0, axis.inverse);
var relativedValue = DataHelper.SampleValue(ref showData, serie.sampleType, rate, serie.minShow,
maxCount, totalAverage, i, dataChangeDuration, ref dataChanging, relativedAxis);
maxCount, totalAverage, i, dataChangeDuration, ref dataChanging, relativedAxis, unscaledTime);

serieData.context.stackHeight = GetDataPoint(isY, axis, relativedAxis, m_SerieGrid, xValue, relativedValue,
i, scaleWid, false, ref np);
Expand Down
Loading

0 comments on commit e1f20e0

Please sign in to comment.