forked from amkovkov/GranuSightSoftware2
67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
using System.Collections.ObjectModel;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
using Avalonia;
|
|
|
|
using LiveChartsCore;
|
|
using LiveChartsCore.SkiaSharpView;
|
|
|
|
namespace GSS2.UI.Core.ViewModels;
|
|
|
|
public partial class ResourceChartViewModel : ViewModelBase
|
|
{
|
|
private readonly ILogger<ResourceChartViewModel> _logger;
|
|
[ObservableProperty] private ObservableCollection<ISeries> _series;
|
|
[ObservableProperty] private ObservableCollection<Axis> _yAxes;
|
|
[ObservableProperty] private ObservableCollection<Axis> _xAxes;
|
|
[ObservableProperty] private Rect _bounds;
|
|
|
|
public ResourceChartViewModel(ILogger<ResourceChartViewModel> logger, IEnumerable<ISeries> series, IEnumerable<Axis> yAxes, IEnumerable<Axis> xAxes)
|
|
{
|
|
_logger = logger;
|
|
_logger.LogInformation("Initialization");
|
|
|
|
Series = new ObservableCollection<ISeries>(series);
|
|
YAxes = new ObservableCollection<Axis>(yAxes);
|
|
XAxes = new ObservableCollection<Axis>(xAxes);
|
|
|
|
_logger.LogInformation("Initialized");
|
|
}
|
|
|
|
partial void OnBoundsChanged(Rect value)
|
|
{
|
|
var textSize = value.Height switch
|
|
{
|
|
< 100 => 8,
|
|
< 150 => 10,
|
|
< 200 => 12,
|
|
_ => 14
|
|
};
|
|
var labelsDensity = value.Height switch
|
|
{
|
|
< 100 => 0.2f,
|
|
< 150 => 0.3f,
|
|
< 200 => 0.4f,
|
|
_ => 0.5f
|
|
};
|
|
foreach (var axis in YAxes)
|
|
{
|
|
axis.TextSize = textSize;
|
|
axis.NameTextSize = textSize;
|
|
axis.LabelsDensity = labelsDensity;
|
|
}
|
|
}
|
|
|
|
public void AppendValue(double value, int maxValuesCount)
|
|
{
|
|
if (Series.Count() != 1 || Series.First().Values is not ObservableCollection<double> values)
|
|
return;
|
|
|
|
values.Add(value);
|
|
while (values.Count() > maxValuesCount || values.Count() == 0)
|
|
values.RemoveAt(0);
|
|
}
|
|
} |