I can't think of a reasonnable argument for having different
text.Handler within the same plot.Plot (but users are always very
imaginatives :P), but a different text.Handler per plot.Plot (within the
same program or library), yes.
that said, we could imagine introducing a new protocol:
package text
type ResetHandler interface { // SetHandlerer? HandlerSetter ?
SetTextHandler(h Handler)
}
// ---
package plot
func (p *Plot) TextHandler() text.Handler {
return p.hdlr
}
func (p *Plot) SetTextHandler(h text.Handler) {
// set its own handler (in Title, axes, Legend)
// ...
// propagate to plotters
for i := range p.plotters {
pp := &p.plotters[i]
if pp, ok := pp.(text.ResetHandler); ok {
pp.SetTextHandler(h)
}
}
}
and have plot/plotter types (Labels, BoxPlot, Quartile and Sankey)
implement text.ResetHandler.
that way, user code could use the default plot.New function and still,
w/o too much ceremony override the default one.
p := plot.New()
p.SetTextHandler(mypkg.Handler(...))
labels, err := plotter.NewLabels(...)
p.Add(labels)
err = p.Save(...)
(p.Save (well, p.Draw) would harmonize text.Handler by looping over p.plotters and call
SetTextHandler).
another approach:
- drop the text.Handler field from text.Style
- add it as a parameter for text.Style methods that need it (Width,
Height, Rectangle)
- add an exported text.Handler field to plot.Plot
- add an exported text.Handler field to vg/draw.Canvas (that would be seeded from
plot.Plot)
that alternative approach may fit better with the overall philosophical
approach of gonum/plot.
WDYT?
-s