Skip to content

Commit

Permalink
plot,plotter,vg/vgtex: introduce Plot.TextHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Feb 12, 2021
1 parent dfecc4a commit 5093fd0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions plot.go
Expand Up @@ -58,8 +58,10 @@ type Plot struct {
// Legend is the plot's legend.
Legend Legend

// Fonts is the cache of fonts used by this plot.
Fonts *font.Cache
// TextHandler parses and formats text according to a given
// dialect (Markdown, LaTeX, plain, ...)
// The default is a plain text handler.
TextHandler text.Handler

// plotters are drawn by calling their Plot method
// after the axes are drawn.
Expand Down Expand Up @@ -93,17 +95,13 @@ const (
// New returns a new plot with some reasonable
// default settings.
func New() (*Plot, error) {
var (
hdlr = DefaultTextHandler
fonts = font.DefaultCache
)

hdlr := DefaultTextHandler
p := &Plot{
BackgroundColor: color.White,
X: makeAxis(horizontal),
Y: makeAxis(vertical),
Legend: newLegend(hdlr),
Fonts: fonts,
TextHandler: hdlr,
}
p.Title.TextStyle = text.Style{
Color: color.Black,
Expand Down
2 changes: 1 addition & 1 deletion plotter/labels_example_test.go
Expand Up @@ -97,7 +97,7 @@ func ExampleLabels_inCanvasCoordinates() {

// Put an 'X' in the middle of the data-canvas.
{
fnt := p.Fonts.Lookup(plotter.DefaultFont, vg.Points(12))
fnt := p.TextHandler.Cache().Lookup(plotter.DefaultFont, vg.Points(12))
da := p.DataCanvas(dc)
da.FillString(fnt, vg.Point{X: da.X(0.5), Y: da.Y(0.5)}, "X")
}
Expand Down
2 changes: 1 addition & 1 deletion vg/vgtex/canvas_example_test.go
Expand Up @@ -44,7 +44,7 @@ func Example() {

p.Add(scatter1, scatter2)

txtFont := p.Fonts.Lookup(
txtFont := p.TextHandler.Cache().Lookup(
p.X.Label.TextStyle.Font,
p.X.Label.TextStyle.Font.Size,
)
Expand Down

0 comments on commit 5093fd0

Please sign in to comment.