From ce5b36a6cb4ea4fdcae29b197c4609d7e189c3af Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Sat, 27 Aug 2016 14:23:55 -0700 Subject: [PATCH] image collector. --- _examples/image_writer/main.go | 27 +++++++++++++++++++++++++++ raster_renderer.go | 4 ++++ 2 files changed, 31 insertions(+) create mode 100644 _examples/image_writer/main.go diff --git a/_examples/image_writer/main.go b/_examples/image_writer/main.go new file mode 100644 index 0000000..13bf013 --- /dev/null +++ b/_examples/image_writer/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "log" + + "github.com/wcharczuk/go-chart" +) + +func main() { + graph := chart.Chart{ + Series: []chart.Series{ + chart.ContinuousSeries{ + XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, + YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, + }, + }, + } + collector := &chart.ImageWriter{} + graph.Render(chart.PNG, collector) + + image, err := collector.Image() + if err != nil { + log.Fatal(err) + } + fmt.Printf("Final Image: %dx%d\n", image.Bounds().Size().X, image.Bounds().Size().Y) +} diff --git a/raster_renderer.go b/raster_renderer.go index 3b9fa4d..1b0cf96 100644 --- a/raster_renderer.go +++ b/raster_renderer.go @@ -210,5 +210,9 @@ func (rr *rasterRenderer) ClearTextRotation() { // Save implements the interface method. func (rr *rasterRenderer) Save(w io.Writer) error { + if typed, isTyped := w.(RGBACollector); isTyped { + typed.SetRGBA(rr.i) + return nil + } return png.Encode(w, rr.i) }