Skip to content

Commit b96e4e3

Browse files
committed
Select the document element, not the document.
Fixes d3#1219.
1 parent d8c14b9 commit b96e4e3

5 files changed

Lines changed: 17 additions & 7 deletions

File tree

d3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ d3 = function() {
10881088
}
10891089
return d3_transition(subgroups, id);
10901090
};
1091-
var d3_selectionRoot = d3_selection([ [ d3_document ] ]);
1091+
var d3_selectionRoot = d3_selection([ [ d3_selectRoot ] ]);
10921092
d3_selectionRoot[0].parentNode = d3_selectRoot;
10931093
d3.select = function(selector) {
10941094
return typeof selector === "string" ? d3_selectionRoot.select(selector) : d3_selection([ [ selector ] ]);

d3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/selection/selection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import "node";
5151
import "enter";
5252
import "transition";
5353

54-
var d3_selectionRoot = d3_selection([[d3_document]]);
54+
var d3_selectionRoot = d3_selection([[d3_selectRoot]]);
5555

5656
d3_selectionRoot[0].parentNode = d3_selectRoot;
5757

test/selection/selection-test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ var suite = vows.describe("d3.selection");
77
suite.addBatch({
88
"selection": {
99
topic: load("selection/selection").document(),
10-
"selects the document": function(d3) {
10+
"selects the document element": function(d3) {
1111
var selection = d3.selection();
1212
assert.equal(selection.length, 1);
1313
assert.equal(selection[0].length, 1);
14-
assert.equal(selection[0][0].nodeType, 9);
14+
assert.equal(selection[0][0].nodeType, 1);
15+
assert.equal(selection[0][0].tagName, "HTML");
16+
},
17+
"the parentNode is also the document element": function(d3) {
18+
var parentNode = d3.selection()[0].parentNode;
19+
assert.equal(parentNode.nodeType, 1);
20+
assert.equal(parentNode.tagName, "HTML");
1521
},
1622
"is an instanceof d3.selection": function(d3) {
1723
assert.instanceOf(d3.selection(), d3.selection);

test/transition/transition-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ var suite = vows.describe("d3.transition");
77
suite.addBatch({
88
"transition": {
99
topic: load("transition/transition").document(),
10-
"selects the document": function(d3) {
11-
assert.domEqual(d3.transition()[0][0].nodeType, 9);
10+
"selects the document element": function(d3) {
11+
var transition = d3.transition();
12+
assert.equal(transition.length, 1);
13+
assert.equal(transition[0].length, 1);
14+
assert.equal(transition[0][0].nodeType, 1);
15+
assert.equal(transition[0][0].tagName, "HTML");
1216
},
1317
"is an instanceof d3.transition": function(d3) {
1418
assert.isTrue(d3.transition() instanceof d3.transition);

0 commit comments

Comments
 (0)