Skip to content

Commit

Permalink
Merge pull request tsenart#187 from tsenart/parameterise-title
Browse files Browse the repository at this point in the history
Parameterise plot title in NewPlotReporter
  • Loading branch information
tsenart committed May 25, 2016
2 parents 438b19f + 3af77ad commit dbb7ee1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/reporters.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ func NewJSONReporter(m *Metrics) Reporter {
// NewPlotReporter returns a Reporter that writes a self-contained
// HTML page with an interactive plot of the latencies of Requests, built with
// http://dygraphs.com/
func NewPlotReporter(rs *Results) Reporter {
func NewPlotReporter(title string, rs *Results) Reporter {
return func(w io.Writer) (err error) {
_, err = fmt.Fprintf(w, plotsTemplateHead, asset(dygraphs), asset(html2canvas))
_, err = fmt.Fprintf(w, plotsTemplateHead, title, asset(dygraphs), asset(html2canvas))
if err != nil {
return err
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func NewPlotReporter(rs *Results) Reporter {
buf = buf[:0]
}

_, err = w.Write([]byte(plotsTemplateTail))
_, err = fmt.Fprintf(w, plotsTemplateTail, title)
return err
}
}
Expand All @@ -149,7 +149,7 @@ const (
plotsTemplateHead = `<!doctype html>
<html>
<head>
<title>Vegeta Plots</title>
<title>%s</title>
</head>
<body>
<div id="latencies" style="font-family: Courier; width: 100%%; height: 600px"></div>
Expand All @@ -162,7 +162,7 @@ const (
[`
plotsTemplateTail = `],
{
title: 'Vegeta Plot',
title: '%s',
labels: ['Seconds', 'ERR', 'OK'],
ylabel: 'Latency (ms)',
xlabel: 'Seconds elapsed',
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func BenchmarkPlotReporter(b *testing.B) {
rs[i].Error = "Error"
}
}
rep := NewPlotReporter(&rs)
rep := NewPlotReporter("Vegeta Plot", &rs)
// Start benchmark
b.ReportAllocs()
b.StartTimer()
Expand Down
2 changes: 1 addition & 1 deletion report.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func report(reporter, inputs, output string) error {
rep, report = vegeta.NewJSONReporter(&m), &m
case "plot":
var rs vegeta.Results
rep, report = vegeta.NewPlotReporter(&rs), &rs
rep, report = vegeta.NewPlotReporter("Vegeta Plot", &rs), &rs
case "hist":
if len(reporter) < 6 {
return fmt.Errorf("bad buckets: '%s'", reporter[4:])
Expand Down

0 comments on commit dbb7ee1

Please sign in to comment.