Node-Red configuration
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

d3-selection.js 27KB

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