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,9 +23,17 @@ func PNG(width, height int) (Renderer, error) {
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.
func InMemory(width, height int, cb func(image.Image)) (Renderer, error) {
//
// Usage suggestion:
//
// ...
// chart.Render(chart.InMemory(mycollector.SetImage))
// ...
//
func InMemory(cb func(image.Image)) RendererProvider {
return func(width, height int) (Renderer, error) {
i := image.NewRGBA(image.Rect(0, 0, width, height))
gc, err := drawing.NewRasterGraphicContext(i)
if err == nil {
@ -38,6 +46,7 @@ func InMemory(width, height int, cb func(image.Image)) (Renderer, error) {
}, nil
}
return nil, err
}
}
// rasterRenderer renders chart commands to a bitmap.