Permalink
Browse files

Add d3.create and selection.adopt.

  • Loading branch information...
1 parent af5fccd commit 9a279efefe94cbf0d7826e01971e65be761cd968 @mbostock mbostock committed Nov 8, 2011
Showing with 27 additions and 5 deletions.
  1. +2 −0 Makefile
  2. +12 −2 d3.js
  3. +1 −1 d3.min.js
  4. +5 −0 src/core/create.js
  5. +5 −0 src/core/selection-adopt.js
  6. +1 −1 src/core/selection-select.js
  7. +1 −1 src/core/selection-selectAll.js
View
@@ -95,6 +95,7 @@ d3.core.js: \
src/core/selection-append.js \
src/core/selection-insert.js \
src/core/selection-remove.js \
+ src/core/selection-adopt.js \
src/core/selection-data.js \
src/core/selection-filter.js \
src/core/selection-map.js \
@@ -108,6 +109,7 @@ d3.core.js: \
src/core/selection-root.js \
src/core/selection-enter.js \
src/core/selection-enter-select.js \
+ src/core/create.js \
src/core/transition.js \
src/core/transition-select.js \
src/core/transition-selectAll.js \
View
14 d3.js
@@ -1362,7 +1362,7 @@ d3_selectionPrototype.select = function(selector) {
subgroup.parentNode = (group = this[j]).parentNode;
for (var i = -1, n = group.length; ++i < n;) {
if (node = group[i]) {
- subgroup.push(subnode = selector.call(node, node.__data__, i));
+ subgroup.push(subnode = selector.call(node, node.__data__, i, j));
if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
} else {
subgroup.push(null);
@@ -1388,7 +1388,7 @@ d3_selectionPrototype.selectAll = function(selector) {
for (var j = -1, m = this.length; ++j < m;) {
for (var group = this[j], i = -1, n = group.length; ++i < n;) {
if (node = group[i]) {
- subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i)));
+ subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
subgroup.parentNode = node;
}
}
@@ -1612,6 +1612,11 @@ d3_selectionPrototype.remove = function() {
if (parent) parent.removeChild(this);
});
};
+d3_selectionPrototype.adopt = function(selection) {
+ return this.select(function(d, i, j) {
+ return (d = selection[i]) && (d = d[j]) && this.appendChild(d);
+ });
+};
// TODO data(null) for clearing data?
d3_selectionPrototype.data = function(data, join) {
var enter = [],
@@ -1901,6 +1906,11 @@ d3_selection_enterPrototype.select = function(selector) {
return d3_selection(subgroups);
};
+d3.create = function(name) {
+ return d3.select((name = d3.ns.qualify(name)).local
+ ? document.createElementNS(name.space, name.local)
+ : document.createElement(name));
+};
function d3_transition(groups, id, time) {
d3_arraySubclass(groups, d3_transitionPrototype);
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,5 @@
+d3.create = function(name) {
+ return d3.select((name = d3.ns.qualify(name)).local
+ ? document.createElementNS(name.space, name.local)
+ : document.createElement(name));
+};
@@ -0,0 +1,5 @@
+d3_selectionPrototype.adopt = function(selection) {
+ return this.select(function(d, i, j) {
+ return (d = selection[i]) && (d = d[j]) && this.appendChild(d);
+ });
+};
@@ -12,7 +12,7 @@ d3_selectionPrototype.select = function(selector) {
subgroup.parentNode = (group = this[j]).parentNode;
for (var i = -1, n = group.length; ++i < n;) {
if (node = group[i]) {
- subgroup.push(subnode = selector.call(node, node.__data__, i));
+ subgroup.push(subnode = selector.call(node, node.__data__, i, j));
if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
} else {
subgroup.push(null);
@@ -8,7 +8,7 @@ d3_selectionPrototype.selectAll = function(selector) {
for (var j = -1, m = this.length; ++j < m;) {
for (var group = this[j], i = -1, n = group.length; ++i < n;) {
if (node = group[i]) {
- subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i)));
+ subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
subgroup.parentNode = node;
}
}

0 comments on commit 9a279ef

Please sign in to comment.