UNPKG

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