Simple graph package for go. Uses d3.js for visualization and websockets for communication.
Gopher image by [Renee French][rf], licensed under [Creative Commons 3.0 Attributions license][cc3-by].
IMPORTANT – This repo is under active developement and should not be used in production until we acheive v1.0.0 Our initial release is 0.1.0 which is unstable at best. https://semver.org/
This package is a fork from “github.com/fjukstad/gographer”
We fixed various websocket issues. The default is golang’s standard lib for websockets. Also all relavant methods have been consolidated into one file. Once it hits v 1.0 consider it stable and production ready. Our goal is to use this repo to build out a richer set of visualazions based on d3js and then produce a scalable graph db using go.
package main
import (
"fmt"
"github.com/raymondbernard/go-grapher/gographer"
"net/http"
"os"
)
func main() {
// make sure you set you export your gopath!
gopath := os.Getenv("GOPATH")
rootServeDir := gopath + "/pkg/mod/github.com/raymondbernard/go-grapher@v0.1.0/root_serve_dir/"
// make sure the rootServerDir exsists!
// If not, at your command pront in your root > go get github.com/raymondbernard/go-grapher
fmt.Println(rootServeDir)
// init graph
graph := gographer.NewG()
// Create graph nodes
// (ID, NodeText, GroupID, Size)
graph.AddNode(1, "Node Text blah", 1234, 1)
graph.AddNode(2, "Node Text blah 2", 1234, 1)
// Create graph relationships with edges
// (Source, Target, EdgeID, weight)
graph.AddEdge(1, 2, 0, 1)
graph.AddEdge(2, 1, 100, 15)
// graph.json represent the graph you created
graph.DumpJSON("graph.json")
// server up graph on port 8080
http.ListenAndServe(":8080", http.FileServer(http.Dir(".")))
}
go mod init
go mod tidy
Open [localhost:8080](http://localhost:8080) in a webbrowser to view the graph.
Modify the d3js implementation and visualization to your preferences.
All files for our pkgs are kept below
gopath + "/pkg/mod/github.com/raymondbernard/go-grapher@v0.1.0/"
go run
Make sure you are not already runing a process on port 8080 or 3999 (this one is reserved for our websocket communications)
Then visit localhost:8080 in your browser :)
This file is autogenerated when you run your program