diff --git a/WheelWizard/Views/Patterns/VrHistoryGraph.axaml b/WheelWizard/Views/Patterns/VrHistoryGraph.axaml index d55b65b0..041822db 100644 --- a/WheelWizard/Views/Patterns/VrHistoryGraph.axaml +++ b/WheelWizard/Views/Patterns/VrHistoryGraph.axaml @@ -65,11 +65,18 @@ - + + + + diff --git a/WheelWizard/Views/Patterns/VrHistoryGraph.axaml.cs b/WheelWizard/Views/Patterns/VrHistoryGraph.axaml.cs index cd1cdde8..f21eda93 100644 --- a/WheelWizard/Views/Patterns/VrHistoryGraph.axaml.cs +++ b/WheelWizard/Views/Patterns/VrHistoryGraph.axaml.cs @@ -36,6 +36,8 @@ public partial class VrHistoryGraph : UserControlBase, INotifyPropertyChanged private int _reloadVersion; private bool _isInitializingDaysDropdown; private int _selectedHistoryDays = DefaultHistoryDays; + private bool _useMatchesAsXAxis; + private RwfcPlayerVrHistoryResponse? _lastHistoryResponse; private Geometry? _graphPath; private Geometry? _graphAreaPath; private string _graphStartLabel = string.Empty; @@ -54,6 +56,22 @@ static VrHistoryGraph() FriendCodeProperty.Changed.AddClassHandler((graph, _) => graph.TriggerHistoryReload()); } + public bool UseMatchesAsXAxis + { + get => _useMatchesAsXAxis; + set + { + if (_useMatchesAsXAxis == value) + return; + + _useMatchesAsXAxis = value; + OnPropertyChanged(nameof(UseMatchesAsXAxis)); + + if (_lastHistoryResponse != null) + ApplyHistoryData(_lastHistoryResponse, _selectedHistoryDays); + } + } + public string? FriendCode { get => GetValue(FriendCodeProperty); @@ -372,6 +390,7 @@ private void SetNoFriendCodeState() private void ApplyHistoryData(RwfcPlayerVrHistoryResponse historyResponse, int days) { + _lastHistoryResponse = historyResponse; EmptyStateText = "No VR history found for this range yet."; StartingVr = historyResponse.StartingVr; EndingVr = historyResponse.EndingVr; @@ -408,19 +427,40 @@ private void ApplyHistoryData(RwfcPlayerVrHistoryResponse historyResponse, int d GraphMinVrText = minVr.ToString("N0"); GraphMaxVrText = maxVr.ToString("N0"); - var labelFormat = days >= 7 ? "MMM d" : "MMM d HH:mm"; - GraphStartLabel = graphStart.ToLocalTime().ToString(labelFormat); - GraphMidLabel = graphStart.AddSeconds(totalSeconds / 2).ToLocalTime().ToString(labelFormat); - GraphEndLabel = graphEnd.ToLocalTime().ToString(labelFormat); + + if (UseMatchesAsXAxis) + { + GraphStartLabel = "Match 1"; + GraphMidLabel = $"Match {(orderedByDate.Count / 2) + 1}"; + GraphEndLabel = $"Match {orderedByDate.Count}"; + } + else + { + var labelFormat = days >= 7 ? "MMM d" : "MMM d HH:mm"; + GraphStartLabel = graphStart.ToLocalTime().ToString(labelFormat); + GraphMidLabel = graphStart.AddSeconds(totalSeconds / 2).ToLocalTime().ToString(labelFormat); + GraphEndLabel = graphEnd.ToLocalTime().ToString(labelFormat); + } var points = orderedByDate - .Select(entry => - { - var seconds = (entry.Date - graphStart).TotalSeconds; - var x = seconds / totalSeconds * GraphWidth; - var y = GraphHeight - (entry.TotalVr - minVr) / (double)vrRange * GraphHeight; - return new Point(x, y); - }) + .Select( + (entry, i) => + { + double x; + if (UseMatchesAsXAxis) + { + x = orderedByDate.Count > 1 ? (double)i / (orderedByDate.Count - 1) * GraphWidth : 0; + } + else + { + var seconds = (entry.Date - graphStart).TotalSeconds; + x = seconds / totalSeconds * GraphWidth; + } + + var y = GraphHeight - (entry.TotalVr - minVr) / (double)vrRange * GraphHeight; + return new Point(x, y); + } + ) .ToList(); GraphPath = BuildLineGeometry(points); @@ -430,6 +470,7 @@ private void ApplyHistoryData(RwfcPlayerVrHistoryResponse historyResponse, int d private void ResetGraph() { + _lastHistoryResponse = null; GraphPath = null; GraphAreaPath = null; GraphStartLabel = string.Empty;