d3-selection
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -1,1 +0,1 @@ | ||
var version = "0.6.1"; export * from "../index"; export {version}; | ||
var version = "0.6.2"; export * from "../index"; export {version}; |
@@ -72,3 +72,2 @@ (function (global, factory) { | ||
function onAdd(filter, key, type, listener, capture) { | ||
if (capture == null) capture = false; | ||
return function(d, i, group) { | ||
@@ -79,4 +78,4 @@ var value = this[key]; | ||
if (filter) value = filterListener(value); | ||
value._listener = listener; | ||
this.addEventListener(type, this[key] = value, value._capture = capture); | ||
value._listener = listener; | ||
}; | ||
@@ -96,3 +95,3 @@ } | ||
return this.each(listener | ||
? (value ? onAdd(filter, key, type, listener, capture) : noop) // Attempt to add untyped listener is ignored. | ||
? (value ? onAdd(filter, key, name, listener, capture == null ? false : capture) : noop) // Attempt to add untyped listener is ignored. | ||
: (value ? onRemove(key, name) : onRemoveAll(name))); | ||
@@ -217,2 +216,6 @@ } | ||
function constantNull() { | ||
return null; | ||
} | ||
function selection_append(name, before) { | ||
@@ -222,3 +225,6 @@ var create = typeof name === "function" ? name : creator(name); | ||
? append(create) | ||
: insert(create, typeof before === "function" ? before : selector(before))); | ||
: insert(create, before == null | ||
? constantNull : typeof before === "function" | ||
? before | ||
: selector(before))); | ||
} | ||
@@ -242,4 +248,7 @@ | ||
function htmlRemove() { | ||
this.innerHTML = ""; | ||
} | ||
function htmlConstant(value) { | ||
if (value == null) value = ""; | ||
return function() { | ||
@@ -259,3 +268,4 @@ this.innerHTML = value; | ||
return arguments.length | ||
? this.each((typeof value === "function" | ||
? this.each(value == null | ||
? htmlRemove : (typeof value === "function" | ||
? htmlFunction | ||
@@ -266,4 +276,7 @@ : htmlConstant)(value)) | ||
function textRemove() { | ||
this.textContent = ""; | ||
} | ||
function textConstant(value) { | ||
if (value == null) value = ""; | ||
return function() { | ||
@@ -283,3 +296,4 @@ this.textContent = value; | ||
return arguments.length | ||
? this.each((typeof value === "function" | ||
? this.each(value == null | ||
? textRemove : (typeof value === "function" | ||
? textFunction | ||
@@ -290,53 +304,69 @@ : textConstant)(value)) | ||
function collapse(string) { | ||
return string.trim().replace(/\s+/g, " "); | ||
function classArray(string) { | ||
return string.trim().split(/^|\s+/); | ||
} | ||
function classer(name) { | ||
var re; | ||
return function(node, value) { | ||
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(classes)) node.setAttribute("class", collapse(classes + " " + name)); | ||
} else { | ||
node.setAttribute("class", collapse(classes.replace(re, " "))); | ||
function classList(node) { | ||
return node.classList || new ClassList(node); | ||
} | ||
function ClassList(node) { | ||
this._node = node; | ||
this._names = classArray(node.getAttribute("class") || ""); | ||
} | ||
ClassList.prototype = { | ||
add: function(name) { | ||
var i = this._names.indexOf(name); | ||
if (i < 0) { | ||
this._names.push(name); | ||
this._node.setAttribute("class", this._names.join(" ")); | ||
} | ||
}; | ||
}, | ||
remove: function(name) { | ||
var i = this._names.indexOf(name); | ||
if (i >= 0) { | ||
this._names.splice(i, 1); | ||
this._node.setAttribute("class", this._names.join(" ")); | ||
} | ||
}, | ||
contains: function(name) { | ||
return this._names.indexOf(name) >= 0; | ||
} | ||
}; | ||
function classedAdd(node, names) { | ||
var list = classList(node), i = -1, n = names.length; | ||
while (++i < n) list.add(names[i]); | ||
} | ||
function classedRe(name) { | ||
return new RegExp("(?:^|\\s+)" + requote(name) + "(?:\\s+|$)", "g"); | ||
function classedRemove(node, names) { | ||
var list = classList(node), i = -1, n = names.length; | ||
while (++i < n) list.remove(names[i]); | ||
} | ||
function classedConstant(classers, value) { | ||
function classedTrue(names) { | ||
return function() { | ||
var i = -1, n = classers.length; | ||
while (++i < n) classers[i](this, value); | ||
classedAdd(this, names); | ||
}; | ||
} | ||
function classedFunction(classers, value) { | ||
function classedFalse(names) { | ||
return function() { | ||
var i = -1, n = classers.length, v = value.apply(this, arguments); | ||
while (++i < n) classers[i](this, v); | ||
classedRemove(this, names); | ||
}; | ||
} | ||
function classedFunction(names, value) { | ||
return function() { | ||
(value.apply(this, arguments) ? classedAdd : classedRemove)(this, names); | ||
}; | ||
} | ||
function selection_classed(name, value) { | ||
var names = (name + "").trim().split(/^|\s+/); | ||
var names = classArray(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; | ||
} | ||
var list = classList(this.node()), i = -1, n = names.length; | ||
while (++i < n) if (!list.contains(names[i])) return false; | ||
return true; | ||
@@ -346,4 +376,5 @@ } | ||
return this.each((typeof value === "function" | ||
? classedFunction | ||
: classedConstant)(names.map(classer), value)); | ||
? classedFunction : value | ||
? classedTrue | ||
: classedFalse)(names, value)); | ||
} | ||
@@ -470,3 +501,3 @@ | ||
for (var groups = this._, j = 0, m = groups.length; j < m; ++j) { | ||
for (var groups = this._nodes, j = 0, m = groups.length; j < m; ++j) { | ||
for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) { | ||
@@ -492,3 +523,3 @@ if (node = group[i]) callback.call(node, node.__data__, i, group); | ||
for (var groups = this._, j = 0, m = groups.length; j < m; ++j) { | ||
for (var groups = this._nodes, j = 0, m = groups.length; j < m; ++j) { | ||
for (var group = groups[j], i = 0, n = group.length; i < n; ++i) { | ||
@@ -518,3 +549,3 @@ var node = group[i]; | ||
for (var groups = selection._, j = 0, m = groups.length; j < m; ++j) { | ||
for (var groups = selection._nodes, j = 0, m = groups.length; j < m; ++j) { | ||
if (!Array.isArray(group = groups[j])) { | ||
@@ -524,3 +555,2 @@ for (var n = group.length, array = groups[j] = new Array(n), group, i = 0; i < n; ++i) { | ||
} | ||
array._parent = group._parent; | ||
} | ||
@@ -552,3 +582,3 @@ } | ||
for (var groups = this._, j = -1, m = groups.length; ++j < m;) { | ||
for (var groups = this._nodes, j = -1, m = groups.length; ++j < m;) { | ||
for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) { | ||
@@ -566,5 +596,3 @@ if (node = group[i]) { | ||
function sparse(update) { | ||
var group = new Array(update.length); | ||
group._parent = update._parent; | ||
return group; | ||
return new Array(update.length); | ||
} | ||
@@ -575,3 +603,3 @@ | ||
if (exit) return this._exit = null, exit; | ||
return new Selection(arrayify(this).map(sparse)); | ||
return new Selection(this._nodes.map(sparse), this._parents); | ||
} | ||
@@ -582,3 +610,3 @@ | ||
if (enter) return this._enter = null, enter; | ||
enter = new Selection(arrayify(this).map(sparse)); | ||
enter = new Selection(this._nodes.map(sparse), this._parents); | ||
enter._update = this; | ||
@@ -596,3 +624,3 @@ return enter; | ||
function bindIndex(update, enter, exit, data) { | ||
function bindIndex(parent, update, enter, exit, data) { | ||
var i = 0, | ||
@@ -612,3 +640,3 @@ node, | ||
} else { | ||
enter[i] = new EnterNode(update._parent, data[i]); | ||
enter[i] = new EnterNode(parent, data[i]); | ||
} | ||
@@ -620,3 +648,3 @@ } | ||
for (; i < dataLength; ++i) { | ||
enter[i] = new EnterNode(update._parent, data[i]); | ||
enter[i] = new EnterNode(parent, data[i]); | ||
} | ||
@@ -635,3 +663,3 @@ | ||
function bindKey(update, enter, exit, data, key) { | ||
function bindKey(parent, update, enter, exit, data, key) { | ||
var i, | ||
@@ -672,3 +700,3 @@ node, | ||
for (i = 0; i < dataLength; ++i) { | ||
keyValue = keyPrefix + key.call(update._parent, data[i], i, data); | ||
keyValue = keyPrefix + key.call(parent, data[i], i, data); | ||
@@ -678,3 +706,3 @@ // Is there a node associated with this key? | ||
if (!(node = nodeByKeyValue[keyValue])) { | ||
enter[i] = new EnterNode(update._parent, data[i]); | ||
enter[i] = new EnterNode(parent, data[i]); | ||
} | ||
@@ -711,5 +739,6 @@ | ||
var bind = key ? bindKey : bindIndex, | ||
update = this._, | ||
enter = (this._enter = this.enter())._, // Note: arrayify’s! | ||
exit = (this._exit = this.exit())._; | ||
parents = this._parents, | ||
update = arrayify(this), | ||
enter = (this._enter = this.enter())._nodes, | ||
exit = (this._exit = this.exit())._nodes; | ||
@@ -720,5 +749,5 @@ if (typeof value !== "function") value = constant(value); | ||
var group = update[j], | ||
parent = group._parent; | ||
parent = parents[j]; | ||
bind(group, enter[j], exit[j], value.call(parent, parent && parent.__data__, j, group), key); | ||
bind(parent, group, enter[j], exit[j], value.call(parent, parent && parent.__data__, j, parents), key); | ||
@@ -750,3 +779,3 @@ // Now connect the enter nodes to their following update node, such that | ||
appendChild: function(child) { return this._parent.insertBefore(child, this._next); }, | ||
insertBefore: function(child, next) { return this._parent.insertBefore(child, next || this._next); }, | ||
insertBefore: function(child, next) { return this._parent.insertBefore(child, next); }, | ||
querySelector: function(selector) { return this._parent.querySelector(selector); }, | ||
@@ -782,3 +811,3 @@ querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); } | ||
for (var groups = this._, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { | ||
for (var groups = this._nodes, 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) { | ||
@@ -789,6 +818,5 @@ if ((node = group[i]) && match.call(node, node.__data__, i, group)) { | ||
} | ||
subgroup._parent = group._parent; | ||
} | ||
return new Selection(subgroups); | ||
return new Selection(subgroups, this._parents); | ||
} | ||
@@ -805,7 +833,7 @@ | ||
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) { | ||
for (var groups = this._nodes, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) { | ||
for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { | ||
if (node = group[i]) { | ||
subgroups.push(subgroup = select.call(node, node.__data__, i, group)); | ||
subgroup._parent = node; | ||
subgroups.push(select.call(node, node.__data__, i, group)); | ||
parents.push(node); | ||
} | ||
@@ -815,3 +843,3 @@ } | ||
return new Selection(subgroups); | ||
return new Selection(subgroups, parents); | ||
} | ||
@@ -822,22 +850,24 @@ | ||
for (var groups = this._, update = this._update, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { | ||
for (var groups = this._nodes, 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; | ||
if (update) update._nodes[j][i] = subnode; | ||
subgroup[i] = subnode; | ||
} | ||
} | ||
subgroup._parent = group._parent; | ||
} | ||
return new Selection(subgroups); | ||
return new Selection(subgroups, this._parents); | ||
} | ||
function Selection(groups) { | ||
this._ = groups; | ||
var root = [null]; | ||
function Selection(nodes, parents) { | ||
this._nodes = nodes; | ||
this._parents = parents; | ||
} | ||
function selection() { | ||
return new Selection([[document.documentElement]]); | ||
return new Selection([[document.documentElement]], root); | ||
} | ||
@@ -876,3 +906,5 @@ | ||
function select(selector) { | ||
return new Selection([[typeof selector === "string" ? document.querySelector(selector) : selector]]); | ||
return typeof selector === "string" | ||
? new Selection([[document.querySelector(selector)]], [document.documentElement]) | ||
: new Selection([[selector]], root); | ||
} | ||
@@ -916,3 +948,5 @@ | ||
function selectAll(selector) { | ||
return new Selection([typeof selector === "string" ? document.querySelectorAll(selector) : selector]); | ||
return typeof selector === "string" | ||
? new Selection([document.querySelectorAll(selector)], [document.documentElement]) | ||
: new Selection([selector], root); | ||
} | ||
@@ -922,2 +956,3 @@ | ||
if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches; | ||
for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) { | ||
@@ -928,2 +963,3 @@ if ((touch = touches[i]).identifier === identifier) { | ||
} | ||
return null; | ||
@@ -934,9 +970,11 @@ } | ||
if (touches == null) touches = sourceEvent().touches; | ||
for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) { | ||
points[i] = point(node, touches[i]); | ||
} | ||
return points; | ||
} | ||
var version = "0.6.1"; | ||
var version = "0.6.2"; | ||
@@ -943,0 +981,0 @@ exports.version = version; |
@@ -1,1 +0,1 @@ | ||
!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(Bt,"\\$&")}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=Dt.hasOwnProperty(s))&&(s=Dt[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 g(){var t=this.parentNode;t&&t.removeChild(this)}function d(){return this.each(g)}function m(t){var n=t+="",e=n.indexOf(":");return e>=0&&"xmlns"!==(n=t.slice(0,e))&&(t=t.slice(e+1)),Vt.hasOwnProperty(n)?{space:Vt[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 N(){this.parentNode.insertBefore(this,this.parentNode.firstChild)}function C(){return this.each(N)}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 null==t&&(t=""),function(){this.textContent=t}}function D(t){return function(){var n=t.apply(this,arguments);this.textContent=null==n?"":n}}function R(t){return arguments.length?this.each(("function"==typeof t?D:B)(t)):this.node().textContent}function V(t){return t.trim().replace(/\s+/g," ")}function X(t){var n;return function(e,r){if(i=e.classList)return r?i.add(t):i.remove(t);n||(n=$(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 $(t){return new RegExp("(?:^|\\s+)"+n(t)+"(?:\\s+|$)","g")}function z(t,n){return function(){for(var e=-1,r=t.length;++e<r;)t[e](this,n)}}function I(t,n){return function(){for(var e=-1,r=t.length,i=n.apply(this,arguments);++e<r;)t[e](this,i)}}function O(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(!$(e[i]).test(o))return!1;return!0}return this.each(("function"==typeof n?I:z)(e.map(X),n))}function Y(t){return function(){delete this[t]}}function k(t,n){return function(){this[t]=n}}function G(t,n){return function(){var e=n.apply(this,arguments);null==e?delete this[t]:this[t]=e}}function H(t,n){return arguments.length>1?this.each((null==n?Y:"function"==typeof n?G:k)(t,n)):this.node()[t]}function U(t){return function(){this.style.removeProperty(t)}}function j(t,n,e){return function(){this.style.setProperty(t,n,e)}}function K(t,n,e){return function(){var r=n.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,e)}}function W(t,n,e){var r;return arguments.length>1?this.each((null==n?U:"function"==typeof n?K:j)(t,n,null==e?"":e)):l(r=this.node()).getComputedStyle(r,null).getPropertyValue(t)}function F(t){return function(){this.removeAttribute(t)}}function J(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Q(t,n){return function(){this.setAttribute(t,n)}}function Z(t,n){return function(){this.setAttributeNS(t.space,t.local,n)}}function tt(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttribute(t):this.setAttribute(t,e)}}function nt(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 et(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?J:F:"function"==typeof n?e.local?nt:tt:e.local?Z:Q)(e,n))}function rt(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 it(){return!this.node()}function ut(){var t=0;return this.each(function(){++t}),t}function ot(){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 at(){var t=new Array(this.size()),n=-1;return this.each(function(){t[++n]=this}),t}function ct(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this}function st(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 lt(t){function n(n,e){return n&&e?t(n.__data__,e.__data__):!n-!e}t||(t=ft);for(var e=st(this),r=0,i=e.length;i>r;++r)e[r].sort(n);return this.order()}function ft(t,n){return n>t?-1:t>n?1:t>=n?0:NaN}function ht(){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 pt(t){var n=new Array(t.length);return n._parent=t._parent,n}function _t(){var t=this._exit;return t?(this._exit=null,t):new Et(st(this).map(pt))}function vt(){var t=this._enter;return t?(this._enter=null,t):(t=new Et(st(this).map(pt)),t._update=this,t)}function gt(t){return function(){return t}}function dt(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 wt(t._parent,r[u]);for(;a>u;++u)n[u]=new wt(t._parent,r[u]);for(;o>u;++u)(i=t[u])&&(e[u]=t[u]);t.length=a}function mt(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=Xt+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=Xt+i.call(t._parent,r[u],u,r),(o=l[a])?o!==!0&&(t[u]=o,o.__data__=r[u]):n[u]=new wt(t._parent,r[u]),l[a]=!0;for(u=0;s>u;++u)(o=l[f[u]])!==!0&&(e[u]=o)}function yt(t,n){if(!t){var e=new Array(this.size()),r=-1;return this.each(function(t){e[++r]=t}),e}var i=n?mt:dt,u=this._,o=(this._enter=this.enter())._,a=(this._exit=this.exit())._;"function"!=typeof t&&(t=gt(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,g=0;_>v;++v)if(h=o[s][v]){for(v>=g&&(g=v+1);!(p=l[g])&&++g<_;);h._next=p||null}}return this}function wt(t,n){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=n}function xt(t){"function"!=typeof t&&(t=Ot(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 Et(r)}function At(t){return function(){return this.querySelectorAll(t)}}function St(t){"function"!=typeof t&&(t=At(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 Et(r)}function bt(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 Et(i)}function Et(t){this._=t}function Nt(){return new Et([[document.documentElement]])}function Ct(t){return new Et([["string"==typeof t?document.querySelector(t):t]])}function Lt(t,n){var e=t.ownerSVGElement||t;if(e.createSVGPoint){var r=e.createSVGPoint();if(0>Yt){var i=l(t);if(i.scrollX||i.scrollY){e=Ct(i.document.body).append("svg").style({position:"absolute",top:0,left:0,margin:0,padding:0,border:"none"},"important");var u=e.node().getScreenCTM();Yt=!(u.f||u.e),e.remove()}}return Yt?(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 Mt(t,n){return null==n&&(n=s()),n.changedTouches&&(n=n.changedTouches[0]),Lt(t,n)}function Tt(t){return new Et(["string"==typeof t?document.querySelectorAll(t):t])}function Pt(t,n,e){arguments.length<3&&(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 Lt(t,r);return null}function qt(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]=Lt(t,n[e]);return i}var Bt=/[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g,Dt={};if(t.event=null,"undefined"!=typeof document){var Rt=document.documentElement;"onmouseenter"in Rt||(Dt={mouseenter:"mouseover",mouseleave:"mouseout"})}var Vt={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/"},Xt="$";wt.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 $t=function(t){return function(){return this.matches(t)}};if("undefined"!=typeof document){var zt=document.documentElement;if(!zt.matches){var It=zt.webkitMatchesSelector||zt.msMatchesSelector||zt.mozMatchesSelector||zt.oMatchesSelector;$t=function(t){return function(){return It.call(this,t)}}}}var Ot=$t;Et.prototype=Nt.prototype={select:bt,selectAll:St,filter:xt,data:yt,enter:vt,exit:_t,order:ht,sort:lt,call:ct,nodes:at,node:ot,size:ut,empty:it,each:rt,attr:et,style:W,property:H,classed:O,text:R,html:q,raise:M,lower:C,append:E,remove:d,datum:v,on:c,dispatch:_};var Yt="undefined"!=typeof navigator&&/WebKit/.test(navigator.userAgent)?-1:0,kt="0.6.1";t.version=kt,t.mouse=Mt,t.namespace=m,t.namespaces=Vt,t.select=Ct,t.selectAll=Tt,t.selection=Nt,t.touch=Pt,t.touches=qt}); | ||
!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(zt,"\\$&")}function e(){}function r(n,e,r){return function(i){var o=t.event;t.event=i;try{n.call(this,this.__data__,e,r)}finally{t.event=o}}}function i(t){return function(n){var e=n.relatedTarget;e&&(e===this||8&e.compareDocumentPosition(this))||t(n)}}function o(t,n){return function(){var e=this[t];e&&(this.removeEventListener(n,e,e._capture),delete this[t])}}function u(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 s(t,n,e,o,u){return function(s,a,c){var l=this[n];l&&this.removeEventListener(e,l,l._capture),l=r(o,a,c),t&&(l=i(l)),l._listener=o,this.addEventListener(e,this[n]=l,l._capture=u)}}function a(t,n,r){var i,a,c=t+"",l="__on"+c;return arguments.length<2?(i=this.node()[l])&&i._listener:((i=c.indexOf("."))>0&&(c=c.slice(0,i)),(a=Ht.hasOwnProperty(c))&&(c=Ht[c]),this.each(n?i?s(a,l,c,n,null==r?!1:r):e:i?o(l,c):u(c)))}function c(){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 h(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 f(t,n){return function(){return h(this,t,n)}}function p(t,n){return function(){return h(this,t,n.apply(this,arguments))}}function d(t,n){return this.each(("function"==typeof n?p:f)(t,n))}function _(t){return arguments.length?this.property("__data__",t):this.node().__data__}function m(){var t=this.parentNode;t&&t.removeChild(this)}function v(){return this.each(m)}function g(t){var n=t+="",e=n.indexOf(":");return e>=0&&"xmlns"!==(n=t.slice(0,e))&&(t=t.slice(e+1)),$t.hasOwnProperty(n)?{space:$t[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=g(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(){return null}function C(t,n){var e="function"==typeof t?t:A(t);return this.select(arguments.length<2?S(e):b(e,null==n?E:"function"==typeof n?n:y(n)))}function N(){this.parentNode.insertBefore(this,this.parentNode.firstChild)}function M(){return this.each(N)}function T(){this.parentNode.appendChild(this)}function L(){return this.each(T)}function P(){this.innerHTML=""}function q(t){return function(){this.innerHTML=t}}function B(t){return function(){var n=t.apply(this,arguments);this.innerHTML=null==n?"":n}}function D(t){return arguments.length?this.each(null==t?P:("function"==typeof t?B:q)(t)):this.node().innerHTML}function O(){this.textContent=""}function V(t){return function(){this.textContent=t}}function R(t){return function(){var n=t.apply(this,arguments);this.textContent=null==n?"":n}}function X(t){return arguments.length?this.each(null==t?O:("function"==typeof t?R:V)(t)):this.node().textContent}function z(t){return t.trim().split(/^|\s+/)}function H(t){return t.classList||new Y(t)}function Y(t){this._node=t,this._names=z(t.getAttribute("class")||"")}function $(t,n){for(var e=H(t),r=-1,i=n.length;++r<i;)e.add(n[r])}function j(t,n){for(var e=H(t),r=-1,i=n.length;++r<i;)e.remove(n[r])}function k(t){return function(){$(this,t)}}function G(t){return function(){j(this,t)}}function I(t,n){return function(){(n.apply(this,arguments)?$:j)(this,t)}}function U(t,n){var e=z(t+"");if(arguments.length<2){for(var r=H(this.node()),i=-1,o=e.length;++i<o;)if(!r.contains(e[i]))return!1;return!0}return this.each(("function"==typeof n?I:n?k:G)(e,n))}function K(t){return function(){delete this[t]}}function W(t,n){return function(){this[t]=n}}function F(t,n){return function(){var e=n.apply(this,arguments);null==e?delete this[t]:this[t]=e}}function J(t,n){return arguments.length>1?this.each((null==n?K:"function"==typeof n?F:W)(t,n)):this.node()[t]}function Q(t){return function(){this.style.removeProperty(t)}}function Z(t,n,e){return function(){this.style.setProperty(t,n,e)}}function tt(t,n,e){return function(){var r=n.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,e)}}function nt(t,n,e){var r;return arguments.length>1?this.each((null==n?Q:"function"==typeof n?tt:Z)(t,n,null==e?"":e)):l(r=this.node()).getComputedStyle(r,null).getPropertyValue(t)}function et(t){return function(){this.removeAttribute(t)}}function rt(t){return function(){this.removeAttributeNS(t.space,t.local)}}function it(t,n){return function(){this.setAttribute(t,n)}}function ot(t,n){return function(){this.setAttributeNS(t.space,t.local,n)}}function ut(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttribute(t):this.setAttribute(t,e)}}function st(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 at(t,n){var e=g(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?rt:et:"function"==typeof n?e.local?st:ut:e.local?ot:it)(e,n))}function ct(t){for(var n=this._nodes,e=0,r=n.length;r>e;++e)for(var i,o=n[e],u=0,s=o.length;s>u;++u)(i=o[u])&&t.call(i,i.__data__,u,o);return this}function lt(){return!this.node()}function ht(){var t=0;return this.each(function(){++t}),t}function ft(){for(var t=this._nodes,n=0,e=t.length;e>n;++n)for(var r=t[n],i=0,o=r.length;o>i;++i){var u=r[i];if(u)return u}return null}function pt(){var t=new Array(this.size()),n=-1;return this.each(function(){t[++n]=this}),t}function dt(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this}function _t(t){for(var n=t._nodes,e=0,r=n.length;r>e;++e)if(!Array.isArray(i=n[e]))for(var i,o=i.length,u=n[e]=new Array(o),s=0;o>s;++s)u[s]=i[s];return n}function mt(t){function n(n,e){return n&&e?t(n.__data__,e.__data__):!n-!e}t||(t=vt);for(var e=_t(this),r=0,i=e.length;i>r;++r)e[r].sort(n);return this.order()}function vt(t,n){return n>t?-1:t>n?1:t>=n?0:NaN}function gt(){for(var t=this._nodes,n=-1,e=t.length;++n<e;)for(var r,i=t[n],o=i.length-1,u=i[o];--o>=0;)(r=i[o])&&(u&&u!==r.nextSibling&&u.parentNode.insertBefore(r,u),u=r);return this}function yt(t){return new Array(t.length)}function wt(){var t=this._exit;return t?(this._exit=null,t):new Pt(this._nodes.map(yt),this._parents)}function xt(){var t=this._enter;return t?(this._enter=null,t):(t=new Pt(this._nodes.map(yt),this._parents),t._update=this,t)}function At(t){return function(){return t}}function St(t,n,e,r,i){var o,u=0,s=n.length,a=i.length,c=Math.min(s,a);for(e.length=0,e.length=a,r.length=0,r.length=s;c>u;++u)(o=n[u])?o.__data__=i[u]:e[u]=new Ct(t,i[u]);for(;a>u;++u)e[u]=new Ct(t,i[u]);for(;s>u;++u)(o=n[u])&&(r[u]=n[u]);n.length=a}function bt(t,n,e,r,i,o){var u,s,a,c=i.length,l=n.length,h={},f=new Array(l);for(e.length=0,e.length=c,r.length=0,r.length=l,u=0;l>u;++u)(s=n[u])&&(f[u]=a=jt+o.call(s,s.__data__,u,n),h[a]?r[u]=s:h[a]=s);for(n.length=0,n.length=c,u=0;c>u;++u)a=jt+o.call(t,i[u],u,i),(s=h[a])?s!==!0&&(n[u]=s,s.__data__=i[u]):e[u]=new Ct(t,i[u]),h[a]=!0;for(u=0;l>u;++u)(s=h[f[u]])!==!0&&(r[u]=s)}function Et(t,n){if(!t){var e=new Array(this.size()),r=-1;return this.each(function(t){e[++r]=t}),e}var i=n?bt:St,o=this._parents,u=_t(this),s=(this._enter=this.enter())._nodes,a=(this._exit=this.exit())._nodes;"function"!=typeof t&&(t=At(t));for(var c=u.length,l=0;c>l;++l){var h=u[l],f=o[l];i(f,h,s[l],a[l],t.call(f,f&&f.__data__,l,o),n);for(var p,d,_=h.length,m=0,v=0;_>m;++m)if(p=s[l][m]){for(m>=v&&(v=m+1);!(d=h[v])&&++v<_;);p._next=d||null}}return this}function Ct(t,n){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=n}function Nt(t){"function"!=typeof t&&(t=Ut(t));for(var n=this._nodes,e=n.length,r=new Array(e),i=0;e>i;++i)for(var o,u=n[i],s=u.length,a=r[i]=[],c=0;s>c;++c)(o=u[c])&&t.call(o,o.__data__,c,u)&&a.push(o);return new Pt(r,this._parents)}function Mt(t){return function(){return this.querySelectorAll(t)}}function Tt(t){"function"!=typeof t&&(t=Mt(t));for(var n=this._nodes,e=n.length,r=[],i=[],o=0;e>o;++o)for(var u,s=n[o],a=s.length,c=0;a>c;++c)(u=s[c])&&(r.push(t.call(u,u.__data__,c,s)),i.push(u));return new Pt(r,i)}function Lt(t){"function"!=typeof t&&(t=y(t));for(var n=this._nodes,e=this._update,r=n.length,i=new Array(r),o=0;r>o;++o)for(var u,s,a=n[o],c=a.length,l=i[o]=new Array(c),h=0;c>h;++h)(u=a[h])&&(s=t.call(u,u.__data__,h,a))&&("__data__"in u&&(s.__data__=u.__data__),e&&(e._nodes[o][h]=s),l[h]=s);return new Pt(i,this._parents)}function Pt(t,n){this._nodes=t,this._parents=n}function qt(){return new Pt([[document.documentElement]],Kt)}function Bt(t){return"string"==typeof t?new Pt([[document.querySelector(t)]],[document.documentElement]):new Pt([[t]],Kt)}function Dt(t,n){var e=t.ownerSVGElement||t;if(e.createSVGPoint){var r=e.createSVGPoint();if(0>Wt){var i=l(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 o=e.node().getScreenCTM();Wt=!(o.f||o.e),e.remove()}}return Wt?(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 u=t.getBoundingClientRect();return[n.clientX-u.left-t.clientLeft,n.clientY-u.top-t.clientTop]}function Ot(t,n){return null==n&&(n=c()),n.changedTouches&&(n=n.changedTouches[0]),Dt(t,n)}function Vt(t){return"string"==typeof t?new Pt([document.querySelectorAll(t)],[document.documentElement]):new Pt([t],Kt)}function Rt(t,n,e){arguments.length<3&&(e=n,n=c().changedTouches);for(var r,i=0,o=n?n.length:0;o>i;++i)if((r=n[i]).identifier===e)return Dt(t,r);return null}function Xt(t,n){null==n&&(n=c().touches);for(var e=0,r=n?n.length:0,i=new Array(r);r>e;++e)i[e]=Dt(t,n[e]);return i}var zt=/[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g,Ht={};if(t.event=null,"undefined"!=typeof document){var Yt=document.documentElement;"onmouseenter"in Yt||(Ht={mouseenter:"mouseover",mouseleave:"mouseout"})}var $t={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/"};Y.prototype={add:function(t){var n=this._names.indexOf(t);0>n&&(this._names.push(t),this._node.setAttribute("class",this._names.join(" ")))},remove:function(t){var n=this._names.indexOf(t);n>=0&&(this._names.splice(n,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var jt="$";Ct.prototype={appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,n){return this._parent.insertBefore(t,n)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var kt=function(t){return function(){return this.matches(t)}};if("undefined"!=typeof document){var Gt=document.documentElement;if(!Gt.matches){var It=Gt.webkitMatchesSelector||Gt.msMatchesSelector||Gt.mozMatchesSelector||Gt.oMatchesSelector;kt=function(t){return function(){return It.call(this,t)}}}}var Ut=kt,Kt=[null];Pt.prototype=qt.prototype={select:Lt,selectAll:Tt,filter:Nt,data:Et,enter:xt,exit:wt,order:gt,sort:mt,call:dt,nodes:pt,node:ft,size:ht,empty:lt,each:ct,attr:at,style:nt,property:J,classed:U,text:X,html:D,raise:L,lower:M,append:C,remove:v,datum:_,on:a,dispatch:d};var Wt="undefined"!=typeof navigator&&/WebKit/.test(navigator.userAgent)?-1:0,Ft="0.6.2";t.version=Ft,t.mouse=Ot,t.namespace=g,t.namespaces=$t,t.select=Bt,t.selectAll=Vt,t.selection=qt,t.touch=Rt,t.touches=Xt}); |
{ | ||
"name": "d3-selection", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "Data-driven DOM manipulation: select elements and join them to data.", | ||
@@ -25,5 +25,4 @@ "keywords": [ | ||
"pretest": "mkdir -p build && node -e 'process.stdout.write(\"var version = \\\"\" + require(\"./package.json\").version + \"\\\"; export * from \\\"../index\\\"; export {version};\");' > build/bundle.js && rollup -f umd -u d3-selection -n d3_selection -o build/d3-selection.js -- build/bundle.js", | ||
"test": "faucet `find test -name '*-test.js'`", | ||
"lint": "eslint index.js src", | ||
"prepublish": "npm test && npm run lint && uglifyjs build/d3-selection.js -c -m -o build/d3-selection.min.js && rm -f build/d3-selection.zip && zip -j build/d3-selection.zip -- LICENSE README.md build/d3-selection.js build/d3-selection.min.js" | ||
"test": "faucet `find test -name '*-test.js'` && eslint index.js src", | ||
"prepublish": "npm test && uglifyjs build/d3-selection.js -c -m -o build/d3-selection.min.js && rm -f build/d3-selection.zip && zip -j build/d3-selection.zip -- LICENSE README.md build/d3-selection.js build/d3-selection.min.js" | ||
}, | ||
@@ -30,0 +29,0 @@ "devDependencies": { |
@@ -173,5 +173,5 @@ # d3-selection | ||
<a name="selection_classed" href="#selection_classed">#</a> <i>selection</i>.<b>classed</b>(<i>classes</i>[, <i>value</i>]) | ||
<a name="selection_classed" href="#selection_classed">#</a> <i>selection</i>.<b>classed</b>(<i>names</i>[, <i>value</i>]) | ||
If a *value* is specified, assigns or unassigns the specified CSS *classes* on the selected elements by setting the `class` attribute or modifying the `classList` property and returns this selection. The specified *classes* is a string of space-separated class names. For example, to assign the classes `foo` and `bar` to the selected elements: | ||
If a *value* is specified, assigns or unassigns the specified CSS class *names* on the selected elements by setting the `class` attribute or modifying the `classList` property and returns this selection. The specified *names* is a string of space-separated class names. For example, to assign the classes `foo` and `bar` to the selected elements: | ||
@@ -182,3 +182,3 @@ ```js | ||
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: | ||
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: | ||
@@ -239,3 +239,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), 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. To append entering elements after the last child, explicitly specify a null *before* selector. | ||
@@ -248,7 +248,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`). | ||
<a name="selection_sort" href="#selection_sort">#</a> <i>selection</i>.<b>sort</b>(<i>comparator</i>) | ||
<a name="selection_sort" href="#selection_sort">#</a> <i>selection</i>.<b>sort</b>(<i>compare</i>) | ||
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. | ||
Sorts each group of selected elements in-place according to the *compare* function, and then re-inserts the document elements to match the resulting order. Returns this selection. | ||
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. | ||
The compare 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. | ||
@@ -515,4 +515,2 @@ Note that sorting is not guaranteed to be stable; however, it is guaranteed to have the same behavior as your browser’s built-in [sort](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort) method on arrays. | ||
The `this` context of the called function is also the current selection. | ||
<a name="selection_empty" href="#selection_empty">#</a> <i>selection</i>.<b>empty</b>() | ||
@@ -519,0 +517,0 @@ |
@@ -1,5 +0,7 @@ | ||
import {Selection} from "./selection/index"; | ||
import {Selection, root} from "./selection/index"; | ||
export default function(selector) { | ||
return new Selection([[typeof selector === "string" ? document.querySelector(selector) : selector]]); | ||
return typeof selector === "string" | ||
? new Selection([[document.querySelector(selector)]], [document.documentElement]) | ||
: new Selection([[selector]], root); | ||
} |
@@ -1,5 +0,7 @@ | ||
import {Selection} from "./selection/index"; | ||
import {Selection, root} from "./selection/index"; | ||
export default function(selector) { | ||
return new Selection([typeof selector === "string" ? document.querySelectorAll(selector) : selector]); | ||
return typeof selector === "string" | ||
? new Selection([document.querySelectorAll(selector)], [document.documentElement]) | ||
: new Selection([selector], root); | ||
} |
@@ -39,2 +39,6 @@ import namespace from "../namespace"; | ||
function constantNull() { | ||
return null; | ||
} | ||
export default function(name, before) { | ||
@@ -44,3 +48,6 @@ var create = typeof name === "function" ? name : creator(name); | ||
? append(create) | ||
: insert(create, typeof before === "function" ? before : selector(before))); | ||
: insert(create, before == null | ||
? constantNull : typeof before === "function" | ||
? before | ||
: selector(before))); | ||
} |
export default function(selection) { | ||
for (var groups = selection._, j = 0, m = groups.length; j < m; ++j) { | ||
for (var groups = selection._nodes, j = 0, m = groups.length; j < m; ++j) { | ||
if (!Array.isArray(group = groups[j])) { | ||
@@ -8,3 +8,2 @@ for (var n = group.length, array = groups[j] = new Array(n), group, i = 0; i < n; ++i) { | ||
} | ||
array._parent = group._parent; | ||
} | ||
@@ -11,0 +10,0 @@ } |
@@ -1,54 +0,68 @@ | ||
import requote from "../requote"; | ||
function classArray(string) { | ||
return string.trim().split(/^|\s+/); | ||
} | ||
function collapse(string) { | ||
return string.trim().replace(/\s+/g, " "); | ||
function classList(node) { | ||
return node.classList || new ClassList(node); | ||
} | ||
function classer(name) { | ||
var re; | ||
return function(node, value) { | ||
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(classes)) node.setAttribute("class", collapse(classes + " " + name)); | ||
} else { | ||
node.setAttribute("class", collapse(classes.replace(re, " "))); | ||
function ClassList(node) { | ||
this._node = node; | ||
this._names = classArray(node.getAttribute("class") || ""); | ||
} | ||
ClassList.prototype = { | ||
add: function(name) { | ||
var i = this._names.indexOf(name); | ||
if (i < 0) { | ||
this._names.push(name); | ||
this._node.setAttribute("class", this._names.join(" ")); | ||
} | ||
}; | ||
}, | ||
remove: function(name) { | ||
var i = this._names.indexOf(name); | ||
if (i >= 0) { | ||
this._names.splice(i, 1); | ||
this._node.setAttribute("class", this._names.join(" ")); | ||
} | ||
}, | ||
contains: function(name) { | ||
return this._names.indexOf(name) >= 0; | ||
} | ||
}; | ||
function classedAdd(node, names) { | ||
var list = classList(node), i = -1, n = names.length; | ||
while (++i < n) list.add(names[i]); | ||
} | ||
function classedRe(name) { | ||
return new RegExp("(?:^|\\s+)" + requote(name) + "(?:\\s+|$)", "g"); | ||
function classedRemove(node, names) { | ||
var list = classList(node), i = -1, n = names.length; | ||
while (++i < n) list.remove(names[i]); | ||
} | ||
function classedConstant(classers, value) { | ||
function classedTrue(names) { | ||
return function() { | ||
var i = -1, n = classers.length; | ||
while (++i < n) classers[i](this, value); | ||
classedAdd(this, names); | ||
}; | ||
} | ||
function classedFunction(classers, value) { | ||
function classedFalse(names) { | ||
return function() { | ||
var i = -1, n = classers.length, v = value.apply(this, arguments); | ||
while (++i < n) classers[i](this, v); | ||
classedRemove(this, names); | ||
}; | ||
} | ||
function classedFunction(names, value) { | ||
return function() { | ||
(value.apply(this, arguments) ? classedAdd : classedRemove)(this, names); | ||
}; | ||
} | ||
export default function(name, value) { | ||
var names = (name + "").trim().split(/^|\s+/); | ||
var names = classArray(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; | ||
} | ||
var list = classList(this.node()), i = -1, n = names.length; | ||
while (++i < n) if (!list.contains(names[i])) return false; | ||
return true; | ||
@@ -58,4 +72,5 @@ } | ||
return this.each((typeof value === "function" | ||
? classedFunction | ||
: classedConstant)(names.map(classer), value)); | ||
? classedFunction : value | ||
? classedTrue | ||
: classedFalse)(names, value)); | ||
} |
@@ -0,1 +1,2 @@ | ||
import arrayify from "./arrayify"; | ||
import constant from "../constant"; | ||
@@ -5,3 +6,3 @@ | ||
function bindIndex(update, enter, exit, data) { | ||
function bindIndex(parent, update, enter, exit, data) { | ||
var i = 0, | ||
@@ -21,3 +22,3 @@ node, | ||
} else { | ||
enter[i] = new EnterNode(update._parent, data[i]); | ||
enter[i] = new EnterNode(parent, data[i]); | ||
} | ||
@@ -29,3 +30,3 @@ } | ||
for (; i < dataLength; ++i) { | ||
enter[i] = new EnterNode(update._parent, data[i]); | ||
enter[i] = new EnterNode(parent, data[i]); | ||
} | ||
@@ -44,3 +45,3 @@ | ||
function bindKey(update, enter, exit, data, key) { | ||
function bindKey(parent, update, enter, exit, data, key) { | ||
var i, | ||
@@ -81,3 +82,3 @@ node, | ||
for (i = 0; i < dataLength; ++i) { | ||
keyValue = keyPrefix + key.call(update._parent, data[i], i, data); | ||
keyValue = keyPrefix + key.call(parent, data[i], i, data); | ||
@@ -87,3 +88,3 @@ // Is there a node associated with this key? | ||
if (!(node = nodeByKeyValue[keyValue])) { | ||
enter[i] = new EnterNode(update._parent, data[i]); | ||
enter[i] = new EnterNode(parent, data[i]); | ||
} | ||
@@ -120,5 +121,6 @@ | ||
var bind = key ? bindKey : bindIndex, | ||
update = this._, | ||
enter = (this._enter = this.enter())._, // Note: arrayify’s! | ||
exit = (this._exit = this.exit())._; | ||
parents = this._parents, | ||
update = arrayify(this), | ||
enter = (this._enter = this.enter())._nodes, | ||
exit = (this._exit = this.exit())._nodes; | ||
@@ -129,5 +131,5 @@ if (typeof value !== "function") value = constant(value); | ||
var group = update[j], | ||
parent = group._parent; | ||
parent = parents[j]; | ||
bind(group, enter[j], exit[j], value.call(parent, parent && parent.__data__, j, group), key); | ||
bind(parent, group, enter[j], exit[j], value.call(parent, parent && parent.__data__, j, parents), key); | ||
@@ -159,5 +161,5 @@ // Now connect the enter nodes to their following update node, such that | ||
appendChild: function(child) { return this._parent.insertBefore(child, this._next); }, | ||
insertBefore: function(child, next) { return this._parent.insertBefore(child, next || this._next); }, | ||
insertBefore: function(child, next) { return this._parent.insertBefore(child, next); }, | ||
querySelector: function(selector) { return this._parent.querySelector(selector); }, | ||
querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); } | ||
}; |
export default function(callback) { | ||
for (var groups = this._, j = 0, m = groups.length; j < m; ++j) { | ||
for (var groups = this._nodes, j = 0, m = groups.length; j < m; ++j) { | ||
for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) { | ||
@@ -5,0 +5,0 @@ if (node = group[i]) callback.call(node, node.__data__, i, group); |
@@ -1,2 +0,1 @@ | ||
import arrayify from "./arrayify"; | ||
import sparse from "./sparse"; | ||
@@ -8,5 +7,5 @@ import {Selection} from "./index"; | ||
if (enter) return this._enter = null, enter; | ||
enter = new Selection(arrayify(this).map(sparse)); | ||
enter = new Selection(this._nodes.map(sparse), this._parents); | ||
enter._update = this; | ||
return enter; | ||
} |
@@ -1,2 +0,1 @@ | ||
import arrayify from "./arrayify"; | ||
import sparse from "./sparse"; | ||
@@ -8,3 +7,3 @@ import {Selection} from "./index"; | ||
if (exit) return this._exit = null, exit; | ||
return new Selection(arrayify(this).map(sparse)); | ||
return new Selection(this._nodes.map(sparse), this._parents); | ||
} |
@@ -7,3 +7,3 @@ import {Selection} from "./index"; | ||
for (var groups = this._, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { | ||
for (var groups = this._nodes, 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) { | ||
@@ -14,6 +14,5 @@ if ((node = group[i]) && match.call(node, node.__data__, i, group)) { | ||
} | ||
subgroup._parent = group._parent; | ||
} | ||
return new Selection(subgroups); | ||
return new Selection(subgroups, this._parents); | ||
} |
@@ -0,3 +1,6 @@ | ||
function htmlRemove() { | ||
this.innerHTML = ""; | ||
} | ||
function htmlConstant(value) { | ||
if (value == null) value = ""; | ||
return function() { | ||
@@ -17,3 +20,4 @@ this.innerHTML = value; | ||
return arguments.length | ||
? this.each((typeof value === "function" | ||
? this.each(value == null | ||
? htmlRemove : (typeof value === "function" | ||
? htmlFunction | ||
@@ -20,0 +24,0 @@ : htmlConstant)(value)) |
@@ -29,8 +29,11 @@ import selection_select from "./select"; | ||
export function Selection(groups) { | ||
this._ = groups; | ||
export var root = [null]; | ||
export function Selection(nodes, parents) { | ||
this._nodes = nodes; | ||
this._parents = parents; | ||
} | ||
function selection() { | ||
return new Selection([[document.documentElement]]); | ||
return new Selection([[document.documentElement]], root); | ||
} | ||
@@ -37,0 +40,0 @@ |
export default function() { | ||
for (var groups = this._, j = 0, m = groups.length; j < m; ++j) { | ||
for (var groups = this._nodes, j = 0, m = groups.length; j < m; ++j) { | ||
for (var group = groups[j], i = 0, n = group.length; i < n; ++i) { | ||
@@ -5,0 +5,0 @@ var node = group[i]; |
@@ -61,3 +61,2 @@ import requote from "../requote"; | ||
function onAdd(filter, key, type, listener, capture) { | ||
if (capture == null) capture = false; | ||
return function(d, i, group) { | ||
@@ -68,4 +67,4 @@ var value = this[key]; | ||
if (filter) value = filterListener(value); | ||
value._listener = listener; | ||
this.addEventListener(type, this[key] = value, value._capture = capture); | ||
value._listener = listener; | ||
}; | ||
@@ -85,4 +84,4 @@ } | ||
return this.each(listener | ||
? (value ? onAdd(filter, key, type, listener, capture) : noop) // Attempt to add untyped listener is ignored. | ||
? (value ? onAdd(filter, key, name, listener, capture == null ? false : capture) : noop) // Attempt to add untyped listener is ignored. | ||
: (value ? onRemove(key, name) : onRemoveAll(name))); | ||
} |
export default function() { | ||
for (var groups = this._, j = -1, m = groups.length; ++j < m;) { | ||
for (var groups = this._nodes, j = -1, m = groups.length; ++j < m;) { | ||
for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) { | ||
@@ -5,0 +5,0 @@ if (node = group[i]) { |
@@ -7,14 +7,13 @@ import {Selection} from "./index"; | ||
for (var groups = this._, update = this._update, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { | ||
for (var groups = this._nodes, 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; | ||
if (update) update._nodes[j][i] = subnode; | ||
subgroup[i] = subnode; | ||
} | ||
} | ||
subgroup._parent = group._parent; | ||
} | ||
return new Selection(subgroups); | ||
return new Selection(subgroups, this._parents); | ||
} |
@@ -7,7 +7,7 @@ import {Selection} from "./index"; | ||
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) { | ||
for (var groups = this._nodes, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) { | ||
for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { | ||
if (node = group[i]) { | ||
subgroups.push(subgroup = select.call(node, node.__data__, i, group)); | ||
subgroup._parent = node; | ||
subgroups.push(select.call(node, node.__data__, i, group)); | ||
parents.push(node); | ||
} | ||
@@ -17,3 +17,3 @@ } | ||
return new Selection(subgroups); | ||
return new Selection(subgroups, parents); | ||
} |
export default function(update) { | ||
var group = new Array(update.length); | ||
group._parent = update._parent; | ||
return group; | ||
return new Array(update.length); | ||
} |
@@ -0,3 +1,6 @@ | ||
function textRemove() { | ||
this.textContent = ""; | ||
} | ||
function textConstant(value) { | ||
if (value == null) value = ""; | ||
return function() { | ||
@@ -17,3 +20,4 @@ this.textContent = value; | ||
return arguments.length | ||
? this.each((typeof value === "function" | ||
? this.each(value == null | ||
? textRemove : (typeof value === "function" | ||
? textFunction | ||
@@ -20,0 +24,0 @@ : textConstant)(value)) |
@@ -6,2 +6,3 @@ import sourceEvent from "./sourceEvent"; | ||
if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches; | ||
for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) { | ||
@@ -12,3 +13,4 @@ if ((touch = touches[i]).identifier === identifier) { | ||
} | ||
return null; | ||
} |
@@ -6,6 +6,8 @@ import sourceEvent from "./sourceEvent"; | ||
if (touches == null) touches = sourceEvent().touches; | ||
for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) { | ||
points[i] = point(node, touches[i]); | ||
} | ||
return points; | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109075
1630
556