Commit a62bd527 authored by Mike Bostock's avatar Mike Bostock
Browse files

Fix a bug in enter selection's empty.

Due to the ordering in which the prototypes are defined, it was still undefined!
Also, the empty method depends on the node method being defined. Added a test.
parent b4cf93f8
......@@ -94,8 +94,6 @@ d3.core.js: \
src/core/selection-insert.js \
src/core/selection-remove.js \
src/core/selection-data.js \
src/core/selection-enter.js \
src/core/selection-enter-select.js \
src/core/selection-filter.js \
src/core/selection-map.js \
src/core/selection-sort.js \
......@@ -106,6 +104,8 @@ d3.core.js: \
src/core/selection-node.js \
src/core/selection-transition.js \
src/core/selection-root.js \
src/core/selection-enter.js \
src/core/selection-enter-select.js \
src/core/transition.js \
src/core/transition-select.js \
src/core/transition-selectAll.js \
......
......@@ -10,7 +10,7 @@ try {
d3_style_setProperty.call(this, name, value + "", priority);
};
}
d3 = {version: "2.4.4"}; // semver
d3 = {version: "2.4.5"}; // semver
var d3_array = d3_arraySlice; // conversion for NodeLists
function d3_arrayCopy(pseudoarray) {
......@@ -1666,40 +1666,6 @@ d3_selectionPrototype.data = function(data, join) {
function d3_selection_dataNode(data) {
return {__data__: data};
}
function d3_selection_enter(selection) {
d3_arraySubclass(selection, d3_selection_enterPrototype);
return selection;
}
var d3_selection_enterPrototype = [];
d3_selection_enterPrototype.append = d3_selectionPrototype.append;
d3_selection_enterPrototype.insert = d3_selectionPrototype.insert;
d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
d3_selection_enterPrototype.select = function(selector) {
var subgroups = [],
subgroup,
subnode,
upgroup,
group,
node;
for (var j = -1, m = this.length; ++j < m;) {
upgroup = (group = this[j]).update;
subgroups.push(subgroup = []);
subgroup.parentNode = group.parentNode;
for (var i = -1, n = group.length; ++i < n;) {
if (node = group[i]) {
subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i));
subnode.__data__ = node.__data__;
} else {
subgroup.push(null);
}
}
}
return d3_selection(subgroups);
};
// TODO preserve null elements to maintain index?
d3_selectionPrototype.filter = function(filter) {
var subgroups = [],
......@@ -1844,6 +1810,41 @@ d3.selectAll = function(selector) {
? d3_selectionRoot.selectAll(selector)
: d3_selection([d3_array(selector)]); // assume node[]
};
function d3_selection_enter(selection) {
d3_arraySubclass(selection, d3_selection_enterPrototype);
return selection;
}
var d3_selection_enterPrototype = [];
d3_selection_enterPrototype.append = d3_selectionPrototype.append;
d3_selection_enterPrototype.insert = d3_selectionPrototype.insert;
d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
d3_selection_enterPrototype.node = d3_selectionPrototype.node;
d3_selection_enterPrototype.select = function(selector) {
var subgroups = [],
subgroup,
subnode,
upgroup,
group,
node;
for (var j = -1, m = this.length; ++j < m;) {
upgroup = (group = this[j]).update;
subgroups.push(subgroup = []);
subgroup.parentNode = group.parentNode;
for (var i = -1, n = group.length; ++i < n;) {
if (node = group[i]) {
subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i));
subnode.__data__ = node.__data__;
} else {
subgroup.push(null);
}
}
}
return d3_selection(subgroups);
};
function d3_transition(groups, id, time) {
d3_arraySubclass(groups, d3_transitionPrototype);
......
This diff is collapsed.
{
"name": "d3",
"version": "2.4.4",
"version": "2.4.5",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
......
d3 = {version: "2.4.4"}; // semver
d3 = {version: "2.4.5"}; // semver
......@@ -8,3 +8,4 @@ var d3_selection_enterPrototype = [];
d3_selection_enterPrototype.append = d3_selectionPrototype.append;
d3_selection_enterPrototype.insert = d3_selectionPrototype.insert;
d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
d3_selection_enterPrototype.node = d3_selectionPrototype.node;
......@@ -109,6 +109,7 @@ suite.addBatch({
},
"defines an enter selection for entering data": function(span) {
var enter = span.data(d3.range(4)).enter();
assert.isFalse(enter.empty());
assert.equal(enter.length, 2);
assert.equal(enter[0].length, 4);
assert.equal(enter[1].length, 4);
......@@ -123,6 +124,7 @@ suite.addBatch({
},
"defines an exit selection for exiting data": function(span) {
var exit = span.data(d3.range(1)).exit();
assert.isFalse(exit.empty());
assert.equal(exit.length, 2);
assert.equal(exit[0].length, 2);
assert.equal(exit[1].length, 2);
......@@ -133,6 +135,7 @@ suite.addBatch({
},
"observes the specified key function": function(span) {
var update = span.data([1, 2], Number);
assert.isFalse(update.empty());
assert.equal(update.length, 2);
assert.equal(update[0].length, 2);
assert.equal(update[1].length, 2);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment