set_others_view_smooth_2 = (nodes, new_nodes, g, width) => {
const xDomain = d3.extent([].concat(nodes, new_nodes), (node) => node.distance);
const xDomainLength = xDomain[1] - xDomain[0] + 0.01;
const xBinLength = Math.floor(width / (R * 2));
const histogram = [];
for (let i = 0; i < xBinLength; i++) histogram.push([]);
nodes.forEach((node) => {
node.binX = Math.floor(
((node.distance - xDomain[0]) / xDomainLength) * xBinLength
);
node.binY = histogram[node.binX].length;
histogram[node.binX].push(node);
});
const new_histogram = [];
for (let i = 0; i < xBinLength; i++) new_histogram.push([]);
new_nodes.forEach((node) => {
node.binX = Math.floor(
((node.distance - xDomain[0]) / xDomainLength) * xBinLength
);
node.binY = new_histogram[node.binX].length;
new_histogram[node.binX].push(node);
});
smoothHistogram(histogram);
smoothHistogram(histogram);
smoothHistogram(new_histogram);
smoothHistogram(new_histogram);
histogram.forEach((row) => row.sort((a, b) => -a.type + b.type));
const id2bin_pos = {};
histogram.forEach((row, x) => {
row.forEach(({ id }, y) => (id2bin_pos[id] = { x, y }));
});
new_histogram.forEach((row, x) => {
row.forEach(({ id }, y) => (id2bin_pos[id] = { x, y }));
});
const nodes_g = g
.append("g")
.selectAll("g")
.data(nodes)
.join("g")
.attr("transform", (node) => {
return `translate(${(2 * id2bin_pos[node.id].x + 1) * R}, ${
height / 2 - (2 * id2bin_pos[node.id].y + 1) * R
})`;
});
const new_nodes_g = g
.append("g")
.selectAll("g")
.data(new_nodes)
.join("g")
.attr("transform", (node) => {
return `translate(${(2 * id2bin_pos[node.id].x + 1) * R}, ${
height / 2 + (2 * id2bin_pos[node.id].y + 1) * R
})`;
});
nodes_g
.append("circle")
.attr("r", r)
.attr("fill", (node) => colors[node.type])
new_nodes_g
.append("circle")
.attr("r", r)
.attr("fill", colors[2]);
}