{
const buttons = d3.select(viewof buttons);
buttons.select('input[name=add]').on('click', addNode)
buttons.select('input[name=remove]').on('click', removeNode)
function removeNode() {
let { nodes, links } = Graph.graphData();
if (nodes.length == 1) return;
const node = nodes[nodes.length - 1];
links = links.filter(l => l.source !== node && l.target !== node);
nodes.splice(node.id, 1);
nodes.forEach((n, idx) => { n.id = idx; });
Graph.graphData({ nodes, links });
}
function addNode() {
const { nodes, links } = Graph.graphData();
const id = nodes.length;
Graph.graphData({
nodes: [...nodes, { id }],
links: [...links, { source: id, target: Math.round(Math.random() * (id-1)) }]
});
}
return Graph.graphData().nodes
}