WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 48bfaeb

Browse files
authored
Merge pull request #166 from reactivemarbles/AS_UpdatePlot
Crosshair working for SignalUI
2 parents 3834963 + ab97bf8 commit 48bfaeb

File tree

4 files changed

+52
-182
lines changed

4 files changed

+52
-182
lines changed

src/CrissCross.WPF.Plot/CrissCross.WPF.Plot.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
</ItemGroup>
3737

3838
<ItemGroup>
39-
<Folder Include="Live\NewFolder\" />
39+
<Compile Remove="Live\NewFolder\**" />
40+
<EmbeddedResource Remove="Live\NewFolder\**" />
41+
<None Remove="Live\NewFolder\**" />
42+
<Page Remove="Live\NewFolder\**" />
4043
</ItemGroup>
4144
</Project>

src/CrissCross.WPF.Plot/Live/LiveChart.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ private void LockedPlotSetup()
369369
{
370370
if (!_locked)
371371
{
372+
ViewModel!.WpfPlot1vm!.Plot.Axes.ContinuouslyAutoscale = true;
372373
ViewModel!.WpfPlot1vm?.UserInputProcessor.Disable();
373374
_locked = true;
374375
}

src/CrissCross.WPF.Plot/Live/LiveChartViewModel.cs

Lines changed: 15 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

5+
using System.Diagnostics;
56
using System.Reactive;
67
using System.Reactive.Disposables;
78
using System.Reactive.Linq;
@@ -73,7 +74,14 @@ public LiveChartViewModel(Grid grid)
7374
CreateAxisWithTimeStamp();
7475
AutoScale = ReactiveCommand.Create(() => { });
7576
GraphLocked = ReactiveCommand.Create(() => { });
76-
EnableMarkerBtn = ReactiveCommand.Create(() => { });
77+
EnableMarkerBtn = ReactiveCommand.Create(() =>
78+
{
79+
foreach (var p in SignalCollectionUI)
80+
{
81+
p.ChartSettings.IsCrossHairVisible = !p.ChartSettings.IsCrossHairVisible;
82+
}
83+
});
84+
7785
MakeLeftPanelVisible = ReactiveCommand.Create(() => { });
7886

7987
AxesSetup(); // axes colors setup
@@ -563,6 +571,9 @@ where i < 9
563571
}
564572

