Documentation
¶
Overview ¶
Package gg renders refract charts through github.com/gogpu/gg.
This is a separate Go module. Importing refract's core gets you a stdlib-only dependency graph and SVG output; importing this module adds the GoGPU stack and gets you raster output — still with zero CGO, so CGO_ENABLED=0 builds and cross-compiles exactly as before.
import ggbackend "github.com/timzifer/refract/backend/gg"
err := p.Render(ggbackend.PNG("chart.png"))
What this backend uses, and what it deliberately does not ¶
It touches only the gg root package and gg/text. It does not import gg/gpu, gg/scene or gg/recording. That is a deliberate limit on the coupling surface (docs/adr/0006): gg is young and moves fast, so the narrower the adapter's contact with it, the cheaper it is to follow. It also means the CPU rasterizer is what runs — no GPU device is ever created, and CI needs no graphics hardware.
The GPU tier, PDF output and a native window are later milestones. When they arrive they will arrive here, behind the same ir.Backend interface.
Text ¶
gg ships no default font, so this backend embeds Go Regular and Go Bold (golang.org/x/image/font/gofont, BSD-3-Clause) and uses them unless a font is supplied with WithFont. Measurement comes from the same face that draws the text, so metrics here are exact — unlike the built-in SVG backend, which approximates.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*options)
Option configures a target.
func JPEGQuality ¶
JPEGQuality sets the JPEG encoder quality, 1 to 100. The default is 90.
func WithFont ¶
WithFont replaces the embedded Go fonts with supplied TrueType or OpenType files.
Pass bold or italic as nil to synthesise nothing and reuse regular for that style. Italic is worth supplying for a chart whose labels carry notation: a typesetter sets variables italic, and the vector emitters ask the viewer for an italic face whether or not one is given here.
type Surface ¶ added in v1.0.0
type Surface struct {
// contains filtered or unexported fields
}
Surface is a target that draws into memory rather than into a file.
PNG and JPEG encode a chart and are done with it. A Surface keeps the pixels: it stays open, its image can be read after every frame, and it can be resized and repainted in place. That is what a window needs — see github.com/timzifer/refract/backend/window, which presents this image as a texture — and what any caller compositing a chart into a larger picture needs too.
s := gg.NewSurface() live, err := p.Live(s) // ... draw, resize, draw again ... img := s.Image()
A Surface draws one chart at a time and is not safe for concurrent use.
func NewSurface ¶ added in v1.0.0
NewSurface returns an in-memory target. It takes the same options as the file targets: the font is the one thing a raster backend has to be told about.
func (*Surface) Close ¶ added in v1.0.0
Close releases the pixel buffer. The image is not available afterwards.
func (*Surface) Generation ¶ added in v1.0.0
Generation reports a counter that changes whenever the pixels do.
It answers "is this frame the same as the last one" without comparing two buffers, which is what lets a window skip re-uploading a chart nobody has touched. It is zero for a surface that has not been opened, and it is not a frame number: a frame that painted nothing does not advance it.
func (*Surface) Image ¶ added in v1.0.0
Image returns what has been drawn, or nil before the first Surface.Open.
The image is the surface's own buffer rather than a copy, so it is valid until the next frame overwrites it — which is what makes reading it every frame free. A caller keeping one past that must copy it.