Closed Vindaar closed 5 years ago
Ok, quite a bit nicer now. The base plot
templates remain as templates to use the variable names for titles, labels etc.
Added procs to change width / height of layout and fixed a bug (I reused x
and y
in the heatmap template).
Edit: also every proc, which works on a Trace
of the plot, takes an optional idx
parameter, to access a specific trace in the plot.
this is nice! thanks!
Once again, based on https://github.com/brentp/nim-plotly/pull/28.
While playing around with NimData I wanted to have some easy way to just plot data. I wrote a few templates to do that until I realized that this should really go here (support for DataFrames is then trivial).
~To be fair, this is not an efficient way to create plots (every
.
template call will create a mutable copy of the output of the previous!), nor is the created code necessarily nice.~ (rewritten using procs) But it seems to work just fine. Until someone can come up with a cleaner solution, I think this is better than nothing. Well, and that this is incomplete is pretty obvious I guess.It allows us to write e.g.
which would create reasonable title and labels created from the variable names.
I'd consider this code pretty experimental, but maybe playing around with it a little will uncover the shortcomings better than staring at it. :)
Edit: just a note about why all base plot templates aren't procs: this allows us to get the variable name in the calling scope of the template to provide good defaults for labels etc.
Edit2: Ohhh, I just realized that since
Plot
is a ref type I can modify the return value of a proc returningPlot[T]
(so no need forvar Plot[T]
return type). No need for everything being a template.