~humaid/ns2-trace-go

c8c9b1d3d1320be8f65d9b7da5e4ed45e6db34a7 — Humaid AlQassimi 1 year, 9 months ago d864755
Graphs: Fixed go-chart version in Go Mod, and allow selection of zoomed or full view for jitter
5 files changed, 29 insertions(+), 8 deletions(-)

M go.mod
M go.sum
M main.go
M templates/analysis.tmpl
M templates/jitter.tmpl
M go.mod => go.mod +1 -1
@@ 6,7 6,7 @@ require (
	github.com/blend/go-sdk v2.0.0+incompatible // indirect
	github.com/go-macaron/binding v1.0.1
	github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
	github.com/wcharczuk/go-chart v2.0.1+incompatible
	github.com/wcharczuk/go-chart v2.0.2-0.20190910040548-3a7bc5543113+incompatible
	golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect
	gopkg.in/macaron.v1 v1.3.4
)

M go.sum => go.sum +2 -0
@@ 24,6 24,8 @@ github.com/unknwon/com v0.0.0-20190804042917-757f69c95f3e h1:GSGeB9EAKY2spCABz6x
github.com/unknwon/com v0.0.0-20190804042917-757f69c95f3e/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnlCXM=
github.com/wcharczuk/go-chart v2.0.1+incompatible h1:0pz39ZAycJFF7ju/1mepnk26RLVLBCWz1STcD3doU0A=
github.com/wcharczuk/go-chart v2.0.1+incompatible/go.mod h1:PF5tmL4EIx/7Wf+hEkpCqYi5He4u90sw+0+6FhrryuE=
github.com/wcharczuk/go-chart v2.0.2-0.20190910040548-3a7bc5543113+incompatible h1:Bz/7IMIv+MmCANT7drP8zyxHH5xHC0/+smWpcJCCk4M=
github.com/wcharczuk/go-chart v2.0.2-0.20190910040548-3a7bc5543113+incompatible/go.mod h1:PF5tmL4EIx/7Wf+hEkpCqYi5He4u90sw+0+6FhrryuE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=

M main.go => main.go +16 -5
@@ 6,6 6,7 @@ import (
	"fmt"
	"github.com/go-macaron/binding"
	chart "github.com/wcharczuk/go-chart"
	"github.com/wcharczuk/go-chart/drawing"
	"gopkg.in/macaron.v1"
	"html/template"
	"log"


@@ 80,7 81,7 @@ func main() {
			ctx.Data["Analysis"] = analysis
			ctx.HTML(200, "analysis")
		})
		m.Get("/:from/:to/:type", func(ctx *macaron.Context) {
		m.Get("/:from/:to/:type/:zoom", func(ctx *macaron.Context) {
			analysis, ok := Analysises[ctx.Params("id")]
			if !ok {
				ctx.PlainText(404, []byte("Analysis results does not exist"))


@@ 129,19 130,29 @@ func main() {
			//fmt.Println(jitterValues)

			graph := chart.Chart{
				XAxis: chart.XAxis{
					Name: "Sequence",
				},
				YAxis: chart.YAxis{
					Range: &chart.ContinuousRange{
						Min: -0.5,
						Max: 0.5,
					},
					Name: "Jitter",
				},
				Series: []chart.Series{
					chart.ContinuousSeries{
						Style: chart.Style{
							StrokeColor: drawing.ColorRed,
						},
						XValues: seqValues,
						YValues: jitterValues,
					},
				},
			}
			if ctx.Params("zoom") == "zoom" {
				graph.YAxis.Range = &chart.ContinuousRange{
					Min: -0.5,
					Max: 0.5,
				}
				ctx.Data["IsZoom"] = true
			}

			var imgBuf bytes.Buffer
			err = graph.Render(chart.SVG, &imgBuf)

M templates/analysis.tmpl => templates/analysis.tmpl +1 -1
@@ 24,7 24,7 @@
<td>{{$jitter.ToNode}}</td>
<td>{{$jitter.PacketType}}</td>
<td><a class="btn"
href="{{$.ID}}/{{$jitter.FromNode}}/{{$jitter.ToNode}}/{{$jitter.PacketType}}">View
href="{{$.ID}}/{{$jitter.FromNode}}/{{$jitter.ToNode}}/{{$jitter.PacketType}}/zoom">View
jitter</a></td>
</tr>
	{{end}}

M templates/jitter.tmpl => templates/jitter.tmpl +9 -1
@@ 1,10 1,18 @@
{{ template "base/head" .}}
<div class="container">
	<h1 class="title">NS2 Trace File Analysis Result ({{.Analysis.Title}})</h1>
	<h1 class="title">NS2 Trace File Analysis Result</h1>
	<h2 class="title">Jitter graph for {{.Stat.FromNode}}->{{.Stat.ToNode}}
	({{.Stat.PacketType}})</h2>
	<p><a class="btn" href="/{{.ID}}">&#9664; Go back</a></p>
	{{.Graph}}
	<br>
	{{ if .IsZoom}}
	<p><i>This is a zoomed-in view of the graph. <a href="full">Switch to full
	view</a>.</i></p>{{else}}
	<p><i>This is a full view of the graph. <a href="zoom">Switch to zoomed
	view</a>.</i></p>{{end}}
	<br>
	<br>

</div>
{{ template "base/footer" .}}