From: Sebastian Harl Date: Fri, 21 Nov 2014 20:36:21 +0000 (+0100) Subject: graph: Use a date string for x-axis tick markers. X-Git-Url: https://git.tokkee.org/?p=sysdb%2Fwebui.git;a=commitdiff_plain;h=9b31c619cc89f45286357eb6791005bc1d7621ae graph: Use a date string for x-axis tick markers. This is a very basic implementation which is not well suited for all time ranges but it's good enough to get started. --- diff --git a/server/graph.go b/server/graph.go index 054fe8e..11b55b8 100644 --- a/server/graph.go +++ b/server/graph.go @@ -70,6 +70,7 @@ func (s *Server) graph(w http.ResponseWriter, req request) { return } p.Add(plotter.NewGrid()) + p.X.Tick.Marker = dateTicks var i int for name, data := range ts.Data { @@ -102,4 +103,18 @@ func (s *Server) graph(w http.ResponseWriter, req request) { io.Copy(w, &buf) } +func dateTicks(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) + for i, t := range ticks { + if t.Label == "" { + // Skip minor ticks. + continue + } + ticks[i].Label = time.Unix(0, int64(t.Value)).Format(time.RFC822) + } + return ticks +} + // vim: set tw=78 sw=4 sw=4 noexpandtab :