From 5bc01e79f3c35d9472bfe233957bd41791107e79 Mon Sep 17 00:00:00 2001 From: Erik Bunn Date: Mon, 27 Jun 2022 15:15:13 +0200 Subject: [PATCH] fixes to InMemory setup --- raster_renderer.go | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/raster_renderer.go b/raster_renderer.go index 86c8e02..4fdc5b3 100644 --- a/raster_renderer.go +++ b/raster_renderer.go @@ -23,21 +23,30 @@ 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) { - i := image.NewRGBA(image.Rect(0, 0, width, height)) - gc, err := drawing.NewRasterGraphicContext(i) - if err == nil { - return &memRenderer{ - rasterRenderer{ - i: i, - gc: gc, - }, - cb, - }, nil +// +// 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 { + return &memRenderer{ + rasterRenderer{ + i: i, + gc: gc, + }, + cb, + }, nil + } + return nil, err } - return nil, err } // rasterRenderer renders chart commands to a bitmap.