allDistances = {
let nodes = data[r1]
worldMap.select("#piecharts").remove()
worldMap.select("#land")
let adjSize = size *2;
if (dorling) {
const simulation = d3
.forceSimulation(nodes)
.force(
"x",
d3.forceX((d) => mapProjection([parseFloat(d[baseX]), parseFloat(d[baseY])])[0])
)
.force(
"y",
d3.forceY((d) => mapProjection([parseFloat(d[baseX]), parseFloat(d[baseY])])[1])
)
.force(
"collide",
d3.forceCollide(size+2).strength(repulsionFactor)
)
const nodeG = worldMap.append("g")
.attr("id", "piecharts")
.attr("stroke", "white")
.attr("stroke-width", 0.5)
.selectAll("g")
.data(nodes)
.join("g")
.call(drag(simulation))
nodeG.append("g")
.each(function(node) {
d3.select(this).append('g')
.append("rect")
.attr("stroke-width", 0.15)
.attr("stroke", "#8F5601")
.attr('fill', '#FFFCF6')
.attr("width", adjSize)
// .attr('x', -size)
// .attr('y', -size)
.attr("height", adjSize);
let linePoints = [{year: 2019, val: node[x]}, {year: 2050, val: node[y]}];
//let color = node[y] > node[x] ? 'green' : 'red';
// let color = colorScale(node['ad_press_eq']);
d3.select(this).append('path')
.datum(linePoints)
.attr("stroke", colorScale(node[colorVal]))
.attr("stroke-width", stroke)
.attr("stroke-opacity", 1)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("d", line);
})
simulation.on("tick", () => {
nodeG.attr("transform", d => `translate(${d.x}, ${d.y})`)
textG.attr("transform", d => `translate(${d.x}, ${d.y})`)
});
invalidation.then(() => simulation.stop());
const textG = worldMap.append("g")
.attr("id", "text-charts")
.selectAll("g")
.data(nodes)
.join("g")
.call(drag(simulation))
textG.append('g')
.attr('id', 'city-names')
.each(function(node) {
if (callouts.includes(node.city)) {
d3.select(this)
.append('text')
.text(node.city)
.attr('font-size', 6)
.attr('font-family', 'IBM Plex Sans')
.attr('stroke', 'none');
}
})
} else {
// Finalized unforced code
nodes.forEach(node => {
let coordinates = mapProjection([parseFloat(node[baseX]),parseFloat(node[baseY])]);
let x = coordinates[0];
let y = coordinates[1];
// let pieData = [];
// for (let i in categories[basePie]) {
// let name = categories[basePie][i]
// let value = parseFloat(node[name])
// pieData.push({name, value});
// }
// let arcs = pie(pieData);
// worldMap
// .append('g')
// .attr("id", "piecharts")
// .attr("transform", "translate(" + x + "," + y + ")")
// //.attr('stroke', pieStroke ? "white" : "none")
// .selectAll('path')
// .data(arcs)
// .join('path')
// .attr('fill',
// d => {
// return sectorColor(d.data.name)})
// .attr(
// 'd',
// d3
// .arc()
// .innerRadius(0)
// .outerRadius(() => radiusFunction(parseInt(node[radiusBase]))))
// .append('title')
// // title will not actually be visible
// .text(d => `${d.data.name}: ${d.data.value}`);
});
}
return worldMap.node();
}