mirror of
https://github.com/status-im/clusterviz.git
synced 2025-02-23 18:28:16 +00:00
40 lines
770 B
Go
40 lines
770 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"log"
|
|
|
|
"github.com/divan/graph-experiments/export"
|
|
"github.com/divan/graph-experiments/graph"
|
|
"github.com/divan/graph-experiments/layout"
|
|
"github.com/gorilla/websocket"
|
|
)
|
|
|
|
func (ws *WSServer) sendGraphData(c *websocket.Conn) {
|
|
var buf bytes.Buffer
|
|
err := export.NewJSON(&buf, false).ExportGraph(ws.graph)
|
|
if err != nil {
|
|
log.Fatal("Can't marshal graph to JSON")
|
|
}
|
|
msg := &WSResponse{
|
|
Type: RespGraph,
|
|
Graph: json.RawMessage(buf.Bytes()),
|
|
}
|
|
|
|
ws.sendMsg(c, msg)
|
|
}
|
|
|
|
func (ws *WSServer) updateGraph(g *graph.Graph, l layout.Layout) {
|
|
ws.graph = g
|
|
ws.layout = l
|
|
|
|
ws.broadcastGraphData()
|
|
}
|
|
|
|
func (ws *WSServer) broadcastGraphData() {
|
|
for i := 0; i < len(ws.hub); i++ {
|
|
ws.sendGraphData(ws.hub[i])
|
|
}
|
|
}
|