whispervis/main.go

45 lines
975 B
Go
Raw Normal View History

2018-07-04 16:56:18 +00:00
package main
import (
"flag"
"log"
2018-07-12 10:31:15 +00:00
"github.com/divan/graphx/formats"
"github.com/divan/graphx/layout"
2018-07-04 16:56:18 +00:00
)
func main() {
2018-07-04 19:57:57 +00:00
bind := flag.String("bind", ":20002", "Port to bind to")
2018-07-04 16:56:18 +00:00
iterations := flag.Int("i", 600, "Graph layout iterations to run (0 = auto, buggy)")
flag.Parse()
2018-07-12 10:31:15 +00:00
data, err := formats.FromD3JSON("network.json")
2018-07-04 16:56:18 +00:00
if err != nil {
log.Fatal(err)
}
log.Printf("Loaded graph: %d nodes, %d links\n", len(data.Nodes()), len(data.Links()))
plog, err := LoadPropagationData("propagation.json")
if err != nil {
log.Fatal(err)
}
log.Printf("Loaded propagation data: %d timestamps\n", len(plog.Timestamps))
log.Printf("Initializing layout...")
2018-07-13 15:13:19 +00:00
l := layout.NewAuto(data)
2018-07-04 16:56:18 +00:00
2018-07-12 23:23:07 +00:00
ws := NewWSServer(l)
2018-07-04 16:56:18 +00:00
if *iterations == 0 {
ws.layout.Calculate()
} else {
ws.layout.CalculateN(*iterations)
}
2018-07-12 23:23:07 +00:00
ws.updatePositions()
2018-07-04 16:56:18 +00:00
ws.updateGraph(data)
ws.updatePropagationData(plog)
2018-07-04 19:57:57 +00:00
log.Printf("Starting web server on %s...", *bind)
startWeb(ws, *bind)
2018-07-04 16:56:18 +00:00
select {}
}