Vereinsmeisterschaften  22aa7800eae54b428d40e835886cefe1fdefdfdf
This is a software that can be used to manage the internal competition of the swimming club Illertissen called "Vereinsmeisterschaften".
Loading...
Searching...
No Matches
AnalyticsWidgetDistancesBetweenStarts.xaml.cs
2using System.Windows.Media;
3using LiveChartsCore;
4using LiveChartsCore.Kernel.Events;
5using LiveChartsCore.Measure;
6using LiveChartsCore.SkiaSharpView;
7using LiveChartsCore.SkiaSharpView.Painting;
8using SkiaSharp;
13
15{
19 public partial class AnalyticsWidgetDistancesBetweenStarts : AnalyticsWidgetBase
20 {
22 private IWorkspaceService _workspaceService;
23
24 public AnalyticsWidgetDistancesBetweenStarts(AnalyticsModuleDistancesBetweenStarts analyticsModule, IWorkspaceService workspaceService) : base(analyticsModule)
25 {
26 InitializeComponent();
27 _workspaceService = workspaceService;
28 PART_scrollViewerChart.SizeChanged += (sender, e) => OnPropertyChanged(nameof(ChartHeight));
29 }
30
31 public override string Icon { get; } = "\uE769";
32
33 public override void Refresh()
34 {
35 OnPropertyChanged(nameof(StartDistancesPerPersonSeries));
36 OnPropertyChanged(nameof(ChartHeight));
37 OnPropertyChanged(nameof(XAxes));
38 OnPropertyChanged(nameof(YAxes));
39 base.Refresh();
40 }
41
42 public Dictionary<Person, List<int>> DistancesBetweenStartsPerPersonReversed => _analyticsModule?.DistancesBetweenStartsPerPerson?.Reverse()?.ToDictionary() ?? new Dictionary<Person, List<int>>();
43
44 public ISeries[] StartDistancesPerPersonSeries
45 {
46 get
47 {
48 if (_analyticsModule == null || AnalyticsAvailable == false) return null;
49
50 uint shortPausesThreshold = _workspaceService?.Settings?.GetSettingValue<uint>(WorkspaceSettings.GROUP_RACE_CALCULATION, WorkspaceSettings.SETTING_RACE_CALCULATION_SHORT_PAUSE_THRESHOLD) ?? 3;
51
52 int maxLength = DistancesBetweenStartsPerPersonReversed.Values.Max(list => list.Count);
53 List<List<int?>> normalizedLists = DistancesBetweenStartsPerPersonReversed.Values.Select(list =>
54 {
55 List<int?> padded = list.Select(i => (int?)i).ToList();
56 while (padded.Count < maxLength) { padded.Add(null); }
57 return padded;
58 }).ToList();
59
60 List<ISeries> seriesList = new List<ISeries>();
61 for (int i = 0; i < maxLength; i++)
62 {
63 var series = new StackedRowSeries<int?>
64 {
65 StackGroup = 0,
66 Name = $"Value {i}",
67 Values = normalizedLists.Select(list => list[i]).ToList(),
68 DataLabelsPaint = new SolidColorPaint(SKColors.Black),
69 DataLabelsSize = 14,
70 DataLabelsPosition = DataLabelsPosition.Middle,
71 MaxBarWidth = ChartMaxBarWidth,
73 }
74 .OnPointMeasured(point =>
75 {
76 // assign a color to each point depending on the start distance
77 if (point.Visual is null) return;
78 SolidColorBrush displayColor;
79 if(point.Model.Value < shortPausesThreshold)
80 {
81 displayColor = Application.Current.Resources["BrushError"] as SolidColorBrush;
82 }
83 else
84 {
85 displayColor = Application.Current.Resources["BrushOk"] as SolidColorBrush;
86 }
87 point.Visual.Fill = new SolidColorPaint(SKColor.Parse(displayColor.Color.ToString()));
88 });
89 (series as StackedRowSeries<int?>).Stroke.StrokeThickness = 2;
90 seriesList.Add(series);
91 }
92
93 return seriesList.ToArray();
94 }
95 }
96
100 public double ChartMaxBarWidth => 45;
101
106 public double ChartHeight => Math.Max(PART_scrollViewerChart.ActualHeight, DistancesBetweenStartsPerPersonReversed.Keys.Count * ChartMaxBarWidth);
107
108 public Axis[] XAxes =>
109 [
110 new Axis
111 {
113 NamePaint = ColorPaintMahAppsText,
114 NameTextSize = ANALYTICS_WIDGET_AXIS_TEXTSIZE_DEFAULT,
115 MinLimit = 0,
116 SeparatorsPaint = COLORPAINT_SEPARATORS,
117 LabelsPaint = ColorPaintMahAppsText,
118 TextSize = ANALYTICS_WIDGET_AXIS_TEXTSIZE_DEFAULT,
119 MinStep = 1
120 }
121 ];
122
123 public Axis[] YAxes =>
124 [
125 new Axis
126 {
127 IsVisible = true,
128 SeparatorsPaint = null,
129 Labels = DistancesBetweenStartsPerPersonReversed.Keys.Select(p => $"{p.FirstName}, {p.Name}").ToArray(),
130 LabelsPaint = ColorPaintMahAppsText,
131 TextSize = ANALYTICS_WIDGET_AXIS_TEXTSIZE_DEFAULT,
132 MinStep = 1,
133 ForceStepToMin = true
134 }
135 ];
136 }
137}
Analytics module to calculate the distances between the starts of each person in the persisted race v...
Dictionary< Person, List< int > > DistancesBetweenStartsPerPerson
Distances between the starts (value) per person (key).
Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
static string DistanceBetweenStartsString
Sucht eine lokalisierte Zeichenfolge, die Distance between starts ähnelt.
bool AnalyticsAvailable
Indicating if the analytics module has data.
IAnalyticsModule AnalyticsModule
Analytics module used by this user control.
SolidColorPaint ColorPaintMahAppsText
SolidColorPaint that represents the MahApps.Brushes.Text brush.
AnalyticsWidgetBase(IAnalyticsModule analyticsModule)
Constructor of the AnalyticsWidgetBase
double ChartHeight
Calculate the chart height manually to support scrolling of the RowSeries by the surrounding scroll v...
Interface for a service used to manage a workspace.
WorkspaceSettings Settings
Settings for the current workspace.