source: node_modules/d3-selection/dist/d3-selection.js@ a762898

Last change on this file since a762898 was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 27.2 KB
Line 
1// https://d3js.org/d3-selection/ v3.0.0 Copyright 2010-2021 Mike Bostock
2(function (global, factory) {
3typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4typeof define === 'function' && define.amd ? define(['exports'], factory) :
5(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
6}(this, (function (exports) { 'use strict';
7
8var xhtml = "http://www.w3.org/1999/xhtml";
9
10var namespaces = {
11 svg: "http://www.w3.org/2000/svg",
12 xhtml: xhtml,
13 xlink: "http://www.w3.org/1999/xlink",
14 xml: "http://www.w3.org/XML/1998/namespace",
15 xmlns: "http://www.w3.org/2000/xmlns/"
16};
17
18function namespace(name) {
19 var prefix = name += "", i = prefix.indexOf(":");
20 if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
21 return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; // eslint-disable-line no-prototype-builtins
22}
23
24function creatorInherit(name) {
25 return function() {
26 var document = this.ownerDocument,
27 uri = this.namespaceURI;
28 return uri === xhtml && document.documentElement.namespaceURI === xhtml
29 ? document.createElement(name)
30 : document.createElementNS(uri, name);
31 };
32}
33
34function creatorFixed(fullname) {
35 return function() {
36 return this.ownerDocument.createElementNS(fullname.space, fullname.local);
37 };
38}
39
40function creator(name) {
41 var fullname = namespace(name);
42 return (fullname.local
43 ? creatorFixed
44 : creatorInherit)(fullname);
45}
46
47function none() {}
48
49function selector(selector) {
50 return selector == null ? none : function() {
51 return this.querySelector(selector);
52 };
53}
54
55function selection_select(select) {
56 if (typeof select !== "function") select = selector(select);
57
58 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
59 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
60 if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
61 if ("__data__" in node) subnode.__data__ = node.__data__;
62 subgroup[i] = subnode;
63 }
64 }
65 }
66
67 return new Selection(subgroups, this._parents);
68}
69
70// Given something array like (or null), returns something that is strictly an
71// array. This is used to ensure that array-like objects passed to d3.selectAll
72// or selection.selectAll are converted into proper arrays when creating a
73// selection; we don’t ever want to create a selection backed by a live
74// HTMLCollection or NodeList. However, note that selection.selectAll will use a
75// static NodeList as a group, since it safely derived from querySelectorAll.
76function array(x) {
77 return x == null ? [] : Array.isArray(x) ? x : Array.from(x);
78}
79
80function empty() {
81 return [];
82}
83
84function selectorAll(selector) {
85 return selector == null ? empty : function() {
86 return this.querySelectorAll(selector);
87 };
88}
89
90function arrayAll(select) {
91 return function() {
92 return array(select.apply(this, arguments));
93 };
94}
95
96function selection_selectAll(select) {
97 if (typeof select === "function") select = arrayAll(select);
98 else select = selectorAll(select);
99
100 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
101 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
102 if (node = group[i]) {
103 subgroups.push(select.call(node, node.__data__, i, group));
104 parents.push(node);
105 }
106 }
107 }
108
109 return new Selection(subgroups, parents);
110}
111
112function matcher(selector) {
113 return function() {
114 return this.matches(selector);
115 };
116}
117
118function childMatcher(selector) {
119 return function(node) {
120 return node.matches(selector);
121 };
122}
123
124var find = Array.prototype.find;
125
126function childFind(match) {
127 return function() {
128 return find.call(this.children, match);
129 };
130}
131
132function childFirst() {
133 return this.firstElementChild;
134}
135
136function selection_selectChild(match) {
137 return this.select(match == null ? childFirst
138 : childFind(typeof match === "function" ? match : childMatcher(match)));
139}
140
141var filter = Array.prototype.filter;
142
143function children() {
144 return Array.from(this.children);
145}
146
147function childrenFilter(match) {
148 return function() {
149 return filter.call(this.children, match);
150 };
151}
152
153function selection_selectChildren(match) {
154 return this.selectAll(match == null ? children
155 : childrenFilter(typeof match === "function" ? match : childMatcher(match)));
156}
157
158function selection_filter(match) {
159 if (typeof match !== "function") match = matcher(match);
160
161 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
162 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
163 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
164 subgroup.push(node);
165 }
166 }
167 }
168
169 return new Selection(subgroups, this._parents);
170}
171
172function sparse(update) {
173 return new Array(update.length);
174}
175
176function selection_enter() {
177 return new Selection(this._enter || this._groups.map(sparse), this._parents);
178}
179
180function EnterNode(parent, datum) {
181 this.ownerDocument = parent.ownerDocument;
182 this.namespaceURI = parent.namespaceURI;
183 this._next = null;
184 this._parent = parent;
185 this.__data__ = datum;
186}
187
188EnterNode.prototype = {
189 constructor: EnterNode,
190 appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
191 insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
192 querySelector: function(selector) { return this._parent.querySelector(selector); },
193 querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
194};
195
196function constant(x) {
197 return function() {
198 return x;
199 };
200}
201
202function bindIndex(parent, group, enter, update, exit, data) {
203 var i = 0,
204 node,
205 groupLength = group.length,
206 dataLength = data.length;
207
208 // Put any non-null nodes that fit into update.
209 // Put any null nodes into enter.
210 // Put any remaining data into enter.
211 for (; i < dataLength; ++i) {
212 if (node = group[i]) {
213 node.__data__ = data[i];
214 update[i] = node;
215 } else {
216 enter[i] = new EnterNode(parent, data[i]);
217 }
218 }
219
220 // Put any non-null nodes that don’t fit into exit.
221 for (; i < groupLength; ++i) {
222 if (node = group[i]) {
223 exit[i] = node;
224 }
225 }
226}
227
228function bindKey(parent, group, enter, update, exit, data, key) {
229 var i,
230 node,
231 nodeByKeyValue = new Map,
232 groupLength = group.length,
233 dataLength = data.length,
234 keyValues = new Array(groupLength),
235 keyValue;
236
237 // Compute the key for each node.
238 // If multiple nodes have the same key, the duplicates are added to exit.
239 for (i = 0; i < groupLength; ++i) {
240 if (node = group[i]) {
241 keyValues[i] = keyValue = key.call(node, node.__data__, i, group) + "";
242 if (nodeByKeyValue.has(keyValue)) {
243 exit[i] = node;
244 } else {
245 nodeByKeyValue.set(keyValue, node);
246 }
247 }
248 }
249
250 // Compute the key for each datum.
251 // If there a node associated with this key, join and add it to update.
252 // If there is not (or the key is a duplicate), add it to enter.
253 for (i = 0; i < dataLength; ++i) {
254 keyValue = key.call(parent, data[i], i, data) + "";
255 if (node = nodeByKeyValue.get(keyValue)) {
256 update[i] = node;
257 node.__data__ = data[i];
258 nodeByKeyValue.delete(keyValue);
259 } else {
260 enter[i] = new EnterNode(parent, data[i]);
261 }
262 }
263
264 // Add any remaining nodes that were not bound to data to exit.
265 for (i = 0; i < groupLength; ++i) {
266 if ((node = group[i]) && (nodeByKeyValue.get(keyValues[i]) === node)) {
267 exit[i] = node;
268 }
269 }
270}
271
272function datum(node) {
273 return node.__data__;
274}
275
276function selection_data(value, key) {
277 if (!arguments.length) return Array.from(this, datum);
278
279 var bind = key ? bindKey : bindIndex,
280 parents = this._parents,
281 groups = this._groups;
282
283 if (typeof value !== "function") value = constant(value);
284
285 for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
286 var parent = parents[j],
287 group = groups[j],
288 groupLength = group.length,
289 data = arraylike(value.call(parent, parent && parent.__data__, j, parents)),
290 dataLength = data.length,
291 enterGroup = enter[j] = new Array(dataLength),
292 updateGroup = update[j] = new Array(dataLength),
293 exitGroup = exit[j] = new Array(groupLength);
294
295 bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
296
297 // Now connect the enter nodes to their following update node, such that
298 // appendChild can insert the materialized enter node before this node,
299 // rather than at the end of the parent node.
300 for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
301 if (previous = enterGroup[i0]) {
302 if (i0 >= i1) i1 = i0 + 1;
303 while (!(next = updateGroup[i1]) && ++i1 < dataLength);
304 previous._next = next || null;
305 }
306 }
307 }
308
309 update = new Selection(update, parents);
310 update._enter = enter;
311 update._exit = exit;
312 return update;
313}
314
315// Given some data, this returns an array-like view of it: an object that
316// exposes a length property and allows numeric indexing. Note that unlike
317// selectAll, this isn’t worried about “live” collections because the resulting
318// array will only be used briefly while data is being bound. (It is possible to
319// cause the data to change while iterating by using a key function, but please
320// don’t; we’d rather avoid a gratuitous copy.)
321function arraylike(data) {
322 return typeof data === "object" && "length" in data
323 ? data // Array, TypedArray, NodeList, array-like
324 : Array.from(data); // Map, Set, iterable, string, or anything else
325}
326
327function selection_exit() {
328 return new Selection(this._exit || this._groups.map(sparse), this._parents);
329}
330
331function selection_join(onenter, onupdate, onexit) {
332 var enter = this.enter(), update = this, exit = this.exit();
333 if (typeof onenter === "function") {
334 enter = onenter(enter);
335 if (enter) enter = enter.selection();
336 } else {
337 enter = enter.append(onenter + "");
338 }
339 if (onupdate != null) {
340 update = onupdate(update);
341 if (update) update = update.selection();
342 }
343 if (onexit == null) exit.remove(); else onexit(exit);
344 return enter && update ? enter.merge(update).order() : update;
345}
346
347function selection_merge(context) {
348 var selection = context.selection ? context.selection() : context;
349
350 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) {
351 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
352 if (node = group0[i] || group1[i]) {
353 merge[i] = node;
354 }
355 }
356 }
357
358 for (; j < m0; ++j) {
359 merges[j] = groups0[j];
360 }
361
362 return new Selection(merges, this._parents);
363}
364
365function selection_order() {
366
367 for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
368 for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
369 if (node = group[i]) {
370 if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
371 next = node;
372 }
373 }
374 }
375
376 return this;
377}
378
379function selection_sort(compare) {
380 if (!compare) compare = ascending;
381
382 function compareNode(a, b) {
383 return a && b ? compare(a.__data__, b.__data__) : !a - !b;
384 }
385
386 for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
387 for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
388 if (node = group[i]) {
389 sortgroup[i] = node;
390 }
391 }
392 sortgroup.sort(compareNode);
393 }
394
395 return new Selection(sortgroups, this._parents).order();
396}
397
398function ascending(a, b) {
399 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
400}
401
402function selection_call() {
403 var callback = arguments[0];
404 arguments[0] = this;
405 callback.apply(null, arguments);
406 return this;
407}
408
409function selection_nodes() {
410 return Array.from(this);
411}
412
413function selection_node() {
414
415 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
416 for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
417 var node = group[i];
418 if (node) return node;
419 }
420 }
421
422 return null;
423}
424
425function selection_size() {
426 let size = 0;
427 for (const node of this) ++size; // eslint-disable-line no-unused-vars
428 return size;
429}
430
431function selection_empty() {
432 return !this.node();
433}
434
435function selection_each(callback) {
436
437 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
438 for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
439 if (node = group[i]) callback.call(node, node.__data__, i, group);
440 }
441 }
442
443 return this;
444}
445
446function attrRemove(name) {
447 return function() {
448 this.removeAttribute(name);
449 };
450}
451
452function attrRemoveNS(fullname) {
453 return function() {
454 this.removeAttributeNS(fullname.space, fullname.local);
455 };
456}
457
458function attrConstant(name, value) {
459 return function() {
460 this.setAttribute(name, value);
461 };
462}
463
464function attrConstantNS(fullname, value) {
465 return function() {
466 this.setAttributeNS(fullname.space, fullname.local, value);
467 };
468}
469
470function attrFunction(name, value) {
471 return function() {
472 var v = value.apply(this, arguments);
473 if (v == null) this.removeAttribute(name);
474 else this.setAttribute(name, v);
475 };
476}
477
478function attrFunctionNS(fullname, value) {
479 return function() {
480 var v = value.apply(this, arguments);
481 if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
482 else this.setAttributeNS(fullname.space, fullname.local, v);
483 };
484}
485
486function selection_attr(name, value) {
487 var fullname = namespace(name);
488
489 if (arguments.length < 2) {
490 var node = this.node();
491 return fullname.local
492 ? node.getAttributeNS(fullname.space, fullname.local)
493 : node.getAttribute(fullname);
494 }
495
496 return this.each((value == null
497 ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
498 ? (fullname.local ? attrFunctionNS : attrFunction)
499 : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
500}
501
502function defaultView(node) {
503 return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
504 || (node.document && node) // node is a Window
505 || node.defaultView; // node is a Document
506}
507
508function styleRemove(name) {
509 return function() {
510 this.style.removeProperty(name);
511 };
512}
513
514function styleConstant(name, value, priority) {
515 return function() {
516 this.style.setProperty(name, value, priority);
517 };
518}
519
520function styleFunction(name, value, priority) {
521 return function() {
522 var v = value.apply(this, arguments);
523 if (v == null) this.style.removeProperty(name);
524 else this.style.setProperty(name, v, priority);
525 };
526}
527
528function selection_style(name, value, priority) {
529 return arguments.length > 1
530 ? this.each((value == null
531 ? styleRemove : typeof value === "function"
532 ? styleFunction
533 : styleConstant)(name, value, priority == null ? "" : priority))
534 : styleValue(this.node(), name);
535}
536
537function styleValue(node, name) {
538 return node.style.getPropertyValue(name)
539 || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
540}
541
542function propertyRemove(name) {
543 return function() {
544 delete this[name];
545 };
546}
547
548function propertyConstant(name, value) {
549 return function() {
550 this[name] = value;
551 };
552}
553
554function propertyFunction(name, value) {
555 return function() {
556 var v = value.apply(this, arguments);
557 if (v == null) delete this[name];
558 else this[name] = v;
559 };
560}
561
562function selection_property(name, value) {
563 return arguments.length > 1
564 ? this.each((value == null
565 ? propertyRemove : typeof value === "function"
566 ? propertyFunction
567 : propertyConstant)(name, value))
568 : this.node()[name];
569}
570
571function classArray(string) {
572 return string.trim().split(/^|\s+/);
573}
574
575function classList(node) {
576 return node.classList || new ClassList(node);
577}
578
579function ClassList(node) {
580 this._node = node;
581 this._names = classArray(node.getAttribute("class") || "");
582}
583
584ClassList.prototype = {
585 add: function(name) {
586 var i = this._names.indexOf(name);
587 if (i < 0) {
588 this._names.push(name);
589 this._node.setAttribute("class", this._names.join(" "));
590 }
591 },
592 remove: function(name) {
593 var i = this._names.indexOf(name);
594 if (i >= 0) {
595 this._names.splice(i, 1);
596 this._node.setAttribute("class", this._names.join(" "));
597 }
598 },
599 contains: function(name) {
600 return this._names.indexOf(name) >= 0;
601 }
602};
603
604function classedAdd(node, names) {
605 var list = classList(node), i = -1, n = names.length;
606 while (++i < n) list.add(names[i]);
607}
608
609function classedRemove(node, names) {
610 var list = classList(node), i = -1, n = names.length;
611 while (++i < n) list.remove(names[i]);
612}
613
614function classedTrue(names) {
615 return function() {
616 classedAdd(this, names);
617 };
618}
619
620function classedFalse(names) {
621 return function() {
622 classedRemove(this, names);
623 };
624}
625
626function classedFunction(names, value) {
627 return function() {
628 (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
629 };
630}
631
632function selection_classed(name, value) {
633 var names = classArray(name + "");
634
635 if (arguments.length < 2) {
636 var list = classList(this.node()), i = -1, n = names.length;
637 while (++i < n) if (!list.contains(names[i])) return false;
638 return true;
639 }
640
641 return this.each((typeof value === "function"
642 ? classedFunction : value
643 ? classedTrue
644 : classedFalse)(names, value));
645}
646
647function textRemove() {
648 this.textContent = "";
649}
650
651function textConstant(value) {
652 return function() {
653 this.textContent = value;
654 };
655}
656
657function textFunction(value) {
658 return function() {
659 var v = value.apply(this, arguments);
660 this.textContent = v == null ? "" : v;
661 };
662}
663
664function selection_text(value) {
665 return arguments.length
666 ? this.each(value == null
667 ? textRemove : (typeof value === "function"
668 ? textFunction
669 : textConstant)(value))
670 : this.node().textContent;
671}
672
673function htmlRemove() {
674 this.innerHTML = "";
675}
676
677function htmlConstant(value) {
678 return function() {
679 this.innerHTML = value;
680 };
681}
682
683function htmlFunction(value) {
684 return function() {
685 var v = value.apply(this, arguments);
686 this.innerHTML = v == null ? "" : v;
687 };
688}
689
690function selection_html(value) {
691 return arguments.length
692 ? this.each(value == null
693 ? htmlRemove : (typeof value === "function"
694 ? htmlFunction
695 : htmlConstant)(value))
696 : this.node().innerHTML;
697}
698
699function raise() {
700 if (this.nextSibling) this.parentNode.appendChild(this);
701}
702
703function selection_raise() {
704 return this.each(raise);
705}
706
707function lower() {
708 if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
709}
710
711function selection_lower() {
712 return this.each(lower);
713}
714
715function selection_append(name) {
716 var create = typeof name === "function" ? name : creator(name);
717 return this.select(function() {
718 return this.appendChild(create.apply(this, arguments));
719 });
720}
721
722function constantNull() {
723 return null;
724}
725
726function selection_insert(name, before) {
727 var create = typeof name === "function" ? name : creator(name),
728 select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
729 return this.select(function() {
730 return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
731 });
732}
733
734function remove() {
735 var parent = this.parentNode;
736 if (parent) parent.removeChild(this);
737}
738
739function selection_remove() {
740 return this.each(remove);
741}
742
743function selection_cloneShallow() {
744 var clone = this.cloneNode(false), parent = this.parentNode;
745 return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
746}
747
748function selection_cloneDeep() {
749 var clone = this.cloneNode(true), parent = this.parentNode;
750 return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
751}
752
753function selection_clone(deep) {
754 return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
755}
756
757function selection_datum(value) {
758 return arguments.length
759 ? this.property("__data__", value)
760 : this.node().__data__;
761}
762
763function contextListener(listener) {
764 return function(event) {
765 listener.call(this, event, this.__data__);
766 };
767}
768
769function parseTypenames(typenames) {
770 return typenames.trim().split(/^|\s+/).map(function(t) {
771 var name = "", i = t.indexOf(".");
772 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
773 return {type: t, name: name};
774 });
775}
776
777function onRemove(typename) {
778 return function() {
779 var on = this.__on;
780 if (!on) return;
781 for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
782 if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
783 this.removeEventListener(o.type, o.listener, o.options);
784 } else {
785 on[++i] = o;
786 }
787 }
788 if (++i) on.length = i;
789 else delete this.__on;
790 };
791}
792
793function onAdd(typename, value, options) {
794 return function() {
795 var on = this.__on, o, listener = contextListener(value);
796 if (on) for (var j = 0, m = on.length; j < m; ++j) {
797 if ((o = on[j]).type === typename.type && o.name === typename.name) {
798 this.removeEventListener(o.type, o.listener, o.options);
799 this.addEventListener(o.type, o.listener = listener, o.options = options);
800 o.value = value;
801 return;
802 }
803 }
804 this.addEventListener(typename.type, listener, options);
805 o = {type: typename.type, name: typename.name, value: value, listener: listener, options: options};
806 if (!on) this.__on = [o];
807 else on.push(o);
808 };
809}
810
811function selection_on(typename, value, options) {
812 var typenames = parseTypenames(typename + ""), i, n = typenames.length, t;
813
814 if (arguments.length < 2) {
815 var on = this.node().__on;
816 if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
817 for (i = 0, o = on[j]; i < n; ++i) {
818 if ((t = typenames[i]).type === o.type && t.name === o.name) {
819 return o.value;
820 }
821 }
822 }
823 return;
824 }
825
826 on = value ? onAdd : onRemove;
827 for (i = 0; i < n; ++i) this.each(on(typenames[i], value, options));
828 return this;
829}
830
831function dispatchEvent(node, type, params) {
832 var window = defaultView(node),
833 event = window.CustomEvent;
834
835 if (typeof event === "function") {
836 event = new event(type, params);
837 } else {
838 event = window.document.createEvent("Event");
839 if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
840 else event.initEvent(type, false, false);
841 }
842
843 node.dispatchEvent(event);
844}
845
846function dispatchConstant(type, params) {
847 return function() {
848 return dispatchEvent(this, type, params);
849 };
850}
851
852function dispatchFunction(type, params) {
853 return function() {
854 return dispatchEvent(this, type, params.apply(this, arguments));
855 };
856}
857
858function selection_dispatch(type, params) {
859 return this.each((typeof params === "function"
860 ? dispatchFunction
861 : dispatchConstant)(type, params));
862}
863
864function* selection_iterator() {
865 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
866 for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
867 if (node = group[i]) yield node;
868 }
869 }
870}
871
872var root = [null];
873
874function Selection(groups, parents) {
875 this._groups = groups;
876 this._parents = parents;
877}
878
879function selection() {
880 return new Selection([[document.documentElement]], root);
881}
882
883function selection_selection() {
884 return this;
885}
886
887Selection.prototype = selection.prototype = {
888 constructor: Selection,
889 select: selection_select,
890 selectAll: selection_selectAll,
891 selectChild: selection_selectChild,
892 selectChildren: selection_selectChildren,
893 filter: selection_filter,
894 data: selection_data,
895 enter: selection_enter,
896 exit: selection_exit,
897 join: selection_join,
898 merge: selection_merge,
899 selection: selection_selection,
900 order: selection_order,
901 sort: selection_sort,
902 call: selection_call,
903 nodes: selection_nodes,
904 node: selection_node,
905 size: selection_size,
906 empty: selection_empty,
907 each: selection_each,
908 attr: selection_attr,
909 style: selection_style,
910 property: selection_property,
911 classed: selection_classed,
912 text: selection_text,
913 html: selection_html,
914 raise: selection_raise,
915 lower: selection_lower,
916 append: selection_append,
917 insert: selection_insert,
918 remove: selection_remove,
919 clone: selection_clone,
920 datum: selection_datum,
921 on: selection_on,
922 dispatch: selection_dispatch,
923 [Symbol.iterator]: selection_iterator
924};
925
926function select(selector) {
927 return typeof selector === "string"
928 ? new Selection([[document.querySelector(selector)]], [document.documentElement])
929 : new Selection([[selector]], root);
930}
931
932function create(name) {
933 return select(creator(name).call(document.documentElement));
934}
935
936var nextId = 0;
937
938function local() {
939 return new Local;
940}
941
942function Local() {
943 this._ = "@" + (++nextId).toString(36);
944}
945
946Local.prototype = local.prototype = {
947 constructor: Local,
948 get: function(node) {
949 var id = this._;
950 while (!(id in node)) if (!(node = node.parentNode)) return;
951 return node[id];
952 },
953 set: function(node, value) {
954 return node[this._] = value;
955 },
956 remove: function(node) {
957 return this._ in node && delete node[this._];
958 },
959 toString: function() {
960 return this._;
961 }
962};
963
964function sourceEvent(event) {
965 let sourceEvent;
966 while (sourceEvent = event.sourceEvent) event = sourceEvent;
967 return event;
968}
969
970function pointer(event, node) {
971 event = sourceEvent(event);
972 if (node === undefined) node = event.currentTarget;
973 if (node) {
974 var svg = node.ownerSVGElement || node;
975 if (svg.createSVGPoint) {
976 var point = svg.createSVGPoint();
977 point.x = event.clientX, point.y = event.clientY;
978 point = point.matrixTransform(node.getScreenCTM().inverse());
979 return [point.x, point.y];
980 }
981 if (node.getBoundingClientRect) {
982 var rect = node.getBoundingClientRect();
983 return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
984 }
985 }
986 return [event.pageX, event.pageY];
987}
988
989function pointers(events, node) {
990 if (events.target) { // i.e., instanceof Event, not TouchList or iterable
991 events = sourceEvent(events);
992 if (node === undefined) node = events.currentTarget;
993 events = events.touches || [events];
994 }
995 return Array.from(events, event => pointer(event, node));
996}
997
998function selectAll(selector) {
999 return typeof selector === "string"
1000 ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
1001 : new Selection([array(selector)], root);
1002}
1003
1004exports.create = create;
1005exports.creator = creator;
1006exports.local = local;
1007exports.matcher = matcher;
1008exports.namespace = namespace;
1009exports.namespaces = namespaces;
1010exports.pointer = pointer;
1011exports.pointers = pointers;
1012exports.select = select;
1013exports.selectAll = selectAll;
1014exports.selection = selection;
1015exports.selector = selector;
1016exports.selectorAll = selectorAll;
1017exports.style = styleValue;
1018exports.window = defaultView;
1019
1020Object.defineProperty(exports, '__esModule', { value: true });
1021
1022})));
Note: See TracBrowser for help on using the repository browser.