fixes to InMemory setup

This commit is contained in:
Erik Bunn 2022-06-27 15:15:13 +02:00
parent e6ca6e52b7
commit 5bc01e79f3

View file

@ -23,21 +23,30 @@ func PNG(width, height int) (Renderer, error) {
return nil, err return nil, err
} }
// InMemory returns an in-memory raster renderer that calls cb() with the // InMemory returns an in-memory raster RenderProvider that calls cb() with the
// rendered image upon completion. // rendered image upon completion.
func InMemory(width, height int, cb func(image.Image)) (Renderer, error) { //
i := image.NewRGBA(image.Rect(0, 0, width, height)) // Usage suggestion:
gc, err := drawing.NewRasterGraphicContext(i) //
if err == nil { // ...
return &memRenderer{ // chart.Render(chart.InMemory(mycollector.SetImage))
rasterRenderer{ // ...
i: i, //
gc: gc, func InMemory(cb func(image.Image)) RendererProvider {
}, return func(width, height int) (Renderer, error) {
cb, i := image.NewRGBA(image.Rect(0, 0, width, height))
}, nil gc, err := drawing.NewRasterGraphicContext(i)
if err == nil {
return &memRenderer{
rasterRenderer{
i: i,
gc: gc,
},
cb,
}, nil
}
return nil, err
} }
return nil, err
} }
// rasterRenderer renders chart commands to a bitmap. // rasterRenderer renders chart commands to a bitmap.