iTranslated by AI
Breaking Changes in gonum.org/v1/plot Package
gonum.org/v1/plot, one of the graph plotting packages, has been updated to v0.9.0. It seems to include breaking changes, so I'm making a note of them here.
Return value of the plot.New function
In the plot.New() function used to create a plot.Plot instance, the previous version returned an error as well, like this:
p, err := plot.New()
However, in v0.9.0, it no longer returns an error:
p := plot.New()
Well, I suppose it's fine since it makes things a little bit easier by removing the need for error handling.
Changes to default fonts and font specification
Previously, fonts were specified as strings, like this:
plot.DefaultFont = "Helvetica"
plotter.DefaultFont = "Helvetica"
It seems the font control part has been completely rebuilt; not only has the method of specifying fonts changed, but the fonts themselves have been replaced. Specifically, you now specify them like this:
plot.DefaultFont = font.Font{
Typeface: "Liberation",
Variant: "Sans",
}
plotter.DefaultFont = plot.DefaultFont
The fonts that gonum.org/v1/plot pre-caches and allows you to specify are as follows:
| Typeface | Variant | Style | Weight |
|---|---|---|---|
"Liberation" |
"Serif" |
font.StyleNormal | font.WeightNormal |
"Liberation" |
"Serif" |
font.StyleNormal | font.WeightBold |
"Liberation" |
"Serif" |
font.StyleItalic | font.WeightNormal |
"Liberation" |
"Serif" |
font.StyleItalic | font.WeightBold |
"Liberation" |
"Sans" |
font.StyleNormal | font.WeightNormal |
"Liberation" |
"Sans" |
font.StyleNormal | font.WeightBold |
"Liberation" |
"Sans" |
font.StyleItalic | font.WeightNormal |
"Liberation" |
"Sans" |
font.StyleItalic | font.WeightBold |
"Liberation" |
"Mono" |
font.StyleNormal | font.WeightNormal |
"Liberation" |
"Mono" |
font.StyleNormal | font.WeightBold |
"Liberation" |
"Mono" |
font.StyleItalic | font.WeightNormal |
"Liberation" |
"Mono" |
font.StyleItalic | font.WeightBold |
Among these, font.StyleNormal and font.WeightNormal are the default values and can be omitted. Also, if no font is specified, Liberation/Serif is set as the default. Note that the font package used for specifying Style and Weight is not gonum.org/v1/plot/font but rather golang.org/x/image/font, so be careful of package name collisions.
By the way, Liberation fonts are provided under the SIL Open Font License 1.1, and in Go, they can be controlled via the go-fonts/liberation package.
Well, it's certainly a breaking change, but with the current structure, it seems to have better affinity with the golang.org/x/image/font package, and it might make it easier to handle external font files. I won't do it because it's a hassle, though.
References
Discussion