2017-03-06 01:54:40 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2017-03-06 08:37:30 +01:00
|
|
|
_ "net/http/pprof"
|
|
|
|
|
2017-03-06 01:54:40 +01:00
|
|
|
"github.com/wcharczuk/go-chart"
|
2017-04-18 01:21:02 +02:00
|
|
|
"github.com/wcharczuk/go-chart/drawing"
|
2017-03-06 01:54:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
2017-04-18 01:21:02 +02:00
|
|
|
|
|
|
|
viridisByY := func(xr, yr chart.Range, x, y float64) drawing.Color {
|
|
|
|
return chart.Viridis(y, yr.GetMin(), yr.GetMax())
|
|
|
|
}
|
|
|
|
|
2017-03-06 01:54:40 +01:00
|
|
|
graph := chart.Chart{
|
|
|
|
Series: []chart.Series{
|
|
|
|
chart.ContinuousSeries{
|
|
|
|
Style: chart.Style{
|
2017-04-15 02:43:52 +02:00
|
|
|
Show: true,
|
|
|
|
StrokeWidth: chart.Disabled,
|
2017-04-15 18:43:59 +02:00
|
|
|
DotWidth: 5,
|
2017-04-18 01:21:02 +02:00
|
|
|
DotColorProvider: viridisByY,
|
2017-03-06 01:54:40 +01:00
|
|
|
},
|
2017-04-15 02:43:52 +02:00
|
|
|
XValues: chart.Sequence.Random(128, 1024),
|
|
|
|
YValues: chart.Sequence.Random(128, 1024),
|
2017-03-06 01:54:40 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-04-15 02:43:52 +02:00
|
|
|
res.Header().Set("Content-Type", chart.ContentTypePNG)
|
|
|
|
err := graph.Render(chart.PNG, res)
|
2017-03-06 01:54:40 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Println(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func unit(res http.ResponseWriter, req *http.Request) {
|
|
|
|
graph := chart.Chart{
|
|
|
|
Height: 50,
|
|
|
|
Width: 50,
|
|
|
|
Canvas: chart.Style{
|
|
|
|
Padding: chart.Box{IsSet: true},
|
|
|
|
},
|
|
|
|
Background: chart.Style{
|
|
|
|
Padding: chart.Box{IsSet: true},
|
|
|
|
},
|
|
|
|
Series: []chart.Series{
|
|
|
|
chart.ContinuousSeries{
|
|
|
|
XValues: chart.Sequence.Float64(0, 4, 1),
|
|
|
|
YValues: chart.Sequence.Float64(0, 4, 1),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-04-15 02:43:52 +02:00
|
|
|
res.Header().Set("Content-Type", chart.ContentTypePNG)
|
|
|
|
err := graph.Render(chart.PNG, res)
|
2017-03-06 01:54:40 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Println(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", drawChart)
|
|
|
|
http.HandleFunc("/unit", unit)
|
|
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
|
|
}
|