Updated: I want to display the value of the data point closest to the cursor. I see the problem. #3847
Replies: 1 comment 5 replies
-
UPDATE Windows 10 Maybe no one is interested? Maybe no one has time for this? I tried to reproduce this problem in a special application for you. You can download this application and play with it. I also uploaded the VS project Try repeating the same steps with the application that I did in the video to reproduce the same problems that I get with the GetNearest() function.
then press the "Clear" button.
Here you will see that 1 of the 2 signals is not visible to the mouse cursor! I think that it is located in a different place and not where it is drawn. Demo video: bandicam.2024-05-23.14-41-01-797.mp4I think this is a problem! Here's all the code: using ScottPlot;
using ScottPlot.Plottables;
namespace SlowDemoSP5
{
public partial class Form1 : Form
{
List<SignalXY> plotList = []; // for count only SignalXY plots
bool right = false; // for additional axes: Add Left or Right
private Marker? HighlightedPoint; // Marker point
private SignalXY? sig; // signal
public Form1()
{
InitializeComponent();
}
private void AddDataToPlot(int lenData, double minData, double maxData, string label)
{
double[] xs = Generate.Consecutive(lenData, 1, 0);
double[] ys = Generate.RandomSample(lenData, minData, maxData);
sig = formsPlot1.Plot.Add.SignalXY(xs, ys);
//plotList.AddRange(formsPlot1.Plot.GetPlottables<SignalXY>());
plotList.Add(sig);
if (plotList.Count > 2)
{
if (right)
{
sig.Axes.YAxis = formsPlot1.Plot.Axes.AddRightAxis();
right = false;
}
else
{
sig.Axes.YAxis = formsPlot1.Plot.Axes.AddLeftAxis();
right = true;
}
}
else
{
if (plotList.Count == 1)
sig.Axes.YAxis = formsPlot1.Plot.Axes.Left;
if (plotList.Count == 2)
sig.Axes.YAxis = formsPlot1.Plot.Axes.Right;
}
sig.Axes.YAxis.Label.Text = $"{label} - {plotList.Count}";
sig.Axes.YAxis.Label.ForeColor = sig.Color;
sig.Axes.YAxis.FrameLineStyle.Color = sig.Color;
sig.Axes.YAxis.MajorTickStyle.Color = sig.Color;
sig.Axes.YAxis.MinorTickStyle.Color = sig.Color;
sig.Axes.YAxis.TickLabelStyle.ForeColor = sig.Color;
HighlightedPoint.IsVisible = false;
HighlightedPoint.Size = 8;
HighlightedPoint.Shape = MarkerShape.FilledCircle;
formsPlot1.Plot.Axes.AutoScale();
formsPlot1.Refresh();
}
private void formsPlot1_MouseMove(object? sender, MouseEventArgs e)
{
if (formsPlot1.Plot.PlottableList.Count > 0)
{
(var signalUnderMouse, DataPoint dp) = GetSignalXYUnderMouse(formsPlot1.Plot, e.X, e.Y);
HighlightedPoint.IsVisible = signalUnderMouse is not null;
if (signalUnderMouse is not null)
{
HighlightedPoint.Axes = signalUnderMouse.Axes;
HighlightedPoint.Location = dp.Coordinates;
HighlightedPoint.Color = signalUnderMouse.Color;
formsPlot1.Plot.Axes.Title.Label.IsVisible = true;
formsPlot1.Plot.Axes.Title.Label.Text = $"Index {dp.Index} at {dp.Coordinates}";
formsPlot1.Plot.Axes.Title.Label.ForeColor = signalUnderMouse.Color;
formsPlot1.Refresh();
}
return;
}
}
private (SignalXY? signalXY, DataPoint point) GetSignalXYUnderMouse(Plot plot, double x, double y)
{
Pixel mousePixel = new(x, y);
foreach (SignalXY signal in plot.GetPlottables<SignalXY>().Reverse())
{
Coordinates mouseLocation = signal.Axes.GetCoordinates(mousePixel);
RenderDetails RndDet = formsPlot1.Plot.LastRender;
//where does the program stumble? GetNearest?
DataPoint nearest = signal.Data.GetNearest(mouseLocation, RndDet);
if (nearest.IsReal)
{
return (signal, nearest);
}
}
return (null, DataPoint.None);
}
private void NumValChanged()
{
trbDataLowMin.Value = (int)numDataLowMin.Value;
trbDataLowMax.Value = (int)numDataLowMax.Value;
trbDataHighMin.Value = (int)numDataHighMin.Value;
trbDataHighMax.Value = (int)numDataHighMax.Value;
}
private void TrBarValChanged()
{
numDataLowMin.Value = trbDataLowMin.Value;
numDataLowMax.Value = trbDataLowMax.Value;
numDataHighMin.Value = trbDataHighMin.Value;
numDataHighMax.Value = trbDataHighMax.Value;
}
private void numDataValueChanged(object sender, EventArgs e)
{
NumValChanged();
}
private void trbDataValueChanged(object sender, EventArgs e)
{
TrBarValChanged();
}
private void btnClear_Click(object sender, EventArgs e)
{
plotList.Clear();
formsPlot1.Reset();
formsPlot1.Refresh();
right = false;
HighlightedPoint = formsPlot1.Plot.Add.Marker(0, 0);
HighlightedPoint.IsVisible = false;
}
private void btnAddDataLow_Click(object sender, EventArgs e)
{
AddDataToPlot((int)numLenData.Value, (double)numDataLowMin.Value, (double)numDataLowMax.Value, tbDataLowLabel.Text);
}
private void btnAddDataHigh_Click(object sender, EventArgs e)
{
AddDataToPlot((int)numLenData.Value, (double)numDataHighMin.Value, (double)numDataHighMax.Value, tbDataHighLabel.Text);
}
private void Form1_Load(object sender, EventArgs e)
{
// Only after Reset() formsPlot1.Plot.Axes.Title.Label.Text = "string" is Worked
formsPlot1.Reset();
HighlightedPoint = formsPlot1.Plot.Add.Marker(0, 0);
HighlightedPoint.IsVisible = false;
}
private void btnRefresh_Click(object sender, EventArgs e)
{
formsPlot1.Refresh();
}
}
} @swharden please let me know if you read this! Thank you. |
Beta Was this translation helpful? Give feedback.
-
Hi all! Firstly, I want to thank the author for the great work done!
Secondly I want to apologize for my English. I write with translator!
Thirdly, I'm not a programmer! But, I urgently needed a program to display graphs from a log file.
I started studying BC Winforms C# + ScottPlot, since ScottPlot is faster than its competitors.
I didn’t know what to choose SP 4 or SP 5?
I decided to try both versions!
ScottPlot 4
I used the code from here #1762
modifying it a little
Here's a video, it works great!
ScottPlot.v4.1.mp4
ScottPlot 5
I used the code from here SignalXYDrag.cs
modifying it a little
here's a video, it's slow
ScottPlot.v5.0.34.mp4
how can I speed up SP 5 like SP 4? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions