graph = {
const svg = d3.create('svg')
.attr("width", vWidth)
.attr("height", vHeight)
.attr("viewBox", [0, 0, vWidth, vHeight])
const delaunay = new d3.Delaunay(points)
const voronoi = delaunay.voronoi([0, 0, vWidth, vHeight])
svg.append('path')
.attr('fill', 'lightblue')
.attr('d', voronoi.renderCell(debugCellA))
svg.append('path')
.attr('fill', 'yellow')
.attr('d', voronoi.renderCell(debugCellB))
const divisions = svg.append('path')
.attr('stroke', 'gray')
.attr('stroke-width', '2')
.attr('d', voronoi.render())
const vorNeighbors = []
const notVorNeighbors = []
for (let i = 0; i< points.length/2; i++){
const vNeighbors = [...voronoi.neighbors(i)]
for (let neighbor of delaunay.neighbors(i)){
if (vNeighbors.indexOf(neighbor) < 0){
notVorNeighbors.push({
source: i,
target: neighbor
})
}else{
vorNeighbors.push({
source: i,
target: neighbor
})
}
}
}
const notVorLinks = svg.append('g')
.selectAll('line')
.data(notVorNeighbors)
.join('line')
.attr('stroke', 'red')
.attr('x1', d=>delaunay.points[d.source*2])
.attr('y1', d=>delaunay.points[d.source*2+1])
.attr('x2', d=>delaunay.points[d.target*2])
.attr('y2', d=>delaunay.points[d.target*2+1])
const vorLinks = svg.append('g')
.selectAll('line')
.data(vorNeighbors)
.join('line')
.attr('stroke', 'green')
.attr('x1', d=>delaunay.points[d.source*2])
.attr('y1', d=>delaunay.points[d.source*2+1])
.attr('x2', d=>delaunay.points[d.target*2])
.attr('y2', d=>delaunay.points[d.target*2+1])
const dots = svg.append('path')
.attr('d', delaunay.renderPoints())
const texts = svg.append('g')
for (let i = 0; i< points.length/2; i++){
texts.append('text')
.attr('x', delaunay.points[i*2]+5)
.attr('y', delaunay.points[i*2+1])
.text(i)
}
return {
node: svg.node(),
delaunay,
voronoi,
}
}