From 8c86d8c04f668592ed072ec1cef5d0adff24aa43 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sat, 25 Apr 2015 14:34:31 +0200 Subject: [PATCH] Migrate to github.com/gonum/plot. This is the new, official fork of code.google.com/p/plotinum. --- server/graph.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/server/graph.go b/server/graph.go index 5134ed6..11254d6 100644 --- a/server/graph.go +++ b/server/graph.go @@ -35,11 +35,10 @@ import ( "net/http" "time" - "code.google.com/p/plotinum/plot" - "code.google.com/p/plotinum/plotter" - "code.google.com/p/plotinum/plotutil" - "code.google.com/p/plotinum/vg" - "code.google.com/p/plotinum/vg/vgsvg" + "github.com/gonum/plot" + "github.com/gonum/plot/plotter" + "github.com/gonum/plot/plotutil" + "github.com/gonum/plot/vg" "github.com/sysdb/go/sysdb" ) @@ -89,7 +88,7 @@ func (s *Server) graph(w http.ResponseWriter, req request) { return } p.Add(plotter.NewGrid()) - p.X.Tick.Marker = dateTicks + p.X.Tick.Marker = dateTicks{} var i int for name, data := range ts.Data { @@ -109,11 +108,14 @@ func (s *Server) graph(w http.ResponseWriter, req request) { i++ } - c := vgsvg.New(vg.Length(500), vg.Length(200)) - p.Draw(plot.MakeDrawArea(c)) + pw, err := p.WriterTo(vg.Length(500), vg.Length(200), "svg") + if err != nil { + s.internal(w, fmt.Errorf("Failed to write plot: %v", err)) + return + } var buf bytes.Buffer - if _, err := c.WriteTo(&buf); err != nil { + if _, err := pw.WriteTo(&buf); err != nil { s.internal(w, fmt.Errorf("Failed to write plot: %v", err)) return } @@ -122,10 +124,12 @@ func (s *Server) graph(w http.ResponseWriter, req request) { io.Copy(w, &buf) } -func dateTicks(min, max float64) []plot.Tick { +type dateTicks struct{} + +func (dateTicks) Ticks(min, max float64) []plot.Tick { // TODO: this is surely not the best we can do // but it'll distribute ticks evenly. - ticks := plot.DefaultTicks(min, max) + ticks := plot.DefaultTicks{}.Ticks(min, max) for i, t := range ticks { if t.Label == "" { // Skip minor ticks. -- 2.30.2