Skip to content

Commit

Permalink
Add Gif Image
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Jul 30, 2024
1 parent 490e8d9 commit 7cd59a2
Show file tree
Hide file tree
Showing 38 changed files with 2,803 additions and 248 deletions.
2 changes: 1 addition & 1 deletion Version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "2.0.3",
"version": "2.0.4",
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/main$"
Expand Down
6 changes: 3 additions & 3 deletions src/CrissCross.WPF.Plot/CrissCross.WPF.Plot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
<ItemGroup>
<PackageReference Include="AppBarButton.WPF" Version="1.0.1" />
<PackageReference Include="ReactiveList" Version="2.0.2" />
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41" />
<PackageReference Include="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="1.3.1" PrivateAssets="all" />
<PackageReference Include="ScottPlot.WPF" Version="5.0.36" />
<PackageReference Include="ReactiveUI.SourceGenerators" Version="1.0.3" PrivateAssets="all" />
<PackageReference Include="ScottPlot.WPF" Version="5.0.37" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CrissCross.WPF\CrissCross.WPF.csproj" />
</ItemGroup>

<ItemGroup>
<Resource Include="Images\add2.png" />
<Resource Include="Images\*.png" />
</ItemGroup>
</Project>
3 changes: 0 additions & 3 deletions src/CrissCross.WPF.Plot/FodyWeavers.xml

This file was deleted.

20 changes: 10 additions & 10 deletions src/CrissCross.WPF.Plot/Live/LiveChart.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void ExecuteMarkerOnOff()
_needMarkerOff = !(_needMarkerOff && _markerOff);
EnableMarkerBtn.ToolTip = _markerOff ? "Marker off" : "Marker";
EnableMarkerBtn.Icon = _markerOff ? AppBarIcons.md_crosshairs_off : AppBarIcons.md_crosshairs;
ViewModel!.WpfPlot1vm?.Refresh();
ViewModel!.WpfLivePlot?.Refresh();
}

private void ExecuteLockUnlock()
Expand All @@ -131,7 +131,7 @@ private void ExecuteLockUnlock()
_needLock = !(_needLock && _locked);
LiveHistory.ToolTip = _locked ? "Locked" : "Interact";
LiveHistory.Icon = _locked ? AppBarIcons.md_lock : AppBarIcons.md_lock_open;
ViewModel!.WpfPlot1vm?.Refresh();
ViewModel!.WpfLivePlot?.Refresh();
}

private void ExecuteManAutoScale()
Expand All @@ -150,7 +150,7 @@ private void ExecuteManAutoScale()
AutoScale.Icon = _autoScaled ? AppBarIcons.md_hand_back_left_off : AppBarIcons.md_hand_back_left;
_needLock = true;
ExecuteLockUnlock();
ViewModel!.WpfPlot1vm?.Refresh();
ViewModel!.WpfLivePlot?.Refresh();
}

