Code

graph: Use a date string for x-axis tick markers.
[sysdb/webui.git] / server / graph.go
index 054fe8eac4a18827b82bfe6c8f84519493d1f705..11b55b84fef483d16ff545bf50894444fdd58576 100644 (file)
@@ -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 :