chart = {
const links = data.links.map(d => Object.create(d));
let nodes = data.nodes.map(d => Object.create(d));
console.log(links)
const simulation = d3.forceSimulation(nodes)
.force("link", d3.forceLink(links).id(d => d.id).distance(d => dist/d.value))
.force("charge", d3.forceManyBody())
.velocityDecay(.5)
.force("center", d3.forceCenter(width / 2, height / 2))
.on("tick", ticked);
const svg = d3.select(DOM.svg(width, height));
const party = {
"-": "#d2dcdc",
"v": "#911414",
"s": "#e03141",
"mp": "#82c782",
"c": "#31a431",
"fp": "#1e69aa",
"m": "#7cbde0",
"kd": "#00006d",
"sd": "#ffc346",
"fi": "#b2367e",
"ovr": "#8c8c8c",
}
const link = svg.append("g")
.attr("stroke", "#999")
.attr("stroke-opacity", 0.6)
.selectAll("line")
.data(links)
.enter().append("line")
.attr("stroke-width", d => d.value*10);
const node = svg.append("g")
.attr("stroke", "#fff")
.attr("stroke-width", 1.5)
.selectAll("circle")
.data(nodes)
.enter().append("circle")
.attr("r", radius)
.attr("fill", d => party[d.id])
.call(drag(simulation));
const text = svg.append("g")
.attr("stroke", "#fff")
.attr("stroke-width", 1.5)
.selectAll("text")
.data(nodes)
.enter().append("text")
.text(d => d.id)
.attr("text-anchor", "middle")
.attr("alignment-baseline", "central")
.attr("dominant-baseline", "central ")
.attr("fill", d => party[d.id])
.call(drag(simulation));
node.append("title")
.text(d => d.id);
function ticked() {
link
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y);
node
.attr("cx", d => d.x)
.attr("cy", d => d.y);
text
.attr("x", d => d.x)
.attr("y", d => d.y)
}
return svg.node();
}