/// <summary>
Expand All @@ -160,15 +160,15 @@ private void LockedPlotSetup()
{
if (!_locked)
{
ViewModel!.WpfPlot1vm?.Interaction.Disable();
ViewModel!.WpfLivePlot?.Interaction.Disable();
_locked = true;

// SIGNAL
foreach (var item in ViewModel!.DataSignalUI)
{
if (_autoScaled)
{
ViewModel!.WpfPlot1vm?.Plot.Axes.AutoScale(false, false);
ViewModel!.WpfLivePlot?.Plot.Axes.AutoScale(false, false);
}

item.ManualScale = !_autoScaled;
Expand All @@ -184,15 +184,15 @@ private void UnockedPlotSetup()
{
if (_locked)
{
ViewModel!.WpfPlot1vm?.Interaction.Enable();
ViewModel!.WpfLivePlot?.Interaction.Enable();
_locked = false;

// SIGNAL
foreach (var item in ViewModel!.DataSignalUI)
{
if (_autoScaled)
{
ViewModel!.WpfPlot1vm?.Plot.Axes.AutoScale(false, false);
ViewModel!.WpfLivePlot?.Plot.Axes.AutoScale(false, false);
}

item.ManualScale = false;
Expand All @@ -213,7 +213,7 @@ private void ManualScaledSetup()
{
if (_autoScaled)
{
ViewModel!.WpfPlot1vm?.Plot.Axes.AutoScale(false, false);
ViewModel!.WpfLivePlot?.Plot.Axes.AutoScale(false, false);
}

item.ManualScale = true;
Expand All @@ -237,14 +237,14 @@ private void AutoScaledSetup()
{
if (_autoScaled)
{
ViewModel!.WpfPlot1vm?.Plot.Axes.AutoScale(false, false);
ViewModel!.WpfLivePlot?.Plot.Axes.AutoScale(false, false);
}

item.ManualScale = false;
item.AutoScale = true;
}

ViewModel!.WpfPlot1vm?.Plot.Axes.AutoScale();
ViewModel!.WpfLivePlot?.Plot.Axes.AutoScale();
_autoScaled = true;
}
}
Expand Down
96 changes: 48 additions & 48 deletions src/CrissCross.WPF.Plot/Live/LiveChartViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using CP.Reactive;
using ReactiveMarbles.ObservableEvents;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using ReactiveUI.SourceGenerators;
using ScottPlot;
using ScottPlot.Palettes;
using ScottPlot.Plottables;
Expand All @@ -20,11 +20,20 @@ namespace CrissCross.WPF.Plot;
/// <summary>
/// AICSLiveChart.
/// </summary>
public class LiveChartViewModel : RxObject
public partial class LiveChartViewModel : RxObject
{
private readonly ReactiveList<IYAxis> _yAxisList;
private readonly IXAxis _xAxis1;
private WpfPlot? _wpfPlot1;
private WpfPlot? _wpfLivePlot;

/// <summary>
/// Gets or sets a value indicating whether [enable marker].
/// </summary>
/// <value>
/// <c>true</c> if [enable marker]; otherwise, <c>false</c>.
/// </value>
[Reactive]
private bool _enableMarker;

/// <summary>
/// Initializes a new instance of the <see cref="LiveChartViewModel" /> class.
Expand All @@ -33,26 +42,26 @@ public class LiveChartViewModel : RxObject
public LiveChartViewModel(Grid grid)
{
// INITIALIZATION
if (WpfPlot1vm == null)
if (WpfLivePlot == null)
{
WpfPlot1vm = new WpfPlot()
WpfLivePlot = new WpfPlot()
{
Margin = new(10, 0, 0, 0),
Name = grid?.Name + "WpfPlot"
};

SetTheme();
grid?.Children.Clear();
grid?.Children.Add(WpfPlot1vm);
grid?.Children.Add(WpfLivePlot);
}

// INITIALIZATION
DataSignalUI = [];
ControlMenu = [];

_yAxisList = [];
_xAxis1 = WpfPlot1vm.Plot.Axes.AddBottomAxis();
_xAxis1 = WpfPlot1vm.Plot.Axes.DateTimeTicksBottom();
_xAxis1 = WpfLivePlot.Plot.Axes.AddBottomAxis();
_xAxis1 = WpfLivePlot.Plot.Axes.DateTimeTicksBottom();
AutoScale = ReactiveCommand.Create(() => { });
GraphLocked = ReactiveCommand.Create(() => { });
EnableMarkerBtn = ReactiveCommand.Create(() => { });
Expand All @@ -78,10 +87,10 @@ public LiveChartViewModel(Grid grid)
/// <value>
/// The WPF plot.
/// </value>
public WpfPlot? WpfPlot1vm
public WpfPlot? WpfLivePlot
{
get => _wpfPlot1;
set => this.RaiseAndSetIfChanged(ref _wpfPlot1, value);
get => _wpfLivePlot;
set => this.RaiseAndSetIfChanged(ref _wpfLivePlot, value);
}

/// <summary>
Expand All @@ -108,21 +117,12 @@ public WpfPlot? WpfPlot1vm
/// </value>
public ReactiveCommand<Unit, Unit>? AutoScale { get; }

/// <summary>
/// Gets or sets a value indicating whether [enable marker].
/// </summary>
/// <value>
/// <c>true</c> if [enable marker]; otherwise, <c>false</c>.
/// </value>
[Reactive]
public bool EnableMarker { get; set; }

/// <summary>
/// Clears the content.
/// </summary>
public void ClearContent()
{
WpfPlot1vm?.Plot.Clear();
WpfLivePlot?.Plot.Clear();

// SIGNAL
if (DataSignalUI?.Count > 0)
Expand Down Expand Up @@ -162,7 +162,7 @@ public void InitializeSignalPlotLines(IEnumerable<IObservable<(string? Name, ILi
{
if (i < 9)
{
var newMyItem = new SignalUI(WpfPlot1vm!, observable, GetLegendColor(DataSignalUI!));
var newMyItem = new SignalUI(WpfLivePlot!, observable, GetLegendColor(DataSignalUI!));
observable.Select(x => x.Axis)
.DistinctUntilChanged()
.Subscribe(a =>
Expand Down Expand Up @@ -196,7 +196,7 @@ public void InitializeSignalPlotLines((string? Name, IList<double>? Value, IList
axis.IsVisible = false;
}

var newMyItem = new SignalUI(WpfPlot1vm!, (data.Name, data.Value, data.DateTime, data.Axis), GetLegendColor(DataSignalUI!));
var newMyItem = new SignalUI(WpfLivePlot!, (data.Name, data.Value, data.DateTime, data.Axis), GetLegendColor(DataSignalUI!));
newMyItem.SignalXY!.Axes.YAxis = _yAxisList[data.Axis];

for (var j = 0; j < _yAxisList.Count; j++)
Expand All @@ -212,10 +212,10 @@ public void InitializeSignalPlotLines((string? Name, IList<double>? Value, IList
/// </summary>
public void ManualScaleY()
{
WpfPlot1vm?.Plot.Axes.SetLimitsY(0, 100, _yAxisList[0]);
WpfPlot1vm?.Plot.Axes.SetLimitsY(0, 1000, _yAxisList[1]);
WpfPlot1vm?.Plot.Axes.SetLimitsY(0, 200, _yAxisList[2]);
WpfPlot1vm?.Refresh();
WpfLivePlot?.Plot.Axes.SetLimitsY(0, 100, _yAxisList[0]);
WpfLivePlot?.Plot.Axes.SetLimitsY(0, 1000, _yAxisList[1]);
WpfLivePlot?.Plot.Axes.SetLimitsY(0, 200, _yAxisList[2]);
WpfLivePlot?.Refresh();
}

private static string GetLegendColor(ReactiveList<StreamerUI> legend)
Expand Down Expand Up @@ -261,25 +261,25 @@ private void SetTheme(string backgroundColorHex = "#252526", string axisColorHex
var color = Color.FromHex(backgroundColorHex);
var axisColor = Color.FromHex(axisColorHex);
var majorColor = Color.FromHex(majorColorHex);
WpfPlot1vm!.Plot.Add.Palette = new Penumbra();
WpfPlot1vm.Plot.Axes.Color(axisColor);
WpfPlot1vm.Plot.Grid.MajorLineColor = majorColor;
WpfPlot1vm.Plot.FigureBackground.Color = color;
WpfPlot1vm.Plot.DataBackground.Color = color;
WpfPlot1vm.Plot.Legend.BackgroundColor = majorColor;
WpfPlot1vm.Plot.Legend.FontColor = axisColor;
WpfPlot1vm.Plot.Legend.OutlineColor = axisColor;
WpfLivePlot!.Plot.Add.Palette = new Penumbra();
WpfLivePlot.Plot.Axes.Color(axisColor);
WpfLivePlot.Plot.Grid.MajorLineColor = majorColor;
WpfLivePlot.Plot.FigureBackground.Color = color;
WpfLivePlot.Plot.DataBackground.Color = color;
WpfLivePlot.Plot.Legend.BackgroundColor = majorColor;
WpfLivePlot.Plot.Legend.FontColor = axisColor;
WpfLivePlot.Plot.Legend.OutlineColor = axisColor;
}

private void Initializations2()
{
InitializeDraggableAxisRules();
InitializeControlMenu();
WpfPlot1vm?.Refresh();
WpfLivePlot?.Refresh();
}

private void InitializeDraggableAxisRules() =>
WpfPlot1vm.Events().MouseMove.Select(e => e.GetPosition(e.Device.Target))
WpfLivePlot.Events().MouseMove.Select(e => e.GetPosition(e.Device.Target))
.CombineLatest(
DataSignalUI.CurrentItems.Select(x =>
{
Expand All @@ -296,11 +296,11 @@ private void InitializeDraggableAxisRules() =>
var mousePosition = d.e;
var xx = Convert.ToSingle(mousePosition.X);
var yy = Convert.ToSingle(mousePosition.Y);
var rect = WpfPlot1vm!.Plot.GetCoordinates(xx, yy);
var rect = WpfLivePlot!.Plot.GetCoordinates(xx, yy);
foreach (var x in d.x)
{
WpfPlot1vm!.Refresh();
var closestCoordinate = x.MyItem.SignalXY!.Data.GetNearestX(rect, WpfPlot1vm!.Plot.LastRender).Coordinates;
WpfLivePlot!.Refresh();
var closestCoordinate = x.MyItem.SignalXY!.Data.GetNearestX(rect, WpfLivePlot!.Plot.LastRender).Coordinates;
// hide the crosshair, marker and text when no point is selected
var visible = x.MyItem.IsChecked && EnableMarker;
Expand All @@ -324,7 +324,7 @@ private void InitializeDraggableAxisRules() =>
x.Item2.Text.LabelFontColor = x.MyItem.SignalXY.Color;
}
WpfPlot1vm?.Refresh();
WpfLivePlot?.Refresh();
}
});

Expand All @@ -333,19 +333,19 @@ private void InitializeDraggableAxisRules() =>
private (Crosshair? Crosshair, Marker? Marker, Text? Text) CreateCursorValues()
{
// Create a crosshair to highlight the point under the cursor
var crosshair = WpfPlot1vm?.Plot.Add.Crosshair(0, 0);
var crosshair = WpfLivePlot?.Plot.Add.Crosshair(0, 0);

crosshair!.IsVisible = false;

// Create a marker to highlight the point under the cursor
var marker = WpfPlot1vm?.Plot.Add.Marker(0, 0);
var marker = WpfLivePlot?.Plot.Add.Marker(0, 0);
marker!.Shape = MarkerShape.OpenCircle;
marker.Size = 17;
marker.LineWidth = 2;
marker!.IsVisible = false;

// Create a text label to place near the highlighted value
var text = WpfPlot1vm?.Plot.Add.Text(" ", 0, 0);
var text = WpfLivePlot?.Plot.Add.Text(" ", 0, 0);
text!.LabelAlignment = Alignment.LowerLeft;
text.LabelBold = true;
text.OffsetX = 7;
Expand Down Expand Up @@ -374,7 +374,7 @@ private void AxesSetup()
// Setup Y Axis
for (var i = 0; i < 3; i++)
{
_yAxisList.Add(WpfPlot1vm!.Plot.Axes.AddRightAxis());
_yAxisList.Add(WpfLivePlot!.Plot.Axes.AddRightAxis());
_yAxisList[i].FrameLineStyle.Color = baseColor;
_yAxisList[i].TickLabelStyle.ForeColor = baseColor;
_yAxisList[i].MajorTickStyle.Color = baseColor;
Expand All @@ -394,7 +394,7 @@ private void AxesSetup()

private void HideLeftAxis(Color color)
{
var l = WpfPlot1vm?.Plot.Axes.Left;
var l = WpfLivePlot?.Plot.Axes.Left;
var backColour = Color.FromHex("#252526");
l!.Label.ForeColor = backColour;
l.FrameLineStyle.Color = color;
Expand All @@ -412,7 +412,7 @@ private void ManualScaleX()
var doublenow = now.ToOADate();
var limits = now.Add(TimeSpan.FromMinutes(-60));
var doublelimits = limits.ToOADate();
WpfPlot1vm?.Plot.Axes.SetLimitsX(doublelimits, doublenow, _xAxis1);
WpfPlot1vm?.Refresh();
WpfLivePlot?.Plot.Axes.SetLimitsX(doublelimits, doublenow, _xAxis1);
WpfLivePlot?.Refresh();
}
}
Loading

0 comments on commit 7cd59a2

Please sign in to comment.