2018-07-04 18:56:18 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
|
2018-07-12 12:31:15 +02:00
|
|
|
"github.com/divan/graphx/formats"
|
|
|
|
"github.com/divan/graphx/layout"
|
2018-07-04 18:56:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2018-07-04 21:57:57 +02:00
|
|
|
bind := flag.String("bind", ":20002", "Port to bind to")
|
2018-09-05 16:49:11 +03:00
|
|
|
iterations := flag.Int("i", 200, "Graph layout iterations to run (0 = auto, buggy)")
|
2018-07-04 18:56:18 +02:00
|
|
|
flag.Parse()
|
|
|
|
|
2018-07-12 12:31:15 +02:00
|
|
|
data, err := formats.FromD3JSON("network.json")
|
2018-07-04 18:56:18 +02: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-09-05 16:49:11 +03:00
|
|
|
//l := layout.NewAuto(data)
|
|
|
|
|
|
|
|
repelling := layout.NewGravityForce(-50.0, layout.BarneHutMethod)
|
|
|
|
springs := layout.NewSpringForce(0.02, 5, layout.ForEachLink)
|
|
|
|
drag := layout.NewDragForce(0.4, layout.ForEachNode)
|
|
|
|
|
|
|
|
l := layout.New(data, repelling, springs, drag)
|
2018-07-04 18:56:18 +02:00
|
|
|
|
2018-07-13 01:23:07 +02:00
|
|
|
ws := NewWSServer(l)
|
2018-07-04 18:56:18 +02:00
|
|
|
if *iterations == 0 {
|
|
|
|
ws.layout.Calculate()
|
|
|
|
} else {
|
|
|
|
ws.layout.CalculateN(*iterations)
|
|
|
|
}
|
2018-07-13 01:23:07 +02:00
|
|
|
ws.updatePositions()
|
2018-07-04 18:56:18 +02:00
|
|
|
ws.updateGraph(data)
|
|
|
|
ws.updatePropagationData(plog)
|
|
|
|
|
2018-07-04 21:57:57 +02:00
|
|
|
log.Printf("Starting web server on %s...", *bind)
|
|
|
|
startWeb(ws, *bind)
|
2018-07-04 18:56:18 +02:00
|
|
|
select {}
|
|
|
|
}
|