glot icon indicating copy to clipboard operation
glot copied to clipboard

Consider making NewPlot function consume variadic arguments

Open szaydel opened this issue 6 years ago • 3 comments

I think this is a great start to a useful library. I very much like GNUPlot and happy to see it being leveraged in this way. It is a great idea really. It feels like it is quite raw, and as much as I love GNUPlot , I realize its use is sometimes thorny. This library has a tough hill to climb if the intention is to abstract most of the complexity of GNUPlot and present a pleasant interface.

I had a quick Go at it, pun intended, and thought this might improve things. In my mind, in most cases you will have a good idea for what a plot needs at the moment you are creating it, and so setting up as much state as possible, I believe to be best. Variadic function therefore to me makes most sense here. I would also consider making pdf the default output format, as well as an easier means of doing things like: 'set terminal qt'.

This is awesome though, looking forward to seeing it mature, and perhaps contribute something in the process.

diff --git i/glot.go w/glot.go
index a21e367..4d918a4 100644
--- i/glot.go
+++ w/glot.go
@@ -46,9 +46,31 @@ type Plot struct {
 //  dimensions  :=> refers to the dimensions of the plot.
 //  debug       :=> can be used by developers to check the actual commands sent to gnu plot.
 //  persist     :=> used to make the gnu plot window stay open.
-func NewPlot(dimensions int, persist, debug bool) (*Plot, error) {
+func NewPlot(dimensions int, args ...string) (*Plot, error) {
+       var plotFmt = "png"
+       var pltStyle = "points"
+       var debug, persist bool
+
+       for _, arg := range args {
+               switch arg {
+               case "pdf":
+                       plotFmt = "pdf"
+               case "persist":
+                       persist = true
+               case "debug":
+                       debug = true
+               case "bar":
+                       pltStyle = "bar"
+               case "lines":
+                       pltStyle = "lines"
+               case "linepoints":
+                       pltStyle = "linepoints"
+               case "histogram":
+                       pltStyle = "histogram"
+               }
+       }
        p := &Plot{proc: nil, debug: debug, plotcmd: "plot",
-               nplots: 0, dimensions: dimensions, style: "points", format: "png"}
+               nplots: 0, dimensions: dimensions, style: pltStyle, format: plotFmt}
        p.PointGroup = make(map[string]*PointGroup) // Adding a mapping between a curve name and a curve
        p.tmpfiles = make(tmpfilesDb)
        proc, err := newPlotterProc(persist)

szaydel avatar Oct 19 '17 18:10 szaydel

Hey, @szaydel
Thanks, these are some interesting ideas and thank you so much for pointing it out.
I went png save format initially primarily because it seemed really convinient(especially for debugging) but on a second thought I think Pdf would be more reasonable.
Also Variadic function definitely seems like a very useful and interesting proposition and I am certainly going to make use of it as the development moves forward. (I can't believe I didn't use it already but nevermind.... )

Here's just one problem, I am going through a tough academic schedule and nowadays I don't really have much time to contribute because of my commitments.(Atleast for 2 weeks). I will certainly start as soon as I have time.
If you have any suggestions and feel like making a contribution please go ahead. I will take a look.

arafatkatze avatar Oct 19 '17 21:10 arafatkatze

Happy that you think these are good ideas. I am generally slammed, as much as I would love to help, it is not likely to come in significant chunks. Academia is critical, so I am sure this project will wait. I have same sorts of time constraints, so I can totally appreciate what you are saying. If I do find some time to offer something meaningful, I will give it a go. No pun intended... Or, well maybe a little. :)

szaydel avatar Oct 19 '17 21:10 szaydel

@szaydel Thanks.
By the way, I love puns too so keep em coming.

arafatkatze avatar Oct 19 '17 21:10 arafatkatze