plot: Changing the default font for plots is unintuitive and/or not possible
- Dominant language
- Go
- Stars
- 3k
- Forks
- 201
- PR merge metrics
- No merged PRs in 30d
Description
### What are you trying to do?
Render a plot to SVG with a certain font as a default for title and axis
### What did you do?
```golang
plot.DefaultFont = font.Font{Typeface: "Arial"}
p := plot.New()
err := plotutil.AddLinePoints(p, ...)
...
err = p.Save(4*vg.Inch, 4*vg.Inch, "plot.svg")
...
```
### What did you expect to happen?
That all labels in the plot use the Arial font.
### What actually happened?
Rending the plot panic'ed, because Font objects are used unchecked in places using `Extent()`.
It is not clear at all, what fonts can even be used for `plot.DefaultFont` and that it needs to happen before calling `plot.New()`. Digging through the code reveals there was a built-in map, which is currently [being removed](https://github.com/gonum/plot/issues/696).
It is possible to load a custom font such as Arial, by extending the `vg.FontDirs` global. In addition, the default font cache needs to be manually extended with a mapping for "Arial" to a font object loaded via `vg.MakeFont()`.
However, this will still fail later in the SVG renderer, because it has a hard-coded mapping of typefaces to CSS style strings. This mapping cannot currently be extended. If a font is not part of this mapping, it will at least throw a proper error.
### What version of Go and Gonum/plot are you using?
From go.sum, it looks like I am using v0.9.0.
### Does this issue reproduce with the current master?
No idea.
Contributor guide
Assessment
This issue has not been assessed yet.