// test graphviz functions func TestGraph(t *testing.T) { gp.SetSeed(1) pset := initPset(true) exprs := testExprs(pset) t.Log(exprs[2], exprs[2].Format()) graph := exprs[2].Graph("test") t.Log(graph) data, err := gp.Layout(graph, "svg") if err != nil { t.Error(err) } t.Log(string(data)) }
// return handler to serve SVG graph of best individual via HTTP func (l *Logger) graphHandler() func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { if len(l.history) == 0 { http.NotFound(w, r) return } code := l.history[len(l.history)-1].Best.Code graph := code.Graph("best") data, err := gp.Layout(graph, "svg") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } send(w, r, data, "image/svg+xml") } }