mirror of
https://github.com/status-im/whispervis.git
synced 2025-02-02 16:33:56 +00:00
Initial refactoring to use graphx
This commit is contained in:
parent
9ee56d0720
commit
a502d29b8f
8
main.go
8
main.go
@ -4,8 +4,8 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/divan/graph-experiments/graph"
|
"github.com/divan/graphx/formats"
|
||||||
"github.com/divan/graph-experiments/layout"
|
"github.com/divan/graphx/layout"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -13,7 +13,7 @@ func main() {
|
|||||||
iterations := flag.Int("i", 600, "Graph layout iterations to run (0 = auto, buggy)")
|
iterations := flag.Int("i", 600, "Graph layout iterations to run (0 = auto, buggy)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
data, err := graph.NewGraphFromJSON("network.json")
|
data, err := formats.FromD3JSON("network.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ func main() {
|
|||||||
log.Printf("Loaded propagation data: %d timestamps\n", len(plog.Timestamps))
|
log.Printf("Loaded propagation data: %d timestamps\n", len(plog.Timestamps))
|
||||||
|
|
||||||
log.Printf("Initializing layout...")
|
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)
|
springs := layout.NewSpringForce(0.01, 5.0, layout.ForEachLink)
|
||||||
drag := layout.NewDragForce(0.4, layout.ForEachNode)
|
drag := layout.NewDragForce(0.4, layout.ForEachNode)
|
||||||
layout3D := layout.New(data, repelling, springs, drag)
|
layout3D := layout.New(data, repelling, springs, drag)
|
||||||
|
4
ws.go
4
ws.go
@ -5,8 +5,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/divan/graph-experiments/graph"
|
"github.com/divan/graphx/graph"
|
||||||
"github.com/divan/graph-experiments/layout"
|
"github.com/divan/graphx/layout"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -5,14 +5,15 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/divan/graph-experiments/export"
|
"github.com/divan/graphx/formats"
|
||||||
"github.com/divan/graph-experiments/graph"
|
"github.com/divan/graphx/graph"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ws *WSServer) sendGraphData(c *websocket.Conn) {
|
func (ws *WSServer) sendGraphData(c *websocket.Conn) {
|
||||||
var buf bytes.Buffer
|
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 {
|
if err != nil {
|
||||||
log.Fatal("Can't marshal graph to JSON")
|
log.Fatal("Can't marshal graph to JSON")
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,11 @@ func (ws *WSServer) updatePositions() {
|
|||||||
// positions
|
// positions
|
||||||
nodes := ws.layout.Nodes()
|
nodes := ws.layout.Nodes()
|
||||||
positions := []*position{}
|
positions := []*position{}
|
||||||
for i := 0; i < len(nodes); i++ {
|
for _, node := range nodes {
|
||||||
pos := &position{
|
pos := &position{
|
||||||
X: nodes[i].X,
|
X: node.X,
|
||||||
Y: nodes[i].Y,
|
Y: node.Y,
|
||||||
Z: nodes[i].Z,
|
Z: node.Z,
|
||||||
}
|
}
|
||||||
positions = append(positions, pos)
|
positions = append(positions, pos)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user