Refactor the Plot Module
See original GitHub issueWhat can we do to make ScottPlot better?
Current Plot.cs
source file contain about 2500 lines of code. Each time working with such a huge file is difficult.
Grouping by regions only partially solves the problem. Most of the code is API from which there is no escape.
It may make sense to split the current class into different files, at least we can move the PlotScatter, PlotSignal, etc
API definitions to a separate file, or even better to a group of files.
Plot.cs
public partial class Plot
{
// all definitions without Plottables API
....
}
PlotPlottablesAPI.cs
public partial class Plot
{
public PlottableScatter PlotScatter(...)
{
...
}
public PlottableSignal PlotSignal(...)
{
...
}
...
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Refactoring and enhancing categorical plots · Issue #2429
This issue serves to track the work involved in refactoring the categorical module to use the core infrastructure, modernizing the API, ...
Read more >Refactoring and Evolving a Model - Graph Data ...
At the end of this module, you will be able to: Describe why you would refactor a graph data model. Refactor a model...
Read more >Refactor Python models into modules
We refactor an existing model into modules, consisting of functions located in separate files. Adding models. We extend the existing model ...
Read more >Refactoring Python Applications for Simplicity
In this step-by-step tutorial, you'll learn how to refactor your Python application to be simpler and more maintainable and have fewer bugs.
Read more >Refactor webplot module as a plotter [172345011]
Use case 1: embedding Webplot as a plotter in an application # Instantiate a webplot server and starts ... webplot: Refactor the webplot...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No worries!
I’m glad you agree with this direction 👍
I like this idea! Perhaps we can break it into these groups. If we do this, perhaps we should move
Plot.cs
intoPlot/Plot.cs
and put all these files in that folder (without changing the namespace) to keep them together.Plot.PlotBar.cs
- population, barPlot.PlotFinance.cs
- candle, ohlcPlot.PlotScatter.cs
- scatter, point, linePlot.PlotSignal.cs
- Signal, SignalXY, SignalConstPlot.PlotBitmap.cs
- image, heatmapPlot.PlotText.cs
- text, annotationPlot.PlotAxisLine
- hline, vline, hspan, vspanPlot.PlotMisc.cs
- errorbar, polygon, function, pie, radar, vector fieldThank you for your offer, but I think it would be a good idea for me to do this. It has been a long time since I have looked at many of these methods and I would prefer to this carefully and slowly, refining each method one-by-one. I also want to make this change as I refactor the constructor of plottables to remove styling arguments.
Indeed! I’m experimenting with the best way to refactor plottable constructors, and I am only working on the bar plot until I figure out the best way. I hope to get the bar plot looking good in the next few days, then refactor the rest of the plottables to use a similar style.
This may be possible, but I prefer the simplicity of having a few hand-crafted methods. If there were >100 plot types I would feel differently, but there are so few that I think it is easy to maintain them by hand.
I will continue to work on this over the weekend! Thank you @StendProg, as always, for your valuable input.
Hi @StendProg, thank you for your insightful feedback! It has been very helpful discussing these topics with you.
Partial Classes
I like this conclusion. Typically classes should be small, but since this is the primary user-facing API it can be large. The files appear especially large because every argument is given its own line. I will split the Plot module like you suggest.
I will probably name this filePlotAddAPI.cs
.EDIT: I researched this topic and found the recommended naming convention for extension methods is to add a period in the filename then words to describe its purpose.
Plot.AddPlottable.cs
makes sense here.However, there is an alternative way to split this class… What if we put partial classes inside the files that define each plottable? The top ofPlottableScatter.cs
would have a small partial class to extend thePlot
module with a method to create a scatter plot. This means adding new customizations to a plottable could be achieved by editing a single file, rather than editing the plottable file and also a large API file in another folder. I could begin implementing this change, one plottable at a time, with no breaking changes. What do you think of this strategy?EDIT: I experimented with this and I no longer think this is a good idea. It does not separate concerns: files containing plot creation methods with long lists of optional arguments serve a distinctly different purpose than files which define plottable behavior and rendering. I think keeping the partial class out of the files that define plottables is a better idea.
Plot Module Structure
These are all excellent points, and your message is very well-received. I will leave the existing methods are they are.
Simplifying Plottable Constructors
I still like the idea of refactoring to simplify the constructors of plottables so that they accept only data, and public properties customize styling and behavior. Changes like this will involve changing code inside methods in the plot module, and are unlikely to affect users (since users typically do not construct plottables themselves). This improvement will reduce complexity of plottables and have no effect on users, so it seems like it has benefits and no disadvantages.