Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
jdfekete committed Apr 23, 2015
1 parent 508c09b commit bd3bcf0
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 164 deletions.
166 changes: 94 additions & 72 deletions examples/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,51 @@ function matrix(json) {

var dist_adjacency;

var leafOrder = reorder.leafOrder()
.distance(science.stats.distance.manhattan);

function computeLeaforder() {
var order = leafOrder(adjacency);

order.forEach(function(lo, i) {
nodes[i].leafOrder = lo;
});
return nodes.map(function(n) { return n.leafOrder; });
}

function computeLeaforderDist() {
if (! dist_adjacency)
dist_adjacency = reorder.graph2valuemats(graph);

var order = reorder.valuemats_reorder(dist_adjacency,
leafOrder);

order.forEach(function(lo, i) {
nodes[i].leafOrderDist = lo;
});
return nodes.map(function(n) { return n.leafOrderDist; });

}

function computeBarycenter() {
var barycenter = reorder.barycenter(graph);

barycenter[0].forEach(function(lo, i) {
nodes[i].barycenter = lo;
});

return nodes.map(function(n) { return n.barycenter; });
}

function computeRCM() {
var rcm = reorder.reverse_cuthill_mckee(graph);
rcm.forEach(function(lo, i) {
nodes[i].rcm = lo;
});

return nodes.map(function(n) { return n.rcm; });
}

// Precompute the orders.
var orders = {
name: d3.range(n).sort(function(a, b) { return d3.ascending(nodes[a].name, nodes[b].name); }),
Expand All @@ -53,45 +98,10 @@ function matrix(json) {
var x = nodes[b].group - nodes[a].group;
return (x != 0) ? x : d3.ascending(nodes[a].name, nodes[b].name);
}),
leafOrder: function() {
var leafOrder = reorder.leafOrder()
.distance(science.stats.distance.manhattan)(adjacency);

leafOrder.forEach(function(lo, i) {
nodes[i].leafOrder = lo;
});
return nodes.map(function(n) { return n.leafOrder; });
},
leafOrderDist: function() {
if (! dist_adjacency)
dist_adjacency = reorder.graph2distmat(graph);

var leafOrder = reorder.leafOrder()
.distance(science.stats.distance.manhattan)(dist_adjacency);

leafOrder.forEach(function(lo, i) {
nodes[i].leafOrderDist = lo;
});
return nodes.map(function(n) { return n.leafOrderDist; });

},
barycenter: function() {
var barycenter = reorder.barycenter(graph);

barycenter[0].forEach(function(lo, i) {
nodes[i].barycenter = lo;
});

return nodes.map(function(n) { return n.barycenter; });
},
rcm: function() {
var rcm = reorder.reverse_cuthill_mckee(graph);
rcm.forEach(function(lo, i) {
nodes[i].rcm = lo;
});

return nodes.map(function(n) { return n.rcm; });
}
leafOrder: computeLeaforder,
leafOrderDist: computeLeaforderDist,
barycenter: computeBarycenter,
rcm: computeRCM
};

// The default sort order.
Expand Down Expand Up @@ -174,38 +184,50 @@ function matrix(json) {
d3.selectAll(".highlight").remove();
}

function order(value) {
var o = orders[value];

if (typeof o === "function") {
orders[value] = o.call();
}
x.domain(orders[value]);
var currentOrder = 'name';

var t = svg.transition().duration(1500);
function order(value) {
var o = orders[value];
currentOrder = value;

if (typeof o === "function") {
orders[value] = o.call();
}
x.domain(orders[value]);

t.selectAll(".row")
.delay(function(d, i) { return x(i) * 4; })
.attr("transform", function(d, i) { return "translate(0," + x(i) + ")"; })
.selectAll(".cell")
.delay(function(d) { return x(d.x) * 4; })
.attr("x", function(d) { return x(d.x); });
var t = svg.transition().duration(1500);

t.selectAll(".column")
.delay(function(d, i) { return x(i) * 4; })
.attr("transform", function(d, i) { return "translate(" + x(i) + ")rotate(-90)"; });
}
t.selectAll(".row")
.delay(function(d, i) { return x(i) * 4; })
.attr("transform", function(d, i) { return "translate(0," + x(i) + ")"; })
.selectAll(".cell")
.delay(function(d) { return x(d.x) * 4; })
.attr("x", function(d) { return x(d.x); });

t.selectAll(".column")
.delay(function(d, i) { return x(i) * 4; })
.attr("transform", function(d, i) { return "translate(" + x(i) + ")rotate(-90)"; });
}

function distance(value) {
var leafOrder = reorder.leafOrder().distance(science.stats.distance[value])(adjacency);
function distance(value) {
leafOrder.distance(science.stats.distance[value]);

leafOrder.forEach(function(lo, i) {
nodes[lo].leafOrder = i;
});
orders.leafOrder = d3.range(n).sort(function(a, b) {
return nodes[b].leafOrder - nodes[a].leafOrder; });
order("leafOrder");
d3.select("#order").property("selectedIndex", 3);
if (currentOrder == 'leafOrder') {
orders.leafOrder = computeLeaforder();
order("leafOrder");
d3.select("#order").property("selectedIndex", 3);
}
else if (currentOrder == 'leafOrderDist') {
orders.leafOrderDist = computeLeaforderDist();
order("leafOrderDist");
d3.select("#order").property("selectedIndex", 3);
}

// leafOrder.forEach(function(lo, i) {
// nodes[lo].leafOrder = i;
// });
// orders.leafOrder = d3.range(n).sort(function(a, b) {
// return nodes[b].leafOrder - nodes[a].leafOrder; });
}

matrix.order = order;
Expand All @@ -220,18 +242,18 @@ function matrix(json) {

function loadJson(json) {
var mat = matrix(json);
mat.timeout = setTimeout(function() {
mat.order("group");
d3.select("#order").property("selectedIndex", 2).node().focus();
}, 5000);
// mat.timeout = setTimeout(function() {
// mat.order("group");
// d3.select("#order").property("selectedIndex", 2).node().focus();
// }, 5000);

d3.select("#order").on("change", function() {
clearTimeout(mat.timeout);
// clearTimeout(mat.timeout);
mat.order(this.value);
});

d3.select("#distance").on("change", function() {
clearTimeout(mat.timeout);
// clearTimeout(mat.timeout);
mat.distance(this.value);
});
}
8 changes: 4 additions & 4 deletions examples/miserables/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ <h1><i>Les Misérables</i> Co-occurrence</h1>

d3.json("miserables.json", function(json) {
var mat = matrix(json);
mat.timeout = setTimeout(function() {
mat.order("group");
d3.select("#order").property("selectedIndex", 2).node().focus();
}, 5000);
// mat.timeout = setTimeout(function() {
// mat.order("group");
// d3.select("#order").property("selectedIndex", 2).node().focus();
// }, 5000);

d3.select("#order").on("change", function() {
clearTimeout(mat.timeout);
Expand Down
1 change: 1 addition & 0 deletions examples/saclay/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ <h1>INRIA Saclay Researchers Co-Authorship Network</h1>
<option value="count">by Frequency</option>
<option value="group">by Cluster</option>
<option value="leafOrder">by Leaf Order</option>
<option value="leafOrderDist">by Leaf Order over Distance Matrix</option>
<option value="barycenter">by Crossing Reduction</option>
<option value="rcm">by Bandwidth Reduction (RCM)</option>
</select>
Expand Down
Loading

0 comments on commit bd3bcf0

Please sign in to comment.