Skip to content

Commit

Permalink
Merge branch '2.7.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Dec 30, 2011
2 parents 2d66075 + 1a8e875 commit a92f8b3
Show file tree
Hide file tree
Showing 23 changed files with 155 additions and 79 deletions.
47 changes: 26 additions & 21 deletions d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ try {
d3_style_setProperty.call(this, name, value + "", priority);
};
}
d3 = {version: "2.7.0"}; // semver
d3 = {version: "2.7.1"}; // semver
var d3_array = d3_arraySlice; // conversion for NodeLists

function d3_arrayCopy(pseudoarray) {
Expand Down Expand Up @@ -424,9 +424,10 @@ d3.round = function(x, n) {
};
d3.xhr = function(url, mime, callback) {
var req = new XMLHttpRequest;
if (arguments.length < 3) callback = mime;
if (arguments.length < 3) callback = mime, mime = null;
else if (mime && req.overrideMimeType) req.overrideMimeType(mime);
req.open("GET", url, true);
if (mime) req.setRequestHeader("Accept", mime);
req.onreadystatechange = function() {
if (req.readyState === 4) callback(req.status < 300 ? req : null);
};
Expand Down Expand Up @@ -1574,16 +1575,18 @@ d3_selectionPrototype.property = function(name, value) {
? propertyFunction : propertyConstant));
};
d3_selectionPrototype.text = function(value) {
return arguments.length < 1 ? this.node().textContent
: (this.each(typeof value === "function"
? function() { this.textContent = value.apply(this, arguments); }
: function() { this.textContent = value; }));
return arguments.length < 1
? this.node().textContent : this.each(typeof value === "function"
? function() { var v = value.apply(this, arguments); this.textContent = v == null ? "" : v; } : value == null
? function() { this.textContent = ""; }
: function() { this.textContent = value; });
};
d3_selectionPrototype.html = function(value) {
return arguments.length < 1 ? this.node().innerHTML
: (this.each(typeof value === "function"
? function() { this.innerHTML = value.apply(this, arguments); }
: function() { this.innerHTML = value; }));
return arguments.length < 1
? this.node().innerHTML : this.each(typeof value === "function"
? function() { var v = value.apply(this, arguments); this.innerHTML = v == null ? "" : v; } : value == null
? function() { this.innerHTML = ""; }
: function() { this.innerHTML = value; });
};
// TODO append(node)?
// TODO append(function)?
Expand Down Expand Up @@ -2276,9 +2279,13 @@ var d3_timer_frame = window.requestAnimationFrame
|| window.msRequestAnimationFrame
|| function(callback) { setTimeout(callback, 17); };
d3.transform = function(string) {
d3_transformG.setAttribute("transform", string);
var t = d3_transformG.transform.baseVal.consolidate();
return new d3_transform(t ? t.matrix : d3_transformIdentity);
var g = document.createElementNS(d3.ns.prefix.svg, "g"),
identity = {a: 1, b: 0, c: 0, d: 1, e: 0, f: 0};
return (d3.transform = function(string) {
g.setAttribute("transform", string);
var t = g.transform.baseVal.consolidate();
return new d3_transform(t ? t.matrix : identity);
})(string);
};

// Compute x-scale and normalize the first row.
Expand Down Expand Up @@ -2330,9 +2337,7 @@ function d3_transformCombine(a, b, k) {
return a;
}

var d3_transformG = document.createElementNS(d3.ns.prefix.svg, "g"),
d3_transformIdentity = {a: 1, b: 0, c: 0, d: 1, e: 0, f: 0},
d3_transformDegrees = 180 / Math.PI;
var d3_transformDegrees = 180 / Math.PI;
function d3_noop() {}
d3.scale = {};

Expand Down Expand Up @@ -2716,7 +2721,7 @@ function d3_scale_ordinal(domain, ranger) {
};

scale.rangeExtent = function() {
return ranger.x;
return ranger.t === "range" ? d3_scaleExtent(ranger.x) : ranger.x;
};

scale.copy = function() {
Expand Down Expand Up @@ -3503,10 +3508,10 @@ d3.svg.chord = function() {
var s = subgroup(this, source, d, i),
t = subgroup(this, target, d, i);
return "M" + s.p0
+ arc(s.r, s.p1) + (equals(s, t)
+ arc(s.r, s.p1, s.a1 - s.a0) + (equals(s, t)
? curve(s.r, s.p1, s.r, s.p0)
: curve(s.r, s.p1, t.r, t.p0)
+ arc(t.r, t.p1)
+ arc(t.r, t.p1, t.a1 - t.a0)
+ curve(t.r, t.p1, s.r, s.p0))
+ "Z";
}
Expand All @@ -3529,8 +3534,8 @@ d3.svg.chord = function() {
return a.a0 == b.a0 && a.a1 == b.a1;
}

function arc(r, p) {
return "A" + r + "," + r + " 0 0,1 " + p;
function arc(r, p, a) {
return "A" + r + "," + r + " 0 " + +(a > Math.PI) + ",1 " + p;
}

function curve(r0, p0, r1, p1) {
Expand Down
14 changes: 6 additions & 8 deletions d3.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,19 +628,17 @@ d3.layout.pie = function() {
: function(i, j) { return sort(data[i], data[j]); });

// Compute the arcs!
var arcs = index.map(function(i) {
return {
// They are stored in the original data's order.
var arcs = [];
index.forEach(function(i) {
arcs[i] = {
data: data[i],
value: d = values[i],
startAngle: a,
endAngle: a += d * k
};
});

// Return the arcs in the original data's order.
return data.map(function(d, i) {
return arcs[index[i]];
});
return arcs;
}

/**
Expand Down Expand Up @@ -1392,7 +1390,7 @@ d3.layout.cluster = function() {
// Second walk, normalizing x & y to the desired size.
d3_layout_treeVisitAfter(root, function(node) {
node.x = (node.x - x0) / (x1 - x0) * size[0];
node.y = (1 - node.y / root.y) * size[1];
node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
});

return nodes;
Expand Down
2 changes: 1 addition & 1 deletion d3.layout.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions d3.min.js

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "2.7.0",
"version": "2.7.1",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
Expand All @@ -21,8 +21,13 @@
},
"main": "d3.js",
"dependencies": {
"uglify-js": "1.1.1",
"jsdom": "0.2.9",
"vows": "0.5.13"
"jsdom": "0.2.10"
},
"devDependencies": {
"uglify-js": "1.2.3",
"vows": "0.6.x"
},
"scripts": {
"test": "./node_modules/vows/bin/vows"
}
}
2 changes: 1 addition & 1 deletion src/core/core.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d3 = {version: "2.7.0"}; // semver
d3 = {version: "2.7.1"}; // semver
9 changes: 5 additions & 4 deletions src/core/selection-html.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
d3_selectionPrototype.html = function(value) {
return arguments.length < 1 ? this.node().innerHTML
: (this.each(typeof value === "function"
? function() { this.innerHTML = value.apply(this, arguments); }
: function() { this.innerHTML = value; }));
return arguments.length < 1
? this.node().innerHTML : this.each(typeof value === "function"
? function() { var v = value.apply(this, arguments); this.innerHTML = v == null ? "" : v; } : value == null
? function() { this.innerHTML = ""; }
: function() { this.innerHTML = value; });
};
9 changes: 5 additions & 4 deletions src/core/selection-text.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
d3_selectionPrototype.text = function(value) {
return arguments.length < 1 ? this.node().textContent
: (this.each(typeof value === "function"
? function() { this.textContent = value.apply(this, arguments); }
: function() { this.textContent = value; }));
return arguments.length < 1
? this.node().textContent : this.each(typeof value === "function"
? function() { var v = value.apply(this, arguments); this.textContent = v == null ? "" : v; } : value == null
? function() { this.textContent = ""; }
: function() { this.textContent = value; });
};
14 changes: 8 additions & 6 deletions src/core/transform.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
d3.transform = function(string) {
d3_transformG.setAttribute("transform", string);
var t = d3_transformG.transform.baseVal.consolidate();
return new d3_transform(t ? t.matrix : d3_transformIdentity);
var g = document.createElementNS(d3.ns.prefix.svg, "g"),
identity = {a: 1, b: 0, c: 0, d: 1, e: 0, f: 0};
return (d3.transform = function(string) {
g.setAttribute("transform", string);
var t = g.transform.baseVal.consolidate();
return new d3_transform(t ? t.matrix : identity);
})(string);
};

// Compute x-scale and normalize the first row.
Expand Down Expand Up @@ -53,6 +57,4 @@ function d3_transformCombine(a, b, k) {
return a;
}

var d3_transformG = document.createElementNS(d3.ns.prefix.svg, "g"),
d3_transformIdentity = {a: 1, b: 0, c: 0, d: 1, e: 0, f: 0},
d3_transformDegrees = 180 / Math.PI;
var d3_transformDegrees = 180 / Math.PI;
3 changes: 2 additions & 1 deletion src/core/xhr.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
d3.xhr = function(url, mime, callback) {
var req = new XMLHttpRequest;
if (arguments.length < 3) callback = mime;
if (arguments.length < 3) callback = mime, mime = null;
else if (mime && req.overrideMimeType) req.overrideMimeType(mime);
req.open("GET", url, true);
if (mime) req.setRequestHeader("Accept", mime);
req.onreadystatechange = function() {
if (req.readyState === 4) callback(req.status < 300 ? req : null);
};
Expand Down
2 changes: 1 addition & 1 deletion src/layout/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ d3.layout.cluster = function() {
// Second walk, normalizing x & y to the desired size.
d3_layout_treeVisitAfter(root, function(node) {
node.x = (node.x - x0) / (x1 - x0) * size[0];
node.y = (1 - node.y / root.y) * size[1];
node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
});

return nodes;
Expand Down
12 changes: 5 additions & 7 deletions src/layout/pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ d3.layout.pie = function() {
: function(i, j) { return sort(data[i], data[j]); });

// Compute the arcs!
var arcs = index.map(function(i) {
return {
// They are stored in the original data's order.
var arcs = [];
index.forEach(function(i) {
arcs[i] = {
data: data[i],
value: d = values[i],
startAngle: a,
endAngle: a += d * k
};
});

// Return the arcs in the original data's order.
return data.map(function(d, i) {
return arcs[index[i]];
});
return arcs;
}

/**
Expand Down
11 changes: 7 additions & 4 deletions src/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ require("util").puts(JSON.stringify({
"repository": {"type": "git", "url": "http://github.com/mbostock/d3.git"},
"main": "d3.js",
"dependencies": {
"uglify-js": "1.1.1",
"jsdom": "0.2.9",
"vows": "0.5.13"
}
"jsdom": "0.2.10"
},
"devDependencies": {
"uglify-js": "1.2.3",
"vows": "0.6.x"
},
"scripts": {"test": "./node_modules/vows/bin/vows"}
}, null, 2));
2 changes: 1 addition & 1 deletion src/scale/ordinal.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function d3_scale_ordinal(domain, ranger) {
};

scale.rangeExtent = function() {
return ranger.x;
return ranger.t === "range" ? d3_scaleExtent(ranger.x) : ranger.x;
};

scale.copy = function() {
Expand Down
8 changes: 4 additions & 4 deletions src/svg/chord.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ d3.svg.chord = function() {
var s = subgroup(this, source, d, i),
t = subgroup(this, target, d, i);
return "M" + s.p0
+ arc(s.r, s.p1) + (equals(s, t)
+ arc(s.r, s.p1, s.a1 - s.a0) + (equals(s, t)
? curve(s.r, s.p1, s.r, s.p0)
: curve(s.r, s.p1, t.r, t.p0)
+ arc(t.r, t.p1)
+ arc(t.r, t.p1, t.a1 - t.a0)
+ curve(t.r, t.p1, s.r, s.p0))
+ "Z";
}
Expand All @@ -37,8 +37,8 @@ d3.svg.chord = function() {
return a.a0 == b.a0 && a.a1 == b.a1;
}

function arc(r, p) {
return "A" + r + "," + r + " 0 0,1 " + p;
function arc(r, p, a) {
return "A" + r + "," + r + " 0 " + +(a > Math.PI) + ",1 " + p;
}

function curve(r0, p0, r1, p1) {
Expand Down
20 changes: 16 additions & 4 deletions test/core/selection-html-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,36 @@ suite.addBatch({
assert.equal(document.body.lastChild.tagName, "I");
assert.equal(document.body.lastChild.textContent, "0");
},
/*
https://github.com/tmpvar/jsdom/issues/276
"clears the inner HTML as null": function(body) {
body.html(null);
assert.equal(document.body.innerHTML, "");
assert.isNull(document.body.firstChild);
},
*/
"clears the inner HTML as undefined": function(body) {
body.html(undefined);
assert.equal(document.body.innerHTML, "");
assert.isNull(document.body.firstChild);
},
"clears the inner HTML as the empty string": function(body) {
body.html("");
assert.equal(document.body.innerHTML, "");
assert.isNull(document.body.firstChild);
},
"clears the inner HTML as a function": function(body) {
"clears the inner HTML as a function returning the empty string": function(body) {
body.text(function() { return ""; });
assert.equal(document.body.innerHTML, "");
assert.isNull(document.body.firstChild);
},
"clears the inner HTML as a function returning null": function(body) {
body.text(function() { return null; });
assert.equal(document.body.innerHTML, "");
assert.isNull(document.body.firstChild);
},
"clears the inner HTML as a function returning undefined": function(body) {
body.text(function() { return undefined; });
assert.equal(document.body.innerHTML, "");
assert.isNull(document.body.firstChild);
},
"ignores null nodes": function() {
var body = d3.select("body");
body[0][0] = null;
Expand Down
13 changes: 10 additions & 3 deletions test/core/selection-text-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@ suite.addBatch({
assert.equal(document.body.textContent, "<h1>Hello, world!</h1>");
assert.equal(document.body.firstChild.nodeType, document.TEXT_NODE);
},
/*
https://github.com/tmpvar/jsdom/issues/276
/* <https://github.com/tmpvar/jsdom/issues/276>
"clears the text content as null": function(body) {
body.text(null);
assert.equal(document.body.textContent, "");
},
"clears the text content as a function": function(body) {
"clears the text content as undefined": function(body) {
body.text(undefined);
assert.equal(document.body.textContent, "");
},
"clears the text content as a function returning null": function(body) {
body.text(function() { return null; });
assert.equal(document.body.textContent, "");
},
"clears the text content as a function returning undefined": function(body) {
body.text(function() { return undefined; });
assert.equal(document.body.textContent, "");
},
*/
"ignores null nodes": function() {
var body = d3.select("body");
Expand Down
5 changes: 2 additions & 3 deletions test/env-xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ XMLHttpRequest = function() {
self.open = function(m, u, a) {
info.url = u;
info.async = a;
Object.freeze(info);
self.send = a ? read : readSync;
};

self.overrideMimeType = function(x) {
info.mimeType = x;
self.setRequestHeader = function(n, v) {
if (/^Accept$/i.test(n)) info.mimeType = v;
};

function read() {
Expand Down
Loading

0 comments on commit a92f8b3

Please sign in to comment.