This commit is contained in:
Mike Bostock 2011-09-27 08:47:14 -07:00
Родитель c974d3a941 80fafd527c
Коммит 151d09d479
9 изменённых файлов: 55 добавлений и 11 удалений

28
d3.js поставляемый
Просмотреть файл

@ -10,7 +10,25 @@ try {
d3_style_setProperty.call(this, name, value + "", priority); d3_style_setProperty.call(this, name, value + "", priority);
}; };
} }
d3 = {version: "2.2.0"}; // semver d3 = {version: "2.2.1"}; // semver
var d3_array = d3_arraySlice; // conversion for NodeLists
function d3_arrayCopy(pseudoarray) {
var i = -1, n = pseudoarray.length, array = [];
while (++i < n) array.push(pseudoarray[i]);
return array;
}
function d3_arraySlice(pseudoarray) {
return Array.prototype.slice.call(pseudoarray);
}
try {
d3_array(document.documentElement.childNodes)[0].nodeType;
} catch(e) {
d3_array = d3_arrayCopy;
}
var d3_arraySubclass = [].__proto__? var d3_arraySubclass = [].__proto__?
// Until ECMAScript supports array subclassing, prototype injection works well. // Until ECMAScript supports array subclassing, prototype injection works well.
@ -1254,7 +1272,7 @@ d3_selectionPrototype.selectAll = function(selector) {
for (var j = -1, m = this.length; ++j < m;) { for (var j = -1, m = this.length; ++j < m;) {
for (var group = this[j], i = -1, n = group.length; ++i < n;) { for (var group = this[j], i = -1, n = group.length; ++i < n;) {
if (node = group[i]) { if (node = group[i]) {
subgroups.push(subgroup = selector.call(node, node.__data__, i)); subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i)));
subgroup.parentNode = node; subgroup.parentNode = node;
} }
} }
@ -1738,16 +1756,18 @@ var d3_selectionRoot = d3_selection([[document]]);
d3_selectionRoot[0].parentNode = document.documentElement; d3_selectionRoot[0].parentNode = document.documentElement;
// TODO fast singleton implementation! // TODO fast singleton implementation!
// TODO select(function)
d3.select = function(selector) { d3.select = function(selector) {
return typeof selector === "string" return typeof selector === "string"
? d3_selectionRoot.select(selector) ? d3_selectionRoot.select(selector)
: d3_selection([[selector]]); // assume node : d3_selection([[selector]]); // assume node
}; };
// TODO selectAll(function)
d3.selectAll = function(selector) { d3.selectAll = function(selector) {
return typeof selector === "string" return typeof selector === "string"
? d3_selectionRoot.selectAll(selector) ? d3_selectionRoot.selectAll(selector)
: d3_selection([selector]); // assume node[] : d3_selection([d3_array(selector)]); // assume node[]
}; };
function d3_transition(groups, id) { function d3_transition(groups, id) {
d3_arraySubclass(groups, d3_transitionPrototype); d3_arraySubclass(groups, d3_transitionPrototype);
@ -3401,7 +3421,7 @@ function d3_svg_mousePoint(container, e) {
}; };
d3.svg.touches = function(container) { d3.svg.touches = function(container) {
var touches = d3.event.touches; var touches = d3.event.touches;
return touches ? Array.prototype.map.call(touches, function(touch) { return touches ? d3_array(touches).map(function(touch) {
var point = d3_svg_mousePoint(container, touch); var point = d3_svg_mousePoint(container, touch);
point.identifier = touch.identifier; point.identifier = touch.identifier;
return point; return point;

4
d3.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -1,6 +1,6 @@
{ {
"name": "d3", "name": "d3",
"version": "2.2.0", "version": "2.2.1",
"description": "A small, free JavaScript library for manipulating documents based on data.", "description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [ "keywords": [
"dom", "dom",

Просмотреть файл

@ -1,3 +1,21 @@
var d3_array = d3_arraySlice; // conversion for NodeLists
function d3_arrayCopy(pseudoarray) {
var i = -1, n = pseudoarray.length, array = [];
while (++i < n) array.push(pseudoarray[i]);
return array;
}
function d3_arraySlice(pseudoarray) {
return Array.prototype.slice.call(pseudoarray);
}
try {
d3_array(document.documentElement.childNodes)[0].nodeType;
} catch(e) {
d3_array = d3_arrayCopy;
}
var d3_arraySubclass = [].__proto__? var d3_arraySubclass = [].__proto__?
// Until ECMAScript supports array subclassing, prototype injection works well. // Until ECMAScript supports array subclassing, prototype injection works well.

Просмотреть файл

@ -1 +1 @@
d3 = {version: "2.2.0"}; // semver d3 = {version: "2.2.1"}; // semver

Просмотреть файл

@ -3,14 +3,16 @@ var d3_selectionRoot = d3_selection([[document]]);
d3_selectionRoot[0].parentNode = document.documentElement; d3_selectionRoot[0].parentNode = document.documentElement;
// TODO fast singleton implementation! // TODO fast singleton implementation!
// TODO select(function)
d3.select = function(selector) { d3.select = function(selector) {
return typeof selector === "string" return typeof selector === "string"
? d3_selectionRoot.select(selector) ? d3_selectionRoot.select(selector)
: d3_selection([[selector]]); // assume node : d3_selection([[selector]]); // assume node
}; };
// TODO selectAll(function)
d3.selectAll = function(selector) { d3.selectAll = function(selector) {
return typeof selector === "string" return typeof selector === "string"
? d3_selectionRoot.selectAll(selector) ? d3_selectionRoot.selectAll(selector)
: d3_selection([selector]); // assume node[] : d3_selection([d3_array(selector)]); // assume node[]
}; };

Просмотреть файл

@ -8,7 +8,7 @@ d3_selectionPrototype.selectAll = function(selector) {
for (var j = -1, m = this.length; ++j < m;) { for (var j = -1, m = this.length; ++j < m;) {
for (var group = this[j], i = -1, n = group.length; ++i < n;) { for (var group = this[j], i = -1, n = group.length; ++i < n;) {
if (node = group[i]) { if (node = group[i]) {
subgroups.push(subgroup = selector.call(node, node.__data__, i)); subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i)));
subgroup.parentNode = node; subgroup.parentNode = node;
} }
} }

Просмотреть файл

@ -1,6 +1,6 @@
d3.svg.touches = function(container) { d3.svg.touches = function(container) {
var touches = d3.event.touches; var touches = d3.event.touches;
return touches ? Array.prototype.map.call(touches, function(touch) { return touches ? d3_array(touches).map(function(touch) {
var point = d3_svg_mousePoint(container, touch); var point = d3_svg_mousePoint(container, touch);
point.identifier = touch.identifier; point.identifier = touch.identifier;
return point; return point;

Просмотреть файл

@ -35,6 +35,10 @@ suite.addBatch({
assert.isTrue(div[0][0] === document.body.lastChild); assert.isTrue(div[0][0] === document.body.lastChild);
assert.length(div, 1); assert.length(div, 1);
assert.length(div[0], 1); assert.length(div[0], 1);
},
"groups are not instances of NodeList": function() {
var div = d3.select("body").selectAll(function() { return this.getElementsByClassName("div"); });
assert.isFalse(div[0] instanceof window.NodeList);
} }
} }
}); });