Skip to content

Commit

Permalink
yay
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGuy920 committed Oct 25, 2024
1 parent 4e62330 commit 7cb0866
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 93 deletions.
15 changes: 7 additions & 8 deletions LogVisualizer/App.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Application x:Class="LogVisualizer.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:LogVisualizer"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
<Application
x:Class="LogVisualizer.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:LogVisualizer"
StartupUri="Windows/MainWindow.xaml">
<Application.Resources />
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</Border>
</Border>
</Grid>
<DockPanel>
<DockPanel Visibility="Collapsed">
<Button
x:Name="ResetButton"
Margin="1,0,5,0"
Expand Down Expand Up @@ -118,7 +118,7 @@
IsMoveToPointEnabled="True"
Maximum="100"
Minimum="1"
ValueChanged="ScaleData_ValueChanged"
ValueChanged="ScaleDataValueChanged"
Value="27.46551563" />
</DockPanel>
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using ScottPlot;
using ScottPlot.DataSources;
using ScottPlot.Plottables;
using System.Diagnostics;
using System.Windows.Controls;
using System.Windows.Threading;
using Color = System.Windows.Media.Color;

namespace LogVisualizer.Models;
Expand All @@ -15,12 +17,12 @@ public partial class LineGraph : UserControl
public readonly string Key;
public readonly uint MetaPtr;

public Scatter ScatterLine { get; private set; }
public Signal Line { get; private set; }
public event Action? GraphUpdated;

private bool IsChecked => this.VisibilityCB.IsChecked == true;
public LineGraph(LdChan channel, double resolution)

public LineGraph(LdChan channel)
{
InitializeComponent();
this.Key = channel.Name;
Expand All @@ -34,25 +36,22 @@ public LineGraph(LdChan channel, double resolution)
this.MetaPtr = channel.MetaPtr;
this.TitleTB.Text = this.Key;

int nth = (int)(1d / resolution);
int skip = channel.Frequency > nth ? channel.Frequency / nth : channel.Frequency;
Coordinates[] coords = channel.Data.Where((_, i) => i % skip == 0).Select((d, i) => new Coordinates(i * resolution, d)).ToArray();
ScatterSourceCoordinatesArray data = new(coords);
this.ScatterLine = new Scatter(data)
float[] dt = channel.Data;
var dataPoints = new SignalSourceDouble([.. dt.Select((d, i) => (double)d)], 1d / channel.Frequency);
this.Line = new Signal(dataPoints)
{
MarkerStyle = MarkerStyle.None,
IsVisible = false,
LineColor = new ScottPlot.Color(colorR, colorG, colorB),
LineWidth = 3,
ScaleY = 1.1,
};

this.ScatterLine.LineColor = this.ScatterLine.LineColor.Lighten(0.4);
this.Line.LineColor = this.Line.LineColor.Lighten(0.4);
}

private void IsCheckedChanged(object? _, System.Windows.RoutedEventArgs? __)
{
this.ScatterLine.IsVisible = this.IsChecked;
this.Line.IsVisible = this.IsChecked;
this.GraphUpdated?.Invoke();
}

Expand All @@ -69,35 +68,40 @@ private void OnMouseDown(object _, System.Windows.Input.MouseButtonEventArgs e)

private void SelectedColorChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<Color?> e)
{
if (e.NewValue == null || this.ScatterLine == null)
if (e.NewValue == null || this.Line == null)
return;

this.ScatterLine.LineColor = new ScottPlot.Color(e.NewValue.Value.R, e.NewValue.Value.G, e.NewValue.Value.B);
this.Line.LineColor = new ScottPlot.Color(e.NewValue.Value.R, e.NewValue.Value.G, e.NewValue.Value.B);
this.GraphUpdated?.Invoke();
}

private static readonly double divisor = Math.Pow(Math.E, 5) - 1;

private void ScaleData_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
private void ScaleDataValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
{
if (this.ScatterLine == null)
if (this.Line == null)
return;

this.ScatterLine.ScaleY = 50 * (Math.Pow(Math.E, e.NewValue/20) - 1) / divisor;
this.ResetButton.IsEnabled = Math.Abs(this.ScatterLine.ScaleY - 1) >= 0.01;
//this.Line.ScaleY = 50 * (Math.Pow(Math.E, e.NewValue/20) - 1) / divisor;
//this.ResetButton.IsEnabled = Math.Abs(this.Line.ScaleY - 1) >= 0.01;

this.GraphUpdated?.Invoke();
}

private void ResetScale()
{
this.ScaleData.Value = 27.46551563;
this.ScatterLine.ScaleY = 1;
//this.Line.ScaleY = 1;
this.GraphUpdated?.Invoke();
}

private void ResetButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
this.ResetScale();
}

public void TmpEnable()
{
this.VisibilityCB.IsChecked = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
xmlns:data="clr-namespace:ScottPlot.WPF;assembly=ScottPlot.WPF"
xmlns:local="clr-namespace:LogVisualizer.Models"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
MinWidth="600"
MinHeight="400"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
Expand Down Expand Up @@ -43,18 +41,21 @@
<Border
x:Name="BorderSelector"
Grid.Row="1"
Margin="5"
Padding="5"
Background="#1FFFFFFF"
Margin="0"
Padding="0"
Background="Transparent"
BorderBrush="Transparent"
BorderThickness="3"
CornerRadius="2"
MouseDown="Selected">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock
x:Name="TitleTB"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Foreground="White"
Text="Title" />
<data:WpfPlot x:Name="Graph" Margin="0,10,0,0" />
<Button
HorizontalAlignment="Right"
VerticalAlignment="Top"
Expand All @@ -68,7 +69,6 @@
Text="x"
TextAlignment="Center" />
</Button>
<data:WpfPlot x:Name="Graph" Grid.Row="1" />
</Grid>
</Border>
</UserControl>
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using MotecLogSerializer.LdParser;
using ScottPlot;
using System.IO;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Color = System.Windows.Media.Color;
using DColor = System.Drawing.Color;

namespace LogVisualizer.Models;
Expand All @@ -17,14 +19,15 @@ public partial class PlotGraph : UserControl
public readonly IEnumerable<LineGraph> OrderedChannels;

private static readonly SolidColorBrush SelectedBrush = new(Color.FromArgb(0xFF, 0x00, 0x80, 0xFF));
private static readonly SolidColorBrush SelectedBrushBG = new(Color.FromArgb(0x10, 0xFF, 0xFF, 0xFF));
private static readonly SolidColorBrush UnselectedBrush = new(Color.FromArgb(0x01, 0xFF, 0xFF, 0xFF));
private static readonly SolidColorBrush SelectedBrushBG = new(Color.FromArgb(0x00, 0xFF, 0xFF, 0xFF));
private static readonly SolidColorBrush UnselectedBrush = new(Color.FromArgb(0x00, 0xFF, 0xFF, 0xFF));

public PlotGraph(string FullFile, IEnumerable<LdChan> Channels)
{
InitializeComponent();

this.Graph.Plot.Title(Path.GetFileName(FullFile));
this.TitleTB.Text = Path.GetFileName(FullFile);
//this.Graph.Plot.Title(Path.GetFileName(FullFile));
this.Graph.Plot.SetStyle(new ScottPlot.PlotStyle()
{
GridMajorLineColor = ScottPlot.Color.FromColor(DColor.FromArgb(50, 255, 255, 255)),
Expand All @@ -36,19 +39,16 @@ public PlotGraph(string FullFile, IEnumerable<LdChan> Channels)
IEnumerable<string> names = active.Select(c => c.Name);
string fixName(LineGraph lg) => names.Count(n => n == lg.Key) > 1 ? $"{lg.Key}.{lg.MetaPtr}" : lg.Key;

this.Channels = active.Select(c => new LineGraph(c, 0.250)).ToDictionary(fixName);
this.Channels = active.Select(c => new LineGraph(c)).ToDictionary(fixName);
this.OrderedChannels = this.Channels.Values.OrderBy(g => g.Key);

foreach ((string key, LineGraph graph) in this.Channels.OrderBy(_ => _.Key))
{
graph.GraphUpdated += this.Graph.Refresh;
this.Graph.Plot.Add.Plottable(graph.ScatterLine);
graph.GraphUpdated += () => { this.Graph.Plot.Axes.AutoScale(); this.Graph.Refresh(); };
this.Graph.Plot.Add.Plottable(graph.Line);
}

this.Graph.Plot.XLabel("Time (s)");
foreach (ScottPlot.IAxis axes in Graph.Plot.Axes.GetAxes())
axes.Min = 0;

//this.Graph.Plot.XLabel("Time (s)");
this.Graph.Refresh();
}

Expand Down
3 changes: 2 additions & 1 deletion LogVisualizer/LogVisualizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

<ItemGroup>
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.6.1" />
<PackageReference Include="ScottPlot.WPF" Version="5.0.39" />
<PackageReference Include="ScottPlot" Version="5.0.40" />
<PackageReference Include="ScottPlot.WPF" Version="5.0.40" />
</ItemGroup>

<ItemGroup>
Expand Down
73 changes: 49 additions & 24 deletions LogVisualizer/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
</Grid.RowDefinitions>

<DockPanel
x:Name="TDock"
HorizontalAlignment="Stretch"
Background="Transparent"
MouseDown="DockPanel_MouseDown">

MouseDown="DockPanelMouseDown">
<Menu
Margin="5,5,0,0"
Padding="0"
Background="#FF191919"
Background="Transparent"
BorderBrush="Gray"
BorderThickness="0"
FontSize="15"
Expand Down Expand Up @@ -153,7 +153,11 @@
BorderThickness="0"
Foreground="Transparent"
IsEnabled="False" />
<MenuItem Foreground="#1AFFFFFF" IsEnabled="False">
<MenuItem
Background="Transparent"
Foreground="#1AFFFFFF"
IsCheckable="False"
IsEnabled="False">
<MenuItem.Header>
<TextBlock
Margin="5,0"
Expand All @@ -164,7 +168,6 @@
</MenuItem.Header>
</MenuItem>
</Menu>

<Button
x:Name="CloseButton"
Width="30"
Expand Down Expand Up @@ -213,12 +216,10 @@
Text="_"
TextAlignment="Center" />
</Button>

</DockPanel>
<Border
Grid.Row="1"
Margin="5"
Background="Black"
CornerRadius="5">
<Grid>
<Grid.RowDefinitions>
Expand All @@ -230,48 +231,72 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<ScrollViewer
Grid.RowSpan="2"
Grid.Column="0"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
<UniformGrid x:Name="GraphViewer" />
</ScrollViewer>
<Grid Grid.RowSpan="2">
<TabControl
x:Name="TabController"
Background="Black"
BorderThickness="0"
SelectionChanged="TabControlSelectionChanged">
<TabItem
x:Name="NewTabControl"
Background="Gray"
Header="+ New Tab" />
</TabControl>
</Grid>

<Grid Grid.Row="0" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ToggleButton
x:Name="OnlyViewEnabled"
Grid.Column="0"
VerticalAlignment="Stretch"
BorderThickness="0"
Click="ToggleButtonClick"
Content="F"
FontWeight="Black" />

<TextBox
x:Name="SearchBar"
Grid.Column="2"
Padding="5,2"
BorderThickness="0"
FontSize="14"
FontSize="15.5"
Foreground="Gray"
GotKeyboardFocus="TextBox_GotKeyboardFocus"
LostKeyboardFocus="TextBoxLostKeyboardFocus"
Text="Search"
TextChanged="TextBoxTextChanged" />
<Button
Grid.Column="1"
Grid.Column="3"
Width="17"
Margin="0"
Padding="-2"
Padding="-5"
VerticalAlignment="Stretch"
VerticalContentAlignment="Center"
Background="LightGray"
BorderThickness="0"
Click="ClearSearch"
Content="x"
FontFamily="Cascadia Mono"
FontSize="18"
FontWeight="Bold"
Foreground="Red" />
Click="ClearSearch">
<TextBlock
Margin="0"
Padding="2,0,2,1"
VerticalAlignment="Center"
FontFamily="Cascadia Mono"
FontSize="20"
FontWeight="Bold"
Foreground="Red"
Text="x" />
</Button>
</Grid>
<Grid
Grid.Row="1"
Grid.Column="1"
Background="#19FFFFFF">
<ScrollViewer MinWidth="200">
<ScrollViewer MinWidth="{Binding ActualWidth, RelativeSource={RelativeSource Self}}">
<xctk:Selector
x:Name="ListView"
Margin="5,10,5,5"
Expand Down
Loading

0 comments on commit 7cb0866

Please sign in to comment.