Published
Edited
Jul 11, 2020
Fork of Bible-net
Insert cell
md`# Harness-net`
Insert cell
graph = {
let rawGraph = await
FileAttachment("dataNET55.json").json(),
degreeNodes = _.filter(rawGraph['nodes'], d => d['degree'] >= minimumDegree ),
listDegreeNodes = _.map(degreeNodes, 'id'),
degreeEdges = _.filter(rawGraph['links'], function (d) {
return (_.includes(listDegreeNodes, d['source'])) && (_.includes(listDegreeNodes, d['target']))
})
return {'nodes': degreeNodes, 'links': degreeEdges}
}

Insert cell
d3 = require ("d3@5.8")
Insert cell
_ = require("lodash")
Insert cell
drag = (simulation) => {
function dragstarted(d) {
if (!d3.event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x;
d.fy = d.y;
}
function dragged(d) {
d.fx = d3.event.x;
d.fy = d3.event.y;
}
function dragended(d) {
if (!d3.event.active) simulation.alphaTarget(0);
d.fx = d.x; //null;
d.fy = d.y; //null;
}
return d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
network = {
const radiusRange = [10, maxNodeSize],
height=1000,
strengthValue = 0.5;
const simulation = d3.forceSimulation(graph.nodes)
.force("link", d3.forceLink(graph.links).id(d => d.id))
.force("charge", d3.forceManyBody().strength(-strengthValue))
.force("center", d3.forceCenter(width / 2, height / 2))
.force("collide", d3.forceCollide().radius(function(d) { return collideStrength;}).strength(.5).iterations(.10));
const svg = d3.select(DOM.svg(width, height));
const link = svg.append("g")
.attr("stroke", "#999")
.attr("stroke-opacity", 0.6)
.attr("stroke-width", 1)
.selectAll("line")
.data(graph.links)
.join("line");
var nodeRadiusScale = d3.scaleLinear(
d3.extent(_.map(graph.nodes, 'degree')),
radiusRange
);
const node = svg.append("g")
.attr("stroke", "#fff")
.attr("stroke-width", 5)
.selectAll("circle")
.data(graph.nodes)
.join("circle")
.attr("r", (d) => nodeRadiusScale(+d.degree))
.attr("fill", "blue") // #077e93
.call(drag(simulation));
// Text to nodes
const text = svg.append("g")
.attr("class", "text")
.selectAll("text")
.data(graph.nodes)
.enter().append("text")
.text(d => d.id)

simulation.on("tick", function() {
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 - 5) //position of the lower left point of the text
.attr("y", d => d.y + 5); //position of the lower left point of the text
;
});
invalidation.then(() => simulation.stop());
return svg.node();

}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more