graph = {
const _graph = datasets[selectedDataset];
var degrees = {}
_graph.edges.forEach((e) => {
const { source, target } = e;
degrees[source] = (degrees[source] || 0) + 1
degrees[target] = (degrees[target] || 0) + 1
})
_graph.nodes.forEach((n) => {
const attributes = n.attributes;
const t = new Set();
const classes = [];
let classes_sorted = JSON.parse(JSON.stringify(classes));
classes_sorted = classes_sorted.sort();
attributes.classes_sorted = classes_sorted;
const modeValue = d3.mode(classes);
const modeValueIntensity =
classes.filter((c) => c === modeValue).length / classes.length;
attributes.modeValue = modeValue;
attributes.modeValueIntensity = modeValueIntensity;
});
_graph.edges.forEach((e) => {
const { source, target } = e;
const sourceNode = _graph.nodes.find((n) => n.id === source);
e.x1 = sourceNode.x;
e.y1 = sourceNode.y;
const targetNode = _graph.nodes.find((n) => n.id === target);
e.x2 = targetNode.x;
e.y2 = targetNode.y;
var continuity = 0
for (let i = 0; i < 10; i++) {
const sourceAttributes = sourceNode.attributes;
const targetAttributes = targetNode.attributes;
const key = "Modularity Class_" + i;
const same = sourceAttributes[key] == targetAttributes[key]
if (same) { continuity += 0.1 }
}
e.continuity = continuity
e.bias = 0.5
e.angle = Math.atan2(e.y2-e.y1,e.x2-e.x1) + Math.PI/2
});
return _graph;
}