d3-selection
Advanced tools
Comparing version 1.4.0 to 2.0.0-rc.1
@@ -1,7 +0,7 @@ | ||
// https://d3js.org/d3-selection/ v1.4.0 Copyright 2019 Mike Bostock | ||
// https://d3js.org/d3-selection/ v2.0.0-rc.1 Copyright 2019 Mike Bostock | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.d3 = global.d3 || {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
(global = global || self, factory(global.d3 = global.d3 || {})); | ||
}(this, function (exports) { 'use strict'; | ||
@@ -21,3 +21,3 @@ var xhtml = "http://www.w3.org/1999/xhtml"; | ||
if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1); | ||
return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; | ||
return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; // eslint-disable-line no-prototype-builtins | ||
} | ||
@@ -218,8 +218,12 @@ | ||
function datum(node) { | ||
return node.__data__; | ||
} | ||
function arrayify(data) { | ||
return Array.isArray(data) ? data : Array.from(data); | ||
} | ||
function selection_data(value, key) { | ||
if (!value) { | ||
data = new Array(this.size()), j = -1; | ||
this.each(function(d) { data[++j] = d; }); | ||
return data; | ||
} | ||
if (!value) return Array.from(this, datum); | ||
@@ -236,3 +240,3 @@ var bind = key ? bindKey : bindIndex, | ||
groupLength = group.length, | ||
data = value.call(parent, parent && parent.__data__, j, parents), | ||
data = arrayify(value.call(parent, parent && parent.__data__, j, parents)), | ||
dataLength = data.length, | ||
@@ -275,5 +279,6 @@ enterGroup = enter[j] = new Array(dataLength), | ||
function selection_merge(selection$$1) { | ||
function selection_merge(selection) { | ||
if (!(selection instanceof Selection)) throw new Error("invalid merge"); | ||
for (var groups0 = this._groups, groups1 = selection$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) { | ||
for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) { | ||
for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) { | ||
@@ -338,5 +343,3 @@ if (node = group0[i] || group1[i]) { | ||
function selection_nodes() { | ||
var nodes = new Array(this.size()), i = -1; | ||
this.each(function() { nodes[++i] = this; }); | ||
return nodes; | ||
return Array.from(this); | ||
} | ||
@@ -357,4 +360,4 @@ | ||
function selection_size() { | ||
var size = 0; | ||
this.each(function() { ++size; }); | ||
let size = 0; | ||
for (const node of this) ++size; // eslint-disable-line no-unused-vars | ||
return size; | ||
@@ -676,7 +679,9 @@ } | ||
function selection_cloneShallow() { | ||
return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling); | ||
var clone = this.cloneNode(false), parent = this.parentNode; | ||
return parent ? parent.insertBefore(clone, this.nextSibling) : clone; | ||
} | ||
function selection_cloneDeep() { | ||
return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling); | ||
var clone = this.cloneNode(true), parent = this.parentNode; | ||
return parent ? parent.insertBefore(clone, this.nextSibling) : clone; | ||
} | ||
@@ -694,35 +699,8 @@ | ||
var filterEvents = {}; | ||
exports.event = null; | ||
if (typeof document !== "undefined") { | ||
var element = document.documentElement; | ||
if (!("onmouseenter" in element)) { | ||
filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"}; | ||
} | ||
} | ||
function filterContextListener(listener, index, group) { | ||
listener = contextListener(listener, index, group); | ||
function contextListener(listener) { | ||
return function(event) { | ||
var related = event.relatedTarget; | ||
if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) { | ||
listener.call(this, event); | ||
} | ||
listener.call(this, event, this.__data__); | ||
}; | ||
} | ||
function contextListener(listener, index, group) { | ||
return function(event1) { | ||
var event0 = exports.event; // Events can be reentrant (e.g., focus). | ||
exports.event = event1; | ||
try { | ||
listener.call(this, this.__data__, index, group); | ||
} finally { | ||
exports.event = event0; | ||
} | ||
}; | ||
} | ||
function parseTypenames(typenames) { | ||
@@ -742,3 +720,3 @@ return typenames.trim().split(/^|\s+/).map(function(t) { | ||
if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) { | ||
this.removeEventListener(o.type, o.listener, o.capture); | ||
this.removeEventListener(o.type, o.listener, o.options); | ||
} else { | ||
@@ -753,10 +731,9 @@ on[++i] = o; | ||
function onAdd(typename, value, capture) { | ||
var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener; | ||
return function(d, i, group) { | ||
var on = this.__on, o, listener = wrap(value, i, group); | ||
function onAdd(typename, value, options) { | ||
return function() { | ||
var on = this.__on, o, listener = contextListener(value); | ||
if (on) for (var j = 0, m = on.length; j < m; ++j) { | ||
if ((o = on[j]).type === typename.type && o.name === typename.name) { | ||
this.removeEventListener(o.type, o.listener, o.capture); | ||
this.addEventListener(o.type, o.listener = listener, o.capture = capture); | ||
this.removeEventListener(o.type, o.listener, o.options); | ||
this.addEventListener(o.type, o.listener = listener, o.options = options); | ||
o.value = value; | ||
@@ -766,4 +743,4 @@ return; | ||
} | ||
this.addEventListener(typename.type, listener, capture); | ||
o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture}; | ||
this.addEventListener(typename.type, listener, options); | ||
o = {type: typename.type, name: typename.name, value: value, listener: listener, options: options}; | ||
if (!on) this.__on = [o]; | ||
@@ -774,3 +751,3 @@ else on.push(o); | ||
function selection_on(typename, value, capture) { | ||
function selection_on(typename, value, options) { | ||
var typenames = parseTypenames(typename + ""), i, n = typenames.length, t; | ||
@@ -791,18 +768,6 @@ | ||
on = value ? onAdd : onRemove; | ||
if (capture == null) capture = false; | ||
for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture)); | ||
for (i = 0; i < n; ++i) this.each(on(typenames[i], value, options)); | ||
return this; | ||
} | ||
function customEvent(event1, listener, that, args) { | ||
var event0 = exports.event; | ||
event1.sourceEvent = exports.event; | ||
exports.event = event1; | ||
try { | ||
return listener.apply(that, args); | ||
} finally { | ||
exports.event = event0; | ||
} | ||
} | ||
function dispatchEvent(node, type, params) { | ||
@@ -841,2 +806,10 @@ var window = defaultView(node), | ||
function* selection_iterator() { | ||
for (var groups = this._groups, 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]) yield node; | ||
} | ||
} | ||
} | ||
var root = [null]; | ||
@@ -885,3 +858,4 @@ | ||
on: selection_on, | ||
dispatch: selection_dispatch | ||
dispatch: selection_dispatch, | ||
[Symbol.iterator]: selection_iterator | ||
}; | ||
@@ -927,9 +901,3 @@ | ||
function sourceEvent() { | ||
var current = exports.event, source; | ||
while (source = current.sourceEvent) current = source; | ||
return current; | ||
} | ||
function point(node, event) { | ||
function pointer(event, node = event.currentTarget) { | ||
var svg = node.ownerSVGElement || node; | ||
@@ -948,36 +916,8 @@ | ||
function mouse(node) { | ||
var event = sourceEvent(); | ||
if (event.changedTouches) event = event.changedTouches[0]; | ||
return point(node, event); | ||
} | ||
function selectAll(selector) { | ||
return typeof selector === "string" | ||
? new Selection([document.querySelectorAll(selector)], [document.documentElement]) | ||
: new Selection([selector == null ? [] : selector], root); | ||
: new Selection([selector == null ? [] : Array.from(selector)], root); | ||
} | ||
function touch(node, touches, identifier) { | ||
if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches; | ||
for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) { | ||
if ((touch = touches[i]).identifier === identifier) { | ||
return point(node, touch); | ||
} | ||
} | ||
return null; | ||
} | ||
function touches(node, touches) { | ||
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; | ||
} | ||
exports.create = create; | ||
@@ -987,6 +927,5 @@ exports.creator = creator; | ||
exports.matcher = matcher; | ||
exports.mouse = mouse; | ||
exports.namespace = namespace; | ||
exports.namespaces = namespaces; | ||
exports.clientPoint = point; | ||
exports.pointer = pointer; | ||
exports.select = select; | ||
@@ -998,9 +937,6 @@ exports.selectAll = selectAll; | ||
exports.style = styleValue; | ||
exports.touch = touch; | ||
exports.touches = touches; | ||
exports.window = defaultView; | ||
exports.customEvent = customEvent; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
})); |
@@ -1,2 +0,2 @@ | ||
// https://d3js.org/d3-selection/ v1.4.0 Copyright 2019 Mike Bostock | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.d3=t.d3||{})}(this,function(t){"use strict";var n="http://www.w3.org/1999/xhtml",e={svg:"http://www.w3.org/2000/svg",xhtml:n,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function r(t){var n=t+="",r=n.indexOf(":");return r>=0&&"xmlns"!==(n=t.slice(0,r))&&(t=t.slice(r+1)),e.hasOwnProperty(n)?{space:e[n],local:t}:t}function i(t){var e=r(t);return(e.local?function(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}:function(t){return function(){var e=this.ownerDocument,r=this.namespaceURI;return r===n&&e.documentElement.namespaceURI===n?e.createElement(t):e.createElementNS(r,t)}})(e)}function o(){}function u(t){return null==t?o:function(){return this.querySelector(t)}}function c(){return[]}function s(t){return null==t?c:function(){return this.querySelectorAll(t)}}function a(t){return function(){return this.matches(t)}}function l(t){return new Array(t.length)}function f(t,n){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=n}f.prototype={constructor:f,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 h="$";function p(t,n,e,r,i,o){for(var u,c=0,s=n.length,a=o.length;c<a;++c)(u=n[c])?(u.__data__=o[c],r[c]=u):e[c]=new f(t,o[c]);for(;c<s;++c)(u=n[c])&&(i[c]=u)}function _(t,n,e,r,i,o,u){var c,s,a,l={},p=n.length,_=o.length,v=new Array(p);for(c=0;c<p;++c)(s=n[c])&&(v[c]=a=h+u.call(s,s.__data__,c,n),a in l?i[c]=s:l[a]=s);for(c=0;c<_;++c)(s=l[a=h+u.call(t,o[c],c,o)])?(r[c]=s,s.__data__=o[c],l[a]=null):e[c]=new f(t,o[c]);for(c=0;c<p;++c)(s=n[c])&&l[v[c]]===s&&(i[c]=s)}function v(t,n){return t<n?-1:t>n?1:t>=n?0:NaN}function d(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function y(t,n){return t.style.getPropertyValue(n)||d(t).getComputedStyle(t,null).getPropertyValue(n)}function m(t){return t.trim().split(/^|\s+/)}function g(t){return t.classList||new w(t)}function w(t){this._node=t,this._names=m(t.getAttribute("class")||"")}function A(t,n){for(var e=g(t),r=-1,i=n.length;++r<i;)e.add(n[r])}function x(t,n){for(var e=g(t),r=-1,i=n.length;++r<i;)e.remove(n[r])}function S(){this.textContent=""}function b(){this.innerHTML=""}function E(){this.nextSibling&&this.parentNode.appendChild(this)}function N(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function P(){return null}function C(){var t=this.parentNode;t&&t.removeChild(this)}function L(){return this.parentNode.insertBefore(this.cloneNode(!1),this.nextSibling)}function T(){return this.parentNode.insertBefore(this.cloneNode(!0),this.nextSibling)}w.prototype={add:function(t){this._names.indexOf(t)<0&&(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 B={};(t.event=null,"undefined"!=typeof document)&&("onmouseenter"in document.documentElement||(B={mouseenter:"mouseover",mouseleave:"mouseout"}));function q(t,n,e){return t=D(t,n,e),function(n){var e=n.relatedTarget;e&&(e===this||8&e.compareDocumentPosition(this))||t.call(this,n)}}function D(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 M(t){return function(){var n=this.__on;if(n){for(var e,r=0,i=-1,o=n.length;r<o;++r)e=n[r],t.type&&e.type!==t.type||e.name!==t.name?n[++i]=e:this.removeEventListener(e.type,e.listener,e.capture);++i?n.length=i:delete this.__on}}}function O(t,n,e){var r=B.hasOwnProperty(t.type)?q:D;return function(i,o,u){var c,s=this.__on,a=r(n,o,u);if(s)for(var l=0,f=s.length;l<f;++l)if((c=s[l]).type===t.type&&c.name===t.name)return this.removeEventListener(c.type,c.listener,c.capture),this.addEventListener(c.type,c.listener=a,c.capture=e),void(c.value=n);this.addEventListener(t.type,a,e),c={type:t.type,name:t.name,value:n,listener:a,capture:e},s?s.push(c):this.__on=[c]}}function V(t,n,e){var r=d(t),i=r.CustomEvent;"function"==typeof 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)}var j=[null];function R(t,n){this._groups=t,this._parents=n}function H(){return new R([[document.documentElement]],j)}function I(t){return"string"==typeof t?new R([[document.querySelector(t)]],[document.documentElement]):new R([[t]],j)}R.prototype=H.prototype={constructor:R,select:function(t){"function"!=typeof t&&(t=u(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i<e;++i)for(var o,c,s=n[i],a=s.length,l=r[i]=new Array(a),f=0;f<a;++f)(o=s[f])&&(c=t.call(o,o.__data__,f,s))&&("__data__"in o&&(c.__data__=o.__data__),l[f]=c);return new R(r,this._parents)},selectAll:function(t){"function"!=typeof t&&(t=s(t));for(var n=this._groups,e=n.length,r=[],i=[],o=0;o<e;++o)for(var u,c=n[o],a=c.length,l=0;l<a;++l)(u=c[l])&&(r.push(t.call(u,u.__data__,l,c)),i.push(u));return new R(r,i)},filter:function(t){"function"!=typeof t&&(t=a(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i<e;++i)for(var o,u=n[i],c=u.length,s=r[i]=[],l=0;l<c;++l)(o=u[l])&&t.call(o,o.__data__,l,u)&&s.push(o);return new R(r,this._parents)},data:function(t,n){if(!t)return d=new Array(this.size()),l=-1,this.each(function(t){d[++l]=t}),d;var e,r=n?_:p,i=this._parents,o=this._groups;"function"!=typeof t&&(e=t,t=function(){return e});for(var u=o.length,c=new Array(u),s=new Array(u),a=new Array(u),l=0;l<u;++l){var f=i[l],h=o[l],v=h.length,d=t.call(f,f&&f.__data__,l,i),y=d.length,m=s[l]=new Array(y),g=c[l]=new Array(y);r(f,h,m,g,a[l]=new Array(v),d,n);for(var w,A,x=0,S=0;x<y;++x)if(w=m[x]){for(x>=S&&(S=x+1);!(A=g[S])&&++S<y;);w._next=A||null}}return(c=new R(c,i))._enter=s,c._exit=a,c},enter:function(){return new R(this._enter||this._groups.map(l),this._parents)},exit:function(){return new R(this._exit||this._groups.map(l),this._parents)},join:function(t,n,e){var r=this.enter(),i=this,o=this.exit();return r="function"==typeof t?t(r):r.append(t+""),null!=n&&(i=n(i)),null==e?o.remove():e(o),r&&i?r.merge(i).order():i},merge:function(t){for(var n=this._groups,e=t._groups,r=n.length,i=e.length,o=Math.min(r,i),u=new Array(r),c=0;c<o;++c)for(var s,a=n[c],l=e[c],f=a.length,h=u[c]=new Array(f),p=0;p<f;++p)(s=a[p]||l[p])&&(h[p]=s);for(;c<r;++c)u[c]=n[c];return new R(u,this._parents)},order:function(){for(var t=this._groups,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&&4^r.compareDocumentPosition(u)&&u.parentNode.insertBefore(r,u),u=r);return this},sort:function(t){function n(n,e){return n&&e?t(n.__data__,e.__data__):!n-!e}t||(t=v);for(var e=this._groups,r=e.length,i=new Array(r),o=0;o<r;++o){for(var u,c=e[o],s=c.length,a=i[o]=new Array(s),l=0;l<s;++l)(u=c[l])&&(a[l]=u);a.sort(n)}return new R(i,this._parents).order()},call:function(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this},nodes:function(){var t=new Array(this.size()),n=-1;return this.each(function(){t[++n]=this}),t},node:function(){for(var t=this._groups,n=0,e=t.length;n<e;++n)for(var r=t[n],i=0,o=r.length;i<o;++i){var u=r[i];if(u)return u}return null},size:function(){var t=0;return this.each(function(){++t}),t},empty:function(){return!this.node()},each:function(t){for(var n=this._groups,e=0,r=n.length;e<r;++e)for(var i,o=n[e],u=0,c=o.length;u<c;++u)(i=o[u])&&t.call(i,i.__data__,u,o);return this},attr:function(t,n){var e=r(t);if(arguments.length<2){var i=this.node();return e.local?i.getAttributeNS(e.space,e.local):i.getAttribute(e)}return this.each((null==n?e.local?function(t){return function(){this.removeAttributeNS(t.space,t.local)}}:function(t){return function(){this.removeAttribute(t)}}:"function"==typeof n?e.local?function(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(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttribute(t):this.setAttribute(t,e)}}:e.local?function(t,n){return function(){this.setAttributeNS(t.space,t.local,n)}}:function(t,n){return function(){this.setAttribute(t,n)}})(e,n))},style:function(t,n,e){return arguments.length>1?this.each((null==n?function(t){return function(){this.style.removeProperty(t)}}:"function"==typeof n?function(t,n,e){return function(){var r=n.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,e)}}:function(t,n,e){return function(){this.style.setProperty(t,n,e)}})(t,n,null==e?"":e)):y(this.node(),t)},property:function(t,n){return arguments.length>1?this.each((null==n?function(t){return function(){delete this[t]}}:"function"==typeof n?function(t,n){return function(){var e=n.apply(this,arguments);null==e?delete this[t]:this[t]=e}}:function(t,n){return function(){this[t]=n}})(t,n)):this.node()[t]},classed:function(t,n){var e=m(t+"");if(arguments.length<2){for(var r=g(this.node()),i=-1,o=e.length;++i<o;)if(!r.contains(e[i]))return!1;return!0}return this.each(("function"==typeof n?function(t,n){return function(){(n.apply(this,arguments)?A:x)(this,t)}}:n?function(t){return function(){A(this,t)}}:function(t){return function(){x(this,t)}})(e,n))},text:function(t){return arguments.length?this.each(null==t?S:("function"==typeof t?function(t){return function(){var n=t.apply(this,arguments);this.textContent=null==n?"":n}}:function(t){return function(){this.textContent=t}})(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?b:("function"==typeof t?function(t){return function(){var n=t.apply(this,arguments);this.innerHTML=null==n?"":n}}:function(t){return function(){this.innerHTML=t}})(t)):this.node().innerHTML},raise:function(){return this.each(E)},lower:function(){return this.each(N)},append:function(t){var n="function"==typeof t?t:i(t);return this.select(function(){return this.appendChild(n.apply(this,arguments))})},insert:function(t,n){var e="function"==typeof t?t:i(t),r=null==n?P:"function"==typeof n?n:u(n);return this.select(function(){return this.insertBefore(e.apply(this,arguments),r.apply(this,arguments)||null)})},remove:function(){return this.each(C)},clone:function(t){return this.select(t?T:L)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,n,e){var r,i,o=function(t){return t.trim().split(/^|\s+/).map(function(t){var n="",e=t.indexOf(".");return e>=0&&(n=t.slice(e+1),t=t.slice(0,e)),{type:t,name:n}})}(t+""),u=o.length;if(!(arguments.length<2)){for(c=n?O:M,null==e&&(e=!1),r=0;r<u;++r)this.each(c(o[r],n,e));return this}var c=this.node().__on;if(c)for(var s,a=0,l=c.length;a<l;++a)for(r=0,s=c[a];r<u;++r)if((i=o[r]).type===s.type&&i.name===s.name)return s.value},dispatch:function(t,n){return this.each(("function"==typeof n?function(t,n){return function(){return V(this,t,n.apply(this,arguments))}}:function(t,n){return function(){return V(this,t,n)}})(t,n))}};var U=0;function z(){return new G}function G(){this._="@"+(++U).toString(36)}function X(){for(var n,e=t.event;n=e.sourceEvent;)e=n;return e}function k(t,n){var e=t.ownerSVGElement||t;if(e.createSVGPoint){var r=e.createSVGPoint();return r.x=n.clientX,r.y=n.clientY,[(r=r.matrixTransform(t.getScreenCTM().inverse())).x,r.y]}var i=t.getBoundingClientRect();return[n.clientX-i.left-t.clientLeft,n.clientY-i.top-t.clientTop]}G.prototype=z.prototype={constructor:G,get:function(t){for(var n=this._;!(n in t);)if(!(t=t.parentNode))return;return t[n]},set:function(t,n){return t[this._]=n},remove:function(t){return this._ in t&&delete t[this._]},toString:function(){return this._}},t.create=function(t){return I(i(t).call(document.documentElement))},t.creator=i,t.local=z,t.matcher=a,t.mouse=function(t){var n=X();return n.changedTouches&&(n=n.changedTouches[0]),k(t,n)},t.namespace=r,t.namespaces=e,t.clientPoint=k,t.select=I,t.selectAll=function(t){return"string"==typeof t?new R([document.querySelectorAll(t)],[document.documentElement]):new R([null==t?[]:t],j)},t.selection=H,t.selector=u,t.selectorAll=s,t.style=y,t.touch=function(t,n,e){arguments.length<3&&(e=n,n=X().changedTouches);for(var r,i=0,o=n?n.length:0;i<o;++i)if((r=n[i]).identifier===e)return k(t,r);return null},t.touches=function(t,n){null==n&&(n=X().touches);for(var e=0,r=n?n.length:0,i=new Array(r);e<r;++e)i[e]=k(t,n[e]);return i},t.window=d,t.customEvent=function(n,e,r,i){var o=t.event;n.sourceEvent=t.event,t.event=n;try{return e.apply(r,i)}finally{t.event=o}},Object.defineProperty(t,"__esModule",{value:!0})}); | ||
// https://d3js.org/d3-selection/ v2.0.0-rc.1 Copyright 2019 Mike Bostock | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).d3=t.d3||{})}(this,function(t){"use strict";var n="http://www.w3.org/1999/xhtml",e={svg:"http://www.w3.org/2000/svg",xhtml:n,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function r(t){var n=t+="",r=n.indexOf(":");return r>=0&&"xmlns"!==(n=t.slice(0,r))&&(t=t.slice(r+1)),e.hasOwnProperty(n)?{space:e[n],local:t}:t}function i(t){var e=r(t);return(e.local?function(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}:function(t){return function(){var e=this.ownerDocument,r=this.namespaceURI;return r===n&&e.documentElement.namespaceURI===n?e.createElement(t):e.createElementNS(r,t)}})(e)}function o(){}function u(t){return null==t?o:function(){return this.querySelector(t)}}function s(){return[]}function c(t){return null==t?s:function(){return this.querySelectorAll(t)}}function a(t){return function(){return this.matches(t)}}function l(t){return new Array(t.length)}function f(t,n){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=n}f.prototype={constructor:f,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 h="$";function p(t,n,e,r,i,o){for(var u,s=0,c=n.length,a=o.length;s<a;++s)(u=n[s])?(u.__data__=o[s],r[s]=u):e[s]=new f(t,o[s]);for(;s<c;++s)(u=n[s])&&(i[s]=u)}function _(t,n,e,r,i,o,u){var s,c,a,l={},p=n.length,_=o.length,d=new Array(p);for(s=0;s<p;++s)(c=n[s])&&(d[s]=a=h+u.call(c,c.__data__,s,n),a in l?i[s]=c:l[a]=c);for(s=0;s<_;++s)(c=l[a=h+u.call(t,o[s],s,o)])?(r[s]=c,c.__data__=o[s],l[a]=null):e[s]=new f(t,o[s]);for(s=0;s<p;++s)(c=n[s])&&l[d[s]]===c&&(i[s]=c)}function d(t){return t.__data__}function y(t){return Array.isArray(t)?t:Array.from(t)}function m(t,n){return t<n?-1:t>n?1:t>=n?0:NaN}function v(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function g(t,n){return t.style.getPropertyValue(n)||v(t).getComputedStyle(t,null).getPropertyValue(n)}function w(t){return t.trim().split(/^|\s+/)}function A(t){return t.classList||new x(t)}function x(t){this._node=t,this._names=w(t.getAttribute("class")||"")}function S(t,n){for(var e=A(t),r=-1,i=n.length;++r<i;)e.add(n[r])}function b(t,n){for(var e=A(t),r=-1,i=n.length;++r<i;)e.remove(n[r])}function E(){this.textContent=""}function N(){this.innerHTML=""}function C(){this.nextSibling&&this.parentNode.appendChild(this)}function L(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function P(){return null}function B(){var t=this.parentNode;t&&t.removeChild(this)}function q(){var t=this.cloneNode(!1),n=this.parentNode;return n?n.insertBefore(t,this.nextSibling):t}function M(){var t=this.cloneNode(!0),n=this.parentNode;return n?n.insertBefore(t,this.nextSibling):t}function T(t){return function(){var n=this.__on;if(n){for(var e,r=0,i=-1,o=n.length;r<o;++r)e=n[r],t.type&&e.type!==t.type||e.name!==t.name?n[++i]=e:this.removeEventListener(e.type,e.listener,e.options);++i?n.length=i:delete this.__on}}}function D(t,n,e){return function(){var r,i=this.__on,o=function(t){return function(n){t.call(this,n,this.__data__)}}(n);if(i)for(var u=0,s=i.length;u<s;++u)if((r=i[u]).type===t.type&&r.name===t.name)return this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=o,r.options=e),void(r.value=n);this.addEventListener(t.type,o,e),r={type:t.type,name:t.name,value:n,listener:o,options:e},i?i.push(r):this.__on=[r]}}function O(t,n,e){var r=v(t),i=r.CustomEvent;"function"==typeof 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)}x.prototype={add:function(t){this._names.indexOf(t)<0&&(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 V=[null];function j(t,n){this._groups=t,this._parents=n}function R(){return new j([[document.documentElement]],V)}function H(t){return"string"==typeof t?new j([[document.querySelector(t)]],[document.documentElement]):new j([[t]],V)}j.prototype=R.prototype={constructor:j,select:function(t){"function"!=typeof t&&(t=u(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i<e;++i)for(var o,s,c=n[i],a=c.length,l=r[i]=new Array(a),f=0;f<a;++f)(o=c[f])&&(s=t.call(o,o.__data__,f,c))&&("__data__"in o&&(s.__data__=o.__data__),l[f]=s);return new j(r,this._parents)},selectAll:function(t){"function"!=typeof t&&(t=c(t));for(var n=this._groups,e=n.length,r=[],i=[],o=0;o<e;++o)for(var u,s=n[o],a=s.length,l=0;l<a;++l)(u=s[l])&&(r.push(t.call(u,u.__data__,l,s)),i.push(u));return new j(r,i)},filter:function(t){"function"!=typeof t&&(t=a(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i<e;++i)for(var o,u=n[i],s=u.length,c=r[i]=[],l=0;l<s;++l)(o=u[l])&&t.call(o,o.__data__,l,u)&&c.push(o);return new j(r,this._parents)},data:function(t,n){if(!t)return Array.from(this,d);var e,r=n?_:p,i=this._parents,o=this._groups;"function"!=typeof t&&(e=t,t=function(){return e});for(var u=o.length,s=new Array(u),c=new Array(u),a=new Array(u),l=0;l<u;++l){var f=i[l],h=o[l],m=h.length,v=y(t.call(f,f&&f.__data__,l,i)),g=v.length,w=c[l]=new Array(g),A=s[l]=new Array(g);r(f,h,w,A,a[l]=new Array(m),v,n);for(var x,S,b=0,E=0;b<g;++b)if(x=w[b]){for(b>=E&&(E=b+1);!(S=A[E])&&++E<g;);x._next=S||null}}return(s=new j(s,i))._enter=c,s._exit=a,s},enter:function(){return new j(this._enter||this._groups.map(l),this._parents)},exit:function(){return new j(this._exit||this._groups.map(l),this._parents)},join:function(t,n,e){var r=this.enter(),i=this,o=this.exit();return r="function"==typeof t?t(r):r.append(t+""),null!=n&&(i=n(i)),null==e?o.remove():e(o),r&&i?r.merge(i).order():i},merge:function(t){if(!(t instanceof j))throw new Error("invalid merge");for(var n=this._groups,e=t._groups,r=n.length,i=e.length,o=Math.min(r,i),u=new Array(r),s=0;s<o;++s)for(var c,a=n[s],l=e[s],f=a.length,h=u[s]=new Array(f),p=0;p<f;++p)(c=a[p]||l[p])&&(h[p]=c);for(;s<r;++s)u[s]=n[s];return new j(u,this._parents)},order:function(){for(var t=this._groups,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&&4^r.compareDocumentPosition(u)&&u.parentNode.insertBefore(r,u),u=r);return this},sort:function(t){function n(n,e){return n&&e?t(n.__data__,e.__data__):!n-!e}t||(t=m);for(var e=this._groups,r=e.length,i=new Array(r),o=0;o<r;++o){for(var u,s=e[o],c=s.length,a=i[o]=new Array(c),l=0;l<c;++l)(u=s[l])&&(a[l]=u);a.sort(n)}return new j(i,this._parents).order()},call:function(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this},nodes:function(){return Array.from(this)},node:function(){for(var t=this._groups,n=0,e=t.length;n<e;++n)for(var r=t[n],i=0,o=r.length;i<o;++i){var u=r[i];if(u)return u}return null},size:function(){let t=0;for(const n of this)++t;return t},empty:function(){return!this.node()},each:function(t){for(var n=this._groups,e=0,r=n.length;e<r;++e)for(var i,o=n[e],u=0,s=o.length;u<s;++u)(i=o[u])&&t.call(i,i.__data__,u,o);return this},attr:function(t,n){var e=r(t);if(arguments.length<2){var i=this.node();return e.local?i.getAttributeNS(e.space,e.local):i.getAttribute(e)}return this.each((null==n?e.local?function(t){return function(){this.removeAttributeNS(t.space,t.local)}}:function(t){return function(){this.removeAttribute(t)}}:"function"==typeof n?e.local?function(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(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttribute(t):this.setAttribute(t,e)}}:e.local?function(t,n){return function(){this.setAttributeNS(t.space,t.local,n)}}:function(t,n){return function(){this.setAttribute(t,n)}})(e,n))},style:function(t,n,e){return arguments.length>1?this.each((null==n?function(t){return function(){this.style.removeProperty(t)}}:"function"==typeof n?function(t,n,e){return function(){var r=n.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,e)}}:function(t,n,e){return function(){this.style.setProperty(t,n,e)}})(t,n,null==e?"":e)):g(this.node(),t)},property:function(t,n){return arguments.length>1?this.each((null==n?function(t){return function(){delete this[t]}}:"function"==typeof n?function(t,n){return function(){var e=n.apply(this,arguments);null==e?delete this[t]:this[t]=e}}:function(t,n){return function(){this[t]=n}})(t,n)):this.node()[t]},classed:function(t,n){var e=w(t+"");if(arguments.length<2){for(var r=A(this.node()),i=-1,o=e.length;++i<o;)if(!r.contains(e[i]))return!1;return!0}return this.each(("function"==typeof n?function(t,n){return function(){(n.apply(this,arguments)?S:b)(this,t)}}:n?function(t){return function(){S(this,t)}}:function(t){return function(){b(this,t)}})(e,n))},text:function(t){return arguments.length?this.each(null==t?E:("function"==typeof t?function(t){return function(){var n=t.apply(this,arguments);this.textContent=null==n?"":n}}:function(t){return function(){this.textContent=t}})(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?N:("function"==typeof t?function(t){return function(){var n=t.apply(this,arguments);this.innerHTML=null==n?"":n}}:function(t){return function(){this.innerHTML=t}})(t)):this.node().innerHTML},raise:function(){return this.each(C)},lower:function(){return this.each(L)},append:function(t){var n="function"==typeof t?t:i(t);return this.select(function(){return this.appendChild(n.apply(this,arguments))})},insert:function(t,n){var e="function"==typeof t?t:i(t),r=null==n?P:"function"==typeof n?n:u(n);return this.select(function(){return this.insertBefore(e.apply(this,arguments),r.apply(this,arguments)||null)})},remove:function(){return this.each(B)},clone:function(t){return this.select(t?M:q)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,n,e){var r,i,o=function(t){return t.trim().split(/^|\s+/).map(function(t){var n="",e=t.indexOf(".");return e>=0&&(n=t.slice(e+1),t=t.slice(0,e)),{type:t,name:n}})}(t+""),u=o.length;if(!(arguments.length<2)){for(s=n?D:T,r=0;r<u;++r)this.each(s(o[r],n,e));return this}var s=this.node().__on;if(s)for(var c,a=0,l=s.length;a<l;++a)for(r=0,c=s[a];r<u;++r)if((i=o[r]).type===c.type&&i.name===c.name)return c.value},dispatch:function(t,n){return this.each(("function"==typeof n?function(t,n){return function(){return O(this,t,n.apply(this,arguments))}}:function(t,n){return function(){return O(this,t,n)}})(t,n))},[Symbol.iterator]:function*(){for(var t=this._groups,n=0,e=t.length;n<e;++n)for(var r,i=t[n],o=0,u=i.length;o<u;++o)(r=i[o])&&(yield r)}};var I=0;function U(){return new G}function G(){this._="@"+(++I).toString(36)}G.prototype=U.prototype={constructor:G,get:function(t){for(var n=this._;!(n in t);)if(!(t=t.parentNode))return;return t[n]},set:function(t,n){return t[this._]=n},remove:function(t){return this._ in t&&delete t[this._]},toString:function(){return this._}},t.create=function(t){return H(i(t).call(document.documentElement))},t.creator=i,t.local=U,t.matcher=a,t.namespace=r,t.namespaces=e,t.pointer=function(t,n=t.currentTarget){var e=n.ownerSVGElement||n;if(e.createSVGPoint){var r=e.createSVGPoint();return r.x=t.clientX,r.y=t.clientY,[(r=r.matrixTransform(n.getScreenCTM().inverse())).x,r.y]}var i=n.getBoundingClientRect();return[t.clientX-i.left-n.clientLeft,t.clientY-i.top-n.clientTop]},t.select=H,t.selectAll=function(t){return"string"==typeof t?new j([document.querySelectorAll(t)],[document.documentElement]):new j([null==t?[]:Array.from(t)],V)},t.selection=R,t.selector=u,t.selectorAll=c,t.style=g,t.window=v,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "d3-selection", | ||
"version": "1.4.0", | ||
"version": "2.0.0-rc.1", | ||
"publishConfig": { | ||
"tag": "next" | ||
}, | ||
"description": "Data-driven DOM manipulation: select elements and join them to data.", | ||
@@ -29,12 +32,11 @@ "keywords": [ | ||
"test": "tape 'test/**/*-test.js' && eslint src", | ||
"prepublishOnly": "rm -rf dist && yarn test", | ||
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd - && zip -j dist/${npm_package_name}.zip -- LICENSE README.md dist/${npm_package_name}.js dist/${npm_package_name}.min.js" | ||
"prepublishOnly": "rm -rf dist && yarn test" | ||
}, | ||
"devDependencies": { | ||
"eslint": "5", | ||
"jsdom": "12", | ||
"rollup": "0.64", | ||
"rollup-plugin-terser": "1", | ||
"eslint": "6", | ||
"jsdom": "15", | ||
"rollup": "1", | ||
"rollup-plugin-terser": "5", | ||
"tape": "4" | ||
} | ||
} |
189
README.md
@@ -16,3 +16,3 @@ # d3-selection | ||
```js | ||
var p = d3.selectAll("p"); | ||
const p = d3.selectAll("p"); | ||
p.attr("class", "graf"); | ||
@@ -46,3 +46,3 @@ p.style("color", "red"); | ||
var div = d3.selectAll("div"); | ||
const div = d3.selectAll("div"); | ||
@@ -91,3 +91,3 @@ </script> | ||
```js | ||
var anchor = d3.select("a"); | ||
const anchor = d3.select("a"); | ||
``` | ||
@@ -98,3 +98,3 @@ | ||
```js | ||
d3.selectAll("p").on("click", function() { | ||
d3.selectAll("p").on("click", function(event) { | ||
d3.select(this).style("color", "red"); | ||
@@ -109,3 +109,3 @@ }); | ||
```js | ||
var paragraph = d3.selectAll("p"); | ||
const paragraph = d3.selectAll("p"); | ||
``` | ||
@@ -124,3 +124,3 @@ | ||
```js | ||
var b = d3.selectAll("p").select("b"); | ||
const b = d3.selectAll("p").select("b"); | ||
``` | ||
@@ -131,3 +131,3 @@ | ||
```js | ||
var previous = d3.selectAll("p").select(function() { | ||
const previous = d3.selectAll("p").select(function() { | ||
return this.previousElementSibling; | ||
@@ -144,3 +144,3 @@ }); | ||
```js | ||
var b = d3.selectAll("p").selectAll("b"); | ||
const b = d3.selectAll("p").selectAll("b"); | ||
``` | ||
@@ -151,3 +151,3 @@ | ||
```js | ||
var sibling = d3.selectAll("p").selectAll(function() { | ||
const sibling = d3.selectAll("p").selectAll(function() { | ||
return [ | ||
@@ -169,3 +169,3 @@ this.previousElementSibling, | ||
```js | ||
var even = d3.selectAll("tr").filter(":nth-child(even)"); | ||
const even = d3.selectAll("tr").filter(":nth-child(even)"); | ||
``` | ||
@@ -176,3 +176,3 @@ | ||
```js | ||
var even = d3.selectAll("tr:nth-child(even)"); | ||
const even = d3.selectAll("tr:nth-child(even)"); | ||
``` | ||
@@ -183,9 +183,9 @@ | ||
```js | ||
var even = d3.selectAll("tr").filter(function(d, i) { return i & 1; }); | ||
const even = d3.selectAll("tr").filter((d, i) => i & 1); | ||
``` | ||
Or using [*selection*.select](#selection_select): | ||
Or using [*selection*.select](#selection_select) (and avoiding an arrow function, since *this* is needed to refer to the current element): | ||
```js | ||
var even = d3.selectAll("tr").select(function(d, i) { return i & 1 ? this : null; }); | ||
const even = d3.selectAll("tr").select(function(d, i) { return i & 1 ? this : null; }); | ||
``` | ||
@@ -201,14 +201,8 @@ | ||
This method is used internally by [*selection*.join](#selection_join) to merge the [enter](#selection_enter) and [update](#selection_data) selections after [binding data](#joining-data). You can also merge explicitly. For example: | ||
This method is used internally by [*selection*.join](#selection_join) to merge the [enter](#selection_enter) and [update](#selection_data) selections after [binding data](#joining-data). You can also merge explicitly, although note that since merging is based on element index, you should use operations that preserve index, such as [*selection*.select](#selection_select) instead of [*selection*.filter](#selection_filter). For example: | ||
```js | ||
var circle = svg.selectAll("circle").data(data) // UPDATE | ||
.style("fill", "blue"); | ||
circle.exit().remove(); // EXIT | ||
circle = circle.enter().append("circle") // ENTER | ||
.style("fill", "green") | ||
.merge(circle) // ENTER + UPDATE | ||
.style("stroke", "black"); | ||
const odd = selection.select(function(d, i) { return i & 1 ? this : null; )); | ||
const even = selection.select(function(d, i) { return i & 1 ? null : this; )); | ||
const merged = odd.merge(even); | ||
``` | ||
@@ -225,3 +219,3 @@ | ||
```js | ||
var div = selection.filter("div"); | ||
const div = selection.filter("div"); | ||
``` | ||
@@ -232,3 +226,3 @@ | ||
```js | ||
var div = selection.filter(d3.matcher("div")); | ||
const div = selection.filter(d3.matcher("div")); | ||
``` | ||
@@ -243,3 +237,3 @@ | ||
```js | ||
var div = selection.select("div"); | ||
const div = selection.select("div"); | ||
``` | ||
@@ -250,3 +244,3 @@ | ||
```js | ||
var div = selection.select(d3.selector("div")); | ||
const div = selection.select(d3.selector("div")); | ||
``` | ||
@@ -259,3 +253,3 @@ | ||
```js | ||
var div = selection.selectAll("div"); | ||
const div = selection.selectAll("div"); | ||
``` | ||
@@ -266,3 +260,3 @@ | ||
```js | ||
var div = selection.selectAll(d3.selectorAll("div")); | ||
const div = selection.selectAll(d3.selectorAll("div")); | ||
``` | ||
@@ -309,3 +303,3 @@ | ||
```js | ||
selection.classed("foo", function() { return Math.random() > 0.5; }); | ||
selection.classed("foo", () => Math.random() > 0.5); | ||
``` | ||
@@ -358,5 +352,3 @@ | ||
```js | ||
d3.selectAll("p").append(function() { | ||
return document.createElement("div"); | ||
}); | ||
d3.selectAll("p").append(() => document.createElement("div")); | ||
``` | ||
@@ -389,5 +381,3 @@ | ||
```js | ||
d3.selectAll("p").insert(function() { | ||
return document.createElement("div"); | ||
}); | ||
d3.selectAll("p").insert(() => document.createElement("div")); | ||
``` | ||
@@ -455,4 +445,11 @@ | ||
Given the specified element *name*, returns a single-element selection containing a detached element of the given name in the current document. | ||
Given the specified element *name*, returns a single-element selection containing a detached element of the given name in the current document. This method assumes the HTML namespace, so you must specify a namespace explicitly when creating SVG or other non-HTML elements; see [namespace](#namespace) for details on supported namespace prefixes. | ||
```js | ||
d3.create("svg") // equivalent to svg:svg | ||
d3.create("svg:svg") // more explicitly | ||
d3.create("svg:g") // an SVG G element | ||
d3.create("g") // an HTML G (unknown) element | ||
``` | ||
<a name="creator" href="#creator">#</a> d3.<b>creator</b>(<i>name</i>) [<>](https://github.com/d3/d3-selection/blob/master/src/creator.js "Source") | ||
@@ -476,3 +473,3 @@ | ||
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. | ||
For an introduction to D3’s data joins, see the [*selection*.join notebook](https://observablehq.com/@d3/selection-join). Also see [Thinking With Joins](http://bost.ocks.org/mike/join/). | ||
@@ -488,3 +485,3 @@ <a name="selection_data" href="#selection_data">#</a> <i>selection</i>.<b>data</b>([<i>data</i>[, <i>key</i>]]) [<>](https://github.com/d3/d3-selection/blob/master/src/selection/data.js "Source") | ||
```js | ||
var matrix = [ | ||
const matrix = [ | ||
[11975, 5871, 8916, 2868], | ||
@@ -496,12 +493,11 @@ [ 1951, 10048, 2060, 6171], | ||
var tr = d3.select("body") | ||
d3.select("body") | ||
.append("table") | ||
.selectAll("tr") | ||
.data(matrix) | ||
.join("tr"); | ||
var td = tr.selectAll("td") | ||
.data(function(d) { return d; }) | ||
.join("tr") | ||
.selectAll("td") | ||
.data(d => d) | ||
.join("td") | ||
.text(function(d) { return d; }); | ||
.text(d => d); | ||
``` | ||
@@ -528,3 +524,3 @@ | ||
```js | ||
var data = [ | ||
const data = [ | ||
{name: "Locke", number: 4}, | ||
@@ -540,3 +536,3 @@ {name: "Reyes", number: 8}, | ||
.data(data, function(d) { return d ? d.name : this.id; }) | ||
.text(function(d) { return d.number; }); | ||
.text(d => d.number); | ||
``` | ||
@@ -554,3 +550,3 @@ | ||
Appends, removes and reorders elements as necessary to match the data that was previously bound by [*selection*.data](#selection_data), returning the [merged](#selection_merge) enter and update selection. This method is a convenient alternative to the more explicit [*selection*.enter](#selection_enter), [*selection*.exit](#selection_exit), [*selection*.append](#selection_append) and [*selection*.remove](#selection_remove)). For example: | ||
Appends, removes and reorders elements as necessary to match the data that was previously bound by [*selection*.data](#selection_data), returning the [merged](#selection_merge) enter and update selection. This method is a convenient alternative to the explicit [general update pattern](https://bl.ocks.org/mbostock/3808218), replacing [*selection*.enter](#selection_enter), [*selection*.exit](#selection_exit), [*selection*.append](#selection_append), [*selection*.remove](#selection_remove), and [*selection*.order](#selection_order). For example: | ||
@@ -560,41 +556,38 @@ ```js | ||
.data(data) | ||
.join( | ||
enter => enter.append("circle").attr("fill", "green"), | ||
update => update.attr("fill", "blue") | ||
) | ||
.join("circle") | ||
.attr("fill", "none") | ||
.attr("stroke", "black"); | ||
``` | ||
See the [*selection*.join Observable notebook](https://beta.observablehq.com/d/6c522dda5dd9daa3) for more examples. | ||
The *enter* function may be specified as a string shorthand, as above, which is equivalent to [*selection*.append](#selection_append) with the given element name. Likewise, optional *update* and *exit* functions may be specified, which default to the identity function and calling [*selection*.remove](#selection_remove), respectively. The shorthand above is thus equivalent to: | ||
This is equivalent to the [General Update Pattern](http://bl.ocks.org/mbostock/3808218): | ||
```js | ||
var circle = svg.selectAll("circle") // 1 | ||
.data(data) // 2 | ||
.attr("fill", "blue"); // 3 | ||
svg.selectAll("circle") | ||
.data(data) | ||
.join( | ||
enter => enter.append("circle"), | ||
update => update, | ||
exit => exit.remove() | ||
) | ||
.attr("fill", "none") | ||
.attr("stroke", "black"); | ||
```` | ||
circle.exit().remove(); // 4 | ||
By passing separate functions on enter, update and exit, you have greater control over what happens. And by specifying a key function to [*selection*.data](#selection_data), you can minimize changes to the DOM to optimize performance. For example, to set different fill colors for enter and update: | ||
circle = circle.enter().append("circle") // 5, 9 | ||
.attr("fill", "green") // 6 | ||
.merge(circle) // 7 | ||
.order() // 8 | ||
.attr("stroke", "black"); // 9 | ||
```js | ||
svg.selectAll("circle") | ||
.data(data) | ||
.join( | ||
enter => enter.append("circle").attr("fill", "green"), | ||
update => update.attr("fill", "blue") | ||
) | ||
.attr("stroke", "black"); | ||
``` | ||
Breaking this down into discrete steps: | ||
The selections returned by the *enter* and *update* functions are merged and then returned by *selection*.join. | ||
1. Any existing circles (that are descendants of the `svg` selection) are [selected](#selection_selectAll). | ||
2. These circles are [joined to new `data`](#selection_data), returning the matching circles: the *update* selection. | ||
3. These updating circles are given a blue fill. | ||
4. Any existing circles that do *not* match new data—the *exit* selection—are removed. | ||
5. New circles are [appended](#selection_append) for any new data that do *not* match any existing circle: the *enter* selection. | ||
6. These entering circles are given a green fill. | ||
7. A new selection representing the [union](#selection_merge) of entering and updating circles is created. | ||
8. These entering and updating circles are reordered to match the data (if necessary). | ||
9. The circles are given a black stroke. | ||
10. The circles are stored in the variable `circle`. | ||
You also animate enter, update and exit by creating transitions inside the *enter*, *update* and *exit* functions. To avoid breaking the method chain, use *selection*.call to create transitions, or return an undefined enter or update selection to prevent merging: the return value of the *enter* and *update* functions specifies the two selections to merge and return by *selection*.join. | ||
As described in the preceding paragraphs, the “matching” logic is determined by the key function passed to *selection*.data; since no key function is used in the above code sample, the elements and data are joined by index. | ||
For more, see the [*selection*.join notebook](https://observablehq.com/@d3/selection-join). | ||
@@ -608,7 +601,7 @@ <a name="selection_enter" href="#selection_enter">#</a> <i>selection</i>.<b>enter</b>() [<>](https://github.com/d3/d3-selection/blob/master/src/selection/enter.js "Source") | ||
```js | ||
var div = d3.select("body") | ||
const div = d3.select("body") | ||
.selectAll("div") | ||
.data([4, 8, 15, 16, 23, 42]) | ||
.enter().append("div") | ||
.text(function(d) { return d; }); | ||
.text(d => d); | ||
``` | ||
@@ -636,3 +629,3 @@ | ||
```js | ||
div = div.data([1, 2, 4, 8, 16, 32], function(d) { return d; }); | ||
div = div.data([1, 2, 4, 8, 16, 32], d => d); | ||
``` | ||
@@ -643,3 +636,3 @@ | ||
```js | ||
div.enter().append("div").text(function(d) { return d; }); | ||
div.enter().append("div").text(d => d); | ||
``` | ||
@@ -697,3 +690,3 @@ | ||
When a specified event is dispatched on a selected element, the specified *listener* will be evaluated for the element, being passed the current datum (*d*), the current index (*i*), and the current group (*nodes*), with *this* as the current DOM element (*nodes*[*i*]). 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). | ||
When a specified event is dispatched on a selected element, the specified *listener* will be evaluated for the element, being passed the current event (*event*) and the current datum (*d*), with *this* as the current DOM element (*event*.currentTarget). Listeners always see the latest datum for their element. Note: while you can use [*event*.pageX](https://developer.mozilla.org/en/DOM/event.pageX) and [*event*.pageY](https://developer.mozilla.org/en/DOM/event.pageY) directly, it is often convenient to transform the event position to the local coordinate system of the element that received the event using [d3.pointer](#pointer). | ||
@@ -716,28 +709,6 @@ If an event listener was previously registered for the same *typename* on a selected element, the old listener is removed before the new listener is added. 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 *typename*, where `foo` is the name; to remove all listeners with no name, specify `.` as the *typename*. | ||
<a name="event" href="#event">#</a> d3.<b>event</b> | ||
<a name="pointer" href="#pointer">#</a> d3.<b>pointer</b>(<i>event</i>[, <i>target</i>]) [<>](https://github.com/d3/d3-selection/blob/master/src/pointer.js "Source") | ||
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). | ||
Returns a two-element array of numbers [*x*, *y*] representing the coordinates of the specified *event* relative to the specified *target*. (The *event* may also be a [touch](https://www.w3.org/TR/touch-events/#touch-interface).) The target may be an HTML or SVG element, such as a [G element](http://www.w3.org/TR/SVG/struct.html#Groups). If *target* is not specified, it defaults to *event*.currentTarget. | ||
If you use Babel, Webpack, or another ES6-to-ES5 bundler, be aware that the value of d3.event changes during an event! An import of d3.event must be a [live binding](http://www.2ality.com/2015/07/es6-module-exports.html), so you may need to configure the bundler to import from D3’s ES6 modules rather than from the generated UMD bundle; not all bundlers observe [jsnext:main](https://github.com/rollup/rollup/wiki/jsnext:main). Also beware of conflicts with the [*window*.event](https://developer.mozilla.org/en-US/docs/Web/API/Window/event) global. | ||
<a name="customEvent" href="#customEvent">#</a> d3.<b>customEvent</b>(<i>event</i>, <i>listener</i>[, <i>that</i>[, <i>arguments</i>]]) [<>](https://github.com/d3/d3-selection/blob/master/src/selection/on.js#L98 "Source") | ||
Invokes the specified *listener*, using the specified *that* `this` context and passing the specified *arguments*, if any. During the invocation, [d3.event](#event) is set to the specified *event*; after the listener returns (or throws an error), d3.event is restored to its previous value. In addition, sets *event*.sourceEvent to the prior value of d3.event, allowing custom events to retain a reference to the originating native event. Returns the value returned by the *listener*. | ||
<a name="mouse" href="#mouse">#</a> d3.<b>mouse</b>(<i>container</i>) [<>](https://github.com/d3/d3-selection/blob/master/src/mouse.js "Source") | ||
Returns the *x* and *y* coordinates of the [current event](#event) relative to the specified *container*. The container may be an HTML or SVG container element, such as a [G element](http://www.w3.org/TR/SVG/struct.html#Groups) or an [SVG element](http://www.w3.org/TR/SVG/struct.html#SVGElement). The coordinates are returned as a two-element array of numbers [*x*, *y*]. | ||
<a name="touch" href="#touch">#</a> d3.<b>touch</b>(<i>container</i>[, <i>touches</i>], <i>identifier</i>) [<>](https://github.com/d3/d3-selection/blob/master/src/touch.js "Source") | ||
Returns the *x* and *y* coordinates of the touch with the specified *identifier* associated with the [current event](#event) relative to the specified *container*. The container may be an HTML or SVG container element, such as a [G element](http://www.w3.org/TR/SVG/struct.html#Groups) or an [SVG element](http://www.w3.org/TR/SVG/struct.html#SVGElement). The coordinates are returned as a two-element array of numbers [*x*, *y*]. If there is no touch with the specified identifier in *touches*, returns null; this can be useful for ignoring touchmove events where the only some touches have moved. If *touches* is not specified, it defaults to the current event’s [changedTouches](http://developer.apple.com/library/safari/documentation/UserExperience/Reference/TouchEventClassReference/TouchEvent/TouchEvent.html#//apple_ref/javascript/instp/TouchEvent/changedTouches) property. | ||
<a name="touches" href="#touches">#</a> d3.<b>touches</b>(<i>container</i>[, <i>touches</i>]) [<>](https://github.com/d3/d3-selection/blob/master/src/touches.js "Source") | ||
Returns the *x* and *y* coordinates of the touches associated with the [current event](#event) relative to the specified *container*. The container may be an HTML or SVG container element, such as a [G element](http://www.w3.org/TR/SVG/struct.html#Groups) or an [SVG element](http://www.w3.org/TR/SVG/struct.html#SVGElement). The coordinates are returned as an array of two-element arrays of numbers \[\[*x1*, *y1*], [*x2*, *y2*], …\]. If *touches* is not specified, it defaults to the current event’s [touches](http://developer.apple.com/library/safari/documentation/UserExperience/Reference/TouchEventClassReference/TouchEvent/TouchEvent.html#//apple_ref/javascript/instp/TouchEvent/touches) property. | ||
<a name="clientPoint" href="#clientPoint">#</a> d3.<b>clientPoint</b>(<i>container</i>, <i>event</i>) [<>](https://github.com/d3/d3-selection/blob/master/src/point.js "Source") | ||
Returns the *x* and *y* coordinates of the specified *event* relative to the specified *container*. (The *event* may also be a [touch](https://www.w3.org/TR/touch-events/#touch-interface).) The container may be an HTML or SVG container element, such as a [G element](http://www.w3.org/TR/SVG/struct.html#Groups) or an [SVG element](http://www.w3.org/TR/SVG/struct.html#SVGElement). The coordinates are returned as a two-element array of numbers [*x*, *y*]. | ||
### Control Flow | ||
@@ -755,3 +726,3 @@ | ||
.selectAll(".child") | ||
.text(function(d, i) { return "child " + d.name + " of " + p.name; }); | ||
.text(d => `child ${d.name} of ${p.name}`); | ||
}); | ||
@@ -813,3 +784,3 @@ ``` | ||
```js | ||
var foo = d3.local(); | ||
const foo = d3.local(); | ||
``` | ||
@@ -830,3 +801,3 @@ | ||
```js | ||
selection.property(foo, function(d) { return d.value; }); | ||
selection.property(foo, d => d.value); | ||
``` | ||
@@ -833,0 +804,0 @@ |
@@ -1,3 +0,3 @@ | ||
import creator from "./creator"; | ||
import select from "./select"; | ||
import creator from "./creator.js"; | ||
import select from "./select.js"; | ||
@@ -4,0 +4,0 @@ export default function(name) { |
@@ -1,3 +0,3 @@ | ||
import namespace from "./namespace"; | ||
import {xhtml} from "./namespaces"; | ||
import namespace from "./namespace.js"; | ||
import {xhtml} from "./namespaces.js"; | ||
@@ -4,0 +4,0 @@ function creatorInherit(name) { |
@@ -1,18 +0,14 @@ | ||
export {default as create} from "./create"; | ||
export {default as creator} from "./creator"; | ||
export {default as local} from "./local"; | ||
export {default as matcher} from "./matcher"; | ||
export {default as mouse} from "./mouse"; | ||
export {default as namespace} from "./namespace"; | ||
export {default as namespaces} from "./namespaces"; | ||
export {default as clientPoint} from "./point"; | ||
export {default as select} from "./select"; | ||
export {default as selectAll} from "./selectAll"; | ||
export {default as selection} from "./selection/index"; | ||
export {default as selector} from "./selector"; | ||
export {default as selectorAll} from "./selectorAll"; | ||
export {styleValue as style} from "./selection/style"; | ||
export {default as touch} from "./touch"; | ||
export {default as touches} from "./touches"; | ||
export {default as window} from "./window"; | ||
export {event, customEvent} from "./selection/on"; | ||
export {default as create} from "./create.js"; | ||
export {default as creator} from "./creator.js"; | ||
export {default as local} from "./local.js"; | ||
export {default as matcher} from "./matcher.js"; | ||
export {default as namespace} from "./namespace.js"; | ||
export {default as namespaces} from "./namespaces.js"; | ||
export {default as pointer} from "./pointer.js"; | ||
export {default as select} from "./select.js"; | ||
export {default as selectAll} from "./selectAll.js"; | ||
export {default as selection} from "./selection/index.js"; | ||
export {default as selector} from "./selector.js"; | ||
export {default as selectorAll} from "./selectorAll.js"; | ||
export {styleValue as style} from "./selection/style.js"; | ||
export {default as window} from "./window.js"; |
@@ -1,2 +0,2 @@ | ||
import namespaces from "./namespaces"; | ||
import namespaces from "./namespaces.js"; | ||
@@ -6,3 +6,3 @@ export default function(name) { | ||
if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1); | ||
return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; | ||
return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; // eslint-disable-line no-prototype-builtins | ||
} |
@@ -1,2 +0,2 @@ | ||
import {Selection, root} from "./selection/index"; | ||
import {Selection, root} from "./selection/index.js"; | ||
@@ -3,0 +3,0 @@ export default function(selector) { |
@@ -1,2 +0,2 @@ | ||
import {Selection, root} from "./selection/index"; | ||
import {Selection, root} from "./selection/index.js"; | ||
@@ -6,3 +6,3 @@ export default function(selector) { | ||
? new Selection([document.querySelectorAll(selector)], [document.documentElement]) | ||
: new Selection([selector == null ? [] : selector], root); | ||
: new Selection([selector == null ? [] : Array.from(selector)], root); | ||
} |
@@ -1,2 +0,2 @@ | ||
import creator from "../creator"; | ||
import creator from "../creator.js"; | ||
@@ -3,0 +3,0 @@ export default function(name) { |
@@ -1,2 +0,2 @@ | ||
import namespace from "../namespace"; | ||
import namespace from "../namespace.js"; | ||
@@ -3,0 +3,0 @@ function attrRemove(name) { |
function selection_cloneShallow() { | ||
return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling); | ||
var clone = this.cloneNode(false), parent = this.parentNode; | ||
return parent ? parent.insertBefore(clone, this.nextSibling) : clone; | ||
} | ||
function selection_cloneDeep() { | ||
return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling); | ||
var clone = this.cloneNode(true), parent = this.parentNode; | ||
return parent ? parent.insertBefore(clone, this.nextSibling) : clone; | ||
} | ||
@@ -8,0 +10,0 @@ |
@@ -1,4 +0,4 @@ | ||
import {Selection} from "./index"; | ||
import {EnterNode} from "./enter"; | ||
import constant from "../constant"; | ||
import {Selection} from "./index.js"; | ||
import {EnterNode} from "./enter.js"; | ||
import constant from "../constant.js"; | ||
@@ -77,8 +77,12 @@ var keyPrefix = "$"; // Protect against keys like “__proto__”. | ||
function datum(node) { | ||
return node.__data__; | ||
} | ||
function arrayify(data) { | ||
return Array.isArray(data) ? data : Array.from(data); | ||
} | ||
export default function(value, key) { | ||
if (!value) { | ||
data = new Array(this.size()), j = -1; | ||
this.each(function(d) { data[++j] = d; }); | ||
return data; | ||
} | ||
if (!value) return Array.from(this, datum); | ||
@@ -95,3 +99,3 @@ var bind = key ? bindKey : bindIndex, | ||
groupLength = group.length, | ||
data = value.call(parent, parent && parent.__data__, j, parents), | ||
data = arrayify(value.call(parent, parent && parent.__data__, j, parents)), | ||
dataLength = data.length, | ||
@@ -98,0 +102,0 @@ enterGroup = enter[j] = new Array(dataLength), |
@@ -1,2 +0,2 @@ | ||
import defaultView from "../window"; | ||
import defaultView from "../window.js"; | ||
@@ -3,0 +3,0 @@ function dispatchEvent(node, type, params) { |
@@ -1,3 +0,3 @@ | ||
import sparse from "./sparse"; | ||
import {Selection} from "./index"; | ||
import sparse from "./sparse.js"; | ||
import {Selection} from "./index.js"; | ||
@@ -4,0 +4,0 @@ export default function() { |
@@ -1,3 +0,3 @@ | ||
import sparse from "./sparse"; | ||
import {Selection} from "./index"; | ||
import sparse from "./sparse.js"; | ||
import {Selection} from "./index.js"; | ||
@@ -4,0 +4,0 @@ export default function() { |
@@ -1,3 +0,3 @@ | ||
import {Selection} from "./index"; | ||
import matcher from "../matcher"; | ||
import {Selection} from "./index.js"; | ||
import matcher from "../matcher.js"; | ||
@@ -4,0 +4,0 @@ export default function(match) { |
@@ -1,32 +0,33 @@ | ||
import selection_select from "./select"; | ||
import selection_selectAll from "./selectAll"; | ||
import selection_filter from "./filter"; | ||
import selection_data from "./data"; | ||
import selection_enter from "./enter"; | ||
import selection_exit from "./exit"; | ||
import selection_join from "./join"; | ||
import selection_merge from "./merge"; | ||
import selection_order from "./order"; | ||
import selection_sort from "./sort"; | ||
import selection_call from "./call"; | ||
import selection_nodes from "./nodes"; | ||
import selection_node from "./node"; | ||
import selection_size from "./size"; | ||
import selection_empty from "./empty"; | ||
import selection_each from "./each"; | ||
import selection_attr from "./attr"; | ||
import selection_style from "./style"; | ||
import selection_property from "./property"; | ||
import selection_classed from "./classed"; | ||
import selection_text from "./text"; | ||
import selection_html from "./html"; | ||
import selection_raise from "./raise"; | ||
import selection_lower from "./lower"; | ||
import selection_append from "./append"; | ||
import selection_insert from "./insert"; | ||
import selection_remove from "./remove"; | ||
import selection_clone from "./clone"; | ||
import selection_datum from "./datum"; | ||
import selection_on from "./on"; | ||
import selection_dispatch from "./dispatch"; | ||
import selection_select from "./select.js"; | ||
import selection_selectAll from "./selectAll.js"; | ||
import selection_filter from "./filter.js"; | ||
import selection_data from "./data.js"; | ||
import selection_enter from "./enter.js"; | ||
import selection_exit from "./exit.js"; | ||
import selection_join from "./join.js"; | ||
import selection_merge from "./merge.js"; | ||
import selection_order from "./order.js"; | ||
import selection_sort from "./sort.js"; | ||
import selection_call from "./call.js"; | ||
import selection_nodes from "./nodes.js"; | ||
import selection_node from "./node.js"; | ||
import selection_size from "./size.js"; | ||
import selection_empty from "./empty.js"; | ||
import selection_each from "./each.js"; | ||
import selection_attr from "./attr.js"; | ||
import selection_style from "./style.js"; | ||
import selection_property from "./property.js"; | ||
import selection_classed from "./classed.js"; | ||
import selection_text from "./text.js"; | ||
import selection_html from "./html.js"; | ||
import selection_raise from "./raise.js"; | ||
import selection_lower from "./lower.js"; | ||
import selection_append from "./append.js"; | ||
import selection_insert from "./insert.js"; | ||
import selection_remove from "./remove.js"; | ||
import selection_clone from "./clone.js"; | ||
import selection_datum from "./datum.js"; | ||
import selection_on from "./on.js"; | ||
import selection_dispatch from "./dispatch.js"; | ||
import selection_iterator from "./iterator.js"; | ||
@@ -76,5 +77,6 @@ export var root = [null]; | ||
on: selection_on, | ||
dispatch: selection_dispatch | ||
dispatch: selection_dispatch, | ||
[Symbol.iterator]: selection_iterator | ||
}; | ||
export default selection; |
@@ -1,3 +0,3 @@ | ||
import creator from "../creator"; | ||
import selector from "../selector"; | ||
import creator from "../creator.js"; | ||
import selector from "../selector.js"; | ||
@@ -4,0 +4,0 @@ function constantNull() { |
@@ -1,4 +0,5 @@ | ||
import {Selection} from "./index"; | ||
import {Selection} from "./index.js"; | ||
export default function(selection) { | ||
if (!(selection instanceof Selection)) throw new Error("invalid merge"); | ||
@@ -5,0 +6,0 @@ for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) { |
export default function() { | ||
var nodes = new Array(this.size()), i = -1; | ||
this.each(function() { nodes[++i] = this; }); | ||
return nodes; | ||
return Array.from(this); | ||
} |
@@ -1,34 +0,7 @@ | ||
var filterEvents = {}; | ||
export var event = null; | ||
if (typeof document !== "undefined") { | ||
var element = document.documentElement; | ||
if (!("onmouseenter" in element)) { | ||
filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"}; | ||
} | ||
} | ||
function filterContextListener(listener, index, group) { | ||
listener = contextListener(listener, index, group); | ||
function contextListener(listener) { | ||
return function(event) { | ||
var related = event.relatedTarget; | ||
if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) { | ||
listener.call(this, event); | ||
} | ||
listener.call(this, event, this.__data__); | ||
}; | ||
} | ||
function contextListener(listener, index, group) { | ||
return function(event1) { | ||
var event0 = event; // Events can be reentrant (e.g., focus). | ||
event = event1; | ||
try { | ||
listener.call(this, this.__data__, index, group); | ||
} finally { | ||
event = event0; | ||
} | ||
}; | ||
} | ||
function parseTypenames(typenames) { | ||
@@ -48,3 +21,3 @@ return typenames.trim().split(/^|\s+/).map(function(t) { | ||
if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) { | ||
this.removeEventListener(o.type, o.listener, o.capture); | ||
this.removeEventListener(o.type, o.listener, o.options); | ||
} else { | ||
@@ -59,10 +32,9 @@ on[++i] = o; | ||
function onAdd(typename, value, capture) { | ||
var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener; | ||
return function(d, i, group) { | ||
var on = this.__on, o, listener = wrap(value, i, group); | ||
function onAdd(typename, value, options) { | ||
return function() { | ||
var on = this.__on, o, listener = contextListener(value); | ||
if (on) for (var j = 0, m = on.length; j < m; ++j) { | ||
if ((o = on[j]).type === typename.type && o.name === typename.name) { | ||
this.removeEventListener(o.type, o.listener, o.capture); | ||
this.addEventListener(o.type, o.listener = listener, o.capture = capture); | ||
this.removeEventListener(o.type, o.listener, o.options); | ||
this.addEventListener(o.type, o.listener = listener, o.options = options); | ||
o.value = value; | ||
@@ -72,4 +44,4 @@ return; | ||
} | ||
this.addEventListener(typename.type, listener, capture); | ||
o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture}; | ||
this.addEventListener(typename.type, listener, options); | ||
o = {type: typename.type, name: typename.name, value: value, listener: listener, options: options}; | ||
if (!on) this.__on = [o]; | ||
@@ -80,3 +52,3 @@ else on.push(o); | ||
export default function(typename, value, capture) { | ||
export default function(typename, value, options) { | ||
var typenames = parseTypenames(typename + ""), i, n = typenames.length, t; | ||
@@ -97,16 +69,4 @@ | ||
on = value ? onAdd : onRemove; | ||
if (capture == null) capture = false; | ||
for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture)); | ||
for (i = 0; i < n; ++i) this.each(on(typenames[i], value, options)); | ||
return this; | ||
} | ||
export function customEvent(event1, listener, that, args) { | ||
var event0 = event; | ||
event1.sourceEvent = event; | ||
event = event1; | ||
try { | ||
return listener.apply(that, args); | ||
} finally { | ||
event = event0; | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
import {Selection} from "./index"; | ||
import selector from "../selector"; | ||
import {Selection} from "./index.js"; | ||
import selector from "../selector.js"; | ||
@@ -4,0 +4,0 @@ export default function(select) { |
@@ -1,3 +0,3 @@ | ||
import {Selection} from "./index"; | ||
import selectorAll from "../selectorAll"; | ||
import {Selection} from "./index.js"; | ||
import selectorAll from "../selectorAll.js"; | ||
@@ -4,0 +4,0 @@ export default function(select) { |
export default function() { | ||
var size = 0; | ||
this.each(function() { ++size; }); | ||
let size = 0; | ||
for (const node of this) ++size; // eslint-disable-line no-unused-vars | ||
return size; | ||
} |
@@ -1,2 +0,2 @@ | ||
import {Selection} from "./index"; | ||
import {Selection} from "./index.js"; | ||
@@ -3,0 +3,0 @@ export default function(compare) { |
@@ -1,2 +0,2 @@ | ||
import defaultView from "../window"; | ||
import defaultView from "../window.js"; | ||
@@ -3,0 +3,0 @@ function styleRemove(name) { |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
191999
57
1701
1
808