Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions Source/NETworkManager.Utilities/LvlChartsDefaultInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

namespace NETworkManager.Utilities;

public class LvlChartsDefaultInfo
public class LvlChartsDefaultInfo(DateTime dateTime, double value)
{
public LvlChartsDefaultInfo(DateTime dateTime, double value)
{
DateTime = dateTime;
Value = value;
}

public DateTime DateTime { get; }
public double Value { get; set; }
public DateTime DateTime { get; } = dateTime;
public double Value { get; } = value;
}
46 changes: 46 additions & 0 deletions Source/NETworkManager/Controls/LiveChartsPingTimeTooltip.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<UserControl x:Class="NETworkManager.Controls.LiveChartsPingTimeTooltip"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d">
<Border Background="{DynamicResource MahApps.Brushes.Window.Background}"
BorderBrush="{DynamicResource MahApps.Brushes.Gray8}"
BorderThickness="1">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0"
Style="{StaticResource InfoTextBlock}"
HorizontalAlignment="Center"
Text="{Binding HeaderText}" />
<ItemsControl Grid.Row="2" Grid.Column="0"
ItemsSource="{Binding TooltipEntries}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Height="2" Width="14"
Fill="{Binding SeriesColor}" />
<TextBlock Grid.Column="2" Text="{Binding Value}"
Style="{StaticResource DefaultTextBlock}"
VerticalAlignment="Center" Foreground="{DynamicResource MahApps.Brushes.Gray3}" />
<TextBlock Grid.Column="4" Text="{Binding SeriesName}"
Style="{StaticResource AccentTextBlock}"
VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Border>
</UserControl>
94 changes: 94 additions & 0 deletions Source/NETworkManager/Controls/LiveChartsPingTimeTooltip.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using LiveChartsCore;
using LiveChartsCore.Kernel;
using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using NETworkManager.Utilities;
using SkiaSharp;

namespace NETworkManager.Controls;

public partial class LiveChartsPingTimeTooltip : IChartTooltip, INotifyPropertyChanged
{
private readonly Popup _popup;

public LiveChartsPingTimeTooltip()
{
InitializeComponent();
DataContext = this;
_popup = new Popup
{
AllowsTransparency = true,
Placement = PlacementMode.MousePoint,
StaysOpen = true,
Child = this
};
}

public event PropertyChangedEventHandler PropertyChanged;

public string HeaderText
{
get;
private set
{
if (field == value) return;
field = value;
OnPropertyChanged();
}
}

public ObservableCollection<TooltipEntry> TooltipEntries { get; } = [];

public void Show(IEnumerable<ChartPoint> tooltipPoints, Chart chart)
{
var points = tooltipPoints.ToList();
if (points.Count == 0) return;

if (points[0].Context.DataSource is LvlChartsDefaultInfo firstInfo)
HeaderText = DateTimeHelper.DateTimeToTimeString(firstInfo.DateTime);

TooltipEntries.Clear();
foreach (var point in points)
{
var value = point.Context.DataSource is LvlChartsDefaultInfo info
? $"{info.Value} ms"
: "-/-";
TooltipEntries.Add(new TooltipEntry(
SkColorToBrush(GetSeriesColor(point)),
value,
point.Context.Series.Name ?? string.Empty));
}

_popup.PlacementTarget = chart.View as FrameworkElement;
_popup.IsOpen = true;
}

public void Hide(Chart chart)
{
_popup.IsOpen = false;
}

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

private static SKColor GetSeriesColor(ChartPoint point)
{
if (point.Context.Series is LineSeries<LvlChartsDefaultInfo> ls && ls.Stroke is SolidColorPaint paint)
return paint.Color;
return SKColors.Gray;
}

private static Brush SkColorToBrush(SKColor color)
=> new SolidColorBrush(Color.FromArgb(color.Alpha, color.Red, color.Green, color.Blue));

public record TooltipEntry(Brush SeriesColor, string Value, string SeriesName);
}
38 changes: 38 additions & 0 deletions Source/NETworkManager/Controls/LiveChartsSpeedTestTooltip.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<UserControl x:Class="NETworkManager.Controls.LiveChartsSpeedTestTooltip"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d">
<Border Background="{DynamicResource MahApps.Brushes.Window.Background}"
BorderBrush="{DynamicResource MahApps.Brushes.Gray8}"
BorderThickness="1">
<Grid>
<StackPanel Margin="10">
<ItemsControl ItemsSource="{Binding TooltipEntries}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Height="2" Width="14"
Fill="{Binding SeriesColor}" />
<TextBlock Grid.Column="2" Text="{Binding Value}"
Style="{StaticResource DefaultTextBlock}"
VerticalAlignment="Center" Foreground="{DynamicResource MahApps.Brushes.Gray3}" />
<TextBlock Grid.Column="4" Text="{Binding SeriesName}"
Style="{StaticResource AccentTextBlock}"
VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Grid>
</Border>
</UserControl>
67 changes: 67 additions & 0 deletions Source/NETworkManager/Controls/LiveChartsSpeedTestTooltip.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using LiveChartsCore;
using LiveChartsCore.Kernel;
using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using SkiaSharp;

namespace NETworkManager.Controls;

public partial class LiveChartsSpeedTestTooltip : IChartTooltip
{
private readonly Popup _popup;

public LiveChartsSpeedTestTooltip()
{
InitializeComponent();
DataContext = this;
_popup = new Popup
{
AllowsTransparency = true,
Placement = PlacementMode.MousePoint,
StaysOpen = true,
Child = this
};
}

public ObservableCollection<TooltipEntry> TooltipEntries { get; } = [];

public void Show(IEnumerable<ChartPoint> tooltipPoints, Chart chart)
{
var points = tooltipPoints.ToList();
if (points.Count == 0) return;

TooltipEntries.Clear();
foreach (var point in points)
{
var value = point.Context.DataSource is double mbps ? $"{mbps:F1} Mbps" : "-/-";
TooltipEntries.Add(new TooltipEntry(
SkColorToBrush(GetSeriesColor(point)),
value,
point.Context.Series.Name ?? string.Empty));
}

_popup.PlacementTarget = chart.View as FrameworkElement;
_popup.IsOpen = true;
}

public void Hide(Chart chart)
{
_popup.IsOpen = false;
}

private static SKColor GetSeriesColor(ChartPoint point)
{
return point.Context.Series is LineSeries<double> { Stroke: SolidColorPaint paint } ? paint.Color : SKColors.Gray;
}

private static Brush SkColorToBrush(SKColor color) => new SolidColorBrush(Color.FromArgb(color.Alpha, color.Red, color.Green, color.Blue));

public record TooltipEntry(Brush SeriesColor, string Value, string SeriesName);
}
48 changes: 0 additions & 48 deletions Source/NETworkManager/Controls/LvlChartsPingTimeTooltip.xaml

This file was deleted.

35 changes: 0 additions & 35 deletions Source/NETworkManager/Controls/LvlChartsPingTimeTooltip.xaml.cs

This file was deleted.

Loading
Loading