mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 00:20:18 +00:00
修复Axis的更新数据时效果不顺畅的问题
This commit is contained in:
@@ -29,7 +29,7 @@ namespace XCharts.Runtime
|
||||
if (axis.IsCategory() || !axis.show) return;
|
||||
double tempMinValue = 0;
|
||||
double tempMaxValue = 0;
|
||||
SeriesHelper.GetYMinMaxValue(chart, axis.polarIndex, true, axis.inverse, out tempMinValue,
|
||||
SeriesHelper.GetYMinMaxValue(chart, axis.polarIndex, axis.inverse, out tempMinValue,
|
||||
out tempMaxValue, true);
|
||||
AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
|
||||
if (tempMinValue != axis.context.minValue || tempMaxValue != axis.context.maxValue)
|
||||
|
||||
@@ -106,6 +106,7 @@ namespace XCharts.Runtime
|
||||
[SerializeField] protected AxisLabel m_AxisLabel = AxisLabel.defaultAxisLabel;
|
||||
[SerializeField] protected AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine;
|
||||
[SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
|
||||
[SerializeField] protected AxisAnimation m_Animation = new AxisAnimation();
|
||||
[SerializeField][Since("v3.2.0")] protected AxisMinorTick m_MinorTick = AxisMinorTick.defaultMinorTick;
|
||||
[SerializeField][Since("v3.2.0")] protected AxisMinorSplitLine m_MinorSplitLine = AxisMinorSplitLine.defaultMinorSplitLine;
|
||||
[SerializeField][Since("v3.4.0")] protected LabelStyle m_IndicatorLabel = new LabelStyle() { numericFormatter = "f2" };
|
||||
@@ -387,6 +388,15 @@ namespace XCharts.Runtime
|
||||
set { if (value != null) { m_IndicatorLabel = value; SetComponentDirty(); } }
|
||||
}
|
||||
/// <summary>
|
||||
/// animation of axis.
|
||||
/// ||坐标轴动画。
|
||||
/// </summary>
|
||||
public AxisAnimation animation
|
||||
{
|
||||
get { return m_Animation; }
|
||||
set { if (value != null) { m_Animation = value; SetComponentDirty(); } }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether to add new data at the head or at the end of the list.
|
||||
/// ||添加新数据时是在列表的头部还是尾部加入。
|
||||
/// </summary>
|
||||
@@ -439,7 +449,7 @@ namespace XCharts.Runtime
|
||||
splitArea.ClearVerticesDirty();
|
||||
minorTick.ClearVerticesDirty();
|
||||
minorSplitLine.ClearVerticesDirty();
|
||||
indicatorLabel.ClearComponentDirty();
|
||||
indicatorLabel.ClearVerticesDirty();
|
||||
}
|
||||
|
||||
public override void SetComponentDirty()
|
||||
@@ -474,6 +484,7 @@ namespace XCharts.Runtime
|
||||
axis.minorTick = minorTick.Clone();
|
||||
axis.minorSplitLine = minorSplitLine.Clone();
|
||||
axis.indicatorLabel = indicatorLabel.Clone();
|
||||
axis.animation = animation.Clone();
|
||||
axis.icons = new List<Sprite>();
|
||||
axis.data = new List<string>();
|
||||
ChartHelper.CopyList(axis.data, data);
|
||||
@@ -505,6 +516,7 @@ namespace XCharts.Runtime
|
||||
minorTick.Copy(axis.minorTick);
|
||||
minorSplitLine.Copy(axis.minorSplitLine);
|
||||
indicatorLabel.Copy(axis.indicatorLabel);
|
||||
animation.Copy(axis.animation);
|
||||
ChartHelper.CopyList(data, axis.data);
|
||||
ChartHelper.CopyList<Sprite>(icons, axis.icons);
|
||||
}
|
||||
@@ -713,11 +725,11 @@ namespace XCharts.Runtime
|
||||
if (IsCategory() && boundaryGap)
|
||||
{
|
||||
var each = axisLength / data.Count;
|
||||
return (float) (each * (value + 0.5f));
|
||||
return (float)(each * (value + 0.5f));
|
||||
}
|
||||
else
|
||||
{
|
||||
return axisLength * (float) ((value - context.minValue) / context.minMaxRange);
|
||||
return axisLength * (float)((value - context.minValue) / context.minMaxRange);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -725,7 +737,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (context.minMaxRange > 0)
|
||||
{
|
||||
return axisLength * ((float) (value / context.minMaxRange));
|
||||
return axisLength * ((float)(value / context.minMaxRange));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -789,7 +801,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (context.labelObjectList[i] != null)
|
||||
{
|
||||
var text = AxisHelper.GetLabelName(this, coordinateWidth, i, context.minValue, context.maxValue, dataZoom, forcePercent);
|
||||
var text = AxisHelper.GetLabelName(this, coordinateWidth, i, context.destMinValue, context.destMaxValue, dataZoom, forcePercent);
|
||||
context.labelObjectList[i].SetText(text);
|
||||
}
|
||||
}
|
||||
@@ -803,10 +815,27 @@ namespace XCharts.Runtime
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
internal void UpdateMinMaxValue(double minValue, double maxValue)
|
||||
internal void UpdateMinMaxValue(double minValue, double maxValue, bool needAnimation = false)
|
||||
{
|
||||
context.minValue = minValue;
|
||||
context.maxValue = maxValue;
|
||||
if (needAnimation)
|
||||
{
|
||||
if (context.lastMinValue == 0 && context.lastMaxValue == 0)
|
||||
{
|
||||
context.minValue = minValue;
|
||||
context.maxValue = maxValue;
|
||||
}
|
||||
context.lastMinValue = context.minValue;
|
||||
context.lastMaxValue = context.maxValue;
|
||||
context.destMinValue = minValue;
|
||||
context.destMaxValue = maxValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.minValue = minValue;
|
||||
context.maxValue = maxValue;
|
||||
context.destMinValue = minValue;
|
||||
context.destMaxValue = maxValue;
|
||||
}
|
||||
double tempRange = maxValue - minValue;
|
||||
if (context.minMaxRange != tempRange)
|
||||
{
|
||||
@@ -823,7 +852,7 @@ namespace XCharts.Runtime
|
||||
if (value <= 0 || value == 1)
|
||||
return 0;
|
||||
else
|
||||
return logBaseE ? (float) Math.Log(value) : (float) Math.Log(value, logBase);
|
||||
return logBaseE ? (float)Math.Log(value) : (float)Math.Log(value, logBase);
|
||||
}
|
||||
|
||||
public double GetLogMinIndex()
|
||||
@@ -868,8 +897,7 @@ namespace XCharts.Runtime
|
||||
0 :
|
||||
(context.maxValue < 0 ?
|
||||
axisLength :
|
||||
(float) (Math.Abs(context.minValue) * (axisLength /
|
||||
(Math.Abs(context.minValue) + Math.Abs(context.maxValue))))
|
||||
(float)(Math.Abs(context.minValue) * (axisLength / (Math.Abs(context.minValue) + Math.Abs(context.maxValue))))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +35,16 @@ namespace XCharts.Runtime
|
||||
/// ||当前最小值。
|
||||
/// </summary>
|
||||
public double minValue;
|
||||
public double lastMinValue { get; internal set; }
|
||||
public double destMinValue { get; internal set; }
|
||||
/// <summary>
|
||||
/// the current maximum value.
|
||||
/// ||当前最大值。
|
||||
/// </summary>
|
||||
public double maxValue;
|
||||
public double lastMaxValue { get; internal set; }
|
||||
public double destMaxValue { get; internal set; }
|
||||
public bool needAnimation { get; internal set; }
|
||||
/// <summary>
|
||||
/// the offset of zero position.
|
||||
/// ||坐标轴原点在坐标轴的偏移。
|
||||
|
||||
@@ -140,8 +140,9 @@ namespace XCharts
|
||||
return;
|
||||
}
|
||||
|
||||
double tempMinValue = 0;
|
||||
double tempMaxValue = 0;
|
||||
double tempMinValue;
|
||||
double tempMaxValue;
|
||||
axis.context.needAnimation = Application.isPlaying && axis.animation.show;
|
||||
chart.GetSeriesMinMaxValue(axis, axisIndex, out tempMinValue, out tempMaxValue);
|
||||
|
||||
var dataZoom = chart.GetDataZoomOfAxis(axis);
|
||||
@@ -152,14 +153,15 @@ namespace XCharts
|
||||
else
|
||||
dataZoom.SetYAxisIndexValueInfo(axisIndex, ref tempMinValue, ref tempMaxValue);
|
||||
}
|
||||
if (tempMinValue != axis.context.minValue ||
|
||||
tempMaxValue != axis.context.maxValue ||
|
||||
|
||||
if (tempMinValue != axis.context.destMinValue ||
|
||||
tempMaxValue != axis.context.destMaxValue ||
|
||||
m_LastInterval != axis.interval ||
|
||||
m_LastSplitNumber != axis.splitNumber)
|
||||
{
|
||||
m_LastSplitNumber = axis.splitNumber;
|
||||
m_LastInterval = axis.interval;
|
||||
axis.UpdateMinMaxValue(tempMinValue, tempMaxValue);
|
||||
axis.UpdateMinMaxValue(tempMinValue, tempMaxValue, axis.context.needAnimation);
|
||||
axis.context.offset = 0;
|
||||
axis.context.lastCheckInverse = axis.inverse;
|
||||
UpdateAxisTickValueList(axis);
|
||||
@@ -183,6 +185,36 @@ namespace XCharts
|
||||
chart.RefreshChart();
|
||||
}
|
||||
}
|
||||
|
||||
if (axis.context.needAnimation && (axis.context.minValue != axis.context.destMinValue || axis.context.maxValue != axis.context.destMaxValue))
|
||||
{
|
||||
var duration = axis.animation.duration == 0
|
||||
? SeriesHelper.GetMinAnimationDuration(chart.series) / 1000f
|
||||
: axis.animation.duration / 1000f;
|
||||
var deltaTime = axis.animation.unscaledTime ? Time.unscaledDeltaTime : Time.deltaTime;
|
||||
var minDiff = axis.context.destMinValue - axis.context.lastMinValue;
|
||||
var maxDiff = axis.context.destMaxValue - axis.context.lastMaxValue;
|
||||
var minDelta = minDiff / duration * deltaTime;
|
||||
var maxDelta = maxDiff / duration * deltaTime;
|
||||
axis.context.minValue += minDelta;
|
||||
axis.context.maxValue += maxDelta;
|
||||
if ((minDiff > 0 && axis.context.minValue > axis.context.destMinValue)
|
||||
|| (minDiff < 0 && axis.context.minValue < axis.context.destMinValue))
|
||||
{
|
||||
axis.context.minValue = axis.context.destMinValue;
|
||||
axis.context.lastMinValue = axis.context.destMinValue;
|
||||
}
|
||||
if ((maxDiff > 0 && axis.context.maxValue > axis.context.destMaxValue)
|
||||
|| (maxDiff < 0 && axis.context.maxValue < axis.context.destMaxValue))
|
||||
{
|
||||
axis.context.maxValue = axis.context.destMaxValue;
|
||||
axis.context.lastMaxValue = axis.context.destMaxValue;
|
||||
}
|
||||
axis.context.minMaxRange = axis.context.maxValue - axis.context.minValue;
|
||||
UpdateAxisTickValueList(axis);
|
||||
UpdateAxisLabelText(axis);
|
||||
chart.RefreshChart();
|
||||
}
|
||||
}
|
||||
|
||||
internal virtual void UpdateAxisLabelText(Axis axis)
|
||||
@@ -376,8 +408,8 @@ namespace XCharts
|
||||
{
|
||||
var labelWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom);
|
||||
var labelName = AxisHelper.GetLabelName(axis, axisLength, i,
|
||||
axis.context.minValue,
|
||||
axis.context.maxValue,
|
||||
axis.context.destMinValue,
|
||||
axis.context.destMaxValue,
|
||||
dataZoom, isPercentStack);
|
||||
|
||||
var label = ChartHelper.AddAxisLabelObject(splitNumber, i,
|
||||
@@ -631,7 +663,8 @@ namespace XCharts
|
||||
minorTickDistance = scaleWidth * axis.GetLogValue(1 + (count + 1) * logRange / minorTickSplitNumber);
|
||||
tickTotal = lastTickX + minorTickDistance;
|
||||
}
|
||||
}else if (lastTickX <= axis.context.zeroX || (i == minorStartIndex && pX > axis.context.zeroX))
|
||||
}
|
||||
else if (lastTickX <= axis.context.zeroX || (i == minorStartIndex && pX > axis.context.zeroX))
|
||||
{
|
||||
var tickTotal = pX - minorTickDistance;
|
||||
while (tickTotal > lastTickX)
|
||||
|
||||
@@ -106,18 +106,20 @@ namespace XCharts.Runtime
|
||||
|
||||
public new AxisLabel Clone()
|
||||
{
|
||||
var axisLabel = new AxisLabel();
|
||||
axisLabel.show = show;
|
||||
axisLabel.formatter = formatter;
|
||||
axisLabel.interval = interval;
|
||||
axisLabel.inside = inside;
|
||||
axisLabel.distance = distance;
|
||||
axisLabel.numericFormatter = numericFormatter;
|
||||
axisLabel.width = width;
|
||||
axisLabel.height = height;
|
||||
axisLabel.showStartLabel = showStartLabel;
|
||||
axisLabel.showEndLabel = showEndLabel;
|
||||
axisLabel.textLimit = textLimit.Clone();
|
||||
var axisLabel = new AxisLabel
|
||||
{
|
||||
show = show,
|
||||
formatter = formatter,
|
||||
interval = interval,
|
||||
inside = inside,
|
||||
distance = distance,
|
||||
numericFormatter = numericFormatter,
|
||||
width = width,
|
||||
height = height,
|
||||
showStartLabel = showStartLabel,
|
||||
showEndLabel = showEndLabel,
|
||||
textLimit = textLimit.Clone()
|
||||
};
|
||||
axisLabel.textStyle.Copy(textStyle);
|
||||
return axisLabel;
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (axis == null) return;
|
||||
if (axis.IsCategory() || !axis.show) return;
|
||||
double tempMinValue = 0;
|
||||
double tempMaxValue = 0;
|
||||
SeriesHelper.GetXMinMaxValue(chart, axis.polarIndex, true, axis.inverse, out tempMinValue,
|
||||
double tempMinValue;
|
||||
double tempMaxValue;
|
||||
SeriesHelper.GetXMinMaxValue(chart, axis.polarIndex, axis.inverse, out tempMinValue,
|
||||
out tempMaxValue, true);
|
||||
AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
|
||||
if (tempMinValue != axis.context.minValue || tempMaxValue != axis.context.maxValue)
|
||||
|
||||
@@ -529,7 +529,7 @@ namespace XCharts.Runtime
|
||||
Vector3 np = Vector3.zero;
|
||||
double minValue = 0;
|
||||
double maxValue = 0;
|
||||
SeriesHelper.GetYMinMaxValue(chart, 0, chart.IsAllAxisValue(), axis.inverse, out minValue, out maxValue, false, false);
|
||||
SeriesHelper.GetYMinMaxValue(chart, 0, axis.inverse, out minValue, out maxValue, false, false);
|
||||
AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true);
|
||||
|
||||
int rate = 1;
|
||||
@@ -621,7 +621,7 @@ namespace XCharts.Runtime
|
||||
Vector3 np = Vector3.zero;
|
||||
double minValue = 0;
|
||||
double maxValue = 0;
|
||||
SeriesHelper.GetYMinMaxValue(chart, 0, chart.IsAllAxisValue(), axis.inverse, out minValue, out maxValue);
|
||||
SeriesHelper.GetYMinMaxValue(chart, 0, axis.inverse, out minValue, out maxValue);
|
||||
AxisHelper.AdjustMinMaxValue(axis, ref minValue, ref maxValue, true);
|
||||
|
||||
int rate = 1;
|
||||
|
||||
Reference in New Issue
Block a user