Merge branch 'master' into log
This commit is contained in:
Коммит
64c4e787e2
|
@ -10,8 +10,8 @@
|
|||
|
||||
circle.node {
|
||||
cursor: pointer;
|
||||
stroke: #3182bd;
|
||||
stroke-width: 1.5px;
|
||||
stroke: #000;
|
||||
stroke-width: .5px;
|
||||
}
|
||||
|
||||
line.link {
|
||||
|
@ -34,6 +34,8 @@ var w = 960,
|
|||
|
||||
var force = d3.layout.force()
|
||||
.on("tick", tick)
|
||||
.charge(function(d) { return d._children ? -d.size / 100 : -30; })
|
||||
.linkDistance(function(d) { return d.target._children ? 80 : 30; })
|
||||
.size([w, h]);
|
||||
|
||||
var vis = d3.select("#chart").append("svg:svg")
|
||||
|
@ -42,6 +44,9 @@ var vis = d3.select("#chart").append("svg:svg")
|
|||
|
||||
d3.json("../data/flare.json", function(json) {
|
||||
root = json;
|
||||
root.fixed = true;
|
||||
root.x = w / 2;
|
||||
root.y = h / 2;
|
||||
update();
|
||||
});
|
||||
|
||||
|
@ -75,12 +80,15 @@ function update() {
|
|||
.data(nodes, function(d) { return d.id; })
|
||||
.style("fill", color);
|
||||
|
||||
node.transition()
|
||||
.attr("r", function(d) { return d.children ? 4.5 : Math.sqrt(d.size) / 10; });
|
||||
|
||||
// Enter any new nodes.
|
||||
node.enter().append("svg:circle")
|
||||
.attr("class", "node")
|
||||
.attr("cx", function(d) { return d.x; })
|
||||
.attr("cy", function(d) { return d.y; })
|
||||
.attr("r", function(d) { return Math.sqrt(d.size) / 10 || 4.5; })
|
||||
.attr("r", function(d) { return d.children ? 4.5 : Math.sqrt(d.size) / 10; })
|
||||
.style("fill", color)
|
||||
.on("click", click)
|
||||
.call(force.drag);
|
||||
|
@ -121,12 +129,13 @@ function flatten(root) {
|
|||
var nodes = [], i = 0;
|
||||
|
||||
function recurse(node) {
|
||||
if (node.children) node.children.forEach(recurse);
|
||||
if (node.children) node.size = node.children.reduce(function(p, v) { return p + recurse(v); }, 0);
|
||||
if (!node.id) node.id = ++i;
|
||||
nodes.push(node);
|
||||
return node.size;
|
||||
}
|
||||
|
||||
recurse(root);
|
||||
root.size = recurse(root);
|
||||
return nodes;
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
"main": "d3.js",
|
||||
"dependencies": {
|
||||
"uglify-js": "1.1.1",
|
||||
"jsdom": "0.2.8",
|
||||
"vows": "0.5.11"
|
||||
"jsdom": "0.2.9",
|
||||
"vows": "0.5.13"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ require("util").puts(JSON.stringify({
|
|||
"main": "d3.js",
|
||||
"dependencies": {
|
||||
"uglify-js": "1.1.1",
|
||||
"jsdom": "0.2.8",
|
||||
"vows": "0.5.11"
|
||||
"jsdom": "0.2.9",
|
||||
"vows": "0.5.13"
|
||||
}
|
||||
}, null, 2));
|
||||
|
|
|
@ -33,8 +33,8 @@ suite.addBatch({
|
|||
"selects by node": function() {
|
||||
var div = d3.select(document.body.lastChild);
|
||||
assert.isTrue(div[0][0] === document.body.lastChild);
|
||||
assert.length(div, 1);
|
||||
assert.length(div[0], 1);
|
||||
assert.lengthOf(div, 1);
|
||||
assert.lengthOf(div[0], 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -33,8 +33,8 @@ suite.addBatch({
|
|||
"selects by array": function() {
|
||||
var div = d3.selectAll([document.body.lastChild]);
|
||||
assert.isTrue(div[0][0] === document.body.lastChild);
|
||||
assert.length(div, 1);
|
||||
assert.length(div[0], 1);
|
||||
assert.lengthOf(div, 1);
|
||||
assert.lengthOf(div[0], 1);
|
||||
},
|
||||
"groups are not instances of NodeList": function() {
|
||||
var div = d3.select("body").selectAll(function() { return this.getElementsByClassName("div"); });
|
||||
|
|
|
@ -17,8 +17,8 @@ function category(category, n) {
|
|||
return {
|
||||
"is an ordinal scale": function() {
|
||||
var x = category(), colors = x.range();
|
||||
assert.length(x.domain(), 0);
|
||||
assert.length(x.range(), n);
|
||||
assert.lengthOf(x.domain(), 0);
|
||||
assert.lengthOf(x.range(), n);
|
||||
assert.equal(x(1), colors[0]);
|
||||
assert.equal(x(2), colors[1]);
|
||||
assert.equal(x(1), colors[0]);
|
||||
|
@ -39,7 +39,7 @@ function category(category, n) {
|
|||
},
|
||||
"contains the expected number of values in the range": function() {
|
||||
var x = category();
|
||||
assert.length(x.range(), n);
|
||||
assert.lengthOf(x.range(), n);
|
||||
},
|
||||
"each range value is distinct": function() {
|
||||
var map = {}, count = 0, x = category();
|
||||
|
|
Загрузка…
Ссылка в новой задаче