Socket
Socket
Sign inDemoInstall

d3-selection

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-selection - npm Package Compare versions

Comparing version 0.5.1 to 0.6.0

src/matcher.js

2

build/bundle.js

@@ -1,1 +0,1 @@

var version = "0.5.1"; export * from "../index"; export {version};
var version = "0.6.0"; export * from "../index"; export {version};

@@ -13,4 +13,5 @@ (function (global, factory) {

function noop() {};
var filterEvents = {};
exports.event = null;

@@ -25,55 +26,8 @@

function selection_on(type, listener, capture) {
var n = arguments.length,
key = "__on" + type,
filter,
root = this._root;
if (n < 2) return (n = this.node()[key]) && n._listener;
if (n < 3) capture = false;
if ((n = type.indexOf(".")) > 0) type = type.slice(0, n);
if (filter = filterEvents.hasOwnProperty(type)) type = filterEvents[type];
function add() {
var ancestor = root, i = arguments.length >> 1, ancestors = new Array(i);
while (--i >= 0) ancestor = ancestor[arguments[(i << 1) + 1]], ancestors[i] = i ? ancestor._parent : ancestor;
var l = listenerOf(listener, ancestors, arguments);
if (filter) l = filterListenerOf(l);
remove.call(this);
this.addEventListener(type, this[key] = l, l._capture = capture);
l._listener = listener;
}
function remove() {
var l = this[key];
if (l) {
this.removeEventListener(type, l, l._capture);
delete this[key];
}
}
function removeAll() {
var re = new RegExp("^__on([^.]+)" + requote(type) + "$"), match;
for (var name in this) {
if (match = name.match(re)) {
var l = this[name];
this.removeEventListener(match[1], l, l._capture);
delete this[name];
}
}
}
return this.each(listener
? (n ? add : noop) // Attempt to add untyped listener is ignored.
: (n ? remove : removeAll));
};
function listenerOf(listener, ancestors, args) {
function contextListener(listener, index, group) {
return function(event1) {
var i = ancestors.length, event0 = exports.event; // Events can be reentrant (e.g., focus).
while (--i >= 0) args[i << 1] = ancestors[i].__data__;
var event0 = exports.event; // Events can be reentrant (e.g., focus).
exports.event = event1;
try {
listener.apply(ancestors[0], args);
listener.call(this, this.__data__, index, group);
} finally {

@@ -85,3 +39,3 @@ exports.event = event0;

function filterListenerOf(listener) {
function filterListener(listener) {
return function(event) {

@@ -95,4 +49,53 @@ var related = event.relatedTarget;

function noop() {}
function onRemove(key, type) {
return function() {
var l = this[key];
if (l) {
this.removeEventListener(type, l, l._capture);
delete this[key];
}
};
}
function onRemoveAll(dotname) {
var re = new RegExp("^__on([^.]+)" + requote(dotname) + "$");
return function() {
for (var key in this) {
var match = key.match(re);
if (match) {
var l = this[key];
this.removeEventListener(match[1], l, l._capture);
delete this[key];
}
}
};
}
function onAdd(filter, key, type, listener, capture) {
if (capture == null) capture = false;
return function(d, i, group) {
var value = this[key];
if (value) this.removeEventListener(type, value, value._capture);
value = contextListener(listener, i, group);
if (filter) value = filterListener(value);
this.addEventListener(type, this[key] = value, value._capture = capture);
value._listener = listener;
};
}
function selection_on(type, listener, capture) {
var value,
name = type + "",
key = "__on" + name,
filter;
if (arguments.length < 2) return (value = this.node()[key]) && value._listener;
if ((value = name.indexOf(".")) > 0) name = name.slice(0, value);
if (filter = filterEvents.hasOwnProperty(name)) name = filterEvents[name];
return this.each(listener
? (value ? onAdd(filter, key, type, listener, capture) : noop) // Attempt to add untyped listener is ignored.
: (value ? onRemove(key, name) : onRemoveAll(name)));
};
function sourceEvent() {

@@ -111,15 +114,2 @@ var current = exports.event, source;

function selection_dispatch(type, params) {
function dispatchConstant() {
return dispatchEvent(this, type, params);
}
function dispatchFunction() {
return dispatchEvent(this, type, params.apply(this, arguments));
}
return this.each(typeof params === "function" ? dispatchFunction : dispatchConstant);
};
function dispatchEvent(node, type, params) {

@@ -140,11 +130,33 @@ var window = defaultView$1(node),

function dispatchConstant(type, params) {
return function() {
return dispatchEvent(this, type, params);
};
}
function dispatchFunction(type, params) {
return function() {
return dispatchEvent(this, type, params.apply(this, arguments));
};
}
function selection_dispatch(type, params) {
return this.each((typeof params === "function"
? dispatchFunction
: dispatchConstant)(type, params));
};
function selection_datum(value) {
return arguments.length ? this.property("__data__", value) : this.node().__data__;
return arguments.length
? this.property("__data__", value)
: this.node().__data__;
};
function remove() {
var parent = this.parentNode;
if (parent) parent.removeChild(this);
}
function selection_remove() {
return this.each(function() {
var parent = this.parentNode;
if (parent) parent.removeChild(this);
});
return this.each(remove);
};

@@ -161,3 +173,3 @@

function namespace(name) {
var i = name.indexOf(":"), prefix = name;
var prefix = name += "", i = prefix.indexOf(":");
if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);

@@ -167,3 +179,3 @@ return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;

function selectorOf(selector) {
function selector(selector) {
return function() {

@@ -174,111 +186,112 @@ return this.querySelector(selector);

function selection_append(creator, selector) {
if (typeof creator !== "function") creator = creatorOf(creator);
function creatorInherit(name) {
return function() {
var document = this.ownerDocument,
uri = this.namespaceURI;
return uri
? document.createElementNS(uri, name)
: document.createElement(name);
};
}
function append() {
return this.appendChild(creator.apply(this, arguments));
}
function creatorFixed(fullname) {
return function() {
return this.ownerDocument.createElementNS(fullname.space, fullname.local);
};
}
function insert() {
return this.insertBefore(creator.apply(this, arguments), selector.apply(this, arguments) || null);
}
function creator(name) {
var fullname = namespace(name);
return (fullname.local
? creatorFixed
: creatorInherit)(fullname);
}
function append(create) {
return function() {
return this.appendChild(create.apply(this, arguments));
};
}
function insert(create, select) {
return function() {
return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
};
}
function selection_append(name, before) {
var create = typeof name === "function" ? name : creator(name);
return this.select(arguments.length < 2
? append
: (typeof selector !== "function" && (selector = selectorOf(selector)), insert));
? append(create)
: insert(create, typeof before === "function" ? before : selector(before)));
};
function creatorOf(name) {
name = namespace(name);
function lower() {
this.parentNode.insertBefore(this, this.parentNode.firstChild);
}
function creator() {
var document = this.ownerDocument,
uri = this.namespaceURI;
return uri
? document.createElementNS(uri, name)
: document.createElement(name);
}
function selection_lower() {
return this.each(lower);
};
function creatorNS() {
return this.ownerDocument.createElementNS(name.space, name.local);
}
return name.local ? creatorNS : creator;
function raise() {
this.parentNode.appendChild(this);
}
function selection_html(value) {
if (!arguments.length) return this.node().innerHTML;
function selection_raise() {
return this.each(raise);
};
function setConstant() {
function htmlConstant(value) {
if (value == null) value = "";
return function() {
this.innerHTML = value;
}
};
}
function setFunction() {
function htmlFunction(value) {
return function() {
var v = value.apply(this, arguments);
this.innerHTML = v == null ? "" : v;
}
};
}
if (value == null) value = "";
return this.each(typeof value === "function" ? setFunction : setConstant);
function selection_html(value) {
return arguments.length
? this.each((typeof value === "function"
? htmlFunction
: htmlConstant)(value))
: this.node().innerHTML;
};
function selection_text(value) {
if (!arguments.length) return this.node().textContent;
function setConstant() {
this.textContent = value;
}
function setFunction() {
function textFunction(value) {
return function() {
var v = value.apply(this, arguments);
this.textContent = v == null ? "" : v;
}
};
}
if (value == null) value = "";
return this.each(typeof value === "function" ? setFunction : setConstant);
function selection_text(value) {
return arguments.length
? this.each((typeof value === "function"
? textFunction
: textContent)(value))
: this.node().textContent;
};
function selection_classed(name, value) {
name = (name + "").trim().split(/^|\s+/);
var n = name.length;
function collapse(string) {
return string.trim().replace(/\s+/g, " ");
}
if (arguments.length < 2) {
var node = this.node(), i = -1;
if (value = node.classList) { // SVG elements may not support DOMTokenList!
while (++i < n) if (!value.contains(name[i])) return false;
} else {
value = node.getAttribute("class");
while (++i < n) if (!classedRe(name[i]).test(value)) return false;
}
return true;
}
name = name.map(classerOf);
function setConstant() {
var i = -1;
while (++i < n) name[i](this, value);
}
function setFunction() {
var i = -1, x = value.apply(this, arguments);
while (++i < n) name[i](this, x);
}
return this.each(typeof value === "function" ? setFunction : setConstant);
};
function classerOf(name) {
function classer(name) {
var re;
return function(node, value) {
if (c = node.classList) return value ? c.add(name) : c.remove(name);
if (!re) re = classedRe(name);
var c = node.getAttribute("class") || "";
if (classes = node.classList) return value ? classes.add(name) : classes.remove(name);
if (!re) re = classedRe(name); // Create only if classList is missing.
var classes = node.getAttribute("class") || "";
if (value) {
re.lastIndex = 0;
if (!re.test(c)) node.setAttribute("class", collapse(c + " " + name));
if (!re.test(classes)) node.setAttribute("class", collapse(classes + " " + name));
} else {
node.setAttribute("class", collapse(c.replace(re, " ")));
node.setAttribute("class", collapse(classes.replace(re, " ")));
}

@@ -288,6 +301,2 @@ };

function collapse(string) {
return string.trim().replace(/\s+/g, " ");
}
function classedRe(name) {

@@ -297,122 +306,149 @@ return new RegExp("(?:^|\\s+)" + requote(name) + "(?:\\s+|$)", "g");

function selection_property(name, value) {
if (arguments.length < 2) return this.node()[name];
function selection_classed(name, value) {
var names = (name + "").trim().split(/^|\s+/);
function remove() {
delete this[name];
if (arguments.length < 2) {
var node = this.node(),
i = -1,
n = names.length,
classes = node.classList;
if (classes) { // SVG elements may not support DOMTokenList!
while (++i < n) if (!classes.contains(names[i])) return false;
} else {
classes = node.getAttribute("class") || "";
while (++i < n) if (!classedRe(names[i]).test(classes)) return false;
}
return true;
}
function setConstant() {
return this.each((typeof value === "function"
? setFunction
: setConstant)(names.map(classer), value));
};
function propertyRemove(name) {
return function() {
delete this[name];
};
}
function propertyConstant(name, value) {
return function() {
this[name] = value;
}
};
}
function setFunction() {
var x = value.apply(this, arguments);
if (x == null) delete this[name];
else this[name] = x;
}
function propertyFunction(name, value) {
return function() {
var v = value.apply(this, arguments);
if (v == null) delete this[name];
else this[name] = v;
};
}
return this.each(value == null ? remove : typeof value === "function" ? setFunction : setConstant);
function selection_property(name, value) {
return arguments.length > 1
? this.each((value == null
? propertyRemove : typeof value === "function"
? propertyFunction
: propertyConstant)(name, value))
: this.node()[name];
};
function selection_style(name, value, priority) {
var n = arguments.length;
if (n < 2) return defaultView$1(n = this.node()).getComputedStyle(n, null).getPropertyValue(name);
if (n < 3) priority = "";
function remove() {
function styleRemove(name) {
return function() {
this.style.removeProperty(name);
}
};
}
function setConstant() {
function styleConstant(name, value, priority) {
return function() {
this.style.setProperty(name, value, priority);
}
};
}
function setFunction() {
var x = value.apply(this, arguments);
if (x == null) this.style.removeProperty(name);
else this.style.setProperty(name, x, priority);
}
function styleFunction(name, value, priority) {
return function() {
var v = value.apply(this, arguments);
if (v == null) this.style.removeProperty(name);
else this.style.setProperty(name, v, priority);
};
}
return this.each(value == null ? remove : typeof value === "function" ? setFunction : setConstant);
function selection_style(name, value, priority) {
var node;
return arguments.length > 1
? this.each((value == null
? styleRemove : typeof value === "function"
? styleFunction
: styleConstant)(name, value, priority == null ? "" : priority))
: defaultView$1(node = this.node())
.getComputedStyle(node, null)
.getPropertyValue(name);
};
function selection_attr(name, value) {
name = namespace(name);
if (arguments.length < 2) {
var node = this.node();
return name.local
? node.getAttributeNS(name.space, name.local)
: node.getAttribute(name);
}
function remove() {
function attrRemove(name) {
return function() {
this.removeAttribute(name);
}
};
}
function removeNS() {
this.removeAttributeNS(name.space, name.local);
}
function attrRemoveNS(fullname) {
return function() {
this.removeAttributeNS(fullname.space, fullname.local);
};
}
function setConstant() {
function attrConstant(name, value) {
return function() {
this.setAttribute(name, value);
}
};
}
function setConstantNS() {
this.setAttributeNS(name.space, name.local, value);
}
function attrConstantNS(fullname, value) {
return function() {
this.setAttributeNS(fullname.space, fullname.local, value);
};
}
function setFunction() {
var x = value.apply(this, arguments);
if (x == null) this.removeAttribute(name);
else this.setAttribute(name, x);
}
function attrFunction(name, value) {
return function() {
var v = value.apply(this, arguments);
if (v == null) this.removeAttribute(name);
else this.setAttribute(name, v);
};
}
function setFunctionNS() {
var x = value.apply(this, arguments);
if (x == null) this.removeAttributeNS(name.space, name.local);
else this.setAttributeNS(name.space, name.local, x);
function attrFunctionNS(fullname, value) {
return function() {
var v = value.apply(this, arguments);
if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
else this.setAttributeNS(fullname.space, fullname.local, v);
};
}
function selection_attr(name, value) {
var fullname = namespace(name);
if (arguments.length < 2) {
var node = this.node();
return fullname.local
? node.getAttributeNS(fullname.space, fullname.local)
: node.getAttribute(fullname);
}
return this.each(value == null
? (name.local ? removeNS : remove)
: (typeof value === "function"
? (name.local ? setFunctionNS : setFunction)
: (name.local ? setConstantNS : setConstant)));
return this.each((value == null
? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
? (fullname.local ? attrFunctionNS : attrFunction)
: (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
};
function selection_each(callback) {
var depth = this._depth,
stack = new Array(depth);
function visit(nodes, depth) {
var i = -1,
n = nodes.length,
node;
if (--depth) {
var stack0 = depth * 2,
stack1 = stack0 + 1;
while (++i < n) {
if (node = nodes[i]) {
stack[stack0] = node._parent.__data__, stack[stack1] = i;
visit(node, depth);
}
}
for (var groups = this._, j = 0, m = groups.length; j < m; ++j) {
for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
if (node = group[i]) callback.call(node, node.__data__, i, group);
}
else {
while (++i < n) {
if (node = nodes[i]) {
stack[0] = node.__data__, stack[1] = i;
callback.apply(node, stack);
}
}
}
}
visit(this._root, depth);
return this;

@@ -432,28 +468,12 @@ };

function selection_node() {
return firstNode(this._root, this._depth);
};
function firstNode(nodes, depth) {
var i = -1,
n = nodes.length,
node;
if (--depth) {
while (++i < n) {
if (node = nodes[i]) {
if (node = firstNode(node, depth)) {
return node;
}
}
for (var groups = this._, j = 0, m = groups.length; j < m; ++j) {
for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
var node = group[i];
if (node) return node;
}
}
else {
while (++i < n) {
if (node = nodes[i]) {
return node;
}
}
}
}
return null;
};

@@ -468,60 +488,32 @@ function selection_nodes() {

var callback = arguments[0];
callback.apply(arguments[0] = this, arguments);
arguments[0] = this;
callback.apply(null, arguments);
return this;
};
// The leaf groups of the selection hierarchy are initially NodeList,
// and then lazily converted to arrays when mutation is required.
function arrayify(selection) {
return selection._root = arrayifyNode(selection._root, selection._depth);
};
function arrayifyNode(nodes, depth) {
var i = -1,
n = nodes.length,
node;
if (--depth) {
while (++i < n) {
if (node = nodes[i]) {
nodes[i] = arrayifyNode(node, depth);
for (var groups = selection._, j = 0, m = groups.length; j < m; ++j) {
if (!Array.isArray(group = groups[j])) {
for (var n = group.length, array = groups[j] = new Array(n), group, i = 0; i < n; ++i) {
array[i] = group[i];
}
array._parent = group._parent;
}
}
else if (!Array.isArray(nodes)) {
var array = new Array(n);
while (++i < n) array[i] = nodes[i];
array._parent = nodes._parent;
nodes = array;
}
return groups;
};
return nodes;
}
function selection_sort(compare) {
if (!compare) compare = ascending;
function selection_sort(comparator) {
if (!comparator) comparator = ascending;
function compare(a, b) {
return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
return a && b ? compare(a.__data__, b.__data__) : !a - !b;
}
function visit(nodes, depth) {
if (--depth) {
var i = -1,
n = nodes.length,
node;
while (++i < n) {
if (node = nodes[i]) {
visit(node, depth);
}
}
}
else {
nodes.sort(compare);
}
for (var groups = arrayify(this), j = 0, m = groups.length; j < m; ++j) {
groups[j].sort(compare);
}
visit(arrayify(this), this._depth);
return this.order();

@@ -535,23 +527,6 @@ };

function selection_order() {
orderNode(this._root, this._depth);
return this;
};
function orderNode(nodes, depth) {
var i = nodes.length,
node,
next;
if (--depth) {
while (--i >= 0) {
if (node = nodes[i]) {
orderNode(node, depth);
}
}
}
else {
next = nodes[--i];
while (--i >= 0) {
if (node = nodes[i]) {
for (var groups = this._, j = -1, m = groups.length; ++j < m;) {
for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
if (node = group[i]) {
if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);

@@ -562,40 +537,24 @@ next = node;

}
}
function emptyOf(selection) {
return new Selection(emptyNode(arrayify(selection), selection._depth), selection._depth);
return this;
};
function emptyNode(nodes, depth) {
var i = -1,
n = nodes.length,
node,
empty = new Array(n);
function sparse(update) {
var group = new Array(update.length);
group._parent = update._parent;
return group;
};
if (--depth) {
while (++i < n) {
if (node = nodes[i]) {
empty[i] = emptyNode(node, depth);
}
}
}
empty._parent = nodes._parent;
return empty;
}
// Lazily constructs the exit selection for this (update) selection.
// Until this selection is joined to data, the exit selection will be empty.
function selection_exit() {
return this._exit || (this._exit = emptyOf(this));
var exit = this._exit;
if (exit) return this._exit = null, exit;
return new Selection(arrayify(this).map(sparse));
};
// Lazily constructs the enter selection for this (update) selection.
// Until this selection is joined to data, the enter selection will be empty.
function selection_enter() {
if (!this._enter) {
this._enter = emptyOf(this);
this._enter._update = this;
}
return this._enter;
var enter = this._enter;
if (enter) return this._enter = null, enter;
enter = new Selection(arrayify(this).map(sparse));
enter._update = this;
return enter;
};

@@ -609,60 +568,67 @@

var keyPrefix = "$";
var keyPrefix = "$"; // Protect against keys like “__proto__”.
// The value may either be an array or a function that returns an array.
// An optional key function may be specified to control how data is bound;
// if no key function is specified, data is bound to nodes by index.
// Or, if no arguments are specified, this method returns all bound data.
function selection_data(value, key) {
if (!value) {
var data = new Array(this.size()), i = -1;
this.each(function(d) { data[++i] = d; });
return data;
function bindIndex(update, enter, exit, data) {
var i = 0,
node,
nodeLength = update.length,
dataLength = data.length,
minLength = Math.min(nodeLength, dataLength);
// Clear the enter and exit arrays, and then initialize to the new length.
enter.length = 0, enter.length = dataLength;
exit.length = 0, exit.length = nodeLength;
for (; i < minLength; ++i) {
if (node = update[i]) {
node.__data__ = data[i];
} else {
enter[i] = new EnterNode(update._parent, data[i]);
}
}
var depth = this._depth - 1,
stack = new Array(depth * 2),
bind = key ? bindKey : bindIndex,
enter = this.enter(), // Note: arrayify’s!
exit = this.exit();
// Note: we don’t need to delete update[i] here because this loop only
// runs when the data length is greater than the node length.
for (; i < dataLength; ++i) {
enter[i] = new EnterNode(update._parent, data[i]);
}
if (typeof value !== "function") value = constant(value);
// Note: and, we don’t need to delete update[i] here because immediately
// following this loop we set the update length to data length.
for (; i < nodeLength; ++i) {
if (node = update[i]) {
exit[i] = update[i];
}
}
visit(this._root, enter._root, exit._root, depth);
update.length = dataLength;
}
function visit(update, enter, exit, depth) {
var i = -1,
n,
node;
function bindKey(update, enter, exit, data, key) {
var i,
node,
dataLength = data.length,
nodeLength = update.length,
nodeByKeyValue = {},
keyValues = new Array(nodeLength),
keyValue;
if (depth--) {
var stack0 = depth * 2,
stack1 = stack0 + 1;
// Clear the enter and exit arrays, and then initialize to the new length.
enter.length = 0, enter.length = dataLength;
exit.length = 0, exit.length = nodeLength;
n = update.length;
// Compute the keys for each node.
for (i = 0; i < nodeLength; ++i) {
if (node = update[i]) {
keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, update);
while (++i < n) {
if (node = update[i]) {
stack[stack0] = node._parent.__data__, stack[stack1] = i;
visit(node, enter[i], exit[i], depth);
}
// Is this a duplicate of a key we’ve previously seen?
// If so, this node is moved to the exit selection.
if (nodeByKeyValue[keyValue]) {
exit[i] = node;
}
}
else {
var j = 0,
before;
bind(update, enter, exit, value.apply(update._parent, stack));
n = update.length;
// Now connect the enter nodes to their following update node, such that
// appendChild can insert the materialized enter node before this node,
// rather than at the end of the parent node.
while (++i < n) {
if (before = enter[i]) {
if (i >= j) j = i + 1;
while (!(node = update[j]) && ++j < n);
before._next = node || null;
}
// Otherwise, record the mapping from key to node.
else {
nodeByKeyValue[keyValue] = node;
}

@@ -672,102 +638,64 @@ }

function bindIndex(update, enter, exit, data) {
var i = 0,
node,
nodeLength = update.length,
dataLength = data.length,
minLength = Math.min(nodeLength, dataLength);
// Now clear the update array and initialize to the new length.
update.length = 0, update.length = dataLength;
// Clear the enter and exit arrays, and then initialize to the new length.
enter.length = 0, enter.length = dataLength;
exit.length = 0, exit.length = nodeLength;
// Compute the keys for each datum.
for (i = 0; i < dataLength; ++i) {
keyValue = keyPrefix + key.call(update._parent, data[i], i, data);
for (; i < minLength; ++i) {
if (node = update[i]) {
node.__data__ = data[i];
} else {
enter[i] = new EnterNode(update._parent, data[i]);
}
}
// Note: we don’t need to delete update[i] here because this loop only
// runs when the data length is greater than the node length.
for (; i < dataLength; ++i) {
// Is there a node associated with this key?
// If not, this datum is added to the enter selection.
if (!(node = nodeByKeyValue[keyValue])) {
enter[i] = new EnterNode(update._parent, data[i]);
}
// Note: and, we don’t need to delete update[i] here because immediately
// following this loop we set the update length to data length.
for (; i < nodeLength; ++i) {
if (node = update[i]) {
exit[i] = update[i];
}
// Did we already bind a node using this key? (Or is a duplicate?)
// If unique, the node and datum are joined in the update selection.
// Otherwise, the datum is ignored, neither entering nor exiting.
else if (node !== true) {
update[i] = node;
node.__data__ = data[i];
}
update.length = dataLength;
// Record that we consumed this key, either to enter or update.
nodeByKeyValue[keyValue] = true;
}
function bindKey(update, enter, exit, data) {
var i,
node,
dataLength = data.length,
nodeLength = update.length,
nodeByKeyValue = {},
keyStack = new Array(2).concat(stack),
keyValues = new Array(nodeLength),
keyValue;
// Clear the enter and exit arrays, and then initialize to the new length.
enter.length = 0, enter.length = dataLength;
exit.length = 0, exit.length = nodeLength;
// Compute the keys for each node.
for (i = 0; i < nodeLength; ++i) {
if (node = update[i]) {
keyStack[0] = node.__data__, keyStack[1] = i;
keyValues[i] = keyValue = keyPrefix + key.apply(node, keyStack);
// Is this a duplicate of a key we’ve previously seen?
// If so, this node is moved to the exit selection.
if (nodeByKeyValue[keyValue]) {
exit[i] = node;
}
// Otherwise, record the mapping from key to node.
else {
nodeByKeyValue[keyValue] = node;
}
}
// Take any remaining nodes that were not bound to data,
// and place them in the exit selection.
for (i = 0; i < nodeLength; ++i) {
if ((node = nodeByKeyValue[keyValues[i]]) !== true) {
exit[i] = node;
}
}
}
// Now clear the update array and initialize to the new length.
update.length = 0, update.length = dataLength;
function selection_data(value, key) {
if (!value) {
var data = new Array(this.size()), i = -1;
this.each(function(d) { data[++i] = d; });
return data;
}
// Compute the keys for each datum.
for (i = 0; i < dataLength; ++i) {
keyStack[0] = data[i], keyStack[1] = i;
keyValue = keyPrefix + key.apply(update._parent, keyStack);
var bind = key ? bindKey : bindIndex,
update = this._,
enter = (this._enter = this.enter())._, // Note: arrayify’s!
exit = (this._exit = this.exit())._;
// Is there a node associated with this key?
// If not, this datum is added to the enter selection.
if (!(node = nodeByKeyValue[keyValue])) {
enter[i] = new EnterNode(update._parent, data[i]);
}
if (typeof value !== "function") value = constant(value);
// Did we already bind a node using this key? (Or is a duplicate?)
// If unique, the node and datum are joined in the update selection.
// Otherwise, the datum is ignored, neither entering nor exiting.
else if (node !== true) {
update[i] = node;
node.__data__ = data[i];
}
for (var m = update.length, j = 0; j < m; ++j) {
var group = update[j],
parent = group._parent;
// Record that we consumed this key, either to enter or update.
nodeByKeyValue[keyValue] = true;
}
bind(group, enter[j], exit[j], value.call(parent, parent && parent.__data__, j, group), key);
// Take any remaining nodes that were not bound to data,
// and place them in the exit selection.
for (i = 0; i < nodeLength; ++i) {
if ((node = nodeByKeyValue[keyValues[i]]) !== true) {
exit[i] = node;
// Now connect the enter nodes to their following update node, such that
// appendChild can insert the materialized enter node before this node,
// rather than at the end of the parent node.
for (var n = group.length, i0 = 0, i1 = 0, previous, next; i0 < n; ++i0) {
if (previous = enter[j][i0]) {
if (i0 >= i1) i1 = i0 + 1;
while (!(next = group[i1]) && ++i1 < n);
previous._next = next || null;
}

@@ -791,53 +719,7 @@ }

insertBefore: function(child, next) { return this._parent.insertBefore(child, next || this._next); },
querySelector: function(selector) { return this._parent.querySelector(selector); }
querySelector: function(selector) { return this._parent.querySelector(selector); },
querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
};
// The filter may either be a selector string (e.g., ".foo")
// or a function that returns a boolean.
function selection_filter(filter) {
var depth = this._depth,
stack = new Array(depth * 2);
if (typeof filter !== "function") filter = filterOf(filter);
function visit(nodes, depth) {
var i = -1,
n = nodes.length,
node,
subnodes;
if (--depth) {
var stack0 = depth * 2,
stack1 = stack0 + 1;
subnodes = new Array(n);
while (++i < n) {
if (node = nodes[i]) {
stack[stack0] = node._parent.__data__, stack[stack1] = i;
subnodes[i] = visit(node, depth);
}
}
}
// The filter operation does not preserve the original index,
// so the resulting leaf groups are dense (not sparse).
else {
subnodes = [];
while (++i < n) {
if (node = nodes[i]) {
stack[0] = node.__data__, stack[1] = i;
if (filter.apply(node, stack)) {
subnodes.push(node);
}
}
}
}
subnodes._parent = nodes._parent;
return subnodes;
}
return new Selection(visit(this._root, depth), depth);
};
var filterOf = function(selector) {
var matcher = function(selector) {
return function() {

@@ -851,121 +733,75 @@ return this.matches(selector);

if (!element$1.matches) {
var vendorMatches = element$1.webkitMatchesSelector || element$1.msMatchesSelector || element$1.mozMatchesSelector || element$1.oMatchesSelector;
filterOf = function(selector) { return function() { return vendorMatches.call(this, selector); }; };
var vendorMatches = element$1.webkitMatchesSelector
|| element$1.msMatchesSelector
|| element$1.mozMatchesSelector
|| element$1.oMatchesSelector;
matcher = function(selector) {
return function() {
return vendorMatches.call(this, selector);
};
};
}
}
// The selector may either be a selector string (e.g., ".foo")
// or a function that optionally returns an array of nodes to select.
// This is the only operation that increases the depth of a selection.
function selection_selectAll(selector) {
var depth = this._depth,
stack = new Array(depth * 2);
var matcher$1 = matcher;
if (typeof selector !== "function") selector = selectorAllOf(selector);
function selection_filter(match) {
if (typeof match !== "function") match = matcher$1(match);
function visit(nodes, depth) {
var i = -1,
n = nodes.length,
node,
subnode,
subnodes = new Array(n);
if (--depth) {
var stack0 = depth * 2,
stack1 = stack0 + 1;
while (++i < n) {
if (node = nodes[i]) {
stack[stack0] = node._parent.__data__, stack[stack1] = i;
subnodes[i] = visit(node, depth);
}
for (var groups = this._, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
subgroup.push(node);
}
}
// Data is not propagated since there is a one-to-many mapping.
// The parent of the new leaf group is the old node.
else {
while (++i < n) {
if (node = nodes[i]) {
stack[0] = node.__data__, stack[1] = i;
subnodes[i] = subnode = selector.apply(node, stack);
subnode._parent = node;
}
}
}
subnodes._parent = nodes._parent;
return subnodes;
subgroup._parent = group._parent;
}
return new Selection(visit(this._root, depth), depth + 1);
return new Selection(subgroups);
};
function selectorAllOf(selector) {
function selectorAll(selector) {
return function() {
return this.querySelectorAll(selector);
};
}
};
// The selector may either be a selector string (e.g., ".foo")
// or a function that optionally returns the node to select.
function selection_select(selector) {
var depth = this._depth,
stack = new Array(depth * 2);
function selection_selectAll(select) {
if (typeof select !== "function") select = selectorAll(select);
if (typeof selector !== "function") selector = selectorOf(selector);
function visit(nodes, update, depth) {
var i = -1,
n = nodes.length,
node,
subnode,
subnodes = new Array(n);
if (--depth) {
var stack0 = depth * 2,
stack1 = stack0 + 1;
while (++i < n) {
if (node = nodes[i]) {
stack[stack0] = node._parent.__data__, stack[stack1] = i;
subnodes[i] = visit(node, update && update[i], depth);
}
for (var groups = this._, m = groups.length, subgroups = [], j = 0; j < m; ++j) {
for (var group = groups[j], n = group.length, subgroup, node, i = 0; i < n; ++i) {
if (node = group[i]) {
subgroups.push(subgroup = select.call(node, node.__data__, i, group));
subgroup._parent = node;
}
}
}
// The leaf group may be sparse if the selector returns a falsey value;
// this preserves the index of nodes (unlike selection.filter).
// Propagate data to the new node only if it is defined on the old.
// If this is an enter selection, materialized nodes are moved to update.
else {
while (++i < n) {
if (node = nodes[i]) {
stack[0] = node.__data__, stack[1] = i;
if (subnode = selector.apply(node, stack)) {
if ("__data__" in node) subnode.__data__ = node.__data__;
if (update) update[i] = subnode, delete nodes[i];
subnodes[i] = subnode;
}
}
return new Selection(subgroups);
};
function selection_select(select) {
if (typeof select !== "function") select = selector(select);
for (var groups = this._, update = this._update, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
if ("__data__" in node) subnode.__data__ = node.__data__;
if (update) update._[j][i] = subnode;
subgroup[i] = subnode;
}
}
subnodes._parent = nodes._parent;
return subnodes;
subgroup._parent = group._parent;
}
return new Selection(visit(this._root, this._update && this._update._root, depth), depth);
return new Selection(subgroups);
};
// When depth = 1, root = [Node, …].
// When depth = 2, root = [[Node, …], …].
// When depth = 3, root = [[[Node, …], …], …]. etc.
// Note that [Node, …] and NodeList are used interchangeably; see arrayify.
function Selection(root, depth) {
this._root = root;
this._depth = depth;
this._enter = this._update = this._exit = null;
function Selection(groups) {
this._ = groups;
};
function selection() {
return new Selection([document.documentElement], 1);
return new Selection([[document.documentElement]]);
}

@@ -994,2 +830,4 @@

html: selection_html,
raise: selection_raise,
lower: selection_lower,
append: selection_append,

@@ -1003,3 +841,3 @@ remove: selection_remove,

function select(selector) {
return new Selection([typeof selector === "string" ? document.querySelector(selector) : selector], 1);
return new Selection([[typeof selector === "string" ? document.querySelector(selector) : selector]]);
};

@@ -1032,3 +870,3 @@

function mouse(node, event) {
if (arguments.length < 2) event = sourceEvent();
if (event == null) event = sourceEvent();
if (event.changedTouches) event = event.changedTouches[0];

@@ -1039,7 +877,7 @@ return point(node, event);

function selectAll(selector) {
return new Selection(typeof selector === "string" ? document.querySelectorAll(selector) : selector, 1);
return new Selection([typeof selector === "string" ? document.querySelectorAll(selector) : selector]);
};
function touch(node, touches, identifier) {
if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
if (identifier == null) identifier = touches, touches = sourceEvent().changedTouches;
for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {

@@ -1054,3 +892,3 @@ if ((touch = touches[i]).identifier === identifier) {

function touches(node, touches) {
if (arguments.length < 2) touches = sourceEvent().touches;
if (touches == null) touches = sourceEvent().touches;
for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {

@@ -1062,3 +900,3 @@ points[i] = point(node, touches[i]);

var version = "0.5.1";
var version = "0.6.0";

@@ -1069,3 +907,2 @@ exports.version = version;

exports.namespaces = namespaces;
exports.requote = requote;
exports.select = select;

@@ -1072,0 +909,0 @@ exports.selectAll = selectAll;

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define("d3-selection",["exports"],e):e(t.d3_selection={})}(this,function(t){"use strict";function e(t){return t.replace(rt,"\\$&")}function n(t,n,a){function u(){for(var e=p,o=arguments.length>>1,u=new Array(o);--o>=0;)e=e[arguments[(o<<1)+1]],u[o]=o?e._parent:e;var c=r(n,u,arguments);l&&(c=i(c)),s.call(this),this.addEventListener(t,this[f]=c,c._capture=a),c._listener=n}function s(){var e=this[f];e&&(this.removeEventListener(t,e,e._capture),delete this[f])}function c(){var n,r=new RegExp("^__on([^.]+)"+e(t)+"$");for(var i in this)if(n=i.match(r)){var o=this[i];this.removeEventListener(n[1],o,o._capture),delete this[i]}}var l,h=arguments.length,f="__on"+t,p=this._root;return 2>h?(h=this.node()[f])&&h._listener:(3>h&&(a=!1),(h=t.indexOf("."))>0&&(t=t.slice(0,h)),(l=it.hasOwnProperty(t))&&(t=it[t]),this.each(n?h?u:o:h?s:c))}function r(e,n,r){return function(i){for(var o=n.length,a=t.event;--o>=0;)r[o<<1]=n[o].__data__;t.event=i;try{e.apply(n[0],r)}finally{t.event=a}}}function i(t){return function(e){var n=e.relatedTarget;n&&(n===this||8&n.compareDocumentPosition(this))||t(e)}}function o(){}function a(){for(var e,n=t.event;e=n.sourceEvent;)n=e;return n}function u(t){return t&&(t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView)}function s(t,e){function n(){return c(this,t,e)}function r(){return c(this,t,e.apply(this,arguments))}return this.each("function"==typeof e?r:n)}function c(t,e,n){var r=u(t),i=r.CustomEvent;i?i=new i(e,n):(i=r.document.createEvent("Event"),n?(i.initEvent(e,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(e,!1,!1)),t.dispatchEvent(i)}function l(t){return arguments.length?this.property("__data__",t):this.node().__data__}function h(){return this.each(function(){var t=this.parentNode;t&&t.removeChild(this)})}function f(t){var e=t.indexOf(":"),n=t;return e>=0&&"xmlns"!==(n=t.slice(0,e))&&(t=t.slice(e+1)),at.hasOwnProperty(n)?{space:at[n],local:t}:t}function p(t){return function(){return this.querySelector(t)}}function _(t,e){function n(){return this.appendChild(t.apply(this,arguments))}function r(){return this.insertBefore(t.apply(this,arguments),e.apply(this,arguments)||null)}return"function"!=typeof t&&(t=d(t)),this.select(arguments.length<2?n:("function"!=typeof e&&(e=p(e)),r))}function d(t){function e(){var e=this.ownerDocument,n=this.namespaceURI;return n?e.createElementNS(n,t):e.createElement(t)}function n(){return this.ownerDocument.createElementNS(t.space,t.local)}return t=f(t),t.local?n:e}function g(t){function e(){this.innerHTML=t}function n(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}return arguments.length?(null==t&&(t=""),this.each("function"==typeof t?n:e)):this.node().innerHTML}function m(t){function e(){this.textContent=t}function n(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}return arguments.length?(null==t&&(t=""),this.each("function"==typeof t?n:e)):this.node().textContent}function v(t,e){function n(){for(var n=-1;++n<i;)t[n](this,e)}function r(){for(var n=-1,r=e.apply(this,arguments);++n<i;)t[n](this,r)}t=(t+"").trim().split(/^|\s+/);var i=t.length;if(arguments.length<2){var o=this.node(),a=-1;if(e=o.classList){for(;++a<i;)if(!e.contains(t[a]))return!1}else for(e=o.getAttribute("class");++a<i;)if(!A(t[a]).test(e))return!1;return!0}return t=t.map(y),this.each("function"==typeof e?r:n)}function y(t){var e;return function(n,r){if(i=n.classList)return r?i.add(t):i.remove(t);e||(e=A(t));var i=n.getAttribute("class")||"";r?(e.lastIndex=0,e.test(i)||n.setAttribute("class",w(i+" "+t))):n.setAttribute("class",w(i.replace(e," ")))}}function w(t){return t.trim().replace(/\s+/g," ")}function A(t){return new RegExp("(?:^|\\s+)"+e(t)+"(?:\\s+|$)","g")}function x(t,e){function n(){delete this[t]}function r(){this[t]=e}function i(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}return arguments.length<2?this.node()[t]:this.each(null==e?n:"function"==typeof e?i:r)}function b(t,e,n){function r(){this.style.removeProperty(t)}function i(){this.style.setProperty(t,e,n)}function o(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}var a=arguments.length;return 2>a?u(a=this.node()).getComputedStyle(a,null).getPropertyValue(t):(3>a&&(n=""),this.each(null==e?r:"function"==typeof e?o:i))}function S(t,e){function n(){this.removeAttribute(t)}function r(){this.removeAttributeNS(t.space,t.local)}function i(){this.setAttribute(t,e)}function o(){this.setAttributeNS(t.space,t.local,e)}function a(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}function u(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}if(t=f(t),arguments.length<2){var s=this.node();return t.local?s.getAttributeNS(t.space,t.local):s.getAttribute(t)}return this.each(null==e?t.local?r:n:"function"==typeof e?t.local?u:a:t.local?o:i)}function E(t){function e(n,i){var o,a=-1,u=n.length;if(--i)for(var s=2*i,c=s+1;++a<u;)(o=n[a])&&(r[s]=o._parent.__data__,r[c]=a,e(o,i));else for(;++a<u;)(o=n[a])&&(r[0]=o.__data__,r[1]=a,t.apply(o,r))}var n=this._depth,r=new Array(n);return e(this._root,n),this}function C(){return!this.node()}function M(){var t=0;return this.each(function(){++t}),t}function N(){return T(this._root,this._depth)}function T(t,e){var n,r=-1,i=t.length;if(--e){for(;++r<i;)if((n=t[r])&&(n=T(n,e)))return n}else for(;++r<i;)if(n=t[r])return n}function L(){var t=new Array(this.size()),e=-1;return this.each(function(){t[++e]=this}),t}function P(){var t=arguments[0];return t.apply(arguments[0]=this,arguments),this}function q(t){return t._root=D(t._root,t._depth)}function D(t,e){var n,r=-1,i=t.length;if(--e)for(;++r<i;)(n=t[r])&&(t[r]=D(n,e));else if(!Array.isArray(t)){for(var o=new Array(i);++r<i;)o[r]=t[r];o._parent=t._parent,t=o}return t}function V(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}function n(t,r){if(--r)for(var i,o=-1,a=t.length;++o<a;)(i=t[o])&&n(i,r);else t.sort(e)}return t||(t=B),n(q(this),this._depth),this.order()}function B(t,e){return e>t?-1:t>e?1:t>=e?0:NaN}function R(){return X(this._root,this._depth),this}function X(t,e){var n,r,i=t.length;if(--e)for(;--i>=0;)(n=t[i])&&X(n,e);else for(r=t[--i];--i>=0;)(n=t[i])&&(r&&r!==n.nextSibling&&r.parentNode.insertBefore(n,r),r=n)}function $(t){return new W(z(q(t),t._depth),t._depth)}function z(t,e){var n,r=-1,i=t.length,o=new Array(i);if(--e)for(;++r<i;)(n=t[r])&&(o[r]=z(n,e));return o._parent=t._parent,o}function I(){return this._exit||(this._exit=$(this))}function O(){return this._enter||(this._enter=$(this),this._enter._update=this),this._enter}function Y(t){return function(){return t}}function k(t,e){function n(e,r,i,o){var a,u,l=-1;if(o--){var h=2*o,f=h+1;for(a=e.length;++l<a;)(u=e[l])&&(s[h]=u._parent.__data__,s[f]=l,n(u,r[l],i[l],o))}else{var p,_=0;for(c(e,r,i,t.apply(e._parent,s)),a=e.length;++l<a;)if(p=r[l]){for(l>=_&&(_=l+1);!(u=e[_])&&++_<a;);p._next=u||null}}}function r(t,e,n,r){var i,o=0,a=t.length,u=r.length,s=Math.min(a,u);for(e.length=0,e.length=u,n.length=0,n.length=a;s>o;++o)(i=t[o])?i.__data__=r[o]:e[o]=new G(t._parent,r[o]);for(;u>o;++o)e[o]=new G(t._parent,r[o]);for(;a>o;++o)(i=t[o])&&(n[o]=t[o]);t.length=u}function i(t,n,r,i){var o,a,u,c=i.length,l=t.length,h={},f=new Array(2).concat(s),p=new Array(l);for(n.length=0,n.length=c,r.length=0,r.length=l,o=0;l>o;++o)(a=t[o])&&(f[0]=a.__data__,f[1]=o,p[o]=u=ut+e.apply(a,f),h[u]?r[o]=a:h[u]=a);for(t.length=0,t.length=c,o=0;c>o;++o)f[0]=i[o],f[1]=o,u=ut+e.apply(t._parent,f),(a=h[u])?a!==!0&&(t[o]=a,a.__data__=i[o]):n[o]=new G(t._parent,i[o]),h[u]=!0;for(o=0;l>o;++o)(a=h[p[o]])!==!0&&(r[o]=a)}if(!t){var o=new Array(this.size()),a=-1;return this.each(function(t){o[++a]=t}),o}var u=this._depth-1,s=new Array(2*u),c=e?i:r,l=this.enter(),h=this.exit();return"function"!=typeof t&&(t=Y(t)),n(this._root,l._root,h._root,u),this}function G(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function H(t){function e(n,i){var o,a,u=-1,s=n.length;if(--i){var c=2*i,l=c+1;for(a=new Array(s);++u<s;)(o=n[u])&&(r[c]=o._parent.__data__,r[l]=u,a[u]=e(o,i))}else for(a=[];++u<s;)(o=n[u])&&(r[0]=o.__data__,r[1]=u,t.apply(o,r)&&a.push(o));return a._parent=n._parent,a}var n=this._depth,r=new Array(2*n);return"function"!=typeof t&&(t=st(t)),new W(e(this._root,n),n)}function U(t){function e(n,i){var o,a,u=-1,s=n.length,c=new Array(s);if(--i)for(var l=2*i,h=l+1;++u<s;)(o=n[u])&&(r[l]=o._parent.__data__,r[h]=u,c[u]=e(o,i));else for(;++u<s;)(o=n[u])&&(r[0]=o.__data__,r[1]=u,c[u]=a=t.apply(o,r),a._parent=o);return c._parent=n._parent,c}var n=this._depth,r=new Array(2*n);return"function"!=typeof t&&(t=j(t)),new W(e(this._root,n),n+1)}function j(t){return function(){return this.querySelectorAll(t)}}function K(t){function e(n,i,o){var a,u,s=-1,c=n.length,l=new Array(c);if(--o)for(var h=2*o,f=h+1;++s<c;)(a=n[s])&&(r[h]=a._parent.__data__,r[f]=s,l[s]=e(a,i&&i[s],o));else for(;++s<c;)(a=n[s])&&(r[0]=a.__data__,r[1]=s,(u=t.apply(a,r))&&("__data__"in a&&(u.__data__=a.__data__),i&&(i[s]=u,delete n[s]),l[s]=u));return l._parent=n._parent,l}var n=this._depth,r=new Array(2*n);return"function"!=typeof t&&(t=p(t)),new W(e(this._root,this._update&&this._update._root,n),n)}function W(t,e){this._root=t,this._depth=e,this._enter=this._update=this._exit=null}function F(){return new W([document.documentElement],1)}function J(t){return new W(["string"==typeof t?document.querySelector(t):t],1)}function Q(t,e){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();if(0>ht){var i=defaultView(t);if(i.scrollX||i.scrollY){n=J(i.document.body).append("svg").style({position:"absolute",top:0,left:0,margin:0,padding:0,border:"none"},"important");var o=n.node().getScreenCTM();ht=!(o.f||o.e),n.remove()}}return ht?(r.x=e.pageX,r.y=e.pageY):(r.x=e.clientX,r.y=e.clientY),r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}var a=t.getBoundingClientRect();return[e.clientX-a.left-t.clientLeft,e.clientY-a.top-t.clientTop]}function Z(t,e){return arguments.length<2&&(e=a()),e.changedTouches&&(e=e.changedTouches[0]),Q(t,e)}function tt(t){return new W("string"==typeof t?document.querySelectorAll(t):t,1)}function et(t,e,n){arguments.length<3&&(n=e,e=a().changedTouches);for(var r,i=0,o=e?e.length:0;o>i;++i)if((r=e[i]).identifier===n)return Q(t,r);return null}function nt(t,e){arguments.length<2&&(e=a().touches);for(var n=0,r=e?e.length:0,i=new Array(r);r>n;++n)i[n]=Q(t,e[n]);return i}var rt=/[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g,it={};if(t.event=null,"undefined"!=typeof document){var ot=document.documentElement;"onmouseenter"in ot||(it={mouseenter:"mouseover",mouseleave:"mouseout"})}var at={svg:"http://www.w3.org/2000/svg",xhtml:"http://www.w3.org/1999/xhtml",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},ut="$";G.prototype={appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e||this._next)},querySelector:function(t){return this._parent.querySelector(t)}};var st=function(t){return function(){return this.matches(t)}};if("undefined"!=typeof document){var ct=document.documentElement;if(!ct.matches){var lt=ct.webkitMatchesSelector||ct.msMatchesSelector||ct.mozMatchesSelector||ct.oMatchesSelector;st=function(t){return function(){return lt.call(this,t)}}}}W.prototype=F.prototype={select:K,selectAll:U,filter:H,data:k,enter:O,exit:I,order:R,sort:V,call:P,nodes:L,node:N,size:M,empty:C,each:E,attr:S,style:b,property:x,classed:v,text:m,html:g,append:_,remove:h,datum:l,on:n,dispatch:s};var ht="undefined"!=typeof navigator&&/WebKit/.test(navigator.userAgent)?-1:0,ft="0.5.1";t.version=ft,t.mouse=Z,t.namespace=f,t.namespaces=at,t.requote=e,t.select=J,t.selectAll=tt,t.selection=F,t.touch=et,t.touches=nt});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define("d3-selection",["exports"],n):n(t.d3_selection={})}(this,function(t){"use strict";function n(t){return t.replace(Tt,"\\$&")}function e(){}function r(n,e,r){return function(i){var u=t.event;t.event=i;try{n.call(this,this.__data__,e,r)}finally{t.event=u}}}function i(t){return function(n){var e=n.relatedTarget;e&&(e===this||8&e.compareDocumentPosition(this))||t(n)}}function u(t,n){return function(){var e=this[t];e&&(this.removeEventListener(n,e,e._capture),delete this[t])}}function o(t){var e=new RegExp("^__on([^.]+)"+n(t)+"$");return function(){for(var t in this){var n=t.match(e);if(n){var r=this[t];this.removeEventListener(n[1],r,r._capture),delete this[t]}}}}function a(t,n,e,u,o){return null==o&&(o=!1),function(a,c,s){var l=this[n];l&&this.removeEventListener(e,l,l._capture),l=r(u,c,s),t&&(l=i(l)),this.addEventListener(e,this[n]=l,l._capture=o),l._listener=u}}function c(t,n,r){var i,c,s=t+"",l="__on"+s;return arguments.length<2?(i=this.node()[l])&&i._listener:((i=s.indexOf("."))>0&&(s=s.slice(0,i)),(c=Pt.hasOwnProperty(s))&&(s=Pt[s]),this.each(n?i?a(c,l,t,n,r):e:i?u(l,s):o(s)))}function s(){for(var n,e=t.event;n=e.sourceEvent;)e=n;return e}function l(t){return t&&(t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView)}function f(t,n,e){var r=l(t),i=r.CustomEvent;i?i=new i(n,e):(i=r.document.createEvent("Event"),e?(i.initEvent(n,e.bubbles,e.cancelable),i.detail=e.detail):i.initEvent(n,!1,!1)),t.dispatchEvent(i)}function h(t,n){return function(){return f(this,t,n)}}function p(t,n){return function(){return f(this,t,n.apply(this,arguments))}}function _(t,n){return this.each(("function"==typeof n?p:h)(t,n))}function v(t){return arguments.length?this.property("__data__",t):this.node().__data__}function d(){var t=this.parentNode;t&&t.removeChild(this)}function g(){return this.each(d)}function m(t){var n=t+="",e=n.indexOf(":");return e>=0&&"xmlns"!==(n=t.slice(0,e))&&(t=t.slice(e+1)),Bt.hasOwnProperty(n)?{space:Bt[n],local:t}:t}function y(t){return function(){return this.querySelector(t)}}function w(t){return function(){var n=this.ownerDocument,e=this.namespaceURI;return e?n.createElementNS(e,t):n.createElement(t)}}function x(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function A(t){var n=m(t);return(n.local?x:w)(n)}function S(t){return function(){return this.appendChild(t.apply(this,arguments))}}function b(t,n){return function(){return this.insertBefore(t.apply(this,arguments),n.apply(this,arguments)||null)}}function E(t,n){var e="function"==typeof t?t:A(t);return this.select(arguments.length<2?S(e):b(e,"function"==typeof n?n:y(n)))}function C(){this.parentNode.insertBefore(this,this.parentNode.firstChild)}function N(){return this.each(C)}function L(){this.parentNode.appendChild(this)}function M(){return this.each(L)}function T(t){return null==t&&(t=""),function(){this.innerHTML=t}}function P(t){return function(){var n=t.apply(this,arguments);this.innerHTML=null==n?"":n}}function q(t){return arguments.length?this.each(("function"==typeof t?P:T)(t)):this.node().innerHTML}function B(t){return function(){var n=t.apply(this,arguments);this.textContent=null==n?"":n}}function D(t){return arguments.length?this.each(("function"==typeof t?B:textContent)(t)):this.node().textContent}function V(t){return t.trim().replace(/\s+/g," ")}function R(t){var n;return function(e,r){if(i=e.classList)return r?i.add(t):i.remove(t);n||(n=X(t));var i=e.getAttribute("class")||"";r?(n.lastIndex=0,n.test(i)||e.setAttribute("class",V(i+" "+t))):e.setAttribute("class",V(i.replace(n," ")))}}function X(t){return new RegExp("(?:^|\\s+)"+n(t)+"(?:\\s+|$)","g")}function $(t,n){var e=(t+"").trim().split(/^|\s+/);if(arguments.length<2){var r=this.node(),i=-1,u=e.length,o=r.classList;if(o){for(;++i<u;)if(!o.contains(e[i]))return!1}else for(o=r.getAttribute("class")||"";++i<u;)if(!X(e[i]).test(o))return!1;return!0}return this.each(("function"==typeof n?setFunction:setConstant)(e.map(R),n))}function z(t){return function(){delete this[t]}}function I(t,n){return function(){this[t]=n}}function O(t,n){return function(){var e=n.apply(this,arguments);null==e?delete this[t]:this[t]=e}}function Y(t,n){return arguments.length>1?this.each((null==n?z:"function"==typeof n?O:I)(t,n)):this.node()[t]}function k(t){return function(){this.style.removeProperty(t)}}function G(t,n,e){return function(){this.style.setProperty(t,n,e)}}function H(t,n,e){return function(){var r=n.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,e)}}function U(t,n,e){var r;return arguments.length>1?this.each((null==n?k:"function"==typeof n?H:G)(t,n,null==e?"":e)):l(r=this.node()).getComputedStyle(r,null).getPropertyValue(t)}function j(t){return function(){this.removeAttribute(t)}}function F(t){return function(){this.removeAttributeNS(t.space,t.local)}}function K(t,n){return function(){this.setAttribute(t,n)}}function W(t,n){return function(){this.setAttributeNS(t.space,t.local,n)}}function J(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttribute(t):this.setAttribute(t,e)}}function Q(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,e)}}function Z(t,n){var e=m(t);if(arguments.length<2){var r=this.node();return e.local?r.getAttributeNS(e.space,e.local):r.getAttribute(e)}return this.each((null==n?e.local?F:j:"function"==typeof n?e.local?Q:J:e.local?W:K)(e,n))}function tt(t){for(var n=this._,e=0,r=n.length;r>e;++e)for(var i,u=n[e],o=0,a=u.length;a>o;++o)(i=u[o])&&t.call(i,i.__data__,o,u);return this}function nt(){return!this.node()}function et(){var t=0;return this.each(function(){++t}),t}function rt(){for(var t=this._,n=0,e=t.length;e>n;++n)for(var r=t[n],i=0,u=r.length;u>i;++i){var o=r[i];if(o)return o}return null}function it(){var t=new Array(this.size()),n=-1;return this.each(function(){t[++n]=this}),t}function ut(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this}function ot(t){for(var n=t._,e=0,r=n.length;r>e;++e)if(!Array.isArray(i=n[e])){for(var i,u=i.length,o=n[e]=new Array(u),a=0;u>a;++a)o[a]=i[a];o._parent=i._parent}return n}function at(t){function t(n,e){return n&&e?t(n.__data__,e.__data__):!n-!e}t||(t=ct);for(var n=ot(this),e=0,r=n.length;r>e;++e)n[e].sort(t);return this.order()}function ct(t,n){return n>t?-1:t>n?1:t>=n?0:NaN}function st(){for(var t=this._,n=-1,e=t.length;++n<e;)for(var r,i=t[n],u=i.length-1,o=i[u];--u>=0;)(r=i[u])&&(o&&o!==r.nextSibling&&o.parentNode.insertBefore(r,o),o=r);return this}function lt(t){var n=new Array(t.length);return n._parent=t._parent,n}function ft(){var t=this._exit;return t?(this._exit=null,t):new At(ot(this).map(lt))}function ht(){var t=this._enter;return t?(this._enter=null,t):(t=new At(ot(this).map(lt)),t._update=this,t)}function pt(t){return function(){return t}}function _t(t,n,e,r){var i,u=0,o=t.length,a=r.length,c=Math.min(o,a);for(n.length=0,n.length=a,e.length=0,e.length=o;c>u;++u)(i=t[u])?i.__data__=r[u]:n[u]=new gt(t._parent,r[u]);for(;a>u;++u)n[u]=new gt(t._parent,r[u]);for(;o>u;++u)(i=t[u])&&(e[u]=t[u]);t.length=a}function vt(t,n,e,r,i){var u,o,a,c=r.length,s=t.length,l={},f=new Array(s);for(n.length=0,n.length=c,e.length=0,e.length=s,u=0;s>u;++u)(o=t[u])&&(f[u]=a=Dt+i.call(o,o.__data__,u,t),l[a]?e[u]=o:l[a]=o);for(t.length=0,t.length=c,u=0;c>u;++u)a=Dt+i.call(t._parent,r[u],u,r),(o=l[a])?o!==!0&&(t[u]=o,o.__data__=r[u]):n[u]=new gt(t._parent,r[u]),l[a]=!0;for(u=0;s>u;++u)(o=l[f[u]])!==!0&&(e[u]=o)}function dt(t,n){if(!t){var e=new Array(this.size()),r=-1;return this.each(function(t){e[++r]=t}),e}var i=n?vt:_t,u=this._,o=(this._enter=this.enter())._,a=(this._exit=this.exit())._;"function"!=typeof t&&(t=pt(t));for(var c=u.length,s=0;c>s;++s){var l=u[s],f=l._parent;i(l,o[s],a[s],t.call(f,f&&f.__data__,s,l),n);for(var h,p,_=l.length,v=0,d=0;_>v;++v)if(h=o[s][v]){for(v>=d&&(d=v+1);!(p=l[d])&&++d<_;);h._next=p||null}}return this}function gt(t,n){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=n}function mt(t){"function"!=typeof t&&(t=$t(t));for(var n=this._,e=n.length,r=new Array(e),i=0;e>i;++i){for(var u,o=n[i],a=o.length,c=r[i]=[],s=0;a>s;++s)(u=o[s])&&t.call(u,u.__data__,s,o)&&c.push(u);c._parent=o._parent}return new At(r)}function yt(t){return function(){return this.querySelectorAll(t)}}function wt(t){"function"!=typeof t&&(t=yt(t));for(var n=this._,e=n.length,r=[],i=0;e>i;++i)for(var u,o,a=n[i],c=a.length,s=0;c>s;++s)(o=a[s])&&(r.push(u=t.call(o,o.__data__,s,a)),u._parent=o);return new At(r)}function xt(t){"function"!=typeof t&&(t=y(t));for(var n=this._,e=this._update,r=n.length,i=new Array(r),u=0;r>u;++u){for(var o,a,c=n[u],s=c.length,l=i[u]=new Array(s),f=0;s>f;++f)(o=c[f])&&(a=t.call(o,o.__data__,f,c))&&("__data__"in o&&(a.__data__=o.__data__),e&&(e._[u][f]=a),l[f]=a);l._parent=c._parent}return new At(i)}function At(t){this._=t}function St(){return new At([[document.documentElement]])}function bt(t){return new At([["string"==typeof t?document.querySelector(t):t]])}function Et(t,n){var e=t.ownerSVGElement||t;if(e.createSVGPoint){var r=e.createSVGPoint();if(0>zt){var i=defaultView(t);if(i.scrollX||i.scrollY){e=bt(i.document.body).append("svg").style({position:"absolute",top:0,left:0,margin:0,padding:0,border:"none"},"important");var u=e.node().getScreenCTM();zt=!(u.f||u.e),e.remove()}}return zt?(r.x=n.pageX,r.y=n.pageY):(r.x=n.clientX,r.y=n.clientY),r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}var o=t.getBoundingClientRect();return[n.clientX-o.left-t.clientLeft,n.clientY-o.top-t.clientTop]}function Ct(t,n){return null==n&&(n=s()),n.changedTouches&&(n=n.changedTouches[0]),Et(t,n)}function Nt(t){return new At(["string"==typeof t?document.querySelectorAll(t):t])}function Lt(t,n,e){null==e&&(e=n,n=s().changedTouches);for(var r,i=0,u=n?n.length:0;u>i;++i)if((r=n[i]).identifier===e)return Et(t,r);return null}function Mt(t,n){null==n&&(n=s().touches);for(var e=0,r=n?n.length:0,i=new Array(r);r>e;++e)i[e]=Et(t,n[e]);return i}var Tt=/[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g,Pt={};if(t.event=null,"undefined"!=typeof document){var qt=document.documentElement;"onmouseenter"in qt||(Pt={mouseenter:"mouseover",mouseleave:"mouseout"})}var Bt={svg:"http://www.w3.org/2000/svg",xhtml:"http://www.w3.org/1999/xhtml",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},Dt="$";gt.prototype={appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,n){return this._parent.insertBefore(t,n||this._next)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var Vt=function(t){return function(){return this.matches(t)}};if("undefined"!=typeof document){var Rt=document.documentElement;if(!Rt.matches){var Xt=Rt.webkitMatchesSelector||Rt.msMatchesSelector||Rt.mozMatchesSelector||Rt.oMatchesSelector;Vt=function(t){return function(){return Xt.call(this,t)}}}}var $t=Vt;At.prototype=St.prototype={select:xt,selectAll:wt,filter:mt,data:dt,enter:ht,exit:ft,order:st,sort:at,call:ut,nodes:it,node:rt,size:et,empty:nt,each:tt,attr:Z,style:U,property:Y,classed:$,text:D,html:q,raise:M,lower:N,append:E,remove:g,datum:v,on:c,dispatch:_};var zt="undefined"!=typeof navigator&&/WebKit/.test(navigator.userAgent)?-1:0,It="0.6.0";t.version=It,t.mouse=Ct,t.namespace=m,t.namespaces=Bt,t.select=bt,t.selectAll=Nt,t.selection=St,t.touch=Lt,t.touches=Mt});
export {default as mouse} from "./src/mouse";
export {default as namespace} from "./src/namespace";
export {default as namespaces} from "./src/namespaces";
export {default as requote} from "./src/requote";
export {default as select} from "./src/select";
export {default as selectAll} from "./src/selectAll";
export {default as selection} from "./src/selection";
export {default as selection} from "./src/selection/index";
export {default as touch} from "./src/touch";
export {default as touches} from "./src/touches";
export {event} from "./src/selection-on"
export {event} from "./src/selection/on"
{
"name": "d3-selection",
"version": "0.5.1",
"version": "0.6.0",
"description": "Data-driven DOM manipulation: select elements and join them to data.",

@@ -5,0 +5,0 @@ "keywords": [

# d3-selection
Selections allow powerful data-driven transformation of the document object model (DOM): set [attributes](#selection_attr), [styles](#selection_style), [properties](#selection_property), [HTML](#selection_html) or [text](#selection_text) content, and more. Using the [data join](#data)’s [enter](#selection_enter) and [exit](#selection_enter) selections, you can also [add](#selection_append) or [remove](#selection_remove) elements to correspond to data.
Selections allow powerful data-driven transformation of the document object model (DOM): set [attributes](#selection_attr), [styles](#selection_style), [properties](#selection_property), [HTML](#selection_html) or [text](#selection_text) content, and more. Using the [data join](#binding-data)’s [enter](#selection_enter) and [exit](#selection_enter) selections, you can also [add](#selection_append) or [remove](#selection_remove) elements to correspond to data.

@@ -10,3 +10,3 @@ ## Installing

```html
<script src="https://d3js.org/d3-selection.v0.5.min.js"></script>
<script src="https://d3js.org/d3-selection.v0.6.min.js"></script>
```

@@ -18,16 +18,16 @@

* [Selection](#selection)
* [Transformation](#transformation)
* [Data](#data)
* [Events](#events)
* [Control](#control)
* [Selecting Elements](#selecting-elements)
* [Modifying Elements](#modifying-elements)
* [Binding Data](#binding-data)
* [Handling Events](#handling-events)
* [Control Flow](#control-flow)
* [Namespaces](#namespaces)
### Selection
### Selecting Elements
Selection methods accept [W3C selector strings](http://www.w3.org/TR/selectors-api/) such as `.foo` to select elements with the class *foo*, or `div` to select DIV elements. Selection methods come in two forms: select and selectAll: the former selects only the first matching element, while the latter selects all matching elements in traversal order. The top-level selection methods, [d3.select](#select) and [d3.selectAll](#selectAll), query the entire document; the subselection methods, in contrast, [*selection*.select](#selection_select) and [*selection*.selectAll](#selection_selectAll), restrict selection to descendants of the selected elements.
Selection methods accept [W3C selector strings](http://www.w3.org/TR/selectors-api/) such as `.fancy` to select elements with the class *fancy*, or `div` to select DIV elements. Selection methods come in two forms: select and selectAll: the former selects only the first matching element, while the latter selects all matching elements in document order. The top-level selection methods, [d3.select](#select) and [d3.selectAll](#selectAll), query the entire document; the subselection methods, [*selection*.select](#selection_select) and [*selection*.selectAll](#selection_selectAll), restrict selection to descendants of the selected elements.
<a name="selection" href="#selection">#</a> d3.<b>selection</b>()
[Selects](#select) the root element, `document.documentElement`. This function can also be used to check if an object is a selection (`instanceof selection`) or to extend the selection prototype. For example, to add a method to check or uncheck input checkboxes:
[Selects](#select) the root element, `document.documentElement`. This function can also be used to check if an object is a selection (`instanceof selection`) or to extend the selection prototype. For example, to add a method to check checkboxes:

@@ -42,3 +42,3 @@ ```js

And then to check all checkboxes:
And then to use:

@@ -51,3 +51,3 @@ ```js

Selects the first element that matches the specified *selector*. If no elements match the *selector*, returns an empty selection. If multiple elements match the *selector*, only the first matching element (in traversal order) will be selected. For example, to select the first anchor element:
Selects the first element that matches the specified *selector* string. If no elements match the *selector*, returns an empty selection. If multiple elements match the *selector*, only the first matching element(in document order will be selected. For example, to select the first anchor element:

@@ -58,3 +58,3 @@ ```js

If the *selector* is not a string, instead selects the specified node; this is useful if you already have a reference to a node, such as `this` within an event listener or a global such as `document.body`. For example, to make the text of any clicked paragraph red:
If the *selector* is not a string, instead selects the specified node; this is useful if you already have a reference to a node, such as `this` within an event listener or a global such as `document.body`. For example, to make a clicked paragraph red:

@@ -69,3 +69,3 @@ ```js

Selects all elements that match the specified *selector*. The elements will be selected in traversal order (top-to-bottom). If no elements in the document match the *selector*, returns an empty selection. For example, to select all paragraphs:
Selects all elements that match the specified *selector* string. The elements will be selected in document order (top-to-bottom). If no elements in the document match the *selector*, returns an empty selection. For example, to select all paragraphs:

@@ -84,3 +84,3 @@ ```js

For each selected element, selects the first descendant element that matches the specified *selector*. If no element matches the specified selector for the current element, the element at the current index will be null in the returned selection, preserving the index of the existing selection. (Operators automatically skip null elements.) If the current element has associated data, this data is propagated to the newly selected elements. If multiple elements match the selector, only the first matching element (in traversal order) is selected. For example, to select the first bold element in every paragraph:
For each selected element, selects the first descendant element that matches the specified *selector* string. If no element matches the specified selector for the current element, the element at the current index will be null in the returned selection. If the current element has associated data, this data is propagated to the corresponding selected element. If multiple elements match the selector, only the first matching element in document order is selected. For example, to select the first bold element in every paragraph:

@@ -91,3 +91,3 @@ ```js

If the *selector* is a function, it will be invoked in the same manner as other operator functions, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. It must then return an element, or null if there is no matching element. For example, to select the previous sibling of each paragraph:
If the *selector* is a function, it is evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. It must return an element, or null if there is no matching element. For example, to select the previous sibling of each paragraph:

@@ -100,7 +100,7 @@ ```js

Unlike [*selection*.selectAll](#selection_selectAll), *selection*.select does not affect grouping: it preserves the existing grouping and propagates parent data (if any) to selected children. Grouping plays an important role in the [data join](#data). See [Nested Selections](http://bost.ocks.org/mike/nest/) for more on this topic.
Unlike [*selection*.selectAll](#selection_selectAll), *selection*.select does not affect grouping: it preserves the existing group structure and indexes, and propagates data (if any) to selected children. Grouping plays an important role in the [data join](#binding-data). See [Nested Selections](http://bost.ocks.org/mike/nest/) and [How Selections Work](http://bost.ocks.org/mike/selection/) for more on this topic.
<a name="selection_selectAll" href="#selection_selectAll">#</a> <i>selection</i>.<b>selectAll</b>(<i>selector</i>)
For each selected element, selects all descendant elements that match the specified *selector*. The returned selection is grouped by its parent node in the current selection. If no element matches the specified selector for the current element, the group at the current index will be empty in the returned selection. The subselection does not inherit data from the current selection; use [*selection*.data](#selection_data) to propagate data to children. For example, to select the bold elements in every paragraph:
For each selected element, selects the descendant elements that match the specified *selector* string. The elements in the returned selection are grouped by their corresponding parent node in this selection. If no element matches the specified selector for the current element, the group at the current index will be empty. The selected elements do not inherit data from the current selection; use [*selection*.data](#selection_data) to propagate data to children. For example, to select the bold elements in every paragraph:

@@ -111,3 +111,3 @@ ```js

If the *selector* is a function, it will be invoked in the same manner as other operator functions, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. It must then return an array of elements (or a psuedo-array, such as a NodeList), or the empty array if there are no matching elements. For example, to select the previous and next siblings of each paragraph:
If the *selector* is a function, it is evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. It must return an array of elements (or a psuedo-array, such as a NodeList), or the empty array if there are no matching elements. For example, to select the previous and next siblings of each paragraph:

@@ -123,29 +123,37 @@ ```js

Unlike [*selection*.select](#selection_select), *selection*.selectAll does affect grouping: each selected descendant is grouped by the parent element in the originating selection. Grouping plays an important role in the [data join](#data). See [Nested Selections](http://bost.ocks.org/mike/nest/) for more on this topic.
Unlike [*selection*.select](#selection_select), *selection*.selectAll does affect grouping: each selected descendant is grouped by the parent element in the originating selection. Grouping plays an important role in the [data join](#binding-data). See [Nested Selections](http://bost.ocks.org/mike/nest/) and [How Selections Work](http://bost.ocks.org/mike/selection/) for more on this topic.
<a name="selection_filter" href="#selection_filter">#</a> <i>selection</i>.<b>filter</b>(<i>filter</i>)
Filters the selection, returning a new selection that contains only the elements for which the specified *filter* is true. The *filter* may be specified either as a function or as a selector string, such as `.foo`. If a function, it is passed the current datum `d` and index `i`, with the `this` context as the current DOM element. For example, to select every element with an odd index (relative to the zero-based index):
Filters the selection, returning a new selection that contains only the elements for which the specified *filter* is true. The *filter* may be specified either as a selector string or a function. If a function, it is evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. For example, to filter a selection of table rows to contain only even rows:
```js
var odd = selection.select(function(d, i) { return i % 2 === 1 ? this : null; });
var even = d3.selectAll("tr").filter(":nth-child(even)");
```
Equivalently, using a filter function:
Equivalently, using [d3.selectAll](#selectAll) directly:
```js
var odd = selection.filter(function(d, i) { return i % 2 === 1; });
var even = d3.selectAll("tr:nth-child(even)");
```
Or a filter selector (note that the `:nth-child` pseudo-class is a one-based index rather than a zero-based index):
Similarly, using a function:
```js
var odd = selection.filter(":nth-child(even)");
var even = d3.selectAll("tr").filter(function(d, i) { return i & 1; });
```
Or using [*selection*.select](#selection_select):
```js
var even = d3.selectAll("tr").select(function(d, i) { return i & 1 ? this : null; });
```
Note that the `:nth-child` pseudo-class is a one-based index rather than a zero-based index. Also, the above filter functions do not have precisely the same meaning as `:nth-child`; they rely on the selection index rather than the number of preceeding sibling elements in the DOM.
The returned selection may not preserve the index of the original selection, as some elements may be removed; you can use [*selection*.select](#selection_select) to preserve the index, if needed.
### Transformation
### Modifying Elements
Selections expose a variety of operators to affect document content. Selection operators return the current selection, allowing the concise application of multiple operators on a given selection via method chaining. For example, to see the name attribute and color style of an anchor element:
After selecting elements, use the selection’s transformation methods to affect document content. Selection methods return the current selection, allowing the concise application of multiple methods on a given selection via method chaining. For example, to set the name attribute and color style of an anchor element:

@@ -166,7 +174,7 @@ ```js

To learn selections experientially, go to [d3js.org](https://d3js.org) and try selecting elements in your browser’s developer console! (In Chrome, open the console with ⌥⌘J.) Inspect the returned selection to see which elements are selected and how they are grouped. Apply operators to the selection and see how the page content changes.
To experiment with selections, visit [d3js.org](https://d3js.org) and open your browser’s developer console! (In Chrome, open the console with ⌥⌘J.) Select elements and then inspect the returned selection to see which elements are selected and how they are grouped. Call selection methods and see how the page content changes.
<a name="selection_attr" href="#selection_attr">#</a> <i>selection</i>.<b>attr</b>(<i>name</i>[, <i>value</i>])
If a *value* is specified, sets the attribute with the specified *name* to the specified value on the selected elements and returns this selection. If the *value* is a constant, then all elements are given the same attribute value; otherwise, if the *value* is a function, the function is evaluated for each selected element (in order), being passed the current datum *d* and the current index *i*, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s attribute. A null value will remove the specified attribute.
If a *value* is specified, sets the attribute with the specified *name* to the specified value on the selected elements and returns this selection. If the *value* is a constant, all elements are given the same attribute value; otherwise, if the *value* is a function, the function is evaluated for each selected element, in order, being passed the current datum *d* and index *i*, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s attribute. A null value will remove the specified attribute.

@@ -185,3 +193,3 @@ If a *value* is not specified, returns the current value of the specified attribute for the first (non-null) element in the selection. This is generally useful only if you know that the selection contains exactly one element.

If the *value* is truthy, then all elements are assigned the specified *classes*; otherwise, the classes are unassigned. If the *value* is a function, then the function is evaluated for each selected element (in order), being passed the current datum *d* and the current index *i*, with the `this` context as the current DOM element. The function’s return value is then used to assign or unassign classes on each element. For example, to randomly associate the class *foo* with on average half the selected elements:
If the *value* is truthy, then all elements are assigned the specified *classes*; otherwise, the classes are unassigned. If the *value* is a function, then the function is evaluated for each selected element, in order, being passed the current datum *d* and index *i*, with the `this` context as the current DOM element. The function’s return value is then used to assign or unassign classes on each element. For example, to randomly associate the class *foo* with on average half the selected elements:

@@ -196,3 +204,3 @@ ```js

If a *value* is specified, sets the style property with the specified *name* to the specified value on the selected elements and returns this selection. If the *value* is a constant, then all elements are given the same style property value; otherwise, if the *value* is a function, then the function is evaluated for each selected element (in order), being passed the current datum *d* and the current index *i*, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s style property. A null value will remove the style property. An optional *priority* may also be specified, either as null or the string `important` (without the exclamation point).
If a *value* is specified, sets the style property with the specified *name* to the specified value on the selected elements and returns this selection. If the *value* is a constant, then all elements are given the same style property value; otherwise, if the *value* is a function, then the function is evaluated for each selected element, in order, being passed the current datum *d* and index *i*, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s style property. A null value will remove the style property. An optional *priority* may also be specified, either as null or the string `important` (without the exclamation point).

@@ -205,5 +213,5 @@ If a *value* is not specified, returns the current computed value of the specified style property for the first (non-null) element in the selection. This is generally useful only if you know the selection contains exactly one element. The computed value **may be different than the previously-set value**, particularly if it was set using a shorthand property (such as the `font` style, which is shorthand for `font-size`, `font-face`, etc.).

Some HTML elements have special properties that are not addressable using attributes or styles, such as a form field’s text `value` and a checkbox’s `checked` boolean. Use this operator to get or set these properties.
Some HTML elements have special properties that are not addressable using attributes or styles, such as a form field’s text `value` and a checkbox’s `checked` boolean. Use this method to get or set these properties.
If a *value* is specified, sets the property with the specified *name* to the specified value on selected elements. If the *value* is a constant, then all elements are given the same property value; otherwise, if the *value* is a function, then the function is evaluated for each selected element (in order), being passed the current datum *d* and the current index *i*, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s property. A null value will delete the specified property.
If a *value* is specified, sets the property with the specified *name* to the specified value on selected elements. If the *value* is a constant, then all elements are given the same property value; otherwise, if the *value* is a function, then the function is evaluated for each selected element, in order, being passed the current datum *d* and index *i*, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s property. A null value will delete the specified property.

@@ -214,6 +222,4 @@ If a *value* is not specified, returns the value of the specified property for the first (non-null) element in the selection. This is generally useful only if you know the selection contains exactly one element.

The text operator is based on the [textContent](http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent) property; setting the text content will replace any existing child elements.
If a *value* is specified, sets the [text content](http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent) to the specified value on all selected elements, replacing any existing child elements. If the *value* is a constant, then all elements are given the same text content; otherwise, if the *value* is a function, then the function is evaluated for each selected element, in order, being passed the current datum *d* and index *i*, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s text content. A null value will clear the content.
If a *value* is specified, sets the text content to the specified value on all selected elements. If the *value* is a constant, then all elements are given the same text content; otherwise, if the *value* is a function, then the function is evaluated for each selected element (in order), being passed the current datum *d* and the current index *i*, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s text content. A null value will clear the content.
If a *value* is not specified, returns the text content for the first (non-null) element in the selection. This is generally useful only if you know the selection contains exactly one element.

@@ -223,13 +229,11 @@

The html operator is based on the [innerHTML](http://dev.w3.org/html5/spec-LC/apis-in-html-documents.html#innerhtml) property; setting the inner HTML will replace any existing child elements. Also, you may prefer to use [*selection*.append](#selection_append) to create HTML content in a data-driven way; this operator is intended for when you want a little bit of HTML, say for rich formatting.
If a *value* is specified, sets the [inner HTML](http://dev.w3.org/html5/spec-LC/apis-in-html-documents.html#innerhtml) to the specified value on all selected elements, replacing any existing child elements. If the *value* is a constant, then all elements are given the same inner HTML; otherwise, if the *value* is a function, then the function is evaluated for each selected element, in order, being passed the current datum *d* and index *i*, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s inner HTML. A null value will clear the content.
If a *value* is specified, sets the inner HTML to the specified value on all selected elements. If the *value* is a constant, then all elements are given the same inner HTML; otherwise, if the *value* is a function, then the function is evaluated for each selected element (in order), being passed the current datum *d* and the current index *i*, with the `this` context as the current DOM element. The function’s return value is then used to set each element’s inner HTML. A null value will clear the content.
If a *value* is not specified, returns the inner HTML for the first (non-null) element in the selection. This is generally useful only if you know the selection contains exactly one element.
As the name suggests, *selection*.html is only supported on HTML elements. SVG elements and other non-HTML elements do not support the innerHTML property, and thus are incompatible with *selection*.html. Consider using [XMLSerializer](https://developer.mozilla.org/en-US/docs/XMLSerializer) to convert a DOM subtree to text. See also the [innersvg polyfill](https://code.google.com/p/innersvg/), which provides a shim to support the innerHTML property on SVG elements.
Use [*selection*.append](#selection_append) instead to create data-driven content; this method is intended for when you want a little bit of HTML, say for rich formatting. Also, *selection*.html is only supported on HTML elements. SVG elements and other non-HTML elements do not support the innerHTML property, and thus are incompatible with *selection*.html. Consider using [XMLSerializer](https://developer.mozilla.org/en-US/docs/XMLSerializer) to convert a DOM subtree to text. See also the [innersvg polyfill](https://code.google.com/p/innersvg/), which provides a shim to support the innerHTML property on SVG elements.
<a name="selection_append" href="#selection_append">#</a> <i>selection</i>.<b>append</b>(<i>type</i>[, <i>before</i>])
If the specified *type* is a string, appends a new element of this type (tag name) as the last child of each element in the current selection. Otherwise, the *type* may be a function which is evaluated for each selected element (in order), being passed the current datum *d* and the current index *i*, with the `this` context as the current DOM element. This function should return an element to be appended. (Typically, the function creates a new element, but it may return an existing element instead.) For example, to append a DIV element to each paragraph:
If the specified *type* is a string, appends a new element of this type (tag name) as the last child of each element in the current selection. Otherwise, the *type* may be a function which is evaluated for each selected element, in order, being passed the current datum *d* and index *i*, with the `this` context as the current DOM element. This function should return an element to be appended. Typically, the function creates a new element, but it may instead return an existing element. For example, to append a DIV element to each paragraph:

@@ -250,3 +254,3 @@ ```js

An optional *before* selector string or function may be specified. For instance, the selector `:first-child` will prepend nodes before the first child, rather than after the last child. If no *before* selector is specified on an [enter selection](#selection_enter), then entering elements are inserted immediately before the next following sibling in the update selection, if any. This allows you to insert elements into the DOM in an order consistent with bound data. Note, however, the slower [*selection*.order](#selection_order) may still be required if updating elements change order.
An optional *before* selector string or function may be specified. For instance, the selector `:first-child` will prepend nodes before the first child, rather than after the last child. If no *before* selector is specified on an [enter selection](#selection_enter), entering elements are inserted immediately before the next following sibling in the update selection, if any. This allows you to insert elements into the DOM in an order consistent with bound data. Note, however, the slower [*selection*.order](#selection_order) may still be required if updating elements change order.

@@ -257,7 +261,7 @@ The specified *name* may have a namespace prefix, such as `svg:text` to specify a `text` attribute in the SVG namespace. See [namespaces](#namespaces) for the map of supported namespaces; additional namespaces can be registered by adding to the map. If no namespace is specified, the namespace will be inherited from the parent element; or, if the name is one of the known prefixes, the corresponding namespace will be used (for example, `svg` implies `svg:svg`).

Removes the selected elements from the document. Returns this selection (the removed elements) which are now detached from the DOM. Note that there is not currently a dedicated API to add removed elements back to the document; however, you can pass a function to [*selection*.append](#selection_append) to re-add elements.
Removes the selected elements from the document. Returns this selection (the removed elements) which are now detached from the DOM. There is not currently a dedicated API to add removed elements back to the document; however, you can pass a function to [*selection*.append](#selection_append) to re-add elements.
<a name="selection_sort" href="#selection_sort">#</a> <i>selection</i>.<b>sort</b>(<i>comparator</i>)
Sorts the selected elements according to the *comparator* function, and then re-inserts the document elements to match the resulting order. Returns this selection.
Sorts each group of selected elements in-place according to the *comparator* function, and then re-inserts the document elements to match the resulting order. Returns this selection.

@@ -270,8 +274,28 @@ The comparator function, which defaults to [ascending](https://github.com/d3/d3-array#ascending), is passed two elements’ data *a* and *b* to compare. It should return either a negative, positive, or zero value. If negative, then *a* should be before *b*; if positive, then *a* should be after *b*; otherwise, *a* and *b* are considered equal and the order is arbitrary.

Re-inserts elements into the document such that the document order matches the selection order. This is equivalent to calling [*selection*.sort](#selection_sort) if the data is already sorted, but much faster.
Re-inserts elements into the document such that the document order of each group matches the selection order. This is equivalent to calling [*selection*.sort](#selection_sort) if the data is already sorted, but much faster.
### Data
<a name="selection_raise" href="#selection_raise">#</a> <i>selection</i>.<b>raise</b>()
For an introduction to D3’s data joins, see [Thinking With Joins](http://bost.ocks.org/mike/join/). Also see the [General Update Pattern](http://bl.ocks.org/mbostock/3808218) example thread.
Re-inserts each selected element, in order, as the last child of its parent. Equivalent to:
```js
selection.each(function() {
this.parentNode.appendChild(this);
});
```
<a name="selection_lower" href="#selection_lower">#</a> <i>selection</i>.<b>lower</b>()
Re-inserts each selected element, in order, as the first child of its parent. Equivalent to:
```js
selection.each(function() {
this.parentNode.insertBefore(this, this.parentNode.firstChild);
});
```
### Joining Data
For an introduction to D3’s data joins, see [Thinking With Joins](http://bost.ocks.org/mike/join/). Also see the [General Update Pattern](http://bl.ocks.org/mbostock/3808218) examples.
<a name="selection_data" href="#selection_data">#</a> <i>selection</i>.<b>data</b>([<i>data</i>[, <i>key</i>]])

@@ -281,3 +305,3 @@

The *data* is specified **for each group** in the selection. If the selection has multiple groups (such as [d3.selectAll](#selectAll) followed by [*selection*.selectAll](#selection_selectAll)), then *data* should typically be specified as a function. This function will be invoked for each group, being passed the parent datum *d* (which may be undefined) and the group index *i*, with the parent element as the `this` context. For example, to create an HTML table from a matrix of numbers:
The *data* is specified **for each group** in the selection. If the selection has multiple groups (such as [d3.selectAll](#selectAll) followed by [*selection*.selectAll](#selection_selectAll)), then *data* should typically be specified as a function. This function will be invoked for each group in order, being passed the parent datum *d* (which may be undefined) and group index *i*, with the parent element as the `this` context. For example, to create an HTML table from a matrix of numbers:

@@ -303,5 +327,5 @@ ```js

The *data* function here is the identity function: it is invoked for each table row, and returns the numbers for each table cell.
In this example the *data* function is the identity function: for each table row, it returns the corresponding row from the data matrix.
If a *key* is not specified, then the first datum in *data* is assigned to the first selected element, the second datum to the second selected element, and so on. A *key* function may be specified to control how data is assigned to elements, replacing the default join-by-index. This key function is evaluated for each selected element (in order), being passed the current datum *d* and the current index *i*, with the `this` context as the current DOM element. The key function is also evaluated for each new datum in *data*, being passed the datum `d`, the index `i`, with the `this` context as the parent DOM element. The datum for a given key is assigned to the element with the matching key. For example, given this document:
If a *key* function is not specified, then the first datum in *data* is assigned to the first selected element, the second datum to the second selected element, and so on. A *key* function may be specified to control which datum is assigned to which element, replacing the default join-by-index. This key function is evaluated for each selected element, in order, being passed the current datum *d* and index *i*, with the `this` context as the current DOM element. The key function is then also evaluated for each new datum in *data*, being passed the datum `d` and index `i`, with the `this` context as the parent DOM element. The datum for a given key is assigned to the element with the matching key. For example, given this document:

@@ -335,5 +359,5 @@ ```html

This key function uses the bound datum *d* if present, and otherwise falls back to the element’s id property.
This key function uses the datum *d* if present, and otherwise falls back to the element’s id property. Since these elements were not previously bound to data, the datum *d* is null when the key function is evaluated on selected elements, and non-null when the key function is evaluated on the new data.
The *update* and *enter* selections are returned in data order, while the *exit* selection preserves the order prior to the data join. If a key function is specified, the order of elements in the selection may not match their order in the document; use [*selection*.order](#order) or [*selection*.sort](#sort) as needed. For more on how the key function affects the join, see [A Bar Chart, Part 2](http://bost.ocks.org/mike/bar/2/).
The *update* and *enter* selections are returned in data order, while the *exit* selection preserves the selection order prior to the join. If a key function is specified, the order of elements in the selection may not match their order in the document; use [*selection*.order](#order) or [*selection*.sort](#sort) as needed. For more on how the key function affects the join, see [A Bar Chart, Part 2](http://bost.ocks.org/mike/bar/2/) and [Object Constancy](http://bost.ocks.org/mike/constancy/).

@@ -346,4 +370,6 @@ If *data* is not specified, this method returns the array of data for the selected elements.

Returns the enter selection: placeholder nodes for each datum that had no corresponding DOM element in the selection. The enter selection is always empty until the selection is joined to data by [*selection*.data](#selection_data). The enter selection is typically used to create “missing” elements from new data. For example, to create DIV elements from an array of numbers:
Returns the enter selection: placeholder nodes for each datum that had no corresponding DOM element in the selection. The enter selection is determined by the previous [*selection*.data](#selection_data), and is thus empty until the selection is joined to data. If the enter selection is retrieved more than once after a data join, subsequent calls return the empty selection.
The enter selection is typically used to create “missing” elements corresponding to new data. For example, to create DIV elements from an array of numbers:
```js

@@ -368,3 +394,3 @@ var div = d3.select("body").selectAll("div");

The enter selection **merges into the update selection** on [append](#selection_append). Rather than applying the same operators to the enter and update selections separately, apply them once to the update selection *after* entering nodes. For example:
The enter selection **merges into the update selection** on [append](#selection_append) or [select](#selection_select). This enables you to first modify entering and updating elements separately, as needed, and then modify entering and updating elements together, avoiding duplicate code. For example:

@@ -374,6 +400,6 @@ ```js

circle.data(data);
circle.attr(…); // applies to updating (old) elements only
circle.enter().append("circle").attr(…); // applies to entering (new) elements only
circle.attr(…); // applies to BOTH updating and entering elements
circle.exit().remove(); // removes exiting elements
circle.exit().remove(); // remove exiting elements
circle.attr(…); // modify ONLY updating elements
circle.enter().append("circle").attr(…); // modify ONLY entering elements
circle.attr(…); // modify BOTH updating AND entering elements
```

@@ -383,4 +409,6 @@

Returns the exit selection: existing DOM elements in the selection for which no new datum was found. The exit selection is always empty until the selection is joined to data by [*selection*.data](#selection_data). The exit selection is typically used to remove “superfluous” elements from old data. For example, to update the DIV elements created previously with a new array of numbers:
Returns the exit selection: existing DOM elements in the selection for which no new datum was found. The exit selection is determined by the previous [*selection*.data](#selection_data), and is thus empty until the selection is joined to data. If the exit selection is retrieved more than once after a data join, subsequent calls return the empty selection.
The exit selection is typically used to remove “superfluous” elements corresponding to old data. For example, to update the DIV elements created previously with a new array of numbers:
```js

@@ -390,3 +418,3 @@ div.data([1, 2, 4, 8, 16, 32], function(d) { return d; });

Since a key function was specified (as the identity function), and the new data contains the numbers [4, 8, 16] which match existing elements in the document, the update selection contains three DIV elements. We’ll leave those elements as-is. We can append new elements for [1, 2, 32] using the enter selection:
Since a key function was specified (as the identity function), and the new data contains the numbers [4, 8, 16] which match existing elements in the document, the update selection contains three DIV elements. Leaving those elements as-is, we can append new elements for [1, 2, 32] using the enter selection:

@@ -414,9 +442,9 @@ ```js

Note that the order of the DOM elements matches the order of the data. This is because the old data’s order and the new data’s order were consistent. If the new data’s order is different, use [*selection*.order](#selection_order) to reorder the elements in the DOM. See the [General Update Pattern](http://bl.ocks.org/mbostock/3808218) example thread for more on data joins.
The order of the DOM elements matches the order of the data because the old data’s order and the new data’s order were consistent. If the new data’s order is different, use [*selection*.order](#selection_order) to reorder the elements in the DOM. See the [General Update Pattern](http://bl.ocks.org/mbostock/3808218) example thread for more on data joins.
<a name="selection_datum" href="#selection_datum">#</a> <i>selection</i>.<b>datum</b>([<i>value</i>])
Gets or sets the bound data for each selected element. Unlike [*selection*.data](#selection_data), this method does not compute a join and thus does not affect indexes or the enter and exit selections.
Gets or sets the bound data for each selected element. Unlike [*selection*.data](#selection_data), this method does not compute a join and does not affect indexes or the enter and exit selections.
If a *value* is specified, sets the element’s bound data to the specified value on all selected elements. If the *value* is a constant, all elements are given the same datum; otherwise, if the *value* is a function, then the function is evaluated for each selected element, being passed the previous datum `d` and the current index `i`, with the `this` context as the current DOM element. The function is then used to set each element’s data. A null value will delete the bound data.
If a *value* is specified, sets the element’s bound data to the specified value on all selected elements. If the *value* is a constant, all elements are given the same datum; otherwise, if the *value* is a function, then the function is evaluated for each selected element, in order, being passed the previous datum `d` and the current index `i`, with the `this` context as the current DOM element. The function is then used to set each element’s data. A null value will delete the bound data.

@@ -440,3 +468,3 @@ If a *value* is not specified, returns the bound datum for the first (non-null) element in the selection. This is generally useful only if you know the selection contains exactly one element.

### Events
### Handling Events

@@ -447,7 +475,7 @@ For interaction, selections allow listening for and dispatching of events.

Adds or removes a *listener* to each selected element for the specified event *type*. The *type* is a string event type name, such as `click`, `mouseover`, or `submit`. (Any [DOM event type](https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events) supported by your browser may be used.) The *listener* is invoked in the same manner as other operator functions, being passed the current datum *d* and index *i*, with the `this` context as the current DOM element. Listeners always see the latest datum for their element, but the index is a property of the selection and is fixed when the listener is assigned; to update the index, re-assign the listener. To access the current event within a listener, use [d3.event](#event).
Adds or removes a *listener* to each selected element for the specified event *type*. The *type* is a string event type name, such as `click`, `mouseover`, or `submit`; any [DOM event type](https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events) supported by your browser may be used. The *listener* is invoked for each selected element, being passed the current datum *d* and index *i*, with the `this` context as the current DOM element. Listeners always see the latest datum for their element, but the index is a property of the selection and is fixed when the listener is assigned; to update the index, re-assign the listener. To access the current event within a listener, use [d3.event](#event).
If an event listener was already registered for the same *type* on a selected element, the existing listener is removed before the new listener is added. To register multiple listeners for a given type, the type may be followed by an optional namespace, such as `click.foo` and `click.bar`. To remove a listener, pass null as the *listener*. To remove all listeners for a particular namespace, pass null as the *listener* and `.foo` as the *type*, where *foo* is the namespace.
If an event listener was previously registered for the same *type* on a selected element, the old listener is removed before the new listener is added. To register multiple listeners for a given type, the type may be followed by an optional name, such as `click.foo` and `click.bar`. To remove a listener, pass null as the *listener*. To remove all listeners for a given name, pass null as the *listener* and `.foo` as the *type*, where *foo* is the name.
An optional *capture* flag may be specified, which corresponds to the W3C [useCapture flag](http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration): “After initiating capture, all events of the specified type will be dispatched to the registered EventListener before being dispatched to any EventTargets beneath them in the tree. Events which are bubbling upward through the tree will not trigger an EventListener designated to use capture.”
An optional *capture* flag may be specified which corresponds to the W3C [useCapture flag](http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration): “After initiating capture, all events of the specified type will be dispatched to the registered EventListener before being dispatched to any EventTargets beneath them in the tree. Events which are bubbling upward through the tree will not trigger an EventListener designated to use capture.”

@@ -458,10 +486,14 @@ If a *listener* is not specified, returns the currently-assigned listener for the specified event *type* on the first (non-null) selected element, if any.

Dispatches a [custom event](http://www.w3.org/TR/dom/#interface-customevent) of the specified *type* to each selected element. An optional *parameters* map may be specified to set additional properties of the event: bubbles, cancelable, and detail. If *parameters* is a function, it will be invoked in the same manner as other operator functions, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. It must then return the parameters map for the current element.
Dispatches a [custom event](http://www.w3.org/TR/dom/#interface-customevent) of the specified *type* to each selected element, in order. An optional *parameters* map may be specified to set additional properties of the event. It may contain the following fields:
* [`bubbles`](https://www.w3.org/TR/dom/#dom-event-bubbles) - if true, the event is dispatched to ancestors in reverse tree order.
* [`cancelable`](https://www.w3.org/TR/dom/#dom-event-cancelable) - if true, *event*.preventDefault is allowed.
* [`detail`](https://www.w3.org/TR/dom/#dom-customevent-detail) - any custom data associated with the event.
If *parameters* is a function, it is evaluated for each selected element, in order, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. It must return the parameters map for the current element.
<a name="event" href="#event">#</a> d3.<b>event</b>
The current [event](https://developer.mozilla.org/en-US/docs/DOM/event), if any. This is set during the invocation of an event listener, and is reset after the listener terminates. Use this to access standard event fields such as event.timeStamp, and methods such as event.preventDefault.
The current [event](https://developer.mozilla.org/en-US/docs/DOM/event), if any. This is set during the invocation of an event listener, and is reset after the listener terminates. Use this to access standard event fields such as [*event*.timeStamp](https://www.w3.org/TR/dom/#dom-event-timestamp) and methods such as [*event*.preventDefault](https://www.w3.org/TR/dom/#dom-event-preventdefault). While you can use the native [*event*.pageX](https://developer.mozilla.org/en/DOM/event.pageX) and [*event*.pageY](https://developer.mozilla.org/en/DOM/event.pageY), it is often more convenient to transform the event position to the local coordinate system of the container that received the event using [d3.mouse](#mouse), [d3.touch](#touch) or [d3.touches](#touches).
While you can use the native [event.pageX](https://developer.mozilla.org/en/DOM/event.pageX) and [event.pageY](https://developer.mozilla.org/en/DOM/event.pageY), it is often more convenient to transform the event position to the local coordinate system of the container that received the event using [d3.mouse](#mouse), [d3.touch](#touch) or [d3.touches](#touches).
<a name="mouse" href="#mouse">#</a> d3.<b>mouse</b>(<i>container</i>)

@@ -479,13 +511,13 @@

### Control
### Control Flow
For advanced usage, selections provide operators for custom control flow.
For advanced usage, selections provide methods for custom control flow.
<a name="selection_each" href="#selection_each">#</a> <i>selection</i>.<b>each</b>(<i>function</i>)
Invokes the specified *function* for each selected element, passing in the current datum `d` and index `i`, with the `this` context of the current DOM element. This operator is used internally by most other operators, and can be used to invoke arbitrary code for each selected element.
Invokes the specified *function* for each selected element, passing in the current datum `d` and index `i`, with the `this` context of the current DOM element. This method is used internally by many [transformation methods](#modifying-elements) and can be used to invoke arbitrary code for each selected element.
<a name="selection_call" href="#selection_call">#</a> <i>selection</i>.<b>call</b>(<i>selection</i>[, <i>arguments…</i>])
Invokes the specified *function* (once), passing in the current selection along with any optional *arguments*, and returns the current selection. The call operator is identical to invoking a function by hand, but it facilitates method chaining. For example, to set several attributes in a reusable function:
Invokes the specified *function* (exactly once), passing in the current selection along with any optional *arguments*. Returns the current selection. This is equivalent to invoking the function by hand but facilitates method chaining. For example, to set several attributes in a reusable function:

@@ -500,15 +532,15 @@ ```javascript

Now, we can say this:
Now say:
```javascript
name(d3.selectAll("div"), "John", "Snow");
d3.selectAll("div").call(name, "John", "Snow");
```
Or equivalently:
This is equivalent to:
```javascript
d3.selectAll("div").call(name, "John", "Snow");
name(d3.selectAll("div"), "John", "Snow");
```
The `this` context of the called function is also the current selection. This is slightly redundant with the first argument, which we might fix in the future.
The `this` context of the called function is also the current selection.

@@ -547,3 +579,3 @@ <a name="selection_empty" href="#selection_empty">#</a> <i>selection</i>.<b>empty</b>()

The map of registered namespace prefixes. The default value is:
The map of registered namespace prefixes. The initial value is:

@@ -561,9 +593,1 @@ ```js

Additional prefixes may be assigned as needed to create elements or attributes in other namespaces.
<a name="requote" href="#requote">#</a> d3.<b>requote</b>(<i>string</i>)
Returns a quoted (escaped) version of the specified *string* that may be safely embedded within a regular expression as a string literal. For example:
```js
d3.requote("[]"); // "\[\]"
```

@@ -5,5 +5,5 @@ import sourceEvent from "./sourceEvent";

export default function(node, event) {
if (arguments.length < 2) event = sourceEvent();
if (event == null) event = sourceEvent();
if (event.changedTouches) event = event.changedTouches[0];
return point(node, event);
};
import namespaces from "./namespaces";
export default function(name) {
var i = name.indexOf(":"), prefix = name;
var prefix = name += "", i = prefix.indexOf(":");
if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
};

@@ -1,5 +0,5 @@

import {Selection} from "./selection";
import {Selection} from "./selection/index";
export default function(selector) {
return new Selection([typeof selector === "string" ? document.querySelector(selector) : selector], 1);
return new Selection([[typeof selector === "string" ? document.querySelector(selector) : selector]]);
};

@@ -1,5 +0,5 @@

import {Selection} from "./selection";
import {Selection} from "./selection/index";
export default function(selector) {
return new Selection(typeof selector === "string" ? document.querySelectorAll(selector) : selector, 1);
return new Selection([typeof selector === "string" ? document.querySelectorAll(selector) : selector]);
};

@@ -1,2 +0,2 @@

import {event} from "./selection-on";
import {event} from "./selection/on";

@@ -3,0 +3,0 @@ export default function() {

@@ -5,3 +5,3 @@ import sourceEvent from "./sourceEvent";

export default function(node, touches, identifier) {
if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
if (identifier == null) identifier = touches, touches = sourceEvent().changedTouches;
for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {

@@ -8,0 +8,0 @@ if ((touch = touches[i]).identifier === identifier) {

@@ -5,3 +5,3 @@ import sourceEvent from "./sourceEvent";

export default function(node, touches) {
if (arguments.length < 2) touches = sourceEvent().touches;
if (touches == null) touches = sourceEvent().touches;
for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {

@@ -8,0 +8,0 @@ points[i] = point(node, touches[i]);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc