ScottPlot / ScottPlot

Interactive plotting library for .NET
https://ScottPlot.net
MIT License
5.32k stars 861 forks source link

IPlotControl: Add `Reset()` method #3353

Closed jon-rizzo closed 7 months ago

jon-rizzo commented 9 months ago

There is probably a technical reason that I am not aware of and this is very minor point for sure, but it seems to me that it would be helpful to have Reset() on IPlotControl, since it seems to be implemented separately on each control anyways. This would allow us to build controls that know how to "wipe the slate clean" regardless of which platform they are implemented on.

swharden commented 8 months ago

Hi @jon-rizzo, thanks for this question!

In console applications the easiest way to reset a Plot is like this:

ScottPlot.Plot plot = new();
plot.Dispose();
plot = new(); // a clean one!

In user controls the way to reset a plot is something like:

formsPlot1.Plot.Reset();
formsPlot1.Refresh();

I noticed that Reset() isn't in IPlotControl but if we think it should be, we could add it to ensure all controls have this feature.

EDIT: If we add Reset() we should also add Reset(Plot newPlot) too

Let me know if this doesn't do the trick!

swharden commented 8 months ago

Following-up, I misunderstood the original suggestion 😅

I agree that this is a good idea and I'll leave this issue open until someone (or me if no one takes it, lol) adds the following methods to IPlotControl

/// <summary>
/// Disposes the current Plot and creates a new one for the control
/// </summary>
void Reset();

/// <summary>
/// Loads the given Plot into the control
/// </summary>
void Reset(Plot plot);

https://github.com/ScottPlot/ScottPlot/blob/ad66085d2086fbe3c744f5cb43cd04620517830d/src/ScottPlot5/ScottPlot5/Interfaces/IPlotControl.cs#L1-L47

These methods are already implemented in FormsPlot, and maybe other controls too....

https://github.com/ScottPlot/ScottPlot/blob/ad66085d2086fbe3c744f5cb43cd04620517830d/src/ScottPlot5/ScottPlot5%20Controls/ScottPlot.WinForms/FormsPlotBase.cs#L46-L61

aniketkumar7 commented 7 months ago

I have add the following methods to IPlotControl :

/// <summary>
/// Disposes the current Plot and creates a new one for the control
/// </summary>
void Reset();

/// <summary>
/// Loads the given Plot into the control
/// </summary>
void Reset(Plot plot);

But PR check failed please check it out.