You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Infinite loop when there is only one DateTimePoint in the Series and MinLimit / MaxLimit is null
To Reproduce
Steps to reproduce the behavior:
Replace samples\ViewModelsSamples\Lines\AutoUpdate\ViewModel.cs with this code and then press "Add" in Lines/Autoupdate sample :
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using LiveChartsCore;
using LiveChartsCore.Defaults;
using LiveChartsCore.SkiaSharpView;
namespace ViewModelsSamples.Lines.AutoUpdate;
[ObservableObject]
public partial class ViewModel
{
private readonly Random _random = new();
private readonly ObservableCollection<DateTimePoint> _observableValues;
public ViewModel()
{
// Use ObservableCollections to let the chart listen for changes (or any INotifyCollectionChanged). // mark
_observableValues = new ObservableCollection<DateTimePoint>
{
};
Series = new ObservableCollection<ISeries>
{
new LineSeries<DateTimePoint>
{
Values = _observableValues,
Fill = null
}
};
// in the following sample notice that the type int does not implement INotifyPropertyChanged
// and our Series.Values property is of type List<T>
// List<T> does not implement INotifyCollectionChanged
// this means the following series is not listening for changes.
// Series.Add(new ColumnSeries<int> { Values = new List<int> { 2, 4, 6, 1, 7, -2 } }); // mark
}
public ObservableCollection<ISeries> Series { get; set; }
[ICommand]
public void AddItem()
{
var randomValue = _random.Next(1, 10);
_observableValues.Add(new DateTimePoint(DateTime.Now,randomValue));
}
[ICommand]
public void RemoveItem()
{
if (_observableValues.Count == 0) return;
_observableValues.RemoveAt(0);
}
[ICommand]
public void UpdateItem()
{
var randomValue = _random.Next(1, 10);
// we grab the last instance in our collection
var lastInstance = _observableValues[_observableValues.Count - 1];
// finally modify the value property and the chart is updated!
lastInstance.Value = randomValue;
}
[ICommand]
public void ReplaceItem()
{
var randomValue = _random.Next(1, 10);
var randomIndex = _random.Next(0, _observableValues.Count - 1);
_observableValues[randomIndex] = new DateTimePoint(DateTime.Now, randomValue);
}
[ICommand]
public void AddSeries()
{
// for this sample only 5 series are supported.
if (Series.Count == 5) return;
Series.Add(
new LineSeries<int>
{
Values = new List<int>
{
_random.Next(0, 10),
_random.Next(0, 10),
_random.Next(0, 10)
}
});
}
[ICommand]
public void RemoveSeries()
{
if (Series.Count == 1) return;
Series.RemoveAt(Series.Count - 1);
}
}
Expected behavior
No infinite loop
Additional context
It seems that there is a problem with double precision in src\LiveChartsCore\Axis.cs function GetPossibleSize
for (var i = start; i <= max; i += s)
when i increments (s = 1) then it has the same value as before
Immediate window:
(long)i
637958911297489152
s
1
(long)((double)i + (double)s)
637958911297489152
(long)i + (long)s
637958911297489153
The text was updated successfully, but these errors were encountered:
Describe the bug
Infinite loop when there is only one DateTimePoint in the Series and MinLimit / MaxLimit is null
To Reproduce
Steps to reproduce the behavior:
Replace samples\ViewModelsSamples\Lines\AutoUpdate\ViewModel.cs with this code and then press "Add" in Lines/Autoupdate sample :
Expected behavior
No infinite loop
Additional context
It seems that there is a problem with double precision in src\LiveChartsCore\Axis.cs function GetPossibleSize
for (var i = start; i <= max; i += s)
when i increments (s = 1) then it has the same value as before
Immediate window:
(long)i
637958911297489152
s
1
(long)((double)i + (double)s)
637958911297489152
(long)i + (long)s
637958911297489153
The text was updated successfully, but these errors were encountered: