|
|
@@ -1,9 +1,14 @@
|
|
|
-using Avalonia.Media;
|
|
|
+using Avalonia.Data.Converters;
|
|
|
+using Avalonia.Media;
|
|
|
using Avalonia.Media.Imaging;
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
+using DynamicData;
|
|
|
using InABox.Avalonia;
|
|
|
+using InABox.Clients;
|
|
|
+using NetTopologySuite.Triangulate;
|
|
|
using PRS.Avalonia.Modules;
|
|
|
+using Svg.Model.Drawables.Elements;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
@@ -16,11 +21,9 @@ namespace PRS.Avalonia;
|
|
|
public partial class A : ObservableObject
|
|
|
{
|
|
|
[ObservableProperty]
|
|
|
- private TimeSpan _start;
|
|
|
+ private DateTime _start;
|
|
|
[ObservableProperty]
|
|
|
- private TimeSpan _end;
|
|
|
- [ObservableProperty]
|
|
|
- private DateTime _date;
|
|
|
+ private DateTime _end;
|
|
|
|
|
|
[ObservableProperty]
|
|
|
private string _name;
|
|
|
@@ -31,38 +34,66 @@ public partial class A : ObservableObject
|
|
|
|
|
|
public partial class TestViewModel : ModuleViewModel
|
|
|
{
|
|
|
+ public static readonly IValueConverter ForegroundConverter = new FuncValueConverter<ISolidColorBrush, IBrush?>(x =>
|
|
|
+ {
|
|
|
+ if (x is null) return null;
|
|
|
+
|
|
|
+ double ConvertC(byte c)
|
|
|
+ {
|
|
|
+ var frac = c / 255.0;
|
|
|
+ if(frac <= 0.04045)
|
|
|
+ {
|
|
|
+ return frac / 12.92;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Math.Pow((frac + 0.055) / 1.055, 2.4);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var fill = x.Color;
|
|
|
+ var L = 0.2126 * ConvertC(fill.R)
|
|
|
+ + 0.7152 * ConvertC(fill.G)
|
|
|
+ + 0.0722 * ConvertC(fill.B);
|
|
|
+ if(L > 0.179)
|
|
|
+ {
|
|
|
+ return new SolidColorBrush(Colors.Black);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return new SolidColorBrush(Colors.White);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
public override string Title => "Test";
|
|
|
|
|
|
[ObservableProperty]
|
|
|
private ObservableCollection<A> _items = new();
|
|
|
|
|
|
[ObservableProperty]
|
|
|
- private double _rowIntervalMinutes = 60;
|
|
|
+ private string _block = "";
|
|
|
|
|
|
[ObservableProperty]
|
|
|
- private TimeSpan _rowInterval = TimeSpan.FromHours(1);
|
|
|
+ private DateTime _currentDate = DateTime.Today;
|
|
|
|
|
|
[ObservableProperty]
|
|
|
- private string _block = "";
|
|
|
+ private double _firstDayOfWeekNumber = 0;
|
|
|
|
|
|
[ObservableProperty]
|
|
|
- private DateTime[] _columns = [];
|
|
|
+ private DayOfWeek _firstDayOfWeek = DayOfWeek.Sunday;
|
|
|
|
|
|
public TestViewModel()
|
|
|
{
|
|
|
PrimaryMenu.Items.Add(new(Images.refresh, Refresh));
|
|
|
PrimaryMenu.Items.Add(new(Images.notification, () =>
|
|
|
{
|
|
|
- if(Items.Count > 0)
|
|
|
- {
|
|
|
- Items[0].Date = DateTime.Today.AddDays(Random.Shared.Next(0, 3));
|
|
|
- }
|
|
|
+ Items = new(Items);
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
- partial void OnRowIntervalMinutesChanged(double oldValue, double newValue)
|
|
|
+ partial void OnFirstDayOfWeekNumberChanged(double value)
|
|
|
{
|
|
|
- RowInterval = TimeSpan.FromMinutes(RowIntervalMinutes);
|
|
|
+ FirstDayOfWeek = (DayOfWeek)(int)Math.Floor(value);
|
|
|
}
|
|
|
|
|
|
public void BlockHeld(object? value, object column, TimeSpan start, TimeSpan end)
|
|
|
@@ -90,27 +121,30 @@ public partial class TestViewModel : ModuleViewModel
|
|
|
}
|
|
|
|
|
|
private void Refresh()
|
|
|
+ {
|
|
|
+ RebuildRandom();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void RebuildRandom()
|
|
|
{
|
|
|
Items.Clear();
|
|
|
- for(int j = 0; j < 4; ++j)
|
|
|
+ var date = DateTime.Today;
|
|
|
+ var startDate = new DateTime(date.Year, date.Month, 1);
|
|
|
+ var endDate = startDate.AddMonths(2).AddDays(-1);
|
|
|
+ for(int j = 0; j < 30; ++j)
|
|
|
{
|
|
|
- var date = DateTime.Today.AddDays(j);
|
|
|
- for(int i = 0; i < 5; ++i)
|
|
|
+ var start = Random.Shared.Next(0, (endDate - startDate).Days + 1);
|
|
|
+ var end = Random.Shared.Next(start, (endDate - startDate).Days + 1);
|
|
|
+ var colour = new byte[3];
|
|
|
+ Random.Shared.NextBytes(colour);
|
|
|
+ Items.Add(new A
|
|
|
{
|
|
|
- var start = RandomTime();
|
|
|
- var colour = new byte[3];
|
|
|
- Random.Shared.NextBytes(colour);
|
|
|
- Items.Add(new A
|
|
|
- {
|
|
|
- Date = date,
|
|
|
- Start = start,
|
|
|
- End = RandomTime(minimum: start),
|
|
|
- Name = RandomString(),
|
|
|
- Colour = new SolidColorBrush(new Color(255, colour[0], colour[1], colour[2]))
|
|
|
- });
|
|
|
- }
|
|
|
+ Start = startDate.AddDays(start),
|
|
|
+ End = startDate.AddDays(end),
|
|
|
+ Name = RandomString(),
|
|
|
+ Colour = new SolidColorBrush(new Color(255, colour[0], colour[1], colour[2]))
|
|
|
+ });
|
|
|
}
|
|
|
- Columns = Items.Select(x => x.Date).Distinct().Reverse().ToArray();
|
|
|
}
|
|
|
|
|
|
private static string RandomString()
|