优化AxisTime时间轴的滚动表现

This commit is contained in:
monitor1394
2024-07-14 15:07:26 +08:00
parent b22288eac4
commit e3098e6e16
3 changed files with 12 additions and 8 deletions

View File

@@ -49,6 +49,11 @@ namespace XCharts.Runtime
}
}
public static DateTime GetDateTime(double timestamp)
{
return k_DateTime1970.AddSeconds(timestamp);
}
public static DateTime GetDateTime(int timestamp)
{
return k_DateTime1970.AddSeconds(timestamp);
@@ -97,6 +102,8 @@ namespace XCharts.Runtime
/// <param name="splitNumber"></param>
internal static float UpdateTimeAxisDateTimeList(List<double> list, int minTimestamp, int maxTimestamp, int splitNumber)
{
var firstValue = list.Count > 0 ? list[0] : 0;
var secondValue = list.Count > 1 ? list[1] : 0;
list.Clear();
var range = maxTimestamp - minTimestamp;
if (range <= 0) return 0;
@@ -107,7 +114,8 @@ namespace XCharts.Runtime
if (range >= ONE_YEAR * MIN_TIME_SPLIT_NUMBER)
{
var num = Math.Max(range / (splitNumber * ONE_YEAR), 1);
var dtStart = new DateTime(dtMin.Year + 1, 1, 1);
var dtStart = (firstValue == 0 || secondValue == 0) ? new DateTime(dtMin.Year + 1, 1, 1) :
(minTimestamp > firstValue ? DateTimeUtil.GetDateTime(secondValue) : DateTimeUtil.GetDateTime(firstValue));
tick = num * 365 * 24 * 3600;
while (dtStart.Ticks < dtMax.Ticks)
{
@@ -118,7 +126,8 @@ namespace XCharts.Runtime
else if (range >= ONE_MONTH * MIN_TIME_SPLIT_NUMBER)
{
var num = Math.Max(range / (splitNumber * ONE_MONTH), 1);
var dtStart = new DateTime(dtMin.Year, dtMin.Month, 1).AddMonths(1);
var dtStart = (firstValue == 0 || secondValue == 0) ? (new DateTime(dtMin.Year, dtMin.Month, 1).AddMonths(1)) :
(minTimestamp > firstValue ? DateTimeUtil.GetDateTime(secondValue) : DateTimeUtil.GetDateTime(firstValue));
tick = num * 30 * 24 * 3600;
while (dtStart.Ticks < dtMax.Ticks)
{