An example of how cell splitting could be achieved using examples from the Sparse Matrix Collection
Based on Force Layout & Matrix Market Format
forked from syntagmatic's block: Force-directed Splitting
xxxxxxxxxx
<meta charset="utf-8">
<style>
body {
margin: 0;
}
.node {
fill: steelblue;
}
.link {
stroke: #ccc;
}
</style>
<body>
<script src="https://d3js.org/d3.v2.js?2.9.1"></script>
<script>
var width = 960,
height = 500;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var force = d3.layout.force()
.size([width, height]);
d3.text("can_161.mtx", function(text) {
var graph = parseMtx(text);
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("class", "link")
.on("mouseover", function(d,i) {
console.log(d,i);
});
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("circle")
.attr("class", "node")
.attr("r", 4.5)
.call(force.drag);
force
.nodes(graph.nodes)
.links(graph.links)
.on("tick", tick)
.start();
function tick() {
link.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
}
function update() {
force
.nodes(graph.nodes)
.links(graph.links);
node.data(graph.nodes)
.exit().remove();
link.data(graph.links)
.exit().remove();
};
var start = 300;
var remove = 100;
var index = 0;
function anim() {
if (index > remove) return;
graph.links.splice(start,1);
update();
force.start();
index++;
setTimeout(anim, 30);
};
setTimeout(anim,900);
});
function parseMtx(text) {
var nodes = [];
var links = text
.split(/\n/g) // split lines
.filter(function(d) { return d.charAt(0) != "%"; }) // skip comments
.slice(1, -1) // skip header line, last line
.map(function(d) {
d = d.split(/\s+/g);
var source = d[0] - 1, target = d[1] - 1;
return {
source: nodes[source] || (nodes[source] = {index: source}),
target: nodes[target] || (nodes[target] = {index: target})
};
});
return {
nodes: nodes,
links: links
};
}
</script>
Modified http://d3js.org/d3.v2.js?2.9.1 to a secure url
https://d3js.org/d3.v2.js?2.9.1