From 9b31c619cc89f45286357eb6791005bc1d7621ae Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 21 Nov 2014 21:36:21 +0100 Subject: [PATCH] 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. --- server/graph.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 : -- 2.30.2