forked from amkovkov/GranuSightSoftware2
refactor: ResouceView
Move ResourceView and all related to ui core namespace GSS2.UI.Core Split ResourceView on separate elements Make parts folding depended on size
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using Avalonia;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
using LiveChartsCore;
|
||||
using LiveChartsCore.SkiaSharpView;
|
||||
|
||||
namespace GSS2.UI.Core.ViewModels;
|
||||
|
||||
public partial class ResourceChartViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty] private ObservableCollection<ISeries> _series;
|
||||
[ObservableProperty] private ObservableCollection<Axis> _yAxes;
|
||||
[ObservableProperty] private ObservableCollection<Axis> _xAxes;
|
||||
[ObservableProperty] private Rect _bounds;
|
||||
|
||||
public ResourceChartViewModel(IEnumerable<ISeries> series, IEnumerable<Axis> yAxes, IEnumerable<Axis> xAxes)
|
||||
{
|
||||
Series = new ObservableCollection<ISeries>(series);
|
||||
YAxes = new ObservableCollection<Axis>(yAxes);
|
||||
XAxes = new ObservableCollection<Axis>(xAxes);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user