1
0
Fork 0
mirror of https://github.com/Findus23/RPGnotes.git synced 2024-09-20 16:53:44 +02:00
RPGnotes/static/js/graph.ts

45 lines
782 B
TypeScript
Raw Normal View History

2022-11-19 22:09:15 +01:00
import Sigma from "sigma";
2022-11-25 20:20:14 +01:00
import FA2Layout from 'graphology-layout-forceatlas2/worker';
2022-11-19 22:09:15 +01:00
import Graph from "graphology";
import random from 'graphology-layout/random';
2022-11-25 20:20:14 +01:00
const container = document.getElementById("graph")!
const graph = new Graph({
type: "directed",
});
fetch('/graph/graph')
.then((response) => response.json())
.then((data) => {
console.log(data)
graph.import(data)
random.assign(graph);
2022-11-19 22:09:15 +01:00
});
2022-11-20 00:25:04 +01:00
2022-11-25 20:20:14 +01:00
const layout = new FA2Layout(graph, {
settings: {
gravity: 0.2
}
});
layout.start();
const renderer = new Sigma(graph, container, {
labelSize: 20,
edgeLabelSize: 200,
});
renderer.on("clickNode", (e) => {
const url = graph.getNodeAttribute(e.node, "url")
window.open(url, 'graphURL')
2022-11-20 00:25:04 +01:00
2022-11-25 20:20:14 +01:00
})
2022-11-19 22:09:15 +01:00