From a502d29b8f9f943b1539f6f39c9a075157d39c3a Mon Sep 17 00:00:00 2001 From: Ivan Daniluk Date: Thu, 12 Jul 2018 12:31:15 +0200 Subject: [PATCH] Initial refactoring to use graphx --- main.go | 8 ++++---- ws.go | 4 ++-- ws_graph.go | 7 ++++--- ws_positions.go | 8 ++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 9991e36..08ba5ea 100644 --- a/main.go +++ b/main.go @@ -4,8 +4,8 @@ import ( "flag" "log" - "github.com/divan/graph-experiments/graph" - "github.com/divan/graph-experiments/layout" + "github.com/divan/graphx/formats" + "github.com/divan/graphx/layout" ) func main() { @@ -13,7 +13,7 @@ func main() { iterations := flag.Int("i", 600, "Graph layout iterations to run (0 = auto, buggy)") flag.Parse() - data, err := graph.NewGraphFromJSON("network.json") + data, err := formats.FromD3JSON("network.json") if err != nil { log.Fatal(err) } @@ -26,7 +26,7 @@ func main() { log.Printf("Loaded propagation data: %d timestamps\n", len(plog.Timestamps)) log.Printf("Initializing layout...") - repelling := layout.NewGravityForce(-100.0, layout.BarneHutMethod) + repelling := layout.NewGravityForce(-10.0, layout.BarneHutMethod) springs := layout.NewSpringForce(0.01, 5.0, layout.ForEachLink) drag := layout.NewDragForce(0.4, layout.ForEachNode) layout3D := layout.New(data, repelling, springs, drag) diff --git a/ws.go b/ws.go index a82fdaa..f416f75 100644 --- a/ws.go +++ b/ws.go @@ -5,8 +5,8 @@ import ( "log" "net/http" - "github.com/divan/graph-experiments/graph" - "github.com/divan/graph-experiments/layout" + "github.com/divan/graphx/graph" + "github.com/divan/graphx/layout" "github.com/gorilla/websocket" ) diff --git a/ws_graph.go b/ws_graph.go index 415856e..3c6de7c 100644 --- a/ws_graph.go +++ b/ws_graph.go @@ -5,14 +5,15 @@ import ( "encoding/json" "log" - "github.com/divan/graph-experiments/export" - "github.com/divan/graph-experiments/graph" + "github.com/divan/graphx/formats" + "github.com/divan/graphx/graph" "github.com/gorilla/websocket" ) func (ws *WSServer) sendGraphData(c *websocket.Conn) { var buf bytes.Buffer - err := export.NewJSON(&buf, false).ExportGraph(ws.graph) + d3json := formats.NewD3JSON(&buf, false) + err := d3json.ExportGraph(ws.graph) if err != nil { log.Fatal("Can't marshal graph to JSON") } diff --git a/ws_positions.go b/ws_positions.go index b764065..6611375 100644 --- a/ws_positions.go +++ b/ws_positions.go @@ -21,11 +21,11 @@ func (ws *WSServer) updatePositions() { // positions nodes := ws.layout.Nodes() positions := []*position{} - for i := 0; i < len(nodes); i++ { + for _, node := range nodes { pos := &position{ - X: nodes[i].X, - Y: nodes[i].Y, - Z: nodes[i].Z, + X: node.X, + Y: node.Y, + Z: node.Z, } positions = append(positions, pos) }