565573
newMyItem.DataLogger!.Axes.YAxis = YAxisList[a];
574+
newMyItem.Marker!.Axes.YAxis = YAxisList[a];
575+
newMyItem.MarkerText!.Axes.YAxis = YAxisList[a];
576+
newMyItem.Crosshair!.Axes.YAxis = YAxisList[a];
566577
////newMyItem.SignalXY!.Axes.YAxis = YAxisList[a];
567578
})
568579
.DisposeWith(Disposables);
@@ -938,164 +949,14 @@ private void InitializeMouseObservable()
938949
try
939950
{
940951
MouseCoordinatesObservable.OnNext(mouseLocation);
952+
953+
Trace.WriteLine("Mouse Location: { X: " + position.X + " Y: " + position.Y + " }");
941954
}
942955
catch (Exception ex)
943956
{
944-
Console.WriteLine(ex.ToString());
957+
Console.WriteLine("mouse location error: " + ex.ToString());
945958
}
946-
947-
////foreach (var x in SignalCollectionUI)
948-
////{
949-
//// WpfPlot1vm!.Refresh();
950-
//// var closestCoordinate = x.MyItem.SignalXY!.Data.GetNearestX(rect, WpfPlot1vm!.Plot.LastRender).Coordinates;
951-
//// ////.OrderBy(coordinate => Math.Abs(coordinate.X - rect!.Value.X))
952-
//// ////.FirstOrDefault();
953-
954-
//// // hide the crosshair, marker and text when no point is selected
955-
//// var visible = x.MyItem.IsChecked && EnableMarker;
956-
//// x.Item2.Crosshair!.IsVisible = visible;
957-
//// x.Item2.Marker!.IsVisible = visible;
958-
//// x.Item2.Text!.IsVisible = visible;
959-
960-
//// if (closestCoordinate != Coordinates.NaN)
961-
//// {
962-
//// x.Item2.Crosshair!.Axes.YAxis = x.MyItem.SignalXY.Axes.YAxis;
963-
//// x.Item2.Crosshair.Position = closestCoordinate;
964-
//// x.Item2.Crosshair.LineColor = x.MyItem.SignalXY.Color;
965-
966-
//// x.Item2.Marker!.Axes.YAxis = x.MyItem.SignalXY.Axes.YAxis;
967-
//// x.Item2.Marker.Location = closestCoordinate;
968-
//// x.Item2.Marker.MarkerStyle.LineColor = x.MyItem.SignalXY.Color;
969-
970-
//// x.Item2.Text!.Axes.YAxis = x.MyItem.SignalXY.Axes.YAxis;
971-
//// x.Item2.Text.Location = closestCoordinate;
972-
//// try
973-
//// {
974-
//// x.Item2.Text.LabelText = $"{closestCoordinate.Y:0.##}\n{DateTime.FromOADate(closestCoordinate.X)}";
975-
//// }
976-
//// catch
977-
//// {
978-
//// x.Item2.Text.LabelText = $"{closestCoordinate.Y:0.##}\n{closestCoordinate.X}";
979-
//// }
980-
981-
//// x.Item2.Text.LabelFontColor = x.MyItem.SignalXY.Color;
982-
//// }
983-
984-
//// WpfPlot1vm?.Refresh();
985-
////}
986959
};
987-
////WpfPlot1vm.Events().MouseMove.Select(e => e.GetPosition(e.Device.Target))
988-
//// .CombineLatest(
989-
//// SignalCollectionUI.CurrentItems.Select(x =>
990-
//// {
991-
//// var l = new List<(SignalUI MyItem, (Crosshair? Crosshair, Marker? Marker, Text? Text))>();
992-
//// foreach (var d in x)
993-
//// {
994-
//// l.Add((d, CreateCursorValues()));
995-
//// }
996-
997-
//// return l;
998-
//// }),
999-
//// (e, x) => (e, x)).Subscribe(d =>
1000-
//// {
1001-
//// Point mousePosition = d.e;
1002-
//// float xx = Convert.ToSingle(mousePosition.X);
1003-
//// float yy = Convert.ToSingle(mousePosition.Y);
1004-
//// var rect = WpfPlot1vm!.Plot.GetCoordinates(xx, yy);
1005-
//// foreach (var x in d.x)
1006-
//// {
1007-
//// WpfPlot1vm!.Refresh();
1008-
//// var closestCoordinate = x.MyItem.SignalXY!.Data.GetNearestX(rect, WpfPlot1vm!.Plot.LastRender).Coordinates;
1009-
//// ////.OrderBy(coordinate => Math.Abs(coordinate.X - rect!.Value.X))
1010-
//// ////.FirstOrDefault();
1011-
1012-
//// // hide the crosshair, marker and text when no point is selected
1013-
//// var visible = x.MyItem.IsChecked && EnableMarker;
1014-
//// x.Item2.Crosshair!.IsVisible = visible;
1015-
//// x.Item2.Marker!.IsVisible = visible;
1016-
//// x.Item2.Text!.IsVisible = visible;
1017-
1018-
//// if (closestCoordinate != Coordinates.NaN)
1019-
//// {
1020-
//// x.Item2.Crosshair!.Axes.YAxis = x.MyItem.SignalXY.Axes.YAxis;
1021-
//// x.Item2.Crosshair.Position = closestCoordinate;
1022-
//// x.Item2.Crosshair.LineColor = x.MyItem.SignalXY.Color;
1023-
1024-
//// x.Item2.Marker!.Axes.YAxis = x.MyItem.SignalXY.Axes.YAxis;
1025-
//// x.Item2.Marker.Location = closestCoordinate;
1026-
//// x.Item2.Marker.MarkerStyle.LineColor = x.MyItem.SignalXY.Color;
1027-
1028-
//// x.Item2.Text!.Axes.YAxis = x.MyItem.SignalXY.Axes.YAxis;
1029-
//// x.Item2.Text.Location = closestCoordinate;
1030-
//// try
1031-
//// {
1032-
//// x.Item2.Text.LabelText = $"{closestCoordinate.Y:0.##}\n{DateTime.FromOADate(closestCoordinate.X)}";
1033-
//// }
1034-
//// catch
1035-
//// {
1036-
//// x.Item2.Text.LabelText = $"{closestCoordinate.Y:0.##}\n{closestCoordinate.X}";
1037-
//// }
1038-
1039-
//// x.Item2.Text.LabelFontColor = x.MyItem.SignalXY.Color;
1040-
//// }
1041-
1042-
//// WpfPlot1vm?.Refresh();
1043-
//// }
1044-
//// });
1045-
1046-
////// MOUSE EVENT
1047-
////WpfPlot1vm.Events().MouseMove.Select(e => e.GetPosition(e.Device.Target))
1048-
//// .CombineLatest(
1049-
//// ScatterCollectionUI.CurrentItems.Select(x =>
1050-
//// {
1051-
//// var l = new List<(ScatterUI MyItem, (Crosshair? Crosshair, Marker? Marker, Text? Text))>();
1052-
//// foreach (var d in x)
1053-
//// {
1054-
//// l.Add((d, CreateCursorValues()));
1055-
//// }
1056-
1057-
//// return l;
1058-
//// }),
1059-
//// (e, x) => (e, x)).Subscribe(d =>
1060-
//// {
1061-
//// Point mousePosition = d.e;
1062-
//// float xx = Convert.ToSingle(mousePosition.X);
1063-
//// float yy = Convert.ToSingle(mousePosition.Y);
1064-
//// var rect = WpfPlot1vm!.Plot.GetCoordinates(xx, yy);
1065-
//// foreach (var x in d.x)
1066-
//// {
1067-
//// WpfPlot1vm!.Refresh();
1068-
//// var closestCoordinate = x.MyItem.Scatter!.Data.GetNearestX(rect, WpfPlot1vm!.Plot.LastRender).Coordinates;
1069-
//// ////.OrderBy(coordinate => Math.Abs(coordinate.X - rect!.Value.X))
1070-
//// ////.FirstOrDefault();
1071-
1072-
//// // hide the crosshair, marker and text when no point is selected
1073-
//// var visible = x.MyItem.IsChecked && EnableMarker;
1074-
//// x.Item2.Crosshair!.IsVisible = visible;
1075-
//// x.Item2.Marker!.IsVisible = visible;
1076-
//// x.Item2.Text!.IsVisible = visible;
1077-
1078-
//// if (closestCoordinate != Coordinates.NaN)
1079-
//// {
1080-
//// x.Item2.Crosshair!.Axes.YAxis = x.MyItem.Scatter.Axes.YAxis;
1081-
//// x.Item2.Crosshair.Position = closestCoordinate;
1082-
//// x.Item2.Crosshair.LineColor = x.MyItem.Scatter.Color;
1083-
1084-
//// x.Item2.Marker!.Axes.YAxis = x.MyItem.Scatter.Axes.YAxis;
1085-
//// x.Item2.Marker.Location = closestCoordinate;
1086-
//// x.Item2.Marker.MarkerStyle.LineColor = x.MyItem.Scatter.Color;
1087-
1088-
//// x.Item2.Text!.Axes.YAxis = x.MyItem.Scatter.Axes.YAxis;
1089-
//// x.Item2.Text.Location = closestCoordinate;
1090-
1091-
//// x.Item2.Text.LabelText = $"{closestCoordinate.Y:0.##}\n{closestCoordinate.X}";
1092-
1093-
//// x.Item2.Text.LabelFontColor = x.MyItem.Scatter.Color;
1094-
//// }
1095-
1096-
//// WpfPlot1vm?.Refresh();
1097-
//// }
1098-
//// });
1099960
}
1100961

