function graph(nodes) {
const graph = { sources: [], targets: [], costs: [] },
n = nodes.length,
delaunay = d3.Delaunay.from(nodes);
delaunay.halfedges.forEach((ei, ej) => {
if (ei > ej) {
const i = delaunay.triangles[ei],
j = delaunay.triangles[ej],
cost = distance(nodes[i], nodes[j]);
graph.sources.push(i);
graph.targets.push(j);
graph.costs.push(cost);
graph.sources.push(j);
graph.targets.push(i);
graph.costs.push(cost);
}
});
return graph;
}