2017-03-05 19:54:40 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2017-03-06 02:37:30 -05:00
|
|
|
_ "net/http/pprof"
|
|
|
|
|
2019-02-13 21:55:13 -05:00
|
|
|
chart "github.com/wcharczuk/go-chart"
|
2017-04-17 19:21:02 -04:00
|
|
|
"github.com/wcharczuk/go-chart/drawing"
|
2017-03-05 19:54:40 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
2017-04-17 19:21:02 -04:00
|
|
|
|
2017-04-19 18:27:31 -04:00
|
|
|
viridisByY := func(xr, yr chart.Range, index int, x, y float64) drawing.Color {
|
2017-04-17 19:21:02 -04:00
|
|
|
return chart.Viridis(y, yr.GetMin(), yr.GetMax())
|
|
|
|
}
|
|
|
|
|
2017-03-05 19:54:40 -05:00
|
|
|
graph := chart.Chart{
|
|
|
|
Series: []chart.Series{
|
|
|
|
chart.ContinuousSeries{
|
|
|
|
Style: chart.Style{
|
2017-04-14 20:43:52 -04:00
|
|
|
Show: true,
|
|
|
|
StrokeWidth: chart.Disabled,
|
2017-04-15 12:43:59 -04:00
|
|
|
DotWidth: 5,
|
2017-04-17 19:21:02 -04:00
|
|
|
DotColorProvider: viridisByY,
|
2017-03-05 19:54:40 -05:00
|
|
|
},
|
2019-02-13 21:55:13 -05:00
|
|
|
XValues: chart.SeqRange(0, 127),
|
|
|
|
YValues: chart.NewSeq(chart.NewSeqRandom().WithLen(128).WithMax(1024)).Values(),
|
2017-03-05 19:54:40 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-04-14 20:43:52 -04:00
|
|
|
res.Header().Set("Content-Type", chart.ContentTypePNG)
|
|
|
|
err := graph.Render(chart.PNG, res)
|
2017-03-05 19:54:40 -05: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{
|
2018-10-11 20:20:44 -04:00
|
|
|
Padding: chart.BoxZero,
|
2017-03-05 19:54:40 -05:00
|
|
|
},
|
|
|
|
Background: chart.Style{
|
2018-10-11 20:20:44 -04:00
|
|
|
Padding: chart.BoxZero,
|
2017-03-05 19:54:40 -05:00
|
|
|
},
|
|
|
|
Series: []chart.Series{
|
|
|
|
chart.ContinuousSeries{
|
2019-02-13 21:55:13 -05:00
|
|
|
XValues: chart.SeqRangeWithStep(0, 4, 1),
|
|
|
|
YValues: chart.SeqRangeWithStep(0, 4, 1),
|
2017-03-05 19:54:40 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-04-14 20:43:52 -04:00
|
|
|
res.Header().Set("Content-Type", chart.ContentTypePNG)
|
|
|
|
err := graph.Render(chart.PNG, res)
|
2017-03-05 19:54:40 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Println(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", drawChart)
|
|
|
|
http.HandleFunc("/unit", unit)
|
|
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
|
|
}
|