1101962
/// <summary>

src/CrissCross.WPF.Plot/Live/SignalUI.cs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ public SignalUI(
109109
AutoScale = autoscale;
110110
ZoomXY = false;
111111
ChartSettings.IsChecked = true;
112-
Crosshair = new Crosshair();
113-
Marker = new Marker();
114-
MarkerText = new Text();
112+
////Crosshair = new Crosshair();
113+
////Marker = new Marker();
114+
////MarkerText = new Text();
115115

116116
NumberPointsPlotted = 1024;
117117
Plot = plot;
@@ -120,26 +120,32 @@ public SignalUI(
120120
{
121121
CreateStreamer(color);
122122
UpdateStreamerFixedPoints(observable);
123-
AppearanceSubsriptionsStreamer();
124123
CreateCursorValues();
124+
AppearanceSubsriptionsStreamer();
125125
}
126126
else
127127
{
128128
CreateSignal(color);
129129
UpdateSignal(observable);
130-
AppearanceSubsriptions();
131130
CreateCursorValues();
131+
AppearanceSubsriptions();
132132
MouseCoordinatesObs = coordinatesObs.Subscribe(x =>
133133
{
134134
if (DataLogger!.Data.Coordinates.Count <= 0)
135135
{
136136
return;
137137
}
138138

139-
var coord = DataLogger!.GetNearestX(x, Plot.Plot.LastRender.DataRect).Coordinates;
140-
Marker.Coordinates = x;
141-
Crosshair.Position = coord;
142-
Marker.Coordinates = coord;
139+
var closestCoordinate = DataLogger!.Data.Coordinates
140+
.OrderBy(coordinate => Math.Abs(coordinate.X - x.X))
141+
.FirstOrDefault();
142+
143+
Crosshair!.Position = closestCoordinate;
144+
Marker!.Position = closestCoordinate;
145+
MarkerText!.Location = closestCoordinate;
146+
MarkerText!.LabelText = $"{closestCoordinate.Y:0.##}\n{DateTime.FromOADate(closestCoordinate.X)}";
147+
148+
Plot?.Refresh();
143149
}).DisposeWith(Disposables);
144150
}
145151
}
@@ -244,16 +250,17 @@ public SignalUI(WpfPlot plot, (string? Name, IList<double>? Value, IList<double>
244250
public void CreateCursorValues()
245251
{
246252
// Create a crosshair to highlight the point under the cursor
247-
Crosshair = Plot!.Plot.Add.Crosshair(0, 0);
248-
253+
Crosshair = Plot!.Plot.Add.Crosshair(10, 0);
249254
Crosshair.IsVisible = false;
255+
Crosshair!.LineColor = ScottPlot.Color.FromColor(System.Drawing.Color.FromName(ChartSettings!.Color!));
250256

251257
// Create a marker to highlight the point under the cursor
252258
Marker = Plot!.Plot.Add.Marker(0, 0);
253259
Marker.Shape = MarkerShape.OpenCircle;
254260
Marker.Size = 17;
255261
Marker.LineWidth = 2;
256262
Marker.IsVisible = false;
263+
Marker!.Color = ScottPlot.Color.FromColor(System.Drawing.Color.FromName(ChartSettings!.Color!));
257264

258265
// Create a text label to place near the highlighted value
259266
MarkerText = Plot!.Plot.Add.Text(" ", 0, 0);
@@ -262,6 +269,7 @@ public void CreateCursorValues()
262269
MarkerText.OffsetX = 7;
263270
MarkerText.OffsetY = -7;
264271
MarkerText.IsVisible = false;
272+
MarkerText!.LabelFontColor = ScottPlot.Color.FromColor(System.Drawing.Color.FromName(ChartSettings!.Color!));
265273
}
266274

267275
/// <summary>
@@ -361,21 +369,6 @@ public void UpdateSignal(IObservable<(string? Name, IList<double>? Value, IList<
361369
DataLogger.ManageAxisLimits = false;
362370
////DataLogger!.Add(uniqueDataValues);
363371

364-
////// UPDATE X AXIS
365-
////if (ManualScale || AutoScale)
366-
////{
367-
//// ////Plot.Plot.Axes.SetLimitsX(doublelimits, doublenow, SignalXY.Axes.XAxis);
368-
//// Plot.Plot.Axes.SetLimitsX(doublelimits, doublenow, DataLogger.Axes.XAxis);
369-
//// ////Plot.Plot.Axes.ContinuouslyAutoscale = true;
370-
//// ////Plot.Plot.RenderManager.
371-
//// ////Plot.UserInputProcessor.Disable();
372-
////}
373-
////else
374-
////{
375-
//// ////Plot.Plot.Axes.ContinuouslyAutoscale = false;
376-
//// ////Plot.UserInputProcessor.Disable();
377-
////}
378-
379372
//// UPDATE IF IS NOT PAUSED
380373
if (!ChartSettings.IsPaused)
381374
{
@@ -506,13 +499,23 @@ private void AppearanceSubsriptions()
506499
DataLogger!.LineStyle.Width = (float)x.Item1;
507500
DataLogger!.Color = ScottPlot.Color.FromColor(System.Drawing.Color.FromName(x.Item2));
508501
ChartSettings.IsChecked = x.Item3 == "Invisible" ? true : false;
509-
DataLogger.IsVisible = x.Item3 == "Invisible" ? false : true;
502+
DataLogger!.IsVisible = x.Item3 == "Invisible" ? false : true;
503+
Crosshair!.LineColor = ScottPlot.Color.FromColor(System.Drawing.Color.FromName(x.Item2));
504+
Marker!.Color = ScottPlot.Color.FromColor(System.Drawing.Color.FromName(x.Item2));
505+
MarkerText!.LabelFontColor = ScottPlot.Color.FromColor(System.Drawing.Color.FromName(x.Item2));
510506
Plot.Refresh();
511507
}).DisposeWith(Disposables);
512508
this.WhenAnyValue(x => x.ChartSettings.IsChecked).Subscribe(x =>
513509
{
514510
ChartSettings.Visibility = x == true ? "Invisible" : "Visible";
515511
}).DisposeWith(Disposables);
512+
this.WhenAnyValue(x => x.ChartSettings.IsCrossHairVisible, x => x.ChartSettings.Visibility).Subscribe(x =>
513+
{
514+
var visibility = (!x.Item1 || x.Item2 == "Invisible") ? false : true;
515+
Marker.IsVisible = visibility;
516+
Crosshair.IsVisible = visibility;
517+
MarkerText.IsVisible = visibility;
518+
}).DisposeWith(Disposables);
516519
}
517520

518521
private void AppearanceSubsriptionsStreamer()
@@ -524,6 +527,8 @@ private void AppearanceSubsriptionsStreamer()
524527
ChartSettings.IsChecked = x.Item3 == "Invisible" ? true : false;
525528
Streamer.IsVisible = x.Item3 == "Invisible" ? false : true;
526529
Crosshair.MarkerLineColor = ScottPlot.Color.FromColor(System.Drawing.Color.FromName(x.Item2));
530+
Marker!.Color = ScottPlot.Color.FromColor(System.Drawing.Color.FromName(x.Item2));
531+
MarkerText!.LabelFontColor = ScottPlot.Color.FromColor(System.Drawing.Color.FromName(x.Item2));
527532
Plot.Refresh();
528533
}).DisposeWith(Disposables);
529534
this.WhenAnyValue(x => x.ChartSettings.IsChecked).Subscribe(x =>

0 commit comments

Comments
 (0)