Peter Stuifzand
2a0a582d7b
All checks were successful
continuous-integration/drone/push Build is passing
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
import {DataSet} from "vis-data/peer";
|
|
import {Network} from "vis-network/peer";
|
|
import $ from 'jquery';
|
|
|
|
function wikiGraph(selector, options) {
|
|
$(selector).each(function (i, el) {
|
|
let $el = $(el)
|
|
var nodeName = $el.data('name')
|
|
fetch('/api/graph?name=' + nodeName)
|
|
.then(res => res.json())
|
|
.then(graph => {
|
|
var nodes = new DataSet(graph.nodes)
|
|
var edges = new DataSet(graph.edges)
|
|
|
|
var data = {
|
|
nodes: nodes,
|
|
edges: edges
|
|
};
|
|
|
|
var options = {
|
|
edges: {
|
|
arrows: 'to',
|
|
color: {
|
|
highlight: 'green'
|
|
},
|
|
chosen: {
|
|
edge: function (values, id, selected, hovering) {
|
|
if (this.from === 1) {
|
|
values.color = 'blue';
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
nodes: {
|
|
shape: 'dot',
|
|
size: 15,
|
|
font: {
|
|
background: 'white'
|
|
}
|
|
},
|
|
layout: {
|
|
improvedLayout: true
|
|
}
|
|
};
|
|
|
|
var network = new Network(el, data, options);
|
|
network.on('doubleClick', function (props) {
|
|
if (props.nodes.length) {
|
|
let nodeId = props.nodes[0]
|
|
let node = nodes.get(nodeId)
|
|
// TODO: Reload directly in this same page
|
|
window.location.href = '/edit/' + node.label
|
|
}
|
|
})
|
|
})
|
|
})
|
|
}
|
|
|
|
export default wikiGraph
|