gonum / gonum/plot

plot: Changing the default font for plots is unintuitive and/or not possible

Aperta
#702 9 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Go
Stelle
3k
Fork
201
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### 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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia tracciando plot.DefaultFont e la gestione dei font attorno a vg.FontDirs e vg.MakeFont(), quindi esamina la mappatura dei caratteri tipografici del renderer SVG. Riproduci l’esempio Arial e segui i fallimenti attraverso il calcolo dell’estensione del font e l’output SVG. Il lavoro sarà completo quando un font predefinito configurato non causerà più un panic e i caratteri tipografici non supportati produrranno un risultato chiaro.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
go
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.