UNPKG

775 kBJavaScriptView Raw
1(function webpackUniversalModuleDefinition(root, factory) {
2 if(typeof exports === 'object' && typeof module === 'object')
3 module.exports = factory();
4 else if(typeof define === 'function' && define.amd)
5 define([], factory);
6 else if(typeof exports === 'object')
7 exports["d3-state-visualizer"] = factory();
8 else
9 root["d3-state-visualizer"] = factory();
10})(this, function() {
11return /******/ (function(modules) { // webpackBootstrap
12/******/ // The module cache
13/******/ var installedModules = {};
14
15/******/ // The require function
16/******/ function __webpack_require__(moduleId) {
17
18/******/ // Check if module is in cache
19/******/ if(installedModules[moduleId])
20/******/ return installedModules[moduleId].exports;
21
22/******/ // Create a new module (and put it into the cache)
23/******/ var module = installedModules[moduleId] = {
24/******/ exports: {},
25/******/ id: moduleId,
26/******/ loaded: false
27/******/ };
28
29/******/ // Execute the module function
30/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31
32/******/ // Flag the module as loaded
33/******/ module.loaded = true;
34
35/******/ // Return the exports of the module
36/******/ return module.exports;
37/******/ }
38
39
40/******/ // expose the modules object (__webpack_modules__)
41/******/ __webpack_require__.m = modules;
42
43/******/ // expose the module cache
44/******/ __webpack_require__.c = installedModules;
45
46/******/ // __webpack_public_path__
47/******/ __webpack_require__.p = "";
48
49/******/ // Load entry module and return exports
50/******/ return __webpack_require__(0);
51/******/ })
52/************************************************************************/
53/******/ ([
54/* 0 */
55/***/ function(module, exports, __webpack_require__) {
56
57 'use strict';
58
59 exports.__esModule = true;
60 exports.tree = undefined;
61
62 var _charts = __webpack_require__(35);
63
64 Object.defineProperty(exports, 'tree', {
65 enumerable: true,
66 get: function get() {
67 return _charts.tree;
68 }
69 });
70
71 var charts = _interopRequireWildcard(_charts);
72
73 function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
74
75 exports.default = charts;
76
77/***/ },
78/* 1 */
79/***/ function(module, exports) {
80
81 /**
82 * Checks if `value` is classified as an `Array` object.
83 *
84 * @static
85 * @memberOf _
86 * @type Function
87 * @category Lang
88 * @param {*} value The value to check.
89 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
90 * @example
91 *
92 * _.isArray([1, 2, 3]);
93 * // => true
94 *
95 * _.isArray(document.body.children);
96 * // => false
97 *
98 * _.isArray('abc');
99 * // => false
100 *
101 * _.isArray(_.noop);
102 * // => false
103 */
104 var isArray = Array.isArray;
105
106 module.exports = isArray;
107
108
109/***/ },
110/* 2 */
111/***/ function(module, exports) {
112
113 /**
114 * Checks if `value` is object-like. A value is object-like if it's not `null`
115 * and has a `typeof` result of "object".
116 *
117 * @static
118 * @memberOf _
119 * @category Lang
120 * @param {*} value The value to check.
121 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
122 * @example
123 *
124 * _.isObjectLike({});
125 * // => true
126 *
127 * _.isObjectLike([1, 2, 3]);
128 * // => true
129 *
130 * _.isObjectLike(_.noop);
131 * // => false
132 *
133 * _.isObjectLike(null);
134 * // => false
135 */
136 function isObjectLike(value) {
137 return !!value && typeof value == 'object';
138 }
139
140 module.exports = isObjectLike;
141
142
143/***/ },
144/* 3 */
145/***/ function(module, exports, __webpack_require__) {
146
147 var getNative = __webpack_require__(10),
148 root = __webpack_require__(8);
149
150 /* Built-in method references that are verified to be native. */
151 var Map = getNative(root, 'Map');
152
153 module.exports = Map;
154
155
156/***/ },
157/* 4 */
158/***/ function(module, exports, __webpack_require__) {
159
160 // Ramda v0.17.1
161 // https://github.com/ramda/ramda
162 // (c) 2013-2015 Scott Sauyet, Michael Hurley, and David Chambers
163 // Ramda may be freely distributed under the MIT license.
164
165 ;(function() {
166
167 'use strict';
168
169 /**
170 * A special placeholder value used to specify "gaps" within curried functions,
171 * allowing partial application of any combination of arguments,
172 * regardless of their positions.
173 *
174 * If `g` is a curried ternary function and `_` is `R.__`, the following are equivalent:
175 *
176 * - `g(1, 2, 3)`
177 * - `g(_, 2, 3)(1)`
178 * - `g(_, _, 3)(1)(2)`
179 * - `g(_, _, 3)(1, 2)`
180 * - `g(_, 2, _)(1, 3)`
181 * - `g(_, 2)(1)(3)`
182 * - `g(_, 2)(1, 3)`
183 * - `g(_, 2)(_, 3)(1)`
184 *
185 * @constant
186 * @memberOf R
187 * @category Function
188 * @example
189 *
190 * var greet = R.replace('{name}', R.__, 'Hello, {name}!');
191 * greet('Alice'); //=> 'Hello, Alice!'
192 */
193 var __ = { '@@functional/placeholder': true };
194
195 // jshint unused:vars
196 var _arity = function _arity(n, fn) {
197 // jshint unused:vars
198 switch (n) {
199 case 0:
200 return function () {
201 return fn.apply(this, arguments);
202 };
203 case 1:
204 return function (a0) {
205 return fn.apply(this, arguments);
206 };
207 case 2:
208 return function (a0, a1) {
209 return fn.apply(this, arguments);
210 };
211 case 3:
212 return function (a0, a1, a2) {
213 return fn.apply(this, arguments);
214 };
215 case 4:
216 return function (a0, a1, a2, a3) {
217 return fn.apply(this, arguments);
218 };
219 case 5:
220 return function (a0, a1, a2, a3, a4) {
221 return fn.apply(this, arguments);
222 };
223 case 6:
224 return function (a0, a1, a2, a3, a4, a5) {
225 return fn.apply(this, arguments);
226 };
227 case 7:
228 return function (a0, a1, a2, a3, a4, a5, a6) {
229 return fn.apply(this, arguments);
230 };
231 case 8:
232 return function (a0, a1, a2, a3, a4, a5, a6, a7) {
233 return fn.apply(this, arguments);
234 };
235 case 9:
236 return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) {
237 return fn.apply(this, arguments);
238 };
239 case 10:
240 return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
241 return fn.apply(this, arguments);
242 };
243 default:
244 throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
245 }
246 };
247
248 var _cloneRegExp = function _cloneRegExp(pattern) {
249 return new RegExp(pattern.source, (pattern.global ? 'g' : '') + (pattern.ignoreCase ? 'i' : '') + (pattern.multiline ? 'm' : '') + (pattern.sticky ? 'y' : '') + (pattern.unicode ? 'u' : ''));
250 };
251
252 var _complement = function _complement(f) {
253 return function () {
254 return !f.apply(this, arguments);
255 };
256 };
257
258 /**
259 * Private `concat` function to merge two array-like objects.
260 *
261 * @private
262 * @param {Array|Arguments} [set1=[]] An array-like object.
263 * @param {Array|Arguments} [set2=[]] An array-like object.
264 * @return {Array} A new, merged array.
265 * @example
266 *
267 * _concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3]
268 */
269 var _concat = function _concat(set1, set2) {
270 set1 = set1 || [];
271 set2 = set2 || [];
272 var idx;
273 var len1 = set1.length;
274 var len2 = set2.length;
275 var result = [];
276 idx = 0;
277 while (idx < len1) {
278 result[result.length] = set1[idx];
279 idx += 1;
280 }
281 idx = 0;
282 while (idx < len2) {
283 result[result.length] = set2[idx];
284 idx += 1;
285 }
286 return result;
287 };
288
289 var _containsWith = function _containsWith(pred, x, list) {
290 var idx = 0, len = list.length;
291 while (idx < len) {
292 if (pred(x, list[idx])) {
293 return true;
294 }
295 idx += 1;
296 }
297 return false;
298 };
299
300 /**
301 * Optimized internal two-arity curry function.
302 *
303 * @private
304 * @category Function
305 * @param {Function} fn The function to curry.
306 * @return {Function} The curried function.
307 */
308 var _curry1 = function _curry1(fn) {
309 return function f1(a) {
310 if (arguments.length === 0) {
311 return f1;
312 } else if (a != null && a['@@functional/placeholder'] === true) {
313 return f1;
314 } else {
315 return fn.apply(this, arguments);
316 }
317 };
318 };
319
320 /**
321 * Optimized internal two-arity curry function.
322 *
323 * @private
324 * @category Function
325 * @param {Function} fn The function to curry.
326 * @return {Function} The curried function.
327 */
328 var _curry2 = function _curry2(fn) {
329 return function f2(a, b) {
330 var n = arguments.length;
331 if (n === 0) {
332 return f2;
333 } else if (n === 1 && a != null && a['@@functional/placeholder'] === true) {
334 return f2;
335 } else if (n === 1) {
336 return _curry1(function (b) {
337 return fn(a, b);
338 });
339 } else if (n === 2 && a != null && a['@@functional/placeholder'] === true && b != null && b['@@functional/placeholder'] === true) {
340 return f2;
341 } else if (n === 2 && a != null && a['@@functional/placeholder'] === true) {
342 return _curry1(function (a) {
343 return fn(a, b);
344 });
345 } else if (n === 2 && b != null && b['@@functional/placeholder'] === true) {
346 return _curry1(function (b) {
347 return fn(a, b);
348 });
349 } else {
350 return fn(a, b);
351 }
352 };
353 };
354
355 /**
356 * Optimized internal three-arity curry function.
357 *
358 * @private
359 * @category Function
360 * @param {Function} fn The function to curry.
361 * @return {Function} The curried function.
362 */
363 var _curry3 = function _curry3(fn) {
364 return function f3(a, b, c) {
365 var n = arguments.length;
366 if (n === 0) {
367 return f3;
368 } else if (n === 1 && a != null && a['@@functional/placeholder'] === true) {
369 return f3;
370 } else if (n === 1) {
371 return _curry2(function (b, c) {
372 return fn(a, b, c);
373 });
374 } else if (n === 2 && a != null && a['@@functional/placeholder'] === true && b != null && b['@@functional/placeholder'] === true) {
375 return f3;
376 } else if (n === 2 && a != null && a['@@functional/placeholder'] === true) {
377 return _curry2(function (a, c) {
378 return fn(a, b, c);
379 });
380 } else if (n === 2 && b != null && b['@@functional/placeholder'] === true) {
381 return _curry2(function (b, c) {
382 return fn(a, b, c);
383 });
384 } else if (n === 2) {
385 return _curry1(function (c) {
386 return fn(a, b, c);
387 });
388 } else if (n === 3 && a != null && a['@@functional/placeholder'] === true && b != null && b['@@functional/placeholder'] === true && c != null && c['@@functional/placeholder'] === true) {
389 return f3;
390 } else if (n === 3 && a != null && a['@@functional/placeholder'] === true && b != null && b['@@functional/placeholder'] === true) {
391 return _curry2(function (a, b) {
392 return fn(a, b, c);
393 });
394 } else if (n === 3 && a != null && a['@@functional/placeholder'] === true && c != null && c['@@functional/placeholder'] === true) {
395 return _curry2(function (a, c) {
396 return fn(a, b, c);
397 });
398 } else if (n === 3 && b != null && b['@@functional/placeholder'] === true && c != null && c['@@functional/placeholder'] === true) {
399 return _curry2(function (b, c) {
400 return fn(a, b, c);
401 });
402 } else if (n === 3 && a != null && a['@@functional/placeholder'] === true) {
403 return _curry1(function (a) {
404 return fn(a, b, c);
405 });
406 } else if (n === 3 && b != null && b['@@functional/placeholder'] === true) {
407 return _curry1(function (b) {
408 return fn(a, b, c);
409 });
410 } else if (n === 3 && c != null && c['@@functional/placeholder'] === true) {
411 return _curry1(function (c) {
412 return fn(a, b, c);
413 });
414 } else {
415 return fn(a, b, c);
416 }
417 };
418 };
419
420 /**
421 * Internal curryN function.
422 *
423 * @private
424 * @category Function
425 * @param {Number} length The arity of the curried function.
426 * @return {array} An array of arguments received thus far.
427 * @param {Function} fn The function to curry.
428 */
429 var _curryN = function _curryN(length, received, fn) {
430 return function () {
431 var combined = [];
432 var argsIdx = 0;
433 var left = length;
434 var combinedIdx = 0;
435 while (combinedIdx < received.length || argsIdx < arguments.length) {
436 var result;
437 if (combinedIdx < received.length && (received[combinedIdx] == null || received[combinedIdx]['@@functional/placeholder'] !== true || argsIdx >= arguments.length)) {
438 result = received[combinedIdx];
439 } else {
440 result = arguments[argsIdx];
441 argsIdx += 1;
442 }
443 combined[combinedIdx] = result;
444 if (result == null || result['@@functional/placeholder'] !== true) {
445 left -= 1;
446 }
447 combinedIdx += 1;
448 }
449 return left <= 0 ? fn.apply(this, combined) : _arity(left, _curryN(length, combined, fn));
450 };
451 };
452
453 var _filter = function _filter(fn, list) {
454 var idx = 0, len = list.length, result = [];
455 while (idx < len) {
456 if (fn(list[idx])) {
457 result[result.length] = list[idx];
458 }
459 idx += 1;
460 }
461 return result;
462 };
463
464 var _forceReduced = function _forceReduced(x) {
465 return {
466 '@@transducer/value': x,
467 '@@transducer/reduced': true
468 };
469 };
470
471 /**
472 * @private
473 * @param {Function} fn The strategy for extracting function names from an object
474 * @return {Function} A function that takes an object and returns an array of function names.
475 */
476 var _functionsWith = function _functionsWith(fn) {
477 return function (obj) {
478 return _filter(function (key) {
479 return typeof obj[key] === 'function';
480 }, fn(obj));
481 };
482 };
483
484 var _has = function _has(prop, obj) {
485 return Object.prototype.hasOwnProperty.call(obj, prop);
486 };
487
488 var _identity = function _identity(x) {
489 return x;
490 };
491
492 /**
493 * Tests whether or not an object is an array.
494 *
495 * @private
496 * @param {*} val The object to test.
497 * @return {Boolean} `true` if `val` is an array, `false` otherwise.
498 * @example
499 *
500 * _isArray([]); //=> true
501 * _isArray(null); //=> false
502 * _isArray({}); //=> false
503 */
504 var _isArray = Array.isArray || function _isArray(val) {
505 return val != null && val.length >= 0 && Object.prototype.toString.call(val) === '[object Array]';
506 };
507
508 /**
509 * Determine if the passed argument is an integer.
510 *
511 * @private
512 * @param {*} n
513 * @category Type
514 * @return {Boolean}
515 */
516 var _isInteger = Number.isInteger || function _isInteger(n) {
517 return n << 0 === n;
518 };
519
520 var _isNumber = function _isNumber(x) {
521 return Object.prototype.toString.call(x) === '[object Number]';
522 };
523
524 var _isString = function _isString(x) {
525 return Object.prototype.toString.call(x) === '[object String]';
526 };
527
528 var _isTransformer = function _isTransformer(obj) {
529 return typeof obj['@@transducer/step'] === 'function';
530 };
531
532 var _map = function _map(fn, list) {
533 var idx = 0, len = list.length, result = Array(len);
534 while (idx < len) {
535 result[idx] = fn(list[idx]);
536 idx += 1;
537 }
538 return result;
539 };
540
541 var _pipe = function _pipe(f, g) {
542 return function () {
543 return g.call(this, f.apply(this, arguments));
544 };
545 };
546
547 var _pipeP = function _pipeP(f, g) {
548 return function () {
549 var ctx = this;
550 return f.apply(ctx, arguments).then(function (x) {
551 return g.call(ctx, x);
552 });
553 };
554 };
555
556 var _quote = function _quote(s) {
557 return '"' + s.replace(/"/g, '\\"') + '"';
558 };
559
560 var _reduced = function _reduced(x) {
561 return x && x['@@transducer/reduced'] ? x : {
562 '@@transducer/value': x,
563 '@@transducer/reduced': true
564 };
565 };
566
567 /**
568 * An optimized, private array `slice` implementation.
569 *
570 * @private
571 * @param {Arguments|Array} args The array or arguments object to consider.
572 * @param {Number} [from=0] The array index to slice from, inclusive.
573 * @param {Number} [to=args.length] The array index to slice to, exclusive.
574 * @return {Array} A new, sliced array.
575 * @example
576 *
577 * _slice([1, 2, 3, 4, 5], 1, 3); //=> [2, 3]
578 *
579 * var firstThreeArgs = function(a, b, c, d) {
580 * return _slice(arguments, 0, 3);
581 * };
582 * firstThreeArgs(1, 2, 3, 4); //=> [1, 2, 3]
583 */
584 var _slice = function _slice(args, from, to) {
585 switch (arguments.length) {
586 case 1:
587 return _slice(args, 0, args.length);
588 case 2:
589 return _slice(args, from, args.length);
590 default:
591 var list = [];
592 var idx = 0;
593 var len = Math.max(0, Math.min(args.length, to) - from);
594 while (idx < len) {
595 list[idx] = args[from + idx];
596 idx += 1;
597 }
598 return list;
599 }
600 };
601
602 /**
603 * Polyfill from <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString>.
604 */
605 var _toISOString = function () {
606 var pad = function pad(n) {
607 return (n < 10 ? '0' : '') + n;
608 };
609 return typeof Date.prototype.toISOString === 'function' ? function _toISOString(d) {
610 return d.toISOString();
611 } : function _toISOString(d) {
612 return d.getUTCFullYear() + '-' + pad(d.getUTCMonth() + 1) + '-' + pad(d.getUTCDate()) + 'T' + pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ':' + pad(d.getUTCSeconds()) + '.' + (d.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) + 'Z';
613 };
614 }();
615
616 var _xdropRepeatsWith = function () {
617 function XDropRepeatsWith(pred, xf) {
618 this.xf = xf;
619 this.pred = pred;
620 this.lastValue = undefined;
621 this.seenFirstValue = false;
622 }
623 XDropRepeatsWith.prototype['@@transducer/init'] = function () {
624 return this.xf['@@transducer/init']();
625 };
626 XDropRepeatsWith.prototype['@@transducer/result'] = function (result) {
627 return this.xf['@@transducer/result'](result);
628 };
629 XDropRepeatsWith.prototype['@@transducer/step'] = function (result, input) {
630 var sameAsLast = false;
631 if (!this.seenFirstValue) {
632 this.seenFirstValue = true;
633 } else if (this.pred(this.lastValue, input)) {
634 sameAsLast = true;
635 }
636 this.lastValue = input;
637 return sameAsLast ? result : this.xf['@@transducer/step'](result, input);
638 };
639 return _curry2(function _xdropRepeatsWith(pred, xf) {
640 return new XDropRepeatsWith(pred, xf);
641 });
642 }();
643
644 var _xfBase = {
645 init: function () {
646 return this.xf['@@transducer/init']();
647 },
648 result: function (result) {
649 return this.xf['@@transducer/result'](result);
650 }
651 };
652
653 var _xfilter = function () {
654 function XFilter(f, xf) {
655 this.xf = xf;
656 this.f = f;
657 }
658 XFilter.prototype['@@transducer/init'] = _xfBase.init;
659 XFilter.prototype['@@transducer/result'] = _xfBase.result;
660 XFilter.prototype['@@transducer/step'] = function (result, input) {
661 return this.f(input) ? this.xf['@@transducer/step'](result, input) : result;
662 };
663 return _curry2(function _xfilter(f, xf) {
664 return new XFilter(f, xf);
665 });
666 }();
667
668 var _xfind = function () {
669 function XFind(f, xf) {
670 this.xf = xf;
671 this.f = f;
672 this.found = false;
673 }
674 XFind.prototype['@@transducer/init'] = _xfBase.init;
675 XFind.prototype['@@transducer/result'] = function (result) {
676 if (!this.found) {
677 result = this.xf['@@transducer/step'](result, void 0);
678 }
679 return this.xf['@@transducer/result'](result);
680 };
681 XFind.prototype['@@transducer/step'] = function (result, input) {
682 if (this.f(input)) {
683 this.found = true;
684 result = _reduced(this.xf['@@transducer/step'](result, input));
685 }
686 return result;
687 };
688 return _curry2(function _xfind(f, xf) {
689 return new XFind(f, xf);
690 });
691 }();
692
693 var _xfindIndex = function () {
694 function XFindIndex(f, xf) {
695 this.xf = xf;
696 this.f = f;
697 this.idx = -1;
698 this.found = false;
699 }
700 XFindIndex.prototype['@@transducer/init'] = _xfBase.init;
701 XFindIndex.prototype['@@transducer/result'] = function (result) {
702 if (!this.found) {
703 result = this.xf['@@transducer/step'](result, -1);
704 }
705 return this.xf['@@transducer/result'](result);
706 };
707 XFindIndex.prototype['@@transducer/step'] = function (result, input) {
708 this.idx += 1;
709 if (this.f(input)) {
710 this.found = true;
711 result = _reduced(this.xf['@@transducer/step'](result, this.idx));
712 }
713 return result;
714 };
715 return _curry2(function _xfindIndex(f, xf) {
716 return new XFindIndex(f, xf);
717 });
718 }();
719
720 var _xfindLast = function () {
721 function XFindLast(f, xf) {
722 this.xf = xf;
723 this.f = f;
724 }
725 XFindLast.prototype['@@transducer/init'] = _xfBase.init;
726 XFindLast.prototype['@@transducer/result'] = function (result) {
727 return this.xf['@@transducer/result'](this.xf['@@transducer/step'](result, this.last));
728 };
729 XFindLast.prototype['@@transducer/step'] = function (result, input) {
730 if (this.f(input)) {
731 this.last = input;
732 }
733 return result;
734 };
735 return _curry2(function _xfindLast(f, xf) {
736 return new XFindLast(f, xf);
737 });
738 }();
739
740 var _xfindLastIndex = function () {
741 function XFindLastIndex(f, xf) {
742 this.xf = xf;
743 this.f = f;
744 this.idx = -1;
745 this.lastIdx = -1;
746 }
747 XFindLastIndex.prototype['@@transducer/init'] = _xfBase.init;
748 XFindLastIndex.prototype['@@transducer/result'] = function (result) {
749 return this.xf['@@transducer/result'](this.xf['@@transducer/step'](result, this.lastIdx));
750 };
751 XFindLastIndex.prototype['@@transducer/step'] = function (result, input) {
752 this.idx += 1;
753 if (this.f(input)) {
754 this.lastIdx = this.idx;
755 }
756 return result;
757 };
758 return _curry2(function _xfindLastIndex(f, xf) {
759 return new XFindLastIndex(f, xf);
760 });
761 }();
762
763 var _xmap = function () {
764 function XMap(f, xf) {
765 this.xf = xf;
766 this.f = f;
767 }
768 XMap.prototype['@@transducer/init'] = _xfBase.init;
769 XMap.prototype['@@transducer/result'] = _xfBase.result;
770 XMap.prototype['@@transducer/step'] = function (result, input) {
771 return this.xf['@@transducer/step'](result, this.f(input));
772 };
773 return _curry2(function _xmap(f, xf) {
774 return new XMap(f, xf);
775 });
776 }();
777
778 var _xtake = function () {
779 function XTake(n, xf) {
780 this.xf = xf;
781 this.n = n;
782 }
783 XTake.prototype['@@transducer/init'] = _xfBase.init;
784 XTake.prototype['@@transducer/result'] = _xfBase.result;
785 XTake.prototype['@@transducer/step'] = function (result, input) {
786 if (this.n === 0) {
787 return _reduced(result);
788 } else {
789 this.n -= 1;
790 return this.xf['@@transducer/step'](result, input);
791 }
792 };
793 return _curry2(function _xtake(n, xf) {
794 return new XTake(n, xf);
795 });
796 }();
797
798 var _xtakeWhile = function () {
799 function XTakeWhile(f, xf) {
800 this.xf = xf;
801 this.f = f;
802 }
803 XTakeWhile.prototype['@@transducer/init'] = _xfBase.init;
804 XTakeWhile.prototype['@@transducer/result'] = _xfBase.result;
805 XTakeWhile.prototype['@@transducer/step'] = function (result, input) {
806 return this.f(input) ? this.xf['@@transducer/step'](result, input) : _reduced(result);
807 };
808 return _curry2(function _xtakeWhile(f, xf) {
809 return new XTakeWhile(f, xf);
810 });
811 }();
812
813 var _xwrap = function () {
814 function XWrap(fn) {
815 this.f = fn;
816 }
817 XWrap.prototype['@@transducer/init'] = function () {
818 throw new Error('init not implemented on XWrap');
819 };
820 XWrap.prototype['@@transducer/result'] = function (acc) {
821 return acc;
822 };
823 XWrap.prototype['@@transducer/step'] = function (acc, x) {
824 return this.f(acc, x);
825 };
826 return function _xwrap(fn) {
827 return new XWrap(fn);
828 };
829 }();
830
831 /**
832 * Adds two numbers. Equivalent to `a + b` but curried.
833 *
834 * @func
835 * @memberOf R
836 * @category Math
837 * @sig Number -> Number -> Number
838 * @param {Number} a
839 * @param {Number} b
840 * @return {Number}
841 * @see R.subtract
842 * @example
843 *
844 * R.add(2, 3); //=> 5
845 * R.add(7)(10); //=> 17
846 */
847 var add = _curry2(function add(a, b) {
848 return a + b;
849 });
850
851 /**
852 * Applies a function to the value at the given index of an array,
853 * returning a new copy of the array with the element at the given
854 * index replaced with the result of the function application.
855 * @see R.update
856 *
857 * @func
858 * @memberOf R
859 * @category List
860 * @sig (a -> a) -> Number -> [a] -> [a]
861 * @param {Function} fn The function to apply.
862 * @param {Number} idx The index.
863 * @param {Array|Arguments} list An array-like object whose value
864 * at the supplied index will be replaced.
865 * @return {Array} A copy of the supplied array-like object with
866 * the element at index `idx` replaced with the value
867 * returned by applying `fn` to the existing element.
868 * @example
869 *
870 * R.adjust(R.add(10), 1, [0, 1, 2]); //=> [0, 11, 2]
871 * R.adjust(R.add(10))(1)([0, 1, 2]); //=> [0, 11, 2]
872 */
873 var adjust = _curry3(function adjust(fn, idx, list) {
874 if (idx >= list.length || idx < -list.length) {
875 return list;
876 }
877 var start = idx < 0 ? list.length : 0;
878 var _idx = start + idx;
879 var _list = _concat(list);
880 _list[_idx] = fn(list[_idx]);
881 return _list;
882 });
883
884 /**
885 * Returns a function that always returns the given value. Note that for
886 * non-primitives the value returned is a reference to the original value.
887 *
888 * This function is known as `const`, `constant`, or `K` (for K combinator)
889 * in other languages and libraries.
890 *
891 * @func
892 * @memberOf R
893 * @category Function
894 * @sig a -> (* -> a)
895 * @param {*} val The value to wrap in a function
896 * @return {Function} A Function :: * -> val.
897 * @example
898 *
899 * var t = R.always('Tee');
900 * t(); //=> 'Tee'
901 */
902 var always = _curry1(function always(val) {
903 return function () {
904 return val;
905 };
906 });
907
908 /**
909 * Returns a new list, composed of n-tuples of consecutive elements
910 * If `n` is greater than the length of the list, an empty list is returned.
911 *
912 * @func
913 * @memberOf R
914 * @category List
915 * @sig Number -> [a] -> [[a]]
916 * @param {Number} n The size of the tuples to create
917 * @param {Array} list The list to split into `n`-tuples
918 * @return {Array} The new list.
919 * @example
920 *
921 * R.aperture(2, [1, 2, 3, 4, 5]); //=> [[1, 2], [2, 3], [3, 4], [4, 5]]
922 * R.aperture(3, [1, 2, 3, 4, 5]); //=> [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
923 * R.aperture(7, [1, 2, 3, 4, 5]); //=> []
924 */
925 var aperture = _curry2(function aperture(n, list) {
926 var idx = 0;
927 var limit = list.length - (n - 1);
928 var acc = new Array(limit >= 0 ? limit : 0);
929 while (idx < limit) {
930 acc[idx] = _slice(list, idx, idx + n);
931 idx += 1;
932 }
933 return acc;
934 });
935
936 /**
937 * Returns a new list containing the contents of the given list, followed by the given
938 * element.
939 *
940 * @func
941 * @memberOf R
942 * @category List
943 * @sig a -> [a] -> [a]
944 * @param {*} el The element to add to the end of the new list.
945 * @param {Array} list The list whose contents will be added to the beginning of the output
946 * list.
947 * @return {Array} A new list containing the contents of the old list followed by `el`.
948 * @see R.prepend
949 * @example
950 *
951 * R.append('tests', ['write', 'more']); //=> ['write', 'more', 'tests']
952 * R.append('tests', []); //=> ['tests']
953 * R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']]
954 */
955 var append = _curry2(function append(el, list) {
956 return _concat(list, [el]);
957 });
958
959 /**
960 * Applies function `fn` to the argument list `args`. This is useful for
961 * creating a fixed-arity function from a variadic function. `fn` should
962 * be a bound function if context is significant.
963 *
964 * @func
965 * @memberOf R
966 * @category Function
967 * @sig (*... -> a) -> [*] -> a
968 * @param {Function} fn
969 * @param {Array} args
970 * @return {*}
971 * @see R.call, R.unapply
972 * @example
973 *
974 * var nums = [1, 2, 3, -99, 42, 6, 7];
975 * R.apply(Math.max, nums); //=> 42
976 */
977 var apply = _curry2(function apply(fn, args) {
978 return fn.apply(this, args);
979 });
980
981 /**
982 * Makes a shallow clone of an object, setting or overriding the specified
983 * property with the given value. Note that this copies and flattens
984 * prototype properties onto the new object as well. All non-primitive
985 * properties are copied by reference.
986 *
987 * @func
988 * @memberOf R
989 * @category Object
990 * @sig String -> a -> {k: v} -> {k: v}
991 * @param {String} prop the property name to set
992 * @param {*} val the new value
993 * @param {Object} obj the object to clone
994 * @return {Object} a new object similar to the original except for the specified property.
995 * @see R.dissoc
996 * @example
997 *
998 * R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
999 */
1000 var assoc = _curry3(function assoc(prop, val, obj) {
1001 var result = {};
1002 for (var p in obj) {
1003 result[p] = obj[p];
1004 }
1005 result[prop] = val;
1006 return result;
1007 });
1008
1009 /**
1010 * Makes a shallow clone of an object, setting or overriding the nodes
1011 * required to create the given path, and placing the specific value at the
1012 * tail end of that path. Note that this copies and flattens prototype
1013 * properties onto the new object as well. All non-primitive properties
1014 * are copied by reference.
1015 *
1016 * @func
1017 * @memberOf R
1018 * @category Object
1019 * @sig [String] -> a -> {k: v} -> {k: v}
1020 * @param {Array} path the path to set
1021 * @param {*} val the new value
1022 * @param {Object} obj the object to clone
1023 * @return {Object} a new object similar to the original except along the specified path.
1024 * @see R.dissocPath
1025 * @example
1026 *
1027 * R.assocPath(['a', 'b', 'c'], 42, {a: {b: {c: 0}}}); //=> {a: {b: {c: 42}}}
1028 */
1029 var assocPath = _curry3(function assocPath(path, val, obj) {
1030 switch (path.length) {
1031 case 0:
1032 return obj;
1033 case 1:
1034 return assoc(path[0], val, obj);
1035 default:
1036 return assoc(path[0], assocPath(_slice(path, 1), val, Object(obj[path[0]])), obj);
1037 }
1038 });
1039
1040 /**
1041 * Creates a function that is bound to a context.
1042 * Note: `R.bind` does not provide the additional argument-binding capabilities of
1043 * [Function.prototype.bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).
1044 *
1045 * @func
1046 * @memberOf R
1047 * @category Function
1048 * @category Object
1049 * @see R.partial
1050 * @sig (* -> *) -> {*} -> (* -> *)
1051 * @param {Function} fn The function to bind to context
1052 * @param {Object} thisObj The context to bind `fn` to
1053 * @return {Function} A function that will execute in the context of `thisObj`.
1054 */
1055 var bind = _curry2(function bind(fn, thisObj) {
1056 return _arity(fn.length, function () {
1057 return fn.apply(thisObj, arguments);
1058 });
1059 });
1060
1061 /**
1062 * A function wrapping calls to the two functions in an `&&` operation, returning the result of the first
1063 * function if it is false-y and the result of the second function otherwise. Note that this is
1064 * short-circuited, meaning that the second function will not be invoked if the first returns a false-y
1065 * value.
1066 *
1067 * @func
1068 * @memberOf R
1069 * @category Logic
1070 * @sig (*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean)
1071 * @param {Function} f a predicate
1072 * @param {Function} g another predicate
1073 * @return {Function} a function that applies its arguments to `f` and `g` and `&&`s their outputs together.
1074 * @see R.and
1075 * @example
1076 *
1077 * var gt10 = function(x) { return x > 10; };
1078 * var even = function(x) { return x % 2 === 0 };
1079 * var f = R.both(gt10, even);
1080 * f(100); //=> true
1081 * f(101); //=> false
1082 */
1083 var both = _curry2(function both(f, g) {
1084 return function _both() {
1085 return f.apply(this, arguments) && g.apply(this, arguments);
1086 };
1087 });
1088
1089 /**
1090 * Makes a comparator function out of a function that reports whether the first element is less than the second.
1091 *
1092 * @func
1093 * @memberOf R
1094 * @category Function
1095 * @sig (a, b -> Boolean) -> (a, b -> Number)
1096 * @param {Function} pred A predicate function of arity two.
1097 * @return {Function} A Function :: a -> b -> Int that returns `-1` if a < b, `1` if b < a, otherwise `0`.
1098 * @example
1099 *
1100 * var cmp = R.comparator(function(a, b) {
1101 * return a.age < b.age;
1102 * });
1103 * var people = [
1104 * // ...
1105 * ];
1106 * R.sort(cmp, people);
1107 */
1108 var comparator = _curry1(function comparator(pred) {
1109 return function (a, b) {
1110 return pred(a, b) ? -1 : pred(b, a) ? 1 : 0;
1111 };
1112 });
1113
1114 /**
1115 * Takes a function `f` and returns a function `g` such that:
1116 *
1117 * - applying `g` to zero or more arguments will give __true__ if applying
1118 * the same arguments to `f` gives a logical __false__ value; and
1119 *
1120 * - applying `g` to zero or more arguments will give __false__ if applying
1121 * the same arguments to `f` gives a logical __true__ value.
1122 *
1123 * @func
1124 * @memberOf R
1125 * @category Logic
1126 * @sig (*... -> *) -> (*... -> Boolean)
1127 * @param {Function} f
1128 * @return {Function}
1129 * @see R.not
1130 * @example
1131 *
1132 * var isEven = function(n) { return n % 2 === 0; };
1133 * var isOdd = R.complement(isEven);
1134 * isOdd(21); //=> true
1135 * isOdd(42); //=> false
1136 */
1137 var complement = _curry1(_complement);
1138
1139 /**
1140 * Returns a function, `fn`, which encapsulates if/else-if/else logic.
1141 * `R.cond` takes a list of [predicate, transform] pairs. All of the
1142 * arguments to `fn` are applied to each of the predicates in turn
1143 * until one returns a "truthy" value, at which point `fn` returns the
1144 * result of applying its arguments to the corresponding transformer.
1145 * If none of the predicates matches, `fn` returns undefined.
1146 *
1147 * @func
1148 * @memberOf R
1149 * @category Logic
1150 * @sig [[(*... -> Boolean),(*... -> *)]] -> (*... -> *)
1151 * @param {Array} pairs
1152 * @return {Function}
1153 * @example
1154 *
1155 * var fn = R.cond([
1156 * [R.equals(0), R.always('water freezes at 0°C')],
1157 * [R.equals(100), R.always('water boils at 100°C')],
1158 * [R.T, function(temp) { return 'nothing special happens at ' + temp + '°C'; }]
1159 * ]);
1160 * fn(0); //=> 'water freezes at 0°C'
1161 * fn(50); //=> 'nothing special happens at 50°C'
1162 * fn(100); //=> 'water boils at 100°C'
1163 */
1164 var cond = _curry1(function cond(pairs) {
1165 return function () {
1166 var idx = 0;
1167 while (idx < pairs.length) {
1168 if (pairs[idx][0].apply(this, arguments)) {
1169 return pairs[idx][1].apply(this, arguments);
1170 }
1171 idx += 1;
1172 }
1173 };
1174 });
1175
1176 /**
1177 * Returns `true` if the `x` is found in the `list`, using `pred` as an
1178 * equality predicate for `x`.
1179 *
1180 * @func
1181 * @memberOf R
1182 * @category List
1183 * @sig (a, a -> Boolean) -> a -> [a] -> Boolean
1184 * @param {Function} pred A predicate used to test whether two items are equal.
1185 * @param {*} x The item to find
1186 * @param {Array} list The list to iterate over
1187 * @return {Boolean} `true` if `x` is in `list`, else `false`.
1188 * @example
1189 *
1190 * var xs = [{x: 12}, {x: 11}, {x: 10}];
1191 * R.containsWith(function(a, b) { return a.x === b.x; }, {x: 10}, xs); //=> true
1192 * R.containsWith(function(a, b) { return a.x === b.x; }, {x: 1}, xs); //=> false
1193 */
1194 var containsWith = _curry3(_containsWith);
1195
1196 /**
1197 * Counts the elements of a list according to how many match each value
1198 * of a key generated by the supplied function. Returns an object
1199 * mapping the keys produced by `fn` to the number of occurrences in
1200 * the list. Note that all keys are coerced to strings because of how
1201 * JavaScript objects work.
1202 *
1203 * @func
1204 * @memberOf R
1205 * @category Relation
1206 * @sig (a -> String) -> [a] -> {*}
1207 * @param {Function} fn The function used to map values to keys.
1208 * @param {Array} list The list to count elements from.
1209 * @return {Object} An object mapping keys to number of occurrences in the list.
1210 * @example
1211 *
1212 * var numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2];
1213 * var letters = R.split('', 'abcABCaaaBBc');
1214 * R.countBy(Math.floor)(numbers); //=> {'1': 3, '2': 2, '3': 1}
1215 * R.countBy(R.toLower)(letters); //=> {'a': 5, 'b': 4, 'c': 3}
1216 */
1217 var countBy = _curry2(function countBy(fn, list) {
1218 var counts = {};
1219 var len = list.length;
1220 var idx = 0;
1221 while (idx < len) {
1222 var key = fn(list[idx]);
1223 counts[key] = (_has(key, counts) ? counts[key] : 0) + 1;
1224 idx += 1;
1225 }
1226 return counts;
1227 });
1228
1229 /**
1230 * Creates an object containing a single key:value pair.
1231 *
1232 * @func
1233 * @memberOf R
1234 * @category Object
1235 * @sig String -> a -> {String:a}
1236 * @param {String} key
1237 * @param {*} val
1238 * @return {Object}
1239 * @example
1240 *
1241 * var matchPhrases = R.compose(
1242 * R.createMapEntry('must'),
1243 * R.map(R.createMapEntry('match_phrase'))
1244 * );
1245 * matchPhrases(['foo', 'bar', 'baz']); //=> {must: [{match_phrase: 'foo'}, {match_phrase: 'bar'}, {match_phrase: 'baz'}]}
1246 */
1247 var createMapEntry = _curry2(function createMapEntry(key, val) {
1248 var obj = {};
1249 obj[key] = val;
1250 return obj;
1251 });
1252
1253 /**
1254 * Returns a curried equivalent of the provided function, with the
1255 * specified arity. The curried function has two unusual capabilities.
1256 * First, its arguments needn't be provided one at a time. If `g` is
1257 * `R.curryN(3, f)`, the following are equivalent:
1258 *
1259 * - `g(1)(2)(3)`
1260 * - `g(1)(2, 3)`
1261 * - `g(1, 2)(3)`
1262 * - `g(1, 2, 3)`
1263 *
1264 * Secondly, the special placeholder value `R.__` may be used to specify
1265 * "gaps", allowing partial application of any combination of arguments,
1266 * regardless of their positions. If `g` is as above and `_` is `R.__`,
1267 * the following are equivalent:
1268 *
1269 * - `g(1, 2, 3)`
1270 * - `g(_, 2, 3)(1)`
1271 * - `g(_, _, 3)(1)(2)`
1272 * - `g(_, _, 3)(1, 2)`
1273 * - `g(_, 2)(1)(3)`
1274 * - `g(_, 2)(1, 3)`
1275 * - `g(_, 2)(_, 3)(1)`
1276 *
1277 * @func
1278 * @memberOf R
1279 * @category Function
1280 * @sig Number -> (* -> a) -> (* -> a)
1281 * @param {Number} length The arity for the returned function.
1282 * @param {Function} fn The function to curry.
1283 * @return {Function} A new, curried function.
1284 * @see R.curry
1285 * @example
1286 *
1287 * var addFourNumbers = function() {
1288 * return R.sum([].slice.call(arguments, 0, 4));
1289 * };
1290 *
1291 * var curriedAddFourNumbers = R.curryN(4, addFourNumbers);
1292 * var f = curriedAddFourNumbers(1, 2);
1293 * var g = f(3);
1294 * g(4); //=> 10
1295 */
1296 var curryN = _curry2(function curryN(length, fn) {
1297 if (length === 1) {
1298 return _curry1(fn);
1299 }
1300 return _arity(length, _curryN(length, [], fn));
1301 });
1302
1303 /**
1304 * Decrements its argument.
1305 *
1306 * @func
1307 * @memberOf R
1308 * @category Math
1309 * @sig Number -> Number
1310 * @param {Number} n
1311 * @return {Number}
1312 * @see R.inc
1313 * @example
1314 *
1315 * R.dec(42); //=> 41
1316 */
1317 var dec = add(-1);
1318
1319 /**
1320 * Returns the second argument if it is not null or undefined. If it is null
1321 * or undefined, the first (default) argument is returned.
1322 *
1323 * @func
1324 * @memberOf R
1325 * @category Logic
1326 * @sig a -> b -> a | b
1327 * @param {a} val The default value.
1328 * @param {b} val The value to return if it is not null or undefined
1329 * @return {*} The the second value or the default value
1330 * @example
1331 *
1332 * var defaultTo42 = defaultTo(42);
1333 *
1334 * defaultTo42(null); //=> 42
1335 * defaultTo42(undefined); //=> 42
1336 * defaultTo42('Ramda'); //=> 'Ramda'
1337 */
1338 var defaultTo = _curry2(function defaultTo(d, v) {
1339 return v == null ? d : v;
1340 });
1341
1342 /**
1343 * Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list.
1344 * Duplication is determined according to the value returned by applying the supplied predicate to two list
1345 * elements.
1346 *
1347 * @func
1348 * @memberOf R
1349 * @category Relation
1350 * @sig (a,a -> Boolean) -> [a] -> [a] -> [a]
1351 * @param {Function} pred A predicate used to test whether two items are equal.
1352 * @param {Array} list1 The first list.
1353 * @param {Array} list2 The second list.
1354 * @see R.difference
1355 * @return {Array} The elements in `list1` that are not in `list2`.
1356 * @example
1357 *
1358 * function cmp(x, y) { return x.a === y.a; }
1359 * var l1 = [{a: 1}, {a: 2}, {a: 3}];
1360 * var l2 = [{a: 3}, {a: 4}];
1361 * R.differenceWith(cmp, l1, l2); //=> [{a: 1}, {a: 2}]
1362 */
1363 var differenceWith = _curry3(function differenceWith(pred, first, second) {
1364 var out = [];
1365 var idx = 0;
1366 var firstLen = first.length;
1367 var containsPred = containsWith(pred);
1368 while (idx < firstLen) {
1369 if (!containsPred(first[idx], second) && !containsPred(first[idx], out)) {
1370 out[out.length] = first[idx];
1371 }
1372 idx += 1;
1373 }
1374 return out;
1375 });
1376
1377 /**
1378 * Returns a new object that does not contain a `prop` property.
1379 *
1380 * @func
1381 * @memberOf R
1382 * @category Object
1383 * @sig String -> {k: v} -> {k: v}
1384 * @param {String} prop the name of the property to dissociate
1385 * @param {Object} obj the object to clone
1386 * @return {Object} a new object similar to the original but without the specified property
1387 * @see R.assoc
1388 * @example
1389 *
1390 * R.dissoc('b', {a: 1, b: 2, c: 3}); //=> {a: 1, c: 3}
1391 */
1392 var dissoc = _curry2(function dissoc(prop, obj) {
1393 var result = {};
1394 for (var p in obj) {
1395 if (p !== prop) {
1396 result[p] = obj[p];
1397 }
1398 }
1399 return result;
1400 });
1401
1402 /**
1403 * Makes a shallow clone of an object, omitting the property at the
1404 * given path. Note that this copies and flattens prototype properties
1405 * onto the new object as well. All non-primitive properties are copied
1406 * by reference.
1407 *
1408 * @func
1409 * @memberOf R
1410 * @category Object
1411 * @sig [String] -> {k: v} -> {k: v}
1412 * @param {Array} path the path to set
1413 * @param {Object} obj the object to clone
1414 * @return {Object} a new object without the property at path
1415 * @see R.assocPath
1416 * @example
1417 *
1418 * R.dissocPath(['a', 'b', 'c'], {a: {b: {c: 42}}}); //=> {a: {b: {}}}
1419 */
1420 var dissocPath = _curry2(function dissocPath(path, obj) {
1421 switch (path.length) {
1422 case 0:
1423 return obj;
1424 case 1:
1425 return dissoc(path[0], obj);
1426 default:
1427 var head = path[0];
1428 var tail = _slice(path, 1);
1429 return obj[head] == null ? obj : assoc(head, dissocPath(tail, obj[head]), obj);
1430 }
1431 });
1432
1433 /**
1434 * Divides two numbers. Equivalent to `a / b`.
1435 *
1436 * @func
1437 * @memberOf R
1438 * @category Math
1439 * @sig Number -> Number -> Number
1440 * @param {Number} a The first value.
1441 * @param {Number} b The second value.
1442 * @return {Number} The result of `a / b`.
1443 * @see R.multiply
1444 * @example
1445 *
1446 * R.divide(71, 100); //=> 0.71
1447 *
1448 * var half = R.divide(R.__, 2);
1449 * half(42); //=> 21
1450 *
1451 * var reciprocal = R.divide(1);
1452 * reciprocal(4); //=> 0.25
1453 */
1454 var divide = _curry2(function divide(a, b) {
1455 return a / b;
1456 });
1457
1458 /**
1459 * Returns a new list containing all but last the`n` elements of a given list,
1460 * passing each value from the right to the supplied predicate function, skipping
1461 * elements while the predicate function returns `true`. The predicate function
1462 * is passed one argument: (value)*.
1463 *
1464 * @func
1465 * @memberOf R
1466 * @category List
1467 * @sig (a -> Boolean) -> [a] -> [a]
1468 * @param {Function} fn The function called per iteration.
1469 * @param {Array} list The collection to iterate over.
1470 * @return {Array} A new array.
1471 * @see R.takeLastWhile
1472 * @example
1473 *
1474 * var lteThree = function(x) {
1475 * return x <= 3;
1476 * };
1477 *
1478 * R.dropLastWhile(lteThree, [1, 2, 3, 4, 3, 2, 1]); //=> [1, 2]
1479 */
1480 var dropLastWhile = _curry2(function dropLastWhile(pred, list) {
1481 var idx = list.length - 1;
1482 while (idx >= 0 && pred(list[idx])) {
1483 idx -= 1;
1484 }
1485 return _slice(list, 0, idx + 1);
1486 });
1487
1488 /**
1489 * A function wrapping calls to the two functions in an `||` operation, returning the result of the first
1490 * function if it is truth-y and the result of the second function otherwise. Note that this is
1491 * short-circuited, meaning that the second function will not be invoked if the first returns a truth-y
1492 * value.
1493 *
1494 * @func
1495 * @memberOf R
1496 * @category Logic
1497 * @sig (*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean)
1498 * @param {Function} f a predicate
1499 * @param {Function} g another predicate
1500 * @return {Function} a function that applies its arguments to `f` and `g` and `||`s their outputs together.
1501 * @see R.or
1502 * @example
1503 *
1504 * var gt10 = function(x) { return x > 10; };
1505 * var even = function(x) { return x % 2 === 0 };
1506 * var f = R.either(gt10, even);
1507 * f(101); //=> true
1508 * f(8); //=> true
1509 */
1510 var either = _curry2(function either(f, g) {
1511 return function _either() {
1512 return f.apply(this, arguments) || g.apply(this, arguments);
1513 };
1514 });
1515
1516 /**
1517 * Returns the empty value of its argument's type. Ramda defines the empty
1518 * value of Array (`[]`), Object (`{}`), and String (`''`). Other types are
1519 * supported if they define `<Type>.empty` and/or `<Type>.prototype.empty`.
1520 *
1521 * @func
1522 * @memberOf R
1523 * @category Function
1524 * @sig a -> a
1525 * @param {*} x
1526 * @return {*}
1527 * @example
1528 *
1529 * R.empty(Just(42)); //=> Nothing()
1530 * R.empty([1, 2, 3]); //=> []
1531 * R.empty('unicorns'); //=> ''
1532 * R.empty({x: 1, y: 2}); //=> {}
1533 */
1534 var empty = _curry1(function empty(x) {
1535 if (x != null && typeof x.empty === 'function') {
1536 return x.empty();
1537 } else if (x != null && typeof x.constructor != null && typeof x.constructor.empty === 'function') {
1538 return x.constructor.empty();
1539 } else {
1540 switch (Object.prototype.toString.call(x)) {
1541 case '[object Array]':
1542 return [];
1543 case '[object Object]':
1544 return {};
1545 case '[object String]':
1546 return '';
1547 }
1548 }
1549 });
1550
1551 /**
1552 * Creates a new object by recursively evolving a shallow copy of `object`, according to the
1553 * `transformation` functions. All non-primitive properties are copied by reference.
1554 *
1555 * A `tranformation` function will not be invoked if its corresponding key does not exist in
1556 * the evolved object.
1557 *
1558 * @func
1559 * @memberOf R
1560 * @category Object
1561 * @sig {k: (v -> v)} -> {k: v} -> {k: v}
1562 * @param {Object} transformations The object specifying transformation functions to apply
1563 * to the object.
1564 * @param {Object} object The object to be transformed.
1565 * @return {Object} The transformed object.
1566 * @example
1567 *
1568 * var tomato = {firstName: ' Tomato ', data: {elapsed: 100, remaining: 1400}, id:123};
1569 * var transformations = {
1570 * firstName: R.trim,
1571 * lastName: R.trim, // Will not get invoked.
1572 * data: {elapsed: R.add(1), remaining: R.add(-1)}
1573 * };
1574 * R.evolve(transformations, tomato); //=> {firstName: 'Tomato', data: {elapsed: 101, remaining: 1399}, id:123}
1575 */
1576 var evolve = _curry2(function evolve(transformations, object) {
1577 var transformation, key, type, result = {};
1578 for (key in object) {
1579 transformation = transformations[key];
1580 type = typeof transformation;
1581 result[key] = type === 'function' ? transformation(object[key]) : type === 'object' ? evolve(transformations[key], object[key]) : object[key];
1582 }
1583 return result;
1584 });
1585
1586 /**
1587 * Creates a new object out of a list key-value pairs.
1588 *
1589 * @func
1590 * @memberOf R
1591 * @category List
1592 * @sig [[k,v]] -> {k: v}
1593 * @param {Array} pairs An array of two-element arrays that will be the keys and values of the output object.
1594 * @return {Object} The object made by pairing up `keys` and `values`.
1595 * @see R.toPairs
1596 * @example
1597 *
1598 * R.fromPairs([['a', 1], ['b', 2], ['c', 3]]); //=> {a: 1, b: 2, c: 3}
1599 */
1600 var fromPairs = _curry1(function fromPairs(pairs) {
1601 var idx = 0, len = pairs.length, out = {};
1602 while (idx < len) {
1603 if (_isArray(pairs[idx]) && pairs[idx].length) {
1604 out[pairs[idx][0]] = pairs[idx][1];
1605 }
1606 idx += 1;
1607 }
1608 return out;
1609 });
1610
1611 /**
1612 * Returns `true` if the first argument is greater than the second;
1613 * `false` otherwise.
1614 *
1615 * @func
1616 * @memberOf R
1617 * @category Relation
1618 * @sig Ord a => a -> a -> Boolean
1619 * @param {*} a
1620 * @param {*} b
1621 * @return {Boolean}
1622 * @see R.lt
1623 * @example
1624 *
1625 * R.gt(2, 1); //=> true
1626 * R.gt(2, 2); //=> false
1627 * R.gt(2, 3); //=> false
1628 * R.gt('a', 'z'); //=> false
1629 * R.gt('z', 'a'); //=> true
1630 */
1631 var gt = _curry2(function gt(a, b) {
1632 return a > b;
1633 });
1634
1635 /**
1636 * Returns `true` if the first argument is greater than or equal to the second;
1637 * `false` otherwise.
1638 *
1639 * @func
1640 * @memberOf R
1641 * @category Relation
1642 * @sig Ord a => a -> a -> Boolean
1643 * @param {Number} a
1644 * @param {Number} b
1645 * @return {Boolean}
1646 * @see R.lte
1647 * @example
1648 *
1649 * R.gte(2, 1); //=> true
1650 * R.gte(2, 2); //=> true
1651 * R.gte(2, 3); //=> false
1652 * R.gte('a', 'z'); //=> false
1653 * R.gte('z', 'a'); //=> true
1654 */
1655 var gte = _curry2(function gte(a, b) {
1656 return a >= b;
1657 });
1658
1659 /**
1660 * Returns whether or not an object has an own property with
1661 * the specified name
1662 *
1663 * @func
1664 * @memberOf R
1665 * @category Object
1666 * @sig s -> {s: x} -> Boolean
1667 * @param {String} prop The name of the property to check for.
1668 * @param {Object} obj The object to query.
1669 * @return {Boolean} Whether the property exists.
1670 * @example
1671 *
1672 * var hasName = R.has('name');
1673 * hasName({name: 'alice'}); //=> true
1674 * hasName({name: 'bob'}); //=> true
1675 * hasName({}); //=> false
1676 *
1677 * var point = {x: 0, y: 0};
1678 * var pointHas = R.has(R.__, point);
1679 * pointHas('x'); //=> true
1680 * pointHas('y'); //=> true
1681 * pointHas('z'); //=> false
1682 */
1683 var has = _curry2(_has);
1684
1685 /**
1686 * Returns whether or not an object or its prototype chain has
1687 * a property with the specified name
1688 *
1689 * @func
1690 * @memberOf R
1691 * @category Object
1692 * @sig s -> {s: x} -> Boolean
1693 * @param {String} prop The name of the property to check for.
1694 * @param {Object} obj The object to query.
1695 * @return {Boolean} Whether the property exists.
1696 * @example
1697 *
1698 * function Rectangle(width, height) {
1699 * this.width = width;
1700 * this.height = height;
1701 * }
1702 * Rectangle.prototype.area = function() {
1703 * return this.width * this.height;
1704 * };
1705 *
1706 * var square = new Rectangle(2, 2);
1707 * R.hasIn('width', square); //=> true
1708 * R.hasIn('area', square); //=> true
1709 */
1710 var hasIn = _curry2(function hasIn(prop, obj) {
1711 return prop in obj;
1712 });
1713
1714 /**
1715 * Returns true if its arguments are identical, false otherwise. Values are
1716 * identical if they reference the same memory. `NaN` is identical to `NaN`;
1717 * `0` and `-0` are not identical.
1718 *
1719 * @func
1720 * @memberOf R
1721 * @category Relation
1722 * @sig a -> a -> Boolean
1723 * @param {*} a
1724 * @param {*} b
1725 * @return {Boolean}
1726 * @example
1727 *
1728 * var o = {};
1729 * R.identical(o, o); //=> true
1730 * R.identical(1, 1); //=> true
1731 * R.identical(1, '1'); //=> false
1732 * R.identical([], []); //=> false
1733 * R.identical(0, -0); //=> false
1734 * R.identical(NaN, NaN); //=> true
1735 */
1736 // SameValue algorithm
1737 // Steps 1-5, 7-10
1738 // Steps 6.b-6.e: +0 != -0
1739 // Step 6.a: NaN == NaN
1740 var identical = _curry2(function identical(a, b) {
1741 // SameValue algorithm
1742 if (a === b) {
1743 // Steps 1-5, 7-10
1744 // Steps 6.b-6.e: +0 != -0
1745 return a !== 0 || 1 / a === 1 / b;
1746 } else {
1747 // Step 6.a: NaN == NaN
1748 return a !== a && b !== b;
1749 }
1750 });
1751
1752 /**
1753 * A function that does nothing but return the parameter supplied to it. Good as a default
1754 * or placeholder function.
1755 *
1756 * @func
1757 * @memberOf R
1758 * @category Function
1759 * @sig a -> a
1760 * @param {*} x The value to return.
1761 * @return {*} The input value, `x`.
1762 * @example
1763 *
1764 * R.identity(1); //=> 1
1765 *
1766 * var obj = {};
1767 * R.identity(obj) === obj; //=> true
1768 */
1769 var identity = _curry1(_identity);
1770
1771 /**
1772 * Creates a function that will process either the `onTrue` or the `onFalse` function depending
1773 * upon the result of the `condition` predicate.
1774 *
1775 * @func
1776 * @memberOf R
1777 * @category Logic
1778 * @sig (*... -> Boolean) -> (*... -> *) -> (*... -> *) -> (*... -> *)
1779 * @param {Function} condition A predicate function
1780 * @param {Function} onTrue A function to invoke when the `condition` evaluates to a truthy value.
1781 * @param {Function} onFalse A function to invoke when the `condition` evaluates to a falsy value.
1782 * @return {Function} A new unary function that will process either the `onTrue` or the `onFalse`
1783 * function depending upon the result of the `condition` predicate.
1784 * @example
1785 *
1786 * // Flatten all arrays in the list but leave other values alone.
1787 * var flattenArrays = R.map(R.ifElse(Array.isArray, R.flatten, R.identity));
1788 *
1789 * flattenArrays([[0], [[10], [8]], 1234, {}]); //=> [[0], [10, 8], 1234, {}]
1790 * flattenArrays([[[10], 123], [8, [10]], "hello"]); //=> [[10, 123], [8, 10], "hello"]
1791 */
1792 var ifElse = _curry3(function ifElse(condition, onTrue, onFalse) {
1793 return curryN(Math.max(condition.length, onTrue.length, onFalse.length), function _ifElse() {
1794 return condition.apply(this, arguments) ? onTrue.apply(this, arguments) : onFalse.apply(this, arguments);
1795 });
1796 });
1797
1798 /**
1799 * Increments its argument.
1800 *
1801 * @func
1802 * @memberOf R
1803 * @category Math
1804 * @sig Number -> Number
1805 * @param {Number} n
1806 * @return {Number}
1807 * @see R.dec
1808 * @example
1809 *
1810 * R.inc(42); //=> 43
1811 */
1812 var inc = add(1);
1813
1814 /**
1815 * Inserts the supplied element into the list, at index `index`. _Note
1816 * that this is not destructive_: it returns a copy of the list with the changes.
1817 * <small>No lists have been harmed in the application of this function.</small>
1818 *
1819 * @func
1820 * @memberOf R
1821 * @category List
1822 * @sig Number -> a -> [a] -> [a]
1823 * @param {Number} index The position to insert the element
1824 * @param {*} elt The element to insert into the Array
1825 * @param {Array} list The list to insert into
1826 * @return {Array} A new Array with `elt` inserted at `index`.
1827 * @example
1828 *
1829 * R.insert(2, 'x', [1,2,3,4]); //=> [1,2,'x',3,4]
1830 */
1831 var insert = _curry3(function insert(idx, elt, list) {
1832 idx = idx < list.length && idx >= 0 ? idx : list.length;
1833 var result = _slice(list);
1834 result.splice(idx, 0, elt);
1835 return result;
1836 });
1837
1838 /**
1839 * Inserts the sub-list into the list, at index `index`. _Note that this
1840 * is not destructive_: it returns a copy of the list with the changes.
1841 * <small>No lists have been harmed in the application of this function.</small>
1842 *
1843 * @func
1844 * @memberOf R
1845 * @category List
1846 * @sig Number -> [a] -> [a] -> [a]
1847 * @param {Number} index The position to insert the sub-list
1848 * @param {Array} elts The sub-list to insert into the Array
1849 * @param {Array} list The list to insert the sub-list into
1850 * @return {Array} A new Array with `elts` inserted starting at `index`.
1851 * @example
1852 *
1853 * R.insertAll(2, ['x','y','z'], [1,2,3,4]); //=> [1,2,'x','y','z',3,4]
1854 */
1855 var insertAll = _curry3(function insertAll(idx, elts, list) {
1856 idx = idx < list.length && idx >= 0 ? idx : list.length;
1857 return _concat(_concat(_slice(list, 0, idx), elts), _slice(list, idx));
1858 });
1859
1860 /**
1861 * See if an object (`val`) is an instance of the supplied constructor.
1862 * This function will check up the inheritance chain, if any.
1863 *
1864 * @func
1865 * @memberOf R
1866 * @category Type
1867 * @sig (* -> {*}) -> a -> Boolean
1868 * @param {Object} ctor A constructor
1869 * @param {*} val The value to test
1870 * @return {Boolean}
1871 * @example
1872 *
1873 * R.is(Object, {}); //=> true
1874 * R.is(Number, 1); //=> true
1875 * R.is(Object, 1); //=> false
1876 * R.is(String, 's'); //=> true
1877 * R.is(String, new String('')); //=> true
1878 * R.is(Object, new String('')); //=> true
1879 * R.is(Object, 's'); //=> false
1880 * R.is(Number, {}); //=> false
1881 */
1882 var is = _curry2(function is(Ctor, val) {
1883 return val != null && val.constructor === Ctor || val instanceof Ctor;
1884 });
1885
1886 /**
1887 * Tests whether or not an object is similar to an array.
1888 *
1889 * @func
1890 * @memberOf R
1891 * @category Type
1892 * @category List
1893 * @sig * -> Boolean
1894 * @param {*} x The object to test.
1895 * @return {Boolean} `true` if `x` has a numeric length property and extreme indices defined; `false` otherwise.
1896 * @example
1897 *
1898 * R.isArrayLike([]); //=> true
1899 * R.isArrayLike(true); //=> false
1900 * R.isArrayLike({}); //=> false
1901 * R.isArrayLike({length: 10}); //=> false
1902 * R.isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true
1903 */
1904 var isArrayLike = _curry1(function isArrayLike(x) {
1905 if (_isArray(x)) {
1906 return true;
1907 }
1908 if (!x) {
1909 return false;
1910 }
1911 if (typeof x !== 'object') {
1912 return false;
1913 }
1914 if (x instanceof String) {
1915 return false;
1916 }
1917 if (x.nodeType === 1) {
1918 return !!x.length;
1919 }
1920 if (x.length === 0) {
1921 return true;
1922 }
1923 if (x.length > 0) {
1924 return x.hasOwnProperty(0) && x.hasOwnProperty(x.length - 1);
1925 }
1926 return false;
1927 });
1928
1929 /**
1930 * Reports whether the list has zero elements.
1931 *
1932 * @func
1933 * @memberOf R
1934 * @category Logic
1935 * @sig [a] -> Boolean
1936 * @param {Array} list
1937 * @return {Boolean}
1938 * @example
1939 *
1940 * R.isEmpty([1, 2, 3]); //=> false
1941 * R.isEmpty([]); //=> true
1942 * R.isEmpty(''); //=> true
1943 * R.isEmpty(null); //=> false
1944 * R.isEmpty(R.keys({})); //=> true
1945 * R.isEmpty({}); //=> false ({} does not have a length property)
1946 * R.isEmpty({length: 0}); //=> true
1947 */
1948 var isEmpty = _curry1(function isEmpty(list) {
1949 return Object(list).length === 0;
1950 });
1951
1952 /**
1953 * Checks if the input value is `null` or `undefined`.
1954 *
1955 * @func
1956 * @memberOf R
1957 * @category Type
1958 * @sig * -> Boolean
1959 * @param {*} x The value to test.
1960 * @return {Boolean} `true` if `x` is `undefined` or `null`, otherwise `false`.
1961 * @example
1962 *
1963 * R.isNil(null); //=> true
1964 * R.isNil(undefined); //=> true
1965 * R.isNil(0); //=> false
1966 * R.isNil([]); //=> false
1967 */
1968 var isNil = _curry1(function isNil(x) {
1969 return x == null;
1970 });
1971
1972 /**
1973 * Returns a list containing the names of all the enumerable own
1974 * properties of the supplied object.
1975 * Note that the order of the output array is not guaranteed to be
1976 * consistent across different JS platforms.
1977 *
1978 * @func
1979 * @memberOf R
1980 * @category Object
1981 * @sig {k: v} -> [k]
1982 * @param {Object} obj The object to extract properties from
1983 * @return {Array} An array of the object's own properties.
1984 * @example
1985 *
1986 * R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c']
1987 */
1988 // cover IE < 9 keys issues
1989 var keys = function () {
1990 // cover IE < 9 keys issues
1991 var hasEnumBug = !{ toString: null }.propertyIsEnumerable('toString');
1992 var nonEnumerableProps = [
1993 'constructor',
1994 'valueOf',
1995 'isPrototypeOf',
1996 'toString',
1997 'propertyIsEnumerable',
1998 'hasOwnProperty',
1999 'toLocaleString'
2000 ];
2001 var contains = function contains(list, item) {
2002 var idx = 0;
2003 while (idx < list.length) {
2004 if (list[idx] === item) {
2005 return true;
2006 }
2007 idx += 1;
2008 }
2009 return false;
2010 };
2011 return typeof Object.keys === 'function' ? _curry1(function keys(obj) {
2012 return Object(obj) !== obj ? [] : Object.keys(obj);
2013 }) : _curry1(function keys(obj) {
2014 if (Object(obj) !== obj) {
2015 return [];
2016 }
2017 var prop, ks = [], nIdx;
2018 for (prop in obj) {
2019 if (_has(prop, obj)) {
2020 ks[ks.length] = prop;
2021 }
2022 }
2023 if (hasEnumBug) {
2024 nIdx = nonEnumerableProps.length - 1;
2025 while (nIdx >= 0) {
2026 prop = nonEnumerableProps[nIdx];
2027 if (_has(prop, obj) && !contains(ks, prop)) {
2028 ks[ks.length] = prop;
2029 }
2030 nIdx -= 1;
2031 }
2032 }
2033 return ks;
2034 });
2035 }();
2036
2037 /**
2038 * Returns a list containing the names of all the
2039 * properties of the supplied object, including prototype properties.
2040 * Note that the order of the output array is not guaranteed to be
2041 * consistent across different JS platforms.
2042 *
2043 * @func
2044 * @memberOf R
2045 * @category Object
2046 * @sig {k: v} -> [k]
2047 * @param {Object} obj The object to extract properties from
2048 * @return {Array} An array of the object's own and prototype properties.
2049 * @example
2050 *
2051 * var F = function() { this.x = 'X'; };
2052 * F.prototype.y = 'Y';
2053 * var f = new F();
2054 * R.keysIn(f); //=> ['x', 'y']
2055 */
2056 var keysIn = _curry1(function keysIn(obj) {
2057 var prop, ks = [];
2058 for (prop in obj) {
2059 ks[ks.length] = prop;
2060 }
2061 return ks;
2062 });
2063
2064 /**
2065 * Returns the number of elements in the array by returning `list.length`.
2066 *
2067 * @func
2068 * @memberOf R
2069 * @category List
2070 * @sig [a] -> Number
2071 * @param {Array} list The array to inspect.
2072 * @return {Number} The length of the array.
2073 * @example
2074 *
2075 * R.length([]); //=> 0
2076 * R.length([1, 2, 3]); //=> 3
2077 */
2078 var length = _curry1(function length(list) {
2079 return list != null && is(Number, list.length) ? list.length : NaN;
2080 });
2081
2082 /**
2083 * Returns `true` if the first argument is less than the second;
2084 * `false` otherwise.
2085 *
2086 * @func
2087 * @memberOf R
2088 * @category Relation
2089 * @sig Ord a => a -> a -> Boolean
2090 * @param {*} a
2091 * @param {*} b
2092 * @return {Boolean}
2093 * @see R.gt
2094 * @example
2095 *
2096 * R.lt(2, 1); //=> false
2097 * R.lt(2, 2); //=> false
2098 * R.lt(2, 3); //=> true
2099 * R.lt('a', 'z'); //=> true
2100 * R.lt('z', 'a'); //=> false
2101 */
2102 var lt = _curry2(function lt(a, b) {
2103 return a < b;
2104 });
2105
2106 /**
2107 * Returns `true` if the first argument is less than or equal to the second;
2108 * `false` otherwise.
2109 *
2110 * @func
2111 * @memberOf R
2112 * @category Relation
2113 * @sig Ord a => a -> a -> Boolean
2114 * @param {Number} a
2115 * @param {Number} b
2116 * @return {Boolean}
2117 * @see R.gte
2118 * @example
2119 *
2120 * R.lte(2, 1); //=> false
2121 * R.lte(2, 2); //=> true
2122 * R.lte(2, 3); //=> true
2123 * R.lte('a', 'z'); //=> true
2124 * R.lte('z', 'a'); //=> false
2125 */
2126 var lte = _curry2(function lte(a, b) {
2127 return a <= b;
2128 });
2129
2130 /**
2131 * The mapAccum function behaves like a combination of map and reduce; it applies a
2132 * function to each element of a list, passing an accumulating parameter from left to
2133 * right, and returning a final value of this accumulator together with the new list.
2134 *
2135 * The iterator function receives two arguments, *acc* and *value*, and should return
2136 * a tuple *[acc, value]*.
2137 *
2138 * @func
2139 * @memberOf R
2140 * @category List
2141 * @sig (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
2142 * @param {Function} fn The function to be called on every element of the input `list`.
2143 * @param {*} acc The accumulator value.
2144 * @param {Array} list The list to iterate over.
2145 * @return {*} The final, accumulated value.
2146 * @example
2147 *
2148 * var digits = ['1', '2', '3', '4'];
2149 * var append = function(a, b) {
2150 * return [a + b, a + b];
2151 * }
2152 *
2153 * R.mapAccum(append, 0, digits); //=> ['01234', ['01', '012', '0123', '01234']]
2154 */
2155 var mapAccum = _curry3(function mapAccum(fn, acc, list) {
2156 var idx = 0, len = list.length, result = [], tuple = [acc];
2157 while (idx < len) {
2158 tuple = fn(tuple[0], list[idx]);
2159 result[idx] = tuple[1];
2160 idx += 1;
2161 }
2162 return [
2163 tuple[0],
2164 result
2165 ];
2166 });
2167
2168 /**
2169 * The mapAccumRight function behaves like a combination of map and reduce; it applies a
2170 * function to each element of a list, passing an accumulating parameter from right
2171 * to left, and returning a final value of this accumulator together with the new list.
2172 *
2173 * Similar to `mapAccum`, except moves through the input list from the right to the
2174 * left.
2175 *
2176 * The iterator function receives two arguments, *acc* and *value*, and should return
2177 * a tuple *[acc, value]*.
2178 *
2179 * @func
2180 * @memberOf R
2181 * @category List
2182 * @sig (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
2183 * @param {Function} fn The function to be called on every element of the input `list`.
2184 * @param {*} acc The accumulator value.
2185 * @param {Array} list The list to iterate over.
2186 * @return {*} The final, accumulated value.
2187 * @example
2188 *
2189 * var digits = ['1', '2', '3', '4'];
2190 * var append = function(a, b) {
2191 * return [a + b, a + b];
2192 * }
2193 *
2194 * R.mapAccumRight(append, 0, digits); //=> ['04321', ['04321', '0432', '043', '04']]
2195 */
2196 var mapAccumRight = _curry3(function mapAccumRight(fn, acc, list) {
2197 var idx = list.length - 1, result = [], tuple = [acc];
2198 while (idx >= 0) {
2199 tuple = fn(tuple[0], list[idx]);
2200 result[idx] = tuple[1];
2201 idx -= 1;
2202 }
2203 return [
2204 tuple[0],
2205 result
2206 ];
2207 });
2208
2209 /**
2210 * Tests a regular expression against a String. Note that this function
2211 * will return an empty array when there are no matches. This differs
2212 * from [`String.prototype.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
2213 * which returns `null` when there are no matches.
2214 *
2215 * @func
2216 * @memberOf R
2217 * @see R.test
2218 * @category String
2219 * @sig RegExp -> String -> [String | Undefined]
2220 * @param {RegExp} rx A regular expression.
2221 * @param {String} str The string to match against
2222 * @return {Array} The list of matches or empty array.
2223 * @example
2224 *
2225 * R.match(/([a-z]a)/g, 'bananas'); //=> ['ba', 'na', 'na']
2226 * R.match(/a/, 'b'); //=> []
2227 * R.match(/a/, null); //=> TypeError: null does not have a method named "match"
2228 */
2229 var match = _curry2(function match(rx, str) {
2230 return str.match(rx) || [];
2231 });
2232
2233 /**
2234 * mathMod behaves like the modulo operator should mathematically, unlike the `%`
2235 * operator (and by extension, R.modulo). So while "-17 % 5" is -2,
2236 * mathMod(-17, 5) is 3. mathMod requires Integer arguments, and returns NaN
2237 * when the modulus is zero or negative.
2238 *
2239 * @func
2240 * @memberOf R
2241 * @category Math
2242 * @sig Number -> Number -> Number
2243 * @param {Number} m The dividend.
2244 * @param {Number} p the modulus.
2245 * @return {Number} The result of `b mod a`.
2246 * @example
2247 *
2248 * R.mathMod(-17, 5); //=> 3
2249 * R.mathMod(17, 5); //=> 2
2250 * R.mathMod(17, -5); //=> NaN
2251 * R.mathMod(17, 0); //=> NaN
2252 * R.mathMod(17.2, 5); //=> NaN
2253 * R.mathMod(17, 5.3); //=> NaN
2254 *
2255 * var clock = R.mathMod(R.__, 12);
2256 * clock(15); //=> 3
2257 * clock(24); //=> 0
2258 *
2259 * var seventeenMod = R.mathMod(17);
2260 * seventeenMod(3); //=> 2
2261 * seventeenMod(4); //=> 1
2262 * seventeenMod(10); //=> 7
2263 */
2264 var mathMod = _curry2(function mathMod(m, p) {
2265 if (!_isInteger(m)) {
2266 return NaN;
2267 }
2268 if (!_isInteger(p) || p < 1) {
2269 return NaN;
2270 }
2271 return (m % p + p) % p;
2272 });
2273
2274 /**
2275 * Returns the larger of its two arguments.
2276 *
2277 * @func
2278 * @memberOf R
2279 * @category Relation
2280 * @sig Ord a => a -> a -> a
2281 * @param {*} a
2282 * @param {*} b
2283 * @return {*}
2284 * @see R.maxBy, R.min
2285 * @example
2286 *
2287 * R.max(789, 123); //=> 789
2288 * R.max('a', 'b'); //=> 'b'
2289 */
2290 var max = _curry2(function max(a, b) {
2291 return b > a ? b : a;
2292 });
2293
2294 /**
2295 * Takes a function and two values, and returns whichever value produces
2296 * the larger result when passed to the provided function.
2297 *
2298 * @func
2299 * @memberOf R
2300 * @category Relation
2301 * @sig Ord b => (a -> b) -> a -> a -> a
2302 * @param {Function} f
2303 * @param {*} a
2304 * @param {*} b
2305 * @return {*}
2306 * @see R.max, R.minBy
2307 * @example
2308 *
2309 * R.maxBy(function(n) { return n * n; }, -3, 2); //=> -3
2310 */
2311 var maxBy = _curry3(function maxBy(f, a, b) {
2312 return f(b) > f(a) ? b : a;
2313 });
2314
2315 /**
2316 * Create a new object with the own properties of `a`
2317 * merged with the own properties of object `b`.
2318 *
2319 * @func
2320 * @memberOf R
2321 * @category Object
2322 * @sig {k: v} -> {k: v} -> {k: v}
2323 * @param {Object} a
2324 * @param {Object} b
2325 * @return {Object}
2326 * @example
2327 *
2328 * R.merge({ 'name': 'fred', 'age': 10 }, { 'age': 40 });
2329 * //=> { 'name': 'fred', 'age': 40 }
2330 *
2331 * var resetToDefault = R.merge(R.__, {x: 0});
2332 * resetToDefault({x: 5, y: 2}); //=> {x: 0, y: 2}
2333 */
2334 var merge = _curry2(function merge(a, b) {
2335 var result = {};
2336 var ks = keys(a);
2337 var idx = 0;
2338 while (idx < ks.length) {
2339 result[ks[idx]] = a[ks[idx]];
2340 idx += 1;
2341 }
2342 ks = keys(b);
2343 idx = 0;
2344 while (idx < ks.length) {
2345 result[ks[idx]] = b[ks[idx]];
2346 idx += 1;
2347 }
2348 return result;
2349 });
2350
2351 /**
2352 * Returns the smaller of its two arguments.
2353 *
2354 * @func
2355 * @memberOf R
2356 * @category Relation
2357 * @sig Ord a => a -> a -> a
2358 * @param {*} a
2359 * @param {*} b
2360 * @return {*}
2361 * @see R.minBy, R.max
2362 * @example
2363 *
2364 * R.min(789, 123); //=> 123
2365 * R.min('a', 'b'); //=> 'a'
2366 */
2367 var min = _curry2(function min(a, b) {
2368 return b < a ? b : a;
2369 });
2370
2371 /**
2372 * Takes a function and two values, and returns whichever value produces
2373 * the smaller result when passed to the provided function.
2374 *
2375 * @func
2376 * @memberOf R
2377 * @category Relation
2378 * @sig Ord b => (a -> b) -> a -> a -> a
2379 * @param {Function} f
2380 * @param {*} a
2381 * @param {*} b
2382 * @return {*}
2383 * @see R.min, R.maxBy
2384 * @example
2385 *
2386 * R.minBy(function(n) { return n * n; }, -3, 2); //=> 2
2387 */
2388 var minBy = _curry3(function minBy(f, a, b) {
2389 return f(b) < f(a) ? b : a;
2390 });
2391
2392 /**
2393 * Divides the second parameter by the first and returns the remainder.
2394 * Note that this functions preserves the JavaScript-style behavior for
2395 * modulo. For mathematical modulo see `mathMod`
2396 *
2397 * @func
2398 * @memberOf R
2399 * @category Math
2400 * @sig Number -> Number -> Number
2401 * @param {Number} a The value to the divide.
2402 * @param {Number} b The pseudo-modulus
2403 * @return {Number} The result of `b % a`.
2404 * @see R.mathMod
2405 * @example
2406 *
2407 * R.modulo(17, 3); //=> 2
2408 * // JS behavior:
2409 * R.modulo(-17, 3); //=> -2
2410 * R.modulo(17, -3); //=> 2
2411 *
2412 * var isOdd = R.modulo(R.__, 2);
2413 * isOdd(42); //=> 0
2414 * isOdd(21); //=> 1
2415 */
2416 var modulo = _curry2(function modulo(a, b) {
2417 return a % b;
2418 });
2419
2420 /**
2421 * Multiplies two numbers. Equivalent to `a * b` but curried.
2422 *
2423 * @func
2424 * @memberOf R
2425 * @category Math
2426 * @sig Number -> Number -> Number
2427 * @param {Number} a The first value.
2428 * @param {Number} b The second value.
2429 * @return {Number} The result of `a * b`.
2430 * @see R.divide
2431 * @example
2432 *
2433 * var double = R.multiply(2);
2434 * var triple = R.multiply(3);
2435 * double(3); //=> 6
2436 * triple(4); //=> 12
2437 * R.multiply(2, 5); //=> 10
2438 */
2439 var multiply = _curry2(function multiply(a, b) {
2440 return a * b;
2441 });
2442
2443 /**
2444 * Wraps a function of any arity (including nullary) in a function that accepts exactly `n`
2445 * parameters. Any extraneous parameters will not be passed to the supplied function.
2446 *
2447 * @func
2448 * @memberOf R
2449 * @category Function
2450 * @sig Number -> (* -> a) -> (* -> a)
2451 * @param {Number} n The desired arity of the new function.
2452 * @param {Function} fn The function to wrap.
2453 * @return {Function} A new function wrapping `fn`. The new function is guaranteed to be of
2454 * arity `n`.
2455 * @example
2456 *
2457 * var takesTwoArgs = function(a, b) {
2458 * return [a, b];
2459 * };
2460 * takesTwoArgs.length; //=> 2
2461 * takesTwoArgs(1, 2); //=> [1, 2]
2462 *
2463 * var takesOneArg = R.nAry(1, takesTwoArgs);
2464 * takesOneArg.length; //=> 1
2465 * // Only `n` arguments are passed to the wrapped function
2466 * takesOneArg(1, 2); //=> [1, undefined]
2467 */
2468 var nAry = _curry2(function nAry(n, fn) {
2469 switch (n) {
2470 case 0:
2471 return function () {
2472 return fn.call(this);
2473 };
2474 case 1:
2475 return function (a0) {
2476 return fn.call(this, a0);
2477 };
2478 case 2:
2479 return function (a0, a1) {
2480 return fn.call(this, a0, a1);
2481 };
2482 case 3:
2483 return function (a0, a1, a2) {
2484 return fn.call(this, a0, a1, a2);
2485 };
2486 case 4:
2487 return function (a0, a1, a2, a3) {
2488 return fn.call(this, a0, a1, a2, a3);
2489 };
2490 case 5:
2491 return function (a0, a1, a2, a3, a4) {
2492 return fn.call(this, a0, a1, a2, a3, a4);
2493 };
2494 case 6:
2495 return function (a0, a1, a2, a3, a4, a5) {
2496 return fn.call(this, a0, a1, a2, a3, a4, a5);
2497 };
2498 case 7:
2499 return function (a0, a1, a2, a3, a4, a5, a6) {
2500 return fn.call(this, a0, a1, a2, a3, a4, a5, a6);
2501 };
2502 case 8:
2503 return function (a0, a1, a2, a3, a4, a5, a6, a7) {
2504 return fn.call(this, a0, a1, a2, a3, a4, a5, a6, a7);
2505 };
2506 case 9:
2507 return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) {
2508 return fn.call(this, a0, a1, a2, a3, a4, a5, a6, a7, a8);
2509 };
2510 case 10:
2511 return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
2512 return fn.call(this, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
2513 };
2514 default:
2515 throw new Error('First argument to nAry must be a non-negative integer no greater than ten');
2516 }
2517 });
2518
2519 /**
2520 * Negates its argument.
2521 *
2522 * @func
2523 * @memberOf R
2524 * @category Math
2525 * @sig Number -> Number
2526 * @param {Number} n
2527 * @return {Number}
2528 * @example
2529 *
2530 * R.negate(42); //=> -42
2531 */
2532 var negate = _curry1(function negate(n) {
2533 return -n;
2534 });
2535
2536 /**
2537 * A function that returns the `!` of its argument. It will return `true` when
2538 * passed false-y value, and `false` when passed a truth-y one.
2539 *
2540 * @func
2541 * @memberOf R
2542 * @category Logic
2543 * @sig * -> Boolean
2544 * @param {*} a any value
2545 * @return {Boolean} the logical inverse of passed argument.
2546 * @see R.complement
2547 * @example
2548 *
2549 * R.not(true); //=> false
2550 * R.not(false); //=> true
2551 * R.not(0); => true
2552 * R.not(1); => false
2553 */
2554 var not = _curry1(function not(a) {
2555 return !a;
2556 });
2557
2558 /**
2559 * Returns the nth element of the given list or string.
2560 * If n is negative the element at index length + n is returned.
2561 *
2562 * @func
2563 * @memberOf R
2564 * @category List
2565 * @sig Number -> [a] -> a | Undefined
2566 * @sig Number -> String -> String
2567 * @param {Number} offset
2568 * @param {*} list
2569 * @return {*}
2570 * @example
2571 *
2572 * var list = ['foo', 'bar', 'baz', 'quux'];
2573 * R.nth(1, list); //=> 'bar'
2574 * R.nth(-1, list); //=> 'quux'
2575 * R.nth(-99, list); //=> undefined
2576 *
2577 * R.nth('abc', 2); //=> 'c'
2578 * R.nth('abc', 3); //=> ''
2579 */
2580 var nth = _curry2(function nth(offset, list) {
2581 var idx = offset < 0 ? list.length + offset : offset;
2582 return _isString(list) ? list.charAt(idx) : list[idx];
2583 });
2584
2585 /**
2586 * Returns a function which returns its nth argument.
2587 *
2588 * @func
2589 * @memberOf R
2590 * @category Function
2591 * @sig Number -> *... -> *
2592 * @param {Number} n
2593 * @return {Function}
2594 * @example
2595 *
2596 * R.nthArg(1)('a', 'b', 'c'); //=> 'b'
2597 * R.nthArg(-1)('a', 'b', 'c'); //=> 'c'
2598 */
2599 var nthArg = _curry1(function nthArg(n) {
2600 return function () {
2601 return nth(n, arguments);
2602 };
2603 });
2604
2605 /**
2606 * Returns the nth character of the given string.
2607 *
2608 * @func
2609 * @memberOf R
2610 * @category String
2611 * @sig Number -> String -> String
2612 * @param {Number} n
2613 * @param {String} str
2614 * @return {String}
2615 * @deprecated since v0.16.0
2616 * @example
2617 *
2618 * R.nthChar(2, 'Ramda'); //=> 'm'
2619 * R.nthChar(-2, 'Ramda'); //=> 'd'
2620 */
2621 var nthChar = _curry2(function nthChar(n, str) {
2622 return str.charAt(n < 0 ? str.length + n : n);
2623 });
2624
2625 /**
2626 * Returns the character code of the nth character of the given string.
2627 *
2628 * @func
2629 * @memberOf R
2630 * @category String
2631 * @sig Number -> String -> Number
2632 * @param {Number} n
2633 * @param {String} str
2634 * @return {Number}
2635 * @deprecated since v0.16.0
2636 * @example
2637 *
2638 * R.nthCharCode(2, 'Ramda'); //=> 'm'.charCodeAt(0)
2639 * R.nthCharCode(-2, 'Ramda'); //=> 'd'.charCodeAt(0)
2640 */
2641 var nthCharCode = _curry2(function nthCharCode(n, str) {
2642 return str.charCodeAt(n < 0 ? str.length + n : n);
2643 });
2644
2645 /**
2646 * Returns a singleton array containing the value provided.
2647 *
2648 * Note this `of` is different from the ES6 `of`; See
2649 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of
2650 *
2651 * @func
2652 * @memberOf R
2653 * @category Function
2654 * @sig a -> [a]
2655 * @param {*} x any value
2656 * @return {Array} An array wrapping `x`.
2657 * @example
2658 *
2659 * R.of(null); //=> [null]
2660 * R.of([42]); //=> [[42]]
2661 */
2662 var of = _curry1(function of(x) {
2663 return [x];
2664 });
2665
2666 /**
2667 * Accepts a function `fn` and returns a function that guards invocation of `fn` such that
2668 * `fn` can only ever be called once, no matter how many times the returned function is
2669 * invoked.
2670 *
2671 * @func
2672 * @memberOf R
2673 * @category Function
2674 * @sig (a... -> b) -> (a... -> b)
2675 * @param {Function} fn The function to wrap in a call-only-once wrapper.
2676 * @return {Function} The wrapped function.
2677 * @example
2678 *
2679 * var addOneOnce = R.once(function(x){ return x + 1; });
2680 * addOneOnce(10); //=> 11
2681 * addOneOnce(addOneOnce(50)); //=> 11
2682 */
2683 var once = _curry1(function once(fn) {
2684 var called = false, result;
2685 return function () {
2686 if (called) {
2687 return result;
2688 }
2689 called = true;
2690 result = fn.apply(this, arguments);
2691 return result;
2692 };
2693 });
2694
2695 /**
2696 * Returns the result of "setting" the portion of the given data structure
2697 * focused by the given lens to the given value.
2698 *
2699 * @func
2700 * @memberOf R
2701 * @category Object
2702 * @typedef Lens s a = Functor f => (a -> f a) -> s -> f s
2703 * @sig Lens s a -> (a -> a) -> s -> s
2704 * @param {Lens} lens
2705 * @param {*} v
2706 * @param {*} x
2707 * @return {*}
2708 * @see R.prop, R.lensIndex, R.lensProp
2709 * @example
2710 *
2711 * var headLens = R.lensIndex(0);
2712 *
2713 * R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']); //=> ['FOO', 'bar', 'baz']
2714 */
2715 var over = function () {
2716 var Identity = function (x) {
2717 return {
2718 value: x,
2719 map: function (f) {
2720 return Identity(f(x));
2721 }
2722 };
2723 };
2724 return _curry3(function over(lens, f, x) {
2725 return lens(function (y) {
2726 return Identity(f(y));
2727 })(x).value;
2728 });
2729 }();
2730
2731 /**
2732 * Retrieve the value at a given path.
2733 *
2734 * @func
2735 * @memberOf R
2736 * @category Object
2737 * @sig [String] -> {k: v} -> v | Undefined
2738 * @param {Array} path The path to use.
2739 * @return {*} The data at `path`.
2740 * @example
2741 *
2742 * R.path(['a', 'b'], {a: {b: 2}}); //=> 2
2743 * R.path(['a', 'b'], {c: {b: 2}}); //=> undefined
2744 */
2745 var path = _curry2(function path(paths, obj) {
2746 if (obj == null) {
2747 return;
2748 } else {
2749 var val = obj;
2750 for (var idx = 0, len = paths.length; idx < len && val != null; idx += 1) {
2751 val = val[paths[idx]];
2752 }
2753 return val;
2754 }
2755 });
2756
2757 /**
2758 * Returns a partial copy of an object containing only the keys specified. If the key does not exist, the
2759 * property is ignored.
2760 *
2761 * @func
2762 * @memberOf R
2763 * @category Object
2764 * @sig [k] -> {k: v} -> {k: v}
2765 * @param {Array} names an array of String property names to copy onto a new object
2766 * @param {Object} obj The object to copy from
2767 * @return {Object} A new object with only properties from `names` on it.
2768 * @see R.omit
2769 * @example
2770 *
2771 * R.pick(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
2772 * R.pick(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1}
2773 */
2774 var pick = _curry2(function pick(names, obj) {
2775 var result = {};
2776 var idx = 0;
2777 while (idx < names.length) {
2778 if (names[idx] in obj) {
2779 result[names[idx]] = obj[names[idx]];
2780 }
2781 idx += 1;
2782 }
2783 return result;
2784 });
2785
2786 /**
2787 * Similar to `pick` except that this one includes a `key: undefined` pair for properties that don't exist.
2788 *
2789 * @func
2790 * @memberOf R
2791 * @category Object
2792 * @sig [k] -> {k: v} -> {k: v}
2793 * @param {Array} names an array of String property names to copy onto a new object
2794 * @param {Object} obj The object to copy from
2795 * @return {Object} A new object with only properties from `names` on it.
2796 * @see R.pick
2797 * @example
2798 *
2799 * R.pickAll(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
2800 * R.pickAll(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, e: undefined, f: undefined}
2801 */
2802 var pickAll = _curry2(function pickAll(names, obj) {
2803 var result = {};
2804 var idx = 0;
2805 var len = names.length;
2806 while (idx < len) {
2807 var name = names[idx];
2808 result[name] = obj[name];
2809 idx += 1;
2810 }
2811 return result;
2812 });
2813
2814 /**
2815 * Returns a partial copy of an object containing only the keys that
2816 * satisfy the supplied predicate.
2817 *
2818 * @func
2819 * @memberOf R
2820 * @category Object
2821 * @sig (v, k -> Boolean) -> {k: v} -> {k: v}
2822 * @param {Function} pred A predicate to determine whether or not a key
2823 * should be included on the output object.
2824 * @param {Object} obj The object to copy from
2825 * @return {Object} A new object with only properties that satisfy `pred`
2826 * on it.
2827 * @see R.pick
2828 * @example
2829 *
2830 * var isUpperCase = function(val, key) { return key.toUpperCase() === key; }
2831 * R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4}
2832 */
2833 var pickBy = _curry2(function pickBy(test, obj) {
2834 var result = {};
2835 for (var prop in obj) {
2836 if (test(obj[prop], prop, obj)) {
2837 result[prop] = obj[prop];
2838 }
2839 }
2840 return result;
2841 });
2842
2843 /**
2844 * Returns a new list with the given element at the front, followed by the contents of the
2845 * list.
2846 *
2847 * @func
2848 * @memberOf R
2849 * @category List
2850 * @sig a -> [a] -> [a]
2851 * @param {*} el The item to add to the head of the output list.
2852 * @param {Array} list The array to add to the tail of the output list.
2853 * @return {Array} A new array.
2854 * @see R.append
2855 * @example
2856 *
2857 * R.prepend('fee', ['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum']
2858 */
2859 var prepend = _curry2(function prepend(el, list) {
2860 return _concat([el], list);
2861 });
2862
2863 /**
2864 * Returns a function that when supplied an object returns the indicated property of that object, if it exists.
2865 *
2866 * @func
2867 * @memberOf R
2868 * @category Object
2869 * @sig s -> {s: a} -> a | Undefined
2870 * @param {String} p The property name
2871 * @param {Object} obj The object to query
2872 * @return {*} The value at `obj.p`.
2873 * @example
2874 *
2875 * R.prop('x', {x: 100}); //=> 100
2876 * R.prop('x', {}); //=> undefined
2877 */
2878 var prop = _curry2(function prop(p, obj) {
2879 return obj[p];
2880 });
2881
2882 /**
2883 * If the given, non-null object has an own property with the specified name,
2884 * returns the value of that property.
2885 * Otherwise returns the provided default value.
2886 *
2887 * @func
2888 * @memberOf R
2889 * @category Object
2890 * @sig a -> String -> Object -> a
2891 * @param {*} val The default value.
2892 * @param {String} p The name of the property to return.
2893 * @param {Object} obj The object to query.
2894 * @return {*} The value of given property of the supplied object or the default value.
2895 * @example
2896 *
2897 * var alice = {
2898 * name: 'ALICE',
2899 * age: 101
2900 * };
2901 * var favorite = R.prop('favoriteLibrary');
2902 * var favoriteWithDefault = R.propOr('Ramda', 'favoriteLibrary');
2903 *
2904 * favorite(alice); //=> undefined
2905 * favoriteWithDefault(alice); //=> 'Ramda'
2906 */
2907 var propOr = _curry3(function propOr(val, p, obj) {
2908 return obj != null && _has(p, obj) ? obj[p] : val;
2909 });
2910
2911 /**
2912 * Returns `true` if the specified object property satisfies the given
2913 * predicate; `false` otherwise.
2914 *
2915 * @func
2916 * @memberOf R
2917 * @category Logic
2918 * @sig (a -> Boolean) -> String -> {String: a} -> Boolean
2919 * @param {Function} pred
2920 * @param {String} name
2921 * @param {*} obj
2922 * @return {Boolean}
2923 * @see R.propEq
2924 * @see R.propIs
2925 * @example
2926 *
2927 * R.propSatisfies(x => x > 0, 'x', {x: 1, y: 2}); //=> true
2928 */
2929 var propSatisfies = _curry3(function propSatisfies(pred, name, obj) {
2930 return pred(obj[name]);
2931 });
2932
2933 /**
2934 * Acts as multiple `prop`: array of keys in, array of values out. Preserves order.
2935 *
2936 * @func
2937 * @memberOf R
2938 * @category Object
2939 * @sig [k] -> {k: v} -> [v]
2940 * @param {Array} ps The property names to fetch
2941 * @param {Object} obj The object to query
2942 * @return {Array} The corresponding values or partially applied function.
2943 * @example
2944 *
2945 * R.props(['x', 'y'], {x: 1, y: 2}); //=> [1, 2]
2946 * R.props(['c', 'a', 'b'], {b: 2, a: 1}); //=> [undefined, 1, 2]
2947 *
2948 * var fullName = R.compose(R.join(' '), R.props(['first', 'last']));
2949 * fullName({last: 'Bullet-Tooth', age: 33, first: 'Tony'}); //=> 'Tony Bullet-Tooth'
2950 */
2951 var props = _curry2(function props(ps, obj) {
2952 var len = ps.length;
2953 var out = [];
2954 var idx = 0;
2955 while (idx < len) {
2956 out[idx] = obj[ps[idx]];
2957 idx += 1;
2958 }
2959 return out;
2960 });
2961
2962 /**
2963 * Returns a list of numbers from `from` (inclusive) to `to`
2964 * (exclusive).
2965 *
2966 * @func
2967 * @memberOf R
2968 * @category List
2969 * @sig Number -> Number -> [Number]
2970 * @param {Number} from The first number in the list.
2971 * @param {Number} to One more than the last number in the list.
2972 * @return {Array} The list of numbers in tthe set `[a, b)`.
2973 * @example
2974 *
2975 * R.range(1, 5); //=> [1, 2, 3, 4]
2976 * R.range(50, 53); //=> [50, 51, 52]
2977 */
2978 var range = _curry2(function range(from, to) {
2979 if (!(_isNumber(from) && _isNumber(to))) {
2980 throw new TypeError('Both arguments to range must be numbers');
2981 }
2982 var result = [];
2983 var n = from;
2984 while (n < to) {
2985 result.push(n);
2986 n += 1;
2987 }
2988 return result;
2989 });
2990
2991 /**
2992 * Returns a single item by iterating through the list, successively calling the iterator
2993 * function and passing it an accumulator value and the current value from the array, and
2994 * then passing the result to the next call.
2995 *
2996 * Similar to `reduce`, except moves through the input list from the right to the left.
2997 *
2998 * The iterator function receives two values: *(acc, value)*
2999 *
3000 * Note: `R.reduceRight` does not skip deleted or unassigned indices (sparse arrays), unlike
3001 * the native `Array.prototype.reduce` method. For more details on this behavior, see:
3002 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight#Description
3003 *
3004 * @func
3005 * @memberOf R
3006 * @category List
3007 * @sig (a,b -> a) -> a -> [b] -> a
3008 * @param {Function} fn The iterator function. Receives two values, the accumulator and the
3009 * current element from the array.
3010 * @param {*} acc The accumulator value.
3011 * @param {Array} list The list to iterate over.
3012 * @return {*} The final, accumulated value.
3013 * @example
3014 *
3015 * var pairs = [ ['a', 1], ['b', 2], ['c', 3] ];
3016 * var flattenPairs = function(acc, pair) {
3017 * return acc.concat(pair);
3018 * };
3019 *
3020 * R.reduceRight(flattenPairs, [], pairs); //=> [ 'c', 3, 'b', 2, 'a', 1 ]
3021 */
3022 var reduceRight = _curry3(function reduceRight(fn, acc, list) {
3023 var idx = list.length - 1;
3024 while (idx >= 0) {
3025 acc = fn(acc, list[idx]);
3026 idx -= 1;
3027 }
3028 return acc;
3029 });
3030
3031 /**
3032 * Returns a value wrapped to indicate that it is the final value of the
3033 * reduce and transduce functions. The returned value
3034 * should be considered a black box: the internal structure is not
3035 * guaranteed to be stable.
3036 *
3037 * Note: this optimization is unavailable to functions not explicitly listed
3038 * above. For instance, it is not currently supported by reduceIndexed,
3039 * reduceRight, or reduceRightIndexed.
3040 *
3041 * @func
3042 * @memberOf R
3043 * @category List
3044 * @see R.reduce, R.transduce
3045 * @sig a -> *
3046 * @param {*} x The final value of the reduce.
3047 * @return {*} The wrapped value.
3048 * @example
3049 *
3050 * R.reduce(
3051 * R.pipe(R.add, R.ifElse(R.lte(10), R.reduced, R.identity)),
3052 * 0,
3053 * [1, 2, 3, 4, 5]) // 10
3054 */
3055 var reduced = _curry1(_reduced);
3056
3057 /**
3058 * Removes the sub-list of `list` starting at index `start` and containing
3059 * `count` elements. _Note that this is not destructive_: it returns a
3060 * copy of the list with the changes.
3061 * <small>No lists have been harmed in the application of this function.</small>
3062 *
3063 * @func
3064 * @memberOf R
3065 * @category List
3066 * @sig Number -> Number -> [a] -> [a]
3067 * @param {Number} start The position to start removing elements
3068 * @param {Number} count The number of elements to remove
3069 * @param {Array} list The list to remove from
3070 * @return {Array} A new Array with `count` elements from `start` removed.
3071 * @example
3072 *
3073 * R.remove(2, 3, [1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8]
3074 */
3075 var remove = _curry3(function remove(start, count, list) {
3076 return _concat(_slice(list, 0, Math.min(start, list.length)), _slice(list, Math.min(list.length, start + count)));
3077 });
3078
3079 /**
3080 * Replace a substring or regex match in a string with a replacement.
3081 *
3082 * @func
3083 * @memberOf R
3084 * @category String
3085 * @sig RegExp|String -> String -> String -> String
3086 * @param {RegExp|String} pattern A regular expression or a substring to match.
3087 * @param {String} replacement The string to replace the matches with.
3088 * @param {String} str The String to do the search and replacement in.
3089 * @return {String} The result.
3090 * @example
3091 *
3092 * R.replace('foo', 'bar', 'foo foo foo'); //=> 'bar foo foo'
3093 * R.replace(/foo/, 'bar', 'foo foo foo'); //=> 'bar foo foo'
3094 *
3095 * // Use the "g" (global) flag to replace all occurrences:
3096 * R.replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar'
3097 */
3098 var replace = _curry3(function replace(regex, replacement, str) {
3099 return str.replace(regex, replacement);
3100 });
3101
3102 /**
3103 * Returns a new list with the same elements as the original list, just
3104 * in the reverse order.
3105 *
3106 * @func
3107 * @memberOf R
3108 * @category List
3109 * @sig [a] -> [a]
3110 * @param {Array} list The list to reverse.
3111 * @return {Array} A copy of the list in reverse order.
3112 * @example
3113 *
3114 * R.reverse([1, 2, 3]); //=> [3, 2, 1]
3115 * R.reverse([1, 2]); //=> [2, 1]
3116 * R.reverse([1]); //=> [1]
3117 * R.reverse([]); //=> []
3118 */
3119 var reverse = _curry1(function reverse(list) {
3120 return _slice(list).reverse();
3121 });
3122
3123 /**
3124 * Scan is similar to reduce, but returns a list of successively reduced values from the left
3125 *
3126 * @func
3127 * @memberOf R
3128 * @category List
3129 * @sig (a,b -> a) -> a -> [b] -> [a]
3130 * @param {Function} fn The iterator function. Receives two values, the accumulator and the
3131 * current element from the array
3132 * @param {*} acc The accumulator value.
3133 * @param {Array} list The list to iterate over.
3134 * @return {Array} A list of all intermediately reduced values.
3135 * @example
3136 *
3137 * var numbers = [1, 2, 3, 4];
3138 * var factorials = R.scan(R.multiply, 1, numbers); //=> [1, 1, 2, 6, 24]
3139 */
3140 var scan = _curry3(function scan(fn, acc, list) {
3141 var idx = 0, len = list.length, result = [acc];
3142 while (idx < len) {
3143 acc = fn(acc, list[idx]);
3144 result[idx + 1] = acc;
3145 idx += 1;
3146 }
3147 return result;
3148 });
3149
3150 /**
3151 * Returns the result of "setting" the portion of the given data structure
3152 * focused by the given lens to the given value.
3153 *
3154 * @func
3155 * @memberOf R
3156 * @category Object
3157 * @typedef Lens s a = Functor f => (a -> f a) -> s -> f s
3158 * @sig Lens s a -> a -> s -> s
3159 * @param {Lens} lens
3160 * @param {*} v
3161 * @param {*} x
3162 * @return {*}
3163 * @see R.prop, R.lensIndex, R.lensProp
3164 * @example
3165 *
3166 * var xLens = R.lensProp('x');
3167 *
3168 * R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2}
3169 * R.set(xLens, 8, {x: 1, y: 2}); //=> {x: 8, y: 2}
3170 */
3171 var set = _curry3(function set(lens, v, x) {
3172 return over(lens, always(v), x);
3173 });
3174
3175 /**
3176 * Returns a copy of the list, sorted according to the comparator function, which should accept two values at a
3177 * time and return a negative number if the first value is smaller, a positive number if it's larger, and zero
3178 * if they are equal. Please note that this is a **copy** of the list. It does not modify the original.
3179 *
3180 * @func
3181 * @memberOf R
3182 * @category List
3183 * @sig (a,a -> Number) -> [a] -> [a]
3184 * @param {Function} comparator A sorting function :: a -> b -> Int
3185 * @param {Array} list The list to sort
3186 * @return {Array} a new array with its elements sorted by the comparator function.
3187 * @example
3188 *
3189 * var diff = function(a, b) { return a - b; };
3190 * R.sort(diff, [4,2,7,5]); //=> [2, 4, 5, 7]
3191 */
3192 var sort = _curry2(function sort(comparator, list) {
3193 return _slice(list).sort(comparator);
3194 });
3195
3196 /**
3197 * Sorts the list according to the supplied function.
3198 *
3199 * @func
3200 * @memberOf R
3201 * @category Relation
3202 * @sig Ord b => (a -> b) -> [a] -> [a]
3203 * @param {Function} fn
3204 * @param {Array} list The list to sort.
3205 * @return {Array} A new list sorted by the keys generated by `fn`.
3206 * @example
3207 *
3208 * var sortByFirstItem = R.sortBy(prop(0));
3209 * var sortByNameCaseInsensitive = R.sortBy(R.compose(R.toLower, R.prop('name')));
3210 * var pairs = [[-1, 1], [-2, 2], [-3, 3]];
3211 * sortByFirstItem(pairs); //=> [[-3, 3], [-2, 2], [-1, 1]]
3212 * var alice = {
3213 * name: 'ALICE',
3214 * age: 101
3215 * };
3216 * var bob = {
3217 * name: 'Bob',
3218 * age: -10
3219 * };
3220 * var clara = {
3221 * name: 'clara',
3222 * age: 314.159
3223 * };
3224 * var people = [clara, bob, alice];
3225 * sortByNameCaseInsensitive(people); //=> [alice, bob, clara]
3226 */
3227 var sortBy = _curry2(function sortBy(fn, list) {
3228 return _slice(list).sort(function (a, b) {
3229 var aa = fn(a);
3230 var bb = fn(b);
3231 return aa < bb ? -1 : aa > bb ? 1 : 0;
3232 });
3233 });
3234
3235 /**
3236 * Subtracts two numbers. Equivalent to `a - b` but curried.
3237 *
3238 * @func
3239 * @memberOf R
3240 * @category Math
3241 * @sig Number -> Number -> Number
3242 * @param {Number} a The first value.
3243 * @param {Number} b The second value.
3244 * @return {Number} The result of `a - b`.
3245 * @see R.add
3246 * @example
3247 *
3248 * R.subtract(10, 8); //=> 2
3249 *
3250 * var minus5 = R.subtract(R.__, 5);
3251 * minus5(17); //=> 12
3252 *
3253 * var complementaryAngle = R.subtract(90);
3254 * complementaryAngle(30); //=> 60
3255 * complementaryAngle(72); //=> 18
3256 */
3257 var subtract = _curry2(function subtract(a, b) {
3258 return a - b;
3259 });
3260
3261 /**
3262 * Returns a new list containing the last `n` elements of a given list, passing each value
3263 * to the supplied predicate function, and terminating when the predicate function returns
3264 * `false`. Excludes the element that caused the predicate function to fail. The predicate
3265 * function is passed one argument: *(value)*.
3266 *
3267 * @func
3268 * @memberOf R
3269 * @category List
3270 * @sig (a -> Boolean) -> [a] -> [a]
3271 * @param {Function} fn The function called per iteration.
3272 * @param {Array} list The collection to iterate over.
3273 * @return {Array} A new array.
3274 * @see R.dropLastWhile
3275 * @example
3276 *
3277 * var isNotOne = function(x) {
3278 * return !(x === 1);
3279 * };
3280 *
3281 * R.takeLastWhile(isNotOne, [1, 2, 3, 4]); //=> [2, 3, 4]
3282 */
3283 var takeLastWhile = _curry2(function takeLastWhile(fn, list) {
3284 var idx = list.length - 1;
3285 while (idx >= 0 && fn(list[idx])) {
3286 idx -= 1;
3287 }
3288 return _slice(list, idx + 1, Infinity);
3289 });
3290
3291 /**
3292 * Runs the given function with the supplied object, then returns the object.
3293 *
3294 * @func
3295 * @memberOf R
3296 * @category Function
3297 * @sig (a -> *) -> a -> a
3298 * @param {Function} fn The function to call with `x`. The return value of `fn` will be thrown away.
3299 * @param {*} x
3300 * @return {*} `x`.
3301 * @example
3302 *
3303 * var sayX = function(x) { console.log('x is ' + x); };
3304 * R.tap(sayX, 100); //=> 100
3305 * //-> 'x is 100'
3306 */
3307 var tap = _curry2(function tap(fn, x) {
3308 fn(x);
3309 return x;
3310 });
3311
3312 /**
3313 * Determines whether a given string matches a given regular expression.
3314 *
3315 * @func
3316 * @memberOf R
3317 * @see R.match
3318 * @category String
3319 * @sig RegExp -> String -> Boolean
3320 * @param {RegExp} pattern
3321 * @param {String} str
3322 * @return {Boolean}
3323 * @example
3324 *
3325 * R.test(/^x/, 'xyz'); //=> true
3326 * R.test(/^y/, 'xyz'); //=> false
3327 */
3328 var test = _curry2(function test(pattern, str) {
3329 return _cloneRegExp(pattern).test(str);
3330 });
3331
3332 /**
3333 * Calls an input function `n` times, returning an array containing the results of those
3334 * function calls.
3335 *
3336 * `fn` is passed one argument: The current value of `n`, which begins at `0` and is
3337 * gradually incremented to `n - 1`.
3338 *
3339 * @func
3340 * @memberOf R
3341 * @category List
3342 * @sig (i -> a) -> i -> [a]
3343 * @param {Function} fn The function to invoke. Passed one argument, the current value of `n`.
3344 * @param {Number} n A value between `0` and `n - 1`. Increments after each function call.
3345 * @return {Array} An array containing the return values of all calls to `fn`.
3346 * @example
3347 *
3348 * R.times(R.identity, 5); //=> [0, 1, 2, 3, 4]
3349 */
3350 var times = _curry2(function times(fn, n) {
3351 var len = Number(n);
3352 var list = new Array(len);
3353 var idx = 0;
3354 while (idx < len) {
3355 list[idx] = fn(idx);
3356 idx += 1;
3357 }
3358 return list;
3359 });
3360
3361 /**
3362 * Converts an object into an array of key, value arrays.
3363 * Only the object's own properties are used.
3364 * Note that the order of the output array is not guaranteed to be
3365 * consistent across different JS platforms.
3366 *
3367 * @func
3368 * @memberOf R
3369 * @category Object
3370 * @sig {String: *} -> [[String,*]]
3371 * @param {Object} obj The object to extract from
3372 * @return {Array} An array of key, value arrays from the object's own properties.
3373 * @see R.fromPairs
3374 * @example
3375 *
3376 * R.toPairs({a: 1, b: 2, c: 3}); //=> [['a', 1], ['b', 2], ['c', 3]]
3377 */
3378 var toPairs = _curry1(function toPairs(obj) {
3379 var pairs = [];
3380 for (var prop in obj) {
3381 if (_has(prop, obj)) {
3382 pairs[pairs.length] = [
3383 prop,
3384 obj[prop]
3385 ];
3386 }
3387 }
3388 return pairs;
3389 });
3390
3391 /**
3392 * Converts an object into an array of key, value arrays.
3393 * The object's own properties and prototype properties are used.
3394 * Note that the order of the output array is not guaranteed to be
3395 * consistent across different JS platforms.
3396 *
3397 * @func
3398 * @memberOf R
3399 * @category Object
3400 * @sig {String: *} -> [[String,*]]
3401 * @param {Object} obj The object to extract from
3402 * @return {Array} An array of key, value arrays from the object's own
3403 * and prototype properties.
3404 * @example
3405 *
3406 * var F = function() { this.x = 'X'; };
3407 * F.prototype.y = 'Y';
3408 * var f = new F();
3409 * R.toPairsIn(f); //=> [['x','X'], ['y','Y']]
3410 */
3411 var toPairsIn = _curry1(function toPairsIn(obj) {
3412 var pairs = [];
3413 for (var prop in obj) {
3414 pairs[pairs.length] = [
3415 prop,
3416 obj[prop]
3417 ];
3418 }
3419 return pairs;
3420 });
3421
3422 /**
3423 * Removes (strips) whitespace from both ends of the string.
3424 *
3425 * @func
3426 * @memberOf R
3427 * @category String
3428 * @sig String -> String
3429 * @param {String} str The string to trim.
3430 * @return {String} Trimmed version of `str`.
3431 * @example
3432 *
3433 * R.trim(' xyz '); //=> 'xyz'
3434 * R.map(R.trim, R.split(',', 'x, y, z')); //=> ['x', 'y', 'z']
3435 */
3436 var trim = function () {
3437 var ws = '\t\n\x0B\f\r \xA0\u1680\u180E\u2000\u2001\u2002\u2003' + '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028' + '\u2029\uFEFF';
3438 var zeroWidth = '\u200B';
3439 var hasProtoTrim = typeof String.prototype.trim === 'function';
3440 if (!hasProtoTrim || (ws.trim() || !zeroWidth.trim())) {
3441 return _curry1(function trim(str) {
3442 var beginRx = new RegExp('^[' + ws + '][' + ws + ']*');
3443 var endRx = new RegExp('[' + ws + '][' + ws + ']*$');
3444 return str.replace(beginRx, '').replace(endRx, '');
3445 });
3446 } else {
3447 return _curry1(function trim(str) {
3448 return str.trim();
3449 });
3450 }
3451 }();
3452
3453 /**
3454 * Gives a single-word string description of the (native) type of a value, returning such
3455 * answers as 'Object', 'Number', 'Array', or 'Null'. Does not attempt to distinguish user
3456 * Object types any further, reporting them all as 'Object'.
3457 *
3458 * @func
3459 * @memberOf R
3460 * @category Type
3461 * @sig (* -> {*}) -> String
3462 * @param {*} val The value to test
3463 * @return {String}
3464 * @example
3465 *
3466 * R.type({}); //=> "Object"
3467 * R.type(1); //=> "Number"
3468 * R.type(false); //=> "Boolean"
3469 * R.type('s'); //=> "String"
3470 * R.type(null); //=> "Null"
3471 * R.type([]); //=> "Array"
3472 * R.type(/[A-z]/); //=> "RegExp"
3473 */
3474 var type = _curry1(function type(val) {
3475 return val === null ? 'Null' : val === undefined ? 'Undefined' : Object.prototype.toString.call(val).slice(8, -1);
3476 });
3477
3478 /**
3479 * Takes a function `fn`, which takes a single array argument, and returns
3480 * a function which:
3481 *
3482 * - takes any number of positional arguments;
3483 * - passes these arguments to `fn` as an array; and
3484 * - returns the result.
3485 *
3486 * In other words, R.unapply derives a variadic function from a function
3487 * which takes an array. R.unapply is the inverse of R.apply.
3488 *
3489 * @func
3490 * @memberOf R
3491 * @category Function
3492 * @sig ([*...] -> a) -> (*... -> a)
3493 * @param {Function} fn
3494 * @return {Function}
3495 * @see R.apply
3496 * @example
3497 *
3498 * R.unapply(JSON.stringify)(1, 2, 3); //=> '[1,2,3]'
3499 */
3500 var unapply = _curry1(function unapply(fn) {
3501 return function () {
3502 return fn(_slice(arguments));
3503 };
3504 });
3505
3506 /**
3507 * Wraps a function of any arity (including nullary) in a function that accepts exactly 1
3508 * parameter. Any extraneous parameters will not be passed to the supplied function.
3509 *
3510 * @func
3511 * @memberOf R
3512 * @category Function
3513 * @sig (* -> b) -> (a -> b)
3514 * @param {Function} fn The function to wrap.
3515 * @return {Function} A new function wrapping `fn`. The new function is guaranteed to be of
3516 * arity 1.
3517 * @example
3518 *
3519 * var takesTwoArgs = function(a, b) {
3520 * return [a, b];
3521 * };
3522 * takesTwoArgs.length; //=> 2
3523 * takesTwoArgs(1, 2); //=> [1, 2]
3524 *
3525 * var takesOneArg = R.unary(takesTwoArgs);
3526 * takesOneArg.length; //=> 1
3527 * // Only 1 argument is passed to the wrapped function
3528 * takesOneArg(1, 2); //=> [1, undefined]
3529 */
3530 var unary = _curry1(function unary(fn) {
3531 return nAry(1, fn);
3532 });
3533
3534 /**
3535 * Returns a function of arity `n` from a (manually) curried function.
3536 *
3537 * @func
3538 * @memberOf R
3539 * @category Function
3540 * @sig Number -> (a -> b) -> (a -> c)
3541 * @param {Number} length The arity for the returned function.
3542 * @param {Function} fn The function to uncurry.
3543 * @return {Function} A new function.
3544 * @see R.curry
3545 * @example
3546 *
3547 * var addFour = function(a) {
3548 * return function(b) {
3549 * return function(c) {
3550 * return function(d) {
3551 * return a + b + c + d;
3552 * };
3553 * };
3554 * };
3555 * };
3556 *
3557 * var uncurriedAddFour = R.uncurryN(4, addFour);
3558 * curriedAddFour(1, 2, 3, 4); //=> 10
3559 */
3560 var uncurryN = _curry2(function uncurryN(depth, fn) {
3561 return curryN(depth, function () {
3562 var currentDepth = 1;
3563 var value = fn;
3564 var idx = 0;
3565 var endIdx;
3566 while (currentDepth <= depth && typeof value === 'function') {
3567 endIdx = currentDepth === depth ? arguments.length : idx + value.length;
3568 value = value.apply(this, _slice(arguments, idx, endIdx));
3569 currentDepth += 1;
3570 idx = endIdx;
3571 }
3572 return value;
3573 });
3574 });
3575
3576 /**
3577 * Builds a list from a seed value. Accepts an iterator function, which returns either false
3578 * to stop iteration or an array of length 2 containing the value to add to the resulting
3579 * list and the seed to be used in the next call to the iterator function.
3580 *
3581 * The iterator function receives one argument: *(seed)*.
3582 *
3583 * @func
3584 * @memberOf R
3585 * @category List
3586 * @sig (a -> [b]) -> * -> [b]
3587 * @param {Function} fn The iterator function. receives one argument, `seed`, and returns
3588 * either false to quit iteration or an array of length two to proceed. The element
3589 * at index 0 of this array will be added to the resulting array, and the element
3590 * at index 1 will be passed to the next call to `fn`.
3591 * @param {*} seed The seed value.
3592 * @return {Array} The final list.
3593 * @example
3594 *
3595 * var f = function(n) { return n > 50 ? false : [-n, n + 10] };
3596 * R.unfold(f, 10); //=> [-10, -20, -30, -40, -50]
3597 */
3598 var unfold = _curry2(function unfold(fn, seed) {
3599 var pair = fn(seed);
3600 var result = [];
3601 while (pair && pair.length) {
3602 result[result.length] = pair[0];
3603 pair = fn(pair[1]);
3604 }
3605 return result;
3606 });
3607
3608 /**
3609 * Returns a new list containing only one copy of each element in the original list, based
3610 * upon the value returned by applying the supplied predicate to two list elements. Prefers
3611 * the first item if two items compare equal based on the predicate.
3612 *
3613 * @func
3614 * @memberOf R
3615 * @category List
3616 * @sig (a, a -> Boolean) -> [a] -> [a]
3617 * @param {Function} pred A predicate used to test whether two items are equal.
3618 * @param {Array} list The array to consider.
3619 * @return {Array} The list of unique items.
3620 * @example
3621 *
3622 * var strEq = function(a, b) { return String(a) === String(b); };
3623 * R.uniqWith(strEq)([1, '1', 2, 1]); //=> [1, 2]
3624 * R.uniqWith(strEq)([{}, {}]); //=> [{}]
3625 * R.uniqWith(strEq)([1, '1', 1]); //=> [1]
3626 * R.uniqWith(strEq)(['1', 1, 1]); //=> ['1']
3627 */
3628 var uniqWith = _curry2(function uniqWith(pred, list) {
3629 var idx = 0, len = list.length;
3630 var result = [], item;
3631 while (idx < len) {
3632 item = list[idx];
3633 if (!_containsWith(pred, item, result)) {
3634 result[result.length] = item;
3635 }
3636 idx += 1;
3637 }
3638 return result;
3639 });
3640
3641 /**
3642 * Returns a new copy of the array with the element at the
3643 * provided index replaced with the given value.
3644 * @see R.adjust
3645 *
3646 * @func
3647 * @memberOf R
3648 * @category List
3649 * @sig Number -> a -> [a] -> [a]
3650 * @param {Number} idx The index to update.
3651 * @param {*} x The value to exist at the given index of the returned array.
3652 * @param {Array|Arguments} list The source array-like object to be updated.
3653 * @return {Array} A copy of `list` with the value at index `idx` replaced with `x`.
3654 * @example
3655 *
3656 * R.update(1, 11, [0, 1, 2]); //=> [0, 11, 2]
3657 * R.update(1)(11)([0, 1, 2]); //=> [0, 11, 2]
3658 */
3659 var update = _curry3(function update(idx, x, list) {
3660 return adjust(always(x), idx, list);
3661 });
3662
3663 /**
3664 * Returns a list of all the enumerable own properties of the supplied object.
3665 * Note that the order of the output array is not guaranteed across
3666 * different JS platforms.
3667 *
3668 * @func
3669 * @memberOf R
3670 * @category Object
3671 * @sig {k: v} -> [v]
3672 * @param {Object} obj The object to extract values from
3673 * @return {Array} An array of the values of the object's own properties.
3674 * @example
3675 *
3676 * R.values({a: 1, b: 2, c: 3}); //=> [1, 2, 3]
3677 */
3678 var values = _curry1(function values(obj) {
3679 var props = keys(obj);
3680 var len = props.length;
3681 var vals = [];
3682 var idx = 0;
3683 while (idx < len) {
3684 vals[idx] = obj[props[idx]];
3685 idx += 1;
3686 }
3687 return vals;
3688 });
3689
3690 /**
3691 * Returns a list of all the properties, including prototype properties,
3692 * of the supplied object.
3693 * Note that the order of the output array is not guaranteed to be
3694 * consistent across different JS platforms.
3695 *
3696 * @func
3697 * @memberOf R
3698 * @category Object
3699 * @sig {k: v} -> [v]
3700 * @param {Object} obj The object to extract values from
3701 * @return {Array} An array of the values of the object's own and prototype properties.
3702 * @example
3703 *
3704 * var F = function() { this.x = 'X'; };
3705 * F.prototype.y = 'Y';
3706 * var f = new F();
3707 * R.valuesIn(f); //=> ['X', 'Y']
3708 */
3709 var valuesIn = _curry1(function valuesIn(obj) {
3710 var prop, vs = [];
3711 for (prop in obj) {
3712 vs[vs.length] = obj[prop];
3713 }
3714 return vs;
3715 });
3716
3717 /**
3718 * Returns a "view" of the given data structure, determined by the given lens.
3719 * The lens's focus determines which portion of the data structure is visible.
3720 *
3721 * @func
3722 * @memberOf R
3723 * @category Object
3724 * @typedef Lens s a = Functor f => (a -> f a) -> s -> f s
3725 * @sig Lens s a -> s -> a
3726 * @param {Lens} lens
3727 * @param {*} x
3728 * @return {*}
3729 * @see R.prop, R.lensIndex, R.lensProp
3730 * @example
3731 *
3732 * var xLens = R.lensProp('x');
3733 *
3734 * R.view(xLens, {x: 1, y: 2}); //=> 1
3735 * R.view(xLens, {x: 4, y: 2}); //=> 4
3736 */
3737 var view = function () {
3738 var Const = function (x) {
3739 return {
3740 value: x,
3741 map: function () {
3742 return this;
3743 }
3744 };
3745 };
3746 return _curry2(function view(lens, x) {
3747 return lens(Const)(x).value;
3748 });
3749 }();
3750
3751 /**
3752 * Takes a spec object and a test object; returns true if the test satisfies
3753 * the spec. Each of the spec's own properties must be a predicate function.
3754 * Each predicate is applied to the value of the corresponding property of
3755 * the test object. `where` returns true if all the predicates return true,
3756 * false otherwise.
3757 *
3758 * `where` is well suited to declaratively expressing constraints for other
3759 * functions such as `filter` and `find`.
3760 *
3761 * @func
3762 * @memberOf R
3763 * @category Object
3764 * @sig {String: (* -> Boolean)} -> {String: *} -> Boolean
3765 * @param {Object} spec
3766 * @param {Object} testObj
3767 * @return {Boolean}
3768 * @example
3769 *
3770 * // pred :: Object -> Boolean
3771 * var pred = R.where({
3772 * a: R.equals('foo'),
3773 * b: R.complement(R.equals('bar')),
3774 * x: R.gt(_, 10),
3775 * y: R.lt(_, 20)
3776 * });
3777 *
3778 * pred({a: 'foo', b: 'xxx', x: 11, y: 19}); //=> true
3779 * pred({a: 'xxx', b: 'xxx', x: 11, y: 19}); //=> false
3780 * pred({a: 'foo', b: 'bar', x: 11, y: 19}); //=> false
3781 * pred({a: 'foo', b: 'xxx', x: 10, y: 19}); //=> false
3782 * pred({a: 'foo', b: 'xxx', x: 11, y: 20}); //=> false
3783 */
3784 var where = _curry2(function where(spec, testObj) {
3785 for (var prop in spec) {
3786 if (_has(prop, spec) && !spec[prop](testObj[prop])) {
3787 return false;
3788 }
3789 }
3790 return true;
3791 });
3792
3793 /**
3794 * Wrap a function inside another to allow you to make adjustments to the parameters, or do
3795 * other processing either before the internal function is called or with its results.
3796 *
3797 * @func
3798 * @memberOf R
3799 * @category Function
3800 * @sig (a... -> b) -> ((a... -> b) -> a... -> c) -> (a... -> c)
3801 * @param {Function} fn The function to wrap.
3802 * @param {Function} wrapper The wrapper function.
3803 * @return {Function} The wrapped function.
3804 * @example
3805 *
3806 * var greet = function(name) {return 'Hello ' + name;};
3807 *
3808 * var shoutedGreet = R.wrap(greet, function(gr, name) {
3809 * return gr(name).toUpperCase();
3810 * });
3811 * shoutedGreet("Kathy"); //=> "HELLO KATHY"
3812 *
3813 * var shortenedGreet = R.wrap(greet, function(gr, name) {
3814 * return gr(name.substring(0, 3));
3815 * });
3816 * shortenedGreet("Robert"); //=> "Hello Rob"
3817 */
3818 var wrap = _curry2(function wrap(fn, wrapper) {
3819 return curryN(fn.length, function () {
3820 return wrapper.apply(this, _concat([fn], arguments));
3821 });
3822 });
3823
3824 /**
3825 * Creates a new list out of the two supplied by creating each possible
3826 * pair from the lists.
3827 *
3828 * @func
3829 * @memberOf R
3830 * @category List
3831 * @sig [a] -> [b] -> [[a,b]]
3832 * @param {Array} as The first list.
3833 * @param {Array} bs The second list.
3834 * @return {Array} The list made by combining each possible pair from
3835 * `as` and `bs` into pairs (`[a, b]`).
3836 * @example
3837 *
3838 * R.xprod([1, 2], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
3839 */
3840 // = xprodWith(prepend); (takes about 3 times as long...)
3841 var xprod = _curry2(function xprod(a, b) {
3842 // = xprodWith(prepend); (takes about 3 times as long...)
3843 var idx = 0;
3844 var ilen = a.length;
3845 var j;
3846 var jlen = b.length;
3847 var result = [];
3848 while (idx < ilen) {
3849 j = 0;
3850 while (j < jlen) {
3851 result[result.length] = [
3852 a[idx],
3853 b[j]
3854 ];
3855 j += 1;
3856 }
3857 idx += 1;
3858 }
3859 return result;
3860 });
3861
3862 /**
3863 * Creates a new list out of the two supplied by pairing up
3864 * equally-positioned items from both lists. The returned list is
3865 * truncated to the length of the shorter of the two input lists.
3866 * Note: `zip` is equivalent to `zipWith(function(a, b) { return [a, b] })`.
3867 *
3868 * @func
3869 * @memberOf R
3870 * @category List
3871 * @sig [a] -> [b] -> [[a,b]]
3872 * @param {Array} list1 The first array to consider.
3873 * @param {Array} list2 The second array to consider.
3874 * @return {Array} The list made by pairing up same-indexed elements of `list1` and `list2`.
3875 * @example
3876 *
3877 * R.zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']]
3878 */
3879 var zip = _curry2(function zip(a, b) {
3880 var rv = [];
3881 var idx = 0;
3882 var len = Math.min(a.length, b.length);
3883 while (idx < len) {
3884 rv[idx] = [
3885 a[idx],
3886 b[idx]
3887 ];
3888 idx += 1;
3889 }
3890 return rv;
3891 });
3892
3893 /**
3894 * Creates a new object out of a list of keys and a list of values.
3895 *
3896 * @func
3897 * @memberOf R
3898 * @category List
3899 * @sig [String] -> [*] -> {String: *}
3900 * @param {Array} keys The array that will be properties on the output object.
3901 * @param {Array} values The list of values on the output object.
3902 * @return {Object} The object made by pairing up same-indexed elements of `keys` and `values`.
3903 * @example
3904 *
3905 * R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3}
3906 */
3907 var zipObj = _curry2(function zipObj(keys, values) {
3908 var idx = 0, len = keys.length, out = {};
3909 while (idx < len) {
3910 out[keys[idx]] = values[idx];
3911 idx += 1;
3912 }
3913 return out;
3914 });
3915
3916 /**
3917 * Creates a new list out of the two supplied by applying the function to
3918 * each equally-positioned pair in the lists. The returned list is
3919 * truncated to the length of the shorter of the two input lists.
3920 *
3921 * @function
3922 * @memberOf R
3923 * @category List
3924 * @sig (a,b -> c) -> [a] -> [b] -> [c]
3925 * @param {Function} fn The function used to combine the two elements into one value.
3926 * @param {Array} list1 The first array to consider.
3927 * @param {Array} list2 The second array to consider.
3928 * @return {Array} The list made by combining same-indexed elements of `list1` and `list2`
3929 * using `fn`.
3930 * @example
3931 *
3932 * var f = function(x, y) {
3933 * // ...
3934 * };
3935 * R.zipWith(f, [1, 2, 3], ['a', 'b', 'c']);
3936 * //=> [f(1, 'a'), f(2, 'b'), f(3, 'c')]
3937 */
3938 var zipWith = _curry3(function zipWith(fn, a, b) {
3939 var rv = [], idx = 0, len = Math.min(a.length, b.length);
3940 while (idx < len) {
3941 rv[idx] = fn(a[idx], b[idx]);
3942 idx += 1;
3943 }
3944 return rv;
3945 });
3946
3947 /**
3948 * A function that always returns `false`. Any passed in parameters are ignored.
3949 *
3950 * @func
3951 * @memberOf R
3952 * @category Function
3953 * @sig * -> false
3954 * @return {Boolean} false
3955 * @see R.always, R.T
3956 * @example
3957 *
3958 * R.F(); //=> false
3959 */
3960 var F = always(false);
3961
3962 /**
3963 * A function that always returns `true`. Any passed in parameters are ignored.
3964 *
3965 * @func
3966 * @memberOf R
3967 * @category Function
3968 * @sig * -> true
3969 * @return {Boolean} `true`.
3970 * @see R.always, R.F
3971 * @example
3972 *
3973 * R.T(); //=> true
3974 */
3975 var T = always(true);
3976
3977 /**
3978 * Similar to hasMethod, this checks whether a function has a [methodname]
3979 * function. If it isn't an array it will execute that function otherwise it will
3980 * default to the ramda implementation.
3981 *
3982 * @private
3983 * @param {Function} fn ramda implemtation
3984 * @param {String} methodname property to check for a custom implementation
3985 * @return {Object} Whatever the return value of the method is.
3986 */
3987 var _checkForMethod = function _checkForMethod(methodname, fn) {
3988 return function () {
3989 var length = arguments.length;
3990 if (length === 0) {
3991 return fn();
3992 }
3993 var obj = arguments[length - 1];
3994 return _isArray(obj) || typeof obj[methodname] !== 'function' ? fn.apply(this, arguments) : obj[methodname].apply(obj, _slice(arguments, 0, length - 1));
3995 };
3996 };
3997
3998 /**
3999 * Copies an object.
4000 *
4001 * @private
4002 * @param {*} value The value to be copied
4003 * @param {Array} refFrom Array containing the source references
4004 * @param {Array} refTo Array containing the copied source references
4005 * @return {*} The copied value.
4006 */
4007 var _clone = function _clone(value, refFrom, refTo) {
4008 var copy = function copy(copiedValue) {
4009 var len = refFrom.length;
4010 var idx = 0;
4011 while (idx < len) {
4012 if (value === refFrom[idx]) {
4013 return refTo[idx];
4014 }
4015 idx += 1;
4016 }
4017 refFrom[idx + 1] = value;
4018 refTo[idx + 1] = copiedValue;
4019 for (var key in value) {
4020 copiedValue[key] = _clone(value[key], refFrom, refTo);
4021 }
4022 return copiedValue;
4023 };
4024 switch (type(value)) {
4025 case 'Object':
4026 return copy({});
4027 case 'Array':
4028 return copy([]);
4029 case 'Date':
4030 return new Date(value);
4031 case 'RegExp':
4032 return _cloneRegExp(value);
4033 default:
4034 return value;
4035 }
4036 };
4037
4038 var _createPartialApplicator = function _createPartialApplicator(concat) {
4039 return function (fn) {
4040 var args = _slice(arguments, 1);
4041 return _arity(Math.max(0, fn.length - args.length), function () {
4042 return fn.apply(this, concat(args, arguments));
4043 });
4044 };
4045 };
4046
4047 /**
4048 * Returns a function that dispatches with different strategies based on the
4049 * object in list position (last argument). If it is an array, executes [fn].
4050 * Otherwise, if it has a function with [methodname], it will execute that
4051 * function (functor case). Otherwise, if it is a transformer, uses transducer
4052 * [xf] to return a new transformer (transducer case). Otherwise, it will
4053 * default to executing [fn].
4054 *
4055 * @private
4056 * @param {String} methodname property to check for a custom implementation
4057 * @param {Function} xf transducer to initialize if object is transformer
4058 * @param {Function} fn default ramda implementation
4059 * @return {Function} A function that dispatches on object in list position
4060 */
4061 var _dispatchable = function _dispatchable(methodname, xf, fn) {
4062 return function () {
4063 var length = arguments.length;
4064 if (length === 0) {
4065 return fn();
4066 }
4067 var obj = arguments[length - 1];
4068 if (!_isArray(obj)) {
4069 var args = _slice(arguments, 0, length - 1);
4070 if (typeof obj[methodname] === 'function') {
4071 return obj[methodname].apply(obj, args);
4072 }
4073 if (_isTransformer(obj)) {
4074 var transducer = xf.apply(null, args);
4075 return transducer(obj);
4076 }
4077 }
4078 return fn.apply(this, arguments);
4079 };
4080 };
4081
4082 // The algorithm used to handle cyclic structures is
4083 // inspired by underscore's isEqual
4084 // RegExp equality algorithm: http://stackoverflow.com/a/10776635
4085 var _equals = function _equals(a, b, stackA, stackB) {
4086 var typeA = type(a);
4087 if (typeA !== type(b)) {
4088 return false;
4089 }
4090 if (typeA === 'Boolean' || typeA === 'Number' || typeA === 'String') {
4091 return typeof a === 'object' ? typeof b === 'object' && identical(a.valueOf(), b.valueOf()) : identical(a, b);
4092 }
4093 if (identical(a, b)) {
4094 return true;
4095 }
4096 if (typeA === 'RegExp') {
4097 // RegExp equality algorithm: http://stackoverflow.com/a/10776635
4098 return a.source === b.source && a.global === b.global && a.ignoreCase === b.ignoreCase && a.multiline === b.multiline && a.sticky === b.sticky && a.unicode === b.unicode;
4099 }
4100 if (Object(a) === a) {
4101 if (typeA === 'Date' && a.getTime() !== b.getTime()) {
4102 return false;
4103 }
4104 var keysA = keys(a);
4105 if (keysA.length !== keys(b).length) {
4106 return false;
4107 }
4108 var idx = stackA.length - 1;
4109 while (idx >= 0) {
4110 if (stackA[idx] === a) {
4111 return stackB[idx] === b;
4112 }
4113 idx -= 1;
4114 }
4115 stackA[stackA.length] = a;
4116 stackB[stackB.length] = b;
4117 idx = keysA.length - 1;
4118 while (idx >= 0) {
4119 var key = keysA[idx];
4120 if (!_has(key, b) || !_equals(b[key], a[key], stackA, stackB)) {
4121 return false;
4122 }
4123 idx -= 1;
4124 }
4125 stackA.pop();
4126 stackB.pop();
4127 return true;
4128 }
4129 return false;
4130 };
4131
4132 /**
4133 * Private function that determines whether or not a provided object has a given method.
4134 * Does not ignore methods stored on the object's prototype chain. Used for dynamically
4135 * dispatching Ramda methods to non-Array objects.
4136 *
4137 * @private
4138 * @param {String} methodName The name of the method to check for.
4139 * @param {Object} obj The object to test.
4140 * @return {Boolean} `true` has a given method, `false` otherwise.
4141 * @example
4142 *
4143 * var person = { name: 'John' };
4144 * person.shout = function() { alert(this.name); };
4145 *
4146 * _hasMethod('shout', person); //=> true
4147 * _hasMethod('foo', person); //=> false
4148 */
4149 var _hasMethod = function _hasMethod(methodName, obj) {
4150 return obj != null && !_isArray(obj) && typeof obj[methodName] === 'function';
4151 };
4152
4153 /**
4154 * `_makeFlat` is a helper function that returns a one-level or fully recursive function
4155 * based on the flag passed in.
4156 *
4157 * @private
4158 */
4159 var _makeFlat = function _makeFlat(recursive) {
4160 return function flatt(list) {
4161 var value, result = [], idx = 0, j, ilen = list.length, jlen;
4162 while (idx < ilen) {
4163 if (isArrayLike(list[idx])) {
4164 value = recursive ? flatt(list[idx]) : list[idx];
4165 j = 0;
4166 jlen = value.length;
4167 while (j < jlen) {
4168 result[result.length] = value[j];
4169 j += 1;
4170 }
4171 } else {
4172 result[result.length] = list[idx];
4173 }
4174 idx += 1;
4175 }
4176 return result;
4177 };
4178 };
4179
4180 var _reduce = function () {
4181 function _arrayReduce(xf, acc, list) {
4182 var idx = 0, len = list.length;
4183 while (idx < len) {
4184 acc = xf['@@transducer/step'](acc, list[idx]);
4185 if (acc && acc['@@transducer/reduced']) {
4186 acc = acc['@@transducer/value'];
4187 break;
4188 }
4189 idx += 1;
4190 }
4191 return xf['@@transducer/result'](acc);
4192 }
4193 function _iterableReduce(xf, acc, iter) {
4194 var step = iter.next();
4195 while (!step.done) {
4196 acc = xf['@@transducer/step'](acc, step.value);
4197 if (acc && acc['@@transducer/reduced']) {
4198 acc = acc['@@transducer/value'];
4199 break;
4200 }
4201 step = iter.next();
4202 }
4203 return xf['@@transducer/result'](acc);
4204 }
4205 function _methodReduce(xf, acc, obj) {
4206 return xf['@@transducer/result'](obj.reduce(bind(xf['@@transducer/step'], xf), acc));
4207 }
4208 var symIterator = typeof Symbol !== 'undefined' ? Symbol.iterator : '@@iterator';
4209 return function _reduce(fn, acc, list) {
4210 if (typeof fn === 'function') {
4211 fn = _xwrap(fn);
4212 }
4213 if (isArrayLike(list)) {
4214 return _arrayReduce(fn, acc, list);
4215 }
4216 if (typeof list.reduce === 'function') {
4217 return _methodReduce(fn, acc, list);
4218 }
4219 if (list[symIterator] != null) {
4220 return _iterableReduce(fn, acc, list[symIterator]());
4221 }
4222 if (typeof list.next === 'function') {
4223 return _iterableReduce(fn, acc, list);
4224 }
4225 throw new TypeError('reduce: list must be array or iterable');
4226 };
4227 }();
4228
4229 var _stepCat = function () {
4230 var _stepCatArray = {
4231 '@@transducer/init': Array,
4232 '@@transducer/step': function (xs, x) {
4233 return _concat(xs, [x]);
4234 },
4235 '@@transducer/result': _identity
4236 };
4237 var _stepCatString = {
4238 '@@transducer/init': String,
4239 '@@transducer/step': function (a, b) {
4240 return a + b;
4241 },
4242 '@@transducer/result': _identity
4243 };
4244 var _stepCatObject = {
4245 '@@transducer/init': Object,
4246 '@@transducer/step': function (result, input) {
4247 return merge(result, isArrayLike(input) ? createMapEntry(input[0], input[1]) : input);
4248 },
4249 '@@transducer/result': _identity
4250 };
4251 return function _stepCat(obj) {
4252 if (_isTransformer(obj)) {
4253 return obj;
4254 }
4255 if (isArrayLike(obj)) {
4256 return _stepCatArray;
4257 }
4258 if (typeof obj === 'string') {
4259 return _stepCatString;
4260 }
4261 if (typeof obj === 'object') {
4262 return _stepCatObject;
4263 }
4264 throw new Error('Cannot create transformer for ' + obj);
4265 };
4266 }();
4267
4268 var _xall = function () {
4269 function XAll(f, xf) {
4270 this.xf = xf;
4271 this.f = f;
4272 this.all = true;
4273 }
4274 XAll.prototype['@@transducer/init'] = _xfBase.init;
4275 XAll.prototype['@@transducer/result'] = function (result) {
4276 if (this.all) {
4277 result = this.xf['@@transducer/step'](result, true);
4278 }
4279 return this.xf['@@transducer/result'](result);
4280 };
4281 XAll.prototype['@@transducer/step'] = function (result, input) {
4282 if (!this.f(input)) {
4283 this.all = false;
4284 result = _reduced(this.xf['@@transducer/step'](result, false));
4285 }
4286 return result;
4287 };
4288 return _curry2(function _xall(f, xf) {
4289 return new XAll(f, xf);
4290 });
4291 }();
4292
4293 var _xany = function () {
4294 function XAny(f, xf) {
4295 this.xf = xf;
4296 this.f = f;
4297 this.any = false;
4298 }
4299 XAny.prototype['@@transducer/init'] = _xfBase.init;
4300 XAny.prototype['@@transducer/result'] = function (result) {
4301 if (!this.any) {
4302 result = this.xf['@@transducer/step'](result, false);
4303 }
4304 return this.xf['@@transducer/result'](result);
4305 };
4306 XAny.prototype['@@transducer/step'] = function (result, input) {
4307 if (this.f(input)) {
4308 this.any = true;
4309 result = _reduced(this.xf['@@transducer/step'](result, true));
4310 }
4311 return result;
4312 };
4313 return _curry2(function _xany(f, xf) {
4314 return new XAny(f, xf);
4315 });
4316 }();
4317
4318 var _xdrop = function () {
4319 function XDrop(n, xf) {
4320 this.xf = xf;
4321 this.n = n;
4322 }
4323 XDrop.prototype['@@transducer/init'] = _xfBase.init;
4324 XDrop.prototype['@@transducer/result'] = _xfBase.result;
4325 XDrop.prototype['@@transducer/step'] = function (result, input) {
4326 if (this.n > 0) {
4327 this.n -= 1;
4328 return result;
4329 }
4330 return this.xf['@@transducer/step'](result, input);
4331 };
4332 return _curry2(function _xdrop(n, xf) {
4333 return new XDrop(n, xf);
4334 });
4335 }();
4336
4337 var _xdropWhile = function () {
4338 function XDropWhile(f, xf) {
4339 this.xf = xf;
4340 this.f = f;
4341 }
4342 XDropWhile.prototype['@@transducer/init'] = _xfBase.init;
4343 XDropWhile.prototype['@@transducer/result'] = _xfBase.result;
4344 XDropWhile.prototype['@@transducer/step'] = function (result, input) {
4345 if (this.f) {
4346 if (this.f(input)) {
4347 return result;
4348 }
4349 this.f = null;
4350 }
4351 return this.xf['@@transducer/step'](result, input);
4352 };
4353 return _curry2(function _xdropWhile(f, xf) {
4354 return new XDropWhile(f, xf);
4355 });
4356 }();
4357
4358 var _xgroupBy = function () {
4359 function XGroupBy(f, xf) {
4360 this.xf = xf;
4361 this.f = f;
4362 this.inputs = {};
4363 }
4364 XGroupBy.prototype['@@transducer/init'] = _xfBase.init;
4365 XGroupBy.prototype['@@transducer/result'] = function (result) {
4366 var key;
4367 for (key in this.inputs) {
4368 if (_has(key, this.inputs)) {
4369 result = this.xf['@@transducer/step'](result, this.inputs[key]);
4370 if (result['@@transducer/reduced']) {
4371 result = result['@@transducer/value'];
4372 break;
4373 }
4374 }
4375 }
4376 return this.xf['@@transducer/result'](result);
4377 };
4378 XGroupBy.prototype['@@transducer/step'] = function (result, input) {
4379 var key = this.f(input);
4380 this.inputs[key] = this.inputs[key] || [
4381 key,
4382 []
4383 ];
4384 this.inputs[key][1] = append(input, this.inputs[key][1]);
4385 return result;
4386 };
4387 return _curry2(function _xgroupBy(f, xf) {
4388 return new XGroupBy(f, xf);
4389 });
4390 }();
4391
4392 /**
4393 * Creates a new list iteration function from an existing one by adding two new parameters
4394 * to its callback function: the current index, and the entire list.
4395 *
4396 * This would turn, for instance, Ramda's simple `map` function into one that more closely
4397 * resembles `Array.prototype.map`. Note that this will only work for functions in which
4398 * the iteration callback function is the first parameter, and where the list is the last
4399 * parameter. (This latter might be unimportant if the list parameter is not used.)
4400 *
4401 * @func
4402 * @memberOf R
4403 * @category Function
4404 * @category List
4405 * @sig ((a ... -> b) ... -> [a] -> *) -> (a ..., Int, [a] -> b) ... -> [a] -> *)
4406 * @param {Function} fn A list iteration function that does not pass index or list to its callback
4407 * @return {Function} An altered list iteration function that passes (item, index, list) to its callback
4408 * @example
4409 *
4410 * var mapIndexed = R.addIndex(R.map);
4411 * mapIndexed(function(val, idx) {return idx + '-' + val;}, ['f', 'o', 'o', 'b', 'a', 'r']);
4412 * //=> ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r']
4413 */
4414 var addIndex = _curry1(function addIndex(fn) {
4415 return curryN(fn.length, function () {
4416 var idx = 0;
4417 var origFn = arguments[0];
4418 var list = arguments[arguments.length - 1];
4419 var args = _slice(arguments);
4420 args[0] = function () {
4421 var result = origFn.apply(this, _concat(arguments, [
4422 idx,
4423 list
4424 ]));
4425 idx += 1;
4426 return result;
4427 };
4428 return fn.apply(this, args);
4429 });
4430 });
4431
4432 /**
4433 * Returns `true` if all elements of the list match the predicate, `false` if there are any
4434 * that don't.
4435 *
4436 * Acts as a transducer if a transformer is given in list position.
4437 * @see R.transduce
4438 *
4439 * @func
4440 * @memberOf R
4441 * @category List
4442 * @sig (a -> Boolean) -> [a] -> Boolean
4443 * @param {Function} fn The predicate function.
4444 * @param {Array} list The array to consider.
4445 * @return {Boolean} `true` if the predicate is satisfied by every element, `false`
4446 * otherwise.
4447 * @see R.any, R.none
4448 * @example
4449 *
4450 * var lessThan2 = R.flip(R.lt)(2);
4451 * var lessThan3 = R.flip(R.lt)(3);
4452 * R.all(lessThan2)([1, 2]); //=> false
4453 * R.all(lessThan3)([1, 2]); //=> true
4454 */
4455 var all = _curry2(_dispatchable('all', _xall, function all(fn, list) {
4456 var idx = 0;
4457 while (idx < list.length) {
4458 if (!fn(list[idx])) {
4459 return false;
4460 }
4461 idx += 1;
4462 }
4463 return true;
4464 }));
4465
4466 /**
4467 * A function that returns the first argument if it's falsy otherwise the second
4468 * argument. Note that this is NOT short-circuited, meaning that if expressions
4469 * are passed they are both evaluated.
4470 *
4471 * Dispatches to the `and` method of the first argument if applicable.
4472 *
4473 * @func
4474 * @memberOf R
4475 * @category Logic
4476 * @sig * -> * -> *
4477 * @param {*} a any value
4478 * @param {*} b any other value
4479 * @return {*} the first argument if falsy otherwise the second argument.
4480 * @see R.both
4481 * @example
4482 *
4483 * R.and(false, true); //=> false
4484 * R.and(0, []); //=> 0
4485 * R.and(null, ''); => null
4486 */
4487 var and = _curry2(function and(a, b) {
4488 return _hasMethod('and', a) ? a.and(b) : a && b;
4489 });
4490
4491 /**
4492 * Returns `true` if at least one of elements of the list match the predicate, `false`
4493 * otherwise.
4494 *
4495 * Acts as a transducer if a transformer is given in list position.
4496 * @see R.transduce
4497 *
4498 * @func
4499 * @memberOf R
4500 * @category List
4501 * @sig (a -> Boolean) -> [a] -> Boolean
4502 * @param {Function} fn The predicate function.
4503 * @param {Array} list The array to consider.
4504 * @return {Boolean} `true` if the predicate is satisfied by at least one element, `false`
4505 * otherwise.
4506 * @see R.all, R.none
4507 * @example
4508 *
4509 * var lessThan0 = R.flip(R.lt)(0);
4510 * var lessThan2 = R.flip(R.lt)(2);
4511 * R.any(lessThan0)([1, 2]); //=> false
4512 * R.any(lessThan2)([1, 2]); //=> true
4513 */
4514 var any = _curry2(_dispatchable('any', _xany, function any(fn, list) {
4515 var idx = 0;
4516 while (idx < list.length) {
4517 if (fn(list[idx])) {
4518 return true;
4519 }
4520 idx += 1;
4521 }
4522 return false;
4523 }));
4524
4525 /**
4526 * Wraps a function of any arity (including nullary) in a function that accepts exactly 2
4527 * parameters. Any extraneous parameters will not be passed to the supplied function.
4528 *
4529 * @func
4530 * @memberOf R
4531 * @category Function
4532 * @sig (* -> c) -> (a, b -> c)
4533 * @param {Function} fn The function to wrap.
4534 * @return {Function} A new function wrapping `fn`. The new function is guaranteed to be of
4535 * arity 2.
4536 * @example
4537 *
4538 * var takesThreeArgs = function(a, b, c) {
4539 * return [a, b, c];
4540 * };
4541 * takesThreeArgs.length; //=> 3
4542 * takesThreeArgs(1, 2, 3); //=> [1, 2, 3]
4543 *
4544 * var takesTwoArgs = R.binary(takesThreeArgs);
4545 * takesTwoArgs.length; //=> 2
4546 * // Only 2 arguments are passed to the wrapped function
4547 * takesTwoArgs(1, 2, 3); //=> [1, 2, undefined]
4548 */
4549 var binary = _curry1(function binary(fn) {
4550 return nAry(2, fn);
4551 });
4552
4553 /**
4554 * Creates a deep copy of the value which may contain (nested) `Array`s and
4555 * `Object`s, `Number`s, `String`s, `Boolean`s and `Date`s. `Function`s are
4556 * not copied, but assigned by their reference.
4557 *
4558 * @func
4559 * @memberOf R
4560 * @category Object
4561 * @sig {*} -> {*}
4562 * @param {*} value The object or array to clone
4563 * @return {*} A new object or array.
4564 * @example
4565 *
4566 * var objects = [{}, {}, {}];
4567 * var objectsClone = R.clone(objects);
4568 * objects[0] === objectsClone[0]; //=> false
4569 */
4570 var clone = _curry1(function clone(value) {
4571 return _clone(value, [], []);
4572 });
4573
4574 /**
4575 * Returns a new list consisting of the elements of the first list followed by the elements
4576 * of the second.
4577 *
4578 * @func
4579 * @memberOf R
4580 * @category List
4581 * @sig [a] -> [a] -> [a]
4582 * @param {Array} list1 The first list to merge.
4583 * @param {Array} list2 The second set to merge.
4584 * @return {Array} A new array consisting of the contents of `list1` followed by the
4585 * contents of `list2`. If, instead of an Array for `list1`, you pass an
4586 * object with a `concat` method on it, `concat` will call `list1.concat`
4587 * and pass it the value of `list2`.
4588 *
4589 * @example
4590 *
4591 * R.concat([], []); //=> []
4592 * R.concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3]
4593 * R.concat('ABC', 'DEF'); // 'ABCDEF'
4594 */
4595 var concat = _curry2(function concat(set1, set2) {
4596 if (_isArray(set2)) {
4597 return _concat(set1, set2);
4598 } else if (_hasMethod('concat', set1)) {
4599 return set1.concat(set2);
4600 } else {
4601 throw new TypeError('can\'t concat ' + typeof set1);
4602 }
4603 });
4604
4605 /**
4606 * Returns a curried equivalent of the provided function. The curried
4607 * function has two unusual capabilities. First, its arguments needn't
4608 * be provided one at a time. If `f` is a ternary function and `g` is
4609 * `R.curry(f)`, the following are equivalent:
4610 *
4611 * - `g(1)(2)(3)`
4612 * - `g(1)(2, 3)`
4613 * - `g(1, 2)(3)`
4614 * - `g(1, 2, 3)`
4615 *
4616 * Secondly, the special placeholder value `R.__` may be used to specify
4617 * "gaps", allowing partial application of any combination of arguments,
4618 * regardless of their positions. If `g` is as above and `_` is `R.__`,
4619 * the following are equivalent:
4620 *
4621 * - `g(1, 2, 3)`
4622 * - `g(_, 2, 3)(1)`
4623 * - `g(_, _, 3)(1)(2)`
4624 * - `g(_, _, 3)(1, 2)`
4625 * - `g(_, 2)(1)(3)`
4626 * - `g(_, 2)(1, 3)`
4627 * - `g(_, 2)(_, 3)(1)`
4628 *
4629 * @func
4630 * @memberOf R
4631 * @category Function
4632 * @sig (* -> a) -> (* -> a)
4633 * @param {Function} fn The function to curry.
4634 * @return {Function} A new, curried function.
4635 * @see R.curryN
4636 * @example
4637 *
4638 * var addFourNumbers = function(a, b, c, d) {
4639 * return a + b + c + d;
4640 * };
4641 *
4642 * var curriedAddFourNumbers = R.curry(addFourNumbers);
4643 * var f = curriedAddFourNumbers(1, 2);
4644 * var g = f(3);
4645 * g(4); //=> 10
4646 */
4647 var curry = _curry1(function curry(fn) {
4648 return curryN(fn.length, fn);
4649 });
4650
4651 /**
4652 * Returns a new list containing the last `n` elements of a given list, passing each value
4653 * to the supplied predicate function, skipping elements while the predicate function returns
4654 * `true`. The predicate function is passed one argument: *(value)*.
4655 *
4656 * Acts as a transducer if a transformer is given in list position.
4657 * @see R.transduce
4658 *
4659 * @func
4660 * @memberOf R
4661 * @category List
4662 * @sig (a -> Boolean) -> [a] -> [a]
4663 * @param {Function} fn The function called per iteration.
4664 * @param {Array} list The collection to iterate over.
4665 * @return {Array} A new array.
4666 * @see R.takeWhile
4667 * @example
4668 *
4669 * var lteTwo = function(x) {
4670 * return x <= 2;
4671 * };
4672 *
4673 * R.dropWhile(lteTwo, [1, 2, 3, 4, 3, 2, 1]); //=> [3, 4, 3, 2, 1]
4674 */
4675 var dropWhile = _curry2(_dispatchable('dropWhile', _xdropWhile, function dropWhile(pred, list) {
4676 var idx = 0, len = list.length;
4677 while (idx < len && pred(list[idx])) {
4678 idx += 1;
4679 }
4680 return _slice(list, idx);
4681 }));
4682
4683 /**
4684 * Returns `true` if its arguments are equivalent, `false` otherwise.
4685 * Dispatches to an `equals` method if present. Handles cyclical data
4686 * structures.
4687 *
4688 * @func
4689 * @memberOf R
4690 * @category Relation
4691 * @sig a -> b -> Boolean
4692 * @param {*} a
4693 * @param {*} b
4694 * @return {Boolean}
4695 * @example
4696 *
4697 * R.equals(1, 1); //=> true
4698 * R.equals(1, '1'); //=> false
4699 * R.equals([1, 2, 3], [1, 2, 3]); //=> true
4700 *
4701 * var a = {}; a.v = a;
4702 * var b = {}; b.v = b;
4703 * R.equals(a, b); //=> true
4704 */
4705 var equals = _curry2(function equals(a, b) {
4706 return _hasMethod('equals', a) ? a.equals(b) : _hasMethod('equals', b) ? b.equals(a) : _equals(a, b, [], []);
4707 });
4708
4709 /**
4710 * Returns a new list containing only those items that match a given predicate function.
4711 * The predicate function is passed one argument: *(value)*.
4712 *
4713 * Note that `R.filter` does not skip deleted or unassigned indices, unlike the native
4714 * `Array.prototype.filter` method. For more details on this behavior, see:
4715 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#Description
4716 *
4717 * Acts as a transducer if a transformer is given in list position.
4718 * @see R.transduce
4719 *
4720 * @func
4721 * @memberOf R
4722 * @category List
4723 * @sig (a -> Boolean) -> [a] -> [a]
4724 * @param {Function} fn The function called per iteration.
4725 * @param {Array} list The collection to iterate over.
4726 * @return {Array} The new filtered array.
4727 * @see R.reject
4728 * @example
4729 *
4730 * var isEven = function(n) {
4731 * return n % 2 === 0;
4732 * };
4733 * R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4]
4734 */
4735 var filter = _curry2(_dispatchable('filter', _xfilter, _filter));
4736
4737 /**
4738 * Returns the first element of the list which matches the predicate, or `undefined` if no
4739 * element matches.
4740 *
4741 * Acts as a transducer if a transformer is given in list position.
4742 * @see R.transduce
4743 *
4744 * @func
4745 * @memberOf R
4746 * @category List
4747 * @sig (a -> Boolean) -> [a] -> a | undefined
4748 * @param {Function} fn The predicate function used to determine if the element is the
4749 * desired one.
4750 * @param {Array} list The array to consider.
4751 * @return {Object} The element found, or `undefined`.
4752 * @example
4753 *
4754 * var xs = [{a: 1}, {a: 2}, {a: 3}];
4755 * R.find(R.propEq('a', 2))(xs); //=> {a: 2}
4756 * R.find(R.propEq('a', 4))(xs); //=> undefined
4757 */
4758 var find = _curry2(_dispatchable('find', _xfind, function find(fn, list) {
4759 var idx = 0;
4760 var len = list.length;
4761 while (idx < len) {
4762 if (fn(list[idx])) {
4763 return list[idx];
4764 }
4765 idx += 1;
4766 }
4767 }));
4768
4769 /**
4770 * Returns the index of the first element of the list which matches the predicate, or `-1`
4771 * if no element matches.
4772 *
4773 * Acts as a transducer if a transformer is given in list position.
4774 * @see R.transduce
4775 *
4776 * @func
4777 * @memberOf R
4778 * @category List
4779 * @sig (a -> Boolean) -> [a] -> Number
4780 * @param {Function} fn The predicate function used to determine if the element is the
4781 * desired one.
4782 * @param {Array} list The array to consider.
4783 * @return {Number} The index of the element found, or `-1`.
4784 * @example
4785 *
4786 * var xs = [{a: 1}, {a: 2}, {a: 3}];
4787 * R.findIndex(R.propEq('a', 2))(xs); //=> 1
4788 * R.findIndex(R.propEq('a', 4))(xs); //=> -1
4789 */
4790 var findIndex = _curry2(_dispatchable('findIndex', _xfindIndex, function findIndex(fn, list) {
4791 var idx = 0;
4792 var len = list.length;
4793 while (idx < len) {
4794 if (fn(list[idx])) {
4795 return idx;
4796 }
4797 idx += 1;
4798 }
4799 return -1;
4800 }));
4801
4802 /**
4803 * Returns the last element of the list which matches the predicate, or `undefined` if no
4804 * element matches.
4805 *
4806 * Acts as a transducer if a transformer is given in list position.
4807 * @see R.transduce
4808 *
4809 * @func
4810 * @memberOf R
4811 * @category List
4812 * @sig (a -> Boolean) -> [a] -> a | undefined
4813 * @param {Function} fn The predicate function used to determine if the element is the
4814 * desired one.
4815 * @param {Array} list The array to consider.
4816 * @return {Object} The element found, or `undefined`.
4817 * @example
4818 *
4819 * var xs = [{a: 1, b: 0}, {a:1, b: 1}];
4820 * R.findLast(R.propEq('a', 1))(xs); //=> {a: 1, b: 1}
4821 * R.findLast(R.propEq('a', 4))(xs); //=> undefined
4822 */
4823 var findLast = _curry2(_dispatchable('findLast', _xfindLast, function findLast(fn, list) {
4824 var idx = list.length - 1;
4825 while (idx >= 0) {
4826 if (fn(list[idx])) {
4827 return list[idx];
4828 }
4829 idx -= 1;
4830 }
4831 }));
4832
4833 /**
4834 * Returns the index of the last element of the list which matches the predicate, or
4835 * `-1` if no element matches.
4836 *
4837 * Acts as a transducer if a transformer is given in list position.
4838 * @see R.transduce
4839 *
4840 * @func
4841 * @memberOf R
4842 * @category List
4843 * @sig (a -> Boolean) -> [a] -> Number
4844 * @param {Function} fn The predicate function used to determine if the element is the
4845 * desired one.
4846 * @param {Array} list The array to consider.
4847 * @return {Number} The index of the element found, or `-1`.
4848 * @example
4849 *
4850 * var xs = [{a: 1, b: 0}, {a:1, b: 1}];
4851 * R.findLastIndex(R.propEq('a', 1))(xs); //=> 1
4852 * R.findLastIndex(R.propEq('a', 4))(xs); //=> -1
4853 */
4854 var findLastIndex = _curry2(_dispatchable('findLastIndex', _xfindLastIndex, function findLastIndex(fn, list) {
4855 var idx = list.length - 1;
4856 while (idx >= 0) {
4857 if (fn(list[idx])) {
4858 return idx;
4859 }
4860 idx -= 1;
4861 }
4862 return -1;
4863 }));
4864
4865 /**
4866 * Returns a new list by pulling every item out of it (and all its sub-arrays) and putting
4867 * them in a new array, depth-first.
4868 *
4869 * @func
4870 * @memberOf R
4871 * @category List
4872 * @sig [a] -> [b]
4873 * @param {Array} list The array to consider.
4874 * @return {Array} The flattened list.
4875 * @see R.unnest
4876 * @example
4877 *
4878 * R.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]);
4879 * //=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
4880 */
4881 var flatten = _curry1(_makeFlat(true));
4882
4883 /**
4884 * Returns a new function much like the supplied one, except that the first two arguments'
4885 * order is reversed.
4886 *
4887 * @func
4888 * @memberOf R
4889 * @category Function
4890 * @sig (a -> b -> c -> ... -> z) -> (b -> a -> c -> ... -> z)
4891 * @param {Function} fn The function to invoke with its first two parameters reversed.
4892 * @return {*} The result of invoking `fn` with its first two parameters' order reversed.
4893 * @example
4894 *
4895 * var mergeThree = function(a, b, c) {
4896 * return ([]).concat(a, b, c);
4897 * };
4898 *
4899 * mergeThree(1, 2, 3); //=> [1, 2, 3]
4900 *
4901 * R.flip(mergeThree)(1, 2, 3); //=> [2, 1, 3]
4902 */
4903 var flip = _curry1(function flip(fn) {
4904 return curry(function (a, b) {
4905 var args = _slice(arguments);
4906 args[0] = b;
4907 args[1] = a;
4908 return fn.apply(this, args);
4909 });
4910 });
4911
4912 /**
4913 * Iterate over an input `list`, calling a provided function `fn` for each element in the
4914 * list.
4915 *
4916 * `fn` receives one argument: *(value)*.
4917 *
4918 * Note: `R.forEach` does not skip deleted or unassigned indices (sparse arrays), unlike
4919 * the native `Array.prototype.forEach` method. For more details on this behavior, see:
4920 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Description
4921 *
4922 * Also note that, unlike `Array.prototype.forEach`, Ramda's `forEach` returns the original
4923 * array. In some libraries this function is named `each`.
4924 *
4925 * @func
4926 * @memberOf R
4927 * @category List
4928 * @sig (a -> *) -> [a] -> [a]
4929 * @param {Function} fn The function to invoke. Receives one argument, `value`.
4930 * @param {Array} list The list to iterate over.
4931 * @return {Array} The original list.
4932 * @example
4933 *
4934 * var printXPlusFive = function(x) { console.log(x + 5); };
4935 * R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3]
4936 * //-> 6
4937 * //-> 7
4938 * //-> 8
4939 */
4940 var forEach = _curry2(_checkForMethod('forEach', function forEach(fn, list) {
4941 var len = list.length;
4942 var idx = 0;
4943 while (idx < len) {
4944 fn(list[idx]);
4945 idx += 1;
4946 }
4947 return list;
4948 }));
4949
4950 /**
4951 * Returns a list of function names of object's own functions
4952 *
4953 * @func
4954 * @memberOf R
4955 * @category Object
4956 * @sig {*} -> [String]
4957 * @param {Object} obj The objects with functions in it
4958 * @return {Array} A list of the object's own properties that map to functions.
4959 * @example
4960 *
4961 * R.functions(R); // returns list of ramda's own function names
4962 *
4963 * var F = function() { this.x = function(){}; this.y = 1; }
4964 * F.prototype.z = function() {};
4965 * F.prototype.a = 100;
4966 * R.functions(new F()); //=> ["x"]
4967 */
4968 var functions = _curry1(_functionsWith(keys));
4969
4970 /**
4971 * Returns a list of function names of object's own and prototype functions
4972 *
4973 * @func
4974 * @memberOf R
4975 * @category Object
4976 * @sig {*} -> [String]
4977 * @param {Object} obj The objects with functions in it
4978 * @return {Array} A list of the object's own properties and prototype
4979 * properties that map to functions.
4980 * @example
4981 *
4982 * R.functionsIn(R); // returns list of ramda's own and prototype function names
4983 *
4984 * var F = function() { this.x = function(){}; this.y = 1; }
4985 * F.prototype.z = function() {};
4986 * F.prototype.a = 100;
4987 * R.functionsIn(new F()); //=> ["x", "z"]
4988 */
4989 var functionsIn = _curry1(_functionsWith(keysIn));
4990
4991 /**
4992 * Splits a list into sub-lists stored in an object, based on the result of calling a String-returning function
4993 * on each element, and grouping the results according to values returned.
4994 *
4995 * Acts as a transducer if a transformer is given in list position.
4996 * @see R.transduce
4997 *
4998 * @func
4999 * @memberOf R
5000 * @category List
5001 * @sig (a -> String) -> [a] -> {String: [a]}
5002 * @param {Function} fn Function :: a -> String
5003 * @param {Array} list The array to group
5004 * @return {Object} An object with the output of `fn` for keys, mapped to arrays of elements
5005 * that produced that key when passed to `fn`.
5006 * @example
5007 *
5008 * var byGrade = R.groupBy(function(student) {
5009 * var score = student.score;
5010 * return score < 65 ? 'F' :
5011 * score < 70 ? 'D' :
5012 * score < 80 ? 'C' :
5013 * score < 90 ? 'B' : 'A';
5014 * });
5015 * var students = [{name: 'Abby', score: 84},
5016 * {name: 'Eddy', score: 58},
5017 * // ...
5018 * {name: 'Jack', score: 69}];
5019 * byGrade(students);
5020 * // {
5021 * // 'A': [{name: 'Dianne', score: 99}],
5022 * // 'B': [{name: 'Abby', score: 84}]
5023 * // // ...,
5024 * // 'F': [{name: 'Eddy', score: 58}]
5025 * // }
5026 */
5027 var groupBy = _curry2(_dispatchable('groupBy', _xgroupBy, function groupBy(fn, list) {
5028 return _reduce(function (acc, elt) {
5029 var key = fn(elt);
5030 acc[key] = append(elt, acc[key] || (acc[key] = []));
5031 return acc;
5032 }, {}, list);
5033 }));
5034
5035 /**
5036 * Returns the first element of the given list or string. In some libraries
5037 * this function is named `first`.
5038 *
5039 * @func
5040 * @memberOf R
5041 * @category List
5042 * @see R.tail, R.init, R.last
5043 * @sig [a] -> a | Undefined
5044 * @sig String -> String
5045 * @param {*} list
5046 * @return {*}
5047 * @example
5048 *
5049 * R.head(['fi', 'fo', 'fum']); //=> 'fi'
5050 * R.head([]); //=> undefined
5051 *
5052 * R.head('abc'); //=> 'a'
5053 * R.head(''); //=> ''
5054 */
5055 var head = nth(0);
5056
5057 /**
5058 * Combines two lists into a set (i.e. no duplicates) composed of those
5059 * elements common to both lists. Duplication is determined according
5060 * to the value returned by applying the supplied predicate to two list
5061 * elements.
5062 *
5063 * @func
5064 * @memberOf R
5065 * @category Relation
5066 * @sig (a,a -> Boolean) -> [a] -> [a] -> [a]
5067 * @param {Function} pred A predicate function that determines whether
5068 * the two supplied elements are equal.
5069 * @param {Array} list1 One list of items to compare
5070 * @param {Array} list2 A second list of items to compare
5071 * @see R.intersection
5072 * @return {Array} A new list containing those elements common to both lists.
5073 * @example
5074 *
5075 * var buffaloSpringfield = [
5076 * {id: 824, name: 'Richie Furay'},
5077 * {id: 956, name: 'Dewey Martin'},
5078 * {id: 313, name: 'Bruce Palmer'},
5079 * {id: 456, name: 'Stephen Stills'},
5080 * {id: 177, name: 'Neil Young'}
5081 * ];
5082 * var csny = [
5083 * {id: 204, name: 'David Crosby'},
5084 * {id: 456, name: 'Stephen Stills'},
5085 * {id: 539, name: 'Graham Nash'},
5086 * {id: 177, name: 'Neil Young'}
5087 * ];
5088 *
5089 * var sameId = function(o1, o2) {return o1.id === o2.id;};
5090 *
5091 * R.intersectionWith(sameId, buffaloSpringfield, csny);
5092 * //=> [{id: 456, name: 'Stephen Stills'}, {id: 177, name: 'Neil Young'}]
5093 */
5094 var intersectionWith = _curry3(function intersectionWith(pred, list1, list2) {
5095 var results = [], idx = 0;
5096 while (idx < list1.length) {
5097 if (_containsWith(pred, list1[idx], list2)) {
5098 results[results.length] = list1[idx];
5099 }
5100 idx += 1;
5101 }
5102 return uniqWith(pred, results);
5103 });
5104
5105 /**
5106 * Creates a new list with the separator interposed between elements.
5107 *
5108 * @func
5109 * @memberOf R
5110 * @category List
5111 * @sig a -> [a] -> [a]
5112 * @param {*} separator The element to add to the list.
5113 * @param {Array} list The list to be interposed.
5114 * @return {Array} The new list.
5115 * @example
5116 *
5117 * R.intersperse('n', ['ba', 'a', 'a']); //=> ['ba', 'n', 'a', 'n', 'a']
5118 */
5119 var intersperse = _curry2(_checkForMethod('intersperse', function intersperse(separator, list) {
5120 var out = [];
5121 var idx = 0;
5122 var length = list.length;
5123 while (idx < length) {
5124 if (idx === length - 1) {
5125 out.push(list[idx]);
5126 } else {
5127 out.push(list[idx], separator);
5128 }
5129 idx += 1;
5130 }
5131 return out;
5132 }));
5133
5134 /**
5135 * Transforms the items of the list with the transducer and appends the transformed items to
5136 * the accumulator using an appropriate iterator function based on the accumulator type.
5137 *
5138 * The accumulator can be an array, string, object or a transformer. Iterated items will
5139 * be appended to arrays and concatenated to strings. Objects will be merged directly or 2-item
5140 * arrays will be merged as key, value pairs.
5141 *
5142 * The accumulator can also be a transformer object that provides a 2-arity reducing iterator
5143 * function, step, 0-arity initial value function, init, and 1-arity result extraction function
5144 * result. The step function is used as the iterator function in reduce. The result function is
5145 * used to convert the final accumulator into the return type and in most cases is R.identity.
5146 * The init function is used to provide the initial accumulator.
5147 *
5148 * The iteration is performed with R.reduce after initializing the transducer.
5149 *
5150 * @func
5151 * @memberOf R
5152 * @category List
5153 * @sig a -> (b -> b) -> [c] -> a
5154 * @param {*} acc The initial accumulator value.
5155 * @param {Function} xf The transducer function. Receives a transformer and returns a transformer.
5156 * @param {Array} list The list to iterate over.
5157 * @return {*} The final, accumulated value.
5158 * @example
5159 *
5160 * var numbers = [1, 2, 3, 4];
5161 * var transducer = R.compose(R.map(R.add(1)), R.take(2));
5162 *
5163 * R.into([], transducer, numbers); //=> [2, 3]
5164 *
5165 * var intoArray = R.into([]);
5166 * intoArray(transducer, numbers); //=> [2, 3]
5167 */
5168 var into = _curry3(function into(acc, xf, list) {
5169 return _isTransformer(acc) ? _reduce(xf(acc), acc['@@transducer/init'](), list) : _reduce(xf(_stepCat(acc)), acc, list);
5170 });
5171
5172 /**
5173 * Same as R.invertObj, however this accounts for objects
5174 * with duplicate values by putting the values into an
5175 * array.
5176 *
5177 * @func
5178 * @memberOf R
5179 * @category Object
5180 * @sig {s: x} -> {x: [ s, ... ]}
5181 * @param {Object} obj The object or array to invert
5182 * @return {Object} out A new object with keys
5183 * in an array.
5184 * @example
5185 *
5186 * var raceResultsByFirstName = {
5187 * first: 'alice',
5188 * second: 'jake',
5189 * third: 'alice',
5190 * };
5191 * R.invert(raceResultsByFirstName);
5192 * //=> { 'alice': ['first', 'third'], 'jake':['second'] }
5193 */
5194 var invert = _curry1(function invert(obj) {
5195 var props = keys(obj);
5196 var len = props.length;
5197 var idx = 0;
5198 var out = {};
5199 while (idx < len) {
5200 var key = props[idx];
5201 var val = obj[key];
5202 var list = _has(val, out) ? out[val] : out[val] = [];
5203 list[list.length] = key;
5204 idx += 1;
5205 }
5206 return out;
5207 });
5208
5209 /**
5210 * Returns a new object with the keys of the given object
5211 * as values, and the values of the given object as keys.
5212 *
5213 * @func
5214 * @memberOf R
5215 * @category Object
5216 * @sig {s: x} -> {x: s}
5217 * @param {Object} obj The object or array to invert
5218 * @return {Object} out A new object
5219 * @example
5220 *
5221 * var raceResults = {
5222 * first: 'alice',
5223 * second: 'jake'
5224 * };
5225 * R.invertObj(raceResults);
5226 * //=> { 'alice': 'first', 'jake':'second' }
5227 *
5228 * // Alternatively:
5229 * var raceResults = ['alice', 'jake'];
5230 * R.invertObj(raceResults);
5231 * //=> { 'alice': '0', 'jake':'1' }
5232 */
5233 var invertObj = _curry1(function invertObj(obj) {
5234 var props = keys(obj);
5235 var len = props.length;
5236 var idx = 0;
5237 var out = {};
5238 while (idx < len) {
5239 var key = props[idx];
5240 out[obj[key]] = key;
5241 idx += 1;
5242 }
5243 return out;
5244 });
5245
5246 /**
5247 * Returns the last element of the given list or string.
5248 *
5249 * @func
5250 * @memberOf R
5251 * @category List
5252 * @see R.init, R.head, R.tail
5253 * @sig [a] -> a | Undefined
5254 * @sig String -> String
5255 * @param {*} list
5256 * @return {*}
5257 * @example
5258 *
5259 * R.last(['fi', 'fo', 'fum']); //=> 'fum'
5260 * R.last([]); //=> undefined
5261 *
5262 * R.last('abc'); //=> 'c'
5263 * R.last(''); //=> ''
5264 */
5265 var last = nth(-1);
5266
5267 /**
5268 * Returns the position of the last occurrence of an item in
5269 * an array, or -1 if the item is not included in the array.
5270 * `R.equals` is used to determine equality.
5271 *
5272 * @func
5273 * @memberOf R
5274 * @category List
5275 * @sig a -> [a] -> Number
5276 * @param {*} target The item to find.
5277 * @param {Array} xs The array to search in.
5278 * @return {Number} the index of the target, or -1 if the target is not found.
5279 * @see R.indexOf
5280 * @example
5281 *
5282 * R.lastIndexOf(3, [-1,3,3,0,1,2,3,4]); //=> 6
5283 * R.lastIndexOf(10, [1,2,3,4]); //=> -1
5284 */
5285 var lastIndexOf = _curry2(function lastIndexOf(target, xs) {
5286 if (_hasMethod('lastIndexOf', xs)) {
5287 return xs.lastIndexOf(target);
5288 } else {
5289 var idx = xs.length - 1;
5290 while (idx >= 0) {
5291 if (equals(xs[idx], target)) {
5292 return idx;
5293 }
5294 idx -= 1;
5295 }
5296 return -1;
5297 }
5298 });
5299
5300 /**
5301 * Returns a new list, constructed by applying the supplied function to every element of the
5302 * supplied list.
5303 *
5304 * Note: `R.map` does not skip deleted or unassigned indices (sparse arrays), unlike the
5305 * native `Array.prototype.map` method. For more details on this behavior, see:
5306 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map#Description
5307 *
5308 * Acts as a transducer if a transformer is given in list position.
5309 * @see R.transduce
5310 *
5311 * @func
5312 * @memberOf R
5313 * @category List
5314 * @sig (a -> b) -> [a] -> [b]
5315 * @param {Function} fn The function to be called on every element of the input `list`.
5316 * @param {Array} list The list to be iterated over.
5317 * @return {Array} The new list.
5318 * @example
5319 *
5320 * var double = function(x) {
5321 * return x * 2;
5322 * };
5323 *
5324 * R.map(double, [1, 2, 3]); //=> [2, 4, 6]
5325 */
5326 var map = _curry2(_dispatchable('map', _xmap, _map));
5327
5328 /**
5329 * Map, but for objects. Creates an object with the same keys as `obj` and values
5330 * generated by running each property of `obj` through `fn`. `fn` is passed one argument:
5331 * *(value)*.
5332 *
5333 * @func
5334 * @memberOf R
5335 * @category Object
5336 * @sig (v -> v) -> {k: v} -> {k: v}
5337 * @param {Function} fn A function called for each property in `obj`. Its return value will
5338 * become a new property on the return object.
5339 * @param {Object} obj The object to iterate over.
5340 * @return {Object} A new object with the same keys as `obj` and values that are the result
5341 * of running each property through `fn`.
5342 * @example
5343 *
5344 * var values = { x: 1, y: 2, z: 3 };
5345 * var double = function(num) {
5346 * return num * 2;
5347 * };
5348 *
5349 * R.mapObj(double, values); //=> { x: 2, y: 4, z: 6 }
5350 */
5351 var mapObj = _curry2(function mapObj(fn, obj) {
5352 return _reduce(function (acc, key) {
5353 acc[key] = fn(obj[key]);
5354 return acc;
5355 }, {}, keys(obj));
5356 });
5357
5358 /**
5359 * Like `mapObj`, but but passes additional arguments to the predicate function. The
5360 * predicate function is passed three arguments: *(value, key, obj)*.
5361 *
5362 * @func
5363 * @memberOf R
5364 * @category Object
5365 * @sig (v, k, {k: v} -> v) -> {k: v} -> {k: v}
5366 * @param {Function} fn A function called for each property in `obj`. Its return value will
5367 * become a new property on the return object.
5368 * @param {Object} obj The object to iterate over.
5369 * @return {Object} A new object with the same keys as `obj` and values that are the result
5370 * of running each property through `fn`.
5371 * @example
5372 *
5373 * var values = { x: 1, y: 2, z: 3 };
5374 * var prependKeyAndDouble = function(num, key, obj) {
5375 * return key + (num * 2);
5376 * };
5377 *
5378 * R.mapObjIndexed(prependKeyAndDouble, values); //=> { x: 'x2', y: 'y4', z: 'z6' }
5379 */
5380 var mapObjIndexed = _curry2(function mapObjIndexed(fn, obj) {
5381 return _reduce(function (acc, key) {
5382 acc[key] = fn(obj[key], key, obj);
5383 return acc;
5384 }, {}, keys(obj));
5385 });
5386
5387 /**
5388 * Returns `true` if no elements of the list match the predicate,
5389 * `false` otherwise.
5390 *
5391 * @func
5392 * @memberOf R
5393 * @category List
5394 * @sig (a -> Boolean) -> [a] -> Boolean
5395 * @param {Function} fn The predicate function.
5396 * @param {Array} list The array to consider.
5397 * @return {Boolean} `true` if the predicate is not satisfied by every element, `false` otherwise.
5398 * @see R.all, R.any
5399 * @example
5400 *
5401 * R.none(R.isNaN, [1, 2, 3]); //=> true
5402 * R.none(R.isNaN, [1, 2, 3, NaN]); //=> false
5403 */
5404 var none = _curry2(_complement(_dispatchable('any', _xany, any)));
5405
5406 /**
5407 * A function that returns the first truthy of two arguments otherwise the
5408 * last argument. Note that this is NOT short-circuited, meaning that if
5409 * expressions are passed they are both evaluated.
5410 *
5411 * Dispatches to the `or` method of the first argument if applicable.
5412 *
5413 * @func
5414 * @memberOf R
5415 * @category Logic
5416 * @sig * -> * -> *
5417 * @param {*} a any value
5418 * @param {*} b any other value
5419 * @return {*} the first truthy argument, otherwise the last argument.
5420 * @see R.either
5421 * @example
5422 *
5423 * R.or(false, true); //=> true
5424 * R.or(0, []); //=> []
5425 * R.or(null, ''); => ''
5426 */
5427 var or = _curry2(function or(a, b) {
5428 return _hasMethod('or', a) ? a.or(b) : a || b;
5429 });
5430
5431 /**
5432 * Accepts as its arguments a function and any number of values and returns a function that,
5433 * when invoked, calls the original function with all of the values prepended to the
5434 * original function's arguments list. In some libraries this function is named `applyLeft`.
5435 *
5436 * @func
5437 * @memberOf R
5438 * @category Function
5439 * @sig (a -> b -> ... -> i -> j -> ... -> m -> n) -> a -> b-> ... -> i -> (j -> ... -> m -> n)
5440 * @param {Function} fn The function to invoke.
5441 * @param {...*} [args] Arguments to prepend to `fn` when the returned function is invoked.
5442 * @return {Function} A new function wrapping `fn`. When invoked, it will call `fn`
5443 * with `args` prepended to `fn`'s arguments list.
5444 * @example
5445 *
5446 * var multiply = function(a, b) { return a * b; };
5447 * var double = R.partial(multiply, 2);
5448 * double(2); //=> 4
5449 *
5450 * var greet = function(salutation, title, firstName, lastName) {
5451 * return salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';
5452 * };
5453 * var sayHello = R.partial(greet, 'Hello');
5454 * var sayHelloToMs = R.partial(sayHello, 'Ms.');
5455 * sayHelloToMs('Jane', 'Jones'); //=> 'Hello, Ms. Jane Jones!'
5456 */
5457 var partial = curry(_createPartialApplicator(_concat));
5458
5459 /**
5460 * Accepts as its arguments a function and any number of values and returns a function that,
5461 * when invoked, calls the original function with all of the values appended to the original
5462 * function's arguments list.
5463 *
5464 * Note that `partialRight` is the opposite of `partial`: `partialRight` fills `fn`'s arguments
5465 * from the right to the left. In some libraries this function is named `applyRight`.
5466 *
5467 * @func
5468 * @memberOf R
5469 * @category Function
5470 * @sig (a -> b-> ... -> i -> j -> ... -> m -> n) -> j -> ... -> m -> n -> (a -> b-> ... -> i)
5471 * @param {Function} fn The function to invoke.
5472 * @param {...*} [args] Arguments to append to `fn` when the returned function is invoked.
5473 * @return {Function} A new function wrapping `fn`. When invoked, it will call `fn` with
5474 * `args` appended to `fn`'s arguments list.
5475 * @example
5476 *
5477 * var greet = function(salutation, title, firstName, lastName) {
5478 * return salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';
5479 * };
5480 * var greetMsJaneJones = R.partialRight(greet, 'Ms.', 'Jane', 'Jones');
5481 *
5482 * greetMsJaneJones('Hello'); //=> 'Hello, Ms. Jane Jones!'
5483 */
5484 var partialRight = curry(_createPartialApplicator(flip(_concat)));
5485
5486 /**
5487 * Takes a predicate and a list and returns the pair of lists of
5488 * elements which do and do not satisfy the predicate, respectively.
5489 *
5490 * @func
5491 * @memberOf R
5492 * @category List
5493 * @sig (a -> Boolean) -> [a] -> [[a],[a]]
5494 * @param {Function} pred A predicate to determine which array the element belongs to.
5495 * @param {Array} list The array to partition.
5496 * @return {Array} A nested array, containing first an array of elements that satisfied the predicate,
5497 * and second an array of elements that did not satisfy.
5498 * @example
5499 *
5500 * R.partition(R.contains('s'), ['sss', 'ttt', 'foo', 'bars']);
5501 * //=> [ [ 'sss', 'bars' ], [ 'ttt', 'foo' ] ]
5502 */
5503 var partition = _curry2(function partition(pred, list) {
5504 return _reduce(function (acc, elt) {
5505 var xs = acc[pred(elt) ? 0 : 1];
5506 xs[xs.length] = elt;
5507 return acc;
5508 }, [
5509 [],
5510 []
5511 ], list);
5512 });
5513
5514 /**
5515 * Determines whether a nested path on an object has a specific value,
5516 * in `R.equals` terms. Most likely used to filter a list.
5517 *
5518 * @func
5519 * @memberOf R
5520 * @category Relation
5521 * @sig [String] -> * -> {String: *} -> Boolean
5522 * @param {Array} path The path of the nested property to use
5523 * @param {*} val The value to compare the nested property with
5524 * @param {Object} obj The object to check the nested property in
5525 * @return {Boolean} `true` if the value equals the nested object property,
5526 * `false` otherwise.
5527 * @example
5528 *
5529 * var user1 = { address: { zipCode: 90210 } };
5530 * var user2 = { address: { zipCode: 55555 } };
5531 * var user3 = { name: 'Bob' };
5532 * var users = [ user1, user2, user3 ];
5533 * var isFamous = R.pathEq(['address', 'zipCode'], 90210);
5534 * R.filter(isFamous, users); //=> [ user1 ]
5535 */
5536 var pathEq = _curry3(function pathEq(_path, val, obj) {
5537 return equals(path(_path, obj), val);
5538 });
5539
5540 /**
5541 * Returns a new list by plucking the same named property off all objects in the list supplied.
5542 *
5543 * @func
5544 * @memberOf R
5545 * @category List
5546 * @sig k -> [{k: v}] -> [v]
5547 * @param {Number|String} key The key name to pluck off of each object.
5548 * @param {Array} list The array to consider.
5549 * @return {Array} The list of values for the given key.
5550 * @example
5551 *
5552 * R.pluck('a')([{a: 1}, {a: 2}]); //=> [1, 2]
5553 * R.pluck(0)([[1, 2], [3, 4]]); //=> [1, 3]
5554 */
5555 var pluck = _curry2(function pluck(p, list) {
5556 return map(prop(p), list);
5557 });
5558
5559 /**
5560 * Returns `true` if the specified object property is equal, in `R.equals`
5561 * terms, to the given value; `false` otherwise.
5562 *
5563 * @func
5564 * @memberOf R
5565 * @category Relation
5566 * @sig String -> a -> Object -> Boolean
5567 * @param {String} name
5568 * @param {*} val
5569 * @param {*} obj
5570 * @return {Boolean}
5571 * @see R.equals, R.propSatisfies
5572 * @example
5573 *
5574 * var abby = {name: 'Abby', age: 7, hair: 'blond'};
5575 * var fred = {name: 'Fred', age: 12, hair: 'brown'};
5576 * var rusty = {name: 'Rusty', age: 10, hair: 'brown'};
5577 * var alois = {name: 'Alois', age: 15, disposition: 'surly'};
5578 * var kids = [abby, fred, rusty, alois];
5579 * var hasBrownHair = R.propEq('hair', 'brown');
5580 * R.filter(hasBrownHair, kids); //=> [fred, rusty]
5581 */
5582 var propEq = _curry3(function propEq(name, val, obj) {
5583 return propSatisfies(equals(val), name, obj);
5584 });
5585
5586 /**
5587 * Returns `true` if the specified object property is of the given type;
5588 * `false` otherwise.
5589 *
5590 * @func
5591 * @memberOf R
5592 * @category Type
5593 * @sig Type -> String -> Object -> Boolean
5594 * @param {Function} type
5595 * @param {String} name
5596 * @param {*} obj
5597 * @return {Boolean}
5598 * @see R.is
5599 * @see R.propSatisfies
5600 * @example
5601 *
5602 * R.propIs(Number, 'x', {x: 1, y: 2}); //=> true
5603 * R.propIs(Number, 'x', {x: 'foo'}); //=> false
5604 * R.propIs(Number, 'x', {}); //=> false
5605 */
5606 var propIs = _curry3(function propIs(type, name, obj) {
5607 return propSatisfies(is(type), name, obj);
5608 });
5609
5610 /**
5611 * Returns a single item by iterating through the list, successively calling the iterator
5612 * function and passing it an accumulator value and the current value from the array, and
5613 * then passing the result to the next call.
5614 *
5615 * The iterator function receives two values: *(acc, value)*. It may use `R.reduced` to
5616 * shortcut the iteration.
5617 *
5618 * Note: `R.reduce` does not skip deleted or unassigned indices (sparse arrays), unlike
5619 * the native `Array.prototype.reduce` method. For more details on this behavior, see:
5620 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#Description
5621 * @see R.reduced
5622 *
5623 * @func
5624 * @memberOf R
5625 * @category List
5626 * @sig (a,b -> a) -> a -> [b] -> a
5627 * @param {Function} fn The iterator function. Receives two values, the accumulator and the
5628 * current element from the array.
5629 * @param {*} acc The accumulator value.
5630 * @param {Array} list The list to iterate over.
5631 * @return {*} The final, accumulated value.
5632 * @example
5633 *
5634 * var numbers = [1, 2, 3];
5635 * var add = function(a, b) {
5636 * return a + b;
5637 * };
5638 *
5639 * R.reduce(add, 10, numbers); //=> 16
5640 */
5641 var reduce = _curry3(_reduce);
5642
5643 /**
5644 * Similar to `filter`, except that it keeps only values for which the given predicate
5645 * function returns falsy. The predicate function is passed one argument: *(value)*.
5646 *
5647 * Acts as a transducer if a transformer is given in list position.
5648 * @see R.transduce
5649 *
5650 * @func
5651 * @memberOf R
5652 * @category List
5653 * @sig (a -> Boolean) -> [a] -> [a]
5654 * @param {Function} fn The function called per iteration.
5655 * @param {Array} list The collection to iterate over.
5656 * @return {Array} The new filtered array.
5657 * @see R.filter
5658 * @example
5659 *
5660 * var isOdd = function(n) {
5661 * return n % 2 === 1;
5662 * };
5663 * R.reject(isOdd, [1, 2, 3, 4]); //=> [2, 4]
5664 */
5665 var reject = _curry2(function reject(fn, list) {
5666 return filter(_complement(fn), list);
5667 });
5668
5669 /**
5670 * Returns a fixed list of size `n` containing a specified identical value.
5671 *
5672 * @func
5673 * @memberOf R
5674 * @category List
5675 * @sig a -> n -> [a]
5676 * @param {*} value The value to repeat.
5677 * @param {Number} n The desired size of the output list.
5678 * @return {Array} A new array containing `n` `value`s.
5679 * @example
5680 *
5681 * R.repeat('hi', 5); //=> ['hi', 'hi', 'hi', 'hi', 'hi']
5682 *
5683 * var obj = {};
5684 * var repeatedObjs = R.repeat(obj, 5); //=> [{}, {}, {}, {}, {}]
5685 * repeatedObjs[0] === repeatedObjs[1]; //=> true
5686 */
5687 var repeat = _curry2(function repeat(value, n) {
5688 return times(always(value), n);
5689 });
5690
5691 /**
5692 * Returns the elements of the given list or string (or object with a `slice`
5693 * method) from `fromIndex` (inclusive) to `toIndex` (exclusive).
5694 *
5695 * @func
5696 * @memberOf R
5697 * @category List
5698 * @sig Number -> Number -> [a] -> [a]
5699 * @sig Number -> Number -> String -> String
5700 * @param {Number} fromIndex The start index (inclusive).
5701 * @param {Number} toIndex The end index (exclusive).
5702 * @param {*} list
5703 * @return {*}
5704 * @example
5705 *
5706 * R.slice(1, 3, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
5707 * R.slice(1, Infinity, ['a', 'b', 'c', 'd']); //=> ['b', 'c', 'd']
5708 * R.slice(0, -1, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c']
5709 * R.slice(-3, -1, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
5710 * R.slice(0, 3, 'ramda'); //=> 'ram'
5711 */
5712 var slice = _curry3(_checkForMethod('slice', function slice(fromIndex, toIndex, list) {
5713 return Array.prototype.slice.call(list, fromIndex, toIndex);
5714 }));
5715
5716 /**
5717 * Splits a collection into slices of the specified length.
5718 *
5719 * @func
5720 * @memberOf R
5721 * @category List
5722 * @sig Number -> [a] -> [[a]]
5723 * @sig Number -> String -> [String]
5724 * @param {Number} n
5725 * @param {Array} list
5726 * @return {Array}
5727 * @example
5728 *
5729 * R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]); //=> [[1, 2, 3], [4, 5, 6], [7]]
5730 * R.splitEvery(3, 'foobarbaz'); //=> ['foo', 'bar', 'baz']
5731 */
5732 var splitEvery = _curry2(function splitEvery(n, list) {
5733 if (n <= 0) {
5734 throw new Error('First argument to splitEvery must be a positive integer');
5735 }
5736 var result = [];
5737 var idx = 0;
5738 while (idx < list.length) {
5739 result.push(slice(idx, idx += n, list));
5740 }
5741 return result;
5742 });
5743
5744 /**
5745 * Adds together all the elements of a list.
5746 *
5747 * @func
5748 * @memberOf R
5749 * @category Math
5750 * @sig [Number] -> Number
5751 * @param {Array} list An array of numbers
5752 * @return {Number} The sum of all the numbers in the list.
5753 * @see R.reduce
5754 * @example
5755 *
5756 * R.sum([2,4,6,8,100,1]); //=> 121
5757 */
5758 var sum = reduce(add, 0);
5759
5760 /**
5761 * Returns all but the first element of the given list or string (or object
5762 * with a `tail` method).
5763 *
5764 * @func
5765 * @memberOf R
5766 * @category List
5767 * @see R.head, R.init, R.last
5768 * @sig [a] -> [a]
5769 * @sig String -> String
5770 * @param {*} list
5771 * @return {*}
5772 * @example
5773 *
5774 * R.tail([1, 2, 3]); //=> [2, 3]
5775 * R.tail([1, 2]); //=> [2]
5776 * R.tail([1]); //=> []
5777 * R.tail([]); //=> []
5778 *
5779 * R.tail('abc'); //=> 'bc'
5780 * R.tail('ab'); //=> 'b'
5781 * R.tail('a'); //=> ''
5782 * R.tail(''); //=> ''
5783 */
5784 var tail = _checkForMethod('tail', slice(1, Infinity));
5785
5786 /**
5787 * Returns the first `n` elements of the given list, string, or
5788 * transducer/transformer (or object with a `take` method).
5789 *
5790 * @func
5791 * @memberOf R
5792 * @category List
5793 * @sig Number -> [a] -> [a]
5794 * @sig Number -> String -> String
5795 * @param {Number} n
5796 * @param {*} list
5797 * @return {*}
5798 * @see R.drop
5799 * @example
5800 *
5801 * R.take(1, ['foo', 'bar', 'baz']); //=> ['foo']
5802 * R.take(2, ['foo', 'bar', 'baz']); //=> ['foo', 'bar']
5803 * R.take(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
5804 * R.take(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
5805 * R.take(3, 'ramda'); //=> 'ram'
5806 *
5807 * var personnel = [
5808 * 'Dave Brubeck',
5809 * 'Paul Desmond',
5810 * 'Eugene Wright',
5811 * 'Joe Morello',
5812 * 'Gerry Mulligan',
5813 * 'Bob Bates',
5814 * 'Joe Dodge',
5815 * 'Ron Crotty'
5816 * ];
5817 *
5818 * var takeFive = R.take(5);
5819 * takeFive(personnel);
5820 * //=> ['Dave Brubeck', 'Paul Desmond', 'Eugene Wright', 'Joe Morello', 'Gerry Mulligan']
5821 */
5822 var take = _curry2(_dispatchable('take', _xtake, function take(n, xs) {
5823 return slice(0, n < 0 ? Infinity : n, xs);
5824 }));
5825
5826 /**
5827 * Returns a new list containing the first `n` elements of a given list, passing each value
5828 * to the supplied predicate function, and terminating when the predicate function returns
5829 * `false`. Excludes the element that caused the predicate function to fail. The predicate
5830 * function is passed one argument: *(value)*.
5831 *
5832 * Acts as a transducer if a transformer is given in list position.
5833 * @see R.transduce
5834 *
5835 * @func
5836 * @memberOf R
5837 * @category List
5838 * @sig (a -> Boolean) -> [a] -> [a]
5839 * @param {Function} fn The function called per iteration.
5840 * @param {Array} list The collection to iterate over.
5841 * @return {Array} A new array.
5842 * @see R.dropWhile
5843 * @example
5844 *
5845 * var isNotFour = function(x) {
5846 * return !(x === 4);
5847 * };
5848 *
5849 * R.takeWhile(isNotFour, [1, 2, 3, 4]); //=> [1, 2, 3]
5850 */
5851 var takeWhile = _curry2(_dispatchable('takeWhile', _xtakeWhile, function takeWhile(fn, list) {
5852 var idx = 0, len = list.length;
5853 while (idx < len && fn(list[idx])) {
5854 idx += 1;
5855 }
5856 return _slice(list, 0, idx);
5857 }));
5858
5859 /**
5860 * Initializes a transducer using supplied iterator function. Returns a single item by
5861 * iterating through the list, successively calling the transformed iterator function and
5862 * passing it an accumulator value and the current value from the array, and then passing
5863 * the result to the next call.
5864 *
5865 * The iterator function receives two values: *(acc, value)*. It will be wrapped as a
5866 * transformer to initialize the transducer. A transformer can be passed directly in place
5867 * of an iterator function. In both cases, iteration may be stopped early with the
5868 * `R.reduced` function.
5869 *
5870 * A transducer is a function that accepts a transformer and returns a transformer and can
5871 * be composed directly.
5872 *
5873 * A transformer is an an object that provides a 2-arity reducing iterator function, step,
5874 * 0-arity initial value function, init, and 1-arity result extraction function, result.
5875 * The step function is used as the iterator function in reduce. The result function is used
5876 * to convert the final accumulator into the return type and in most cases is R.identity.
5877 * The init function can be used to provide an initial accumulator, but is ignored by transduce.
5878 *
5879 * The iteration is performed with R.reduce after initializing the transducer.
5880 *
5881 * @func
5882 * @memberOf R
5883 * @category List
5884 * @see R.reduce, R.reduced, R.into
5885 * @sig (c -> c) -> (a,b -> a) -> a -> [b] -> a
5886 * @param {Function} xf The transducer function. Receives a transformer and returns a transformer.
5887 * @param {Function} fn The iterator function. Receives two values, the accumulator and the
5888 * current element from the array. Wrapped as transformer, if necessary, and used to
5889 * initialize the transducer
5890 * @param {*} acc The initial accumulator value.
5891 * @param {Array} list The list to iterate over.
5892 * @return {*} The final, accumulated value.
5893 * @example
5894 *
5895 * var numbers = [1, 2, 3, 4];
5896 * var transducer = R.compose(R.map(R.add(1)), R.take(2));
5897 *
5898 * R.transduce(transducer, R.flip(R.append), [], numbers); //=> [2, 3]
5899 */
5900 var transduce = curryN(4, function transduce(xf, fn, acc, list) {
5901 return _reduce(xf(typeof fn === 'function' ? _xwrap(fn) : fn), acc, list);
5902 });
5903
5904 /**
5905 * Combines two lists into a set (i.e. no duplicates) composed of the elements of each list. Duplication is
5906 * determined according to the value returned by applying the supplied predicate to two list elements.
5907 *
5908 * @func
5909 * @memberOf R
5910 * @category Relation
5911 * @sig (a,a -> Boolean) -> [a] -> [a] -> [a]
5912 * @param {Function} pred A predicate used to test whether two items are equal.
5913 * @param {Array} list1 The first list.
5914 * @param {Array} list2 The second list.
5915 * @return {Array} The first and second lists concatenated, with
5916 * duplicates removed.
5917 * @see R.union
5918 * @example
5919 *
5920 * function cmp(x, y) { return x.a === y.a; }
5921 * var l1 = [{a: 1}, {a: 2}];
5922 * var l2 = [{a: 1}, {a: 4}];
5923 * R.unionWith(cmp, l1, l2); //=> [{a: 1}, {a: 2}, {a: 4}]
5924 */
5925 var unionWith = _curry3(function unionWith(pred, list1, list2) {
5926 return uniqWith(pred, _concat(list1, list2));
5927 });
5928
5929 /**
5930 * Returns a new list containing only one copy of each element in the original list.
5931 * `R.equals` is used to determine equality.
5932 *
5933 * @func
5934 * @memberOf R
5935 * @category List
5936 * @sig [a] -> [a]
5937 * @param {Array} list The array to consider.
5938 * @return {Array} The list of unique items.
5939 * @example
5940 *
5941 * R.uniq([1, 1, 2, 1]); //=> [1, 2]
5942 * R.uniq([1, '1']); //=> [1, '1']
5943 * R.uniq([[42], [42]]); //=> [[42]]
5944 */
5945 var uniq = uniqWith(equals);
5946
5947 /**
5948 * Returns a new list by pulling every item at the first level of nesting out, and putting
5949 * them in a new array.
5950 *
5951 * @func
5952 * @memberOf R
5953 * @category List
5954 * @sig [a] -> [b]
5955 * @param {Array} list The array to consider.
5956 * @return {Array} The flattened list.
5957 * @see R.flatten
5958 * @example
5959 *
5960 * R.unnest([1, [2], [[3]]]); //=> [1, 2, [3]]
5961 * R.unnest([[1, 2], [3, 4], [5, 6]]); //=> [1, 2, 3, 4, 5, 6]
5962 */
5963 var unnest = _curry1(_makeFlat(false));
5964
5965 /**
5966 * Accepts a function `fn` and any number of transformer functions and returns a new
5967 * function. When the new function is invoked, it calls the function `fn` with parameters
5968 * consisting of the result of calling each supplied handler on successive arguments to the
5969 * new function.
5970 *
5971 * If more arguments are passed to the returned function than transformer functions, those
5972 * arguments are passed directly to `fn` as additional parameters. If you expect additional
5973 * arguments that don't need to be transformed, although you can ignore them, it's best to
5974 * pass an identity function so that the new function reports the correct arity.
5975 *
5976 * @func
5977 * @memberOf R
5978 * @category Function
5979 * @sig (x1 -> x2 -> ... -> z) -> ((a -> x1), (b -> x2), ...) -> (a -> b -> ... -> z)
5980 * @param {Function} fn The function to wrap.
5981 * @param {...Function} transformers A variable number of transformer functions
5982 * @return {Function} The wrapped function.
5983 * @example
5984 *
5985 * var double = function(y) { return y * 2; };
5986 * var square = function(x) { return x * x; };
5987 * var add = function(a, b) { return a + b; };
5988 * // Adds any number of arguments together
5989 * var addAll = function() {
5990 * return R.reduce(add, 0, arguments);
5991 * };
5992 *
5993 * // Basic example
5994 * var addDoubleAndSquare = R.useWith(addAll, double, square);
5995 *
5996 * //≅ addAll(double(10), square(5));
5997 * addDoubleAndSquare(10, 5); //=> 45
5998 *
5999 * // Example of passing more arguments than transformers
6000 * //≅ addAll(double(10), square(5), 100);
6001 * addDoubleAndSquare(10, 5, 100); //=> 145
6002 *
6003 * // If there are extra _expected_ arguments that don't need to be transformed, although
6004 * // you can ignore them, it might be best to pass in the identity function so that the new
6005 * // function correctly reports arity.
6006 * var addDoubleAndSquareWithExtraParams = R.useWith(addAll, double, square, R.identity);
6007 * // addDoubleAndSquareWithExtraParams.length //=> 3
6008 * //≅ addAll(double(10), square(5), R.identity(100));
6009 * addDoubleAndSquare(10, 5, 100); //=> 145
6010 */
6011 /*, transformers */
6012 var useWith = curry(function useWith(fn) {
6013 var transformers = _slice(arguments, 1);
6014 var tlen = transformers.length;
6015 return curry(_arity(tlen, function () {
6016 var args = [], idx = 0;
6017 while (idx < tlen) {
6018 args[idx] = transformers[idx](arguments[idx]);
6019 idx += 1;
6020 }
6021 return fn.apply(this, args.concat(_slice(arguments, tlen)));
6022 }));
6023 });
6024
6025 /**
6026 * Takes a spec object and a test object; returns true if the test satisfies
6027 * the spec, false otherwise. An object satisfies the spec if, for each of the
6028 * spec's own properties, accessing that property of the object gives the same
6029 * value (in `R.equals` terms) as accessing that property of the spec.
6030 *
6031 * `whereEq` is a specialization of [`where`](#where).
6032 *
6033 * @func
6034 * @memberOf R
6035 * @category Object
6036 * @sig {String: *} -> {String: *} -> Boolean
6037 * @param {Object} spec
6038 * @param {Object} testObj
6039 * @return {Boolean}
6040 * @see R.where
6041 * @example
6042 *
6043 * // pred :: Object -> Boolean
6044 * var pred = R.whereEq({a: 1, b: 2});
6045 *
6046 * pred({a: 1}); //=> false
6047 * pred({a: 1, b: 2}); //=> true
6048 * pred({a: 1, b: 2, c: 3}); //=> true
6049 * pred({a: 1, b: 1}); //=> false
6050 */
6051 var whereEq = _curry2(function whereEq(spec, testObj) {
6052 return where(mapObj(equals, spec), testObj);
6053 });
6054
6055 var _flatCat = function () {
6056 var preservingReduced = function (xf) {
6057 return {
6058 '@@transducer/init': _xfBase.init,
6059 '@@transducer/result': function (result) {
6060 return xf['@@transducer/result'](result);
6061 },
6062 '@@transducer/step': function (result, input) {
6063 var ret = xf['@@transducer/step'](result, input);
6064 return ret['@@transducer/reduced'] ? _forceReduced(ret) : ret;
6065 }
6066 };
6067 };
6068 return function _xcat(xf) {
6069 var rxf = preservingReduced(xf);
6070 return {
6071 '@@transducer/init': _xfBase.init,
6072 '@@transducer/result': function (result) {
6073 return rxf['@@transducer/result'](result);
6074 },
6075 '@@transducer/step': function (result, input) {
6076 return !isArrayLike(input) ? _reduce(rxf, result, [input]) : _reduce(rxf, result, input);
6077 }
6078 };
6079 };
6080 }();
6081
6082 var _indexOf = function _indexOf(list, item, from) {
6083 var idx = from;
6084 while (idx < list.length) {
6085 if (equals(list[idx], item)) {
6086 return idx;
6087 }
6088 idx += 1;
6089 }
6090 return -1;
6091 };
6092
6093 /**
6094 * Create a predicate wrapper which will call a pick function (all/any) for each predicate
6095 *
6096 * @private
6097 * @see R.all
6098 * @see R.any
6099 */
6100 // Call function immediately if given arguments
6101 // Return a function which will call the predicates with the provided arguments
6102 var _predicateWrap = function _predicateWrap(predPicker) {
6103 return function (preds) {
6104 var predIterator = function () {
6105 var args = arguments;
6106 return predPicker(function (predicate) {
6107 return predicate.apply(null, args);
6108 }, preds);
6109 };
6110 return arguments.length > 1 ? // Call function immediately if given arguments
6111 predIterator.apply(null, _slice(arguments, 1)) : // Return a function which will call the predicates with the provided arguments
6112 _arity(Math.max.apply(Math, pluck('length', preds)), predIterator);
6113 };
6114 };
6115
6116 var _xchain = _curry2(function _xchain(f, xf) {
6117 return map(f, _flatCat(xf));
6118 });
6119
6120 /**
6121 * Given a list of predicates, returns a new predicate that will be true exactly when all of them are.
6122 *
6123 * @func
6124 * @memberOf R
6125 * @category Logic
6126 * @sig [(*... -> Boolean)] -> (*... -> Boolean)
6127 * @param {Array} list An array of predicate functions
6128 * @param {*} optional Any arguments to pass into the predicates
6129 * @return {Function} a function that applies its arguments to each of
6130 * the predicates, returning `true` if all are satisfied.
6131 * @see R.anyPass
6132 * @example
6133 *
6134 * var gt10 = function(x) { return x > 10; };
6135 * var even = function(x) { return x % 2 === 0};
6136 * var f = R.allPass([gt10, even]);
6137 * f(11); //=> false
6138 * f(12); //=> true
6139 */
6140 var allPass = _curry1(_predicateWrap(all));
6141
6142 /**
6143 * Given a list of predicates returns a new predicate that will be true exactly when any one of them is.
6144 *
6145 * @func
6146 * @memberOf R
6147 * @category Logic
6148 * @sig [(*... -> Boolean)] -> (*... -> Boolean)
6149 * @param {Array} list An array of predicate functions
6150 * @param {*} optional Any arguments to pass into the predicates
6151 * @return {Function} A function that applies its arguments to each of the predicates, returning
6152 * `true` if all are satisfied.
6153 * @see R.allPass
6154 * @example
6155 *
6156 * var gt10 = function(x) { return x > 10; };
6157 * var even = function(x) { return x % 2 === 0};
6158 * var f = R.anyPass([gt10, even]);
6159 * f(11); //=> true
6160 * f(8); //=> true
6161 * f(9); //=> false
6162 */
6163 var anyPass = _curry1(_predicateWrap(any));
6164
6165 /**
6166 * ap applies a list of functions to a list of values.
6167 *
6168 * @func
6169 * @memberOf R
6170 * @category Function
6171 * @sig [f] -> [a] -> [f a]
6172 * @param {Array} fns An array of functions
6173 * @param {Array} vs An array of values
6174 * @return {Array} An array of results of applying each of `fns` to all of `vs` in turn.
6175 * @example
6176 *
6177 * R.ap([R.multiply(2), R.add(3)], [1,2,3]); //=> [2, 4, 6, 4, 5, 6]
6178 */
6179 var ap = _curry2(function ap(fns, vs) {
6180 return _hasMethod('ap', fns) ? fns.ap(vs) : _reduce(function (acc, fn) {
6181 return _concat(acc, map(fn, vs));
6182 }, [], fns);
6183 });
6184
6185 /**
6186 * Returns the result of calling its first argument with the remaining
6187 * arguments. This is occasionally useful as a converging function for
6188 * `R.converge`: the left branch can produce a function while the right
6189 * branch produces a value to be passed to that function as an argument.
6190 *
6191 * @func
6192 * @memberOf R
6193 * @category Function
6194 * @sig (*... -> a),*... -> a
6195 * @param {Function} fn The function to apply to the remaining arguments.
6196 * @param {...*} args Any number of positional arguments.
6197 * @return {*}
6198 * @see R.apply
6199 * @example
6200 *
6201 * var indentN = R.pipe(R.times(R.always(' ')),
6202 * R.join(''),
6203 * R.replace(/^(?!$)/gm));
6204 *
6205 * var format = R.converge(R.call,
6206 * R.pipe(R.prop('indent'), indentN),
6207 * R.prop('value'));
6208 *
6209 * format({indent: 2, value: 'foo\nbar\nbaz\n'}); //=> ' foo\n bar\n baz\n'
6210 */
6211 var call = curry(function call(fn) {
6212 return fn.apply(this, _slice(arguments, 1));
6213 });
6214
6215 /**
6216 * `chain` maps a function over a list and concatenates the results.
6217 * This implementation is compatible with the
6218 * Fantasy-land Chain spec, and will work with types that implement that spec.
6219 * `chain` is also known as `flatMap` in some libraries
6220 *
6221 * @func
6222 * @memberOf R
6223 * @category List
6224 * @sig (a -> [b]) -> [a] -> [b]
6225 * @param {Function} fn
6226 * @param {Array} list
6227 * @return {Array}
6228 * @example
6229 *
6230 * var duplicate = function(n) {
6231 * return [n, n];
6232 * };
6233 * R.chain(duplicate, [1, 2, 3]); //=> [1, 1, 2, 2, 3, 3]
6234 */
6235 var chain = _curry2(_dispatchable('chain', _xchain, function chain(fn, list) {
6236 return unnest(map(fn, list));
6237 }));
6238
6239 /**
6240 * Turns a list of Functors into a Functor of a list, applying
6241 * a mapping function to the elements of the list along the way.
6242 *
6243 * @func
6244 * @memberOf R
6245 * @category List
6246 * @see R.commute
6247 * @sig Functor f => (f a -> f b) -> (x -> f x) -> [f a] -> f [b]
6248 * @param {Function} fn The transformation function
6249 * @param {Function} of A function that returns the data type to return
6250 * @param {Array} list An array of functors of the same type
6251 * @return {*}
6252 * @example
6253 *
6254 * R.commuteMap(R.map(R.add(10)), R.of, [[1], [2, 3]]); //=> [[11, 12], [11, 13]]
6255 * R.commuteMap(R.map(R.add(10)), R.of, [[1, 2], [3]]); //=> [[11, 13], [12, 13]]
6256 * R.commuteMap(R.map(R.add(10)), R.of, [[1], [2], [3]]); //=> [[11, 12, 13]]
6257 * R.commuteMap(R.map(R.add(10)), Maybe.of, [Just(1), Just(2), Just(3)]); //=> Just([11, 12, 13])
6258 * R.commuteMap(R.map(R.add(10)), Maybe.of, [Just(1), Just(2), Nothing()]); //=> Nothing()
6259 */
6260 var commuteMap = _curry3(function commuteMap(fn, of, list) {
6261 function consF(acc, ftor) {
6262 return ap(map(append, fn(ftor)), acc);
6263 }
6264 return _reduce(consF, of([]), list);
6265 });
6266
6267 /**
6268 * Wraps a constructor function inside a curried function that can be called with the same
6269 * arguments and returns the same type. The arity of the function returned is specified
6270 * to allow using variadic constructor functions.
6271 *
6272 * @func
6273 * @memberOf R
6274 * @category Function
6275 * @sig Number -> (* -> {*}) -> (* -> {*})
6276 * @param {Number} n The arity of the constructor function.
6277 * @param {Function} Fn The constructor function to wrap.
6278 * @return {Function} A wrapped, curried constructor function.
6279 * @example
6280 *
6281 * // Variadic constructor function
6282 * var Widget = function() {
6283 * this.children = Array.prototype.slice.call(arguments);
6284 * // ...
6285 * };
6286 * Widget.prototype = {
6287 * // ...
6288 * };
6289 * var allConfigs = [
6290 * // ...
6291 * ];
6292 * R.map(R.constructN(1, Widget), allConfigs); // a list of Widgets
6293 */
6294 var constructN = _curry2(function constructN(n, Fn) {
6295 if (n > 10) {
6296 throw new Error('Constructor with greater than ten arguments');
6297 }
6298 if (n === 0) {
6299 return function () {
6300 return new Fn();
6301 };
6302 }
6303 return curry(nAry(n, function ($0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
6304 switch (arguments.length) {
6305 case 1:
6306 return new Fn($0);
6307 case 2:
6308 return new Fn($0, $1);
6309 case 3:
6310 return new Fn($0, $1, $2);
6311 case 4:
6312 return new Fn($0, $1, $2, $3);
6313 case 5:
6314 return new Fn($0, $1, $2, $3, $4);
6315 case 6:
6316 return new Fn($0, $1, $2, $3, $4, $5);
6317 case 7:
6318 return new Fn($0, $1, $2, $3, $4, $5, $6);
6319 case 8:
6320 return new Fn($0, $1, $2, $3, $4, $5, $6, $7);
6321 case 9:
6322 return new Fn($0, $1, $2, $3, $4, $5, $6, $7, $8);
6323 case 10:
6324 return new Fn($0, $1, $2, $3, $4, $5, $6, $7, $8, $9);
6325 }
6326 }));
6327 });
6328
6329 /**
6330 * Accepts at least three functions and returns a new function. When invoked, this new
6331 * function will invoke the first function, `after`, passing as its arguments the
6332 * results of invoking the subsequent functions with whatever arguments are passed to
6333 * the new function.
6334 *
6335 * @func
6336 * @memberOf R
6337 * @category Function
6338 * @sig (x1 -> x2 -> ... -> z) -> ((a -> b -> ... -> x1), (a -> b -> ... -> x2), ...) -> (a -> b -> ... -> z)
6339 * @param {Function} after A function. `after` will be invoked with the return values of
6340 * `fn1` and `fn2` as its arguments.
6341 * @param {...Function} functions A variable number of functions.
6342 * @return {Function} A new function.
6343 * @example
6344 *
6345 * var add = function(a, b) { return a + b; };
6346 * var multiply = function(a, b) { return a * b; };
6347 * var subtract = function(a, b) { return a - b; };
6348 *
6349 * //≅ multiply( add(1, 2), subtract(1, 2) );
6350 * R.converge(multiply, add, subtract)(1, 2); //=> -3
6351 *
6352 * var add3 = function(a, b, c) { return a + b + c; };
6353 * R.converge(add3, multiply, add, subtract)(1, 2); //=> 4
6354 */
6355 var converge = curryN(3, function converge(after) {
6356 var fns = _slice(arguments, 1);
6357 return curryN(Math.max.apply(Math, pluck('length', fns)), function () {
6358 var args = arguments;
6359 var context = this;
6360 return after.apply(context, _map(function (fn) {
6361 return fn.apply(context, args);
6362 }, fns));
6363 });
6364 });
6365
6366 /**
6367 * Returns all but the first `n` elements of the given list, string, or
6368 * transducer/transformer (or object with a `drop` method).
6369 *
6370 * @func
6371 * @memberOf R
6372 * @category List
6373 * @see R.transduce
6374 * @sig Number -> [a] -> [a]
6375 * @sig Number -> String -> String
6376 * @param {Number} n
6377 * @param {*} list
6378 * @return {*}
6379 * @see R.take
6380 * @example
6381 *
6382 * R.drop(1, ['foo', 'bar', 'baz']); //=> ['bar', 'baz']
6383 * R.drop(2, ['foo', 'bar', 'baz']); //=> ['baz']
6384 * R.drop(3, ['foo', 'bar', 'baz']); //=> []
6385 * R.drop(4, ['foo', 'bar', 'baz']); //=> []
6386 * R.drop(3, 'ramda'); //=> 'da'
6387 */
6388 var drop = _curry2(_dispatchable('drop', _xdrop, function drop(n, xs) {
6389 return slice(Math.max(0, n), Infinity, xs);
6390 }));
6391
6392 /**
6393 * Returns a list containing all but the last `n` elements of the given `list`.
6394 *
6395 * @func
6396 * @memberOf R
6397 * @category List
6398 * @sig Number -> [a] -> [a]
6399 * @sig Number -> String -> String
6400 * @param {Number} n The number of elements of `xs` to skip.
6401 * @param {Array} xs The collection to consider.
6402 * @return {Array}
6403 * @see R.takeLast
6404 * @example
6405 *
6406 * R.dropLast(1, ['foo', 'bar', 'baz']); //=> ['foo', 'bar']
6407 * R.dropLast(2, ['foo', 'bar', 'baz']); //=> ['foo']
6408 * R.dropLast(3, ['foo', 'bar', 'baz']); //=> []
6409 * R.dropLast(4, ['foo', 'bar', 'baz']); //=> []
6410 * R.dropLast(3, 'ramda'); //=> 'ra'
6411 */
6412 var dropLast = _curry2(function dropLast(n, xs) {
6413 return take(n < xs.length ? xs.length - n : 0, xs);
6414 });
6415
6416 /**
6417 * Returns a new list without any consecutively repeating elements. Equality is
6418 * determined by applying the supplied predicate two consecutive elements.
6419 * The first element in a series of equal element is the one being preserved.
6420 *
6421 * Acts as a transducer if a transformer is given in list position.
6422 * @see R.transduce
6423 *
6424 * @func
6425 * @memberOf R
6426 * @category List
6427 * @sig (a, a -> Boolean) -> [a] -> [a]
6428 * @param {Function} pred A predicate used to test whether two items are equal.
6429 * @param {Array} list The array to consider.
6430 * @return {Array} `list` without repeating elements.
6431 * @example
6432 *
6433 * function lengthEq(x, y) { return Math.abs(x) === Math.abs(y); };
6434 * var l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3];
6435 * R.dropRepeatsWith(lengthEq, l); //=> [1, 3, 4, -5, 3]
6436 */
6437 var dropRepeatsWith = _curry2(_dispatchable('dropRepeatsWith', _xdropRepeatsWith, function dropRepeatsWith(pred, list) {
6438 var result = [];
6439 var idx = 1;
6440 var len = list.length;
6441 if (len !== 0) {
6442 result[0] = list[0];
6443 while (idx < len) {
6444 if (!pred(last(result), list[idx])) {
6445 result[result.length] = list[idx];
6446 }
6447 idx += 1;
6448 }
6449 }
6450 return result;
6451 }));
6452
6453 /**
6454 * Reports whether two objects have the same value, in `R.equals` terms,
6455 * for the specified property. Useful as a curried predicate.
6456 *
6457 * @func
6458 * @memberOf R
6459 * @category Object
6460 * @sig k -> {k: v} -> {k: v} -> Boolean
6461 * @param {String} prop The name of the property to compare
6462 * @param {Object} obj1
6463 * @param {Object} obj2
6464 * @return {Boolean}
6465 *
6466 * @example
6467 *
6468 * var o1 = { a: 1, b: 2, c: 3, d: 4 };
6469 * var o2 = { a: 10, b: 20, c: 3, d: 40 };
6470 * R.eqProps('a', o1, o2); //=> false
6471 * R.eqProps('c', o1, o2); //=> true
6472 */
6473 var eqProps = _curry3(function eqProps(prop, obj1, obj2) {
6474 return equals(obj1[prop], obj2[prop]);
6475 });
6476
6477 /**
6478 * Returns the position of the first occurrence of an item in an array,
6479 * or -1 if the item is not included in the array. `R.equals` is used to
6480 * determine equality.
6481 *
6482 * @func
6483 * @memberOf R
6484 * @category List
6485 * @sig a -> [a] -> Number
6486 * @param {*} target The item to find.
6487 * @param {Array} xs The array to search in.
6488 * @return {Number} the index of the target, or -1 if the target is not found.
6489 * @see R.lastIndexOf
6490 * @example
6491 *
6492 * R.indexOf(3, [1,2,3,4]); //=> 2
6493 * R.indexOf(10, [1,2,3,4]); //=> -1
6494 */
6495 var indexOf = _curry2(function indexOf(target, xs) {
6496 return _hasMethod('indexOf', xs) ? xs.indexOf(target) : _indexOf(xs, target, 0);
6497 });
6498
6499 /**
6500 * Returns all but the last element of the given list or string.
6501 *
6502 * @func
6503 * @memberOf R
6504 * @category List
6505 * @see R.last, R.head, R.tail
6506 * @sig [a] -> [a]
6507 * @sig String -> String
6508 * @param {*} list
6509 * @return {*}
6510 * @example
6511 *
6512 * R.init([1, 2, 3]); //=> [1, 2]
6513 * R.init([1, 2]); //=> [1]
6514 * R.init([1]); //=> []
6515 * R.init([]); //=> []
6516 *
6517 * R.init('abc'); //=> 'ab'
6518 * R.init('ab'); //=> 'a'
6519 * R.init('a'); //=> ''
6520 * R.init(''); //=> ''
6521 */
6522 var init = slice(0, -1);
6523
6524 /**
6525 * Returns `true` if all elements are unique, in `R.equals` terms,
6526 * otherwise `false`.
6527 *
6528 * @func
6529 * @memberOf R
6530 * @category List
6531 * @sig [a] -> Boolean
6532 * @param {Array} list The array to consider.
6533 * @return {Boolean} `true` if all elements are unique, else `false`.
6534 * @example
6535 *
6536 * R.isSet(['1', 1]); //=> true
6537 * R.isSet([1, 1]); //=> false
6538 * R.isSet([[42], [42]]); //=> false
6539 */
6540 var isSet = _curry1(function isSet(list) {
6541 var len = list.length;
6542 var idx = 0;
6543 while (idx < len) {
6544 if (_indexOf(list, list[idx], idx + 1) >= 0) {
6545 return false;
6546 }
6547 idx += 1;
6548 }
6549 return true;
6550 });
6551
6552 /**
6553 * Returns a lens for the given getter and setter functions. The getter "gets"
6554 * the value of the focus; the setter "sets" the value of the focus. The setter
6555 * should not mutate the data structure.
6556 *
6557 * @func
6558 * @memberOf R
6559 * @category Object
6560 * @typedef Lens s a = Functor f => (a -> f a) -> s -> f s
6561 * @sig (s -> a) -> ((a, s) -> s) -> Lens s a
6562 * @param {Function} getter
6563 * @param {Function} setter
6564 * @return {Lens}
6565 * @see R.view, R.set, R.over, R.lensIndex, R.lensProp
6566 * @example
6567 *
6568 * var xLens = R.lens(R.prop('x'), R.assoc('x'));
6569 *
6570 * R.view(xLens, {x: 1, y: 2}); //=> 1
6571 * R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2}
6572 * R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2}
6573 */
6574 var lens = _curry2(function lens(getter, setter) {
6575 return function (f) {
6576 return function (s) {
6577 return map(function (v) {
6578 return setter(v, s);
6579 }, f(getter(s)));
6580 };
6581 };
6582 });
6583
6584 /**
6585 * Returns a lens whose focus is the specified index.
6586 *
6587 * @func
6588 * @memberOf R
6589 * @category Object
6590 * @typedef Lens s a = Functor f => (a -> f a) -> s -> f s
6591 * @sig Number -> Lens s a
6592 * @param {Number} n
6593 * @return {Lens}
6594 * @see R.view, R.set, R.over
6595 * @example
6596 *
6597 * var headLens = R.lensIndex(0);
6598 *
6599 * R.view(headLens, ['a', 'b', 'c']); //=> 'a'
6600 * R.set(headLens, 'x', ['a', 'b', 'c']); //=> ['x', 'b', 'c']
6601 * R.over(headLens, R.toUpper, ['a', 'b', 'c']); //=> ['A', 'b', 'c']
6602 */
6603 var lensIndex = _curry1(function lensIndex(n) {
6604 return lens(nth(n), update(n));
6605 });
6606
6607 /**
6608 * Returns a lens whose focus is the specified property.
6609 *
6610 * @func
6611 * @memberOf R
6612 * @category Object
6613 * @typedef Lens s a = Functor f => (a -> f a) -> s -> f s
6614 * @sig String -> Lens s a
6615 * @param {String} k
6616 * @return {Lens}
6617 * @see R.view, R.set, R.over
6618 * @example
6619 *
6620 * var xLens = R.lensProp('x');
6621 *
6622 * R.view(xLens, {x: 1, y: 2}); //=> 1
6623 * R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2}
6624 * R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2}
6625 */
6626 var lensProp = _curry1(function lensProp(k) {
6627 return lens(prop(k), assoc(k));
6628 });
6629
6630 /**
6631 * "lifts" a function to be the specified arity, so that it may "map over" that many
6632 * lists (or other Functors).
6633 *
6634 * @func
6635 * @memberOf R
6636 * @see R.lift
6637 * @category Function
6638 * @sig Number -> (*... -> *) -> ([*]... -> [*])
6639 * @param {Function} fn The function to lift into higher context
6640 * @return {Function} The function `fn` applicable to mappable objects.
6641 * @example
6642 *
6643 * var madd3 = R.liftN(3, R.curryN(3, function() {
6644 * return R.reduce(R.add, 0, arguments);
6645 * }));
6646 * madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7]
6647 */
6648 var liftN = _curry2(function liftN(arity, fn) {
6649 var lifted = curryN(arity, fn);
6650 return curryN(arity, function () {
6651 return _reduce(ap, map(lifted, arguments[0]), _slice(arguments, 1));
6652 });
6653 });
6654
6655 /**
6656 * Returns the mean of the given list of numbers.
6657 *
6658 * @func
6659 * @memberOf R
6660 * @category Math
6661 * @sig [Number] -> Number
6662 * @param {Array} list
6663 * @return {Number}
6664 * @example
6665 *
6666 * R.mean([2, 7, 9]); //=> 6
6667 * R.mean([]); //=> NaN
6668 */
6669 var mean = _curry1(function mean(list) {
6670 return sum(list) / list.length;
6671 });
6672
6673 /**
6674 * Returns the median of the given list of numbers.
6675 *
6676 * @func
6677 * @memberOf R
6678 * @category Math
6679 * @sig [Number] -> Number
6680 * @param {Array} list
6681 * @return {Number}
6682 * @example
6683 *
6684 * R.median([2, 9, 7]); //=> 7
6685 * R.median([7, 2, 10, 9]); //=> 8
6686 * R.median([]); //=> NaN
6687 */
6688 var median = _curry1(function median(list) {
6689 var len = list.length;
6690 if (len === 0) {
6691 return NaN;
6692 }
6693 var width = 2 - len % 2;
6694 var idx = (len - width) / 2;
6695 return mean(_slice(list).sort(function (a, b) {
6696 return a < b ? -1 : a > b ? 1 : 0;
6697 }).slice(idx, idx + width));
6698 });
6699
6700 /**
6701 * Merges a list of objects together into one object.
6702 *
6703 * @func
6704 * @memberOf R
6705 * @category List
6706 * @sig [{k: v}] -> {k: v}
6707 * @param {Array} list An array of objects
6708 * @return {Object} A merged object.
6709 * @see R.reduce
6710 * @example
6711 *
6712 * R.mergeAll([{foo:1},{bar:2},{baz:3}]); //=> {foo:1,bar:2,baz:3}
6713 * R.mergeAll([{foo:1},{foo:2},{bar:2}]); //=> {foo:2,bar:2}
6714 */
6715 var mergeAll = _curry1(function mergeAll(list) {
6716 return reduce(merge, {}, list);
6717 });
6718
6719 /**
6720 * Performs left-to-right function composition. The leftmost function may have
6721 * any arity; the remaining functions must be unary.
6722 *
6723 * In some libraries this function is named `sequence`.
6724 *
6725 * @func
6726 * @memberOf R
6727 * @category Function
6728 * @sig (((a, b, ..., n) -> o), (o -> p), ..., (x -> y), (y -> z)) -> (a -> b -> ... -> n -> z)
6729 * @param {...Function} functions
6730 * @return {Function}
6731 * @see R.compose
6732 * @example
6733 *
6734 * var f = R.pipe(Math.pow, R.negate, R.inc);
6735 *
6736 * f(3, 4); // -(3^4) + 1
6737 */
6738 var pipe = function pipe() {
6739 if (arguments.length === 0) {
6740 throw new Error('pipe requires at least one argument');
6741 }
6742 return curryN(arguments[0].length, reduce(_pipe, arguments[0], tail(arguments)));
6743 };
6744
6745 /**
6746 * Performs left-to-right composition of one or more Promise-returning
6747 * functions. The leftmost function may have any arity; the remaining
6748 * functions must be unary.
6749 *
6750 * @func
6751 * @memberOf R
6752 * @category Function
6753 * @sig ((a -> Promise b), (b -> Promise c), ..., (y -> Promise z)) -> (a -> Promise z)
6754 * @param {...Function} functions
6755 * @return {Function}
6756 * @see R.composeP
6757 * @example
6758 *
6759 * // followersForUser :: String -> Promise [User]
6760 * var followersForUser = R.pipeP(db.getUserById, db.getFollowers);
6761 */
6762 var pipeP = function pipeP() {
6763 if (arguments.length === 0) {
6764 throw new Error('pipeP requires at least one argument');
6765 }
6766 return curryN(arguments[0].length, reduce(_pipeP, arguments[0], tail(arguments)));
6767 };
6768
6769 /**
6770 * Multiplies together all the elements of a list.
6771 *
6772 * @func
6773 * @memberOf R
6774 * @category Math
6775 * @sig [Number] -> Number
6776 * @param {Array} list An array of numbers
6777 * @return {Number} The product of all the numbers in the list.
6778 * @see R.reduce
6779 * @example
6780 *
6781 * R.product([2,4,6,8,100,1]); //=> 38400
6782 */
6783 var product = reduce(multiply, 1);
6784
6785 /**
6786 * Reasonable analog to SQL `select` statement.
6787 *
6788 * @func
6789 * @memberOf R
6790 * @category Object
6791 * @category Relation
6792 * @sig [k] -> [{k: v}] -> [{k: v}]
6793 * @param {Array} props The property names to project
6794 * @param {Array} objs The objects to query
6795 * @return {Array} An array of objects with just the `props` properties.
6796 * @example
6797 *
6798 * var abby = {name: 'Abby', age: 7, hair: 'blond', grade: 2};
6799 * var fred = {name: 'Fred', age: 12, hair: 'brown', grade: 7};
6800 * var kids = [abby, fred];
6801 * R.project(['name', 'grade'], kids); //=> [{name: 'Abby', grade: 2}, {name: 'Fred', grade: 7}]
6802 */
6803 // passing `identity` gives correct arity
6804 var project = useWith(_map, pickAll, identity);
6805
6806 /**
6807 * Returns a new list containing the last `n` elements of the given list.
6808 * If `n > list.length`, returns a list of `list.length` elements.
6809 *
6810 * @func
6811 * @memberOf R
6812 * @category List
6813 * @sig Number -> [a] -> [a]
6814 * @sig Number -> String -> String
6815 * @param {Number} n The number of elements to return.
6816 * @param {Array} xs The collection to consider.
6817 * @return {Array}
6818 * @see R.dropLast
6819 * @example
6820 *
6821 * R.takeLast(1, ['foo', 'bar', 'baz']); //=> ['baz']
6822 * R.takeLast(2, ['foo', 'bar', 'baz']); //=> ['for', 'baz']
6823 * R.takeLast(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
6824 * R.takeLast(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
6825 * R.takeLast(3, 'ramda'); //=> 'mda'
6826 */
6827 var takeLast = _curry2(function takeLast(n, xs) {
6828 return drop(n >= 0 ? xs.length - n : 0, xs);
6829 });
6830
6831 var _contains = function _contains(a, list) {
6832 return _indexOf(list, a, 0) >= 0;
6833 };
6834
6835 // mapPairs :: (Object, [String]) -> [String]
6836 // Function, RegExp, user-defined types
6837 var _toString = function _toString(x, seen) {
6838 var recur = function recur(y) {
6839 var xs = seen.concat([x]);
6840 return _contains(y, xs) ? '<Circular>' : _toString(y, xs);
6841 };
6842 // mapPairs :: (Object, [String]) -> [String]
6843 var mapPairs = function (obj, keys) {
6844 return _map(function (k) {
6845 return _quote(k) + ': ' + recur(obj[k]);
6846 }, keys.slice().sort());
6847 };
6848 switch (Object.prototype.toString.call(x)) {
6849 case '[object Arguments]':
6850 return '(function() { return arguments; }(' + _map(recur, x).join(', ') + '))';
6851 case '[object Array]':
6852 return '[' + _map(recur, x).concat(mapPairs(x, reject(test(/^\d+$/), keys(x)))).join(', ') + ']';
6853 case '[object Boolean]':
6854 return typeof x === 'object' ? 'new Boolean(' + recur(x.valueOf()) + ')' : x.toString();
6855 case '[object Date]':
6856 return 'new Date(' + _quote(_toISOString(x)) + ')';
6857 case '[object Null]':
6858 return 'null';
6859 case '[object Number]':
6860 return typeof x === 'object' ? 'new Number(' + recur(x.valueOf()) + ')' : 1 / x === -Infinity ? '-0' : x.toString(10);
6861 case '[object String]':
6862 return typeof x === 'object' ? 'new String(' + recur(x.valueOf()) + ')' : _quote(x);
6863 case '[object Undefined]':
6864 return 'undefined';
6865 default:
6866 return typeof x.constructor === 'function' && x.constructor.name !== 'Object' && typeof x.toString === 'function' && x.toString() !== '[object Object]' ? x.toString() : // Function, RegExp, user-defined types
6867 '{' + mapPairs(x, keys(x)).join(', ') + '}';
6868 }
6869 };
6870
6871 /**
6872 * Turns a list of Functors into a Functor of a list.
6873 *
6874 * @func
6875 * @memberOf R
6876 * @category List
6877 * @see R.commuteMap
6878 * @sig Functor f => (x -> f x) -> [f a] -> f [a]
6879 * @param {Function} of A function that returns the data type to return
6880 * @param {Array} list An array of functors of the same type
6881 * @return {*}
6882 * @example
6883 *
6884 * R.commute(R.of, [[1], [2, 3]]); //=> [[1, 2], [1, 3]]
6885 * R.commute(R.of, [[1, 2], [3]]); //=> [[1, 3], [2, 3]]
6886 * R.commute(R.of, [[1], [2], [3]]); //=> [[1, 2, 3]]
6887 * R.commute(Maybe.of, [Just(1), Just(2), Just(3)]); //=> Just([1, 2, 3])
6888 * R.commute(Maybe.of, [Just(1), Just(2), Nothing()]); //=> Nothing()
6889 */
6890 var commute = commuteMap(identity);
6891
6892 /**
6893 * Performs right-to-left function composition. The rightmost function may have
6894 * any arity; the remaining functions must be unary.
6895 *
6896 * @func
6897 * @memberOf R
6898 * @category Function
6899 * @sig ((y -> z), (x -> y), ..., (o -> p), ((a, b, ..., n) -> o)) -> (a -> b -> ... -> n -> z)
6900 * @param {...Function} functions
6901 * @return {Function}
6902 * @see R.pipe
6903 * @example
6904 *
6905 * var f = R.compose(R.inc, R.negate, Math.pow);
6906 *
6907 * f(3, 4); // -(3^4) + 1
6908 */
6909 var compose = function compose() {
6910 if (arguments.length === 0) {
6911 throw new Error('compose requires at least one argument');
6912 }
6913 return pipe.apply(this, reverse(arguments));
6914 };
6915
6916 /**
6917 * Returns the right-to-left Kleisli composition of the provided functions,
6918 * each of which must return a value of a type supported by [`chain`](#chain).
6919 *
6920 * `R.composeK(h, g, f)` is equivalent to `R.compose(R.chain(h), R.chain(g), R.chain(f))`.
6921 *
6922 * @func
6923 * @memberOf R
6924 * @category Function
6925 * @see R.pipeK
6926 * @sig Chain m => ((y -> m z), (x -> m y), ..., (a -> m b)) -> (m a -> m z)
6927 * @param {...Function}
6928 * @return {Function}
6929 * @example
6930 *
6931 * // parseJson :: String -> Maybe *
6932 * // get :: String -> Object -> Maybe *
6933 *
6934 * // getStateCode :: Maybe String -> Maybe String
6935 * var getStateCode = R.composeK(
6936 * R.compose(Maybe.of, R.toUpper),
6937 * get('state'),
6938 * get('address'),
6939 * get('user'),
6940 * parseJson
6941 * );
6942 *
6943 * getStateCode(Maybe.of('{"user":{"address":{"state":"ny"}}}'));
6944 * //=> Just('NY')
6945 * getStateCode(Maybe.of('[Invalid JSON]'));
6946 * //=> Nothing()
6947 */
6948 var composeK = function composeK() {
6949 return arguments.length === 0 ? identity : compose.apply(this, map(chain, arguments));
6950 };
6951
6952 /**
6953 * Performs right-to-left composition of one or more Promise-returning
6954 * functions. The rightmost function may have any arity; the remaining
6955 * functions must be unary.
6956 *
6957 * @func
6958 * @memberOf R
6959 * @category Function
6960 * @sig ((y -> Promise z), (x -> Promise y), ..., (a -> Promise b)) -> (a -> Promise z)
6961 * @param {...Function} functions
6962 * @return {Function}
6963 * @see R.pipeP
6964 * @example
6965 *
6966 * // followersForUser :: String -> Promise [User]
6967 * var followersForUser = R.composeP(db.getFollowers, db.getUserById);
6968 */
6969 var composeP = function composeP() {
6970 if (arguments.length === 0) {
6971 throw new Error('composeP requires at least one argument');
6972 }
6973 return pipeP.apply(this, reverse(arguments));
6974 };
6975
6976 /**
6977 * Wraps a constructor function inside a curried function that can be called with the same
6978 * arguments and returns the same type.
6979 *
6980 * @func
6981 * @memberOf R
6982 * @category Function
6983 * @sig (* -> {*}) -> (* -> {*})
6984 * @param {Function} Fn The constructor function to wrap.
6985 * @return {Function} A wrapped, curried constructor function.
6986 * @example
6987 *
6988 * // Constructor function
6989 * var Widget = function(config) {
6990 * // ...
6991 * };
6992 * Widget.prototype = {
6993 * // ...
6994 * };
6995 * var allConfigs = [
6996 * // ...
6997 * ];
6998 * R.map(R.construct(Widget), allConfigs); // a list of Widgets
6999 */
7000 var construct = _curry1(function construct(Fn) {
7001 return constructN(Fn.length, Fn);
7002 });
7003
7004 /**
7005 * Returns `true` if the specified value is equal, in `R.equals` terms,
7006 * to at least one element of the given list; `false` otherwise.
7007 *
7008 * @func
7009 * @memberOf R
7010 * @category List
7011 * @sig a -> [a] -> Boolean
7012 * @param {Object} a The item to compare against.
7013 * @param {Array} list The array to consider.
7014 * @return {Boolean} `true` if the item is in the list, `false` otherwise.
7015 *
7016 * @example
7017 *
7018 * R.contains(3, [1, 2, 3]); //=> true
7019 * R.contains(4, [1, 2, 3]); //=> false
7020 * R.contains([42], [[42]]); //=> true
7021 */
7022 var contains = _curry2(_contains);
7023
7024 /**
7025 * Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list.
7026 *
7027 * @func
7028 * @memberOf R
7029 * @category Relation
7030 * @sig [a] -> [a] -> [a]
7031 * @param {Array} list1 The first list.
7032 * @param {Array} list2 The second list.
7033 * @return {Array} The elements in `list1` that are not in `list2`.
7034 * @see R.differenceWith
7035 * @example
7036 *
7037 * R.difference([1,2,3,4], [7,6,5,4,3]); //=> [1,2]
7038 * R.difference([7,6,5,4,3], [1,2,3,4]); //=> [7,6,5]
7039 */
7040 var difference = _curry2(function difference(first, second) {
7041 var out = [];
7042 var idx = 0;
7043 var firstLen = first.length;
7044 while (idx < firstLen) {
7045 if (!_contains(first[idx], second) && !_contains(first[idx], out)) {
7046 out[out.length] = first[idx];
7047 }
7048 idx += 1;
7049 }
7050 return out;
7051 });
7052
7053 /**
7054 * Returns a new list without any consecutively repeating elements.
7055 * `R.equals` is used to determine equality.
7056 *
7057 * Acts as a transducer if a transformer is given in list position.
7058 * @see R.transduce
7059 *
7060 * @func
7061 * @memberOf R
7062 * @category List
7063 * @sig [a] -> [a]
7064 * @param {Array} list The array to consider.
7065 * @return {Array} `list` without repeating elements.
7066 * @example
7067 *
7068 * R.dropRepeats([1, 1, 1, 2, 3, 4, 4, 2, 2]); //=> [1, 2, 3, 4, 2]
7069 */
7070 var dropRepeats = _curry1(_dispatchable('dropRepeats', _xdropRepeatsWith(equals), dropRepeatsWith(equals)));
7071
7072 /**
7073 * Combines two lists into a set (i.e. no duplicates) composed of those elements common to both lists.
7074 *
7075 * @func
7076 * @memberOf R
7077 * @category Relation
7078 * @sig [a] -> [a] -> [a]
7079 * @param {Array} list1 The first list.
7080 * @param {Array} list2 The second list.
7081 * @see R.intersectionWith
7082 * @return {Array} The list of elements found in both `list1` and `list2`.
7083 * @example
7084 *
7085 * R.intersection([1,2,3,4], [7,6,5,4,3]); //=> [4, 3]
7086 */
7087 var intersection = _curry2(function intersection(list1, list2) {
7088 return uniq(_filter(flip(_contains)(list1), list2));
7089 });
7090
7091 /**
7092 * "lifts" a function of arity > 1 so that it may "map over" an Array or
7093 * other Functor.
7094 *
7095 * @func
7096 * @memberOf R
7097 * @see R.liftN
7098 * @category Function
7099 * @sig (*... -> *) -> ([*]... -> [*])
7100 * @param {Function} fn The function to lift into higher context
7101 * @return {Function} The function `fn` applicable to mappable objects.
7102 * @example
7103 *
7104 * var madd3 = R.lift(R.curry(function(a, b, c) {
7105 * return a + b + c;
7106 * }));
7107 * madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7]
7108 *
7109 * var madd5 = R.lift(R.curry(function(a, b, c, d, e) {
7110 * return a + b + c + d + e;
7111 * }));
7112 * madd5([1,2], [3], [4, 5], [6], [7, 8]); //=> [21, 22, 22, 23, 22, 23, 23, 24]
7113 */
7114 var lift = _curry1(function lift(fn) {
7115 return liftN(fn.length, fn);
7116 });
7117
7118 /**
7119 * Returns a partial copy of an object omitting the keys specified.
7120 *
7121 * @func
7122 * @memberOf R
7123 * @category Object
7124 * @sig [String] -> {String: *} -> {String: *}
7125 * @param {Array} names an array of String property names to omit from the new object
7126 * @param {Object} obj The object to copy from
7127 * @return {Object} A new object with properties from `names` not on it.
7128 * @see R.pick
7129 * @example
7130 *
7131 * R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3}
7132 */
7133 var omit = _curry2(function omit(names, obj) {
7134 var result = {};
7135 for (var prop in obj) {
7136 if (!_contains(prop, names)) {
7137 result[prop] = obj[prop];
7138 }
7139 }
7140 return result;
7141 });
7142
7143 /**
7144 * Returns the left-to-right Kleisli composition of the provided functions,
7145 * each of which must return a value of a type supported by [`chain`](#chain).
7146 *
7147 * `R.pipeK(f, g, h)` is equivalent to `R.pipe(R.chain(f), R.chain(g), R.chain(h))`.
7148 *
7149 * @func
7150 * @memberOf R
7151 * @category Function
7152 * @see R.composeK
7153 * @sig Chain m => ((a -> m b), (b -> m c), ..., (y -> m z)) -> (m a -> m z)
7154 * @param {...Function}
7155 * @return {Function}
7156 * @example
7157 *
7158 * // parseJson :: String -> Maybe *
7159 * // get :: String -> Object -> Maybe *
7160 *
7161 * // getStateCode :: Maybe String -> Maybe String
7162 * var getStateCode = R.pipeK(
7163 * parseJson,
7164 * get('user'),
7165 * get('address'),
7166 * get('state'),
7167 * R.compose(Maybe.of, R.toUpper)
7168 * );
7169 *
7170 * getStateCode(Maybe.of('{"user":{"address":{"state":"ny"}}}'));
7171 * //=> Just('NY')
7172 * getStateCode(Maybe.of('[Invalid JSON]'));
7173 * //=> Nothing()
7174 */
7175 var pipeK = function pipeK() {
7176 return composeK.apply(this, reverse(arguments));
7177 };
7178
7179 /**
7180 * Returns the string representation of the given value. `eval`'ing the output
7181 * should result in a value equivalent to the input value. Many of the built-in
7182 * `toString` methods do not satisfy this requirement.
7183 *
7184 * If the given value is an `[object Object]` with a `toString` method other
7185 * than `Object.prototype.toString`, this method is invoked with no arguments
7186 * to produce the return value. This means user-defined constructor functions
7187 * can provide a suitable `toString` method. For example:
7188 *
7189 * function Point(x, y) {
7190 * this.x = x;
7191 * this.y = y;
7192 * }
7193 *
7194 * Point.prototype.toString = function() {
7195 * return 'new Point(' + this.x + ', ' + this.y + ')';
7196 * };
7197 *
7198 * R.toString(new Point(1, 2)); //=> 'new Point(1, 2)'
7199 *
7200 * @func
7201 * @memberOf R
7202 * @category String
7203 * @sig * -> String
7204 * @param {*} val
7205 * @return {String}
7206 * @example
7207 *
7208 * R.toString(42); //=> '42'
7209 * R.toString('abc'); //=> '"abc"'
7210 * R.toString([1, 2, 3]); //=> '[1, 2, 3]'
7211 * R.toString({foo: 1, bar: 2, baz: 3}); //=> '{"bar": 2, "baz": 3, "foo": 1}'
7212 * R.toString(new Date('2001-02-03T04:05:06Z')); //=> 'new Date("2001-02-03T04:05:06.000Z")'
7213 */
7214 var toString = _curry1(function toString(val) {
7215 return _toString(val, []);
7216 });
7217
7218 /**
7219 * Combines two lists into a set (i.e. no duplicates) composed of the
7220 * elements of each list.
7221 *
7222 * @func
7223 * @memberOf R
7224 * @category Relation
7225 * @sig [a] -> [a] -> [a]
7226 * @param {Array} as The first list.
7227 * @param {Array} bs The second list.
7228 * @return {Array} The first and second lists concatenated, with
7229 * duplicates removed.
7230 * @example
7231 *
7232 * R.union([1, 2, 3], [2, 3, 4]); //=> [1, 2, 3, 4]
7233 */
7234 var union = _curry2(compose(uniq, _concat));
7235
7236 /**
7237 * Returns a new list containing only one copy of each element in the
7238 * original list, based upon the value returned by applying the supplied
7239 * function to each list element. Prefers the first item if the supplied
7240 * function produces the same value on two items. `R.equals` is used for
7241 * comparison.
7242 *
7243 * @func
7244 * @memberOf R
7245 * @category List
7246 * @sig (a -> b) -> [a] -> [a]
7247 * @param {Function} fn A function used to produce a value to use during comparisons.
7248 * @param {Array} list The array to consider.
7249 * @return {Array} The list of unique items.
7250 * @example
7251 *
7252 * R.uniqBy(Math.abs, [-1, -5, 2, 10, 1, 2]); //=> [-1, -5, 2, 10]
7253 */
7254 var uniqBy = _curry2(function uniqBy(fn, list) {
7255 var idx = 0, applied = [], result = [], appliedItem, item;
7256 while (idx < list.length) {
7257 item = list[idx];
7258 appliedItem = fn(item);
7259 if (!_contains(appliedItem, applied)) {
7260 result.push(item);
7261 applied.push(appliedItem);
7262 }
7263 idx += 1;
7264 }
7265 return result;
7266 });
7267
7268 /**
7269 * Turns a named method with a specified arity into a function
7270 * that can be called directly supplied with arguments and a target object.
7271 *
7272 * The returned function is curried and accepts `arity + 1` parameters where
7273 * the final parameter is the target object.
7274 *
7275 * @func
7276 * @memberOf R
7277 * @category Function
7278 * @sig Number -> String -> (a -> b -> ... -> n -> Object -> *)
7279 * @param {Number} arity Number of arguments the returned function should take
7280 * before the target object.
7281 * @param {Function} method Name of the method to call.
7282 * @return {Function} A new curried function.
7283 * @example
7284 *
7285 * var sliceFrom = R.invoker(1, 'slice');
7286 * sliceFrom(6, 'abcdefghijklm'); //=> 'ghijklm'
7287 * var sliceFrom6 = R.invoker(2, 'slice')(6);
7288 * sliceFrom6(8, 'abcdefghijklm'); //=> 'gh'
7289 */
7290 var invoker = _curry2(function invoker(arity, method) {
7291 return curryN(arity + 1, function () {
7292 var target = arguments[arity];
7293 if (target != null && is(Function, target[method])) {
7294 return target[method].apply(target, _slice(arguments, 0, arity));
7295 }
7296 throw new TypeError(toString(target) + ' does not have a method named "' + method + '"');
7297 });
7298 });
7299
7300 /**
7301 * Returns a string made by inserting the `separator` between each
7302 * element and concatenating all the elements into a single string.
7303 *
7304 * @func
7305 * @memberOf R
7306 * @category List
7307 * @sig String -> [a] -> String
7308 * @param {Number|String} separator The string used to separate the elements.
7309 * @param {Array} xs The elements to join into a string.
7310 * @return {String} str The string made by concatenating `xs` with `separator`.
7311 * @see R.split
7312 * @example
7313 *
7314 * var spacer = R.join(' ');
7315 * spacer(['a', 2, 3.4]); //=> 'a 2 3.4'
7316 * R.join('|', [1, 2, 3]); //=> '1|2|3'
7317 */
7318 var join = invoker(1, 'join');
7319
7320 /**
7321 * Creates a new function that, when invoked, caches the result of calling `fn` for a given
7322 * argument set and returns the result. Subsequent calls to the memoized `fn` with the same
7323 * argument set will not result in an additional call to `fn`; instead, the cached result
7324 * for that set of arguments will be returned.
7325 *
7326 * @func
7327 * @memberOf R
7328 * @category Function
7329 * @sig (*... -> a) -> (*... -> a)
7330 * @param {Function} fn The function to memoize.
7331 * @return {Function} Memoized version of `fn`.
7332 * @example
7333 *
7334 * var count = 0;
7335 * var factorial = R.memoize(function(n) {
7336 * count += 1;
7337 * return R.product(R.range(1, n + 1));
7338 * });
7339 * factorial(5); //=> 120
7340 * factorial(5); //=> 120
7341 * factorial(5); //=> 120
7342 * count; //=> 1
7343 */
7344 var memoize = _curry1(function memoize(fn) {
7345 var cache = {};
7346 return function () {
7347 var key = toString(arguments);
7348 if (!_has(key, cache)) {
7349 cache[key] = fn.apply(this, arguments);
7350 }
7351 return cache[key];
7352 };
7353 });
7354
7355 /**
7356 * Splits a string into an array of strings based on the given
7357 * separator.
7358 *
7359 * @func
7360 * @memberOf R
7361 * @category String
7362 * @sig String -> String -> [String]
7363 * @param {String} sep The separator string.
7364 * @param {String} str The string to separate into an array.
7365 * @return {Array} The array of strings from `str` separated by `str`.
7366 * @see R.join
7367 * @example
7368 *
7369 * var pathComponents = R.split('/');
7370 * R.tail(pathComponents('/usr/local/bin/node')); //=> ['usr', 'local', 'bin', 'node']
7371 *
7372 * R.split('.', 'a.b.c.xyz.d'); //=> ['a', 'b', 'c', 'xyz', 'd']
7373 */
7374 var split = invoker(1, 'split');
7375
7376 /**
7377 * The lower case version of a string.
7378 *
7379 * @func
7380 * @memberOf R
7381 * @category String
7382 * @sig String -> String
7383 * @param {String} str The string to lower case.
7384 * @return {String} The lower case version of `str`.
7385 * @see R.toUpper
7386 * @example
7387 *
7388 * R.toLower('XYZ'); //=> 'xyz'
7389 */
7390 var toLower = invoker(0, 'toLowerCase');
7391
7392 /**
7393 * The upper case version of a string.
7394 *
7395 * @func
7396 * @memberOf R
7397 * @category String
7398 * @sig String -> String
7399 * @param {String} str The string to upper case.
7400 * @return {String} The upper case version of `str`.
7401 * @see R.toLower
7402 * @example
7403 *
7404 * R.toUpper('abc'); //=> 'ABC'
7405 */
7406 var toUpper = invoker(0, 'toUpperCase');
7407
7408 var R = {
7409 F: F,
7410 T: T,
7411 __: __,
7412 add: add,
7413 addIndex: addIndex,
7414 adjust: adjust,
7415 all: all,
7416 allPass: allPass,
7417 always: always,
7418 and: and,
7419 any: any,
7420 anyPass: anyPass,
7421 ap: ap,
7422 aperture: aperture,
7423 append: append,
7424 apply: apply,
7425 assoc: assoc,
7426 assocPath: assocPath,
7427 binary: binary,
7428 bind: bind,
7429 both: both,
7430 call: call,
7431 chain: chain,
7432 clone: clone,
7433 commute: commute,
7434 commuteMap: commuteMap,
7435 comparator: comparator,
7436 complement: complement,
7437 compose: compose,
7438 composeK: composeK,
7439 composeP: composeP,
7440 concat: concat,
7441 cond: cond,
7442 construct: construct,
7443 constructN: constructN,
7444 contains: contains,
7445 containsWith: containsWith,
7446 converge: converge,
7447 countBy: countBy,
7448 createMapEntry: createMapEntry,
7449 curry: curry,
7450 curryN: curryN,
7451 dec: dec,
7452 defaultTo: defaultTo,
7453 difference: difference,
7454 differenceWith: differenceWith,
7455 dissoc: dissoc,
7456 dissocPath: dissocPath,
7457 divide: divide,
7458 drop: drop,
7459 dropLast: dropLast,
7460 dropLastWhile: dropLastWhile,
7461 dropRepeats: dropRepeats,
7462 dropRepeatsWith: dropRepeatsWith,
7463 dropWhile: dropWhile,
7464 either: either,
7465 empty: empty,
7466 eqProps: eqProps,
7467 equals: equals,
7468 evolve: evolve,
7469 filter: filter,
7470 find: find,
7471 findIndex: findIndex,
7472 findLast: findLast,
7473 findLastIndex: findLastIndex,
7474 flatten: flatten,
7475 flip: flip,
7476 forEach: forEach,
7477 fromPairs: fromPairs,
7478 functions: functions,
7479 functionsIn: functionsIn,
7480 groupBy: groupBy,
7481 gt: gt,
7482 gte: gte,
7483 has: has,
7484 hasIn: hasIn,
7485 head: head,
7486 identical: identical,
7487 identity: identity,
7488 ifElse: ifElse,
7489 inc: inc,
7490 indexOf: indexOf,
7491 init: init,
7492 insert: insert,
7493 insertAll: insertAll,
7494 intersection: intersection,
7495 intersectionWith: intersectionWith,
7496 intersperse: intersperse,
7497 into: into,
7498 invert: invert,
7499 invertObj: invertObj,
7500 invoker: invoker,
7501 is: is,
7502 isArrayLike: isArrayLike,
7503 isEmpty: isEmpty,
7504 isNil: isNil,
7505 isSet: isSet,
7506 join: join,
7507 keys: keys,
7508 keysIn: keysIn,
7509 last: last,
7510 lastIndexOf: lastIndexOf,
7511 length: length,
7512 lens: lens,
7513 lensIndex: lensIndex,
7514 lensProp: lensProp,
7515 lift: lift,
7516 liftN: liftN,
7517 lt: lt,
7518 lte: lte,
7519 map: map,
7520 mapAccum: mapAccum,
7521 mapAccumRight: mapAccumRight,
7522 mapObj: mapObj,
7523 mapObjIndexed: mapObjIndexed,
7524 match: match,
7525 mathMod: mathMod,
7526 max: max,
7527 maxBy: maxBy,
7528 mean: mean,
7529 median: median,
7530 memoize: memoize,
7531 merge: merge,
7532 mergeAll: mergeAll,
7533 min: min,
7534 minBy: minBy,
7535 modulo: modulo,
7536 multiply: multiply,
7537 nAry: nAry,
7538 negate: negate,
7539 none: none,
7540 not: not,
7541 nth: nth,
7542 nthArg: nthArg,
7543 nthChar: nthChar,
7544 nthCharCode: nthCharCode,
7545 of: of,
7546 omit: omit,
7547 once: once,
7548 or: or,
7549 over: over,
7550 partial: partial,
7551 partialRight: partialRight,
7552 partition: partition,
7553 path: path,
7554 pathEq: pathEq,
7555 pick: pick,
7556 pickAll: pickAll,
7557 pickBy: pickBy,
7558 pipe: pipe,
7559 pipeK: pipeK,
7560 pipeP: pipeP,
7561 pluck: pluck,
7562 prepend: prepend,
7563 product: product,
7564 project: project,
7565 prop: prop,
7566 propEq: propEq,
7567 propIs: propIs,
7568 propOr: propOr,
7569 propSatisfies: propSatisfies,
7570 props: props,
7571 range: range,
7572 reduce: reduce,
7573 reduceRight: reduceRight,
7574 reduced: reduced,
7575 reject: reject,
7576 remove: remove,
7577 repeat: repeat,
7578 replace: replace,
7579 reverse: reverse,
7580 scan: scan,
7581 set: set,
7582 slice: slice,
7583 sort: sort,
7584 sortBy: sortBy,
7585 split: split,
7586 splitEvery: splitEvery,
7587 subtract: subtract,
7588 sum: sum,
7589 tail: tail,
7590 take: take,
7591 takeLast: takeLast,
7592 takeLastWhile: takeLastWhile,
7593 takeWhile: takeWhile,
7594 tap: tap,
7595 test: test,
7596 times: times,
7597 toLower: toLower,
7598 toPairs: toPairs,
7599 toPairsIn: toPairsIn,
7600 toString: toString,
7601 toUpper: toUpper,
7602 transduce: transduce,
7603 trim: trim,
7604 type: type,
7605 unapply: unapply,
7606 unary: unary,
7607 uncurryN: uncurryN,
7608 unfold: unfold,
7609 union: union,
7610 unionWith: unionWith,
7611 uniq: uniq,
7612 uniqBy: uniqBy,
7613 uniqWith: uniqWith,
7614 unnest: unnest,
7615 update: update,
7616 useWith: useWith,
7617 values: values,
7618 valuesIn: valuesIn,
7619 view: view,
7620 where: where,
7621 whereEq: whereEq,
7622 wrap: wrap,
7623 xprod: xprod,
7624 zip: zip,
7625 zipObj: zipObj,
7626 zipWith: zipWith
7627 };
7628
7629 /* TEST_ENTRY_POINT */
7630
7631 if (true) {
7632 module.exports = R;
7633 } else if (typeof define === 'function' && define.amd) {
7634 define(function() { return R; });
7635 } else {
7636 this.R = R;
7637 }
7638
7639 }.call(this));
7640
7641
7642/***/ },
7643/* 5 */
7644/***/ function(module, exports, __webpack_require__) {
7645
7646 var eq = __webpack_require__(97);
7647
7648 /**
7649 * Gets the index at which the first occurrence of `key` is found in `array`
7650 * of key-value pairs.
7651 *
7652 * @private
7653 * @param {Array} array The array to search.
7654 * @param {*} key The key to search for.
7655 * @returns {number} Returns the index of the matched value, else `-1`.
7656 */
7657 function assocIndexOf(array, key) {
7658 var length = array.length;
7659 while (length--) {
7660 if (eq(array[length][0], key)) {
7661 return length;
7662 }
7663 }
7664 return -1;
7665 }
7666
7667 module.exports = assocIndexOf;
7668
7669
7670/***/ },
7671/* 6 */
7672/***/ function(module, exports) {
7673
7674 /**
7675 * Checks if `value` is suitable for use as unique object key.
7676 *
7677 * @private
7678 * @param {*} value The value to check.
7679 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
7680 */
7681 function isKeyable(value) {
7682 var type = typeof value;
7683 return type == 'number' || type == 'boolean' ||
7684 (type == 'string' && value !== '__proto__') || value == null;
7685 }
7686
7687 module.exports = isKeyable;
7688
7689
7690/***/ },
7691/* 7 */
7692/***/ function(module, exports, __webpack_require__) {
7693
7694 var getNative = __webpack_require__(10);
7695
7696 /* Built-in method references that are verified to be native. */
7697 var nativeCreate = getNative(Object, 'create');
7698
7699 module.exports = nativeCreate;
7700
7701
7702/***/ },
7703/* 8 */
7704/***/ function(module, exports, __webpack_require__) {
7705
7706 /* WEBPACK VAR INJECTION */(function(module, global) {var checkGlobal = __webpack_require__(68);
7707
7708 /** Used to determine if values are of the language type `Object`. */
7709 var objectTypes = {
7710 'function': true,
7711 'object': true
7712 };
7713
7714 /** Detect free variable `exports`. */
7715 var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null;
7716
7717 /** Detect free variable `module`. */
7718 var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null;
7719
7720 /** Detect free variable `global` from Node.js. */
7721 var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
7722
7723 /** Detect free variable `self`. */
7724 var freeSelf = checkGlobal(objectTypes[typeof self] && self);
7725
7726 /** Detect free variable `window`. */
7727 var freeWindow = checkGlobal(objectTypes[typeof window] && window);
7728
7729 /** Detect `this` as the global object. */
7730 var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
7731
7732 /**
7733 * Used as a reference to the global object.
7734 *
7735 * The `this` value is used if it's the global object to avoid Greasemonkey's
7736 * restricted `window` object, otherwise the `window` object is used.
7737 */
7738 var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || freeSelf || thisGlobal || Function('return this')();
7739
7740 module.exports = root;
7741
7742 /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(111)(module), (function() { return this; }())))
7743
7744/***/ },
7745/* 9 */
7746/***/ function(module, exports) {
7747
7748 /** Used as references for various `Number` constants. */
7749 var MAX_SAFE_INTEGER = 9007199254740991;
7750
7751 /**
7752 * Checks if `value` is a valid array-like length.
7753 *
7754 * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
7755 *
7756 * @static
7757 * @memberOf _
7758 * @category Lang
7759 * @param {*} value The value to check.
7760 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
7761 * @example
7762 *
7763 * _.isLength(3);
7764 * // => true
7765 *
7766 * _.isLength(Number.MIN_VALUE);
7767 * // => false
7768 *
7769 * _.isLength(Infinity);
7770 * // => false
7771 *
7772 * _.isLength('3');
7773 * // => false
7774 */
7775 function isLength(value) {
7776 return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
7777 }
7778
7779 module.exports = isLength;
7780
7781
7782/***/ },
7783/* 10 */
7784/***/ function(module, exports, __webpack_require__) {
7785
7786 var isNative = __webpack_require__(101);
7787
7788 /**
7789 * Gets the native function at `key` of `object`.
7790 *
7791 * @private
7792 * @param {Object} object The object to query.
7793 * @param {string} key The key of the method to get.
7794 * @returns {*} Returns the function if it's native, else `undefined`.
7795 */
7796 function getNative(object, key) {
7797 var value = object == null ? undefined : object[key];
7798 return isNative(value) ? value : undefined;
7799 }
7800
7801 module.exports = getNative;
7802
7803
7804/***/ },
7805/* 11 */
7806/***/ function(module, exports) {
7807
7808 /**
7809 * Checks if `value` is a host object in IE < 9.
7810 *
7811 * @private
7812 * @param {*} value The value to check.
7813 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
7814 */
7815 function isHostObject(value) {
7816 // Many host objects are `Object` objects that can coerce to strings
7817 // despite having improperly defined `toString` methods.
7818 var result = false;
7819 if (value != null && typeof value.toString != 'function') {
7820 try {
7821 result = !!(value + '');
7822 } catch (e) {}
7823 }
7824 return result;
7825 }
7826
7827 module.exports = isHostObject;
7828
7829
7830/***/ },
7831/* 12 */
7832/***/ function(module, exports, __webpack_require__) {
7833
7834 var isArray = __webpack_require__(1);
7835
7836 /** Used to match property names within property paths. */
7837 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
7838 reIsPlainProp = /^\w*$/;
7839
7840 /**
7841 * Checks if `value` is a property name and not a property path.
7842 *
7843 * @private
7844 * @param {*} value The value to check.
7845 * @param {Object} [object] The object to query keys on.
7846 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
7847 */
7848 function isKey(value, object) {
7849 if (typeof value == 'number') {
7850 return true;
7851 }
7852 return !isArray(value) &&
7853 (reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
7854 (object != null && value in Object(object)));
7855 }
7856
7857 module.exports = isKey;
7858
7859
7860/***/ },
7861/* 13 */
7862/***/ function(module, exports) {
7863
7864 /**
7865 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
7866 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
7867 *
7868 * @static
7869 * @memberOf _
7870 * @category Lang
7871 * @param {*} value The value to check.
7872 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
7873 * @example
7874 *
7875 * _.isObject({});
7876 * // => true
7877 *
7878 * _.isObject([1, 2, 3]);
7879 * // => true
7880 *
7881 * _.isObject(_.noop);
7882 * // => true
7883 *
7884 * _.isObject(null);
7885 * // => false
7886 */
7887 function isObject(value) {
7888 var type = typeof value;
7889 return !!value && (type == 'object' || type == 'function');
7890 }
7891
7892 module.exports = isObject;
7893
7894
7895/***/ },
7896/* 14 */
7897/***/ function(module, exports, __webpack_require__) {
7898
7899 var baseHas = __webpack_require__(24),
7900 baseKeys = __webpack_require__(61),
7901 indexKeys = __webpack_require__(80),
7902 isArrayLike = __webpack_require__(32),
7903 isIndex = __webpack_require__(29),
7904 isPrototype = __webpack_require__(81);
7905
7906 /**
7907 * Creates an array of the own enumerable property names of `object`.
7908 *
7909 * **Note:** Non-object values are coerced to objects. See the
7910 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
7911 * for more details.
7912 *
7913 * @static
7914 * @memberOf _
7915 * @category Object
7916 * @param {Object} object The object to query.
7917 * @returns {Array} Returns the array of property names.
7918 * @example
7919 *
7920 * function Foo() {
7921 * this.a = 1;
7922 * this.b = 2;
7923 * }
7924 *
7925 * Foo.prototype.c = 3;
7926 *
7927 * _.keys(new Foo);
7928 * // => ['a', 'b'] (iteration order is not guaranteed)
7929 *
7930 * _.keys('hi');
7931 * // => ['0', '1']
7932 */
7933 function keys(object) {
7934 var isProto = isPrototype(object);
7935 if (!(isProto || isArrayLike(object))) {
7936 return baseKeys(object);
7937 }
7938 var indexes = indexKeys(object),
7939 skipIndexes = !!indexes,
7940 result = indexes || [],
7941 length = result.length;
7942
7943 for (var key in object) {
7944 if (baseHas(object, key) &&
7945 !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
7946 !(isProto && key == 'constructor')) {
7947 result.push(key);
7948 }
7949 }
7950 return result;
7951 }
7952
7953 module.exports = keys;
7954
7955
7956/***/ },
7957/* 15 */
7958/***/ function(module, exports, __webpack_require__) {
7959
7960 /* WEBPACK VAR INJECTION */(function(Buffer, global) {/*!
7961 * The buffer module from node.js, for the browser.
7962 *
7963 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
7964 * @license MIT
7965 */
7966 /* eslint-disable no-proto */
7967
7968 'use strict'
7969
7970 var base64 = __webpack_require__(39)
7971 var ieee754 = __webpack_require__(46)
7972 var isArray = __webpack_require__(47)
7973
7974 exports.Buffer = Buffer
7975 exports.SlowBuffer = SlowBuffer
7976 exports.INSPECT_MAX_BYTES = 50
7977
7978 /**
7979 * If `Buffer.TYPED_ARRAY_SUPPORT`:
7980 * === true Use Uint8Array implementation (fastest)
7981 * === false Use Object implementation (most compatible, even IE6)
7982 *
7983 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
7984 * Opera 11.6+, iOS 4.2+.
7985 *
7986 * Due to various browser bugs, sometimes the Object implementation will be used even
7987 * when the browser supports typed arrays.
7988 *
7989 * Note:
7990 *
7991 * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
7992 * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
7993 *
7994 * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
7995 *
7996 * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
7997 * incorrect length in some situations.
7998
7999 * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
8000 * get the Object implementation, which is slower but behaves correctly.
8001 */
8002 Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
8003 ? global.TYPED_ARRAY_SUPPORT
8004 : typedArraySupport()
8005
8006 /*
8007 * Export kMaxLength after typed array support is determined.
8008 */
8009 exports.kMaxLength = kMaxLength()
8010
8011 function typedArraySupport () {
8012 try {
8013 var arr = new Uint8Array(1)
8014 arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
8015 return arr.foo() === 42 && // typed array instances can be augmented
8016 typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
8017 arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
8018 } catch (e) {
8019 return false
8020 }
8021 }
8022
8023 function kMaxLength () {
8024 return Buffer.TYPED_ARRAY_SUPPORT
8025 ? 0x7fffffff
8026 : 0x3fffffff
8027 }
8028
8029 function createBuffer (that, length) {
8030 if (kMaxLength() < length) {
8031 throw new RangeError('Invalid typed array length')
8032 }
8033 if (Buffer.TYPED_ARRAY_SUPPORT) {
8034 // Return an augmented `Uint8Array` instance, for best performance
8035 that = new Uint8Array(length)
8036 that.__proto__ = Buffer.prototype
8037 } else {
8038 // Fallback: Return an object instance of the Buffer class
8039 if (that === null) {
8040 that = new Buffer(length)
8041 }
8042 that.length = length
8043 }
8044
8045 return that
8046 }
8047
8048 /**
8049 * The Buffer constructor returns instances of `Uint8Array` that have their
8050 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
8051 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
8052 * and the `Uint8Array` methods. Square bracket notation works as expected -- it
8053 * returns a single octet.
8054 *
8055 * The `Uint8Array` prototype remains unmodified.
8056 */
8057
8058 function Buffer (arg, encodingOrOffset, length) {
8059 if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
8060 return new Buffer(arg, encodingOrOffset, length)
8061 }
8062
8063 // Common case.
8064 if (typeof arg === 'number') {
8065 if (typeof encodingOrOffset === 'string') {
8066 throw new Error(
8067 'If encoding is specified then the first argument must be a string'
8068 )
8069 }
8070 return allocUnsafe(this, arg)
8071 }
8072 return from(this, arg, encodingOrOffset, length)
8073 }
8074
8075 Buffer.poolSize = 8192 // not used by this implementation
8076
8077 // TODO: Legacy, not needed anymore. Remove in next major version.
8078 Buffer._augment = function (arr) {
8079 arr.__proto__ = Buffer.prototype
8080 return arr
8081 }
8082
8083 function from (that, value, encodingOrOffset, length) {
8084 if (typeof value === 'number') {
8085 throw new TypeError('"value" argument must not be a number')
8086 }
8087
8088 if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
8089 return fromArrayBuffer(that, value, encodingOrOffset, length)
8090 }
8091
8092 if (typeof value === 'string') {
8093 return fromString(that, value, encodingOrOffset)
8094 }
8095
8096 return fromObject(that, value)
8097 }
8098
8099 /**
8100 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
8101 * if value is a number.
8102 * Buffer.from(str[, encoding])
8103 * Buffer.from(array)
8104 * Buffer.from(buffer)
8105 * Buffer.from(arrayBuffer[, byteOffset[, length]])
8106 **/
8107 Buffer.from = function (value, encodingOrOffset, length) {
8108 return from(null, value, encodingOrOffset, length)
8109 }
8110
8111 if (Buffer.TYPED_ARRAY_SUPPORT) {
8112 Buffer.prototype.__proto__ = Uint8Array.prototype
8113 Buffer.__proto__ = Uint8Array
8114 if (typeof Symbol !== 'undefined' && Symbol.species &&
8115 Buffer[Symbol.species] === Buffer) {
8116 // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
8117 Object.defineProperty(Buffer, Symbol.species, {
8118 value: null,
8119 configurable: true
8120 })
8121 }
8122 }
8123
8124 function assertSize (size) {
8125 if (typeof size !== 'number') {
8126 throw new TypeError('"size" argument must be a number')
8127 } else if (size < 0) {
8128 throw new RangeError('"size" argument must not be negative')
8129 }
8130 }
8131
8132 function alloc (that, size, fill, encoding) {
8133 assertSize(size)
8134 if (size <= 0) {
8135 return createBuffer(that, size)
8136 }
8137 if (fill !== undefined) {
8138 // Only pay attention to encoding if it's a string. This
8139 // prevents accidentally sending in a number that would
8140 // be interpretted as a start offset.
8141 return typeof encoding === 'string'
8142 ? createBuffer(that, size).fill(fill, encoding)
8143 : createBuffer(that, size).fill(fill)
8144 }
8145 return createBuffer(that, size)
8146 }
8147
8148 /**
8149 * Creates a new filled Buffer instance.
8150 * alloc(size[, fill[, encoding]])
8151 **/
8152 Buffer.alloc = function (size, fill, encoding) {
8153 return alloc(null, size, fill, encoding)
8154 }
8155
8156 function allocUnsafe (that, size) {
8157 assertSize(size)
8158 that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
8159 if (!Buffer.TYPED_ARRAY_SUPPORT) {
8160 for (var i = 0; i < size; ++i) {
8161 that[i] = 0
8162 }
8163 }
8164 return that
8165 }
8166
8167 /**
8168 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
8169 * */
8170 Buffer.allocUnsafe = function (size) {
8171 return allocUnsafe(null, size)
8172 }
8173 /**
8174 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
8175 */
8176 Buffer.allocUnsafeSlow = function (size) {
8177 return allocUnsafe(null, size)
8178 }
8179
8180 function fromString (that, string, encoding) {
8181 if (typeof encoding !== 'string' || encoding === '') {
8182 encoding = 'utf8'
8183 }
8184
8185 if (!Buffer.isEncoding(encoding)) {
8186 throw new TypeError('"encoding" must be a valid string encoding')
8187 }
8188
8189 var length = byteLength(string, encoding) | 0
8190 that = createBuffer(that, length)
8191
8192 var actual = that.write(string, encoding)
8193
8194 if (actual !== length) {
8195 // Writing a hex string, for example, that contains invalid characters will
8196 // cause everything after the first invalid character to be ignored. (e.g.
8197 // 'abxxcd' will be treated as 'ab')
8198 that = that.slice(0, actual)
8199 }
8200
8201 return that
8202 }
8203
8204 function fromArrayLike (that, array) {
8205 var length = array.length < 0 ? 0 : checked(array.length) | 0
8206 that = createBuffer(that, length)
8207 for (var i = 0; i < length; i += 1) {
8208 that[i] = array[i] & 255
8209 }
8210 return that
8211 }
8212
8213 function fromArrayBuffer (that, array, byteOffset, length) {
8214 array.byteLength // this throws if `array` is not a valid ArrayBuffer
8215
8216 if (byteOffset < 0 || array.byteLength < byteOffset) {
8217 throw new RangeError('\'offset\' is out of bounds')
8218 }
8219
8220 if (array.byteLength < byteOffset + (length || 0)) {
8221 throw new RangeError('\'length\' is out of bounds')
8222 }
8223
8224 if (byteOffset === undefined && length === undefined) {
8225 array = new Uint8Array(array)
8226 } else if (length === undefined) {
8227 array = new Uint8Array(array, byteOffset)
8228 } else {
8229 array = new Uint8Array(array, byteOffset, length)
8230 }
8231
8232 if (Buffer.TYPED_ARRAY_SUPPORT) {
8233 // Return an augmented `Uint8Array` instance, for best performance
8234 that = array
8235 that.__proto__ = Buffer.prototype
8236 } else {
8237 // Fallback: Return an object instance of the Buffer class
8238 that = fromArrayLike(that, array)
8239 }
8240 return that
8241 }
8242
8243 function fromObject (that, obj) {
8244 if (Buffer.isBuffer(obj)) {
8245 var len = checked(obj.length) | 0
8246 that = createBuffer(that, len)
8247
8248 if (that.length === 0) {
8249 return that
8250 }
8251
8252 obj.copy(that, 0, 0, len)
8253 return that
8254 }
8255
8256 if (obj) {
8257 if ((typeof ArrayBuffer !== 'undefined' &&
8258 obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
8259 if (typeof obj.length !== 'number' || isnan(obj.length)) {
8260 return createBuffer(that, 0)
8261 }
8262 return fromArrayLike(that, obj)
8263 }
8264
8265 if (obj.type === 'Buffer' && isArray(obj.data)) {
8266 return fromArrayLike(that, obj.data)
8267 }
8268 }
8269
8270 throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
8271 }
8272
8273 function checked (length) {
8274 // Note: cannot use `length < kMaxLength()` here because that fails when
8275 // length is NaN (which is otherwise coerced to zero.)
8276 if (length >= kMaxLength()) {
8277 throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
8278 'size: 0x' + kMaxLength().toString(16) + ' bytes')
8279 }
8280 return length | 0
8281 }
8282
8283 function SlowBuffer (length) {
8284 if (+length != length) { // eslint-disable-line eqeqeq
8285 length = 0
8286 }
8287 return Buffer.alloc(+length)
8288 }
8289
8290 Buffer.isBuffer = function isBuffer (b) {
8291 return !!(b != null && b._isBuffer)
8292 }
8293
8294 Buffer.compare = function compare (a, b) {
8295 if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
8296 throw new TypeError('Arguments must be Buffers')
8297 }
8298
8299 if (a === b) return 0
8300
8301 var x = a.length
8302 var y = b.length
8303
8304 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
8305 if (a[i] !== b[i]) {
8306 x = a[i]
8307 y = b[i]
8308 break
8309 }
8310 }
8311
8312 if (x < y) return -1
8313 if (y < x) return 1
8314 return 0
8315 }
8316
8317 Buffer.isEncoding = function isEncoding (encoding) {
8318 switch (String(encoding).toLowerCase()) {
8319 case 'hex':
8320 case 'utf8':
8321 case 'utf-8':
8322 case 'ascii':
8323 case 'latin1':
8324 case 'binary':
8325 case 'base64':
8326 case 'ucs2':
8327 case 'ucs-2':
8328 case 'utf16le':
8329 case 'utf-16le':
8330 return true
8331 default:
8332 return false
8333 }
8334 }
8335
8336 Buffer.concat = function concat (list, length) {
8337 if (!isArray(list)) {
8338 throw new TypeError('"list" argument must be an Array of Buffers')
8339 }
8340
8341 if (list.length === 0) {
8342 return Buffer.alloc(0)
8343 }
8344
8345 var i
8346 if (length === undefined) {
8347 length = 0
8348 for (i = 0; i < list.length; ++i) {
8349 length += list[i].length
8350 }
8351 }
8352
8353 var buffer = Buffer.allocUnsafe(length)
8354 var pos = 0
8355 for (i = 0; i < list.length; ++i) {
8356 var buf = list[i]
8357 if (!Buffer.isBuffer(buf)) {
8358 throw new TypeError('"list" argument must be an Array of Buffers')
8359 }
8360 buf.copy(buffer, pos)
8361 pos += buf.length
8362 }
8363 return buffer
8364 }
8365
8366 function byteLength (string, encoding) {
8367 if (Buffer.isBuffer(string)) {
8368 return string.length
8369 }
8370 if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
8371 (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
8372 return string.byteLength
8373 }
8374 if (typeof string !== 'string') {
8375 string = '' + string
8376 }
8377
8378 var len = string.length
8379 if (len === 0) return 0
8380
8381 // Use a for loop to avoid recursion
8382 var loweredCase = false
8383 for (;;) {
8384 switch (encoding) {
8385 case 'ascii':
8386 case 'latin1':
8387 case 'binary':
8388 return len
8389 case 'utf8':
8390 case 'utf-8':
8391 case undefined:
8392 return utf8ToBytes(string).length
8393 case 'ucs2':
8394 case 'ucs-2':
8395 case 'utf16le':
8396 case 'utf-16le':
8397 return len * 2
8398 case 'hex':
8399 return len >>> 1
8400 case 'base64':
8401 return base64ToBytes(string).length
8402 default:
8403 if (loweredCase) return utf8ToBytes(string).length // assume utf8
8404 encoding = ('' + encoding).toLowerCase()
8405 loweredCase = true
8406 }
8407 }
8408 }
8409 Buffer.byteLength = byteLength
8410
8411 function slowToString (encoding, start, end) {
8412 var loweredCase = false
8413
8414 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
8415 // property of a typed array.
8416
8417 // This behaves neither like String nor Uint8Array in that we set start/end
8418 // to their upper/lower bounds if the value passed is out of range.
8419 // undefined is handled specially as per ECMA-262 6th Edition,
8420 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
8421 if (start === undefined || start < 0) {
8422 start = 0
8423 }
8424 // Return early if start > this.length. Done here to prevent potential uint32
8425 // coercion fail below.
8426 if (start > this.length) {
8427 return ''
8428 }
8429
8430 if (end === undefined || end > this.length) {
8431 end = this.length
8432 }
8433
8434 if (end <= 0) {
8435 return ''
8436 }
8437
8438 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
8439 end >>>= 0
8440 start >>>= 0
8441
8442 if (end <= start) {
8443 return ''
8444 }
8445
8446 if (!encoding) encoding = 'utf8'
8447
8448 while (true) {
8449 switch (encoding) {
8450 case 'hex':
8451 return hexSlice(this, start, end)
8452
8453 case 'utf8':
8454 case 'utf-8':
8455 return utf8Slice(this, start, end)
8456
8457 case 'ascii':
8458 return asciiSlice(this, start, end)
8459
8460 case 'latin1':
8461 case 'binary':
8462 return latin1Slice(this, start, end)
8463
8464 case 'base64':
8465 return base64Slice(this, start, end)
8466
8467 case 'ucs2':
8468 case 'ucs-2':
8469 case 'utf16le':
8470 case 'utf-16le':
8471 return utf16leSlice(this, start, end)
8472
8473 default:
8474 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
8475 encoding = (encoding + '').toLowerCase()
8476 loweredCase = true
8477 }
8478 }
8479 }
8480
8481 // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
8482 // Buffer instances.
8483 Buffer.prototype._isBuffer = true
8484
8485 function swap (b, n, m) {
8486 var i = b[n]
8487 b[n] = b[m]
8488 b[m] = i
8489 }
8490
8491 Buffer.prototype.swap16 = function swap16 () {
8492 var len = this.length
8493 if (len % 2 !== 0) {
8494 throw new RangeError('Buffer size must be a multiple of 16-bits')
8495 }
8496 for (var i = 0; i < len; i += 2) {
8497 swap(this, i, i + 1)
8498 }
8499 return this
8500 }
8501
8502 Buffer.prototype.swap32 = function swap32 () {
8503 var len = this.length
8504 if (len % 4 !== 0) {
8505 throw new RangeError('Buffer size must be a multiple of 32-bits')
8506 }
8507 for (var i = 0; i < len; i += 4) {
8508 swap(this, i, i + 3)
8509 swap(this, i + 1, i + 2)
8510 }
8511 return this
8512 }
8513
8514 Buffer.prototype.swap64 = function swap64 () {
8515 var len = this.length
8516 if (len % 8 !== 0) {
8517 throw new RangeError('Buffer size must be a multiple of 64-bits')
8518 }
8519 for (var i = 0; i < len; i += 8) {
8520 swap(this, i, i + 7)
8521 swap(this, i + 1, i + 6)
8522 swap(this, i + 2, i + 5)
8523 swap(this, i + 3, i + 4)
8524 }
8525 return this
8526 }
8527
8528 Buffer.prototype.toString = function toString () {
8529 var length = this.length | 0
8530 if (length === 0) return ''
8531 if (arguments.length === 0) return utf8Slice(this, 0, length)
8532 return slowToString.apply(this, arguments)
8533 }
8534
8535 Buffer.prototype.equals = function equals (b) {
8536 if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
8537 if (this === b) return true
8538 return Buffer.compare(this, b) === 0
8539 }
8540
8541 Buffer.prototype.inspect = function inspect () {
8542 var str = ''
8543 var max = exports.INSPECT_MAX_BYTES
8544 if (this.length > 0) {
8545 str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
8546 if (this.length > max) str += ' ... '
8547 }
8548 return '<Buffer ' + str + '>'
8549 }
8550
8551 Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
8552 if (!Buffer.isBuffer(target)) {
8553 throw new TypeError('Argument must be a Buffer')
8554 }
8555
8556 if (start === undefined) {
8557 start = 0
8558 }
8559 if (end === undefined) {
8560 end = target ? target.length : 0
8561 }
8562 if (thisStart === undefined) {
8563 thisStart = 0
8564 }
8565 if (thisEnd === undefined) {
8566 thisEnd = this.length
8567 }
8568
8569 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
8570 throw new RangeError('out of range index')
8571 }
8572
8573 if (thisStart >= thisEnd && start >= end) {
8574 return 0
8575 }
8576 if (thisStart >= thisEnd) {
8577 return -1
8578 }
8579 if (start >= end) {
8580 return 1
8581 }
8582
8583 start >>>= 0
8584 end >>>= 0
8585 thisStart >>>= 0
8586 thisEnd >>>= 0
8587
8588 if (this === target) return 0
8589
8590 var x = thisEnd - thisStart
8591 var y = end - start
8592 var len = Math.min(x, y)
8593
8594 var thisCopy = this.slice(thisStart, thisEnd)
8595 var targetCopy = target.slice(start, end)
8596
8597 for (var i = 0; i < len; ++i) {
8598 if (thisCopy[i] !== targetCopy[i]) {
8599 x = thisCopy[i]
8600 y = targetCopy[i]
8601 break
8602 }
8603 }
8604
8605 if (x < y) return -1
8606 if (y < x) return 1
8607 return 0
8608 }
8609
8610 // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
8611 // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
8612 //
8613 // Arguments:
8614 // - buffer - a Buffer to search
8615 // - val - a string, Buffer, or number
8616 // - byteOffset - an index into `buffer`; will be clamped to an int32
8617 // - encoding - an optional encoding, relevant is val is a string
8618 // - dir - true for indexOf, false for lastIndexOf
8619 function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
8620 // Empty buffer means no match
8621 if (buffer.length === 0) return -1
8622
8623 // Normalize byteOffset
8624 if (typeof byteOffset === 'string') {
8625 encoding = byteOffset
8626 byteOffset = 0
8627 } else if (byteOffset > 0x7fffffff) {
8628 byteOffset = 0x7fffffff
8629 } else if (byteOffset < -0x80000000) {
8630 byteOffset = -0x80000000
8631 }
8632 byteOffset = +byteOffset // Coerce to Number.
8633 if (isNaN(byteOffset)) {
8634 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
8635 byteOffset = dir ? 0 : (buffer.length - 1)
8636 }
8637
8638 // Normalize byteOffset: negative offsets start from the end of the buffer
8639 if (byteOffset < 0) byteOffset = buffer.length + byteOffset
8640 if (byteOffset >= buffer.length) {
8641 if (dir) return -1
8642 else byteOffset = buffer.length - 1
8643 } else if (byteOffset < 0) {
8644 if (dir) byteOffset = 0
8645 else return -1
8646 }
8647
8648 // Normalize val
8649 if (typeof val === 'string') {
8650 val = Buffer.from(val, encoding)
8651 }
8652
8653 // Finally, search either indexOf (if dir is true) or lastIndexOf
8654 if (Buffer.isBuffer(val)) {
8655 // Special case: looking for empty string/buffer always fails
8656 if (val.length === 0) {
8657 return -1
8658 }
8659 return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
8660 } else if (typeof val === 'number') {
8661 val = val & 0xFF // Search for a byte value [0-255]
8662 if (Buffer.TYPED_ARRAY_SUPPORT &&
8663 typeof Uint8Array.prototype.indexOf === 'function') {
8664 if (dir) {
8665 return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
8666 } else {
8667 return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
8668 }
8669 }
8670 return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
8671 }
8672
8673 throw new TypeError('val must be string, number or Buffer')
8674 }
8675
8676 function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
8677 var indexSize = 1
8678 var arrLength = arr.length
8679 var valLength = val.length
8680
8681 if (encoding !== undefined) {
8682 encoding = String(encoding).toLowerCase()
8683 if (encoding === 'ucs2' || encoding === 'ucs-2' ||
8684 encoding === 'utf16le' || encoding === 'utf-16le') {
8685 if (arr.length < 2 || val.length < 2) {
8686 return -1
8687 }
8688 indexSize = 2
8689 arrLength /= 2
8690 valLength /= 2
8691 byteOffset /= 2
8692 }
8693 }
8694
8695 function read (buf, i) {
8696 if (indexSize === 1) {
8697 return buf[i]
8698 } else {
8699 return buf.readUInt16BE(i * indexSize)
8700 }
8701 }
8702
8703 var i
8704 if (dir) {
8705 var foundIndex = -1
8706 for (i = byteOffset; i < arrLength; i++) {
8707 if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
8708 if (foundIndex === -1) foundIndex = i
8709 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
8710 } else {
8711 if (foundIndex !== -1) i -= i - foundIndex
8712 foundIndex = -1
8713 }
8714 }
8715 } else {
8716 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
8717 for (i = byteOffset; i >= 0; i--) {
8718 var found = true
8719 for (var j = 0; j < valLength; j++) {
8720 if (read(arr, i + j) !== read(val, j)) {
8721 found = false
8722 break
8723 }
8724 }
8725 if (found) return i
8726 }
8727 }
8728
8729 return -1
8730 }
8731
8732 Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
8733 return this.indexOf(val, byteOffset, encoding) !== -1
8734 }
8735
8736 Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
8737 return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
8738 }
8739
8740 Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
8741 return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
8742 }
8743
8744 function hexWrite (buf, string, offset, length) {
8745 offset = Number(offset) || 0
8746 var remaining = buf.length - offset
8747 if (!length) {
8748 length = remaining
8749 } else {
8750 length = Number(length)
8751 if (length > remaining) {
8752 length = remaining
8753 }
8754 }
8755
8756 // must be an even number of digits
8757 var strLen = string.length
8758 if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
8759
8760 if (length > strLen / 2) {
8761 length = strLen / 2
8762 }
8763 for (var i = 0; i < length; ++i) {
8764 var parsed = parseInt(string.substr(i * 2, 2), 16)
8765 if (isNaN(parsed)) return i
8766 buf[offset + i] = parsed
8767 }
8768 return i
8769 }
8770
8771 function utf8Write (buf, string, offset, length) {
8772 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
8773 }
8774
8775 function asciiWrite (buf, string, offset, length) {
8776 return blitBuffer(asciiToBytes(string), buf, offset, length)
8777 }
8778
8779 function latin1Write (buf, string, offset, length) {
8780 return asciiWrite(buf, string, offset, length)
8781 }
8782
8783 function base64Write (buf, string, offset, length) {
8784 return blitBuffer(base64ToBytes(string), buf, offset, length)
8785 }
8786
8787 function ucs2Write (buf, string, offset, length) {
8788 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
8789 }
8790
8791 Buffer.prototype.write = function write (string, offset, length, encoding) {
8792 // Buffer#write(string)
8793 if (offset === undefined) {
8794 encoding = 'utf8'
8795 length = this.length
8796 offset = 0
8797 // Buffer#write(string, encoding)
8798 } else if (length === undefined && typeof offset === 'string') {
8799 encoding = offset
8800 length = this.length
8801 offset = 0
8802 // Buffer#write(string, offset[, length][, encoding])
8803 } else if (isFinite(offset)) {
8804 offset = offset | 0
8805 if (isFinite(length)) {
8806 length = length | 0
8807 if (encoding === undefined) encoding = 'utf8'
8808 } else {
8809 encoding = length
8810 length = undefined
8811 }
8812 // legacy write(string, encoding, offset, length) - remove in v0.13
8813 } else {
8814 throw new Error(
8815 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
8816 )
8817 }
8818
8819 var remaining = this.length - offset
8820 if (length === undefined || length > remaining) length = remaining
8821
8822 if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
8823 throw new RangeError('Attempt to write outside buffer bounds')
8824 }
8825
8826 if (!encoding) encoding = 'utf8'
8827
8828 var loweredCase = false
8829 for (;;) {
8830 switch (encoding) {
8831 case 'hex':
8832 return hexWrite(this, string, offset, length)
8833
8834 case 'utf8':
8835 case 'utf-8':
8836 return utf8Write(this, string, offset, length)
8837
8838 case 'ascii':
8839 return asciiWrite(this, string, offset, length)
8840
8841 case 'latin1':
8842 case 'binary':
8843 return latin1Write(this, string, offset, length)
8844
8845 case 'base64':
8846 // Warning: maxLength not taken into account in base64Write
8847 return base64Write(this, string, offset, length)
8848
8849 case 'ucs2':
8850 case 'ucs-2':
8851 case 'utf16le':
8852 case 'utf-16le':
8853 return ucs2Write(this, string, offset, length)
8854
8855 default:
8856 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
8857 encoding = ('' + encoding).toLowerCase()
8858 loweredCase = true
8859 }
8860 }
8861 }
8862
8863 Buffer.prototype.toJSON = function toJSON () {
8864 return {
8865 type: 'Buffer',
8866 data: Array.prototype.slice.call(this._arr || this, 0)
8867 }
8868 }
8869
8870 function base64Slice (buf, start, end) {
8871 if (start === 0 && end === buf.length) {
8872 return base64.fromByteArray(buf)
8873 } else {
8874 return base64.fromByteArray(buf.slice(start, end))
8875 }
8876 }
8877
8878 function utf8Slice (buf, start, end) {
8879 end = Math.min(buf.length, end)
8880 var res = []
8881
8882 var i = start
8883 while (i < end) {
8884 var firstByte = buf[i]
8885 var codePoint = null
8886 var bytesPerSequence = (firstByte > 0xEF) ? 4
8887 : (firstByte > 0xDF) ? 3
8888 : (firstByte > 0xBF) ? 2
8889 : 1
8890
8891 if (i + bytesPerSequence <= end) {
8892 var secondByte, thirdByte, fourthByte, tempCodePoint
8893
8894 switch (bytesPerSequence) {
8895 case 1:
8896 if (firstByte < 0x80) {
8897 codePoint = firstByte
8898 }
8899 break
8900 case 2:
8901 secondByte = buf[i + 1]
8902 if ((secondByte & 0xC0) === 0x80) {
8903 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
8904 if (tempCodePoint > 0x7F) {
8905 codePoint = tempCodePoint
8906 }
8907 }
8908 break
8909 case 3:
8910 secondByte = buf[i + 1]
8911 thirdByte = buf[i + 2]
8912 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
8913 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
8914 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
8915 codePoint = tempCodePoint
8916 }
8917 }
8918 break
8919 case 4:
8920 secondByte = buf[i + 1]
8921 thirdByte = buf[i + 2]
8922 fourthByte = buf[i + 3]
8923 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
8924 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
8925 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
8926 codePoint = tempCodePoint
8927 }
8928 }
8929 }
8930 }
8931
8932 if (codePoint === null) {
8933 // we did not generate a valid codePoint so insert a
8934 // replacement char (U+FFFD) and advance only 1 byte
8935 codePoint = 0xFFFD
8936 bytesPerSequence = 1
8937 } else if (codePoint > 0xFFFF) {
8938 // encode to utf16 (surrogate pair dance)
8939 codePoint -= 0x10000
8940 res.push(codePoint >>> 10 & 0x3FF | 0xD800)
8941 codePoint = 0xDC00 | codePoint & 0x3FF
8942 }
8943
8944 res.push(codePoint)
8945 i += bytesPerSequence
8946 }
8947
8948 return decodeCodePointsArray(res)
8949 }
8950
8951 // Based on http://stackoverflow.com/a/22747272/680742, the browser with
8952 // the lowest limit is Chrome, with 0x10000 args.
8953 // We go 1 magnitude less, for safety
8954 var MAX_ARGUMENTS_LENGTH = 0x1000
8955
8956 function decodeCodePointsArray (codePoints) {
8957 var len = codePoints.length
8958 if (len <= MAX_ARGUMENTS_LENGTH) {
8959 return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
8960 }
8961
8962 // Decode in chunks to avoid "call stack size exceeded".
8963 var res = ''
8964 var i = 0
8965 while (i < len) {
8966 res += String.fromCharCode.apply(
8967 String,
8968 codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
8969 )
8970 }
8971 return res
8972 }
8973
8974 function asciiSlice (buf, start, end) {
8975 var ret = ''
8976 end = Math.min(buf.length, end)
8977
8978 for (var i = start; i < end; ++i) {
8979 ret += String.fromCharCode(buf[i] & 0x7F)
8980 }
8981 return ret
8982 }
8983
8984 function latin1Slice (buf, start, end) {
8985 var ret = ''
8986 end = Math.min(buf.length, end)
8987
8988 for (var i = start; i < end; ++i) {
8989 ret += String.fromCharCode(buf[i])
8990 }
8991 return ret
8992 }
8993
8994 function hexSlice (buf, start, end) {
8995 var len = buf.length
8996
8997 if (!start || start < 0) start = 0
8998 if (!end || end < 0 || end > len) end = len
8999
9000 var out = ''
9001 for (var i = start; i < end; ++i) {
9002 out += toHex(buf[i])
9003 }
9004 return out
9005 }
9006
9007 function utf16leSlice (buf, start, end) {
9008 var bytes = buf.slice(start, end)
9009 var res = ''
9010 for (var i = 0; i < bytes.length; i += 2) {
9011 res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
9012 }
9013 return res
9014 }
9015
9016 Buffer.prototype.slice = function slice (start, end) {
9017 var len = this.length
9018 start = ~~start
9019 end = end === undefined ? len : ~~end
9020
9021 if (start < 0) {
9022 start += len
9023 if (start < 0) start = 0
9024 } else if (start > len) {
9025 start = len
9026 }
9027
9028 if (end < 0) {
9029 end += len
9030 if (end < 0) end = 0
9031 } else if (end > len) {
9032 end = len
9033 }
9034
9035 if (end < start) end = start
9036
9037 var newBuf
9038 if (Buffer.TYPED_ARRAY_SUPPORT) {
9039 newBuf = this.subarray(start, end)
9040 newBuf.__proto__ = Buffer.prototype
9041 } else {
9042 var sliceLen = end - start
9043 newBuf = new Buffer(sliceLen, undefined)
9044 for (var i = 0; i < sliceLen; ++i) {
9045 newBuf[i] = this[i + start]
9046 }
9047 }
9048
9049 return newBuf
9050 }
9051
9052 /*
9053 * Need to make sure that buffer isn't trying to write out of bounds.
9054 */
9055 function checkOffset (offset, ext, length) {
9056 if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
9057 if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
9058 }
9059
9060 Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
9061 offset = offset | 0
9062 byteLength = byteLength | 0
9063 if (!noAssert) checkOffset(offset, byteLength, this.length)
9064
9065 var val = this[offset]
9066 var mul = 1
9067 var i = 0
9068 while (++i < byteLength && (mul *= 0x100)) {
9069 val += this[offset + i] * mul
9070 }
9071
9072 return val
9073 }
9074
9075 Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
9076 offset = offset | 0
9077 byteLength = byteLength | 0
9078 if (!noAssert) {
9079 checkOffset(offset, byteLength, this.length)
9080 }
9081
9082 var val = this[offset + --byteLength]
9083 var mul = 1
9084 while (byteLength > 0 && (mul *= 0x100)) {
9085 val += this[offset + --byteLength] * mul
9086 }
9087
9088 return val
9089 }
9090
9091 Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
9092 if (!noAssert) checkOffset(offset, 1, this.length)
9093 return this[offset]
9094 }
9095
9096 Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
9097 if (!noAssert) checkOffset(offset, 2, this.length)
9098 return this[offset] | (this[offset + 1] << 8)
9099 }
9100
9101 Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
9102 if (!noAssert) checkOffset(offset, 2, this.length)
9103 return (this[offset] << 8) | this[offset + 1]
9104 }
9105
9106 Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
9107 if (!noAssert) checkOffset(offset, 4, this.length)
9108
9109 return ((this[offset]) |
9110 (this[offset + 1] << 8) |
9111 (this[offset + 2] << 16)) +
9112 (this[offset + 3] * 0x1000000)
9113 }
9114
9115 Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
9116 if (!noAssert) checkOffset(offset, 4, this.length)
9117
9118 return (this[offset] * 0x1000000) +
9119 ((this[offset + 1] << 16) |
9120 (this[offset + 2] << 8) |
9121 this[offset + 3])
9122 }
9123
9124 Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
9125 offset = offset | 0
9126 byteLength = byteLength | 0
9127 if (!noAssert) checkOffset(offset, byteLength, this.length)
9128
9129 var val = this[offset]
9130 var mul = 1
9131 var i = 0
9132 while (++i < byteLength && (mul *= 0x100)) {
9133 val += this[offset + i] * mul
9134 }
9135 mul *= 0x80
9136
9137 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
9138
9139 return val
9140 }
9141
9142 Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
9143 offset = offset | 0
9144 byteLength = byteLength | 0
9145 if (!noAssert) checkOffset(offset, byteLength, this.length)
9146
9147 var i = byteLength
9148 var mul = 1
9149 var val = this[offset + --i]
9150 while (i > 0 && (mul *= 0x100)) {
9151 val += this[offset + --i] * mul
9152 }
9153 mul *= 0x80
9154
9155 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
9156
9157 return val
9158 }
9159
9160 Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
9161 if (!noAssert) checkOffset(offset, 1, this.length)
9162 if (!(this[offset] & 0x80)) return (this[offset])
9163 return ((0xff - this[offset] + 1) * -1)
9164 }
9165
9166 Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
9167 if (!noAssert) checkOffset(offset, 2, this.length)
9168 var val = this[offset] | (this[offset + 1] << 8)
9169 return (val & 0x8000) ? val | 0xFFFF0000 : val
9170 }
9171
9172 Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
9173 if (!noAssert) checkOffset(offset, 2, this.length)
9174 var val = this[offset + 1] | (this[offset] << 8)
9175 return (val & 0x8000) ? val | 0xFFFF0000 : val
9176 }
9177
9178 Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
9179 if (!noAssert) checkOffset(offset, 4, this.length)
9180
9181 return (this[offset]) |
9182 (this[offset + 1] << 8) |
9183 (this[offset + 2] << 16) |
9184 (this[offset + 3] << 24)
9185 }
9186
9187 Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
9188 if (!noAssert) checkOffset(offset, 4, this.length)
9189
9190 return (this[offset] << 24) |
9191 (this[offset + 1] << 16) |
9192 (this[offset + 2] << 8) |
9193 (this[offset + 3])
9194 }
9195
9196 Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
9197 if (!noAssert) checkOffset(offset, 4, this.length)
9198 return ieee754.read(this, offset, true, 23, 4)
9199 }
9200
9201 Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
9202 if (!noAssert) checkOffset(offset, 4, this.length)
9203 return ieee754.read(this, offset, false, 23, 4)
9204 }
9205
9206 Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
9207 if (!noAssert) checkOffset(offset, 8, this.length)
9208 return ieee754.read(this, offset, true, 52, 8)
9209 }
9210
9211 Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
9212 if (!noAssert) checkOffset(offset, 8, this.length)
9213 return ieee754.read(this, offset, false, 52, 8)
9214 }
9215
9216 function checkInt (buf, value, offset, ext, max, min) {
9217 if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
9218 if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
9219 if (offset + ext > buf.length) throw new RangeError('Index out of range')
9220 }
9221
9222 Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
9223 value = +value
9224 offset = offset | 0
9225 byteLength = byteLength | 0
9226 if (!noAssert) {
9227 var maxBytes = Math.pow(2, 8 * byteLength) - 1
9228 checkInt(this, value, offset, byteLength, maxBytes, 0)
9229 }
9230
9231 var mul = 1
9232 var i = 0
9233 this[offset] = value & 0xFF
9234 while (++i < byteLength && (mul *= 0x100)) {
9235 this[offset + i] = (value / mul) & 0xFF
9236 }
9237
9238 return offset + byteLength
9239 }
9240
9241 Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
9242 value = +value
9243 offset = offset | 0
9244 byteLength = byteLength | 0
9245 if (!noAssert) {
9246 var maxBytes = Math.pow(2, 8 * byteLength) - 1
9247 checkInt(this, value, offset, byteLength, maxBytes, 0)
9248 }
9249
9250 var i = byteLength - 1
9251 var mul = 1
9252 this[offset + i] = value & 0xFF
9253 while (--i >= 0 && (mul *= 0x100)) {
9254 this[offset + i] = (value / mul) & 0xFF
9255 }
9256
9257 return offset + byteLength
9258 }
9259
9260 Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
9261 value = +value
9262 offset = offset | 0
9263 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
9264 if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
9265 this[offset] = (value & 0xff)
9266 return offset + 1
9267 }
9268
9269 function objectWriteUInt16 (buf, value, offset, littleEndian) {
9270 if (value < 0) value = 0xffff + value + 1
9271 for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
9272 buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
9273 (littleEndian ? i : 1 - i) * 8
9274 }
9275 }
9276
9277 Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
9278 value = +value
9279 offset = offset | 0
9280 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
9281 if (Buffer.TYPED_ARRAY_SUPPORT) {
9282 this[offset] = (value & 0xff)
9283 this[offset + 1] = (value >>> 8)
9284 } else {
9285 objectWriteUInt16(this, value, offset, true)
9286 }
9287 return offset + 2
9288 }
9289
9290 Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
9291 value = +value
9292 offset = offset | 0
9293 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
9294 if (Buffer.TYPED_ARRAY_SUPPORT) {
9295 this[offset] = (value >>> 8)
9296 this[offset + 1] = (value & 0xff)
9297 } else {
9298 objectWriteUInt16(this, value, offset, false)
9299 }
9300 return offset + 2
9301 }
9302
9303 function objectWriteUInt32 (buf, value, offset, littleEndian) {
9304 if (value < 0) value = 0xffffffff + value + 1
9305 for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
9306 buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
9307 }
9308 }
9309
9310 Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
9311 value = +value
9312 offset = offset | 0
9313 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
9314 if (Buffer.TYPED_ARRAY_SUPPORT) {
9315 this[offset + 3] = (value >>> 24)
9316 this[offset + 2] = (value >>> 16)
9317 this[offset + 1] = (value >>> 8)
9318 this[offset] = (value & 0xff)
9319 } else {
9320 objectWriteUInt32(this, value, offset, true)
9321 }
9322 return offset + 4
9323 }
9324
9325 Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
9326 value = +value
9327 offset = offset | 0
9328 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
9329 if (Buffer.TYPED_ARRAY_SUPPORT) {
9330 this[offset] = (value >>> 24)
9331 this[offset + 1] = (value >>> 16)
9332 this[offset + 2] = (value >>> 8)
9333 this[offset + 3] = (value & 0xff)
9334 } else {
9335 objectWriteUInt32(this, value, offset, false)
9336 }
9337 return offset + 4
9338 }
9339
9340 Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
9341 value = +value
9342 offset = offset | 0
9343 if (!noAssert) {
9344 var limit = Math.pow(2, 8 * byteLength - 1)
9345
9346 checkInt(this, value, offset, byteLength, limit - 1, -limit)
9347 }
9348
9349 var i = 0
9350 var mul = 1
9351 var sub = 0
9352 this[offset] = value & 0xFF
9353 while (++i < byteLength && (mul *= 0x100)) {
9354 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
9355 sub = 1
9356 }
9357 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
9358 }
9359
9360 return offset + byteLength
9361 }
9362
9363 Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
9364 value = +value
9365 offset = offset | 0
9366 if (!noAssert) {
9367 var limit = Math.pow(2, 8 * byteLength - 1)
9368
9369 checkInt(this, value, offset, byteLength, limit - 1, -limit)
9370 }
9371
9372 var i = byteLength - 1
9373 var mul = 1
9374 var sub = 0
9375 this[offset + i] = value & 0xFF
9376 while (--i >= 0 && (mul *= 0x100)) {
9377 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
9378 sub = 1
9379 }
9380 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
9381 }
9382
9383 return offset + byteLength
9384 }
9385
9386 Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
9387 value = +value
9388 offset = offset | 0
9389 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
9390 if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
9391 if (value < 0) value = 0xff + value + 1
9392 this[offset] = (value & 0xff)
9393 return offset + 1
9394 }
9395
9396 Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
9397 value = +value
9398 offset = offset | 0
9399 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
9400 if (Buffer.TYPED_ARRAY_SUPPORT) {
9401 this[offset] = (value & 0xff)
9402 this[offset + 1] = (value >>> 8)
9403 } else {
9404 objectWriteUInt16(this, value, offset, true)
9405 }
9406 return offset + 2
9407 }
9408
9409 Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
9410 value = +value
9411 offset = offset | 0
9412 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
9413 if (Buffer.TYPED_ARRAY_SUPPORT) {
9414 this[offset] = (value >>> 8)
9415 this[offset + 1] = (value & 0xff)
9416 } else {
9417 objectWriteUInt16(this, value, offset, false)
9418 }
9419 return offset + 2
9420 }
9421
9422 Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
9423 value = +value
9424 offset = offset | 0
9425 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
9426 if (Buffer.TYPED_ARRAY_SUPPORT) {
9427 this[offset] = (value & 0xff)
9428 this[offset + 1] = (value >>> 8)
9429 this[offset + 2] = (value >>> 16)
9430 this[offset + 3] = (value >>> 24)
9431 } else {
9432 objectWriteUInt32(this, value, offset, true)
9433 }
9434 return offset + 4
9435 }
9436
9437 Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
9438 value = +value
9439 offset = offset | 0
9440 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
9441 if (value < 0) value = 0xffffffff + value + 1
9442 if (Buffer.TYPED_ARRAY_SUPPORT) {
9443 this[offset] = (value >>> 24)
9444 this[offset + 1] = (value >>> 16)
9445 this[offset + 2] = (value >>> 8)
9446 this[offset + 3] = (value & 0xff)
9447 } else {
9448 objectWriteUInt32(this, value, offset, false)
9449 }
9450 return offset + 4
9451 }
9452
9453 function checkIEEE754 (buf, value, offset, ext, max, min) {
9454 if (offset + ext > buf.length) throw new RangeError('Index out of range')
9455 if (offset < 0) throw new RangeError('Index out of range')
9456 }
9457
9458 function writeFloat (buf, value, offset, littleEndian, noAssert) {
9459 if (!noAssert) {
9460 checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
9461 }
9462 ieee754.write(buf, value, offset, littleEndian, 23, 4)
9463 return offset + 4
9464 }
9465
9466 Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
9467 return writeFloat(this, value, offset, true, noAssert)
9468 }
9469
9470 Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
9471 return writeFloat(this, value, offset, false, noAssert)
9472 }
9473
9474 function writeDouble (buf, value, offset, littleEndian, noAssert) {
9475 if (!noAssert) {
9476 checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
9477 }
9478 ieee754.write(buf, value, offset, littleEndian, 52, 8)
9479 return offset + 8
9480 }
9481
9482 Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
9483 return writeDouble(this, value, offset, true, noAssert)
9484 }
9485
9486 Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
9487 return writeDouble(this, value, offset, false, noAssert)
9488 }
9489
9490 // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
9491 Buffer.prototype.copy = function copy (target, targetStart, start, end) {
9492 if (!start) start = 0
9493 if (!end && end !== 0) end = this.length
9494 if (targetStart >= target.length) targetStart = target.length
9495 if (!targetStart) targetStart = 0
9496 if (end > 0 && end < start) end = start
9497
9498 // Copy 0 bytes; we're done
9499 if (end === start) return 0
9500 if (target.length === 0 || this.length === 0) return 0
9501
9502 // Fatal error conditions
9503 if (targetStart < 0) {
9504 throw new RangeError('targetStart out of bounds')
9505 }
9506 if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
9507 if (end < 0) throw new RangeError('sourceEnd out of bounds')
9508
9509 // Are we oob?
9510 if (end > this.length) end = this.length
9511 if (target.length - targetStart < end - start) {
9512 end = target.length - targetStart + start
9513 }
9514
9515 var len = end - start
9516 var i
9517
9518 if (this === target && start < targetStart && targetStart < end) {
9519 // descending copy from end
9520 for (i = len - 1; i >= 0; --i) {
9521 target[i + targetStart] = this[i + start]
9522 }
9523 } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
9524 // ascending copy from start
9525 for (i = 0; i < len; ++i) {
9526 target[i + targetStart] = this[i + start]
9527 }
9528 } else {
9529 Uint8Array.prototype.set.call(
9530 target,
9531 this.subarray(start, start + len),
9532 targetStart
9533 )
9534 }
9535
9536 return len
9537 }
9538
9539 // Usage:
9540 // buffer.fill(number[, offset[, end]])
9541 // buffer.fill(buffer[, offset[, end]])
9542 // buffer.fill(string[, offset[, end]][, encoding])
9543 Buffer.prototype.fill = function fill (val, start, end, encoding) {
9544 // Handle string cases:
9545 if (typeof val === 'string') {
9546 if (typeof start === 'string') {
9547 encoding = start
9548 start = 0
9549 end = this.length
9550 } else if (typeof end === 'string') {
9551 encoding = end
9552 end = this.length
9553 }
9554 if (val.length === 1) {
9555 var code = val.charCodeAt(0)
9556 if (code < 256) {
9557 val = code
9558 }
9559 }
9560 if (encoding !== undefined && typeof encoding !== 'string') {
9561 throw new TypeError('encoding must be a string')
9562 }
9563 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
9564 throw new TypeError('Unknown encoding: ' + encoding)
9565 }
9566 } else if (typeof val === 'number') {
9567 val = val & 255
9568 }
9569
9570 // Invalid ranges are not set to a default, so can range check early.
9571 if (start < 0 || this.length < start || this.length < end) {
9572 throw new RangeError('Out of range index')
9573 }
9574
9575 if (end <= start) {
9576 return this
9577 }
9578
9579 start = start >>> 0
9580 end = end === undefined ? this.length : end >>> 0
9581
9582 if (!val) val = 0
9583
9584 var i
9585 if (typeof val === 'number') {
9586 for (i = start; i < end; ++i) {
9587 this[i] = val
9588 }
9589 } else {
9590 var bytes = Buffer.isBuffer(val)
9591 ? val
9592 : utf8ToBytes(new Buffer(val, encoding).toString())
9593 var len = bytes.length
9594 for (i = 0; i < end - start; ++i) {
9595 this[i + start] = bytes[i % len]
9596 }
9597 }
9598
9599 return this
9600 }
9601
9602 // HELPER FUNCTIONS
9603 // ================
9604
9605 var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
9606
9607 function base64clean (str) {
9608 // Node strips out invalid characters like \n and \t from the string, base64-js does not
9609 str = stringtrim(str).replace(INVALID_BASE64_RE, '')
9610 // Node converts strings with length < 2 to ''
9611 if (str.length < 2) return ''
9612 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
9613 while (str.length % 4 !== 0) {
9614 str = str + '='
9615 }
9616 return str
9617 }
9618
9619 function stringtrim (str) {
9620 if (str.trim) return str.trim()
9621 return str.replace(/^\s+|\s+$/g, '')
9622 }
9623
9624 function toHex (n) {
9625 if (n < 16) return '0' + n.toString(16)
9626 return n.toString(16)
9627 }
9628
9629 function utf8ToBytes (string, units) {
9630 units = units || Infinity
9631 var codePoint
9632 var length = string.length
9633 var leadSurrogate = null
9634 var bytes = []
9635
9636 for (var i = 0; i < length; ++i) {
9637 codePoint = string.charCodeAt(i)
9638
9639 // is surrogate component
9640 if (codePoint > 0xD7FF && codePoint < 0xE000) {
9641 // last char was a lead
9642 if (!leadSurrogate) {
9643 // no lead yet
9644 if (codePoint > 0xDBFF) {
9645 // unexpected trail
9646 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
9647 continue
9648 } else if (i + 1 === length) {
9649 // unpaired lead
9650 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
9651 continue
9652 }
9653
9654 // valid lead
9655 leadSurrogate = codePoint
9656
9657 continue
9658 }
9659
9660 // 2 leads in a row
9661 if (codePoint < 0xDC00) {
9662 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
9663 leadSurrogate = codePoint
9664 continue
9665 }
9666
9667 // valid surrogate pair
9668 codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
9669 } else if (leadSurrogate) {
9670 // valid bmp char, but last char was a lead
9671 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
9672 }
9673
9674 leadSurrogate = null
9675
9676 // encode utf8
9677 if (codePoint < 0x80) {
9678 if ((units -= 1) < 0) break
9679 bytes.push(codePoint)
9680 } else if (codePoint < 0x800) {
9681 if ((units -= 2) < 0) break
9682 bytes.push(
9683 codePoint >> 0x6 | 0xC0,
9684 codePoint & 0x3F | 0x80
9685 )
9686 } else if (codePoint < 0x10000) {
9687 if ((units -= 3) < 0) break
9688 bytes.push(
9689 codePoint >> 0xC | 0xE0,
9690 codePoint >> 0x6 & 0x3F | 0x80,
9691 codePoint & 0x3F | 0x80
9692 )
9693 } else if (codePoint < 0x110000) {
9694 if ((units -= 4) < 0) break
9695 bytes.push(
9696 codePoint >> 0x12 | 0xF0,
9697 codePoint >> 0xC & 0x3F | 0x80,
9698 codePoint >> 0x6 & 0x3F | 0x80,
9699 codePoint & 0x3F | 0x80
9700 )
9701 } else {
9702 throw new Error('Invalid code point')
9703 }
9704 }
9705
9706 return bytes
9707 }
9708
9709 function asciiToBytes (str) {
9710 var byteArray = []
9711 for (var i = 0; i < str.length; ++i) {
9712 // Node's code seems to be doing this and not & 0x7F..
9713 byteArray.push(str.charCodeAt(i) & 0xFF)
9714 }
9715 return byteArray
9716 }
9717
9718 function utf16leToBytes (str, units) {
9719 var c, hi, lo
9720 var byteArray = []
9721 for (var i = 0; i < str.length; ++i) {
9722 if ((units -= 2) < 0) break
9723
9724 c = str.charCodeAt(i)
9725 hi = c >> 8
9726 lo = c % 256
9727 byteArray.push(lo)
9728 byteArray.push(hi)
9729 }
9730
9731 return byteArray
9732 }
9733
9734 function base64ToBytes (str) {
9735 return base64.toByteArray(base64clean(str))
9736 }
9737
9738 function blitBuffer (src, dst, offset, length) {
9739 for (var i = 0; i < length; ++i) {
9740 if ((i + offset >= dst.length) || (i >= src.length)) break
9741 dst[i + offset] = src[i]
9742 }
9743 return i
9744 }
9745
9746 function isnan (val) {
9747 return val !== val // eslint-disable-line no-self-compare
9748 }
9749
9750 /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(15).Buffer, (function() { return this; }())))
9751
9752/***/ },
9753/* 16 */
9754/***/ function(module, exports, __webpack_require__) {
9755
9756 'use strict';
9757
9758 exports.__esModule = true;
9759 exports.default = functor;
9760
9761 var _ramda = __webpack_require__(4);
9762
9763 function functor(v) {
9764 return (0, _ramda.is)(Function, v) ? v : function () {
9765 return v;
9766 };
9767 }
9768
9769/***/ },
9770/* 17 */
9771/***/ function(module, exports, __webpack_require__) {
9772
9773 var stackClear = __webpack_require__(91),
9774 stackDelete = __webpack_require__(92),
9775 stackGet = __webpack_require__(93),
9776 stackHas = __webpack_require__(94),
9777 stackSet = __webpack_require__(95);
9778
9779 /**
9780 * Creates a stack cache object to store key-value pairs.
9781 *
9782 * @private
9783 * @param {Array} [values] The values to cache.
9784 */
9785 function Stack(values) {
9786 var index = -1,
9787 length = values ? values.length : 0;
9788
9789 this.clear();
9790 while (++index < length) {
9791 var entry = values[index];
9792 this.set(entry[0], entry[1]);
9793 }
9794 }
9795
9796 // Add functions to the `Stack` cache.
9797 Stack.prototype.clear = stackClear;
9798 Stack.prototype['delete'] = stackDelete;
9799 Stack.prototype.get = stackGet;
9800 Stack.prototype.has = stackHas;
9801 Stack.prototype.set = stackSet;
9802
9803 module.exports = Stack;
9804
9805
9806/***/ },
9807/* 18 */
9808/***/ function(module, exports, __webpack_require__) {
9809
9810 var root = __webpack_require__(8);
9811
9812 /** Built-in value references. */
9813 var Symbol = root.Symbol;
9814
9815 module.exports = Symbol;
9816
9817
9818/***/ },
9819/* 19 */
9820/***/ function(module, exports, __webpack_require__) {
9821
9822 var assocIndexOf = __webpack_require__(5);
9823
9824 /** Used for built-in method references. */
9825 var arrayProto = Array.prototype;
9826
9827 /** Built-in value references. */
9828 var splice = arrayProto.splice;
9829
9830 /**
9831 * Removes `key` and its value from the associative array.
9832 *
9833 * @private
9834 * @param {Array} array The array to query.
9835 * @param {string} key The key of the value to remove.
9836 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
9837 */
9838 function assocDelete(array, key) {
9839 var index = assocIndexOf(array, key);
9840 if (index < 0) {
9841 return false;
9842 }
9843 var lastIndex = array.length - 1;
9844 if (index == lastIndex) {
9845 array.pop();
9846 } else {
9847 splice.call(array, index, 1);
9848 }
9849 return true;
9850 }
9851
9852 module.exports = assocDelete;
9853
9854
9855/***/ },
9856/* 20 */
9857/***/ function(module, exports, __webpack_require__) {
9858
9859 var assocIndexOf = __webpack_require__(5);
9860
9861 /**
9862 * Gets the associative array value for `key`.
9863 *
9864 * @private
9865 * @param {Array} array The array to query.
9866 * @param {string} key The key of the value to get.
9867 * @returns {*} Returns the entry value.
9868 */
9869 function assocGet(array, key) {
9870 var index = assocIndexOf(array, key);
9871 return index < 0 ? undefined : array[index][1];
9872 }
9873
9874 module.exports = assocGet;
9875
9876
9877/***/ },
9878/* 21 */
9879/***/ function(module, exports, __webpack_require__) {
9880
9881 var assocIndexOf = __webpack_require__(5);
9882
9883 /**
9884 * Checks if an associative array value for `key` exists.
9885 *
9886 * @private
9887 * @param {Array} array The array to query.
9888 * @param {string} key The key of the entry to check.
9889 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
9890 */
9891 function assocHas(array, key) {
9892 return assocIndexOf(array, key) > -1;
9893 }
9894
9895 module.exports = assocHas;
9896
9897
9898/***/ },
9899/* 22 */
9900/***/ function(module, exports, __webpack_require__) {
9901
9902 var assocIndexOf = __webpack_require__(5);
9903
9904 /**
9905 * Sets the associative array `key` to `value`.
9906 *
9907 * @private
9908 * @param {Array} array The array to modify.
9909 * @param {string} key The key of the value to set.
9910 * @param {*} value The value to set.
9911 */
9912 function assocSet(array, key, value) {
9913 var index = assocIndexOf(array, key);
9914 if (index < 0) {
9915 array.push([key, value]);
9916 } else {
9917 array[index][1] = value;
9918 }
9919 }
9920
9921 module.exports = assocSet;
9922
9923
9924/***/ },
9925/* 23 */
9926/***/ function(module, exports, __webpack_require__) {
9927
9928 var baseToPath = __webpack_require__(27),
9929 isKey = __webpack_require__(12);
9930
9931 /**
9932 * The base implementation of `_.get` without support for default values.
9933 *
9934 * @private
9935 * @param {Object} object The object to query.
9936 * @param {Array|string} path The path of the property to get.
9937 * @returns {*} Returns the resolved value.
9938 */
9939 function baseGet(object, path) {
9940 path = isKey(path, object) ? [path + ''] : baseToPath(path);
9941
9942 var index = 0,
9943 length = path.length;
9944
9945 while (object != null && index < length) {
9946 object = object[path[index++]];
9947 }
9948 return (index && index == length) ? object : undefined;
9949 }
9950
9951 module.exports = baseGet;
9952
9953
9954/***/ },
9955/* 24 */
9956/***/ function(module, exports) {
9957
9958 /** Used for built-in method references. */
9959 var objectProto = Object.prototype;
9960
9961 /** Used to check objects for own properties. */
9962 var hasOwnProperty = objectProto.hasOwnProperty;
9963
9964 /** Built-in value references. */
9965 var getPrototypeOf = Object.getPrototypeOf;
9966
9967 /**
9968 * The base implementation of `_.has` without support for deep paths.
9969 *
9970 * @private
9971 * @param {Object} object The object to query.
9972 * @param {Array|string} key The key to check.
9973 * @returns {boolean} Returns `true` if `key` exists, else `false`.
9974 */
9975 function baseHas(object, key) {
9976 // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
9977 // that are composed entirely of index properties, return `false` for
9978 // `hasOwnProperty` checks of them.
9979 return hasOwnProperty.call(object, key) ||
9980 (typeof object == 'object' && key in object && getPrototypeOf(object) === null);
9981 }
9982
9983 module.exports = baseHas;
9984
9985
9986/***/ },
9987/* 25 */
9988/***/ function(module, exports, __webpack_require__) {
9989
9990 var baseIsEqualDeep = __webpack_require__(58),
9991 isObject = __webpack_require__(13),
9992 isObjectLike = __webpack_require__(2);
9993
9994 /**
9995 * The base implementation of `_.isEqual` which supports partial comparisons
9996 * and tracks traversed objects.
9997 *
9998 * @private
9999 * @param {*} value The value to compare.
10000 * @param {*} other The other value to compare.
10001 * @param {Function} [customizer] The function to customize comparisons.
10002 * @param {boolean} [bitmask] The bitmask of comparison flags.
10003 * The bitmask may be composed of the following flags:
10004 * 1 - Unordered comparison
10005 * 2 - Partial comparison
10006 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
10007 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
10008 */
10009 function baseIsEqual(value, other, customizer, bitmask, stack) {
10010 if (value === other) {
10011 return true;
10012 }
10013 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
10014 return value !== value && other !== other;
10015 }
10016 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
10017 }
10018
10019 module.exports = baseIsEqual;
10020
10021
10022/***/ },
10023/* 26 */
10024/***/ function(module, exports) {
10025
10026 /**
10027 * The base implementation of `_.property` without support for deep paths.
10028 *
10029 * @private
10030 * @param {string} key The key of the property to get.
10031 * @returns {Function} Returns the new function.
10032 */
10033 function baseProperty(key) {
10034 return function(object) {
10035 return object == null ? undefined : object[key];
10036 };
10037 }
10038
10039 module.exports = baseProperty;
10040
10041
10042/***/ },
10043/* 27 */
10044/***/ function(module, exports, __webpack_require__) {
10045
10046 var isArray = __webpack_require__(1),
10047 stringToPath = __webpack_require__(96);
10048
10049 /**
10050 * The base implementation of `_.toPath` which only converts `value` to a
10051 * path if it's not one.
10052 *
10053 * @private
10054 * @param {*} value The value to process.
10055 * @returns {Array} Returns the property path array.
10056 */
10057 function baseToPath(value) {
10058 return isArray(value) ? value : stringToPath(value);
10059 }
10060
10061 module.exports = baseToPath;
10062
10063
10064/***/ },
10065/* 28 */
10066/***/ function(module, exports, __webpack_require__) {
10067
10068 var nativeCreate = __webpack_require__(7);
10069
10070 /** Used for built-in method references. */
10071 var objectProto = Object.prototype;
10072
10073 /** Used to check objects for own properties. */
10074 var hasOwnProperty = objectProto.hasOwnProperty;
10075
10076 /**
10077 * Checks if a hash value for `key` exists.
10078 *
10079 * @private
10080 * @param {Object} hash The hash to query.
10081 * @param {string} key The key of the entry to check.
10082 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
10083 */
10084 function hashHas(hash, key) {
10085 return nativeCreate ? hash[key] !== undefined : hasOwnProperty.call(hash, key);
10086 }
10087
10088 module.exports = hashHas;
10089
10090
10091/***/ },
10092/* 29 */
10093/***/ function(module, exports) {
10094
10095 /** Used as references for various `Number` constants. */
10096 var MAX_SAFE_INTEGER = 9007199254740991;
10097
10098 /** Used to detect unsigned integer values. */
10099 var reIsUint = /^(?:0|[1-9]\d*)$/;
10100
10101 /**
10102 * Checks if `value` is a valid array-like index.
10103 *
10104 * @private
10105 * @param {*} value The value to check.
10106 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
10107 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
10108 */
10109 function isIndex(value, length) {
10110 value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
10111 length = length == null ? MAX_SAFE_INTEGER : length;
10112 return value > -1 && value % 1 == 0 && value < length;
10113 }
10114
10115 module.exports = isIndex;
10116
10117
10118/***/ },
10119/* 30 */
10120/***/ function(module, exports, __webpack_require__) {
10121
10122 var baseGet = __webpack_require__(23);
10123
10124 /**
10125 * Gets the value at `path` of `object`. If the resolved value is
10126 * `undefined` the `defaultValue` is used in its place.
10127 *
10128 * @static
10129 * @memberOf _
10130 * @category Object
10131 * @param {Object} object The object to query.
10132 * @param {Array|string} path The path of the property to get.
10133 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
10134 * @returns {*} Returns the resolved value.
10135 * @example
10136 *
10137 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
10138 *
10139 * _.get(object, 'a[0].b.c');
10140 * // => 3
10141 *
10142 * _.get(object, ['a', '0', 'b', 'c']);
10143 * // => 3
10144 *
10145 * _.get(object, 'a.b.c', 'default');
10146 * // => 'default'
10147 */
10148 function get(object, path, defaultValue) {
10149 var result = object == null ? undefined : baseGet(object, path);
10150 return result === undefined ? defaultValue : result;
10151 }
10152
10153 module.exports = get;
10154
10155
10156/***/ },
10157/* 31 */
10158/***/ function(module, exports, __webpack_require__) {
10159
10160 var isArrayLikeObject = __webpack_require__(100);
10161
10162 /** `Object#toString` result references. */
10163 var argsTag = '[object Arguments]';
10164
10165 /** Used for built-in method references. */
10166 var objectProto = Object.prototype;
10167
10168 /** Used to check objects for own properties. */
10169 var hasOwnProperty = objectProto.hasOwnProperty;
10170
10171 /**
10172 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
10173 * of values.
10174 */
10175 var objectToString = objectProto.toString;
10176
10177 /** Built-in value references. */
10178 var propertyIsEnumerable = objectProto.propertyIsEnumerable;
10179
10180 /**
10181 * Checks if `value` is likely an `arguments` object.
10182 *
10183 * @static
10184 * @memberOf _
10185 * @category Lang
10186 * @param {*} value The value to check.
10187 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10188 * @example
10189 *
10190 * _.isArguments(function() { return arguments; }());
10191 * // => true
10192 *
10193 * _.isArguments([1, 2, 3]);
10194 * // => false
10195 */
10196 function isArguments(value) {
10197 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
10198 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
10199 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
10200 }
10201
10202 module.exports = isArguments;
10203
10204
10205/***/ },
10206/* 32 */
10207/***/ function(module, exports, __webpack_require__) {
10208
10209 var getLength = __webpack_require__(73),
10210 isFunction = __webpack_require__(33),
10211 isLength = __webpack_require__(9);
10212
10213 /**
10214 * Checks if `value` is array-like. A value is considered array-like if it's
10215 * not a function and has a `value.length` that's an integer greater than or
10216 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
10217 *
10218 * @static
10219 * @memberOf _
10220 * @type Function
10221 * @category Lang
10222 * @param {*} value The value to check.
10223 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
10224 * @example
10225 *
10226 * _.isArrayLike([1, 2, 3]);
10227 * // => true
10228 *
10229 * _.isArrayLike(document.body.children);
10230 * // => true
10231 *
10232 * _.isArrayLike('abc');
10233 * // => true
10234 *
10235 * _.isArrayLike(_.noop);
10236 * // => false
10237 */
10238 function isArrayLike(value) {
10239 return value != null &&
10240 !(typeof value == 'function' && isFunction(value)) && isLength(getLength(value));
10241 }
10242
10243 module.exports = isArrayLike;
10244
10245
10246/***/ },
10247/* 33 */
10248/***/ function(module, exports, __webpack_require__) {
10249
10250 var isObject = __webpack_require__(13);
10251
10252 /** `Object#toString` result references. */
10253 var funcTag = '[object Function]',
10254 genTag = '[object GeneratorFunction]';
10255
10256 /** Used for built-in method references. */
10257 var objectProto = Object.prototype;
10258
10259 /**
10260 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
10261 * of values.
10262 */
10263 var objectToString = objectProto.toString;
10264
10265 /**
10266 * Checks if `value` is classified as a `Function` object.
10267 *
10268 * @static
10269 * @memberOf _
10270 * @category Lang
10271 * @param {*} value The value to check.
10272 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10273 * @example
10274 *
10275 * _.isFunction(_);
10276 * // => true
10277 *
10278 * _.isFunction(/abc/);
10279 * // => false
10280 */
10281 function isFunction(value) {
10282 // The use of `Object#toString` avoids issues with the `typeof` operator
10283 // in Safari 8 which returns 'object' for typed array constructors, and
10284 // PhantomJS 1.9 which returns 'function' for `NodeList` instances.
10285 var tag = isObject(value) ? objectToString.call(value) : '';
10286 return tag == funcTag || tag == genTag;
10287 }
10288
10289 module.exports = isFunction;
10290
10291
10292/***/ },
10293/* 34 */
10294/***/ function(module, exports, __webpack_require__) {
10295
10296 var isArray = __webpack_require__(1),
10297 isObjectLike = __webpack_require__(2);
10298
10299 /** `Object#toString` result references. */
10300 var stringTag = '[object String]';
10301
10302 /** Used for built-in method references. */
10303 var objectProto = Object.prototype;
10304
10305 /**
10306 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
10307 * of values.
10308 */
10309 var objectToString = objectProto.toString;
10310
10311 /**
10312 * Checks if `value` is classified as a `String` primitive or object.
10313 *
10314 * @static
10315 * @memberOf _
10316 * @category Lang
10317 * @param {*} value The value to check.
10318 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10319 * @example
10320 *
10321 * _.isString('abc');
10322 * // => true
10323 *
10324 * _.isString(1);
10325 * // => false
10326 */
10327 function isString(value) {
10328 return typeof value == 'string' ||
10329 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
10330 }
10331
10332 module.exports = isString;
10333
10334
10335/***/ },
10336/* 35 */
10337/***/ function(module, exports, __webpack_require__) {
10338
10339 'use strict';
10340
10341 exports.__esModule = true;
10342 exports.tree = undefined;
10343
10344 var _tree2 = __webpack_require__(37);
10345
10346 var _tree3 = _interopRequireDefault(_tree2);
10347
10348 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10349
10350 exports.tree = _tree3.default;
10351
10352/***/ },
10353/* 36 */
10354/***/ function(module, exports, __webpack_require__) {
10355
10356 'use strict';
10357
10358 exports.__esModule = true;
10359
10360 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
10361
10362 exports.default = sortAndSerialize;
10363
10364 var _ramda = __webpack_require__(4);
10365
10366 var _fclone = __webpack_require__(45);
10367
10368 var _fclone2 = _interopRequireDefault(_fclone);
10369
10370 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10371
10372 function sortObject(obj, strict) {
10373 if (obj instanceof Array) {
10374 var ary = void 0;
10375 if (strict) {
10376 ary = obj.sort();
10377 } else {
10378 ary = obj;
10379 }
10380 return ary;
10381 }
10382
10383 if (obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object') {
10384 var _ret = function () {
10385 var tObj = {};
10386 Object.keys(obj).sort().forEach(function (key) {
10387 return tObj[key] = sortObject(obj[key]);
10388 });
10389 return {
10390 v: tObj
10391 };
10392 }();
10393
10394 if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
10395 }
10396
10397 return obj;
10398 }
10399
10400 function sortAndSerialize(obj) {
10401 return JSON.stringify(sortObject((0, _fclone2.default)(obj), true), undefined, 2);
10402 }
10403
10404/***/ },
10405/* 37 */
10406/***/ function(module, exports, __webpack_require__) {
10407
10408 'use strict';
10409
10410 exports.__esModule = true;
10411
10412 var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
10413
10414 exports.default = function (DOMNode) {
10415 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10416
10417 var _deepmerge = (0, _deepmerge3.default)(defaultOptions, options);
10418
10419 var id = _deepmerge.id;
10420 var style = _deepmerge.style;
10421 var size = _deepmerge.size;
10422 var aspectRatio = _deepmerge.aspectRatio;
10423 var initialZoom = _deepmerge.initialZoom;
10424 var margin = _deepmerge.margin;
10425 var isSorted = _deepmerge.isSorted;
10426 var widthBetweenNodesCoeff = _deepmerge.widthBetweenNodesCoeff;
10427 var heightBetweenNodesCoeff = _deepmerge.heightBetweenNodesCoeff;
10428 var transitionDuration = _deepmerge.transitionDuration;
10429 var state = _deepmerge.state;
10430 var rootKeyName = _deepmerge.rootKeyName;
10431 var pushMethod = _deepmerge.pushMethod;
10432 var tree = _deepmerge.tree;
10433 var tooltipOptions = _deepmerge.tooltipOptions;
10434 var onClickText = _deepmerge.onClickText;
10435
10436
10437 var width = size - margin.left - margin.right;
10438 var height = size * aspectRatio - margin.top - margin.bottom;
10439 var fullWidth = size;
10440 var fullHeight = size * aspectRatio;
10441
10442 var attr = {
10443 id: id,
10444 preserveAspectRatio: 'xMinYMin slice'
10445 };
10446
10447 if (!style.width) {
10448 attr.width = fullWidth;
10449 }
10450
10451 if (!style.width || !style.height) {
10452 attr.viewBox = '0 0 ' + fullWidth + ' ' + fullHeight;
10453 }
10454
10455 var root = _d4.default.select(DOMNode);
10456 var zoom = _d4.default.behavior.zoom().scaleExtent([0.1, 3]).scale(initialZoom);
10457 var vis = root.append('svg').attr(attr).style(_extends({ cursor: '-webkit-grab' }, style)).call(zoom.on('zoom', function () {
10458 var _d3$event = _d4.default.event;
10459 var translate = _d3$event.translate;
10460 var scale = _d3$event.scale;
10461
10462 vis.attr('transform', 'translate(' + translate + ')scale(' + scale + ')');
10463 })).append('g').attr({
10464 transform: 'translate(' + (margin.left + style.node.radius) + ', ' + margin.top + ') scale(' + initialZoom + ')'
10465 });
10466
10467 var layout = _d4.default.layout.tree().size([width, height]);
10468 var data = void 0;
10469
10470 if (isSorted) {
10471 layout.sort(function (a, b) {
10472 return b.name.toLowerCase() < a.name.toLowerCase() ? 1 : -1;
10473 });
10474 }
10475
10476 return function renderChart() {
10477 var nextState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : tree || state;
10478
10479 data = !tree ? (0, _map2tree2.default)(nextState, { key: rootKeyName, pushMethod: pushMethod }) : nextState;
10480
10481 if ((0, _ramda.isEmpty)(data) || !data.name) {
10482 data = { name: 'error', message: 'Please provide a state map or a tree structure' };
10483 }
10484
10485 var nodeIndex = 0;
10486 var maxLabelLength = 0;
10487
10488 (0, _utils.visit)(data, function (node) {
10489 return maxLabelLength = Math.max(node.name.length, maxLabelLength);
10490 }, function (node) {
10491 return node.children && node.children.length > 0 ? node.children : null;
10492 });
10493
10494 data.x0 = height / 2;
10495 data.y0 = 0;
10496 /*eslint-disable*/
10497 update(data);
10498 /*eslint-enable*/
10499
10500 function update(source) {
10501 // path generator for links
10502 var diagonal = _d4.default.svg.diagonal().projection(function (d) {
10503 return [d.y, d.x];
10504 });
10505 // set tree dimensions and spacing between branches and nodes
10506 var maxNodeCountByLevel = Math.max.apply(Math, (0, _utils.getNodeGroupByDepthCount)(data));
10507
10508 layout = layout.size([maxNodeCountByLevel * 25 * heightBetweenNodesCoeff, width]);
10509
10510 var nodes = layout.nodes(data);
10511 var links = layout.links(nodes);
10512
10513 nodes.forEach(function (node) {
10514 return node.y = node.depth * (maxLabelLength * 7 * widthBetweenNodesCoeff);
10515 });
10516
10517 // process the node selection
10518 var node = vis.selectAll('g.node').property("__oldData__", function (d) {
10519 return d;
10520 }).data(nodes, function (d) {
10521 return d.id || (d.id = ++nodeIndex);
10522 });
10523
10524 var nodeEnter = node.enter().append('g').attr({
10525 'class': 'node',
10526 transform: function transform(d) {
10527 return 'translate(' + source.y0 + ',' + source.x0 + ')';
10528 }
10529 }).style({
10530 fill: style.text.colors.default,
10531 cursor: 'pointer'
10532 }).on({
10533 mouseover: function mouseover(d, i) {
10534 _d4.default.select(this).style({
10535 fill: style.text.colors.hover
10536 });
10537 },
10538 mouseout: function mouseout(d, i) {
10539 _d4.default.select(this).style({
10540 fill: style.text.colors.default
10541 });
10542 }
10543 });
10544
10545 if (!tooltipOptions.disabled) {
10546 nodeEnter.call((0, _d3tooltip2.default)(_d4.default, 'tooltip', _extends({}, tooltipOptions, { root: root })).text(function (d, i) {
10547 return (0, _utils.getTooltipString)(d, i, tooltipOptions);
10548 }).style(tooltipOptions.style));
10549 }
10550
10551 nodeEnter.append('circle').attr({
10552 'class': 'nodeCircle'
10553 }).on({
10554 click: function click(clickedNode) {
10555 if (_d4.default.event.defaultPrevented) return;
10556 update((0, _utils.toggleChildren)(clickedNode));
10557 }
10558 });
10559
10560 nodeEnter.append('text').attr({
10561 'class': 'nodeText',
10562 dy: '.35em'
10563 }).style({
10564 'fill-opacity': 0
10565 }).text(function (d) {
10566 return d.name;
10567 }).on({
10568 click: onClickText
10569 });
10570
10571 // update the text to reflect whether node has children or not
10572 node.select('text').attr({
10573 x: function x(d) {
10574 return d.children || d._children ? -(style.node.radius + 10) : style.node.radius + 10;
10575 },
10576 'text-anchor': function textAnchor(d) {
10577 return d.children || d._children ? 'end' : 'start';
10578 }
10579 }).text(function (d) {
10580 return d.name;
10581 });
10582
10583 // change the circle fill depending on whether it has children and is collapsed
10584 node.select('circle.nodeCircle').attr({
10585 r: style.node.radius
10586 }).style({
10587 stroke: 'black',
10588 'stroke-width': '1.5px',
10589 fill: function fill(d) {
10590 return d._children ? style.node.colors.collapsed : d.children ? style.node.colors.parent : style.node.colors.default;
10591 }
10592 });
10593
10594 // transition nodes to their new position
10595 var nodeUpdate = node.transition().duration(transitionDuration).attr({
10596 transform: function transform(d) {
10597 return 'translate(' + d.y + ',' + d.x + ')';
10598 }
10599 });
10600
10601 // fade the text in
10602 nodeUpdate.select('text').style('fill-opacity', 1);
10603
10604 // restore the circle
10605 nodeUpdate.select('circle').attr('r', 7);
10606
10607 // blink updated nodes
10608 nodeUpdate.filter(function (d) {
10609 // test whether the relevant properties of d match
10610 // the equivalent property of the oldData
10611 // also test whether the old data exists,
10612 // to catch the entering elements!
10613 return !this.__oldData__ || d.value !== this.__oldData__.value;
10614 }).style('fill-opacity', '0.3').transition().duration(100).style('fill-opacity', '1');
10615
10616 // transition exiting nodes to the parent's new position
10617 var nodeExit = node.exit().transition().duration(transitionDuration).attr({
10618 transform: function transform(d) {
10619 return 'translate(' + source.y + ',' + source.x + ')';
10620 }
10621 }).remove();
10622
10623 nodeExit.select('circle').attr('r', 0);
10624
10625 nodeExit.select('text').style('fill-opacity', 0);
10626
10627 // update the links
10628 var link = vis.selectAll('path.link').data(links, function (d) {
10629 return d.target.id;
10630 });
10631
10632 // enter any new links at the parent's previous position
10633 link.enter().insert('path', 'g').attr({
10634 'class': 'link',
10635 d: function d(_d) {
10636 var o = {
10637 x: source.x0,
10638 y: source.y0
10639 };
10640 return diagonal({
10641 source: o,
10642 target: o
10643 });
10644 }
10645 }).style(style.link);
10646
10647 // transition links to their new position
10648 link.transition().duration(transitionDuration).attr({
10649 d: diagonal
10650 });
10651
10652 // transition exiting nodes to the parent's new position
10653 link.exit().transition().duration(transitionDuration).attr({
10654 d: function d(_d2) {
10655 var o = {
10656 x: source.x,
10657 y: source.y
10658 };
10659 return diagonal({
10660 source: o,
10661 target: o
10662 });
10663 }
10664 }).remove();
10665
10666 // delete the old data once it's no longer needed
10667 node.property("__oldData__", null);
10668
10669 // stash the old positions for transition
10670 nodes.forEach(function (d) {
10671 d.x0 = d.x;
10672 d.y0 = d.y;
10673 });
10674 }
10675 };
10676 };
10677
10678 var _d3 = __webpack_require__(40);
10679
10680 var _d4 = _interopRequireDefault(_d3);
10681
10682 var _ramda = __webpack_require__(4);
10683
10684 var _map2tree = __webpack_require__(110);
10685
10686 var _map2tree2 = _interopRequireDefault(_map2tree);
10687
10688 var _deepmerge2 = __webpack_require__(44);
10689
10690 var _deepmerge3 = _interopRequireDefault(_deepmerge2);
10691
10692 var _utils = __webpack_require__(38);
10693
10694 var _d3tooltip = __webpack_require__(41);
10695
10696 var _d3tooltip2 = _interopRequireDefault(_d3tooltip);
10697
10698 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10699
10700 var defaultOptions = {
10701 state: undefined,
10702 rootKeyName: 'state',
10703 pushMethod: 'push',
10704 tree: undefined,
10705 id: 'd3svg',
10706 style: {
10707 node: {
10708 colors: {
10709 'default': '#ccc',
10710 collapsed: 'lightsteelblue',
10711 parent: 'white'
10712 },
10713 radius: 5
10714 },
10715 text: {
10716 colors: {
10717 'default': 'black',
10718 hover: 'skyblue'
10719 }
10720 },
10721 link: {
10722 stroke: '#000',
10723 fill: 'none'
10724 }
10725 },
10726 size: 500,
10727 aspectRatio: 1.0,
10728 initialZoom: 1,
10729 margin: {
10730 top: 10,
10731 right: 10,
10732 bottom: 10,
10733 left: 50
10734 },
10735 isSorted: false,
10736 heightBetweenNodesCoeff: 2,
10737 widthBetweenNodesCoeff: 1,
10738 transitionDuration: 750,
10739 onClickText: function onClickText() {},
10740 tooltipOptions: {
10741 disabled: false,
10742 left: undefined,
10743 right: undefined,
10744 offset: {
10745 left: 0,
10746 top: 0
10747 },
10748 style: undefined
10749 }
10750 };
10751
10752/***/ },
10753/* 38 */
10754/***/ function(module, exports, __webpack_require__) {
10755
10756 'use strict';
10757
10758 exports.__esModule = true;
10759 exports.collapseChildren = collapseChildren;
10760 exports.expandChildren = expandChildren;
10761 exports.toggleChildren = toggleChildren;
10762 exports.visit = visit;
10763 exports.getNodeGroupByDepthCount = getNodeGroupByDepthCount;
10764 exports.getTooltipString = getTooltipString;
10765
10766 var _jsonPretty = __webpack_require__(48);
10767
10768 var _jsonPretty2 = _interopRequireDefault(_jsonPretty);
10769
10770 var _ramda = __webpack_require__(4);
10771
10772 var _sortAndSerialize = __webpack_require__(36);
10773
10774 var _sortAndSerialize2 = _interopRequireDefault(_sortAndSerialize);
10775
10776 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10777
10778 function collapseChildren(node) {
10779 if (node.children) {
10780 node._children = node.children;
10781 node._children.forEach(collapseChildren);
10782 node.children = null;
10783 }
10784 }
10785
10786 function expandChildren(node) {
10787 if (node._children) {
10788 node.children = node._children;
10789 node.children.forEach(expandChildren);
10790 node._children = null;
10791 }
10792 }
10793
10794 function toggleChildren(node) {
10795 if (node.children) {
10796 node._children = node.children;
10797 node.children = null;
10798 } else if (node._children) {
10799 node.children = node._children;
10800 node._children = null;
10801 }
10802 return node;
10803 }
10804
10805 function visit(parent, visitFn, childrenFn) {
10806 if (!parent) {
10807 return;
10808 }
10809
10810 visitFn(parent);
10811
10812 var children = childrenFn(parent);
10813 if (children) {
10814 var count = children.length;
10815
10816 for (var i = 0; i < count; i++) {
10817 visit(children[i], visitFn, childrenFn);
10818 }
10819 }
10820 }
10821
10822 function getNodeGroupByDepthCount(rootNode) {
10823 var nodeGroupByDepthCount = [1];
10824
10825 var traverseFrom = function traverseFrom(node) {
10826 var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
10827
10828 if (!node.children || node.children.length === 0) {
10829 return 0;
10830 }
10831
10832 if (nodeGroupByDepthCount.length <= depth + 1) {
10833 nodeGroupByDepthCount.push(0);
10834 }
10835
10836 nodeGroupByDepthCount[depth + 1] += node.children.length;
10837
10838 node.children.forEach(function (childNode) {
10839 traverseFrom(childNode, depth + 1);
10840 });
10841 };
10842
10843 traverseFrom(rootNode);
10844 return nodeGroupByDepthCount;
10845 }
10846
10847 function getTooltipString(node, i, _ref) {
10848 var _ref$indentationSize = _ref.indentationSize;
10849 var indentationSize = _ref$indentationSize === undefined ? 4 : _ref$indentationSize;
10850
10851 if (!(0, _ramda.is)(Object, node)) return '';
10852
10853 var spacer = (0, _ramda.join)('&nbsp;&nbsp;');
10854 var cr2br = (0, _ramda.replace)(/\n/g, '<br/>');
10855 var spaces2nbsp = (0, _ramda.replace)(/\s{2}/g, spacer(new Array(indentationSize)));
10856 var json2html = (0, _ramda.pipe)(_sortAndSerialize2.default, cr2br, spaces2nbsp);
10857
10858 var children = node.children || node._children;
10859 var tuple = (0, _ramda.omit)(['parent', 'children', '_children', 'depth', 'id', 'x', 'x0', 'y', 'y0'], node);
10860
10861 if (children) {
10862 tuple.childrenCount = children.length;
10863 }
10864
10865 return json2html(tuple);
10866 }
10867
10868/***/ },
10869/* 39 */
10870/***/ function(module, exports) {
10871
10872 'use strict'
10873
10874 exports.byteLength = byteLength
10875 exports.toByteArray = toByteArray
10876 exports.fromByteArray = fromByteArray
10877
10878 var lookup = []
10879 var revLookup = []
10880 var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
10881
10882 var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
10883 for (var i = 0, len = code.length; i < len; ++i) {
10884 lookup[i] = code[i]
10885 revLookup[code.charCodeAt(i)] = i
10886 }
10887
10888 revLookup['-'.charCodeAt(0)] = 62
10889 revLookup['_'.charCodeAt(0)] = 63
10890
10891 function placeHoldersCount (b64) {
10892 var len = b64.length
10893 if (len % 4 > 0) {
10894 throw new Error('Invalid string. Length must be a multiple of 4')
10895 }
10896
10897 // the number of equal signs (place holders)
10898 // if there are two placeholders, than the two characters before it
10899 // represent one byte
10900 // if there is only one, then the three characters before it represent 2 bytes
10901 // this is just a cheap hack to not do indexOf twice
10902 return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
10903 }
10904
10905 function byteLength (b64) {
10906 // base64 is 4/3 + up to two characters of the original data
10907 return b64.length * 3 / 4 - placeHoldersCount(b64)
10908 }
10909
10910 function toByteArray (b64) {
10911 var i, j, l, tmp, placeHolders, arr
10912 var len = b64.length
10913 placeHolders = placeHoldersCount(b64)
10914
10915 arr = new Arr(len * 3 / 4 - placeHolders)
10916
10917 // if there are placeholders, only get up to the last complete 4 chars
10918 l = placeHolders > 0 ? len - 4 : len
10919
10920 var L = 0
10921
10922 for (i = 0, j = 0; i < l; i += 4, j += 3) {
10923 tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
10924 arr[L++] = (tmp >> 16) & 0xFF
10925 arr[L++] = (tmp >> 8) & 0xFF
10926 arr[L++] = tmp & 0xFF
10927 }
10928
10929 if (placeHolders === 2) {
10930 tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
10931 arr[L++] = tmp & 0xFF
10932 } else if (placeHolders === 1) {
10933 tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
10934 arr[L++] = (tmp >> 8) & 0xFF
10935 arr[L++] = tmp & 0xFF
10936 }
10937
10938 return arr
10939 }
10940
10941 function tripletToBase64 (num) {
10942 return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
10943 }
10944
10945 function encodeChunk (uint8, start, end) {
10946 var tmp
10947 var output = []
10948 for (var i = start; i < end; i += 3) {
10949 tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
10950 output.push(tripletToBase64(tmp))
10951 }
10952 return output.join('')
10953 }
10954
10955 function fromByteArray (uint8) {
10956 var tmp
10957 var len = uint8.length
10958 var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
10959 var output = ''
10960 var parts = []
10961 var maxChunkLength = 16383 // must be multiple of 3
10962
10963 // go through the array every three bytes, we'll deal with trailing stuff later
10964 for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
10965 parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
10966 }
10967
10968 // pad the end with zeros, but make sure to not forget the extra bytes
10969 if (extraBytes === 1) {
10970 tmp = uint8[len - 1]
10971 output += lookup[tmp >> 2]
10972 output += lookup[(tmp << 4) & 0x3F]
10973 output += '=='
10974 } else if (extraBytes === 2) {
10975 tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
10976 output += lookup[tmp >> 10]
10977 output += lookup[(tmp >> 4) & 0x3F]
10978 output += lookup[(tmp << 2) & 0x3F]
10979 output += '='
10980 }
10981
10982 parts.push(output)
10983
10984 return parts.join('')
10985 }
10986
10987
10988/***/ },
10989/* 40 */
10990/***/ function(module, exports, __webpack_require__) {
10991
10992 var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;!function() {
10993 var d3 = {
10994 version: "3.5.17"
10995 };
10996 var d3_arraySlice = [].slice, d3_array = function(list) {
10997 return d3_arraySlice.call(list);
10998 };
10999 var d3_document = this.document;
11000 function d3_documentElement(node) {
11001 return node && (node.ownerDocument || node.document || node).documentElement;
11002 }
11003 function d3_window(node) {
11004 return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
11005 }
11006 if (d3_document) {
11007 try {
11008 d3_array(d3_document.documentElement.childNodes)[0].nodeType;
11009 } catch (e) {
11010 d3_array = function(list) {
11011 var i = list.length, array = new Array(i);
11012 while (i--) array[i] = list[i];
11013 return array;
11014 };
11015 }
11016 }
11017 if (!Date.now) Date.now = function() {
11018 return +new Date();
11019 };
11020 if (d3_document) {
11021 try {
11022 d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
11023 } catch (error) {
11024 var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
11025 d3_element_prototype.setAttribute = function(name, value) {
11026 d3_element_setAttribute.call(this, name, value + "");
11027 };
11028 d3_element_prototype.setAttributeNS = function(space, local, value) {
11029 d3_element_setAttributeNS.call(this, space, local, value + "");
11030 };
11031 d3_style_prototype.setProperty = function(name, value, priority) {
11032 d3_style_setProperty.call(this, name, value + "", priority);
11033 };
11034 }
11035 }
11036 d3.ascending = d3_ascending;
11037 function d3_ascending(a, b) {
11038 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
11039 }
11040 d3.descending = function(a, b) {
11041 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
11042 };
11043 d3.min = function(array, f) {
11044 var i = -1, n = array.length, a, b;
11045 if (arguments.length === 1) {
11046 while (++i < n) if ((b = array[i]) != null && b >= b) {
11047 a = b;
11048 break;
11049 }
11050 while (++i < n) if ((b = array[i]) != null && a > b) a = b;
11051 } else {
11052 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
11053 a = b;
11054 break;
11055 }
11056 while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
11057 }
11058 return a;
11059 };
11060 d3.max = function(array, f) {
11061 var i = -1, n = array.length, a, b;
11062 if (arguments.length === 1) {
11063 while (++i < n) if ((b = array[i]) != null && b >= b) {
11064 a = b;
11065 break;
11066 }
11067 while (++i < n) if ((b = array[i]) != null && b > a) a = b;
11068 } else {
11069 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
11070 a = b;
11071 break;
11072 }
11073 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
11074 }
11075 return a;
11076 };
11077 d3.extent = function(array, f) {
11078 var i = -1, n = array.length, a, b, c;
11079 if (arguments.length === 1) {
11080 while (++i < n) if ((b = array[i]) != null && b >= b) {
11081 a = c = b;
11082 break;
11083 }
11084 while (++i < n) if ((b = array[i]) != null) {
11085 if (a > b) a = b;
11086 if (c < b) c = b;
11087 }
11088 } else {
11089 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
11090 a = c = b;
11091 break;
11092 }
11093 while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
11094 if (a > b) a = b;
11095 if (c < b) c = b;
11096 }
11097 }
11098 return [ a, c ];
11099 };
11100 function d3_number(x) {
11101 return x === null ? NaN : +x;
11102 }
11103 function d3_numeric(x) {
11104 return !isNaN(x);
11105 }
11106 d3.sum = function(array, f) {
11107 var s = 0, n = array.length, a, i = -1;
11108 if (arguments.length === 1) {
11109 while (++i < n) if (d3_numeric(a = +array[i])) s += a;
11110 } else {
11111 while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
11112 }
11113 return s;
11114 };
11115 d3.mean = function(array, f) {
11116 var s = 0, n = array.length, a, i = -1, j = n;
11117 if (arguments.length === 1) {
11118 while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
11119 } else {
11120 while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
11121 }
11122 if (j) return s / j;
11123 };
11124 d3.quantile = function(values, p) {
11125 var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
11126 return e ? v + e * (values[h] - v) : v;
11127 };
11128 d3.median = function(array, f) {
11129 var numbers = [], n = array.length, a, i = -1;
11130 if (arguments.length === 1) {
11131 while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
11132 } else {
11133 while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
11134 }
11135 if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
11136 };
11137 d3.variance = function(array, f) {
11138 var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
11139 if (arguments.length === 1) {
11140 while (++i < n) {
11141 if (d3_numeric(a = d3_number(array[i]))) {
11142 d = a - m;
11143 m += d / ++j;
11144 s += d * (a - m);
11145 }
11146 }
11147 } else {
11148 while (++i < n) {
11149 if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
11150 d = a - m;
11151 m += d / ++j;
11152 s += d * (a - m);
11153 }
11154 }
11155 }
11156 if (j > 1) return s / (j - 1);
11157 };
11158 d3.deviation = function() {
11159 var v = d3.variance.apply(this, arguments);
11160 return v ? Math.sqrt(v) : v;
11161 };
11162 function d3_bisector(compare) {
11163 return {
11164 left: function(a, x, lo, hi) {
11165 if (arguments.length < 3) lo = 0;
11166 if (arguments.length < 4) hi = a.length;
11167 while (lo < hi) {
11168 var mid = lo + hi >>> 1;
11169 if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
11170 }
11171 return lo;
11172 },
11173 right: function(a, x, lo, hi) {
11174 if (arguments.length < 3) lo = 0;
11175 if (arguments.length < 4) hi = a.length;
11176 while (lo < hi) {
11177 var mid = lo + hi >>> 1;
11178 if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
11179 }
11180 return lo;
11181 }
11182 };
11183 }
11184 var d3_bisect = d3_bisector(d3_ascending);
11185 d3.bisectLeft = d3_bisect.left;
11186 d3.bisect = d3.bisectRight = d3_bisect.right;
11187 d3.bisector = function(f) {
11188 return d3_bisector(f.length === 1 ? function(d, x) {
11189 return d3_ascending(f(d), x);
11190 } : f);
11191 };
11192 d3.shuffle = function(array, i0, i1) {
11193 if ((m = arguments.length) < 3) {
11194 i1 = array.length;
11195 if (m < 2) i0 = 0;
11196 }
11197 var m = i1 - i0, t, i;
11198 while (m) {
11199 i = Math.random() * m-- | 0;
11200 t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
11201 }
11202 return array;
11203 };
11204 d3.permute = function(array, indexes) {
11205 var i = indexes.length, permutes = new Array(i);
11206 while (i--) permutes[i] = array[indexes[i]];
11207 return permutes;
11208 };
11209 d3.pairs = function(array) {
11210 var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
11211 while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
11212 return pairs;
11213 };
11214 d3.transpose = function(matrix) {
11215 if (!(n = matrix.length)) return [];
11216 for (var i = -1, m = d3.min(matrix, d3_transposeLength), transpose = new Array(m); ++i < m; ) {
11217 for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n; ) {
11218 row[j] = matrix[j][i];
11219 }
11220 }
11221 return transpose;
11222 };
11223 function d3_transposeLength(d) {
11224 return d.length;
11225 }
11226 d3.zip = function() {
11227 return d3.transpose(arguments);
11228 };
11229 d3.keys = function(map) {
11230 var keys = [];
11231 for (var key in map) keys.push(key);
11232 return keys;
11233 };
11234 d3.values = function(map) {
11235 var values = [];
11236 for (var key in map) values.push(map[key]);
11237 return values;
11238 };
11239 d3.entries = function(map) {
11240 var entries = [];
11241 for (var key in map) entries.push({
11242 key: key,
11243 value: map[key]
11244 });
11245 return entries;
11246 };
11247 d3.merge = function(arrays) {
11248 var n = arrays.length, m, i = -1, j = 0, merged, array;
11249 while (++i < n) j += arrays[i].length;
11250 merged = new Array(j);
11251 while (--n >= 0) {
11252 array = arrays[n];
11253 m = array.length;
11254 while (--m >= 0) {
11255 merged[--j] = array[m];
11256 }
11257 }
11258 return merged;
11259 };
11260 var abs = Math.abs;
11261 d3.range = function(start, stop, step) {
11262 if (arguments.length < 3) {
11263 step = 1;
11264 if (arguments.length < 2) {
11265 stop = start;
11266 start = 0;
11267 }
11268 }
11269 if ((stop - start) / step === Infinity) throw new Error("infinite range");
11270 var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
11271 start *= k, stop *= k, step *= k;
11272 if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
11273 return range;
11274 };
11275 function d3_range_integerScale(x) {
11276 var k = 1;
11277 while (x * k % 1) k *= 10;
11278 return k;
11279 }
11280 function d3_class(ctor, properties) {
11281 for (var key in properties) {
11282 Object.defineProperty(ctor.prototype, key, {
11283 value: properties[key],
11284 enumerable: false
11285 });
11286 }
11287 }
11288 d3.map = function(object, f) {
11289 var map = new d3_Map();
11290 if (object instanceof d3_Map) {
11291 object.forEach(function(key, value) {
11292 map.set(key, value);
11293 });
11294 } else if (Array.isArray(object)) {
11295 var i = -1, n = object.length, o;
11296 if (arguments.length === 1) while (++i < n) map.set(i, object[i]); else while (++i < n) map.set(f.call(object, o = object[i], i), o);
11297 } else {
11298 for (var key in object) map.set(key, object[key]);
11299 }
11300 return map;
11301 };
11302 function d3_Map() {
11303 this._ = Object.create(null);
11304 }
11305 var d3_map_proto = "__proto__", d3_map_zero = "\x00";
11306 d3_class(d3_Map, {
11307 has: d3_map_has,
11308 get: function(key) {
11309 return this._[d3_map_escape(key)];
11310 },
11311 set: function(key, value) {
11312 return this._[d3_map_escape(key)] = value;
11313 },
11314 remove: d3_map_remove,
11315 keys: d3_map_keys,
11316 values: function() {
11317 var values = [];
11318 for (var key in this._) values.push(this._[key]);
11319 return values;
11320 },
11321 entries: function() {
11322 var entries = [];
11323 for (var key in this._) entries.push({
11324 key: d3_map_unescape(key),
11325 value: this._[key]
11326 });
11327 return entries;
11328 },
11329 size: d3_map_size,
11330 empty: d3_map_empty,
11331 forEach: function(f) {
11332 for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
11333 }
11334 });
11335 function d3_map_escape(key) {
11336 return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
11337 }
11338 function d3_map_unescape(key) {
11339 return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
11340 }
11341 function d3_map_has(key) {
11342 return d3_map_escape(key) in this._;
11343 }
11344 function d3_map_remove(key) {
11345 return (key = d3_map_escape(key)) in this._ && delete this._[key];
11346 }
11347 function d3_map_keys() {
11348 var keys = [];
11349 for (var key in this._) keys.push(d3_map_unescape(key));
11350 return keys;
11351 }
11352 function d3_map_size() {
11353 var size = 0;
11354 for (var key in this._) ++size;
11355 return size;
11356 }
11357 function d3_map_empty() {
11358 for (var key in this._) return false;
11359 return true;
11360 }
11361 d3.nest = function() {
11362 var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
11363 function map(mapType, array, depth) {
11364 if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
11365 var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
11366 while (++i < n) {
11367 if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
11368 values.push(object);
11369 } else {
11370 valuesByKey.set(keyValue, [ object ]);
11371 }
11372 }
11373 if (mapType) {
11374 object = mapType();
11375 setter = function(keyValue, values) {
11376 object.set(keyValue, map(mapType, values, depth));
11377 };
11378 } else {
11379 object = {};
11380 setter = function(keyValue, values) {
11381 object[keyValue] = map(mapType, values, depth);
11382 };
11383 }
11384 valuesByKey.forEach(setter);
11385 return object;
11386 }
11387 function entries(map, depth) {
11388 if (depth >= keys.length) return map;
11389 var array = [], sortKey = sortKeys[depth++];
11390 map.forEach(function(key, keyMap) {
11391 array.push({
11392 key: key,
11393 values: entries(keyMap, depth)
11394 });
11395 });
11396 return sortKey ? array.sort(function(a, b) {
11397 return sortKey(a.key, b.key);
11398 }) : array;
11399 }
11400 nest.map = function(array, mapType) {
11401 return map(mapType, array, 0);
11402 };
11403 nest.entries = function(array) {
11404 return entries(map(d3.map, array, 0), 0);
11405 };
11406 nest.key = function(d) {
11407 keys.push(d);
11408 return nest;
11409 };
11410 nest.sortKeys = function(order) {
11411 sortKeys[keys.length - 1] = order;
11412 return nest;
11413 };
11414 nest.sortValues = function(order) {
11415 sortValues = order;
11416 return nest;
11417 };
11418 nest.rollup = function(f) {
11419 rollup = f;
11420 return nest;
11421 };
11422 return nest;
11423 };
11424 d3.set = function(array) {
11425 var set = new d3_Set();
11426 if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
11427 return set;
11428 };
11429 function d3_Set() {
11430 this._ = Object.create(null);
11431 }
11432 d3_class(d3_Set, {
11433 has: d3_map_has,
11434 add: function(key) {
11435 this._[d3_map_escape(key += "")] = true;
11436 return key;
11437 },
11438 remove: d3_map_remove,
11439 values: d3_map_keys,
11440 size: d3_map_size,
11441 empty: d3_map_empty,
11442 forEach: function(f) {
11443 for (var key in this._) f.call(this, d3_map_unescape(key));
11444 }
11445 });
11446 d3.behavior = {};
11447 function d3_identity(d) {
11448 return d;
11449 }
11450 d3.rebind = function(target, source) {
11451 var i = 1, n = arguments.length, method;
11452 while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
11453 return target;
11454 };
11455 function d3_rebind(target, source, method) {
11456 return function() {
11457 var value = method.apply(source, arguments);
11458 return value === source ? target : value;
11459 };
11460 }
11461 function d3_vendorSymbol(object, name) {
11462 if (name in object) return name;
11463 name = name.charAt(0).toUpperCase() + name.slice(1);
11464 for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
11465 var prefixName = d3_vendorPrefixes[i] + name;
11466 if (prefixName in object) return prefixName;
11467 }
11468 }
11469 var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
11470 function d3_noop() {}
11471 d3.dispatch = function() {
11472 var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
11473 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
11474 return dispatch;
11475 };
11476 function d3_dispatch() {}
11477 d3_dispatch.prototype.on = function(type, listener) {
11478 var i = type.indexOf("."), name = "";
11479 if (i >= 0) {
11480 name = type.slice(i + 1);
11481 type = type.slice(0, i);
11482 }
11483 if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
11484 if (arguments.length === 2) {
11485 if (listener == null) for (type in this) {
11486 if (this.hasOwnProperty(type)) this[type].on(name, null);
11487 }
11488 return this;
11489 }
11490 };
11491 function d3_dispatch_event(dispatch) {
11492 var listeners = [], listenerByName = new d3_Map();
11493 function event() {
11494 var z = listeners, i = -1, n = z.length, l;
11495 while (++i < n) if (l = z[i].on) l.apply(this, arguments);
11496 return dispatch;
11497 }
11498 event.on = function(name, listener) {
11499 var l = listenerByName.get(name), i;
11500 if (arguments.length < 2) return l && l.on;
11501 if (l) {
11502 l.on = null;
11503 listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
11504 listenerByName.remove(name);
11505 }
11506 if (listener) listeners.push(listenerByName.set(name, {
11507 on: listener
11508 }));
11509 return dispatch;
11510 };
11511 return event;
11512 }
11513 d3.event = null;
11514 function d3_eventPreventDefault() {
11515 d3.event.preventDefault();
11516 }
11517 function d3_eventSource() {
11518 var e = d3.event, s;
11519 while (s = e.sourceEvent) e = s;
11520 return e;
11521 }
11522 function d3_eventDispatch(target) {
11523 var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
11524 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
11525 dispatch.of = function(thiz, argumentz) {
11526 return function(e1) {
11527 try {
11528 var e0 = e1.sourceEvent = d3.event;
11529 e1.target = target;
11530 d3.event = e1;
11531 dispatch[e1.type].apply(thiz, argumentz);
11532 } finally {
11533 d3.event = e0;
11534 }
11535 };
11536 };
11537 return dispatch;
11538 }
11539 d3.requote = function(s) {
11540 return s.replace(d3_requote_re, "\\$&");
11541 };
11542 var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
11543 var d3_subclass = {}.__proto__ ? function(object, prototype) {
11544 object.__proto__ = prototype;
11545 } : function(object, prototype) {
11546 for (var property in prototype) object[property] = prototype[property];
11547 };
11548 function d3_selection(groups) {
11549 d3_subclass(groups, d3_selectionPrototype);
11550 return groups;
11551 }
11552 var d3_select = function(s, n) {
11553 return n.querySelector(s);
11554 }, d3_selectAll = function(s, n) {
11555 return n.querySelectorAll(s);
11556 }, d3_selectMatches = function(n, s) {
11557 var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
11558 d3_selectMatches = function(n, s) {
11559 return d3_selectMatcher.call(n, s);
11560 };
11561 return d3_selectMatches(n, s);
11562 };
11563 if (typeof Sizzle === "function") {
11564 d3_select = function(s, n) {
11565 return Sizzle(s, n)[0] || null;
11566 };
11567 d3_selectAll = Sizzle;
11568 d3_selectMatches = Sizzle.matchesSelector;
11569 }
11570 d3.selection = function() {
11571 return d3.select(d3_document.documentElement);
11572 };
11573 var d3_selectionPrototype = d3.selection.prototype = [];
11574 d3_selectionPrototype.select = function(selector) {
11575 var subgroups = [], subgroup, subnode, group, node;
11576 selector = d3_selection_selector(selector);
11577 for (var j = -1, m = this.length; ++j < m; ) {
11578 subgroups.push(subgroup = []);
11579 subgroup.parentNode = (group = this[j]).parentNode;
11580 for (var i = -1, n = group.length; ++i < n; ) {
11581 if (node = group[i]) {
11582 subgroup.push(subnode = selector.call(node, node.__data__, i, j));
11583 if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
11584 } else {
11585 subgroup.push(null);
11586 }
11587 }
11588 }
11589 return d3_selection(subgroups);
11590 };
11591 function d3_selection_selector(selector) {
11592 return typeof selector === "function" ? selector : function() {
11593 return d3_select(selector, this);
11594 };
11595 }
11596 d3_selectionPrototype.selectAll = function(selector) {
11597 var subgroups = [], subgroup, node;
11598 selector = d3_selection_selectorAll(selector);
11599 for (var j = -1, m = this.length; ++j < m; ) {
11600 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
11601 if (node = group[i]) {
11602 subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
11603 subgroup.parentNode = node;
11604 }
11605 }
11606 }
11607 return d3_selection(subgroups);
11608 };
11609 function d3_selection_selectorAll(selector) {
11610 return typeof selector === "function" ? selector : function() {
11611 return d3_selectAll(selector, this);
11612 };
11613 }
11614 var d3_nsXhtml = "http://www.w3.org/1999/xhtml";
11615 var d3_nsPrefix = {
11616 svg: "http://www.w3.org/2000/svg",
11617 xhtml: d3_nsXhtml,
11618 xlink: "http://www.w3.org/1999/xlink",
11619 xml: "http://www.w3.org/XML/1998/namespace",
11620 xmlns: "http://www.w3.org/2000/xmlns/"
11621 };
11622 d3.ns = {
11623 prefix: d3_nsPrefix,
11624 qualify: function(name) {
11625 var i = name.indexOf(":"), prefix = name;
11626 if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
11627 return d3_nsPrefix.hasOwnProperty(prefix) ? {
11628 space: d3_nsPrefix[prefix],
11629 local: name
11630 } : name;
11631 }
11632 };
11633 d3_selectionPrototype.attr = function(name, value) {
11634 if (arguments.length < 2) {
11635 if (typeof name === "string") {
11636 var node = this.node();
11637 name = d3.ns.qualify(name);
11638 return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
11639 }
11640 for (value in name) this.each(d3_selection_attr(value, name[value]));
11641 return this;
11642 }
11643 return this.each(d3_selection_attr(name, value));
11644 };
11645 function d3_selection_attr(name, value) {
11646 name = d3.ns.qualify(name);
11647 function attrNull() {
11648 this.removeAttribute(name);
11649 }
11650 function attrNullNS() {
11651 this.removeAttributeNS(name.space, name.local);
11652 }
11653 function attrConstant() {
11654 this.setAttribute(name, value);
11655 }
11656 function attrConstantNS() {
11657 this.setAttributeNS(name.space, name.local, value);
11658 }
11659 function attrFunction() {
11660 var x = value.apply(this, arguments);
11661 if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
11662 }
11663 function attrFunctionNS() {
11664 var x = value.apply(this, arguments);
11665 if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
11666 }
11667 return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
11668 }
11669 function d3_collapse(s) {
11670 return s.trim().replace(/\s+/g, " ");
11671 }
11672 d3_selectionPrototype.classed = function(name, value) {
11673 if (arguments.length < 2) {
11674 if (typeof name === "string") {
11675 var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
11676 if (value = node.classList) {
11677 while (++i < n) if (!value.contains(name[i])) return false;
11678 } else {
11679 value = node.getAttribute("class");
11680 while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
11681 }
11682 return true;
11683 }
11684 for (value in name) this.each(d3_selection_classed(value, name[value]));
11685 return this;
11686 }
11687 return this.each(d3_selection_classed(name, value));
11688 };
11689 function d3_selection_classedRe(name) {
11690 return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
11691 }
11692 function d3_selection_classes(name) {
11693 return (name + "").trim().split(/^|\s+/);
11694 }
11695 function d3_selection_classed(name, value) {
11696 name = d3_selection_classes(name).map(d3_selection_classedName);
11697 var n = name.length;
11698 function classedConstant() {
11699 var i = -1;
11700 while (++i < n) name[i](this, value);
11701 }
11702 function classedFunction() {
11703 var i = -1, x = value.apply(this, arguments);
11704 while (++i < n) name[i](this, x);
11705 }
11706 return typeof value === "function" ? classedFunction : classedConstant;
11707 }
11708 function d3_selection_classedName(name) {
11709 var re = d3_selection_classedRe(name);
11710 return function(node, value) {
11711 if (c = node.classList) return value ? c.add(name) : c.remove(name);
11712 var c = node.getAttribute("class") || "";
11713 if (value) {
11714 re.lastIndex = 0;
11715 if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
11716 } else {
11717 node.setAttribute("class", d3_collapse(c.replace(re, " ")));
11718 }
11719 };
11720 }
11721 d3_selectionPrototype.style = function(name, value, priority) {
11722 var n = arguments.length;
11723 if (n < 3) {
11724 if (typeof name !== "string") {
11725 if (n < 2) value = "";
11726 for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
11727 return this;
11728 }
11729 if (n < 2) {
11730 var node = this.node();
11731 return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
11732 }
11733 priority = "";
11734 }
11735 return this.each(d3_selection_style(name, value, priority));
11736 };
11737 function d3_selection_style(name, value, priority) {
11738 function styleNull() {
11739 this.style.removeProperty(name);
11740 }
11741 function styleConstant() {
11742 this.style.setProperty(name, value, priority);
11743 }
11744 function styleFunction() {
11745 var x = value.apply(this, arguments);
11746 if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
11747 }
11748 return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
11749 }
11750 d3_selectionPrototype.property = function(name, value) {
11751 if (arguments.length < 2) {
11752 if (typeof name === "string") return this.node()[name];
11753 for (value in name) this.each(d3_selection_property(value, name[value]));
11754 return this;
11755 }
11756 return this.each(d3_selection_property(name, value));
11757 };
11758 function d3_selection_property(name, value) {
11759 function propertyNull() {
11760 delete this[name];
11761 }
11762 function propertyConstant() {
11763 this[name] = value;
11764 }
11765 function propertyFunction() {
11766 var x = value.apply(this, arguments);
11767 if (x == null) delete this[name]; else this[name] = x;
11768 }
11769 return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
11770 }
11771 d3_selectionPrototype.text = function(value) {
11772 return arguments.length ? this.each(typeof value === "function" ? function() {
11773 var v = value.apply(this, arguments);
11774 this.textContent = v == null ? "" : v;
11775 } : value == null ? function() {
11776 this.textContent = "";
11777 } : function() {
11778 this.textContent = value;
11779 }) : this.node().textContent;
11780 };
11781 d3_selectionPrototype.html = function(value) {
11782 return arguments.length ? this.each(typeof value === "function" ? function() {
11783 var v = value.apply(this, arguments);
11784 this.innerHTML = v == null ? "" : v;
11785 } : value == null ? function() {
11786 this.innerHTML = "";
11787 } : function() {
11788 this.innerHTML = value;
11789 }) : this.node().innerHTML;
11790 };
11791 d3_selectionPrototype.append = function(name) {
11792 name = d3_selection_creator(name);
11793 return this.select(function() {
11794 return this.appendChild(name.apply(this, arguments));
11795 });
11796 };
11797 function d3_selection_creator(name) {
11798 function create() {
11799 var document = this.ownerDocument, namespace = this.namespaceURI;
11800 return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml ? document.createElement(name) : document.createElementNS(namespace, name);
11801 }
11802 function createNS() {
11803 return this.ownerDocument.createElementNS(name.space, name.local);
11804 }
11805 return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
11806 }
11807 d3_selectionPrototype.insert = function(name, before) {
11808 name = d3_selection_creator(name);
11809 before = d3_selection_selector(before);
11810 return this.select(function() {
11811 return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
11812 });
11813 };
11814 d3_selectionPrototype.remove = function() {
11815 return this.each(d3_selectionRemove);
11816 };
11817 function d3_selectionRemove() {
11818 var parent = this.parentNode;
11819 if (parent) parent.removeChild(this);
11820 }
11821 d3_selectionPrototype.data = function(value, key) {
11822 var i = -1, n = this.length, group, node;
11823 if (!arguments.length) {
11824 value = new Array(n = (group = this[0]).length);
11825 while (++i < n) {
11826 if (node = group[i]) {
11827 value[i] = node.__data__;
11828 }
11829 }
11830 return value;
11831 }
11832 function bind(group, groupData) {
11833 var i, n = group.length, m = groupData.length, n0 = Math.min(n, m), updateNodes = new Array(m), enterNodes = new Array(m), exitNodes = new Array(n), node, nodeData;
11834 if (key) {
11835 var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
11836 for (i = -1; ++i < n; ) {
11837 if (node = group[i]) {
11838 if (nodeByKeyValue.has(keyValue = key.call(node, node.__data__, i))) {
11839 exitNodes[i] = node;
11840 } else {
11841 nodeByKeyValue.set(keyValue, node);
11842 }
11843 keyValues[i] = keyValue;
11844 }
11845 }
11846 for (i = -1; ++i < m; ) {
11847 if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
11848 enterNodes[i] = d3_selection_dataNode(nodeData);
11849 } else if (node !== true) {
11850 updateNodes[i] = node;
11851 node.__data__ = nodeData;
11852 }
11853 nodeByKeyValue.set(keyValue, true);
11854 }
11855 for (i = -1; ++i < n; ) {
11856 if (i in keyValues && nodeByKeyValue.get(keyValues[i]) !== true) {
11857 exitNodes[i] = group[i];
11858 }
11859 }
11860 } else {
11861 for (i = -1; ++i < n0; ) {
11862 node = group[i];
11863 nodeData = groupData[i];
11864 if (node) {
11865 node.__data__ = nodeData;
11866 updateNodes[i] = node;
11867 } else {
11868 enterNodes[i] = d3_selection_dataNode(nodeData);
11869 }
11870 }
11871 for (;i < m; ++i) {
11872 enterNodes[i] = d3_selection_dataNode(groupData[i]);
11873 }
11874 for (;i < n; ++i) {
11875 exitNodes[i] = group[i];
11876 }
11877 }
11878 enterNodes.update = updateNodes;
11879 enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
11880 enter.push(enterNodes);
11881 update.push(updateNodes);
11882 exit.push(exitNodes);
11883 }
11884 var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
11885 if (typeof value === "function") {
11886 while (++i < n) {
11887 bind(group = this[i], value.call(group, group.parentNode.__data__, i));
11888 }
11889 } else {
11890 while (++i < n) {
11891 bind(group = this[i], value);
11892 }
11893 }
11894 update.enter = function() {
11895 return enter;
11896 };
11897 update.exit = function() {
11898 return exit;
11899 };
11900 return update;
11901 };
11902 function d3_selection_dataNode(data) {
11903 return {
11904 __data__: data
11905 };
11906 }
11907 d3_selectionPrototype.datum = function(value) {
11908 return arguments.length ? this.property("__data__", value) : this.property("__data__");
11909 };
11910 d3_selectionPrototype.filter = function(filter) {
11911 var subgroups = [], subgroup, group, node;
11912 if (typeof filter !== "function") filter = d3_selection_filter(filter);
11913 for (var j = 0, m = this.length; j < m; j++) {
11914 subgroups.push(subgroup = []);
11915 subgroup.parentNode = (group = this[j]).parentNode;
11916 for (var i = 0, n = group.length; i < n; i++) {
11917 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
11918 subgroup.push(node);
11919 }
11920 }
11921 }
11922 return d3_selection(subgroups);
11923 };
11924 function d3_selection_filter(selector) {
11925 return function() {
11926 return d3_selectMatches(this, selector);
11927 };
11928 }
11929 d3_selectionPrototype.order = function() {
11930 for (var j = -1, m = this.length; ++j < m; ) {
11931 for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
11932 if (node = group[i]) {
11933 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
11934 next = node;
11935 }
11936 }
11937 }
11938 return this;
11939 };
11940 d3_selectionPrototype.sort = function(comparator) {
11941 comparator = d3_selection_sortComparator.apply(this, arguments);
11942 for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
11943 return this.order();
11944 };
11945 function d3_selection_sortComparator(comparator) {
11946 if (!arguments.length) comparator = d3_ascending;
11947 return function(a, b) {
11948 return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
11949 };
11950 }
11951 d3_selectionPrototype.each = function(callback) {
11952 return d3_selection_each(this, function(node, i, j) {
11953 callback.call(node, node.__data__, i, j);
11954 });
11955 };
11956 function d3_selection_each(groups, callback) {
11957 for (var j = 0, m = groups.length; j < m; j++) {
11958 for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
11959 if (node = group[i]) callback(node, i, j);
11960 }
11961 }
11962 return groups;
11963 }
11964 d3_selectionPrototype.call = function(callback) {
11965 var args = d3_array(arguments);
11966 callback.apply(args[0] = this, args);
11967 return this;
11968 };
11969 d3_selectionPrototype.empty = function() {
11970 return !this.node();
11971 };
11972 d3_selectionPrototype.node = function() {
11973 for (var j = 0, m = this.length; j < m; j++) {
11974 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
11975 var node = group[i];
11976 if (node) return node;
11977 }
11978 }
11979 return null;
11980 };
11981 d3_selectionPrototype.size = function() {
11982 var n = 0;
11983 d3_selection_each(this, function() {
11984 ++n;
11985 });
11986 return n;
11987 };
11988 function d3_selection_enter(selection) {
11989 d3_subclass(selection, d3_selection_enterPrototype);
11990 return selection;
11991 }
11992 var d3_selection_enterPrototype = [];
11993 d3.selection.enter = d3_selection_enter;
11994 d3.selection.enter.prototype = d3_selection_enterPrototype;
11995 d3_selection_enterPrototype.append = d3_selectionPrototype.append;
11996 d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
11997 d3_selection_enterPrototype.node = d3_selectionPrototype.node;
11998 d3_selection_enterPrototype.call = d3_selectionPrototype.call;
11999 d3_selection_enterPrototype.size = d3_selectionPrototype.size;
12000 d3_selection_enterPrototype.select = function(selector) {
12001 var subgroups = [], subgroup, subnode, upgroup, group, node;
12002 for (var j = -1, m = this.length; ++j < m; ) {
12003 upgroup = (group = this[j]).update;
12004 subgroups.push(subgroup = []);
12005 subgroup.parentNode = group.parentNode;
12006 for (var i = -1, n = group.length; ++i < n; ) {
12007 if (node = group[i]) {
12008 subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
12009 subnode.__data__ = node.__data__;
12010 } else {
12011 subgroup.push(null);
12012 }
12013 }
12014 }
12015 return d3_selection(subgroups);
12016 };
12017 d3_selection_enterPrototype.insert = function(name, before) {
12018 if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
12019 return d3_selectionPrototype.insert.call(this, name, before);
12020 };
12021 function d3_selection_enterInsertBefore(enter) {
12022 var i0, j0;
12023 return function(d, i, j) {
12024 var group = enter[j].update, n = group.length, node;
12025 if (j != j0) j0 = j, i0 = 0;
12026 if (i >= i0) i0 = i + 1;
12027 while (!(node = group[i0]) && ++i0 < n) ;
12028 return node;
12029 };
12030 }
12031 d3.select = function(node) {
12032 var group;
12033 if (typeof node === "string") {
12034 group = [ d3_select(node, d3_document) ];
12035 group.parentNode = d3_document.documentElement;
12036 } else {
12037 group = [ node ];
12038 group.parentNode = d3_documentElement(node);
12039 }
12040 return d3_selection([ group ]);
12041 };
12042 d3.selectAll = function(nodes) {
12043 var group;
12044 if (typeof nodes === "string") {
12045 group = d3_array(d3_selectAll(nodes, d3_document));
12046 group.parentNode = d3_document.documentElement;
12047 } else {
12048 group = d3_array(nodes);
12049 group.parentNode = null;
12050 }
12051 return d3_selection([ group ]);
12052 };
12053 d3_selectionPrototype.on = function(type, listener, capture) {
12054 var n = arguments.length;
12055 if (n < 3) {
12056 if (typeof type !== "string") {
12057 if (n < 2) listener = false;
12058 for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
12059 return this;
12060 }
12061 if (n < 2) return (n = this.node()["__on" + type]) && n._;
12062 capture = false;
12063 }
12064 return this.each(d3_selection_on(type, listener, capture));
12065 };
12066 function d3_selection_on(type, listener, capture) {
12067 var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
12068 if (i > 0) type = type.slice(0, i);
12069 var filter = d3_selection_onFilters.get(type);
12070 if (filter) type = filter, wrap = d3_selection_onFilter;
12071 function onRemove() {
12072 var l = this[name];
12073 if (l) {
12074 this.removeEventListener(type, l, l.$);
12075 delete this[name];
12076 }
12077 }
12078 function onAdd() {
12079 var l = wrap(listener, d3_array(arguments));
12080 onRemove.call(this);
12081 this.addEventListener(type, this[name] = l, l.$ = capture);
12082 l._ = listener;
12083 }
12084 function removeAll() {
12085 var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
12086 for (var name in this) {
12087 if (match = name.match(re)) {
12088 var l = this[name];
12089 this.removeEventListener(match[1], l, l.$);
12090 delete this[name];
12091 }
12092 }
12093 }
12094 return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
12095 }
12096 var d3_selection_onFilters = d3.map({
12097 mouseenter: "mouseover",
12098 mouseleave: "mouseout"
12099 });
12100 if (d3_document) {
12101 d3_selection_onFilters.forEach(function(k) {
12102 if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
12103 });
12104 }
12105 function d3_selection_onListener(listener, argumentz) {
12106 return function(e) {
12107 var o = d3.event;
12108 d3.event = e;
12109 argumentz[0] = this.__data__;
12110 try {
12111 listener.apply(this, argumentz);
12112 } finally {
12113 d3.event = o;
12114 }
12115 };
12116 }
12117 function d3_selection_onFilter(listener, argumentz) {
12118 var l = d3_selection_onListener(listener, argumentz);
12119 return function(e) {
12120 var target = this, related = e.relatedTarget;
12121 if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
12122 l.call(target, e);
12123 }
12124 };
12125 }
12126 var d3_event_dragSelect, d3_event_dragId = 0;
12127 function d3_event_dragSuppress(node) {
12128 var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window(node)).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
12129 if (d3_event_dragSelect == null) {
12130 d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
12131 }
12132 if (d3_event_dragSelect) {
12133 var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
12134 style[d3_event_dragSelect] = "none";
12135 }
12136 return function(suppressClick) {
12137 w.on(name, null);
12138 if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
12139 if (suppressClick) {
12140 var off = function() {
12141 w.on(click, null);
12142 };
12143 w.on(click, function() {
12144 d3_eventPreventDefault();
12145 off();
12146 }, true);
12147 setTimeout(off, 0);
12148 }
12149 };
12150 }
12151 d3.mouse = function(container) {
12152 return d3_mousePoint(container, d3_eventSource());
12153 };
12154 var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
12155 function d3_mousePoint(container, e) {
12156 if (e.changedTouches) e = e.changedTouches[0];
12157 var svg = container.ownerSVGElement || container;
12158 if (svg.createSVGPoint) {
12159 var point = svg.createSVGPoint();
12160 if (d3_mouse_bug44083 < 0) {
12161 var window = d3_window(container);
12162 if (window.scrollX || window.scrollY) {
12163 svg = d3.select("body").append("svg").style({
12164 position: "absolute",
12165 top: 0,
12166 left: 0,
12167 margin: 0,
12168 padding: 0,
12169 border: "none"
12170 }, "important");
12171 var ctm = svg[0][0].getScreenCTM();
12172 d3_mouse_bug44083 = !(ctm.f || ctm.e);
12173 svg.remove();
12174 }
12175 }
12176 if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
12177 point.y = e.clientY;
12178 point = point.matrixTransform(container.getScreenCTM().inverse());
12179 return [ point.x, point.y ];
12180 }
12181 var rect = container.getBoundingClientRect();
12182 return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
12183 }
12184 d3.touch = function(container, touches, identifier) {
12185 if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
12186 if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
12187 if ((touch = touches[i]).identifier === identifier) {
12188 return d3_mousePoint(container, touch);
12189 }
12190 }
12191 };
12192 d3.behavior.drag = function() {
12193 var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_window, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_identity, "touchmove", "touchend");
12194 function drag() {
12195 this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
12196 }
12197 function dragstart(id, position, subject, move, end) {
12198 return function() {
12199 var that = this, target = d3.event.target.correspondingElement || d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
12200 if (origin) {
12201 dragOffset = origin.apply(that, arguments);
12202 dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
12203 } else {
12204 dragOffset = [ 0, 0 ];
12205 }
12206 dispatch({
12207 type: "dragstart"
12208 });
12209 function moved() {
12210 var position1 = position(parent, dragId), dx, dy;
12211 if (!position1) return;
12212 dx = position1[0] - position0[0];
12213 dy = position1[1] - position0[1];
12214 dragged |= dx | dy;
12215 position0 = position1;
12216 dispatch({
12217 type: "drag",
12218 x: position1[0] + dragOffset[0],
12219 y: position1[1] + dragOffset[1],
12220 dx: dx,
12221 dy: dy
12222 });
12223 }
12224 function ended() {
12225 if (!position(parent, dragId)) return;
12226 dragSubject.on(move + dragName, null).on(end + dragName, null);
12227 dragRestore(dragged);
12228 dispatch({
12229 type: "dragend"
12230 });
12231 }
12232 };
12233 }
12234 drag.origin = function(x) {
12235 if (!arguments.length) return origin;
12236 origin = x;
12237 return drag;
12238 };
12239 return d3.rebind(drag, event, "on");
12240 };
12241 function d3_behavior_dragTouchId() {
12242 return d3.event.changedTouches[0].identifier;
12243 }
12244 d3.touches = function(container, touches) {
12245 if (arguments.length < 2) touches = d3_eventSource().touches;
12246 return touches ? d3_array(touches).map(function(touch) {
12247 var point = d3_mousePoint(container, touch);
12248 point.identifier = touch.identifier;
12249 return point;
12250 }) : [];
12251 };
12252 var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
12253 function d3_sgn(x) {
12254 return x > 0 ? 1 : x < 0 ? -1 : 0;
12255 }
12256 function d3_cross2d(a, b, c) {
12257 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
12258 }
12259 function d3_acos(x) {
12260 return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
12261 }
12262 function d3_asin(x) {
12263 return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
12264 }
12265 function d3_sinh(x) {
12266 return ((x = Math.exp(x)) - 1 / x) / 2;
12267 }
12268 function d3_cosh(x) {
12269 return ((x = Math.exp(x)) + 1 / x) / 2;
12270 }
12271 function d3_tanh(x) {
12272 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
12273 }
12274 function d3_haversin(x) {
12275 return (x = Math.sin(x / 2)) * x;
12276 }
12277 var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
12278 d3.interpolateZoom = function(p0, p1) {
12279 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2], dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, i, S;
12280 if (d2 < ε2) {
12281 S = Math.log(w1 / w0) / ρ;
12282 i = function(t) {
12283 return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * t * S) ];
12284 };
12285 } else {
12286 var d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1), b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
12287 S = (r1 - r0) / ρ;
12288 i = function(t) {
12289 var s = t * S, coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
12290 return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
12291 };
12292 }
12293 i.duration = S * 1e3;
12294 return i;
12295 };
12296 d3.behavior.zoom = function() {
12297 var view = {
12298 x: 0,
12299 y: 0,
12300 k: 1
12301 }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, duration = 250, zooming = 0, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
12302 if (!d3_behavior_zoomWheel) {
12303 d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
12304 return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
12305 }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
12306 return d3.event.wheelDelta;
12307 }, "mousewheel") : (d3_behavior_zoomDelta = function() {
12308 return -d3.event.detail;
12309 }, "MozMousePixelScroll");
12310 }
12311 function zoom(g) {
12312 g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
12313 }
12314 zoom.event = function(g) {
12315 g.each(function() {
12316 var dispatch = event.of(this, arguments), view1 = view;
12317 if (d3_transitionInheritId) {
12318 d3.select(this).transition().each("start.zoom", function() {
12319 view = this.__chart__ || {
12320 x: 0,
12321 y: 0,
12322 k: 1
12323 };
12324 zoomstarted(dispatch);
12325 }).tween("zoom:zoom", function() {
12326 var dx = size[0], dy = size[1], cx = center0 ? center0[0] : dx / 2, cy = center0 ? center0[1] : dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);
12327 return function(t) {
12328 var l = i(t), k = dx / l[2];
12329 this.__chart__ = view = {
12330 x: cx - l[0] * k,
12331 y: cy - l[1] * k,
12332 k: k
12333 };
12334 zoomed(dispatch);
12335 };
12336 }).each("interrupt.zoom", function() {
12337 zoomended(dispatch);
12338 }).each("end.zoom", function() {
12339 zoomended(dispatch);
12340 });
12341 } else {
12342 this.__chart__ = view;
12343 zoomstarted(dispatch);
12344 zoomed(dispatch);
12345 zoomended(dispatch);
12346 }
12347 });
12348 };
12349 zoom.translate = function(_) {
12350 if (!arguments.length) return [ view.x, view.y ];
12351 view = {
12352 x: +_[0],
12353 y: +_[1],
12354 k: view.k
12355 };
12356 rescale();
12357 return zoom;
12358 };
12359 zoom.scale = function(_) {
12360 if (!arguments.length) return view.k;
12361 view = {
12362 x: view.x,
12363 y: view.y,
12364 k: null
12365 };
12366 scaleTo(+_);
12367 rescale();
12368 return zoom;
12369 };
12370 zoom.scaleExtent = function(_) {
12371 if (!arguments.length) return scaleExtent;
12372 scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
12373 return zoom;
12374 };
12375 zoom.center = function(_) {
12376 if (!arguments.length) return center;
12377 center = _ && [ +_[0], +_[1] ];
12378 return zoom;
12379 };
12380 zoom.size = function(_) {
12381 if (!arguments.length) return size;
12382 size = _ && [ +_[0], +_[1] ];
12383 return zoom;
12384 };
12385 zoom.duration = function(_) {
12386 if (!arguments.length) return duration;
12387 duration = +_;
12388 return zoom;
12389 };
12390 zoom.x = function(z) {
12391 if (!arguments.length) return x1;
12392 x1 = z;
12393 x0 = z.copy();
12394 view = {
12395 x: 0,
12396 y: 0,
12397 k: 1
12398 };
12399 return zoom;
12400 };
12401 zoom.y = function(z) {
12402 if (!arguments.length) return y1;
12403 y1 = z;
12404 y0 = z.copy();
12405 view = {
12406 x: 0,
12407 y: 0,
12408 k: 1
12409 };
12410 return zoom;
12411 };
12412 function location(p) {
12413 return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
12414 }
12415 function point(l) {
12416 return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
12417 }
12418 function scaleTo(s) {
12419 view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
12420 }
12421 function translateTo(p, l) {
12422 l = point(l);
12423 view.x += p[0] - l[0];
12424 view.y += p[1] - l[1];
12425 }
12426 function zoomTo(that, p, l, k) {
12427 that.__chart__ = {
12428 x: view.x,
12429 y: view.y,
12430 k: view.k
12431 };
12432 scaleTo(Math.pow(2, k));
12433 translateTo(center0 = p, l);
12434 that = d3.select(that);
12435 if (duration > 0) that = that.transition().duration(duration);
12436 that.call(zoom.event);
12437 }
12438 function rescale() {
12439 if (x1) x1.domain(x0.range().map(function(x) {
12440 return (x - view.x) / view.k;
12441 }).map(x0.invert));
12442 if (y1) y1.domain(y0.range().map(function(y) {
12443 return (y - view.y) / view.k;
12444 }).map(y0.invert));
12445 }
12446 function zoomstarted(dispatch) {
12447 if (!zooming++) dispatch({
12448 type: "zoomstart"
12449 });
12450 }
12451 function zoomed(dispatch) {
12452 rescale();
12453 dispatch({
12454 type: "zoom",
12455 scale: view.k,
12456 translate: [ view.x, view.y ]
12457 });
12458 }
12459 function zoomended(dispatch) {
12460 if (!--zooming) dispatch({
12461 type: "zoomend"
12462 }), center0 = null;
12463 }
12464 function mousedowned() {
12465 var that = this, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);
12466 d3_selection_interrupt.call(that);
12467 zoomstarted(dispatch);
12468 function moved() {
12469 dragged = 1;
12470 translateTo(d3.mouse(that), location0);
12471 zoomed(dispatch);
12472 }
12473 function ended() {
12474 subject.on(mousemove, null).on(mouseup, null);
12475 dragRestore(dragged);
12476 zoomended(dispatch);
12477 }
12478 }
12479 function touchstarted() {
12480 var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress(that);
12481 started();
12482 zoomstarted(dispatch);
12483 subject.on(mousedown, null).on(touchstart, started);
12484 function relocate() {
12485 var touches = d3.touches(that);
12486 scale0 = view.k;
12487 touches.forEach(function(t) {
12488 if (t.identifier in locations0) locations0[t.identifier] = location(t);
12489 });
12490 return touches;
12491 }
12492 function started() {
12493 var target = d3.event.target;
12494 d3.select(target).on(touchmove, moved).on(touchend, ended);
12495 targets.push(target);
12496 var changed = d3.event.changedTouches;
12497 for (var i = 0, n = changed.length; i < n; ++i) {
12498 locations0[changed[i].identifier] = null;
12499 }
12500 var touches = relocate(), now = Date.now();
12501 if (touches.length === 1) {
12502 if (now - touchtime < 500) {
12503 var p = touches[0];
12504 zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
12505 d3_eventPreventDefault();
12506 }
12507 touchtime = now;
12508 } else if (touches.length > 1) {
12509 var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
12510 distance0 = dx * dx + dy * dy;
12511 }
12512 }
12513 function moved() {
12514 var touches = d3.touches(that), p0, l0, p1, l1;
12515 d3_selection_interrupt.call(that);
12516 for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
12517 p1 = touches[i];
12518 if (l1 = locations0[p1.identifier]) {
12519 if (l0) break;
12520 p0 = p1, l0 = l1;
12521 }
12522 }
12523 if (l1) {
12524 var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
12525 p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
12526 l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
12527 scaleTo(scale1 * scale0);
12528 }
12529 touchtime = null;
12530 translateTo(p0, l0);
12531 zoomed(dispatch);
12532 }
12533 function ended() {
12534 if (d3.event.touches.length) {
12535 var changed = d3.event.changedTouches;
12536 for (var i = 0, n = changed.length; i < n; ++i) {
12537 delete locations0[changed[i].identifier];
12538 }
12539 for (var identifier in locations0) {
12540 return void relocate();
12541 }
12542 }
12543 d3.selectAll(targets).on(zoomName, null);
12544 subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
12545 dragRestore();
12546 zoomended(dispatch);
12547 }
12548 }
12549 function mousewheeled() {
12550 var dispatch = event.of(this, arguments);
12551 if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
12552 translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch);
12553 mousewheelTimer = setTimeout(function() {
12554 mousewheelTimer = null;
12555 zoomended(dispatch);
12556 }, 50);
12557 d3_eventPreventDefault();
12558 scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
12559 translateTo(center0, translate0);
12560 zoomed(dispatch);
12561 }
12562 function dblclicked() {
12563 var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
12564 zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
12565 }
12566 return d3.rebind(zoom, event, "on");
12567 };
12568 var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
12569 d3.color = d3_color;
12570 function d3_color() {}
12571 d3_color.prototype.toString = function() {
12572 return this.rgb() + "";
12573 };
12574 d3.hsl = d3_hsl;
12575 function d3_hsl(h, s, l) {
12576 return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) : arguments.length < 2 ? h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : new d3_hsl(h, s, l);
12577 }
12578 var d3_hslPrototype = d3_hsl.prototype = new d3_color();
12579 d3_hslPrototype.brighter = function(k) {
12580 k = Math.pow(.7, arguments.length ? k : 1);
12581 return new d3_hsl(this.h, this.s, this.l / k);
12582 };
12583 d3_hslPrototype.darker = function(k) {
12584 k = Math.pow(.7, arguments.length ? k : 1);
12585 return new d3_hsl(this.h, this.s, k * this.l);
12586 };
12587 d3_hslPrototype.rgb = function() {
12588 return d3_hsl_rgb(this.h, this.s, this.l);
12589 };
12590 function d3_hsl_rgb(h, s, l) {
12591 var m1, m2;
12592 h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
12593 s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
12594 l = l < 0 ? 0 : l > 1 ? 1 : l;
12595 m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
12596 m1 = 2 * l - m2;
12597 function v(h) {
12598 if (h > 360) h -= 360; else if (h < 0) h += 360;
12599 if (h < 60) return m1 + (m2 - m1) * h / 60;
12600 if (h < 180) return m2;
12601 if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
12602 return m1;
12603 }
12604 function vv(h) {
12605 return Math.round(v(h) * 255);
12606 }
12607 return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
12608 }
12609 d3.hcl = d3_hcl;
12610 function d3_hcl(h, c, l) {
12611 return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) : arguments.length < 2 ? h instanceof d3_hcl ? new d3_hcl(h.h, h.c, h.l) : h instanceof d3_lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : new d3_hcl(h, c, l);
12612 }
12613 var d3_hclPrototype = d3_hcl.prototype = new d3_color();
12614 d3_hclPrototype.brighter = function(k) {
12615 return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
12616 };
12617 d3_hclPrototype.darker = function(k) {
12618 return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
12619 };
12620 d3_hclPrototype.rgb = function() {
12621 return d3_hcl_lab(this.h, this.c, this.l).rgb();
12622 };
12623 function d3_hcl_lab(h, c, l) {
12624 if (isNaN(h)) h = 0;
12625 if (isNaN(c)) c = 0;
12626 return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
12627 }
12628 d3.lab = d3_lab;
12629 function d3_lab(l, a, b) {
12630 return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.h, l.c, l.l) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);
12631 }
12632 var d3_lab_K = 18;
12633 var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
12634 var d3_labPrototype = d3_lab.prototype = new d3_color();
12635 d3_labPrototype.brighter = function(k) {
12636 return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
12637 };
12638 d3_labPrototype.darker = function(k) {
12639 return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
12640 };
12641 d3_labPrototype.rgb = function() {
12642 return d3_lab_rgb(this.l, this.a, this.b);
12643 };
12644 function d3_lab_rgb(l, a, b) {
12645 var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
12646 x = d3_lab_xyz(x) * d3_lab_X;
12647 y = d3_lab_xyz(y) * d3_lab_Y;
12648 z = d3_lab_xyz(z) * d3_lab_Z;
12649 return new d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
12650 }
12651 function d3_lab_hcl(l, a, b) {
12652 return l > 0 ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : new d3_hcl(NaN, NaN, l);
12653 }
12654 function d3_lab_xyz(x) {
12655 return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
12656 }
12657 function d3_xyz_lab(x) {
12658 return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
12659 }
12660 function d3_xyz_rgb(r) {
12661 return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
12662 }
12663 d3.rgb = d3_rgb;
12664 function d3_rgb(r, g, b) {
12665 return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) : arguments.length < 2 ? r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : new d3_rgb(r, g, b);
12666 }
12667 function d3_rgbNumber(value) {
12668 return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
12669 }
12670 function d3_rgbString(value) {
12671 return d3_rgbNumber(value) + "";
12672 }
12673 var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
12674 d3_rgbPrototype.brighter = function(k) {
12675 k = Math.pow(.7, arguments.length ? k : 1);
12676 var r = this.r, g = this.g, b = this.b, i = 30;
12677 if (!r && !g && !b) return new d3_rgb(i, i, i);
12678 if (r && r < i) r = i;
12679 if (g && g < i) g = i;
12680 if (b && b < i) b = i;
12681 return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
12682 };
12683 d3_rgbPrototype.darker = function(k) {
12684 k = Math.pow(.7, arguments.length ? k : 1);
12685 return new d3_rgb(k * this.r, k * this.g, k * this.b);
12686 };
12687 d3_rgbPrototype.hsl = function() {
12688 return d3_rgb_hsl(this.r, this.g, this.b);
12689 };
12690 d3_rgbPrototype.toString = function() {
12691 return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
12692 };
12693 function d3_rgb_hex(v) {
12694 return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
12695 }
12696 function d3_rgb_parse(format, rgb, hsl) {
12697 var r = 0, g = 0, b = 0, m1, m2, color;
12698 m1 = /([a-z]+)\((.*)\)/.exec(format = format.toLowerCase());
12699 if (m1) {
12700 m2 = m1[2].split(",");
12701 switch (m1[1]) {
12702 case "hsl":
12703 {
12704 return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
12705 }
12706
12707 case "rgb":
12708 {
12709 return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
12710 }
12711 }
12712 }
12713 if (color = d3_rgb_names.get(format)) {
12714 return rgb(color.r, color.g, color.b);
12715 }
12716 if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
12717 if (format.length === 4) {
12718 r = (color & 3840) >> 4;
12719 r = r >> 4 | r;
12720 g = color & 240;
12721 g = g >> 4 | g;
12722 b = color & 15;
12723 b = b << 4 | b;
12724 } else if (format.length === 7) {
12725 r = (color & 16711680) >> 16;
12726 g = (color & 65280) >> 8;
12727 b = color & 255;
12728 }
12729 }
12730 return rgb(r, g, b);
12731 }
12732 function d3_rgb_hsl(r, g, b) {
12733 var min = Math.min(r /= 255, g /= 255, b /= 255), max = Math.max(r, g, b), d = max - min, h, s, l = (max + min) / 2;
12734 if (d) {
12735 s = l < .5 ? d / (max + min) : d / (2 - max - min);
12736 if (r == max) h = (g - b) / d + (g < b ? 6 : 0); else if (g == max) h = (b - r) / d + 2; else h = (r - g) / d + 4;
12737 h *= 60;
12738 } else {
12739 h = NaN;
12740 s = l > 0 && l < 1 ? 0 : h;
12741 }
12742 return new d3_hsl(h, s, l);
12743 }
12744 function d3_rgb_lab(r, g, b) {
12745 r = d3_rgb_xyz(r);
12746 g = d3_rgb_xyz(g);
12747 b = d3_rgb_xyz(b);
12748 var x = d3_xyz_lab((.4124564 * r + .3575761 * g + .1804375 * b) / d3_lab_X), y = d3_xyz_lab((.2126729 * r + .7151522 * g + .072175 * b) / d3_lab_Y), z = d3_xyz_lab((.0193339 * r + .119192 * g + .9503041 * b) / d3_lab_Z);
12749 return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
12750 }
12751 function d3_rgb_xyz(r) {
12752 return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
12753 }
12754 function d3_rgb_parseNumber(c) {
12755 var f = parseFloat(c);
12756 return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
12757 }
12758 var d3_rgb_names = d3.map({
12759 aliceblue: 15792383,
12760 antiquewhite: 16444375,
12761 aqua: 65535,
12762 aquamarine: 8388564,
12763 azure: 15794175,
12764 beige: 16119260,
12765 bisque: 16770244,
12766 black: 0,
12767 blanchedalmond: 16772045,
12768 blue: 255,
12769 blueviolet: 9055202,
12770 brown: 10824234,
12771 burlywood: 14596231,
12772 cadetblue: 6266528,
12773 chartreuse: 8388352,
12774 chocolate: 13789470,
12775 coral: 16744272,
12776 cornflowerblue: 6591981,
12777 cornsilk: 16775388,
12778 crimson: 14423100,
12779 cyan: 65535,
12780 darkblue: 139,
12781 darkcyan: 35723,
12782 darkgoldenrod: 12092939,
12783 darkgray: 11119017,
12784 darkgreen: 25600,
12785 darkgrey: 11119017,
12786 darkkhaki: 12433259,
12787 darkmagenta: 9109643,
12788 darkolivegreen: 5597999,
12789 darkorange: 16747520,
12790 darkorchid: 10040012,
12791 darkred: 9109504,
12792 darksalmon: 15308410,
12793 darkseagreen: 9419919,
12794 darkslateblue: 4734347,
12795 darkslategray: 3100495,
12796 darkslategrey: 3100495,
12797 darkturquoise: 52945,
12798 darkviolet: 9699539,
12799 deeppink: 16716947,
12800 deepskyblue: 49151,
12801 dimgray: 6908265,
12802 dimgrey: 6908265,
12803 dodgerblue: 2003199,
12804 firebrick: 11674146,
12805 floralwhite: 16775920,
12806 forestgreen: 2263842,
12807 fuchsia: 16711935,
12808 gainsboro: 14474460,
12809 ghostwhite: 16316671,
12810 gold: 16766720,
12811 goldenrod: 14329120,
12812 gray: 8421504,
12813 green: 32768,
12814 greenyellow: 11403055,
12815 grey: 8421504,
12816 honeydew: 15794160,
12817 hotpink: 16738740,
12818 indianred: 13458524,
12819 indigo: 4915330,
12820 ivory: 16777200,
12821 khaki: 15787660,
12822 lavender: 15132410,
12823 lavenderblush: 16773365,
12824 lawngreen: 8190976,
12825 lemonchiffon: 16775885,
12826 lightblue: 11393254,
12827 lightcoral: 15761536,
12828 lightcyan: 14745599,
12829 lightgoldenrodyellow: 16448210,
12830 lightgray: 13882323,
12831 lightgreen: 9498256,
12832 lightgrey: 13882323,
12833 lightpink: 16758465,
12834 lightsalmon: 16752762,
12835 lightseagreen: 2142890,
12836 lightskyblue: 8900346,
12837 lightslategray: 7833753,
12838 lightslategrey: 7833753,
12839 lightsteelblue: 11584734,
12840 lightyellow: 16777184,
12841 lime: 65280,
12842 limegreen: 3329330,
12843 linen: 16445670,
12844 magenta: 16711935,
12845 maroon: 8388608,
12846 mediumaquamarine: 6737322,
12847 mediumblue: 205,
12848 mediumorchid: 12211667,
12849 mediumpurple: 9662683,
12850 mediumseagreen: 3978097,
12851 mediumslateblue: 8087790,
12852 mediumspringgreen: 64154,
12853 mediumturquoise: 4772300,
12854 mediumvioletred: 13047173,
12855 midnightblue: 1644912,
12856 mintcream: 16121850,
12857 mistyrose: 16770273,
12858 moccasin: 16770229,
12859 navajowhite: 16768685,
12860 navy: 128,
12861 oldlace: 16643558,
12862 olive: 8421376,
12863 olivedrab: 7048739,
12864 orange: 16753920,
12865 orangered: 16729344,
12866 orchid: 14315734,
12867 palegoldenrod: 15657130,
12868 palegreen: 10025880,
12869 paleturquoise: 11529966,
12870 palevioletred: 14381203,
12871 papayawhip: 16773077,
12872 peachpuff: 16767673,
12873 peru: 13468991,
12874 pink: 16761035,
12875 plum: 14524637,
12876 powderblue: 11591910,
12877 purple: 8388736,
12878 rebeccapurple: 6697881,
12879 red: 16711680,
12880 rosybrown: 12357519,
12881 royalblue: 4286945,
12882 saddlebrown: 9127187,
12883 salmon: 16416882,
12884 sandybrown: 16032864,
12885 seagreen: 3050327,
12886 seashell: 16774638,
12887 sienna: 10506797,
12888 silver: 12632256,
12889 skyblue: 8900331,
12890 slateblue: 6970061,
12891 slategray: 7372944,
12892 slategrey: 7372944,
12893 snow: 16775930,
12894 springgreen: 65407,
12895 steelblue: 4620980,
12896 tan: 13808780,
12897 teal: 32896,
12898 thistle: 14204888,
12899 tomato: 16737095,
12900 turquoise: 4251856,
12901 violet: 15631086,
12902 wheat: 16113331,
12903 white: 16777215,
12904 whitesmoke: 16119285,
12905 yellow: 16776960,
12906 yellowgreen: 10145074
12907 });
12908 d3_rgb_names.forEach(function(key, value) {
12909 d3_rgb_names.set(key, d3_rgbNumber(value));
12910 });
12911 function d3_functor(v) {
12912 return typeof v === "function" ? v : function() {
12913 return v;
12914 };
12915 }
12916 d3.functor = d3_functor;
12917 d3.xhr = d3_xhrType(d3_identity);
12918 function d3_xhrType(response) {
12919 return function(url, mimeType, callback) {
12920 if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
12921 mimeType = null;
12922 return d3_xhr(url, mimeType, response, callback);
12923 };
12924 }
12925 function d3_xhr(url, mimeType, response, callback) {
12926 var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
12927 if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
12928 "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
12929 request.readyState > 3 && respond();
12930 };
12931 function respond() {
12932 var status = request.status, result;
12933 if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
12934 try {
12935 result = response.call(xhr, request);
12936 } catch (e) {
12937 dispatch.error.call(xhr, e);
12938 return;
12939 }
12940 dispatch.load.call(xhr, result);
12941 } else {
12942 dispatch.error.call(xhr, request);
12943 }
12944 }
12945 request.onprogress = function(event) {
12946 var o = d3.event;
12947 d3.event = event;
12948 try {
12949 dispatch.progress.call(xhr, request);
12950 } finally {
12951 d3.event = o;
12952 }
12953 };
12954 xhr.header = function(name, value) {
12955 name = (name + "").toLowerCase();
12956 if (arguments.length < 2) return headers[name];
12957 if (value == null) delete headers[name]; else headers[name] = value + "";
12958 return xhr;
12959 };
12960 xhr.mimeType = function(value) {
12961 if (!arguments.length) return mimeType;
12962 mimeType = value == null ? null : value + "";
12963 return xhr;
12964 };
12965 xhr.responseType = function(value) {
12966 if (!arguments.length) return responseType;
12967 responseType = value;
12968 return xhr;
12969 };
12970 xhr.response = function(value) {
12971 response = value;
12972 return xhr;
12973 };
12974 [ "get", "post" ].forEach(function(method) {
12975 xhr[method] = function() {
12976 return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
12977 };
12978 });
12979 xhr.send = function(method, data, callback) {
12980 if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
12981 request.open(method, url, true);
12982 if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
12983 if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
12984 if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
12985 if (responseType != null) request.responseType = responseType;
12986 if (callback != null) xhr.on("error", callback).on("load", function(request) {
12987 callback(null, request);
12988 });
12989 dispatch.beforesend.call(xhr, request);
12990 request.send(data == null ? null : data);
12991 return xhr;
12992 };
12993 xhr.abort = function() {
12994 request.abort();
12995 return xhr;
12996 };
12997 d3.rebind(xhr, dispatch, "on");
12998 return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
12999 }
13000 function d3_xhr_fixCallback(callback) {
13001 return callback.length === 1 ? function(error, request) {
13002 callback(error == null ? request : null);
13003 } : callback;
13004 }
13005 function d3_xhrHasResponse(request) {
13006 var type = request.responseType;
13007 return type && type !== "text" ? request.response : request.responseText;
13008 }
13009 d3.dsv = function(delimiter, mimeType) {
13010 var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
13011 function dsv(url, row, callback) {
13012 if (arguments.length < 3) callback = row, row = null;
13013 var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
13014 xhr.row = function(_) {
13015 return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
13016 };
13017 return xhr;
13018 }
13019 function response(request) {
13020 return dsv.parse(request.responseText);
13021 }
13022 function typedResponse(f) {
13023 return function(request) {
13024 return dsv.parse(request.responseText, f);
13025 };
13026 }
13027 dsv.parse = function(text, f) {
13028 var o;
13029 return dsv.parseRows(text, function(row, i) {
13030 if (o) return o(row, i - 1);
13031 var a = new Function("d", "return {" + row.map(function(name, i) {
13032 return JSON.stringify(name) + ": d[" + i + "]";
13033 }).join(",") + "}");
13034 o = f ? function(row, i) {
13035 return f(a(row), i);
13036 } : a;
13037 });
13038 };
13039 dsv.parseRows = function(text, f) {
13040 var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
13041 function token() {
13042 if (I >= N) return EOF;
13043 if (eol) return eol = false, EOL;
13044 var j = I;
13045 if (text.charCodeAt(j) === 34) {
13046 var i = j;
13047 while (i++ < N) {
13048 if (text.charCodeAt(i) === 34) {
13049 if (text.charCodeAt(i + 1) !== 34) break;
13050 ++i;
13051 }
13052 }
13053 I = i + 2;
13054 var c = text.charCodeAt(i + 1);
13055 if (c === 13) {
13056 eol = true;
13057 if (text.charCodeAt(i + 2) === 10) ++I;
13058 } else if (c === 10) {
13059 eol = true;
13060 }
13061 return text.slice(j + 1, i).replace(/""/g, '"');
13062 }
13063 while (I < N) {
13064 var c = text.charCodeAt(I++), k = 1;
13065 if (c === 10) eol = true; else if (c === 13) {
13066 eol = true;
13067 if (text.charCodeAt(I) === 10) ++I, ++k;
13068 } else if (c !== delimiterCode) continue;
13069 return text.slice(j, I - k);
13070 }
13071 return text.slice(j);
13072 }
13073 while ((t = token()) !== EOF) {
13074 var a = [];
13075 while (t !== EOL && t !== EOF) {
13076 a.push(t);
13077 t = token();
13078 }
13079 if (f && (a = f(a, n++)) == null) continue;
13080 rows.push(a);
13081 }
13082 return rows;
13083 };
13084 dsv.format = function(rows) {
13085 if (Array.isArray(rows[0])) return dsv.formatRows(rows);
13086 var fieldSet = new d3_Set(), fields = [];
13087 rows.forEach(function(row) {
13088 for (var field in row) {
13089 if (!fieldSet.has(field)) {
13090 fields.push(fieldSet.add(field));
13091 }
13092 }
13093 });
13094 return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
13095 return fields.map(function(field) {
13096 return formatValue(row[field]);
13097 }).join(delimiter);
13098 })).join("\n");
13099 };
13100 dsv.formatRows = function(rows) {
13101 return rows.map(formatRow).join("\n");
13102 };
13103 function formatRow(row) {
13104 return row.map(formatValue).join(delimiter);
13105 }
13106 function formatValue(text) {
13107 return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
13108 }
13109 return dsv;
13110 };
13111 d3.csv = d3.dsv(",", "text/csv");
13112 d3.tsv = d3.dsv(" ", "text/tab-separated-values");
13113 var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
13114 setTimeout(callback, 17);
13115 };
13116 d3.timer = function() {
13117 d3_timer.apply(this, arguments);
13118 };
13119 function d3_timer(callback, delay, then) {
13120 var n = arguments.length;
13121 if (n < 2) delay = 0;
13122 if (n < 3) then = Date.now();
13123 var time = then + delay, timer = {
13124 c: callback,
13125 t: time,
13126 n: null
13127 };
13128 if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
13129 d3_timer_queueTail = timer;
13130 if (!d3_timer_interval) {
13131 d3_timer_timeout = clearTimeout(d3_timer_timeout);
13132 d3_timer_interval = 1;
13133 d3_timer_frame(d3_timer_step);
13134 }
13135 return timer;
13136 }
13137 function d3_timer_step() {
13138 var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
13139 if (delay > 24) {
13140 if (isFinite(delay)) {
13141 clearTimeout(d3_timer_timeout);
13142 d3_timer_timeout = setTimeout(d3_timer_step, delay);
13143 }
13144 d3_timer_interval = 0;
13145 } else {
13146 d3_timer_interval = 1;
13147 d3_timer_frame(d3_timer_step);
13148 }
13149 }
13150 d3.timer.flush = function() {
13151 d3_timer_mark();
13152 d3_timer_sweep();
13153 };
13154 function d3_timer_mark() {
13155 var now = Date.now(), timer = d3_timer_queueHead;
13156 while (timer) {
13157 if (now >= timer.t && timer.c(now - timer.t)) timer.c = null;
13158 timer = timer.n;
13159 }
13160 return now;
13161 }
13162 function d3_timer_sweep() {
13163 var t0, t1 = d3_timer_queueHead, time = Infinity;
13164 while (t1) {
13165 if (t1.c) {
13166 if (t1.t < time) time = t1.t;
13167 t1 = (t0 = t1).n;
13168 } else {
13169 t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
13170 }
13171 }
13172 d3_timer_queueTail = t0;
13173 return time;
13174 }
13175 function d3_format_precision(x, p) {
13176 return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
13177 }
13178 d3.round = function(x, n) {
13179 return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
13180 };
13181 var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
13182 d3.formatPrefix = function(value, precision) {
13183 var i = 0;
13184 if (value = +value) {
13185 if (value < 0) value *= -1;
13186 if (precision) value = d3.round(value, d3_format_precision(value, precision));
13187 i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
13188 i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
13189 }
13190 return d3_formatPrefixes[8 + i / 3];
13191 };
13192 function d3_formatPrefix(d, i) {
13193 var k = Math.pow(10, abs(8 - i) * 3);
13194 return {
13195 scale: i > 8 ? function(d) {
13196 return d / k;
13197 } : function(d) {
13198 return d * k;
13199 },
13200 symbol: d
13201 };
13202 }
13203 function d3_locale_numberFormat(locale) {
13204 var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping && locale_thousands ? function(value, width) {
13205 var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
13206 while (i > 0 && g > 0) {
13207 if (length + g + 1 > width) g = Math.max(1, width - length);
13208 t.push(value.substring(i -= g, i + g));
13209 if ((length += g + 1) > width) break;
13210 g = locale_grouping[j = (j + 1) % locale_grouping.length];
13211 }
13212 return t.reverse().join(locale_thousands);
13213 } : d3_identity;
13214 return function(specifier) {
13215 var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "-", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false, exponent = true;
13216 if (precision) precision = +precision.substring(1);
13217 if (zfill || fill === "0" && align === "=") {
13218 zfill = fill = "0";
13219 align = "=";
13220 }
13221 switch (type) {
13222 case "n":
13223 comma = true;
13224 type = "g";
13225 break;
13226
13227 case "%":
13228 scale = 100;
13229 suffix = "%";
13230 type = "f";
13231 break;
13232
13233 case "p":
13234 scale = 100;
13235 suffix = "%";
13236 type = "r";
13237 break;
13238
13239 case "b":
13240 case "o":
13241 case "x":
13242 case "X":
13243 if (symbol === "#") prefix = "0" + type.toLowerCase();
13244
13245 case "c":
13246 exponent = false;
13247
13248 case "d":
13249 integer = true;
13250 precision = 0;
13251 break;
13252
13253 case "s":
13254 scale = -1;
13255 type = "r";
13256 break;
13257 }
13258 if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
13259 if (type == "r" && !precision) type = "g";
13260 if (precision != null) {
13261 if (type == "g") precision = Math.max(1, Math.min(21, precision)); else if (type == "e" || type == "f") precision = Math.max(0, Math.min(20, precision));
13262 }
13263 type = d3_format_types.get(type) || d3_format_typeDefault;
13264 var zcomma = zfill && comma;
13265 return function(value) {
13266 var fullSuffix = suffix;
13267 if (integer && value % 1) return "";
13268 var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
13269 if (scale < 0) {
13270 var unit = d3.formatPrefix(value, precision);
13271 value = unit.scale(value);
13272 fullSuffix = unit.symbol + suffix;
13273 } else {
13274 value *= scale;
13275 }
13276 value = type(value, precision);
13277 var i = value.lastIndexOf("."), before, after;
13278 if (i < 0) {
13279 var j = exponent ? value.lastIndexOf("e") : -1;
13280 if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
13281 } else {
13282 before = value.substring(0, i);
13283 after = locale_decimal + value.substring(i + 1);
13284 }
13285 if (!zfill && comma) before = formatGroup(before, Infinity);
13286 var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
13287 if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
13288 negative += prefix;
13289 value = before + after;
13290 return (align === "<" ? negative + value + padding : align === ">" ? padding + negative + value : align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) : negative + (zcomma ? value : padding + value)) + fullSuffix;
13291 };
13292 };
13293 }
13294 var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
13295 var d3_format_types = d3.map({
13296 b: function(x) {
13297 return x.toString(2);
13298 },
13299 c: function(x) {
13300 return String.fromCharCode(x);
13301 },
13302 o: function(x) {
13303 return x.toString(8);
13304 },
13305 x: function(x) {
13306 return x.toString(16);
13307 },
13308 X: function(x) {
13309 return x.toString(16).toUpperCase();
13310 },
13311 g: function(x, p) {
13312 return x.toPrecision(p);
13313 },
13314 e: function(x, p) {
13315 return x.toExponential(p);
13316 },
13317 f: function(x, p) {
13318 return x.toFixed(p);
13319 },
13320 r: function(x, p) {
13321 return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + 1e-15), p))));
13322 }
13323 });
13324 function d3_format_typeDefault(x) {
13325 return x + "";
13326 }
13327 var d3_time = d3.time = {}, d3_date = Date;
13328 function d3_date_utc() {
13329 this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
13330 }
13331 d3_date_utc.prototype = {
13332 getDate: function() {
13333 return this._.getUTCDate();
13334 },
13335 getDay: function() {
13336 return this._.getUTCDay();
13337 },
13338 getFullYear: function() {
13339 return this._.getUTCFullYear();
13340 },
13341 getHours: function() {
13342 return this._.getUTCHours();
13343 },
13344 getMilliseconds: function() {
13345 return this._.getUTCMilliseconds();
13346 },
13347 getMinutes: function() {
13348 return this._.getUTCMinutes();
13349 },
13350 getMonth: function() {
13351 return this._.getUTCMonth();
13352 },
13353 getSeconds: function() {
13354 return this._.getUTCSeconds();
13355 },
13356 getTime: function() {
13357 return this._.getTime();
13358 },
13359 getTimezoneOffset: function() {
13360 return 0;
13361 },
13362 valueOf: function() {
13363 return this._.valueOf();
13364 },
13365 setDate: function() {
13366 d3_time_prototype.setUTCDate.apply(this._, arguments);
13367 },
13368 setDay: function() {
13369 d3_time_prototype.setUTCDay.apply(this._, arguments);
13370 },
13371 setFullYear: function() {
13372 d3_time_prototype.setUTCFullYear.apply(this._, arguments);
13373 },
13374 setHours: function() {
13375 d3_time_prototype.setUTCHours.apply(this._, arguments);
13376 },
13377 setMilliseconds: function() {
13378 d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
13379 },
13380 setMinutes: function() {
13381 d3_time_prototype.setUTCMinutes.apply(this._, arguments);
13382 },
13383 setMonth: function() {
13384 d3_time_prototype.setUTCMonth.apply(this._, arguments);
13385 },
13386 setSeconds: function() {
13387 d3_time_prototype.setUTCSeconds.apply(this._, arguments);
13388 },
13389 setTime: function() {
13390 d3_time_prototype.setTime.apply(this._, arguments);
13391 }
13392 };
13393 var d3_time_prototype = Date.prototype;
13394 function d3_time_interval(local, step, number) {
13395 function round(date) {
13396 var d0 = local(date), d1 = offset(d0, 1);
13397 return date - d0 < d1 - date ? d0 : d1;
13398 }
13399 function ceil(date) {
13400 step(date = local(new d3_date(date - 1)), 1);
13401 return date;
13402 }
13403 function offset(date, k) {
13404 step(date = new d3_date(+date), k);
13405 return date;
13406 }
13407 function range(t0, t1, dt) {
13408 var time = ceil(t0), times = [];
13409 if (dt > 1) {
13410 while (time < t1) {
13411 if (!(number(time) % dt)) times.push(new Date(+time));
13412 step(time, 1);
13413 }
13414 } else {
13415 while (time < t1) times.push(new Date(+time)), step(time, 1);
13416 }
13417 return times;
13418 }
13419 function range_utc(t0, t1, dt) {
13420 try {
13421 d3_date = d3_date_utc;
13422 var utc = new d3_date_utc();
13423 utc._ = t0;
13424 return range(utc, t1, dt);
13425 } finally {
13426 d3_date = Date;
13427 }
13428 }
13429 local.floor = local;
13430 local.round = round;
13431 local.ceil = ceil;
13432 local.offset = offset;
13433 local.range = range;
13434 var utc = local.utc = d3_time_interval_utc(local);
13435 utc.floor = utc;
13436 utc.round = d3_time_interval_utc(round);
13437 utc.ceil = d3_time_interval_utc(ceil);
13438 utc.offset = d3_time_interval_utc(offset);
13439 utc.range = range_utc;
13440 return local;
13441 }
13442 function d3_time_interval_utc(method) {
13443 return function(date, k) {
13444 try {
13445 d3_date = d3_date_utc;
13446 var utc = new d3_date_utc();
13447 utc._ = date;
13448 return method(utc, k)._;
13449 } finally {
13450 d3_date = Date;
13451 }
13452 };
13453 }
13454 d3_time.year = d3_time_interval(function(date) {
13455 date = d3_time.day(date);
13456 date.setMonth(0, 1);
13457 return date;
13458 }, function(date, offset) {
13459 date.setFullYear(date.getFullYear() + offset);
13460 }, function(date) {
13461 return date.getFullYear();
13462 });
13463 d3_time.years = d3_time.year.range;
13464 d3_time.years.utc = d3_time.year.utc.range;
13465 d3_time.day = d3_time_interval(function(date) {
13466 var day = new d3_date(2e3, 0);
13467 day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
13468 return day;
13469 }, function(date, offset) {
13470 date.setDate(date.getDate() + offset);
13471 }, function(date) {
13472 return date.getDate() - 1;
13473 });
13474 d3_time.days = d3_time.day.range;
13475 d3_time.days.utc = d3_time.day.utc.range;
13476 d3_time.dayOfYear = function(date) {
13477 var year = d3_time.year(date);
13478 return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
13479 };
13480 [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
13481 i = 7 - i;
13482 var interval = d3_time[day] = d3_time_interval(function(date) {
13483 (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
13484 return date;
13485 }, function(date, offset) {
13486 date.setDate(date.getDate() + Math.floor(offset) * 7);
13487 }, function(date) {
13488 var day = d3_time.year(date).getDay();
13489 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
13490 });
13491 d3_time[day + "s"] = interval.range;
13492 d3_time[day + "s"].utc = interval.utc.range;
13493 d3_time[day + "OfYear"] = function(date) {
13494 var day = d3_time.year(date).getDay();
13495 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
13496 };
13497 });
13498 d3_time.week = d3_time.sunday;
13499 d3_time.weeks = d3_time.sunday.range;
13500 d3_time.weeks.utc = d3_time.sunday.utc.range;
13501 d3_time.weekOfYear = d3_time.sundayOfYear;
13502 function d3_locale_timeFormat(locale) {
13503 var locale_dateTime = locale.dateTime, locale_date = locale.date, locale_time = locale.time, locale_periods = locale.periods, locale_days = locale.days, locale_shortDays = locale.shortDays, locale_months = locale.months, locale_shortMonths = locale.shortMonths;
13504 function d3_time_format(template) {
13505 var n = template.length;
13506 function format(date) {
13507 var string = [], i = -1, j = 0, c, p, f;
13508 while (++i < n) {
13509 if (template.charCodeAt(i) === 37) {
13510 string.push(template.slice(j, i));
13511 if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
13512 if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
13513 string.push(c);
13514 j = i + 1;
13515 }
13516 }
13517 string.push(template.slice(j, i));
13518 return string.join("");
13519 }
13520 format.parse = function(string) {
13521 var d = {
13522 y: 1900,
13523 m: 0,
13524 d: 1,
13525 H: 0,
13526 M: 0,
13527 S: 0,
13528 L: 0,
13529 Z: null
13530 }, i = d3_time_parse(d, template, string, 0);
13531 if (i != string.length) return null;
13532 if ("p" in d) d.H = d.H % 12 + d.p * 12;
13533 var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
13534 if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("W" in d || "U" in d) {
13535 if (!("w" in d)) d.w = "W" in d ? 1 : 0;
13536 date.setFullYear(d.y, 0, 1);
13537 date.setFullYear(d.y, 0, "W" in d ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 : d.w + d.U * 7 - (date.getDay() + 6) % 7);
13538 } else date.setFullYear(d.y, d.m, d.d);
13539 date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
13540 return localZ ? date._ : date;
13541 };
13542 format.toString = function() {
13543 return template;
13544 };
13545 return format;
13546 }
13547 function d3_time_parse(date, template, string, j) {
13548 var c, p, t, i = 0, n = template.length, m = string.length;
13549 while (i < n) {
13550 if (j >= m) return -1;
13551 c = template.charCodeAt(i++);
13552 if (c === 37) {
13553 t = template.charAt(i++);
13554 p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
13555 if (!p || (j = p(date, string, j)) < 0) return -1;
13556 } else if (c != string.charCodeAt(j++)) {
13557 return -1;
13558 }
13559 }
13560 return j;
13561 }
13562 d3_time_format.utc = function(template) {
13563 var local = d3_time_format(template);
13564 function format(date) {
13565 try {
13566 d3_date = d3_date_utc;
13567 var utc = new d3_date();
13568 utc._ = date;
13569 return local(utc);
13570 } finally {
13571 d3_date = Date;
13572 }
13573 }
13574 format.parse = function(string) {
13575 try {
13576 d3_date = d3_date_utc;
13577 var date = local.parse(string);
13578 return date && date._;
13579 } finally {
13580 d3_date = Date;
13581 }
13582 };
13583 format.toString = local.toString;
13584 return format;
13585 };
13586 d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
13587 var d3_time_periodLookup = d3.map(), d3_time_dayRe = d3_time_formatRe(locale_days), d3_time_dayLookup = d3_time_formatLookup(locale_days), d3_time_dayAbbrevRe = d3_time_formatRe(locale_shortDays), d3_time_dayAbbrevLookup = d3_time_formatLookup(locale_shortDays), d3_time_monthRe = d3_time_formatRe(locale_months), d3_time_monthLookup = d3_time_formatLookup(locale_months), d3_time_monthAbbrevRe = d3_time_formatRe(locale_shortMonths), d3_time_monthAbbrevLookup = d3_time_formatLookup(locale_shortMonths);
13588 locale_periods.forEach(function(p, i) {
13589 d3_time_periodLookup.set(p.toLowerCase(), i);
13590 });
13591 var d3_time_formats = {
13592 a: function(d) {
13593 return locale_shortDays[d.getDay()];
13594 },
13595 A: function(d) {
13596 return locale_days[d.getDay()];
13597 },
13598 b: function(d) {
13599 return locale_shortMonths[d.getMonth()];
13600 },
13601 B: function(d) {
13602 return locale_months[d.getMonth()];
13603 },
13604 c: d3_time_format(locale_dateTime),
13605 d: function(d, p) {
13606 return d3_time_formatPad(d.getDate(), p, 2);
13607 },
13608 e: function(d, p) {
13609 return d3_time_formatPad(d.getDate(), p, 2);
13610 },
13611 H: function(d, p) {
13612 return d3_time_formatPad(d.getHours(), p, 2);
13613 },
13614 I: function(d, p) {
13615 return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
13616 },
13617 j: function(d, p) {
13618 return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
13619 },
13620 L: function(d, p) {
13621 return d3_time_formatPad(d.getMilliseconds(), p, 3);
13622 },
13623 m: function(d, p) {
13624 return d3_time_formatPad(d.getMonth() + 1, p, 2);
13625 },
13626 M: function(d, p) {
13627 return d3_time_formatPad(d.getMinutes(), p, 2);
13628 },
13629 p: function(d) {
13630 return locale_periods[+(d.getHours() >= 12)];
13631 },
13632 S: function(d, p) {
13633 return d3_time_formatPad(d.getSeconds(), p, 2);
13634 },
13635 U: function(d, p) {
13636 return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
13637 },
13638 w: function(d) {
13639 return d.getDay();
13640 },
13641 W: function(d, p) {
13642 return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
13643 },
13644 x: d3_time_format(locale_date),
13645 X: d3_time_format(locale_time),
13646 y: function(d, p) {
13647 return d3_time_formatPad(d.getFullYear() % 100, p, 2);
13648 },
13649 Y: function(d, p) {
13650 return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
13651 },
13652 Z: d3_time_zone,
13653 "%": function() {
13654 return "%";
13655 }
13656 };
13657 var d3_time_parsers = {
13658 a: d3_time_parseWeekdayAbbrev,
13659 A: d3_time_parseWeekday,
13660 b: d3_time_parseMonthAbbrev,
13661 B: d3_time_parseMonth,
13662 c: d3_time_parseLocaleFull,
13663 d: d3_time_parseDay,
13664 e: d3_time_parseDay,
13665 H: d3_time_parseHour24,
13666 I: d3_time_parseHour24,
13667 j: d3_time_parseDayOfYear,
13668 L: d3_time_parseMilliseconds,
13669 m: d3_time_parseMonthNumber,
13670 M: d3_time_parseMinutes,
13671 p: d3_time_parseAmPm,
13672 S: d3_time_parseSeconds,
13673 U: d3_time_parseWeekNumberSunday,
13674 w: d3_time_parseWeekdayNumber,
13675 W: d3_time_parseWeekNumberMonday,
13676 x: d3_time_parseLocaleDate,
13677 X: d3_time_parseLocaleTime,
13678 y: d3_time_parseYear,
13679 Y: d3_time_parseFullYear,
13680 Z: d3_time_parseZone,
13681 "%": d3_time_parseLiteralPercent
13682 };
13683 function d3_time_parseWeekdayAbbrev(date, string, i) {
13684 d3_time_dayAbbrevRe.lastIndex = 0;
13685 var n = d3_time_dayAbbrevRe.exec(string.slice(i));
13686 return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
13687 }
13688 function d3_time_parseWeekday(date, string, i) {
13689 d3_time_dayRe.lastIndex = 0;
13690 var n = d3_time_dayRe.exec(string.slice(i));
13691 return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
13692 }
13693 function d3_time_parseMonthAbbrev(date, string, i) {
13694 d3_time_monthAbbrevRe.lastIndex = 0;
13695 var n = d3_time_monthAbbrevRe.exec(string.slice(i));
13696 return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
13697 }
13698 function d3_time_parseMonth(date, string, i) {
13699 d3_time_monthRe.lastIndex = 0;
13700 var n = d3_time_monthRe.exec(string.slice(i));
13701 return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
13702 }
13703 function d3_time_parseLocaleFull(date, string, i) {
13704 return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
13705 }
13706 function d3_time_parseLocaleDate(date, string, i) {
13707 return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
13708 }
13709 function d3_time_parseLocaleTime(date, string, i) {
13710 return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
13711 }
13712 function d3_time_parseAmPm(date, string, i) {
13713 var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
13714 return n == null ? -1 : (date.p = n, i);
13715 }
13716 return d3_time_format;
13717 }
13718 var d3_time_formatPads = {
13719 "-": "",
13720 _: " ",
13721 "0": "0"
13722 }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
13723 function d3_time_formatPad(value, fill, width) {
13724 var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
13725 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
13726 }
13727 function d3_time_formatRe(names) {
13728 return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
13729 }
13730 function d3_time_formatLookup(names) {
13731 var map = new d3_Map(), i = -1, n = names.length;
13732 while (++i < n) map.set(names[i].toLowerCase(), i);
13733 return map;
13734 }
13735 function d3_time_parseWeekdayNumber(date, string, i) {
13736 d3_time_numberRe.lastIndex = 0;
13737 var n = d3_time_numberRe.exec(string.slice(i, i + 1));
13738 return n ? (date.w = +n[0], i + n[0].length) : -1;
13739 }
13740 function d3_time_parseWeekNumberSunday(date, string, i) {
13741 d3_time_numberRe.lastIndex = 0;
13742 var n = d3_time_numberRe.exec(string.slice(i));
13743 return n ? (date.U = +n[0], i + n[0].length) : -1;
13744 }
13745 function d3_time_parseWeekNumberMonday(date, string, i) {
13746 d3_time_numberRe.lastIndex = 0;
13747 var n = d3_time_numberRe.exec(string.slice(i));
13748 return n ? (date.W = +n[0], i + n[0].length) : -1;
13749 }
13750 function d3_time_parseFullYear(date, string, i) {
13751 d3_time_numberRe.lastIndex = 0;
13752 var n = d3_time_numberRe.exec(string.slice(i, i + 4));
13753 return n ? (date.y = +n[0], i + n[0].length) : -1;
13754 }
13755 function d3_time_parseYear(date, string, i) {
13756 d3_time_numberRe.lastIndex = 0;
13757 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
13758 return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
13759 }
13760 function d3_time_parseZone(date, string, i) {
13761 return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
13762 i + 5) : -1;
13763 }
13764 function d3_time_expandYear(d) {
13765 return d + (d > 68 ? 1900 : 2e3);
13766 }
13767 function d3_time_parseMonthNumber(date, string, i) {
13768 d3_time_numberRe.lastIndex = 0;
13769 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
13770 return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
13771 }
13772 function d3_time_parseDay(date, string, i) {
13773 d3_time_numberRe.lastIndex = 0;
13774 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
13775 return n ? (date.d = +n[0], i + n[0].length) : -1;
13776 }
13777 function d3_time_parseDayOfYear(date, string, i) {
13778 d3_time_numberRe.lastIndex = 0;
13779 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
13780 return n ? (date.j = +n[0], i + n[0].length) : -1;
13781 }
13782 function d3_time_parseHour24(date, string, i) {
13783 d3_time_numberRe.lastIndex = 0;
13784 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
13785 return n ? (date.H = +n[0], i + n[0].length) : -1;
13786 }
13787 function d3_time_parseMinutes(date, string, i) {
13788 d3_time_numberRe.lastIndex = 0;
13789 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
13790 return n ? (date.M = +n[0], i + n[0].length) : -1;
13791 }
13792 function d3_time_parseSeconds(date, string, i) {
13793 d3_time_numberRe.lastIndex = 0;
13794 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
13795 return n ? (date.S = +n[0], i + n[0].length) : -1;
13796 }
13797 function d3_time_parseMilliseconds(date, string, i) {
13798 d3_time_numberRe.lastIndex = 0;
13799 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
13800 return n ? (date.L = +n[0], i + n[0].length) : -1;
13801 }
13802 function d3_time_zone(d) {
13803 var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
13804 return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
13805 }
13806 function d3_time_parseLiteralPercent(date, string, i) {
13807 d3_time_percentRe.lastIndex = 0;
13808 var n = d3_time_percentRe.exec(string.slice(i, i + 1));
13809 return n ? i + n[0].length : -1;
13810 }
13811 function d3_time_formatMulti(formats) {
13812 var n = formats.length, i = -1;
13813 while (++i < n) formats[i][0] = this(formats[i][0]);
13814 return function(date) {
13815 var i = 0, f = formats[i];
13816 while (!f[1](date)) f = formats[++i];
13817 return f[0](date);
13818 };
13819 }
13820 d3.locale = function(locale) {
13821 return {
13822 numberFormat: d3_locale_numberFormat(locale),
13823 timeFormat: d3_locale_timeFormat(locale)
13824 };
13825 };
13826 var d3_locale_enUS = d3.locale({
13827 decimal: ".",
13828 thousands: ",",
13829 grouping: [ 3 ],
13830 currency: [ "$", "" ],
13831 dateTime: "%a %b %e %X %Y",
13832 date: "%m/%d/%Y",
13833 time: "%H:%M:%S",
13834 periods: [ "AM", "PM" ],
13835 days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
13836 shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
13837 months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
13838 shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
13839 });
13840 d3.format = d3_locale_enUS.numberFormat;
13841 d3.geo = {};
13842 function d3_adder() {}
13843 d3_adder.prototype = {
13844 s: 0,
13845 t: 0,
13846 add: function(y) {
13847 d3_adderSum(y, this.t, d3_adderTemp);
13848 d3_adderSum(d3_adderTemp.s, this.s, this);
13849 if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
13850 },
13851 reset: function() {
13852 this.s = this.t = 0;
13853 },
13854 valueOf: function() {
13855 return this.s;
13856 }
13857 };
13858 var d3_adderTemp = new d3_adder();
13859 function d3_adderSum(a, b, o) {
13860 var x = o.s = a + b, bv = x - a, av = x - bv;
13861 o.t = a - av + (b - bv);
13862 }
13863 d3.geo.stream = function(object, listener) {
13864 if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
13865 d3_geo_streamObjectType[object.type](object, listener);
13866 } else {
13867 d3_geo_streamGeometry(object, listener);
13868 }
13869 };
13870 function d3_geo_streamGeometry(geometry, listener) {
13871 if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
13872 d3_geo_streamGeometryType[geometry.type](geometry, listener);
13873 }
13874 }
13875 var d3_geo_streamObjectType = {
13876 Feature: function(feature, listener) {
13877 d3_geo_streamGeometry(feature.geometry, listener);
13878 },
13879 FeatureCollection: function(object, listener) {
13880 var features = object.features, i = -1, n = features.length;
13881 while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
13882 }
13883 };
13884 var d3_geo_streamGeometryType = {
13885 Sphere: function(object, listener) {
13886 listener.sphere();
13887 },
13888 Point: function(object, listener) {
13889 object = object.coordinates;
13890 listener.point(object[0], object[1], object[2]);
13891 },
13892 MultiPoint: function(object, listener) {
13893 var coordinates = object.coordinates, i = -1, n = coordinates.length;
13894 while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
13895 },
13896 LineString: function(object, listener) {
13897 d3_geo_streamLine(object.coordinates, listener, 0);
13898 },
13899 MultiLineString: function(object, listener) {
13900 var coordinates = object.coordinates, i = -1, n = coordinates.length;
13901 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
13902 },
13903 Polygon: function(object, listener) {
13904 d3_geo_streamPolygon(object.coordinates, listener);
13905 },
13906 MultiPolygon: function(object, listener) {
13907 var coordinates = object.coordinates, i = -1, n = coordinates.length;
13908 while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
13909 },
13910 GeometryCollection: function(object, listener) {
13911 var geometries = object.geometries, i = -1, n = geometries.length;
13912 while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
13913 }
13914 };
13915 function d3_geo_streamLine(coordinates, listener, closed) {
13916 var i = -1, n = coordinates.length - closed, coordinate;
13917 listener.lineStart();
13918 while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
13919 listener.lineEnd();
13920 }
13921 function d3_geo_streamPolygon(coordinates, listener) {
13922 var i = -1, n = coordinates.length;
13923 listener.polygonStart();
13924 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
13925 listener.polygonEnd();
13926 }
13927 d3.geo.area = function(object) {
13928 d3_geo_areaSum = 0;
13929 d3.geo.stream(object, d3_geo_area);
13930 return d3_geo_areaSum;
13931 };
13932 var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
13933 var d3_geo_area = {
13934 sphere: function() {
13935 d3_geo_areaSum += 4 * π;
13936 },
13937 point: d3_noop,
13938 lineStart: d3_noop,
13939 lineEnd: d3_noop,
13940 polygonStart: function() {
13941 d3_geo_areaRingSum.reset();
13942 d3_geo_area.lineStart = d3_geo_areaRingStart;
13943 },
13944 polygonEnd: function() {
13945 var area = 2 * d3_geo_areaRingSum;
13946 d3_geo_areaSum += area < 0 ? 4 * π + area : area;
13947 d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
13948 }
13949 };
13950 function d3_geo_areaRingStart() {
13951 var λ00, φ00, λ0, cosφ0, sinφ0;
13952 d3_geo_area.point = function(λ, φ) {
13953 d3_geo_area.point = nextPoint;
13954 λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
13955 sinφ0 = Math.sin(φ);
13956 };
13957 function nextPoint(λ, φ) {
13958 λ *= d3_radians;
13959 φ = φ * d3_radians / 2 + π / 4;
13960 var dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ);
13961 d3_geo_areaRingSum.add(Math.atan2(v, u));
13962 λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
13963 }
13964 d3_geo_area.lineEnd = function() {
13965 nextPoint(λ00, φ00);
13966 };
13967 }
13968 function d3_geo_cartesian(spherical) {
13969 var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
13970 return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
13971 }
13972 function d3_geo_cartesianDot(a, b) {
13973 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
13974 }
13975 function d3_geo_cartesianCross(a, b) {
13976 return [ a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0] ];
13977 }
13978 function d3_geo_cartesianAdd(a, b) {
13979 a[0] += b[0];
13980 a[1] += b[1];
13981 a[2] += b[2];
13982 }
13983 function d3_geo_cartesianScale(vector, k) {
13984 return [ vector[0] * k, vector[1] * k, vector[2] * k ];
13985 }
13986 function d3_geo_cartesianNormalize(d) {
13987 var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
13988 d[0] /= l;
13989 d[1] /= l;
13990 d[2] /= l;
13991 }
13992 function d3_geo_spherical(cartesian) {
13993 return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
13994 }
13995 function d3_geo_sphericalEqual(a, b) {
13996 return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
13997 }
13998 d3.geo.bounds = function() {
13999 var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
14000 var bound = {
14001 point: point,
14002 lineStart: lineStart,
14003 lineEnd: lineEnd,
14004 polygonStart: function() {
14005 bound.point = ringPoint;
14006 bound.lineStart = ringStart;
14007 bound.lineEnd = ringEnd;
14008 dλSum = 0;
14009 d3_geo_area.polygonStart();
14010 },
14011 polygonEnd: function() {
14012 d3_geo_area.polygonEnd();
14013 bound.point = point;
14014 bound.lineStart = lineStart;
14015 bound.lineEnd = lineEnd;
14016 if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
14017 range[0] = λ0, range[1] = λ1;
14018 }
14019 };
14020 function point(λ, φ) {
14021 ranges.push(range = [ λ0 = λ, λ1 = λ ]);
14022 if (φ < φ0) φ0 = φ;
14023 if (φ > φ1) φ1 = φ;
14024 }
14025 function linePoint(λ, φ) {
14026 var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
14027 if (p0) {
14028 var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
14029 d3_geo_cartesianNormalize(inflection);
14030 inflection = d3_geo_spherical(inflection);
14031 var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
14032 if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
14033 var φi = inflection[1] * d3_degrees;
14034 if (φi > φ1) φ1 = φi;
14035 } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
14036 var φi = -inflection[1] * d3_degrees;
14037 if (φi < φ0) φ0 = φi;
14038 } else {
14039 if (φ < φ0) φ0 = φ;
14040 if (φ > φ1) φ1 = φ;
14041 }
14042 if (antimeridian) {
14043 if (λ < λ_) {
14044 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
14045 } else {
14046 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
14047 }
14048 } else {
14049 if (λ1 >= λ0) {
14050 if (λ < λ0) λ0 = λ;
14051 if (λ > λ1) λ1 = λ;
14052 } else {
14053 if (λ > λ_) {
14054 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
14055 } else {
14056 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
14057 }
14058 }
14059 }
14060 } else {
14061 point(λ, φ);
14062 }
14063 p0 = p, λ_ = λ;
14064 }
14065 function lineStart() {
14066 bound.point = linePoint;
14067 }
14068 function lineEnd() {
14069 range[0] = λ0, range[1] = λ1;
14070 bound.point = point;
14071 p0 = null;
14072 }
14073 function ringPoint(λ, φ) {
14074 if (p0) {
14075 var dλ = λ - λ_;
14076 dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
14077 } else λ__ = λ, φ__ = φ;
14078 d3_geo_area.point(λ, φ);
14079 linePoint(λ, φ);
14080 }
14081 function ringStart() {
14082 d3_geo_area.lineStart();
14083 }
14084 function ringEnd() {
14085 ringPoint(λ__, φ__);
14086 d3_geo_area.lineEnd();
14087 if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
14088 range[0] = λ0, range[1] = λ1;
14089 p0 = null;
14090 }
14091 function angle(λ0, λ1) {
14092 return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
14093 }
14094 function compareRanges(a, b) {
14095 return a[0] - b[0];
14096 }
14097 function withinRange(x, range) {
14098 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
14099 }
14100 return function(feature) {
14101 φ1 = λ1 = -(λ0 = φ0 = Infinity);
14102 ranges = [];
14103 d3.geo.stream(feature, bound);
14104 var n = ranges.length;
14105 if (n) {
14106 ranges.sort(compareRanges);
14107 for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
14108 b = ranges[i];
14109 if (withinRange(b[0], a) || withinRange(b[1], a)) {
14110 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
14111 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
14112 } else {
14113 merged.push(a = b);
14114 }
14115 }
14116 var best = -Infinity, dλ;
14117 for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
14118 b = merged[i];
14119 if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
14120 }
14121 }
14122 ranges = range = null;
14123 return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
14124 };
14125 }();
14126 d3.geo.centroid = function(object) {
14127 d3_geo_centroidW0 = d3_geo_centroidW1 = d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
14128 d3.geo.stream(object, d3_geo_centroid);
14129 var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
14130 if (m < ε2) {
14131 x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
14132 if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
14133 m = x * x + y * y + z * z;
14134 if (m < ε2) return [ NaN, NaN ];
14135 }
14136 return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
14137 };
14138 var d3_geo_centroidW0, d3_geo_centroidW1, d3_geo_centroidX0, d3_geo_centroidY0, d3_geo_centroidZ0, d3_geo_centroidX1, d3_geo_centroidY1, d3_geo_centroidZ1, d3_geo_centroidX2, d3_geo_centroidY2, d3_geo_centroidZ2;
14139 var d3_geo_centroid = {
14140 sphere: d3_noop,
14141 point: d3_geo_centroidPoint,
14142 lineStart: d3_geo_centroidLineStart,
14143 lineEnd: d3_geo_centroidLineEnd,
14144 polygonStart: function() {
14145 d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
14146 },
14147 polygonEnd: function() {
14148 d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
14149 }
14150 };
14151 function d3_geo_centroidPoint(λ, φ) {
14152 λ *= d3_radians;
14153 var cosφ = Math.cos(φ *= d3_radians);
14154 d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
14155 }
14156 function d3_geo_centroidPointXYZ(x, y, z) {
14157 ++d3_geo_centroidW0;
14158 d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
14159 d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
14160 d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
14161 }
14162 function d3_geo_centroidLineStart() {
14163 var x0, y0, z0;
14164 d3_geo_centroid.point = function(λ, φ) {
14165 λ *= d3_radians;
14166 var cosφ = Math.cos(φ *= d3_radians);
14167 x0 = cosφ * Math.cos(λ);
14168 y0 = cosφ * Math.sin(λ);
14169 z0 = Math.sin(φ);
14170 d3_geo_centroid.point = nextPoint;
14171 d3_geo_centroidPointXYZ(x0, y0, z0);
14172 };
14173 function nextPoint(λ, φ) {
14174 λ *= d3_radians;
14175 var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), w = Math.atan2(Math.sqrt((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
14176 d3_geo_centroidW1 += w;
14177 d3_geo_centroidX1 += w * (x0 + (x0 = x));
14178 d3_geo_centroidY1 += w * (y0 + (y0 = y));
14179 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
14180 d3_geo_centroidPointXYZ(x0, y0, z0);
14181 }
14182 }
14183 function d3_geo_centroidLineEnd() {
14184 d3_geo_centroid.point = d3_geo_centroidPoint;
14185 }
14186 function d3_geo_centroidRingStart() {
14187 var λ00, φ00, x0, y0, z0;
14188 d3_geo_centroid.point = function(λ, φ) {
14189 λ00 = λ, φ00 = φ;
14190 d3_geo_centroid.point = nextPoint;
14191 λ *= d3_radians;
14192 var cosφ = Math.cos(φ *= d3_radians);
14193 x0 = cosφ * Math.cos(λ);
14194 y0 = cosφ * Math.sin(λ);
14195 z0 = Math.sin(φ);
14196 d3_geo_centroidPointXYZ(x0, y0, z0);
14197 };
14198 d3_geo_centroid.lineEnd = function() {
14199 nextPoint(λ00, φ00);
14200 d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
14201 d3_geo_centroid.point = d3_geo_centroidPoint;
14202 };
14203 function nextPoint(λ, φ) {
14204 λ *= d3_radians;
14205 var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), cx = y0 * z - z0 * y, cy = z0 * x - x0 * z, cz = x0 * y - y0 * x, m = Math.sqrt(cx * cx + cy * cy + cz * cz), u = x0 * x + y0 * y + z0 * z, v = m && -d3_acos(u) / m, w = Math.atan2(m, u);
14206 d3_geo_centroidX2 += v * cx;
14207 d3_geo_centroidY2 += v * cy;
14208 d3_geo_centroidZ2 += v * cz;
14209 d3_geo_centroidW1 += w;
14210 d3_geo_centroidX1 += w * (x0 + (x0 = x));
14211 d3_geo_centroidY1 += w * (y0 + (y0 = y));
14212 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
14213 d3_geo_centroidPointXYZ(x0, y0, z0);
14214 }
14215 }
14216 function d3_geo_compose(a, b) {
14217 function compose(x, y) {
14218 return x = a(x, y), b(x[0], x[1]);
14219 }
14220 if (a.invert && b.invert) compose.invert = function(x, y) {
14221 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
14222 };
14223 return compose;
14224 }
14225 function d3_true() {
14226 return true;
14227 }
14228 function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
14229 var subject = [], clip = [];
14230 segments.forEach(function(segment) {
14231 if ((n = segment.length - 1) <= 0) return;
14232 var n, p0 = segment[0], p1 = segment[n];
14233 if (d3_geo_sphericalEqual(p0, p1)) {
14234 listener.lineStart();
14235 for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
14236 listener.lineEnd();
14237 return;
14238 }
14239 var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
14240 a.o = b;
14241 subject.push(a);
14242 clip.push(b);
14243 a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
14244 b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
14245 a.o = b;
14246 subject.push(a);
14247 clip.push(b);
14248 });
14249 clip.sort(compare);
14250 d3_geo_clipPolygonLinkCircular(subject);
14251 d3_geo_clipPolygonLinkCircular(clip);
14252 if (!subject.length) return;
14253 for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
14254 clip[i].e = entry = !entry;
14255 }
14256 var start = subject[0], points, point;
14257 while (1) {
14258 var current = start, isSubject = true;
14259 while (current.v) if ((current = current.n) === start) return;
14260 points = current.z;
14261 listener.lineStart();
14262 do {
14263 current.v = current.o.v = true;
14264 if (current.e) {
14265 if (isSubject) {
14266 for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
14267 } else {
14268 interpolate(current.x, current.n.x, 1, listener);
14269 }
14270 current = current.n;
14271 } else {
14272 if (isSubject) {
14273 points = current.p.z;
14274 for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
14275 } else {
14276 interpolate(current.x, current.p.x, -1, listener);
14277 }
14278 current = current.p;
14279 }
14280 current = current.o;
14281 points = current.z;
14282 isSubject = !isSubject;
14283 } while (!current.v);
14284 listener.lineEnd();
14285 }
14286 }
14287 function d3_geo_clipPolygonLinkCircular(array) {
14288 if (!(n = array.length)) return;
14289 var n, i = 0, a = array[0], b;
14290 while (++i < n) {
14291 a.n = b = array[i];
14292 b.p = a;
14293 a = b;
14294 }
14295 a.n = b = array[0];
14296 b.p = a;
14297 }
14298 function d3_geo_clipPolygonIntersection(point, points, other, entry) {
14299 this.x = point;
14300 this.z = points;
14301 this.o = other;
14302 this.e = entry;
14303 this.v = false;
14304 this.n = this.p = null;
14305 }
14306 function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
14307 return function(rotate, listener) {
14308 var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
14309 var clip = {
14310 point: point,
14311 lineStart: lineStart,
14312 lineEnd: lineEnd,
14313 polygonStart: function() {
14314 clip.point = pointRing;
14315 clip.lineStart = ringStart;
14316 clip.lineEnd = ringEnd;
14317 segments = [];
14318 polygon = [];
14319 },
14320 polygonEnd: function() {
14321 clip.point = point;
14322 clip.lineStart = lineStart;
14323 clip.lineEnd = lineEnd;
14324 segments = d3.merge(segments);
14325 var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
14326 if (segments.length) {
14327 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
14328 d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
14329 } else if (clipStartInside) {
14330 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
14331 listener.lineStart();
14332 interpolate(null, null, 1, listener);
14333 listener.lineEnd();
14334 }
14335 if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
14336 segments = polygon = null;
14337 },
14338 sphere: function() {
14339 listener.polygonStart();
14340 listener.lineStart();
14341 interpolate(null, null, 1, listener);
14342 listener.lineEnd();
14343 listener.polygonEnd();
14344 }
14345 };
14346 function point(λ, φ) {
14347 var point = rotate(λ, φ);
14348 if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
14349 }
14350 function pointLine(λ, φ) {
14351 var point = rotate(λ, φ);
14352 line.point(point[0], point[1]);
14353 }
14354 function lineStart() {
14355 clip.point = pointLine;
14356 line.lineStart();
14357 }
14358 function lineEnd() {
14359 clip.point = point;
14360 line.lineEnd();
14361 }
14362 var segments;
14363 var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
14364 function pointRing(λ, φ) {
14365 ring.push([ λ, φ ]);
14366 var point = rotate(λ, φ);
14367 ringListener.point(point[0], point[1]);
14368 }
14369 function ringStart() {
14370 ringListener.lineStart();
14371 ring = [];
14372 }
14373 function ringEnd() {
14374 pointRing(ring[0][0], ring[0][1]);
14375 ringListener.lineEnd();
14376 var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
14377 ring.pop();
14378 polygon.push(ring);
14379 ring = null;
14380 if (!n) return;
14381 if (clean & 1) {
14382 segment = ringSegments[0];
14383 var n = segment.length - 1, i = -1, point;
14384 if (n > 0) {
14385 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
14386 listener.lineStart();
14387 while (++i < n) listener.point((point = segment[i])[0], point[1]);
14388 listener.lineEnd();
14389 }
14390 return;
14391 }
14392 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
14393 segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
14394 }
14395 return clip;
14396 };
14397 }
14398 function d3_geo_clipSegmentLength1(segment) {
14399 return segment.length > 1;
14400 }
14401 function d3_geo_clipBufferListener() {
14402 var lines = [], line;
14403 return {
14404 lineStart: function() {
14405 lines.push(line = []);
14406 },
14407 point: function(λ, φ) {
14408 line.push([ λ, φ ]);
14409 },
14410 lineEnd: d3_noop,
14411 buffer: function() {
14412 var buffer = lines;
14413 lines = [];
14414 line = null;
14415 return buffer;
14416 },
14417 rejoin: function() {
14418 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
14419 }
14420 };
14421 }
14422 function d3_geo_clipSort(a, b) {
14423 return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
14424 }
14425 var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
14426 function d3_geo_clipAntimeridianLine(listener) {
14427 var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
14428 return {
14429 lineStart: function() {
14430 listener.lineStart();
14431 clean = 1;
14432 },
14433 point: function(λ1, φ1) {
14434 var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
14435 if (abs(dλ - π) < ε) {
14436 listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
14437 listener.point(sλ0, φ0);
14438 listener.lineEnd();
14439 listener.lineStart();
14440 listener.point(sλ1, φ0);
14441 listener.point(λ1, φ0);
14442 clean = 0;
14443 } else if (sλ0 !== sλ1 && dλ >= π) {
14444 if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
14445 if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
14446 φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
14447 listener.point(sλ0, φ0);
14448 listener.lineEnd();
14449 listener.lineStart();
14450 listener.point(sλ1, φ0);
14451 clean = 0;
14452 }
14453 listener.point(λ0 = λ1, φ0 = φ1);
14454 sλ0 = sλ1;
14455 },
14456 lineEnd: function() {
14457 listener.lineEnd();
14458 λ0 = φ0 = NaN;
14459 },
14460 clean: function() {
14461 return 2 - clean;
14462 }
14463 };
14464 }
14465 function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
14466 var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
14467 return abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;
14468 }
14469 function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
14470 var φ;
14471 if (from == null) {
14472 φ = direction * halfπ;
14473 listener.point(-π, φ);
14474 listener.point(0, φ);
14475 listener.point(π, φ);
14476 listener.point(π, 0);
14477 listener.point(π, -φ);
14478 listener.point(0, -φ);
14479 listener.point(-π, -φ);
14480 listener.point(-π, 0);
14481 listener.point(-π, φ);
14482 } else if (abs(from[0] - to[0]) > ε) {
14483 var s = from[0] < to[0] ? π : -π;
14484 φ = direction * s / 2;
14485 listener.point(-s, φ);
14486 listener.point(0, φ);
14487 listener.point(s, φ);
14488 } else {
14489 listener.point(to[0], to[1]);
14490 }
14491 }
14492 function d3_geo_pointInPolygon(point, polygon) {
14493 var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
14494 d3_geo_areaRingSum.reset();
14495 for (var i = 0, n = polygon.length; i < n; ++i) {
14496 var ring = polygon[i], m = ring.length;
14497 if (!m) continue;
14498 var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
14499 while (true) {
14500 if (j === m) j = 0;
14501 point = ring[j];
14502 var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ;
14503 d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
14504 polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
14505 if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
14506 var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
14507 d3_geo_cartesianNormalize(arc);
14508 var intersection = d3_geo_cartesianCross(meridianNormal, arc);
14509 d3_geo_cartesianNormalize(intersection);
14510 var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
14511 if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
14512 winding += antimeridian ^ dλ >= 0 ? 1 : -1;
14513 }
14514 }
14515 if (!j++) break;
14516 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
14517 }
14518 }
14519 return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < -ε) ^ winding & 1;
14520 }
14521 function d3_geo_clipCircle(radius) {
14522 var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
14523 return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
14524 function visible(λ, φ) {
14525 return Math.cos(λ) * Math.cos(φ) > cr;
14526 }
14527 function clipLine(listener) {
14528 var point0, c0, v0, v00, clean;
14529 return {
14530 lineStart: function() {
14531 v00 = v0 = false;
14532 clean = 1;
14533 },
14534 point: function(λ, φ) {
14535 var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
14536 if (!point0 && (v00 = v0 = v)) listener.lineStart();
14537 if (v !== v0) {
14538 point2 = intersect(point0, point1);
14539 if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
14540 point1[0] += ε;
14541 point1[1] += ε;
14542 v = visible(point1[0], point1[1]);
14543 }
14544 }
14545 if (v !== v0) {
14546 clean = 0;
14547 if (v) {
14548 listener.lineStart();
14549 point2 = intersect(point1, point0);
14550 listener.point(point2[0], point2[1]);
14551 } else {
14552 point2 = intersect(point0, point1);
14553 listener.point(point2[0], point2[1]);
14554 listener.lineEnd();
14555 }
14556 point0 = point2;
14557 } else if (notHemisphere && point0 && smallRadius ^ v) {
14558 var t;
14559 if (!(c & c0) && (t = intersect(point1, point0, true))) {
14560 clean = 0;
14561 if (smallRadius) {
14562 listener.lineStart();
14563 listener.point(t[0][0], t[0][1]);
14564 listener.point(t[1][0], t[1][1]);
14565 listener.lineEnd();
14566 } else {
14567 listener.point(t[1][0], t[1][1]);
14568 listener.lineEnd();
14569 listener.lineStart();
14570 listener.point(t[0][0], t[0][1]);
14571 }
14572 }
14573 }
14574 if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
14575 listener.point(point1[0], point1[1]);
14576 }
14577 point0 = point1, v0 = v, c0 = c;
14578 },
14579 lineEnd: function() {
14580 if (v0) listener.lineEnd();
14581 point0 = null;
14582 },
14583 clean: function() {
14584 return clean | (v00 && v0) << 1;
14585 }
14586 };
14587 }
14588 function intersect(a, b, two) {
14589 var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
14590 var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
14591 if (!determinant) return !two && a;
14592 var c1 = cr * n2n2 / determinant, c2 = -cr * n1n2 / determinant, n1xn2 = d3_geo_cartesianCross(n1, n2), A = d3_geo_cartesianScale(n1, c1), B = d3_geo_cartesianScale(n2, c2);
14593 d3_geo_cartesianAdd(A, B);
14594 var u = n1xn2, w = d3_geo_cartesianDot(A, u), uu = d3_geo_cartesianDot(u, u), t2 = w * w - uu * (d3_geo_cartesianDot(A, A) - 1);
14595 if (t2 < 0) return;
14596 var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
14597 d3_geo_cartesianAdd(q, A);
14598 q = d3_geo_spherical(q);
14599 if (!two) return q;
14600 var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
14601 if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
14602 var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
14603 if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
14604 if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
14605 var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
14606 d3_geo_cartesianAdd(q1, A);
14607 return [ q, d3_geo_spherical(q1) ];
14608 }
14609 }
14610 function code(λ, φ) {
14611 var r = smallRadius ? radius : π - radius, code = 0;
14612 if (λ < -r) code |= 1; else if (λ > r) code |= 2;
14613 if (φ < -r) code |= 4; else if (φ > r) code |= 8;
14614 return code;
14615 }
14616 }
14617 function d3_geom_clipLine(x0, y0, x1, y1) {
14618 return function(line) {
14619 var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r;
14620 r = x0 - ax;
14621 if (!dx && r > 0) return;
14622 r /= dx;
14623 if (dx < 0) {
14624 if (r < t0) return;
14625 if (r < t1) t1 = r;
14626 } else if (dx > 0) {
14627 if (r > t1) return;
14628 if (r > t0) t0 = r;
14629 }
14630 r = x1 - ax;
14631 if (!dx && r < 0) return;
14632 r /= dx;
14633 if (dx < 0) {
14634 if (r > t1) return;
14635 if (r > t0) t0 = r;
14636 } else if (dx > 0) {
14637 if (r < t0) return;
14638 if (r < t1) t1 = r;
14639 }
14640 r = y0 - ay;
14641 if (!dy && r > 0) return;
14642 r /= dy;
14643 if (dy < 0) {
14644 if (r < t0) return;
14645 if (r < t1) t1 = r;
14646 } else if (dy > 0) {
14647 if (r > t1) return;
14648 if (r > t0) t0 = r;
14649 }
14650 r = y1 - ay;
14651 if (!dy && r < 0) return;
14652 r /= dy;
14653 if (dy < 0) {
14654 if (r > t1) return;
14655 if (r > t0) t0 = r;
14656 } else if (dy > 0) {
14657 if (r < t0) return;
14658 if (r < t1) t1 = r;
14659 }
14660 if (t0 > 0) line.a = {
14661 x: ax + t0 * dx,
14662 y: ay + t0 * dy
14663 };
14664 if (t1 < 1) line.b = {
14665 x: ax + t1 * dx,
14666 y: ay + t1 * dy
14667 };
14668 return line;
14669 };
14670 }
14671 var d3_geo_clipExtentMAX = 1e9;
14672 d3.geo.clipExtent = function() {
14673 var x0, y0, x1, y1, stream, clip, clipExtent = {
14674 stream: function(output) {
14675 if (stream) stream.valid = false;
14676 stream = clip(output);
14677 stream.valid = true;
14678 return stream;
14679 },
14680 extent: function(_) {
14681 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
14682 clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
14683 if (stream) stream.valid = false, stream = null;
14684 return clipExtent;
14685 }
14686 };
14687 return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
14688 };
14689 function d3_geo_clipExtent(x0, y0, x1, y1) {
14690 return function(listener) {
14691 var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
14692 var clip = {
14693 point: point,
14694 lineStart: lineStart,
14695 lineEnd: lineEnd,
14696 polygonStart: function() {
14697 listener = bufferListener;
14698 segments = [];
14699 polygon = [];
14700 clean = true;
14701 },
14702 polygonEnd: function() {
14703 listener = listener_;
14704 segments = d3.merge(segments);
14705 var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
14706 if (inside || visible) {
14707 listener.polygonStart();
14708 if (inside) {
14709 listener.lineStart();
14710 interpolate(null, null, 1, listener);
14711 listener.lineEnd();
14712 }
14713 if (visible) {
14714 d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
14715 }
14716 listener.polygonEnd();
14717 }
14718 segments = polygon = ring = null;
14719 }
14720 };
14721 function insidePolygon(p) {
14722 var wn = 0, n = polygon.length, y = p[1];
14723 for (var i = 0; i < n; ++i) {
14724 for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
14725 b = v[j];
14726 if (a[1] <= y) {
14727 if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
14728 } else {
14729 if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
14730 }
14731 a = b;
14732 }
14733 }
14734 return wn !== 0;
14735 }
14736 function interpolate(from, to, direction, listener) {
14737 var a = 0, a1 = 0;
14738 if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
14739 do {
14740 listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
14741 } while ((a = (a + direction + 4) % 4) !== a1);
14742 } else {
14743 listener.point(to[0], to[1]);
14744 }
14745 }
14746 function pointVisible(x, y) {
14747 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
14748 }
14749 function point(x, y) {
14750 if (pointVisible(x, y)) listener.point(x, y);
14751 }
14752 var x__, y__, v__, x_, y_, v_, first, clean;
14753 function lineStart() {
14754 clip.point = linePoint;
14755 if (polygon) polygon.push(ring = []);
14756 first = true;
14757 v_ = false;
14758 x_ = y_ = NaN;
14759 }
14760 function lineEnd() {
14761 if (segments) {
14762 linePoint(x__, y__);
14763 if (v__ && v_) bufferListener.rejoin();
14764 segments.push(bufferListener.buffer());
14765 }
14766 clip.point = point;
14767 if (v_) listener.lineEnd();
14768 }
14769 function linePoint(x, y) {
14770 x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
14771 y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
14772 var v = pointVisible(x, y);
14773 if (polygon) ring.push([ x, y ]);
14774 if (first) {
14775 x__ = x, y__ = y, v__ = v;
14776 first = false;
14777 if (v) {
14778 listener.lineStart();
14779 listener.point(x, y);
14780 }
14781 } else {
14782 if (v && v_) listener.point(x, y); else {
14783 var l = {
14784 a: {
14785 x: x_,
14786 y: y_
14787 },
14788 b: {
14789 x: x,
14790 y: y
14791 }
14792 };
14793 if (clipLine(l)) {
14794 if (!v_) {
14795 listener.lineStart();
14796 listener.point(l.a.x, l.a.y);
14797 }
14798 listener.point(l.b.x, l.b.y);
14799 if (!v) listener.lineEnd();
14800 clean = false;
14801 } else if (v) {
14802 listener.lineStart();
14803 listener.point(x, y);
14804 clean = false;
14805 }
14806 }
14807 }
14808 x_ = x, y_ = y, v_ = v;
14809 }
14810 return clip;
14811 };
14812 function corner(p, direction) {
14813 return abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
14814 }
14815 function compare(a, b) {
14816 return comparePoints(a.x, b.x);
14817 }
14818 function comparePoints(a, b) {
14819 var ca = corner(a, 1), cb = corner(b, 1);
14820 return ca !== cb ? ca - cb : ca === 0 ? b[1] - a[1] : ca === 1 ? a[0] - b[0] : ca === 2 ? a[1] - b[1] : b[0] - a[0];
14821 }
14822 }
14823 function d3_geo_conic(projectAt) {
14824 var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
14825 p.parallels = function(_) {
14826 if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
14827 return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
14828 };
14829 return p;
14830 }
14831 function d3_geo_conicEqualArea(φ0, φ1) {
14832 var sinφ0 = Math.sin(φ0), n = (sinφ0 + Math.sin(φ1)) / 2, C = 1 + sinφ0 * (2 * n - sinφ0), ρ0 = Math.sqrt(C) / n;
14833 function forward(λ, φ) {
14834 var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
14835 return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
14836 }
14837 forward.invert = function(x, y) {
14838 var ρ0_y = ρ0 - y;
14839 return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
14840 };
14841 return forward;
14842 }
14843 (d3.geo.conicEqualArea = function() {
14844 return d3_geo_conic(d3_geo_conicEqualArea);
14845 }).raw = d3_geo_conicEqualArea;
14846 d3.geo.albers = function() {
14847 return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
14848 };
14849 d3.geo.albersUsa = function() {
14850 var lower48 = d3.geo.albers();
14851 var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
14852 var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
14853 var point, pointStream = {
14854 point: function(x, y) {
14855 point = [ x, y ];
14856 }
14857 }, lower48Point, alaskaPoint, hawaiiPoint;
14858 function albersUsa(coordinates) {
14859 var x = coordinates[0], y = coordinates[1];
14860 point = null;
14861 (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
14862 return point;
14863 }
14864 albersUsa.invert = function(coordinates) {
14865 var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
14866 return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
14867 };
14868 albersUsa.stream = function(stream) {
14869 var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
14870 return {
14871 point: function(x, y) {
14872 lower48Stream.point(x, y);
14873 alaskaStream.point(x, y);
14874 hawaiiStream.point(x, y);
14875 },
14876 sphere: function() {
14877 lower48Stream.sphere();
14878 alaskaStream.sphere();
14879 hawaiiStream.sphere();
14880 },
14881 lineStart: function() {
14882 lower48Stream.lineStart();
14883 alaskaStream.lineStart();
14884 hawaiiStream.lineStart();
14885 },
14886 lineEnd: function() {
14887 lower48Stream.lineEnd();
14888 alaskaStream.lineEnd();
14889 hawaiiStream.lineEnd();
14890 },
14891 polygonStart: function() {
14892 lower48Stream.polygonStart();
14893 alaskaStream.polygonStart();
14894 hawaiiStream.polygonStart();
14895 },
14896 polygonEnd: function() {
14897 lower48Stream.polygonEnd();
14898 alaskaStream.polygonEnd();
14899 hawaiiStream.polygonEnd();
14900 }
14901 };
14902 };
14903 albersUsa.precision = function(_) {
14904 if (!arguments.length) return lower48.precision();
14905 lower48.precision(_);
14906 alaska.precision(_);
14907 hawaii.precision(_);
14908 return albersUsa;
14909 };
14910 albersUsa.scale = function(_) {
14911 if (!arguments.length) return lower48.scale();
14912 lower48.scale(_);
14913 alaska.scale(_ * .35);
14914 hawaii.scale(_);
14915 return albersUsa.translate(lower48.translate());
14916 };
14917 albersUsa.translate = function(_) {
14918 if (!arguments.length) return lower48.translate();
14919 var k = lower48.scale(), x = +_[0], y = +_[1];
14920 lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
14921 alaskaPoint = alaska.translate([ x - .307 * k, y + .201 * k ]).clipExtent([ [ x - .425 * k + ε, y + .12 * k + ε ], [ x - .214 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
14922 hawaiiPoint = hawaii.translate([ x - .205 * k, y + .212 * k ]).clipExtent([ [ x - .214 * k + ε, y + .166 * k + ε ], [ x - .115 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
14923 return albersUsa;
14924 };
14925 return albersUsa.scale(1070);
14926 };
14927 var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
14928 point: d3_noop,
14929 lineStart: d3_noop,
14930 lineEnd: d3_noop,
14931 polygonStart: function() {
14932 d3_geo_pathAreaPolygon = 0;
14933 d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
14934 },
14935 polygonEnd: function() {
14936 d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
14937 d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
14938 }
14939 };
14940 function d3_geo_pathAreaRingStart() {
14941 var x00, y00, x0, y0;
14942 d3_geo_pathArea.point = function(x, y) {
14943 d3_geo_pathArea.point = nextPoint;
14944 x00 = x0 = x, y00 = y0 = y;
14945 };
14946 function nextPoint(x, y) {
14947 d3_geo_pathAreaPolygon += y0 * x - x0 * y;
14948 x0 = x, y0 = y;
14949 }
14950 d3_geo_pathArea.lineEnd = function() {
14951 nextPoint(x00, y00);
14952 };
14953 }
14954 var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
14955 var d3_geo_pathBounds = {
14956 point: d3_geo_pathBoundsPoint,
14957 lineStart: d3_noop,
14958 lineEnd: d3_noop,
14959 polygonStart: d3_noop,
14960 polygonEnd: d3_noop
14961 };
14962 function d3_geo_pathBoundsPoint(x, y) {
14963 if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
14964 if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
14965 if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
14966 if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
14967 }
14968 function d3_geo_pathBuffer() {
14969 var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
14970 var stream = {
14971 point: point,
14972 lineStart: function() {
14973 stream.point = pointLineStart;
14974 },
14975 lineEnd: lineEnd,
14976 polygonStart: function() {
14977 stream.lineEnd = lineEndPolygon;
14978 },
14979 polygonEnd: function() {
14980 stream.lineEnd = lineEnd;
14981 stream.point = point;
14982 },
14983 pointRadius: function(_) {
14984 pointCircle = d3_geo_pathBufferCircle(_);
14985 return stream;
14986 },
14987 result: function() {
14988 if (buffer.length) {
14989 var result = buffer.join("");
14990 buffer = [];
14991 return result;
14992 }
14993 }
14994 };
14995 function point(x, y) {
14996 buffer.push("M", x, ",", y, pointCircle);
14997 }
14998 function pointLineStart(x, y) {
14999 buffer.push("M", x, ",", y);
15000 stream.point = pointLine;
15001 }
15002 function pointLine(x, y) {
15003 buffer.push("L", x, ",", y);
15004 }
15005 function lineEnd() {
15006 stream.point = point;
15007 }
15008 function lineEndPolygon() {
15009 buffer.push("Z");
15010 }
15011 return stream;
15012 }
15013 function d3_geo_pathBufferCircle(radius) {
15014 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
15015 }
15016 var d3_geo_pathCentroid = {
15017 point: d3_geo_pathCentroidPoint,
15018 lineStart: d3_geo_pathCentroidLineStart,
15019 lineEnd: d3_geo_pathCentroidLineEnd,
15020 polygonStart: function() {
15021 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
15022 },
15023 polygonEnd: function() {
15024 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
15025 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
15026 d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
15027 }
15028 };
15029 function d3_geo_pathCentroidPoint(x, y) {
15030 d3_geo_centroidX0 += x;
15031 d3_geo_centroidY0 += y;
15032 ++d3_geo_centroidZ0;
15033 }
15034 function d3_geo_pathCentroidLineStart() {
15035 var x0, y0;
15036 d3_geo_pathCentroid.point = function(x, y) {
15037 d3_geo_pathCentroid.point = nextPoint;
15038 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
15039 };
15040 function nextPoint(x, y) {
15041 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
15042 d3_geo_centroidX1 += z * (x0 + x) / 2;
15043 d3_geo_centroidY1 += z * (y0 + y) / 2;
15044 d3_geo_centroidZ1 += z;
15045 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
15046 }
15047 }
15048 function d3_geo_pathCentroidLineEnd() {
15049 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
15050 }
15051 function d3_geo_pathCentroidRingStart() {
15052 var x00, y00, x0, y0;
15053 d3_geo_pathCentroid.point = function(x, y) {
15054 d3_geo_pathCentroid.point = nextPoint;
15055 d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
15056 };
15057 function nextPoint(x, y) {
15058 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
15059 d3_geo_centroidX1 += z * (x0 + x) / 2;
15060 d3_geo_centroidY1 += z * (y0 + y) / 2;
15061 d3_geo_centroidZ1 += z;
15062 z = y0 * x - x0 * y;
15063 d3_geo_centroidX2 += z * (x0 + x);
15064 d3_geo_centroidY2 += z * (y0 + y);
15065 d3_geo_centroidZ2 += z * 3;
15066 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
15067 }
15068 d3_geo_pathCentroid.lineEnd = function() {
15069 nextPoint(x00, y00);
15070 };
15071 }
15072 function d3_geo_pathContext(context) {
15073 var pointRadius = 4.5;
15074 var stream = {
15075 point: point,
15076 lineStart: function() {
15077 stream.point = pointLineStart;
15078 },
15079 lineEnd: lineEnd,
15080 polygonStart: function() {
15081 stream.lineEnd = lineEndPolygon;
15082 },
15083 polygonEnd: function() {
15084 stream.lineEnd = lineEnd;
15085 stream.point = point;
15086 },
15087 pointRadius: function(_) {
15088 pointRadius = _;
15089 return stream;
15090 },
15091 result: d3_noop
15092 };
15093 function point(x, y) {
15094 context.moveTo(x + pointRadius, y);
15095 context.arc(x, y, pointRadius, 0, τ);
15096 }
15097 function pointLineStart(x, y) {
15098 context.moveTo(x, y);
15099 stream.point = pointLine;
15100 }
15101 function pointLine(x, y) {
15102 context.lineTo(x, y);
15103 }
15104 function lineEnd() {
15105 stream.point = point;
15106 }
15107 function lineEndPolygon() {
15108 context.closePath();
15109 }
15110 return stream;
15111 }
15112 function d3_geo_resample(project) {
15113 var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
15114 function resample(stream) {
15115 return (maxDepth ? resampleRecursive : resampleNone)(stream);
15116 }
15117 function resampleNone(stream) {
15118 return d3_geo_transformPoint(stream, function(x, y) {
15119 x = project(x, y);
15120 stream.point(x[0], x[1]);
15121 });
15122 }
15123 function resampleRecursive(stream) {
15124 var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
15125 var resample = {
15126 point: point,
15127 lineStart: lineStart,
15128 lineEnd: lineEnd,
15129 polygonStart: function() {
15130 stream.polygonStart();
15131 resample.lineStart = ringStart;
15132 },
15133 polygonEnd: function() {
15134 stream.polygonEnd();
15135 resample.lineStart = lineStart;
15136 }
15137 };
15138 function point(x, y) {
15139 x = project(x, y);
15140 stream.point(x[0], x[1]);
15141 }
15142 function lineStart() {
15143 x0 = NaN;
15144 resample.point = linePoint;
15145 stream.lineStart();
15146 }
15147 function linePoint(λ, φ) {
15148 var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
15149 resampleLineTo(x0, y0, λ0, a0, b0, c0, x0 = p[0], y0 = p[1], λ0 = λ, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
15150 stream.point(x0, y0);
15151 }
15152 function lineEnd() {
15153 resample.point = point;
15154 stream.lineEnd();
15155 }
15156 function ringStart() {
15157 lineStart();
15158 resample.point = ringPoint;
15159 resample.lineEnd = ringEnd;
15160 }
15161 function ringPoint(λ, φ) {
15162 linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
15163 resample.point = linePoint;
15164 }
15165 function ringEnd() {
15166 resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
15167 resample.lineEnd = lineEnd;
15168 lineEnd();
15169 }
15170 return resample;
15171 }
15172 function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
15173 var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
15174 if (d2 > 4 * δ2 && depth--) {
15175 var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = abs(abs(c) - 1) < ε || abs0 - λ1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
15176 if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
15177 resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
15178 stream.point(x2, y2);
15179 resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
15180 }
15181 }
15182 }
15183 resample.precision = function(_) {
15184 if (!arguments.length) return Math.sqrt(δ2);
15185 maxDepth = (δ2 = _ * _) > 0 && 16;
15186 return resample;
15187 };
15188 return resample;
15189 }
15190 d3.geo.path = function() {
15191 var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
15192 function path(object) {
15193 if (object) {
15194 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
15195 if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
15196 d3.geo.stream(object, cacheStream);
15197 }
15198 return contextStream.result();
15199 }
15200 path.area = function(object) {
15201 d3_geo_pathAreaSum = 0;
15202 d3.geo.stream(object, projectStream(d3_geo_pathArea));
15203 return d3_geo_pathAreaSum;
15204 };
15205 path.centroid = function(object) {
15206 d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
15207 d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
15208 return d3_geo_centroidZ2 ? [ d3_geo_centroidX2 / d3_geo_centroidZ2, d3_geo_centroidY2 / d3_geo_centroidZ2 ] : d3_geo_centroidZ1 ? [ d3_geo_centroidX1 / d3_geo_centroidZ1, d3_geo_centroidY1 / d3_geo_centroidZ1 ] : d3_geo_centroidZ0 ? [ d3_geo_centroidX0 / d3_geo_centroidZ0, d3_geo_centroidY0 / d3_geo_centroidZ0 ] : [ NaN, NaN ];
15209 };
15210 path.bounds = function(object) {
15211 d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
15212 d3.geo.stream(object, projectStream(d3_geo_pathBounds));
15213 return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
15214 };
15215 path.projection = function(_) {
15216 if (!arguments.length) return projection;
15217 projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
15218 return reset();
15219 };
15220 path.context = function(_) {
15221 if (!arguments.length) return context;
15222 contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
15223 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
15224 return reset();
15225 };
15226 path.pointRadius = function(_) {
15227 if (!arguments.length) return pointRadius;
15228 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
15229 return path;
15230 };
15231 function reset() {
15232 cacheStream = null;
15233 return path;
15234 }
15235 return path.projection(d3.geo.albersUsa()).context(null);
15236 };
15237 function d3_geo_pathProjectStream(project) {
15238 var resample = d3_geo_resample(function(x, y) {
15239 return project([ x * d3_degrees, y * d3_degrees ]);
15240 });
15241 return function(stream) {
15242 return d3_geo_projectionRadians(resample(stream));
15243 };
15244 }
15245 d3.geo.transform = function(methods) {
15246 return {
15247 stream: function(stream) {
15248 var transform = new d3_geo_transform(stream);
15249 for (var k in methods) transform[k] = methods[k];
15250 return transform;
15251 }
15252 };
15253 };
15254 function d3_geo_transform(stream) {
15255 this.stream = stream;
15256 }
15257 d3_geo_transform.prototype = {
15258 point: function(x, y) {
15259 this.stream.point(x, y);
15260 },
15261 sphere: function() {
15262 this.stream.sphere();
15263 },
15264 lineStart: function() {
15265 this.stream.lineStart();
15266 },
15267 lineEnd: function() {
15268 this.stream.lineEnd();
15269 },
15270 polygonStart: function() {
15271 this.stream.polygonStart();
15272 },
15273 polygonEnd: function() {
15274 this.stream.polygonEnd();
15275 }
15276 };
15277 function d3_geo_transformPoint(stream, point) {
15278 return {
15279 point: point,
15280 sphere: function() {
15281 stream.sphere();
15282 },
15283 lineStart: function() {
15284 stream.lineStart();
15285 },
15286 lineEnd: function() {
15287 stream.lineEnd();
15288 },
15289 polygonStart: function() {
15290 stream.polygonStart();
15291 },
15292 polygonEnd: function() {
15293 stream.polygonEnd();
15294 }
15295 };
15296 }
15297 d3.geo.projection = d3_geo_projection;
15298 d3.geo.projectionMutator = d3_geo_projectionMutator;
15299 function d3_geo_projection(project) {
15300 return d3_geo_projectionMutator(function() {
15301 return project;
15302 })();
15303 }
15304 function d3_geo_projectionMutator(projectAt) {
15305 var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
15306 x = project(x, y);
15307 return [ x[0] * k + δx, δy - x[1] * k ];
15308 }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, preclip = d3_geo_clipAntimeridian, postclip = d3_identity, clipAngle = null, clipExtent = null, stream;
15309 function projection(point) {
15310 point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
15311 return [ point[0] * k + δx, δy - point[1] * k ];
15312 }
15313 function invert(point) {
15314 point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
15315 return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
15316 }
15317 projection.stream = function(output) {
15318 if (stream) stream.valid = false;
15319 stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
15320 stream.valid = true;
15321 return stream;
15322 };
15323 projection.clipAngle = function(_) {
15324 if (!arguments.length) return clipAngle;
15325 preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
15326 return invalidate();
15327 };
15328 projection.clipExtent = function(_) {
15329 if (!arguments.length) return clipExtent;
15330 clipExtent = _;
15331 postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
15332 return invalidate();
15333 };
15334 projection.scale = function(_) {
15335 if (!arguments.length) return k;
15336 k = +_;
15337 return reset();
15338 };
15339 projection.translate = function(_) {
15340 if (!arguments.length) return [ x, y ];
15341 x = +_[0];
15342 y = +_[1];
15343 return reset();
15344 };
15345 projection.center = function(_) {
15346 if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
15347 λ = _[0] % 360 * d3_radians;
15348 φ = _[1] % 360 * d3_radians;
15349 return reset();
15350 };
15351 projection.rotate = function(_) {
15352 if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
15353 δλ = _[0] % 360 * d3_radians;
15354 δφ = _[1] % 360 * d3_radians;
15355 δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
15356 return reset();
15357 };
15358 d3.rebind(projection, projectResample, "precision");
15359 function reset() {
15360 projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
15361 var center = project(λ, φ);
15362 δx = x - center[0] * k;
15363 δy = y + center[1] * k;
15364 return invalidate();
15365 }
15366 function invalidate() {
15367 if (stream) stream.valid = false, stream = null;
15368 return projection;
15369 }
15370 return function() {
15371 project = projectAt.apply(this, arguments);
15372 projection.invert = project.invert && invert;
15373 return reset();
15374 };
15375 }
15376 function d3_geo_projectionRadians(stream) {
15377 return d3_geo_transformPoint(stream, function(x, y) {
15378 stream.point(x * d3_radians, y * d3_radians);
15379 });
15380 }
15381 function d3_geo_equirectangular(λ, φ) {
15382 return [ λ, φ ];
15383 }
15384 (d3.geo.equirectangular = function() {
15385 return d3_geo_projection(d3_geo_equirectangular);
15386 }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
15387 d3.geo.rotation = function(rotate) {
15388 rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
15389 function forward(coordinates) {
15390 coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
15391 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
15392 }
15393 forward.invert = function(coordinates) {
15394 coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
15395 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
15396 };
15397 return forward;
15398 };
15399 function d3_geo_identityRotation(λ, φ) {
15400 return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
15401 }
15402 d3_geo_identityRotation.invert = d3_geo_equirectangular;
15403 function d3_geo_rotation(δλ, δφ, δγ) {
15404 return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
15405 }
15406 function d3_geo_forwardRotationλ(δλ) {
15407 return function(λ, φ) {
15408 return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
15409 };
15410 }
15411 function d3_geo_rotationλ(δλ) {
15412 var rotation = d3_geo_forwardRotationλ(δλ);
15413 rotation.invert = d3_geo_forwardRotationλ(-δλ);
15414 return rotation;
15415 }
15416 function d3_geo_rotationφγ(δφ, δγ) {
15417 var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
15418 function rotation(λ, φ) {
15419 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
15420 return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
15421 }
15422 rotation.invert = function(λ, φ) {
15423 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
15424 return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
15425 };
15426 return rotation;
15427 }
15428 d3.geo.circle = function() {
15429 var origin = [ 0, 0 ], angle, precision = 6, interpolate;
15430 function circle() {
15431 var center = typeof origin === "function" ? origin.apply(this, arguments) : origin, rotate = d3_geo_rotation(-center[0] * d3_radians, -center[1] * d3_radians, 0).invert, ring = [];
15432 interpolate(null, null, 1, {
15433 point: function(x, y) {
15434 ring.push(x = rotate(x, y));
15435 x[0] *= d3_degrees, x[1] *= d3_degrees;
15436 }
15437 });
15438 return {
15439 type: "Polygon",
15440 coordinates: [ ring ]
15441 };
15442 }
15443 circle.origin = function(x) {
15444 if (!arguments.length) return origin;
15445 origin = x;
15446 return circle;
15447 };
15448 circle.angle = function(x) {
15449 if (!arguments.length) return angle;
15450 interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
15451 return circle;
15452 };
15453 circle.precision = function(_) {
15454 if (!arguments.length) return precision;
15455 interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
15456 return circle;
15457 };
15458 return circle.angle(90);
15459 };
15460 function d3_geo_circleInterpolate(radius, precision) {
15461 var cr = Math.cos(radius), sr = Math.sin(radius);
15462 return function(from, to, direction, listener) {
15463 var step = direction * precision;
15464 if (from != null) {
15465 from = d3_geo_circleAngle(cr, from);
15466 to = d3_geo_circleAngle(cr, to);
15467 if (direction > 0 ? from < to : from > to) from += direction * τ;
15468 } else {
15469 from = radius + direction * τ;
15470 to = radius - .5 * step;
15471 }
15472 for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
15473 listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
15474 }
15475 };
15476 }
15477 function d3_geo_circleAngle(cr, point) {
15478 var a = d3_geo_cartesian(point);
15479 a[0] -= cr;
15480 d3_geo_cartesianNormalize(a);
15481 var angle = d3_acos(-a[1]);
15482 return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
15483 }
15484 d3.geo.distance = function(a, b) {
15485 var Δλ = (b[0] - a[0]) * d3_radians, φ0 = a[1] * d3_radians, φ1 = b[1] * d3_radians, sinΔλ = Math.sin(Δλ), cosΔλ = Math.cos(Δλ), sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1), t;
15486 return Math.atan2(Math.sqrt((t = cosφ1 * sinΔλ) * t + (t = cosφ0 * sinφ1 - sinφ0 * cosφ1 * cosΔλ) * t), sinφ0 * sinφ1 + cosφ0 * cosφ1 * cosΔλ);
15487 };
15488 d3.geo.graticule = function() {
15489 var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
15490 function graticule() {
15491 return {
15492 type: "MultiLineString",
15493 coordinates: lines()
15494 };
15495 }
15496 function lines() {
15497 return d3.range(Math.ceil(X0 / DX) * DX, X1, DX).map(X).concat(d3.range(Math.ceil(Y0 / DY) * DY, Y1, DY).map(Y)).concat(d3.range(Math.ceil(x0 / dx) * dx, x1, dx).filter(function(x) {
15498 return abs(x % DX) > ε;
15499 }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
15500 return abs(y % DY) > ε;
15501 }).map(y));
15502 }
15503 graticule.lines = function() {
15504 return lines().map(function(coordinates) {
15505 return {
15506 type: "LineString",
15507 coordinates: coordinates
15508 };
15509 });
15510 };
15511 graticule.outline = function() {
15512 return {
15513 type: "Polygon",
15514 coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
15515 };
15516 };
15517 graticule.extent = function(_) {
15518 if (!arguments.length) return graticule.minorExtent();
15519 return graticule.majorExtent(_).minorExtent(_);
15520 };
15521 graticule.majorExtent = function(_) {
15522 if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
15523 X0 = +_[0][0], X1 = +_[1][0];
15524 Y0 = +_[0][1], Y1 = +_[1][1];
15525 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
15526 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
15527 return graticule.precision(precision);
15528 };
15529 graticule.minorExtent = function(_) {
15530 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
15531 x0 = +_[0][0], x1 = +_[1][0];
15532 y0 = +_[0][1], y1 = +_[1][1];
15533 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
15534 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
15535 return graticule.precision(precision);
15536 };
15537 graticule.step = function(_) {
15538 if (!arguments.length) return graticule.minorStep();
15539 return graticule.majorStep(_).minorStep(_);
15540 };
15541 graticule.majorStep = function(_) {
15542 if (!arguments.length) return [ DX, DY ];
15543 DX = +_[0], DY = +_[1];
15544 return graticule;
15545 };
15546 graticule.minorStep = function(_) {
15547 if (!arguments.length) return [ dx, dy ];
15548 dx = +_[0], dy = +_[1];
15549 return graticule;
15550 };
15551 graticule.precision = function(_) {
15552 if (!arguments.length) return precision;
15553 precision = +_;
15554 x = d3_geo_graticuleX(y0, y1, 90);
15555 y = d3_geo_graticuleY(x0, x1, precision);
15556 X = d3_geo_graticuleX(Y0, Y1, 90);
15557 Y = d3_geo_graticuleY(X0, X1, precision);
15558 return graticule;
15559 };
15560 return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
15561 };
15562 function d3_geo_graticuleX(y0, y1, dy) {
15563 var y = d3.range(y0, y1 - ε, dy).concat(y1);
15564 return function(x) {
15565 return y.map(function(y) {
15566 return [ x, y ];
15567 });
15568 };
15569 }
15570 function d3_geo_graticuleY(x0, x1, dx) {
15571 var x = d3.range(x0, x1 - ε, dx).concat(x1);
15572 return function(y) {
15573 return x.map(function(x) {
15574 return [ x, y ];
15575 });
15576 };
15577 }
15578 function d3_source(d) {
15579 return d.source;
15580 }
15581 function d3_target(d) {
15582 return d.target;
15583 }
15584 d3.geo.greatArc = function() {
15585 var source = d3_source, source_, target = d3_target, target_;
15586 function greatArc() {
15587 return {
15588 type: "LineString",
15589 coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
15590 };
15591 }
15592 greatArc.distance = function() {
15593 return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
15594 };
15595 greatArc.source = function(_) {
15596 if (!arguments.length) return source;
15597 source = _, source_ = typeof _ === "function" ? null : _;
15598 return greatArc;
15599 };
15600 greatArc.target = function(_) {
15601 if (!arguments.length) return target;
15602 target = _, target_ = typeof _ === "function" ? null : _;
15603 return greatArc;
15604 };
15605 greatArc.precision = function() {
15606 return arguments.length ? greatArc : 0;
15607 };
15608 return greatArc;
15609 };
15610 d3.geo.interpolate = function(source, target) {
15611 return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
15612 };
15613 function d3_geo_interpolate(x0, y0, x1, y1) {
15614 var cy0 = Math.cos(y0), sy0 = Math.sin(y0), cy1 = Math.cos(y1), sy1 = Math.sin(y1), kx0 = cy0 * Math.cos(x0), ky0 = cy0 * Math.sin(x0), kx1 = cy1 * Math.cos(x1), ky1 = cy1 * Math.sin(x1), d = 2 * Math.asin(Math.sqrt(d3_haversin(y1 - y0) + cy0 * cy1 * d3_haversin(x1 - x0))), k = 1 / Math.sin(d);
15615 var interpolate = d ? function(t) {
15616 var B = Math.sin(t *= d) * k, A = Math.sin(d - t) * k, x = A * kx0 + B * kx1, y = A * ky0 + B * ky1, z = A * sy0 + B * sy1;
15617 return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
15618 } : function() {
15619 return [ x0 * d3_degrees, y0 * d3_degrees ];
15620 };
15621 interpolate.distance = d;
15622 return interpolate;
15623 }
15624 d3.geo.length = function(object) {
15625 d3_geo_lengthSum = 0;
15626 d3.geo.stream(object, d3_geo_length);
15627 return d3_geo_lengthSum;
15628 };
15629 var d3_geo_lengthSum;
15630 var d3_geo_length = {
15631 sphere: d3_noop,
15632 point: d3_noop,
15633 lineStart: d3_geo_lengthLineStart,
15634 lineEnd: d3_noop,
15635 polygonStart: d3_noop,
15636 polygonEnd: d3_noop
15637 };
15638 function d3_geo_lengthLineStart() {
15639 var λ0, sinφ0, cosφ0;
15640 d3_geo_length.point = function(λ, φ) {
15641 λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
15642 d3_geo_length.point = nextPoint;
15643 };
15644 d3_geo_length.lineEnd = function() {
15645 d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
15646 };
15647 function nextPoint(λ, φ) {
15648 var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
15649 d3_geo_lengthSum += Math.atan2(Math.sqrt((t = cosφ * Math.sin(t)) * t + (t = cosφ0 * sinφ - sinφ0 * cosφ * cosΔλ) * t), sinφ0 * sinφ + cosφ0 * cosφ * cosΔλ);
15650 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
15651 }
15652 }
15653 function d3_geo_azimuthal(scale, angle) {
15654 function azimuthal(λ, φ) {
15655 var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
15656 return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
15657 }
15658 azimuthal.invert = function(x, y) {
15659 var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
15660 return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
15661 };
15662 return azimuthal;
15663 }
15664 var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
15665 return Math.sqrt(2 / (1 + cosλcosφ));
15666 }, function(ρ) {
15667 return 2 * Math.asin(ρ / 2);
15668 });
15669 (d3.geo.azimuthalEqualArea = function() {
15670 return d3_geo_projection(d3_geo_azimuthalEqualArea);
15671 }).raw = d3_geo_azimuthalEqualArea;
15672 var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
15673 var c = Math.acos(cosλcosφ);
15674 return c && c / Math.sin(c);
15675 }, d3_identity);
15676 (d3.geo.azimuthalEquidistant = function() {
15677 return d3_geo_projection(d3_geo_azimuthalEquidistant);
15678 }).raw = d3_geo_azimuthalEquidistant;
15679 function d3_geo_conicConformal(φ0, φ1) {
15680 var cosφ0 = Math.cos(φ0), t = function(φ) {
15681 return Math.tan(π / 4 + φ / 2);
15682 }, n = φ0 === φ1 ? Math.sin(φ0) : Math.log(cosφ0 / Math.cos(φ1)) / Math.log(t(φ1) / t(φ0)), F = cosφ0 * Math.pow(t(φ0), n) / n;
15683 if (!n) return d3_geo_mercator;
15684 function forward(λ, φ) {
15685 if (F > 0) {
15686 if (φ < -halfπ + ε) φ = -halfπ + ε;
15687 } else {
15688 if (φ > halfπ - ε) φ = halfπ - ε;
15689 }
15690 var ρ = F / Math.pow(t(φ), n);
15691 return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
15692 }
15693 forward.invert = function(x, y) {
15694 var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
15695 return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
15696 };
15697 return forward;
15698 }
15699 (d3.geo.conicConformal = function() {
15700 return d3_geo_conic(d3_geo_conicConformal);
15701 }).raw = d3_geo_conicConformal;
15702 function d3_geo_conicEquidistant(φ0, φ1) {
15703 var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
15704 if (abs(n) < ε) return d3_geo_equirectangular;
15705 function forward(λ, φ) {
15706 var ρ = G - φ;
15707 return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
15708 }
15709 forward.invert = function(x, y) {
15710 var ρ0_y = G - y;
15711 return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
15712 };
15713 return forward;
15714 }
15715 (d3.geo.conicEquidistant = function() {
15716 return d3_geo_conic(d3_geo_conicEquidistant);
15717 }).raw = d3_geo_conicEquidistant;
15718 var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
15719 return 1 / cosλcosφ;
15720 }, Math.atan);
15721 (d3.geo.gnomonic = function() {
15722 return d3_geo_projection(d3_geo_gnomonic);
15723 }).raw = d3_geo_gnomonic;
15724 function d3_geo_mercator(λ, φ) {
15725 return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
15726 }
15727 d3_geo_mercator.invert = function(x, y) {
15728 return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
15729 };
15730 function d3_geo_mercatorProjection(project) {
15731 var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
15732 m.scale = function() {
15733 var v = scale.apply(m, arguments);
15734 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
15735 };
15736 m.translate = function() {
15737 var v = translate.apply(m, arguments);
15738 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
15739 };
15740 m.clipExtent = function(_) {
15741 var v = clipExtent.apply(m, arguments);
15742 if (v === m) {
15743 if (clipAuto = _ == null) {
15744 var k = π * scale(), t = translate();
15745 clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
15746 }
15747 } else if (clipAuto) {
15748 v = null;
15749 }
15750 return v;
15751 };
15752 return m.clipExtent(null);
15753 }
15754 (d3.geo.mercator = function() {
15755 return d3_geo_mercatorProjection(d3_geo_mercator);
15756 }).raw = d3_geo_mercator;
15757 var d3_geo_orthographic = d3_geo_azimuthal(function() {
15758 return 1;
15759 }, Math.asin);
15760 (d3.geo.orthographic = function() {
15761 return d3_geo_projection(d3_geo_orthographic);
15762 }).raw = d3_geo_orthographic;
15763 var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
15764 return 1 / (1 + cosλcosφ);
15765 }, function(ρ) {
15766 return 2 * Math.atan(ρ);
15767 });
15768 (d3.geo.stereographic = function() {
15769 return d3_geo_projection(d3_geo_stereographic);
15770 }).raw = d3_geo_stereographic;
15771 function d3_geo_transverseMercator(λ, φ) {
15772 return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
15773 }
15774 d3_geo_transverseMercator.invert = function(x, y) {
15775 return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
15776 };
15777 (d3.geo.transverseMercator = function() {
15778 var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
15779 projection.center = function(_) {
15780 return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
15781 };
15782 projection.rotate = function(_) {
15783 return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
15784 [ _[0], _[1], _[2] - 90 ]);
15785 };
15786 return rotate([ 0, 0, 90 ]);
15787 }).raw = d3_geo_transverseMercator;
15788 d3.geom = {};
15789 function d3_geom_pointX(d) {
15790 return d[0];
15791 }
15792 function d3_geom_pointY(d) {
15793 return d[1];
15794 }
15795 d3.geom.hull = function(vertices) {
15796 var x = d3_geom_pointX, y = d3_geom_pointY;
15797 if (arguments.length) return hull(vertices);
15798 function hull(data) {
15799 if (data.length < 3) return [];
15800 var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
15801 for (i = 0; i < n; i++) {
15802 points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
15803 }
15804 points.sort(d3_geom_hullOrder);
15805 for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
15806 var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
15807 var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
15808 for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
15809 for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
15810 return polygon;
15811 }
15812 hull.x = function(_) {
15813 return arguments.length ? (x = _, hull) : x;
15814 };
15815 hull.y = function(_) {
15816 return arguments.length ? (y = _, hull) : y;
15817 };
15818 return hull;
15819 };
15820 function d3_geom_hullUpper(points) {
15821 var n = points.length, hull = [ 0, 1 ], hs = 2;
15822 for (var i = 2; i < n; i++) {
15823 while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
15824 hull[hs++] = i;
15825 }
15826 return hull.slice(0, hs);
15827 }
15828 function d3_geom_hullOrder(a, b) {
15829 return a[0] - b[0] || a[1] - b[1];
15830 }
15831 d3.geom.polygon = function(coordinates) {
15832 d3_subclass(coordinates, d3_geom_polygonPrototype);
15833 return coordinates;
15834 };
15835 var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
15836 d3_geom_polygonPrototype.area = function() {
15837 var i = -1, n = this.length, a, b = this[n - 1], area = 0;
15838 while (++i < n) {
15839 a = b;
15840 b = this[i];
15841 area += a[1] * b[0] - a[0] * b[1];
15842 }
15843 return area * .5;
15844 };
15845 d3_geom_polygonPrototype.centroid = function(k) {
15846 var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
15847 if (!arguments.length) k = -1 / (6 * this.area());
15848 while (++i < n) {
15849 a = b;
15850 b = this[i];
15851 c = a[0] * b[1] - b[0] * a[1];
15852 x += (a[0] + b[0]) * c;
15853 y += (a[1] + b[1]) * c;
15854 }
15855 return [ x * k, y * k ];
15856 };
15857 d3_geom_polygonPrototype.clip = function(subject) {
15858 var input, closed = d3_geom_polygonClosed(subject), i = -1, n = this.length - d3_geom_polygonClosed(this), j, m, a = this[n - 1], b, c, d;
15859 while (++i < n) {
15860 input = subject.slice();
15861 subject.length = 0;
15862 b = this[i];
15863 c = input[(m = input.length - closed) - 1];
15864 j = -1;
15865 while (++j < m) {
15866 d = input[j];
15867 if (d3_geom_polygonInside(d, a, b)) {
15868 if (!d3_geom_polygonInside(c, a, b)) {
15869 subject.push(d3_geom_polygonIntersect(c, d, a, b));
15870 }
15871 subject.push(d);
15872 } else if (d3_geom_polygonInside(c, a, b)) {
15873 subject.push(d3_geom_polygonIntersect(c, d, a, b));
15874 }
15875 c = d;
15876 }
15877 if (closed) subject.push(subject[0]);
15878 a = b;
15879 }
15880 return subject;
15881 };
15882 function d3_geom_polygonInside(p, a, b) {
15883 return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
15884 }
15885 function d3_geom_polygonIntersect(c, d, a, b) {
15886 var x1 = c[0], x3 = a[0], x21 = d[0] - x1, x43 = b[0] - x3, y1 = c[1], y3 = a[1], y21 = d[1] - y1, y43 = b[1] - y3, ua = (x43 * (y1 - y3) - y43 * (x1 - x3)) / (y43 * x21 - x43 * y21);
15887 return [ x1 + ua * x21, y1 + ua * y21 ];
15888 }
15889 function d3_geom_polygonClosed(coordinates) {
15890 var a = coordinates[0], b = coordinates[coordinates.length - 1];
15891 return !(a[0] - b[0] || a[1] - b[1]);
15892 }
15893 var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
15894 function d3_geom_voronoiBeach() {
15895 d3_geom_voronoiRedBlackNode(this);
15896 this.edge = this.site = this.circle = null;
15897 }
15898 function d3_geom_voronoiCreateBeach(site) {
15899 var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
15900 beach.site = site;
15901 return beach;
15902 }
15903 function d3_geom_voronoiDetachBeach(beach) {
15904 d3_geom_voronoiDetachCircle(beach);
15905 d3_geom_voronoiBeaches.remove(beach);
15906 d3_geom_voronoiBeachPool.push(beach);
15907 d3_geom_voronoiRedBlackNode(beach);
15908 }
15909 function d3_geom_voronoiRemoveBeach(beach) {
15910 var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
15911 x: x,
15912 y: y
15913 }, previous = beach.P, next = beach.N, disappearing = [ beach ];
15914 d3_geom_voronoiDetachBeach(beach);
15915 var lArc = previous;
15916 while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
15917 previous = lArc.P;
15918 disappearing.unshift(lArc);
15919 d3_geom_voronoiDetachBeach(lArc);
15920 lArc = previous;
15921 }
15922 disappearing.unshift(lArc);
15923 d3_geom_voronoiDetachCircle(lArc);
15924 var rArc = next;
15925 while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
15926 next = rArc.N;
15927 disappearing.push(rArc);
15928 d3_geom_voronoiDetachBeach(rArc);
15929 rArc = next;
15930 }
15931 disappearing.push(rArc);
15932 d3_geom_voronoiDetachCircle(rArc);
15933 var nArcs = disappearing.length, iArc;
15934 for (iArc = 1; iArc < nArcs; ++iArc) {
15935 rArc = disappearing[iArc];
15936 lArc = disappearing[iArc - 1];
15937 d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
15938 }
15939 lArc = disappearing[0];
15940 rArc = disappearing[nArcs - 1];
15941 rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
15942 d3_geom_voronoiAttachCircle(lArc);
15943 d3_geom_voronoiAttachCircle(rArc);
15944 }
15945 function d3_geom_voronoiAddBeach(site) {
15946 var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
15947 while (node) {
15948 dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
15949 if (dxl > ε) node = node.L; else {
15950 dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
15951 if (dxr > ε) {
15952 if (!node.R) {
15953 lArc = node;
15954 break;
15955 }
15956 node = node.R;
15957 } else {
15958 if (dxl > -ε) {
15959 lArc = node.P;
15960 rArc = node;
15961 } else if (dxr > -ε) {
15962 lArc = node;
15963 rArc = node.N;
15964 } else {
15965 lArc = rArc = node;
15966 }
15967 break;
15968 }
15969 }
15970 }
15971 var newArc = d3_geom_voronoiCreateBeach(site);
15972 d3_geom_voronoiBeaches.insert(lArc, newArc);
15973 if (!lArc && !rArc) return;
15974 if (lArc === rArc) {
15975 d3_geom_voronoiDetachCircle(lArc);
15976 rArc = d3_geom_voronoiCreateBeach(lArc.site);
15977 d3_geom_voronoiBeaches.insert(newArc, rArc);
15978 newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
15979 d3_geom_voronoiAttachCircle(lArc);
15980 d3_geom_voronoiAttachCircle(rArc);
15981 return;
15982 }
15983 if (!rArc) {
15984 newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
15985 return;
15986 }
15987 d3_geom_voronoiDetachCircle(lArc);
15988 d3_geom_voronoiDetachCircle(rArc);
15989 var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = {
15990 x: (cy * hb - by * hc) / d + ax,
15991 y: (bx * hc - cx * hb) / d + ay
15992 };
15993 d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
15994 newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
15995 rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
15996 d3_geom_voronoiAttachCircle(lArc);
15997 d3_geom_voronoiAttachCircle(rArc);
15998 }
15999 function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
16000 var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
16001 if (!pby2) return rfocx;
16002 var lArc = arc.P;
16003 if (!lArc) return -Infinity;
16004 site = lArc.site;
16005 var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
16006 if (!plby2) return lfocx;
16007 var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
16008 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
16009 return (rfocx + lfocx) / 2;
16010 }
16011 function d3_geom_voronoiRightBreakPoint(arc, directrix) {
16012 var rArc = arc.N;
16013 if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
16014 var site = arc.site;
16015 return site.y === directrix ? site.x : Infinity;
16016 }
16017 function d3_geom_voronoiCell(site) {
16018 this.site = site;
16019 this.edges = [];
16020 }
16021 d3_geom_voronoiCell.prototype.prepare = function() {
16022 var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
16023 while (iHalfEdge--) {
16024 edge = halfEdges[iHalfEdge].edge;
16025 if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
16026 }
16027 halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
16028 return halfEdges.length;
16029 };
16030 function d3_geom_voronoiCloseCells(extent) {
16031 var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end;
16032 while (iCell--) {
16033 cell = cells[iCell];
16034 if (!cell || !cell.prepare()) continue;
16035 halfEdges = cell.edges;
16036 nHalfEdges = halfEdges.length;
16037 iHalfEdge = 0;
16038 while (iHalfEdge < nHalfEdges) {
16039 end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
16040 start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
16041 if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
16042 halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
16043 x: x0,
16044 y: abs(x2 - x0) < ε ? y2 : y1
16045 } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
16046 x: abs(y2 - y1) < ε ? x2 : x1,
16047 y: y1
16048 } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
16049 x: x1,
16050 y: abs(x2 - x1) < ε ? y2 : y0
16051 } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
16052 x: abs(y2 - y0) < ε ? x2 : x0,
16053 y: y0
16054 } : null), cell.site, null));
16055 ++nHalfEdges;
16056 }
16057 }
16058 }
16059 }
16060 function d3_geom_voronoiHalfEdgeOrder(a, b) {
16061 return b.angle - a.angle;
16062 }
16063 function d3_geom_voronoiCircle() {
16064 d3_geom_voronoiRedBlackNode(this);
16065 this.x = this.y = this.arc = this.site = this.cy = null;
16066 }
16067 function d3_geom_voronoiAttachCircle(arc) {
16068 var lArc = arc.P, rArc = arc.N;
16069 if (!lArc || !rArc) return;
16070 var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
16071 if (lSite === rSite) return;
16072 var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
16073 var d = 2 * (ax * cy - ay * cx);
16074 if (d >= -ε2) return;
16075 var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by;
16076 var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
16077 circle.arc = arc;
16078 circle.site = cSite;
16079 circle.x = x + bx;
16080 circle.y = cy + Math.sqrt(x * x + y * y);
16081 circle.cy = cy;
16082 arc.circle = circle;
16083 var before = null, node = d3_geom_voronoiCircles._;
16084 while (node) {
16085 if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
16086 if (node.L) node = node.L; else {
16087 before = node.P;
16088 break;
16089 }
16090 } else {
16091 if (node.R) node = node.R; else {
16092 before = node;
16093 break;
16094 }
16095 }
16096 }
16097 d3_geom_voronoiCircles.insert(before, circle);
16098 if (!before) d3_geom_voronoiFirstCircle = circle;
16099 }
16100 function d3_geom_voronoiDetachCircle(arc) {
16101 var circle = arc.circle;
16102 if (circle) {
16103 if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
16104 d3_geom_voronoiCircles.remove(circle);
16105 d3_geom_voronoiCirclePool.push(circle);
16106 d3_geom_voronoiRedBlackNode(circle);
16107 arc.circle = null;
16108 }
16109 }
16110 function d3_geom_voronoiClipEdges(extent) {
16111 var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e;
16112 while (i--) {
16113 e = edges[i];
16114 if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
16115 e.a = e.b = null;
16116 edges.splice(i, 1);
16117 }
16118 }
16119 }
16120 function d3_geom_voronoiConnectEdge(edge, extent) {
16121 var vb = edge.b;
16122 if (vb) return true;
16123 var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb;
16124 if (ry === ly) {
16125 if (fx < x0 || fx >= x1) return;
16126 if (lx > rx) {
16127 if (!va) va = {
16128 x: fx,
16129 y: y0
16130 }; else if (va.y >= y1) return;
16131 vb = {
16132 x: fx,
16133 y: y1
16134 };
16135 } else {
16136 if (!va) va = {
16137 x: fx,
16138 y: y1
16139 }; else if (va.y < y0) return;
16140 vb = {
16141 x: fx,
16142 y: y0
16143 };
16144 }
16145 } else {
16146 fm = (lx - rx) / (ry - ly);
16147 fb = fy - fm * fx;
16148 if (fm < -1 || fm > 1) {
16149 if (lx > rx) {
16150 if (!va) va = {
16151 x: (y0 - fb) / fm,
16152 y: y0
16153 }; else if (va.y >= y1) return;
16154 vb = {
16155 x: (y1 - fb) / fm,
16156 y: y1
16157 };
16158 } else {
16159 if (!va) va = {
16160 x: (y1 - fb) / fm,
16161 y: y1
16162 }; else if (va.y < y0) return;
16163 vb = {
16164 x: (y0 - fb) / fm,
16165 y: y0
16166 };
16167 }
16168 } else {
16169 if (ly < ry) {
16170 if (!va) va = {
16171 x: x0,
16172 y: fm * x0 + fb
16173 }; else if (va.x >= x1) return;
16174 vb = {
16175 x: x1,
16176 y: fm * x1 + fb
16177 };
16178 } else {
16179 if (!va) va = {
16180 x: x1,
16181 y: fm * x1 + fb
16182 }; else if (va.x < x0) return;
16183 vb = {
16184 x: x0,
16185 y: fm * x0 + fb
16186 };
16187 }
16188 }
16189 }
16190 edge.a = va;
16191 edge.b = vb;
16192 return true;
16193 }
16194 function d3_geom_voronoiEdge(lSite, rSite) {
16195 this.l = lSite;
16196 this.r = rSite;
16197 this.a = this.b = null;
16198 }
16199 function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
16200 var edge = new d3_geom_voronoiEdge(lSite, rSite);
16201 d3_geom_voronoiEdges.push(edge);
16202 if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
16203 if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
16204 d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
16205 d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
16206 return edge;
16207 }
16208 function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
16209 var edge = new d3_geom_voronoiEdge(lSite, null);
16210 edge.a = va;
16211 edge.b = vb;
16212 d3_geom_voronoiEdges.push(edge);
16213 return edge;
16214 }
16215 function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
16216 if (!edge.a && !edge.b) {
16217 edge.a = vertex;
16218 edge.l = lSite;
16219 edge.r = rSite;
16220 } else if (edge.l === rSite) {
16221 edge.b = vertex;
16222 } else {
16223 edge.a = vertex;
16224 }
16225 }
16226 function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
16227 var va = edge.a, vb = edge.b;
16228 this.edge = edge;
16229 this.site = lSite;
16230 this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y);
16231 }
16232 d3_geom_voronoiHalfEdge.prototype = {
16233 start: function() {
16234 return this.edge.l === this.site ? this.edge.a : this.edge.b;
16235 },
16236 end: function() {
16237 return this.edge.l === this.site ? this.edge.b : this.edge.a;
16238 }
16239 };
16240 function d3_geom_voronoiRedBlackTree() {
16241 this._ = null;
16242 }
16243 function d3_geom_voronoiRedBlackNode(node) {
16244 node.U = node.C = node.L = node.R = node.P = node.N = null;
16245 }
16246 d3_geom_voronoiRedBlackTree.prototype = {
16247 insert: function(after, node) {
16248 var parent, grandpa, uncle;
16249 if (after) {
16250 node.P = after;
16251 node.N = after.N;
16252 if (after.N) after.N.P = node;
16253 after.N = node;
16254 if (after.R) {
16255 after = after.R;
16256 while (after.L) after = after.L;
16257 after.L = node;
16258 } else {
16259 after.R = node;
16260 }
16261 parent = after;
16262 } else if (this._) {
16263 after = d3_geom_voronoiRedBlackFirst(this._);
16264 node.P = null;
16265 node.N = after;
16266 after.P = after.L = node;
16267 parent = after;
16268 } else {
16269 node.P = node.N = null;
16270 this._ = node;
16271 parent = null;
16272 }
16273 node.L = node.R = null;
16274 node.U = parent;
16275 node.C = true;
16276 after = node;
16277 while (parent && parent.C) {
16278 grandpa = parent.U;
16279 if (parent === grandpa.L) {
16280 uncle = grandpa.R;
16281 if (uncle && uncle.C) {
16282 parent.C = uncle.C = false;
16283 grandpa.C = true;
16284 after = grandpa;
16285 } else {
16286 if (after === parent.R) {
16287 d3_geom_voronoiRedBlackRotateLeft(this, parent);
16288 after = parent;
16289 parent = after.U;
16290 }
16291 parent.C = false;
16292 grandpa.C = true;
16293 d3_geom_voronoiRedBlackRotateRight(this, grandpa);
16294 }
16295 } else {
16296 uncle = grandpa.L;
16297 if (uncle && uncle.C) {
16298 parent.C = uncle.C = false;
16299 grandpa.C = true;
16300 after = grandpa;
16301 } else {
16302 if (after === parent.L) {
16303 d3_geom_voronoiRedBlackRotateRight(this, parent);
16304 after = parent;
16305 parent = after.U;
16306 }
16307 parent.C = false;
16308 grandpa.C = true;
16309 d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
16310 }
16311 }
16312 parent = after.U;
16313 }
16314 this._.C = false;
16315 },
16316 remove: function(node) {
16317 if (node.N) node.N.P = node.P;
16318 if (node.P) node.P.N = node.N;
16319 node.N = node.P = null;
16320 var parent = node.U, sibling, left = node.L, right = node.R, next, red;
16321 if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
16322 if (parent) {
16323 if (parent.L === node) parent.L = next; else parent.R = next;
16324 } else {
16325 this._ = next;
16326 }
16327 if (left && right) {
16328 red = next.C;
16329 next.C = node.C;
16330 next.L = left;
16331 left.U = next;
16332 if (next !== right) {
16333 parent = next.U;
16334 next.U = node.U;
16335 node = next.R;
16336 parent.L = node;
16337 next.R = right;
16338 right.U = next;
16339 } else {
16340 next.U = parent;
16341 parent = next;
16342 node = next.R;
16343 }
16344 } else {
16345 red = node.C;
16346 node = next;
16347 }
16348 if (node) node.U = parent;
16349 if (red) return;
16350 if (node && node.C) {
16351 node.C = false;
16352 return;
16353 }
16354 do {
16355 if (node === this._) break;
16356 if (node === parent.L) {
16357 sibling = parent.R;
16358 if (sibling.C) {
16359 sibling.C = false;
16360 parent.C = true;
16361 d3_geom_voronoiRedBlackRotateLeft(this, parent);
16362 sibling = parent.R;
16363 }
16364 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
16365 if (!sibling.R || !sibling.R.C) {
16366 sibling.L.C = false;
16367 sibling.C = true;
16368 d3_geom_voronoiRedBlackRotateRight(this, sibling);
16369 sibling = parent.R;
16370 }
16371 sibling.C = parent.C;
16372 parent.C = sibling.R.C = false;
16373 d3_geom_voronoiRedBlackRotateLeft(this, parent);
16374 node = this._;
16375 break;
16376 }
16377 } else {
16378 sibling = parent.L;
16379 if (sibling.C) {
16380 sibling.C = false;
16381 parent.C = true;
16382 d3_geom_voronoiRedBlackRotateRight(this, parent);
16383 sibling = parent.L;
16384 }
16385 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
16386 if (!sibling.L || !sibling.L.C) {
16387 sibling.R.C = false;
16388 sibling.C = true;
16389 d3_geom_voronoiRedBlackRotateLeft(this, sibling);
16390 sibling = parent.L;
16391 }
16392 sibling.C = parent.C;
16393 parent.C = sibling.L.C = false;
16394 d3_geom_voronoiRedBlackRotateRight(this, parent);
16395 node = this._;
16396 break;
16397 }
16398 }
16399 sibling.C = true;
16400 node = parent;
16401 parent = parent.U;
16402 } while (!node.C);
16403 if (node) node.C = false;
16404 }
16405 };
16406 function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
16407 var p = node, q = node.R, parent = p.U;
16408 if (parent) {
16409 if (parent.L === p) parent.L = q; else parent.R = q;
16410 } else {
16411 tree._ = q;
16412 }
16413 q.U = parent;
16414 p.U = q;
16415 p.R = q.L;
16416 if (p.R) p.R.U = p;
16417 q.L = p;
16418 }
16419 function d3_geom_voronoiRedBlackRotateRight(tree, node) {
16420 var p = node, q = node.L, parent = p.U;
16421 if (parent) {
16422 if (parent.L === p) parent.L = q; else parent.R = q;
16423 } else {
16424 tree._ = q;
16425 }
16426 q.U = parent;
16427 p.U = q;
16428 p.L = q.R;
16429 if (p.L) p.L.U = p;
16430 q.R = p;
16431 }
16432 function d3_geom_voronoiRedBlackFirst(node) {
16433 while (node.L) node = node.L;
16434 return node;
16435 }
16436 function d3_geom_voronoi(sites, bbox) {
16437 var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
16438 d3_geom_voronoiEdges = [];
16439 d3_geom_voronoiCells = new Array(sites.length);
16440 d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
16441 d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
16442 while (true) {
16443 circle = d3_geom_voronoiFirstCircle;
16444 if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
16445 if (site.x !== x0 || site.y !== y0) {
16446 d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
16447 d3_geom_voronoiAddBeach(site);
16448 x0 = site.x, y0 = site.y;
16449 }
16450 site = sites.pop();
16451 } else if (circle) {
16452 d3_geom_voronoiRemoveBeach(circle.arc);
16453 } else {
16454 break;
16455 }
16456 }
16457 if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
16458 var diagram = {
16459 cells: d3_geom_voronoiCells,
16460 edges: d3_geom_voronoiEdges
16461 };
16462 d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
16463 return diagram;
16464 }
16465 function d3_geom_voronoiVertexOrder(a, b) {
16466 return b.y - a.y || b.x - a.x;
16467 }
16468 d3.geom.voronoi = function(points) {
16469 var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
16470 if (points) return voronoi(points);
16471 function voronoi(data) {
16472 var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
16473 d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
16474 var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
16475 var s = e.start();
16476 return [ s.x, s.y ];
16477 }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
16478 polygon.point = data[i];
16479 });
16480 return polygons;
16481 }
16482 function sites(data) {
16483 return data.map(function(d, i) {
16484 return {
16485 x: Math.round(fx(d, i) / ε) * ε,
16486 y: Math.round(fy(d, i) / ε) * ε,
16487 i: i
16488 };
16489 });
16490 }
16491 voronoi.links = function(data) {
16492 return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
16493 return edge.l && edge.r;
16494 }).map(function(edge) {
16495 return {
16496 source: data[edge.l.i],
16497 target: data[edge.r.i]
16498 };
16499 });
16500 };
16501 voronoi.triangles = function(data) {
16502 var triangles = [];
16503 d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
16504 var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l;
16505 while (++j < m) {
16506 e0 = e1;
16507 s0 = s1;
16508 e1 = edges[j].edge;
16509 s1 = e1.l === site ? e1.r : e1.l;
16510 if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
16511 triangles.push([ data[i], data[s0.i], data[s1.i] ]);
16512 }
16513 }
16514 });
16515 return triangles;
16516 };
16517 voronoi.x = function(_) {
16518 return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
16519 };
16520 voronoi.y = function(_) {
16521 return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
16522 };
16523 voronoi.clipExtent = function(_) {
16524 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
16525 clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
16526 return voronoi;
16527 };
16528 voronoi.size = function(_) {
16529 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
16530 return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
16531 };
16532 return voronoi;
16533 };
16534 var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
16535 function d3_geom_voronoiTriangleArea(a, b, c) {
16536 return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
16537 }
16538 d3.geom.delaunay = function(vertices) {
16539 return d3.geom.voronoi().triangles(vertices);
16540 };
16541 d3.geom.quadtree = function(points, x1, y1, x2, y2) {
16542 var x = d3_geom_pointX, y = d3_geom_pointY, compat;
16543 if (compat = arguments.length) {
16544 x = d3_geom_quadtreeCompatX;
16545 y = d3_geom_quadtreeCompatY;
16546 if (compat === 3) {
16547 y2 = y1;
16548 x2 = x1;
16549 y1 = x1 = 0;
16550 }
16551 return quadtree(points);
16552 }
16553 function quadtree(data) {
16554 var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
16555 if (x1 != null) {
16556 x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
16557 } else {
16558 x2_ = y2_ = -(x1_ = y1_ = Infinity);
16559 xs = [], ys = [];
16560 n = data.length;
16561 if (compat) for (i = 0; i < n; ++i) {
16562 d = data[i];
16563 if (d.x < x1_) x1_ = d.x;
16564 if (d.y < y1_) y1_ = d.y;
16565 if (d.x > x2_) x2_ = d.x;
16566 if (d.y > y2_) y2_ = d.y;
16567 xs.push(d.x);
16568 ys.push(d.y);
16569 } else for (i = 0; i < n; ++i) {
16570 var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
16571 if (x_ < x1_) x1_ = x_;
16572 if (y_ < y1_) y1_ = y_;
16573 if (x_ > x2_) x2_ = x_;
16574 if (y_ > y2_) y2_ = y_;
16575 xs.push(x_);
16576 ys.push(y_);
16577 }
16578 }
16579 var dx = x2_ - x1_, dy = y2_ - y1_;
16580 if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
16581 function insert(n, d, x, y, x1, y1, x2, y2) {
16582 if (isNaN(x) || isNaN(y)) return;
16583 if (n.leaf) {
16584 var nx = n.x, ny = n.y;
16585 if (nx != null) {
16586 if (abs(nx - x) + abs(ny - y) < .01) {
16587 insertChild(n, d, x, y, x1, y1, x2, y2);
16588 } else {
16589 var nPoint = n.point;
16590 n.x = n.y = n.point = null;
16591 insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
16592 insertChild(n, d, x, y, x1, y1, x2, y2);
16593 }
16594 } else {
16595 n.x = x, n.y = y, n.point = d;
16596 }
16597 } else {
16598 insertChild(n, d, x, y, x1, y1, x2, y2);
16599 }
16600 }
16601 function insertChild(n, d, x, y, x1, y1, x2, y2) {
16602 var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
16603 n.leaf = false;
16604 n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
16605 if (right) x1 = xm; else x2 = xm;
16606 if (below) y1 = ym; else y2 = ym;
16607 insert(n, d, x, y, x1, y1, x2, y2);
16608 }
16609 var root = d3_geom_quadtreeNode();
16610 root.add = function(d) {
16611 insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
16612 };
16613 root.visit = function(f) {
16614 d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
16615 };
16616 root.find = function(point) {
16617 return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
16618 };
16619 i = -1;
16620 if (x1 == null) {
16621 while (++i < n) {
16622 insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
16623 }
16624 --i;
16625 } else data.forEach(root.add);
16626 xs = ys = data = d = null;
16627 return root;
16628 }
16629 quadtree.x = function(_) {
16630 return arguments.length ? (x = _, quadtree) : x;
16631 };
16632 quadtree.y = function(_) {
16633 return arguments.length ? (y = _, quadtree) : y;
16634 };
16635 quadtree.extent = function(_) {
16636 if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
16637 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
16638 y2 = +_[1][1];
16639 return quadtree;
16640 };
16641 quadtree.size = function(_) {
16642 if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
16643 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
16644 return quadtree;
16645 };
16646 return quadtree;
16647 };
16648 function d3_geom_quadtreeCompatX(d) {
16649 return d.x;
16650 }
16651 function d3_geom_quadtreeCompatY(d) {
16652 return d.y;
16653 }
16654 function d3_geom_quadtreeNode() {
16655 return {
16656 leaf: true,
16657 nodes: [],
16658 point: null,
16659 x: null,
16660 y: null
16661 };
16662 }
16663 function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
16664 if (!f(node, x1, y1, x2, y2)) {
16665 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
16666 if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
16667 if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
16668 if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
16669 if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
16670 }
16671 }
16672 function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
16673 var minDistance2 = Infinity, closestPoint;
16674 (function find(node, x1, y1, x2, y2) {
16675 if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
16676 if (point = node.point) {
16677 var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
16678 if (distance2 < minDistance2) {
16679 var distance = Math.sqrt(minDistance2 = distance2);
16680 x0 = x - distance, y0 = y - distance;
16681 x3 = x + distance, y3 = y + distance;
16682 closestPoint = point;
16683 }
16684 }
16685 var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
16686 for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
16687 if (node = children[i & 3]) switch (i & 3) {
16688 case 0:
16689 find(node, x1, y1, xm, ym);
16690 break;
16691
16692 case 1:
16693 find(node, xm, y1, x2, ym);
16694 break;
16695
16696 case 2:
16697 find(node, x1, ym, xm, y2);
16698 break;
16699
16700 case 3:
16701 find(node, xm, ym, x2, y2);
16702 break;
16703 }
16704 }
16705 })(root, x0, y0, x3, y3);
16706 return closestPoint;
16707 }
16708 d3.interpolateRgb = d3_interpolateRgb;
16709 function d3_interpolateRgb(a, b) {
16710 a = d3.rgb(a);
16711 b = d3.rgb(b);
16712 var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
16713 return function(t) {
16714 return "#" + d3_rgb_hex(Math.round(ar + br * t)) + d3_rgb_hex(Math.round(ag + bg * t)) + d3_rgb_hex(Math.round(ab + bb * t));
16715 };
16716 }
16717 d3.interpolateObject = d3_interpolateObject;
16718 function d3_interpolateObject(a, b) {
16719 var i = {}, c = {}, k;
16720 for (k in a) {
16721 if (k in b) {
16722 i[k] = d3_interpolate(a[k], b[k]);
16723 } else {
16724 c[k] = a[k];
16725 }
16726 }
16727 for (k in b) {
16728 if (!(k in a)) {
16729 c[k] = b[k];
16730 }
16731 }
16732 return function(t) {
16733 for (k in i) c[k] = i[k](t);
16734 return c;
16735 };
16736 }
16737 d3.interpolateNumber = d3_interpolateNumber;
16738 function d3_interpolateNumber(a, b) {
16739 a = +a, b = +b;
16740 return function(t) {
16741 return a * (1 - t) + b * t;
16742 };
16743 }
16744 d3.interpolateString = d3_interpolateString;
16745 function d3_interpolateString(a, b) {
16746 var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
16747 a = a + "", b = b + "";
16748 while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
16749 if ((bs = bm.index) > bi) {
16750 bs = b.slice(bi, bs);
16751 if (s[i]) s[i] += bs; else s[++i] = bs;
16752 }
16753 if ((am = am[0]) === (bm = bm[0])) {
16754 if (s[i]) s[i] += bm; else s[++i] = bm;
16755 } else {
16756 s[++i] = null;
16757 q.push({
16758 i: i,
16759 x: d3_interpolateNumber(am, bm)
16760 });
16761 }
16762 bi = d3_interpolate_numberB.lastIndex;
16763 }
16764 if (bi < b.length) {
16765 bs = b.slice(bi);
16766 if (s[i]) s[i] += bs; else s[++i] = bs;
16767 }
16768 return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
16769 return b(t) + "";
16770 }) : function() {
16771 return b;
16772 } : (b = q.length, function(t) {
16773 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
16774 return s.join("");
16775 });
16776 }
16777 var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
16778 d3.interpolate = d3_interpolate;
16779 function d3_interpolate(a, b) {
16780 var i = d3.interpolators.length, f;
16781 while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
16782 return f;
16783 }
16784 d3.interpolators = [ function(a, b) {
16785 var t = typeof b;
16786 return (t === "string" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);
16787 } ];
16788 d3.interpolateArray = d3_interpolateArray;
16789 function d3_interpolateArray(a, b) {
16790 var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
16791 for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
16792 for (;i < na; ++i) c[i] = a[i];
16793 for (;i < nb; ++i) c[i] = b[i];
16794 return function(t) {
16795 for (i = 0; i < n0; ++i) c[i] = x[i](t);
16796 return c;
16797 };
16798 }
16799 var d3_ease_default = function() {
16800 return d3_identity;
16801 };
16802 var d3_ease = d3.map({
16803 linear: d3_ease_default,
16804 poly: d3_ease_poly,
16805 quad: function() {
16806 return d3_ease_quad;
16807 },
16808 cubic: function() {
16809 return d3_ease_cubic;
16810 },
16811 sin: function() {
16812 return d3_ease_sin;
16813 },
16814 exp: function() {
16815 return d3_ease_exp;
16816 },
16817 circle: function() {
16818 return d3_ease_circle;
16819 },
16820 elastic: d3_ease_elastic,
16821 back: d3_ease_back,
16822 bounce: function() {
16823 return d3_ease_bounce;
16824 }
16825 });
16826 var d3_ease_mode = d3.map({
16827 "in": d3_identity,
16828 out: d3_ease_reverse,
16829 "in-out": d3_ease_reflect,
16830 "out-in": function(f) {
16831 return d3_ease_reflect(d3_ease_reverse(f));
16832 }
16833 });
16834 d3.ease = function(name) {
16835 var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
16836 t = d3_ease.get(t) || d3_ease_default;
16837 m = d3_ease_mode.get(m) || d3_identity;
16838 return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
16839 };
16840 function d3_ease_clamp(f) {
16841 return function(t) {
16842 return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
16843 };
16844 }
16845 function d3_ease_reverse(f) {
16846 return function(t) {
16847 return 1 - f(1 - t);
16848 };
16849 }
16850 function d3_ease_reflect(f) {
16851 return function(t) {
16852 return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
16853 };
16854 }
16855 function d3_ease_quad(t) {
16856 return t * t;
16857 }
16858 function d3_ease_cubic(t) {
16859 return t * t * t;
16860 }
16861 function d3_ease_cubicInOut(t) {
16862 if (t <= 0) return 0;
16863 if (t >= 1) return 1;
16864 var t2 = t * t, t3 = t2 * t;
16865 return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
16866 }
16867 function d3_ease_poly(e) {
16868 return function(t) {
16869 return Math.pow(t, e);
16870 };
16871 }
16872 function d3_ease_sin(t) {
16873 return 1 - Math.cos(t * halfπ);
16874 }
16875 function d3_ease_exp(t) {
16876 return Math.pow(2, 10 * (t - 1));
16877 }
16878 function d3_ease_circle(t) {
16879 return 1 - Math.sqrt(1 - t * t);
16880 }
16881 function d3_ease_elastic(a, p) {
16882 var s;
16883 if (arguments.length < 2) p = .45;
16884 if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
16885 return function(t) {
16886 return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
16887 };
16888 }
16889 function d3_ease_back(s) {
16890 if (!s) s = 1.70158;
16891 return function(t) {
16892 return t * t * ((s + 1) * t - s);
16893 };
16894 }
16895 function d3_ease_bounce(t) {
16896 return t < 1 / 2.75 ? 7.5625 * t * t : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + .75 : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + .9375 : 7.5625 * (t -= 2.625 / 2.75) * t + .984375;
16897 }
16898 d3.interpolateHcl = d3_interpolateHcl;
16899 function d3_interpolateHcl(a, b) {
16900 a = d3.hcl(a);
16901 b = d3.hcl(b);
16902 var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
16903 if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
16904 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
16905 return function(t) {
16906 return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
16907 };
16908 }
16909 d3.interpolateHsl = d3_interpolateHsl;
16910 function d3_interpolateHsl(a, b) {
16911 a = d3.hsl(a);
16912 b = d3.hsl(b);
16913 var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
16914 if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
16915 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
16916 return function(t) {
16917 return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
16918 };
16919 }
16920 d3.interpolateLab = d3_interpolateLab;
16921 function d3_interpolateLab(a, b) {
16922 a = d3.lab(a);
16923 b = d3.lab(b);
16924 var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
16925 return function(t) {
16926 return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
16927 };
16928 }
16929 d3.interpolateRound = d3_interpolateRound;
16930 function d3_interpolateRound(a, b) {
16931 b -= a;
16932 return function(t) {
16933 return Math.round(a + b * t);
16934 };
16935 }
16936 d3.transform = function(string) {
16937 var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
16938 return (d3.transform = function(string) {
16939 if (string != null) {
16940 g.setAttribute("transform", string);
16941 var t = g.transform.baseVal.consolidate();
16942 }
16943 return new d3_transform(t ? t.matrix : d3_transformIdentity);
16944 })(string);
16945 };
16946 function d3_transform(m) {
16947 var r0 = [ m.a, m.b ], r1 = [ m.c, m.d ], kx = d3_transformNormalize(r0), kz = d3_transformDot(r0, r1), ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0;
16948 if (r0[0] * r1[1] < r1[0] * r0[1]) {
16949 r0[0] *= -1;
16950 r0[1] *= -1;
16951 kx *= -1;
16952 kz *= -1;
16953 }
16954 this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
16955 this.translate = [ m.e, m.f ];
16956 this.scale = [ kx, ky ];
16957 this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
16958 }
16959 d3_transform.prototype.toString = function() {
16960 return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
16961 };
16962 function d3_transformDot(a, b) {
16963 return a[0] * b[0] + a[1] * b[1];
16964 }
16965 function d3_transformNormalize(a) {
16966 var k = Math.sqrt(d3_transformDot(a, a));
16967 if (k) {
16968 a[0] /= k;
16969 a[1] /= k;
16970 }
16971 return k;
16972 }
16973 function d3_transformCombine(a, b, k) {
16974 a[0] += k * b[0];
16975 a[1] += k * b[1];
16976 return a;
16977 }
16978 var d3_transformIdentity = {
16979 a: 1,
16980 b: 0,
16981 c: 0,
16982 d: 1,
16983 e: 0,
16984 f: 0
16985 };
16986 d3.interpolateTransform = d3_interpolateTransform;
16987 function d3_interpolateTransformPop(s) {
16988 return s.length ? s.pop() + "," : "";
16989 }
16990 function d3_interpolateTranslate(ta, tb, s, q) {
16991 if (ta[0] !== tb[0] || ta[1] !== tb[1]) {
16992 var i = s.push("translate(", null, ",", null, ")");
16993 q.push({
16994 i: i - 4,
16995 x: d3_interpolateNumber(ta[0], tb[0])
16996 }, {
16997 i: i - 2,
16998 x: d3_interpolateNumber(ta[1], tb[1])
16999 });
17000 } else if (tb[0] || tb[1]) {
17001 s.push("translate(" + tb + ")");
17002 }
17003 }
17004 function d3_interpolateRotate(ra, rb, s, q) {
17005 if (ra !== rb) {
17006 if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
17007 q.push({
17008 i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2,
17009 x: d3_interpolateNumber(ra, rb)
17010 });
17011 } else if (rb) {
17012 s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")");
17013 }
17014 }
17015 function d3_interpolateSkew(wa, wb, s, q) {
17016 if (wa !== wb) {
17017 q.push({
17018 i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2,
17019 x: d3_interpolateNumber(wa, wb)
17020 });
17021 } else if (wb) {
17022 s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")");
17023 }
17024 }
17025 function d3_interpolateScale(ka, kb, s, q) {
17026 if (ka[0] !== kb[0] || ka[1] !== kb[1]) {
17027 var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")");
17028 q.push({
17029 i: i - 4,
17030 x: d3_interpolateNumber(ka[0], kb[0])
17031 }, {
17032 i: i - 2,
17033 x: d3_interpolateNumber(ka[1], kb[1])
17034 });
17035 } else if (kb[0] !== 1 || kb[1] !== 1) {
17036 s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")");
17037 }
17038 }
17039 function d3_interpolateTransform(a, b) {
17040 var s = [], q = [];
17041 a = d3.transform(a), b = d3.transform(b);
17042 d3_interpolateTranslate(a.translate, b.translate, s, q);
17043 d3_interpolateRotate(a.rotate, b.rotate, s, q);
17044 d3_interpolateSkew(a.skew, b.skew, s, q);
17045 d3_interpolateScale(a.scale, b.scale, s, q);
17046 a = b = null;
17047 return function(t) {
17048 var i = -1, n = q.length, o;
17049 while (++i < n) s[(o = q[i]).i] = o.x(t);
17050 return s.join("");
17051 };
17052 }
17053 function d3_uninterpolateNumber(a, b) {
17054 b = (b -= a = +a) || 1 / b;
17055 return function(x) {
17056 return (x - a) / b;
17057 };
17058 }
17059 function d3_uninterpolateClamp(a, b) {
17060 b = (b -= a = +a) || 1 / b;
17061 return function(x) {
17062 return Math.max(0, Math.min(1, (x - a) / b));
17063 };
17064 }
17065 d3.layout = {};
17066 d3.layout.bundle = function() {
17067 return function(links) {
17068 var paths = [], i = -1, n = links.length;
17069 while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
17070 return paths;
17071 };
17072 };
17073 function d3_layout_bundlePath(link) {
17074 var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
17075 while (start !== lca) {
17076 start = start.parent;
17077 points.push(start);
17078 }
17079 var k = points.length;
17080 while (end !== lca) {
17081 points.splice(k, 0, end);
17082 end = end.parent;
17083 }
17084 return points;
17085 }
17086 function d3_layout_bundleAncestors(node) {
17087 var ancestors = [], parent = node.parent;
17088 while (parent != null) {
17089 ancestors.push(node);
17090 node = parent;
17091 parent = parent.parent;
17092 }
17093 ancestors.push(node);
17094 return ancestors;
17095 }
17096 function d3_layout_bundleLeastCommonAncestor(a, b) {
17097 if (a === b) return a;
17098 var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
17099 while (aNode === bNode) {
17100 sharedNode = aNode;
17101 aNode = aNodes.pop();
17102 bNode = bNodes.pop();
17103 }
17104 return sharedNode;
17105 }
17106 d3.layout.chord = function() {
17107 var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
17108 function relayout() {
17109 var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
17110 chords = [];
17111 groups = [];
17112 k = 0, i = -1;
17113 while (++i < n) {
17114 x = 0, j = -1;
17115 while (++j < n) {
17116 x += matrix[i][j];
17117 }
17118 groupSums.push(x);
17119 subgroupIndex.push(d3.range(n));
17120 k += x;
17121 }
17122 if (sortGroups) {
17123 groupIndex.sort(function(a, b) {
17124 return sortGroups(groupSums[a], groupSums[b]);
17125 });
17126 }
17127 if (sortSubgroups) {
17128 subgroupIndex.forEach(function(d, i) {
17129 d.sort(function(a, b) {
17130 return sortSubgroups(matrix[i][a], matrix[i][b]);
17131 });
17132 });
17133 }
17134 k = (τ - padding * n) / k;
17135 x = 0, i = -1;
17136 while (++i < n) {
17137 x0 = x, j = -1;
17138 while (++j < n) {
17139 var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
17140 subgroups[di + "-" + dj] = {
17141 index: di,
17142 subindex: dj,
17143 startAngle: a0,
17144 endAngle: a1,
17145 value: v
17146 };
17147 }
17148 groups[di] = {
17149 index: di,
17150 startAngle: x0,
17151 endAngle: x,
17152 value: groupSums[di]
17153 };
17154 x += padding;
17155 }
17156 i = -1;
17157 while (++i < n) {
17158 j = i - 1;
17159 while (++j < n) {
17160 var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
17161 if (source.value || target.value) {
17162 chords.push(source.value < target.value ? {
17163 source: target,
17164 target: source
17165 } : {
17166 source: source,
17167 target: target
17168 });
17169 }
17170 }
17171 }
17172 if (sortChords) resort();
17173 }
17174 function resort() {
17175 chords.sort(function(a, b) {
17176 return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
17177 });
17178 }
17179 chord.matrix = function(x) {
17180 if (!arguments.length) return matrix;
17181 n = (matrix = x) && matrix.length;
17182 chords = groups = null;
17183 return chord;
17184 };
17185 chord.padding = function(x) {
17186 if (!arguments.length) return padding;
17187 padding = x;
17188 chords = groups = null;
17189 return chord;
17190 };
17191 chord.sortGroups = function(x) {
17192 if (!arguments.length) return sortGroups;
17193 sortGroups = x;
17194 chords = groups = null;
17195 return chord;
17196 };
17197 chord.sortSubgroups = function(x) {
17198 if (!arguments.length) return sortSubgroups;
17199 sortSubgroups = x;
17200 chords = null;
17201 return chord;
17202 };
17203 chord.sortChords = function(x) {
17204 if (!arguments.length) return sortChords;
17205 sortChords = x;
17206 if (chords) resort();
17207 return chord;
17208 };
17209 chord.chords = function() {
17210 if (!chords) relayout();
17211 return chords;
17212 };
17213 chord.groups = function() {
17214 if (!groups) relayout();
17215 return groups;
17216 };
17217 return chord;
17218 };
17219 d3.layout.force = function() {
17220 var force = {}, event = d3.dispatch("start", "tick", "end"), timer, size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;
17221 function repulse(node) {
17222 return function(quad, x1, _, x2) {
17223 if (quad.point !== node) {
17224 var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
17225 if (dw * dw / theta2 < dn) {
17226 if (dn < chargeDistance2) {
17227 var k = quad.charge / dn;
17228 node.px -= dx * k;
17229 node.py -= dy * k;
17230 }
17231 return true;
17232 }
17233 if (quad.point && dn && dn < chargeDistance2) {
17234 var k = quad.pointCharge / dn;
17235 node.px -= dx * k;
17236 node.py -= dy * k;
17237 }
17238 }
17239 return !quad.charge;
17240 };
17241 }
17242 force.tick = function() {
17243 if ((alpha *= .99) < .005) {
17244 timer = null;
17245 event.end({
17246 type: "end",
17247 alpha: alpha = 0
17248 });
17249 return true;
17250 }
17251 var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
17252 for (i = 0; i < m; ++i) {
17253 o = links[i];
17254 s = o.source;
17255 t = o.target;
17256 x = t.x - s.x;
17257 y = t.y - s.y;
17258 if (l = x * x + y * y) {
17259 l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
17260 x *= l;
17261 y *= l;
17262 t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5);
17263 t.y -= y * k;
17264 s.x += x * (k = 1 - k);
17265 s.y += y * k;
17266 }
17267 }
17268 if (k = alpha * gravity) {
17269 x = size[0] / 2;
17270 y = size[1] / 2;
17271 i = -1;
17272 if (k) while (++i < n) {
17273 o = nodes[i];
17274 o.x += (x - o.x) * k;
17275 o.y += (y - o.y) * k;
17276 }
17277 }
17278 if (charge) {
17279 d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
17280 i = -1;
17281 while (++i < n) {
17282 if (!(o = nodes[i]).fixed) {
17283 q.visit(repulse(o));
17284 }
17285 }
17286 }
17287 i = -1;
17288 while (++i < n) {
17289 o = nodes[i];
17290 if (o.fixed) {
17291 o.x = o.px;
17292 o.y = o.py;
17293 } else {
17294 o.x -= (o.px - (o.px = o.x)) * friction;
17295 o.y -= (o.py - (o.py = o.y)) * friction;
17296 }
17297 }
17298 event.tick({
17299 type: "tick",
17300 alpha: alpha
17301 });
17302 };
17303 force.nodes = function(x) {
17304 if (!arguments.length) return nodes;
17305 nodes = x;
17306 return force;
17307 };
17308 force.links = function(x) {
17309 if (!arguments.length) return links;
17310 links = x;
17311 return force;
17312 };
17313 force.size = function(x) {
17314 if (!arguments.length) return size;
17315 size = x;
17316 return force;
17317 };
17318 force.linkDistance = function(x) {
17319 if (!arguments.length) return linkDistance;
17320 linkDistance = typeof x === "function" ? x : +x;
17321 return force;
17322 };
17323 force.distance = force.linkDistance;
17324 force.linkStrength = function(x) {
17325 if (!arguments.length) return linkStrength;
17326 linkStrength = typeof x === "function" ? x : +x;
17327 return force;
17328 };
17329 force.friction = function(x) {
17330 if (!arguments.length) return friction;
17331 friction = +x;
17332 return force;
17333 };
17334 force.charge = function(x) {
17335 if (!arguments.length) return charge;
17336 charge = typeof x === "function" ? x : +x;
17337 return force;
17338 };
17339 force.chargeDistance = function(x) {
17340 if (!arguments.length) return Math.sqrt(chargeDistance2);
17341 chargeDistance2 = x * x;
17342 return force;
17343 };
17344 force.gravity = function(x) {
17345 if (!arguments.length) return gravity;
17346 gravity = +x;
17347 return force;
17348 };
17349 force.theta = function(x) {
17350 if (!arguments.length) return Math.sqrt(theta2);
17351 theta2 = x * x;
17352 return force;
17353 };
17354 force.alpha = function(x) {
17355 if (!arguments.length) return alpha;
17356 x = +x;
17357 if (alpha) {
17358 if (x > 0) {
17359 alpha = x;
17360 } else {
17361 timer.c = null, timer.t = NaN, timer = null;
17362 event.end({
17363 type: "end",
17364 alpha: alpha = 0
17365 });
17366 }
17367 } else if (x > 0) {
17368 event.start({
17369 type: "start",
17370 alpha: alpha = x
17371 });
17372 timer = d3_timer(force.tick);
17373 }
17374 return force;
17375 };
17376 force.start = function() {
17377 var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
17378 for (i = 0; i < n; ++i) {
17379 (o = nodes[i]).index = i;
17380 o.weight = 0;
17381 }
17382 for (i = 0; i < m; ++i) {
17383 o = links[i];
17384 if (typeof o.source == "number") o.source = nodes[o.source];
17385 if (typeof o.target == "number") o.target = nodes[o.target];
17386 ++o.source.weight;
17387 ++o.target.weight;
17388 }
17389 for (i = 0; i < n; ++i) {
17390 o = nodes[i];
17391 if (isNaN(o.x)) o.x = position("x", w);
17392 if (isNaN(o.y)) o.y = position("y", h);
17393 if (isNaN(o.px)) o.px = o.x;
17394 if (isNaN(o.py)) o.py = o.y;
17395 }
17396 distances = [];
17397 if (typeof linkDistance === "function") for (i = 0; i < m; ++i) distances[i] = +linkDistance.call(this, links[i], i); else for (i = 0; i < m; ++i) distances[i] = linkDistance;
17398 strengths = [];
17399 if (typeof linkStrength === "function") for (i = 0; i < m; ++i) strengths[i] = +linkStrength.call(this, links[i], i); else for (i = 0; i < m; ++i) strengths[i] = linkStrength;
17400 charges = [];
17401 if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); else for (i = 0; i < n; ++i) charges[i] = charge;
17402 function position(dimension, size) {
17403 if (!neighbors) {
17404 neighbors = new Array(n);
17405 for (j = 0; j < n; ++j) {
17406 neighbors[j] = [];
17407 }
17408 for (j = 0; j < m; ++j) {
17409 var o = links[j];
17410 neighbors[o.source.index].push(o.target);
17411 neighbors[o.target.index].push(o.source);
17412 }
17413 }
17414 var candidates = neighbors[i], j = -1, l = candidates.length, x;
17415 while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
17416 return Math.random() * size;
17417 }
17418 return force.resume();
17419 };
17420 force.resume = function() {
17421 return force.alpha(.1);
17422 };
17423 force.stop = function() {
17424 return force.alpha(0);
17425 };
17426 force.drag = function() {
17427 if (!drag) drag = d3.behavior.drag().origin(d3_identity).on("dragstart.force", d3_layout_forceDragstart).on("drag.force", dragmove).on("dragend.force", d3_layout_forceDragend);
17428 if (!arguments.length) return drag;
17429 this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
17430 };
17431 function dragmove(d) {
17432 d.px = d3.event.x, d.py = d3.event.y;
17433 force.resume();
17434 }
17435 return d3.rebind(force, event, "on");
17436 };
17437 function d3_layout_forceDragstart(d) {
17438 d.fixed |= 2;
17439 }
17440 function d3_layout_forceDragend(d) {
17441 d.fixed &= ~6;
17442 }
17443 function d3_layout_forceMouseover(d) {
17444 d.fixed |= 4;
17445 d.px = d.x, d.py = d.y;
17446 }
17447 function d3_layout_forceMouseout(d) {
17448 d.fixed &= ~4;
17449 }
17450 function d3_layout_forceAccumulate(quad, alpha, charges) {
17451 var cx = 0, cy = 0;
17452 quad.charge = 0;
17453 if (!quad.leaf) {
17454 var nodes = quad.nodes, n = nodes.length, i = -1, c;
17455 while (++i < n) {
17456 c = nodes[i];
17457 if (c == null) continue;
17458 d3_layout_forceAccumulate(c, alpha, charges);
17459 quad.charge += c.charge;
17460 cx += c.charge * c.cx;
17461 cy += c.charge * c.cy;
17462 }
17463 }
17464 if (quad.point) {
17465 if (!quad.leaf) {
17466 quad.point.x += Math.random() - .5;
17467 quad.point.y += Math.random() - .5;
17468 }
17469 var k = alpha * charges[quad.point.index];
17470 quad.charge += quad.pointCharge = k;
17471 cx += k * quad.point.x;
17472 cy += k * quad.point.y;
17473 }
17474 quad.cx = cx / quad.charge;
17475 quad.cy = cy / quad.charge;
17476 }
17477 var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
17478 d3.layout.hierarchy = function() {
17479 var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
17480 function hierarchy(root) {
17481 var stack = [ root ], nodes = [], node;
17482 root.depth = 0;
17483 while ((node = stack.pop()) != null) {
17484 nodes.push(node);
17485 if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
17486 var n, childs, child;
17487 while (--n >= 0) {
17488 stack.push(child = childs[n]);
17489 child.parent = node;
17490 child.depth = node.depth + 1;
17491 }
17492 if (value) node.value = 0;
17493 node.children = childs;
17494 } else {
17495 if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
17496 delete node.children;
17497 }
17498 }
17499 d3_layout_hierarchyVisitAfter(root, function(node) {
17500 var childs, parent;
17501 if (sort && (childs = node.children)) childs.sort(sort);
17502 if (value && (parent = node.parent)) parent.value += node.value;
17503 });
17504 return nodes;
17505 }
17506 hierarchy.sort = function(x) {
17507 if (!arguments.length) return sort;
17508 sort = x;
17509 return hierarchy;
17510 };
17511 hierarchy.children = function(x) {
17512 if (!arguments.length) return children;
17513 children = x;
17514 return hierarchy;
17515 };
17516 hierarchy.value = function(x) {
17517 if (!arguments.length) return value;
17518 value = x;
17519 return hierarchy;
17520 };
17521 hierarchy.revalue = function(root) {
17522 if (value) {
17523 d3_layout_hierarchyVisitBefore(root, function(node) {
17524 if (node.children) node.value = 0;
17525 });
17526 d3_layout_hierarchyVisitAfter(root, function(node) {
17527 var parent;
17528 if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
17529 if (parent = node.parent) parent.value += node.value;
17530 });
17531 }
17532 return root;
17533 };
17534 return hierarchy;
17535 };
17536 function d3_layout_hierarchyRebind(object, hierarchy) {
17537 d3.rebind(object, hierarchy, "sort", "children", "value");
17538 object.nodes = object;
17539 object.links = d3_layout_hierarchyLinks;
17540 return object;
17541 }
17542 function d3_layout_hierarchyVisitBefore(node, callback) {
17543 var nodes = [ node ];
17544 while ((node = nodes.pop()) != null) {
17545 callback(node);
17546 if ((children = node.children) && (n = children.length)) {
17547 var n, children;
17548 while (--n >= 0) nodes.push(children[n]);
17549 }
17550 }
17551 }
17552 function d3_layout_hierarchyVisitAfter(node, callback) {
17553 var nodes = [ node ], nodes2 = [];
17554 while ((node = nodes.pop()) != null) {
17555 nodes2.push(node);
17556 if ((children = node.children) && (n = children.length)) {
17557 var i = -1, n, children;
17558 while (++i < n) nodes.push(children[i]);
17559 }
17560 }
17561 while ((node = nodes2.pop()) != null) {
17562 callback(node);
17563 }
17564 }
17565 function d3_layout_hierarchyChildren(d) {
17566 return d.children;
17567 }
17568 function d3_layout_hierarchyValue(d) {
17569 return d.value;
17570 }
17571 function d3_layout_hierarchySort(a, b) {
17572 return b.value - a.value;
17573 }
17574 function d3_layout_hierarchyLinks(nodes) {
17575 return d3.merge(nodes.map(function(parent) {
17576 return (parent.children || []).map(function(child) {
17577 return {
17578 source: parent,
17579 target: child
17580 };
17581 });
17582 }));
17583 }
17584 d3.layout.partition = function() {
17585 var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
17586 function position(node, x, dx, dy) {
17587 var children = node.children;
17588 node.x = x;
17589 node.y = node.depth * dy;
17590 node.dx = dx;
17591 node.dy = dy;
17592 if (children && (n = children.length)) {
17593 var i = -1, n, c, d;
17594 dx = node.value ? dx / node.value : 0;
17595 while (++i < n) {
17596 position(c = children[i], x, d = c.value * dx, dy);
17597 x += d;
17598 }
17599 }
17600 }
17601 function depth(node) {
17602 var children = node.children, d = 0;
17603 if (children && (n = children.length)) {
17604 var i = -1, n;
17605 while (++i < n) d = Math.max(d, depth(children[i]));
17606 }
17607 return 1 + d;
17608 }
17609 function partition(d, i) {
17610 var nodes = hierarchy.call(this, d, i);
17611 position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
17612 return nodes;
17613 }
17614 partition.size = function(x) {
17615 if (!arguments.length) return size;
17616 size = x;
17617 return partition;
17618 };
17619 return d3_layout_hierarchyRebind(partition, hierarchy);
17620 };
17621 d3.layout.pie = function() {
17622 var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
17623 function pie(data) {
17624 var n = data.length, values = data.map(function(d, i) {
17625 return +value.call(pie, d, i);
17626 }), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), sum = d3.sum(values), k = sum ? (da - n * pa) / sum : 0, index = d3.range(n), arcs = [], v;
17627 if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
17628 return values[j] - values[i];
17629 } : function(i, j) {
17630 return sort(data[i], data[j]);
17631 });
17632 index.forEach(function(i) {
17633 arcs[i] = {
17634 data: data[i],
17635 value: v = values[i],
17636 startAngle: a,
17637 endAngle: a += v * k + pa,
17638 padAngle: p
17639 };
17640 });
17641 return arcs;
17642 }
17643 pie.value = function(_) {
17644 if (!arguments.length) return value;
17645 value = _;
17646 return pie;
17647 };
17648 pie.sort = function(_) {
17649 if (!arguments.length) return sort;
17650 sort = _;
17651 return pie;
17652 };
17653 pie.startAngle = function(_) {
17654 if (!arguments.length) return startAngle;
17655 startAngle = _;
17656 return pie;
17657 };
17658 pie.endAngle = function(_) {
17659 if (!arguments.length) return endAngle;
17660 endAngle = _;
17661 return pie;
17662 };
17663 pie.padAngle = function(_) {
17664 if (!arguments.length) return padAngle;
17665 padAngle = _;
17666 return pie;
17667 };
17668 return pie;
17669 };
17670 var d3_layout_pieSortByValue = {};
17671 d3.layout.stack = function() {
17672 var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
17673 function stack(data, index) {
17674 if (!(n = data.length)) return data;
17675 var series = data.map(function(d, i) {
17676 return values.call(stack, d, i);
17677 });
17678 var points = series.map(function(d) {
17679 return d.map(function(v, i) {
17680 return [ x.call(stack, v, i), y.call(stack, v, i) ];
17681 });
17682 });
17683 var orders = order.call(stack, points, index);
17684 series = d3.permute(series, orders);
17685 points = d3.permute(points, orders);
17686 var offsets = offset.call(stack, points, index);
17687 var m = series[0].length, n, i, j, o;
17688 for (j = 0; j < m; ++j) {
17689 out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
17690 for (i = 1; i < n; ++i) {
17691 out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
17692 }
17693 }
17694 return data;
17695 }
17696 stack.values = function(x) {
17697 if (!arguments.length) return values;
17698 values = x;
17699 return stack;
17700 };
17701 stack.order = function(x) {
17702 if (!arguments.length) return order;
17703 order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
17704 return stack;
17705 };
17706 stack.offset = function(x) {
17707 if (!arguments.length) return offset;
17708 offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
17709 return stack;
17710 };
17711 stack.x = function(z) {
17712 if (!arguments.length) return x;
17713 x = z;
17714 return stack;
17715 };
17716 stack.y = function(z) {
17717 if (!arguments.length) return y;
17718 y = z;
17719 return stack;
17720 };
17721 stack.out = function(z) {
17722 if (!arguments.length) return out;
17723 out = z;
17724 return stack;
17725 };
17726 return stack;
17727 };
17728 function d3_layout_stackX(d) {
17729 return d.x;
17730 }
17731 function d3_layout_stackY(d) {
17732 return d.y;
17733 }
17734 function d3_layout_stackOut(d, y0, y) {
17735 d.y0 = y0;
17736 d.y = y;
17737 }
17738 var d3_layout_stackOrders = d3.map({
17739 "inside-out": function(data) {
17740 var n = data.length, i, j, max = data.map(d3_layout_stackMaxIndex), sums = data.map(d3_layout_stackReduceSum), index = d3.range(n).sort(function(a, b) {
17741 return max[a] - max[b];
17742 }), top = 0, bottom = 0, tops = [], bottoms = [];
17743 for (i = 0; i < n; ++i) {
17744 j = index[i];
17745 if (top < bottom) {
17746 top += sums[j];
17747 tops.push(j);
17748 } else {
17749 bottom += sums[j];
17750 bottoms.push(j);
17751 }
17752 }
17753 return bottoms.reverse().concat(tops);
17754 },
17755 reverse: function(data) {
17756 return d3.range(data.length).reverse();
17757 },
17758 "default": d3_layout_stackOrderDefault
17759 });
17760 var d3_layout_stackOffsets = d3.map({
17761 silhouette: function(data) {
17762 var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
17763 for (j = 0; j < m; ++j) {
17764 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
17765 if (o > max) max = o;
17766 sums.push(o);
17767 }
17768 for (j = 0; j < m; ++j) {
17769 y0[j] = (max - sums[j]) / 2;
17770 }
17771 return y0;
17772 },
17773 wiggle: function(data) {
17774 var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
17775 y0[0] = o = o0 = 0;
17776 for (j = 1; j < m; ++j) {
17777 for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
17778 for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
17779 for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
17780 s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
17781 }
17782 s2 += s3 * data[i][j][1];
17783 }
17784 y0[j] = o -= s1 ? s2 / s1 * dx : 0;
17785 if (o < o0) o0 = o;
17786 }
17787 for (j = 0; j < m; ++j) y0[j] -= o0;
17788 return y0;
17789 },
17790 expand: function(data) {
17791 var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
17792 for (j = 0; j < m; ++j) {
17793 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
17794 if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k;
17795 }
17796 for (j = 0; j < m; ++j) y0[j] = 0;
17797 return y0;
17798 },
17799 zero: d3_layout_stackOffsetZero
17800 });
17801 function d3_layout_stackOrderDefault(data) {
17802 return d3.range(data.length);
17803 }
17804 function d3_layout_stackOffsetZero(data) {
17805 var j = -1, m = data[0].length, y0 = [];
17806 while (++j < m) y0[j] = 0;
17807 return y0;
17808 }
17809 function d3_layout_stackMaxIndex(array) {
17810 var i = 1, j = 0, v = array[0][1], k, n = array.length;
17811 for (;i < n; ++i) {
17812 if ((k = array[i][1]) > v) {
17813 j = i;
17814 v = k;
17815 }
17816 }
17817 return j;
17818 }
17819 function d3_layout_stackReduceSum(d) {
17820 return d.reduce(d3_layout_stackSum, 0);
17821 }
17822 function d3_layout_stackSum(p, d) {
17823 return p + d[1];
17824 }
17825 d3.layout.histogram = function() {
17826 var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
17827 function histogram(data, i) {
17828 var bins = [], values = data.map(valuer, this), range = ranger.call(this, values, i), thresholds = binner.call(this, range, values, i), bin, i = -1, n = values.length, m = thresholds.length - 1, k = frequency ? 1 : 1 / n, x;
17829 while (++i < m) {
17830 bin = bins[i] = [];
17831 bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
17832 bin.y = 0;
17833 }
17834 if (m > 0) {
17835 i = -1;
17836 while (++i < n) {
17837 x = values[i];
17838 if (x >= range[0] && x <= range[1]) {
17839 bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
17840 bin.y += k;
17841 bin.push(data[i]);
17842 }
17843 }
17844 }
17845 return bins;
17846 }
17847 histogram.value = function(x) {
17848 if (!arguments.length) return valuer;
17849 valuer = x;
17850 return histogram;
17851 };
17852 histogram.range = function(x) {
17853 if (!arguments.length) return ranger;
17854 ranger = d3_functor(x);
17855 return histogram;
17856 };
17857 histogram.bins = function(x) {
17858 if (!arguments.length) return binner;
17859 binner = typeof x === "number" ? function(range) {
17860 return d3_layout_histogramBinFixed(range, x);
17861 } : d3_functor(x);
17862 return histogram;
17863 };
17864 histogram.frequency = function(x) {
17865 if (!arguments.length) return frequency;
17866 frequency = !!x;
17867 return histogram;
17868 };
17869 return histogram;
17870 };
17871 function d3_layout_histogramBinSturges(range, values) {
17872 return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
17873 }
17874 function d3_layout_histogramBinFixed(range, n) {
17875 var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
17876 while (++x <= n) f[x] = m * x + b;
17877 return f;
17878 }
17879 function d3_layout_histogramRange(values) {
17880 return [ d3.min(values), d3.max(values) ];
17881 }
17882 d3.layout.pack = function() {
17883 var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
17884 function pack(d, i) {
17885 var nodes = hierarchy.call(this, d, i), root = nodes[0], w = size[0], h = size[1], r = radius == null ? Math.sqrt : typeof radius === "function" ? radius : function() {
17886 return radius;
17887 };
17888 root.x = root.y = 0;
17889 d3_layout_hierarchyVisitAfter(root, function(d) {
17890 d.r = +r(d.value);
17891 });
17892 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
17893 if (padding) {
17894 var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
17895 d3_layout_hierarchyVisitAfter(root, function(d) {
17896 d.r += dr;
17897 });
17898 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
17899 d3_layout_hierarchyVisitAfter(root, function(d) {
17900 d.r -= dr;
17901 });
17902 }
17903 d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
17904 return nodes;
17905 }
17906 pack.size = function(_) {
17907 if (!arguments.length) return size;
17908 size = _;
17909 return pack;
17910 };
17911 pack.radius = function(_) {
17912 if (!arguments.length) return radius;
17913 radius = _ == null || typeof _ === "function" ? _ : +_;
17914 return pack;
17915 };
17916 pack.padding = function(_) {
17917 if (!arguments.length) return padding;
17918 padding = +_;
17919 return pack;
17920 };
17921 return d3_layout_hierarchyRebind(pack, hierarchy);
17922 };
17923 function d3_layout_packSort(a, b) {
17924 return a.value - b.value;
17925 }
17926 function d3_layout_packInsert(a, b) {
17927 var c = a._pack_next;
17928 a._pack_next = b;
17929 b._pack_prev = a;
17930 b._pack_next = c;
17931 c._pack_prev = b;
17932 }
17933 function d3_layout_packSplice(a, b) {
17934 a._pack_next = b;
17935 b._pack_prev = a;
17936 }
17937 function d3_layout_packIntersects(a, b) {
17938 var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
17939 return .999 * dr * dr > dx * dx + dy * dy;
17940 }
17941 function d3_layout_packSiblings(node) {
17942 if (!(nodes = node.children) || !(n = nodes.length)) return;
17943 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
17944 function bound(node) {
17945 xMin = Math.min(node.x - node.r, xMin);
17946 xMax = Math.max(node.x + node.r, xMax);
17947 yMin = Math.min(node.y - node.r, yMin);
17948 yMax = Math.max(node.y + node.r, yMax);
17949 }
17950 nodes.forEach(d3_layout_packLink);
17951 a = nodes[0];
17952 a.x = -a.r;
17953 a.y = 0;
17954 bound(a);
17955 if (n > 1) {
17956 b = nodes[1];
17957 b.x = b.r;
17958 b.y = 0;
17959 bound(b);
17960 if (n > 2) {
17961 c = nodes[2];
17962 d3_layout_packPlace(a, b, c);
17963 bound(c);
17964 d3_layout_packInsert(a, c);
17965 a._pack_prev = c;
17966 d3_layout_packInsert(c, b);
17967 b = a._pack_next;
17968 for (i = 3; i < n; i++) {
17969 d3_layout_packPlace(a, b, c = nodes[i]);
17970 var isect = 0, s1 = 1, s2 = 1;
17971 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
17972 if (d3_layout_packIntersects(j, c)) {
17973 isect = 1;
17974 break;
17975 }
17976 }
17977 if (isect == 1) {
17978 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
17979 if (d3_layout_packIntersects(k, c)) {
17980 break;
17981 }
17982 }
17983 }
17984 if (isect) {
17985 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
17986 i--;
17987 } else {
17988 d3_layout_packInsert(a, c);
17989 b = c;
17990 bound(c);
17991 }
17992 }
17993 }
17994 }
17995 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
17996 for (i = 0; i < n; i++) {
17997 c = nodes[i];
17998 c.x -= cx;
17999 c.y -= cy;
18000 cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
18001 }
18002 node.r = cr;
18003 nodes.forEach(d3_layout_packUnlink);
18004 }
18005 function d3_layout_packLink(node) {
18006 node._pack_next = node._pack_prev = node;
18007 }
18008 function d3_layout_packUnlink(node) {
18009 delete node._pack_next;
18010 delete node._pack_prev;
18011 }
18012 function d3_layout_packTransform(node, x, y, k) {
18013 var children = node.children;
18014 node.x = x += k * node.x;
18015 node.y = y += k * node.y;
18016 node.r *= k;
18017 if (children) {
18018 var i = -1, n = children.length;
18019 while (++i < n) d3_layout_packTransform(children[i], x, y, k);
18020 }
18021 }
18022 function d3_layout_packPlace(a, b, c) {
18023 var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
18024 if (db && (dx || dy)) {
18025 var da = b.r + c.r, dc = dx * dx + dy * dy;
18026 da *= da;
18027 db *= db;
18028 var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
18029 c.x = a.x + x * dx + y * dy;
18030 c.y = a.y + x * dy - y * dx;
18031 } else {
18032 c.x = a.x + db;
18033 c.y = a.y;
18034 }
18035 }
18036 d3.layout.tree = function() {
18037 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
18038 function tree(d, i) {
18039 var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
18040 d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
18041 d3_layout_hierarchyVisitBefore(root1, secondWalk);
18042 if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
18043 var left = root0, right = root0, bottom = root0;
18044 d3_layout_hierarchyVisitBefore(root0, function(node) {
18045 if (node.x < left.x) left = node;
18046 if (node.x > right.x) right = node;
18047 if (node.depth > bottom.depth) bottom = node;
18048 });
18049 var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
18050 d3_layout_hierarchyVisitBefore(root0, function(node) {
18051 node.x = (node.x + tx) * kx;
18052 node.y = node.depth * ky;
18053 });
18054 }
18055 return nodes;
18056 }
18057 function wrapTree(root0) {
18058 var root1 = {
18059 A: null,
18060 children: [ root0 ]
18061 }, queue = [ root1 ], node1;
18062 while ((node1 = queue.pop()) != null) {
18063 for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
18064 queue.push((children[i] = child = {
18065 _: children[i],
18066 parent: node1,
18067 children: (child = children[i].children) && child.slice() || [],
18068 A: null,
18069 a: null,
18070 z: 0,
18071 m: 0,
18072 c: 0,
18073 s: 0,
18074 t: null,
18075 i: i
18076 }).a = child);
18077 }
18078 }
18079 return root1.children[0];
18080 }
18081 function firstWalk(v) {
18082 var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
18083 if (children.length) {
18084 d3_layout_treeShift(v);
18085 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
18086 if (w) {
18087 v.z = w.z + separation(v._, w._);
18088 v.m = v.z - midpoint;
18089 } else {
18090 v.z = midpoint;
18091 }
18092 } else if (w) {
18093 v.z = w.z + separation(v._, w._);
18094 }
18095 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
18096 }
18097 function secondWalk(v) {
18098 v._.x = v.z + v.parent.m;
18099 v.m += v.parent.m;
18100 }
18101 function apportion(v, w, ancestor) {
18102 if (w) {
18103 var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift;
18104 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
18105 vom = d3_layout_treeLeft(vom);
18106 vop = d3_layout_treeRight(vop);
18107 vop.a = v;
18108 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
18109 if (shift > 0) {
18110 d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
18111 sip += shift;
18112 sop += shift;
18113 }
18114 sim += vim.m;
18115 sip += vip.m;
18116 som += vom.m;
18117 sop += vop.m;
18118 }
18119 if (vim && !d3_layout_treeRight(vop)) {
18120 vop.t = vim;
18121 vop.m += sim - sop;
18122 }
18123 if (vip && !d3_layout_treeLeft(vom)) {
18124 vom.t = vip;
18125 vom.m += sip - som;
18126 ancestor = v;
18127 }
18128 }
18129 return ancestor;
18130 }
18131 function sizeNode(node) {
18132 node.x *= size[0];
18133 node.y = node.depth * size[1];
18134 }
18135 tree.separation = function(x) {
18136 if (!arguments.length) return separation;
18137 separation = x;
18138 return tree;
18139 };
18140 tree.size = function(x) {
18141 if (!arguments.length) return nodeSize ? null : size;
18142 nodeSize = (size = x) == null ? sizeNode : null;
18143 return tree;
18144 };
18145 tree.nodeSize = function(x) {
18146 if (!arguments.length) return nodeSize ? size : null;
18147 nodeSize = (size = x) == null ? null : sizeNode;
18148 return tree;
18149 };
18150 return d3_layout_hierarchyRebind(tree, hierarchy);
18151 };
18152 function d3_layout_treeSeparation(a, b) {
18153 return a.parent == b.parent ? 1 : 2;
18154 }
18155 function d3_layout_treeLeft(v) {
18156 var children = v.children;
18157 return children.length ? children[0] : v.t;
18158 }
18159 function d3_layout_treeRight(v) {
18160 var children = v.children, n;
18161 return (n = children.length) ? children[n - 1] : v.t;
18162 }
18163 function d3_layout_treeMove(wm, wp, shift) {
18164 var change = shift / (wp.i - wm.i);
18165 wp.c -= change;
18166 wp.s += shift;
18167 wm.c += change;
18168 wp.z += shift;
18169 wp.m += shift;
18170 }
18171 function d3_layout_treeShift(v) {
18172 var shift = 0, change = 0, children = v.children, i = children.length, w;
18173 while (--i >= 0) {
18174 w = children[i];
18175 w.z += shift;
18176 w.m += shift;
18177 shift += w.s + (change += w.c);
18178 }
18179 }
18180 function d3_layout_treeAncestor(vim, v, ancestor) {
18181 return vim.a.parent === v.parent ? vim.a : ancestor;
18182 }
18183 d3.layout.cluster = function() {
18184 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
18185 function cluster(d, i) {
18186 var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
18187 d3_layout_hierarchyVisitAfter(root, function(node) {
18188 var children = node.children;
18189 if (children && children.length) {
18190 node.x = d3_layout_clusterX(children);
18191 node.y = d3_layout_clusterY(children);
18192 } else {
18193 node.x = previousNode ? x += separation(node, previousNode) : 0;
18194 node.y = 0;
18195 previousNode = node;
18196 }
18197 });
18198 var left = d3_layout_clusterLeft(root), right = d3_layout_clusterRight(root), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2;
18199 d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
18200 node.x = (node.x - root.x) * size[0];
18201 node.y = (root.y - node.y) * size[1];
18202 } : function(node) {
18203 node.x = (node.x - x0) / (x1 - x0) * size[0];
18204 node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
18205 });
18206 return nodes;
18207 }
18208 cluster.separation = function(x) {
18209 if (!arguments.length) return separation;
18210 separation = x;
18211 return cluster;
18212 };
18213 cluster.size = function(x) {
18214 if (!arguments.length) return nodeSize ? null : size;
18215 nodeSize = (size = x) == null;
18216 return cluster;
18217 };
18218 cluster.nodeSize = function(x) {
18219 if (!arguments.length) return nodeSize ? size : null;
18220 nodeSize = (size = x) != null;
18221 return cluster;
18222 };
18223 return d3_layout_hierarchyRebind(cluster, hierarchy);
18224 };
18225 function d3_layout_clusterY(children) {
18226 return 1 + d3.max(children, function(child) {
18227 return child.y;
18228 });
18229 }
18230 function d3_layout_clusterX(children) {
18231 return children.reduce(function(x, child) {
18232 return x + child.x;
18233 }, 0) / children.length;
18234 }
18235 function d3_layout_clusterLeft(node) {
18236 var children = node.children;
18237 return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
18238 }
18239 function d3_layout_clusterRight(node) {
18240 var children = node.children, n;
18241 return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
18242 }
18243 d3.layout.treemap = function() {
18244 var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, mode = "squarify", ratio = .5 * (1 + Math.sqrt(5));
18245 function scale(children, k) {
18246 var i = -1, n = children.length, child, area;
18247 while (++i < n) {
18248 area = (child = children[i]).value * (k < 0 ? 0 : k);
18249 child.area = isNaN(area) || area <= 0 ? 0 : area;
18250 }
18251 }
18252 function squarify(node) {
18253 var children = node.children;
18254 if (children && children.length) {
18255 var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" ? rect.dy : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx : Math.min(rect.dx, rect.dy), n;
18256 scale(remaining, rect.dx * rect.dy / node.value);
18257 row.area = 0;
18258 while ((n = remaining.length) > 0) {
18259 row.push(child = remaining[n - 1]);
18260 row.area += child.area;
18261 if (mode !== "squarify" || (score = worst(row, u)) <= best) {
18262 remaining.pop();
18263 best = score;
18264 } else {
18265 row.area -= row.pop().area;
18266 position(row, u, rect, false);
18267 u = Math.min(rect.dx, rect.dy);
18268 row.length = row.area = 0;
18269 best = Infinity;
18270 }
18271 }
18272 if (row.length) {
18273 position(row, u, rect, true);
18274 row.length = row.area = 0;
18275 }
18276 children.forEach(squarify);
18277 }
18278 }
18279 function stickify(node) {
18280 var children = node.children;
18281 if (children && children.length) {
18282 var rect = pad(node), remaining = children.slice(), child, row = [];
18283 scale(remaining, rect.dx * rect.dy / node.value);
18284 row.area = 0;
18285 while (child = remaining.pop()) {
18286 row.push(child);
18287 row.area += child.area;
18288 if (child.z != null) {
18289 position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
18290 row.length = row.area = 0;
18291 }
18292 }
18293 children.forEach(stickify);
18294 }
18295 }
18296 function worst(row, u) {
18297 var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
18298 while (++i < n) {
18299 if (!(r = row[i].area)) continue;
18300 if (r < rmin) rmin = r;
18301 if (r > rmax) rmax = r;
18302 }
18303 s *= s;
18304 u *= u;
18305 return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
18306 }
18307 function position(row, u, rect, flush) {
18308 var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
18309 if (u == rect.dx) {
18310 if (flush || v > rect.dy) v = rect.dy;
18311 while (++i < n) {
18312 o = row[i];
18313 o.x = x;
18314 o.y = y;
18315 o.dy = v;
18316 x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
18317 }
18318 o.z = true;
18319 o.dx += rect.x + rect.dx - x;
18320 rect.y += v;
18321 rect.dy -= v;
18322 } else {
18323 if (flush || v > rect.dx) v = rect.dx;
18324 while (++i < n) {
18325 o = row[i];
18326 o.x = x;
18327 o.y = y;
18328 o.dx = v;
18329 y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
18330 }
18331 o.z = false;
18332 o.dy += rect.y + rect.dy - y;
18333 rect.x += v;
18334 rect.dx -= v;
18335 }
18336 }
18337 function treemap(d) {
18338 var nodes = stickies || hierarchy(d), root = nodes[0];
18339 root.x = root.y = 0;
18340 if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;
18341 if (stickies) hierarchy.revalue(root);
18342 scale([ root ], root.dx * root.dy / root.value);
18343 (stickies ? stickify : squarify)(root);
18344 if (sticky) stickies = nodes;
18345 return nodes;
18346 }
18347 treemap.size = function(x) {
18348 if (!arguments.length) return size;
18349 size = x;
18350 return treemap;
18351 };
18352 treemap.padding = function(x) {
18353 if (!arguments.length) return padding;
18354 function padFunction(node) {
18355 var p = x.call(treemap, node, node.depth);
18356 return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
18357 }
18358 function padConstant(node) {
18359 return d3_layout_treemapPad(node, x);
18360 }
18361 var type;
18362 pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
18363 padConstant) : padConstant;
18364 return treemap;
18365 };
18366 treemap.round = function(x) {
18367 if (!arguments.length) return round != Number;
18368 round = x ? Math.round : Number;
18369 return treemap;
18370 };
18371 treemap.sticky = function(x) {
18372 if (!arguments.length) return sticky;
18373 sticky = x;
18374 stickies = null;
18375 return treemap;
18376 };
18377 treemap.ratio = function(x) {
18378 if (!arguments.length) return ratio;
18379 ratio = x;
18380 return treemap;
18381 };
18382 treemap.mode = function(x) {
18383 if (!arguments.length) return mode;
18384 mode = x + "";
18385 return treemap;
18386 };
18387 return d3_layout_hierarchyRebind(treemap, hierarchy);
18388 };
18389 function d3_layout_treemapPadNull(node) {
18390 return {
18391 x: node.x,
18392 y: node.y,
18393 dx: node.dx,
18394 dy: node.dy
18395 };
18396 }
18397 function d3_layout_treemapPad(node, padding) {
18398 var x = node.x + padding[3], y = node.y + padding[0], dx = node.dx - padding[1] - padding[3], dy = node.dy - padding[0] - padding[2];
18399 if (dx < 0) {
18400 x += dx / 2;
18401 dx = 0;
18402 }
18403 if (dy < 0) {
18404 y += dy / 2;
18405 dy = 0;
18406 }
18407 return {
18408 x: x,
18409 y: y,
18410 dx: dx,
18411 dy: dy
18412 };
18413 }
18414 d3.random = {
18415 normal: function(µ, σ) {
18416 var n = arguments.length;
18417 if (n < 2) σ = 1;
18418 if (n < 1) µ = 0;
18419 return function() {
18420 var x, y, r;
18421 do {
18422 x = Math.random() * 2 - 1;
18423 y = Math.random() * 2 - 1;
18424 r = x * x + y * y;
18425 } while (!r || r > 1);
18426 return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
18427 };
18428 },
18429 logNormal: function() {
18430 var random = d3.random.normal.apply(d3, arguments);
18431 return function() {
18432 return Math.exp(random());
18433 };
18434 },
18435 bates: function(m) {
18436 var random = d3.random.irwinHall(m);
18437 return function() {
18438 return random() / m;
18439 };
18440 },
18441 irwinHall: function(m) {
18442 return function() {
18443 for (var s = 0, j = 0; j < m; j++) s += Math.random();
18444 return s;
18445 };
18446 }
18447 };
18448 d3.scale = {};
18449 function d3_scaleExtent(domain) {
18450 var start = domain[0], stop = domain[domain.length - 1];
18451 return start < stop ? [ start, stop ] : [ stop, start ];
18452 }
18453 function d3_scaleRange(scale) {
18454 return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
18455 }
18456 function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
18457 var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
18458 return function(x) {
18459 return i(u(x));
18460 };
18461 }
18462 function d3_scale_nice(domain, nice) {
18463 var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
18464 if (x1 < x0) {
18465 dx = i0, i0 = i1, i1 = dx;
18466 dx = x0, x0 = x1, x1 = dx;
18467 }
18468 domain[i0] = nice.floor(x0);
18469 domain[i1] = nice.ceil(x1);
18470 return domain;
18471 }
18472 function d3_scale_niceStep(step) {
18473 return step ? {
18474 floor: function(x) {
18475 return Math.floor(x / step) * step;
18476 },
18477 ceil: function(x) {
18478 return Math.ceil(x / step) * step;
18479 }
18480 } : d3_scale_niceIdentity;
18481 }
18482 var d3_scale_niceIdentity = {
18483 floor: d3_identity,
18484 ceil: d3_identity
18485 };
18486 function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
18487 var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
18488 if (domain[k] < domain[0]) {
18489 domain = domain.slice().reverse();
18490 range = range.slice().reverse();
18491 }
18492 while (++j <= k) {
18493 u.push(uninterpolate(domain[j - 1], domain[j]));
18494 i.push(interpolate(range[j - 1], range[j]));
18495 }
18496 return function(x) {
18497 var j = d3.bisect(domain, x, 1, k) - 1;
18498 return i[j](u[j](x));
18499 };
18500 }
18501 d3.scale.linear = function() {
18502 return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
18503 };
18504 function d3_scale_linear(domain, range, interpolate, clamp) {
18505 var output, input;
18506 function rescale() {
18507 var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
18508 output = linear(domain, range, uninterpolate, interpolate);
18509 input = linear(range, domain, uninterpolate, d3_interpolate);
18510 return scale;
18511 }
18512 function scale(x) {
18513 return output(x);
18514 }
18515 scale.invert = function(y) {
18516 return input(y);
18517 };
18518 scale.domain = function(x) {
18519 if (!arguments.length) return domain;
18520 domain = x.map(Number);
18521 return rescale();
18522 };
18523 scale.range = function(x) {
18524 if (!arguments.length) return range;
18525 range = x;
18526 return rescale();
18527 };
18528 scale.rangeRound = function(x) {
18529 return scale.range(x).interpolate(d3_interpolateRound);
18530 };
18531 scale.clamp = function(x) {
18532 if (!arguments.length) return clamp;
18533 clamp = x;
18534 return rescale();
18535 };
18536 scale.interpolate = function(x) {
18537 if (!arguments.length) return interpolate;
18538 interpolate = x;
18539 return rescale();
18540 };
18541 scale.ticks = function(m) {
18542 return d3_scale_linearTicks(domain, m);
18543 };
18544 scale.tickFormat = function(m, format) {
18545 return d3_scale_linearTickFormat(domain, m, format);
18546 };
18547 scale.nice = function(m) {
18548 d3_scale_linearNice(domain, m);
18549 return rescale();
18550 };
18551 scale.copy = function() {
18552 return d3_scale_linear(domain, range, interpolate, clamp);
18553 };
18554 return rescale();
18555 }
18556 function d3_scale_linearRebind(scale, linear) {
18557 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
18558 }
18559 function d3_scale_linearNice(domain, m) {
18560 d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
18561 d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
18562 return domain;
18563 }
18564 function d3_scale_linearTickRange(domain, m) {
18565 if (m == null) m = 10;
18566 var extent = d3_scaleExtent(domain), span = extent[1] - extent[0], step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)), err = m / span * step;
18567 if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
18568 extent[0] = Math.ceil(extent[0] / step) * step;
18569 extent[1] = Math.floor(extent[1] / step) * step + step * .5;
18570 extent[2] = step;
18571 return extent;
18572 }
18573 function d3_scale_linearTicks(domain, m) {
18574 return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
18575 }
18576 function d3_scale_linearTickFormat(domain, m, format) {
18577 var range = d3_scale_linearTickRange(domain, m);
18578 if (format) {
18579 var match = d3_format_re.exec(format);
18580 match.shift();
18581 if (match[8] === "s") {
18582 var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
18583 if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
18584 match[8] = "f";
18585 format = d3.format(match.join(""));
18586 return function(d) {
18587 return format(prefix.scale(d)) + prefix.symbol;
18588 };
18589 }
18590 if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
18591 format = match.join("");
18592 } else {
18593 format = ",." + d3_scale_linearPrecision(range[2]) + "f";
18594 }
18595 return d3.format(format);
18596 }
18597 var d3_scale_linearFormatSignificant = {
18598 s: 1,
18599 g: 1,
18600 p: 1,
18601 r: 1,
18602 e: 1
18603 };
18604 function d3_scale_linearPrecision(value) {
18605 return -Math.floor(Math.log(value) / Math.LN10 + .01);
18606 }
18607 function d3_scale_linearFormatPrecision(type, range) {
18608 var p = d3_scale_linearPrecision(range[2]);
18609 return type in d3_scale_linearFormatSignificant ? Math.abs(p - d3_scale_linearPrecision(Math.max(abs(range[0]), abs(range[1])))) + +(type !== "e") : p - (type === "%") * 2;
18610 }
18611 d3.scale.log = function() {
18612 return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
18613 };
18614 function d3_scale_log(linear, base, positive, domain) {
18615 function log(x) {
18616 return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
18617 }
18618 function pow(x) {
18619 return positive ? Math.pow(base, x) : -Math.pow(base, -x);
18620 }
18621 function scale(x) {
18622 return linear(log(x));
18623 }
18624 scale.invert = function(x) {
18625 return pow(linear.invert(x));
18626 };
18627 scale.domain = function(x) {
18628 if (!arguments.length) return domain;
18629 positive = x[0] >= 0;
18630 linear.domain((domain = x.map(Number)).map(log));
18631 return scale;
18632 };
18633 scale.base = function(_) {
18634 if (!arguments.length) return base;
18635 base = +_;
18636 linear.domain(domain.map(log));
18637 return scale;
18638 };
18639 scale.nice = function() {
18640 var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
18641 linear.domain(niced);
18642 domain = niced.map(pow);
18643 return scale;
18644 };
18645 scale.ticks = function() {
18646 var extent = d3_scaleExtent(domain), ticks = [], u = extent[0], v = extent[1], i = Math.floor(log(u)), j = Math.ceil(log(v)), n = base % 1 ? 2 : base;
18647 if (isFinite(j - i)) {
18648 if (positive) {
18649 for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
18650 ticks.push(pow(i));
18651 } else {
18652 ticks.push(pow(i));
18653 for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
18654 }
18655 for (i = 0; ticks[i] < u; i++) {}
18656 for (j = ticks.length; ticks[j - 1] > v; j--) {}
18657 ticks = ticks.slice(i, j);
18658 }
18659 return ticks;
18660 };
18661 scale.tickFormat = function(n, format) {
18662 if (!arguments.length) return d3_scale_logFormat;
18663 if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
18664 var k = Math.max(1, base * n / scale.ticks().length);
18665 return function(d) {
18666 var i = d / pow(Math.round(log(d)));
18667 if (i * base < base - .5) i *= base;
18668 return i <= k ? format(d) : "";
18669 };
18670 };
18671 scale.copy = function() {
18672 return d3_scale_log(linear.copy(), base, positive, domain);
18673 };
18674 return d3_scale_linearRebind(scale, linear);
18675 }
18676 var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
18677 floor: function(x) {
18678 return -Math.ceil(-x);
18679 },
18680 ceil: function(x) {
18681 return -Math.floor(-x);
18682 }
18683 };
18684 d3.scale.pow = function() {
18685 return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
18686 };
18687 function d3_scale_pow(linear, exponent, domain) {
18688 var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
18689 function scale(x) {
18690 return linear(powp(x));
18691 }
18692 scale.invert = function(x) {
18693 return powb(linear.invert(x));
18694 };
18695 scale.domain = function(x) {
18696 if (!arguments.length) return domain;
18697 linear.domain((domain = x.map(Number)).map(powp));
18698 return scale;
18699 };
18700 scale.ticks = function(m) {
18701 return d3_scale_linearTicks(domain, m);
18702 };
18703 scale.tickFormat = function(m, format) {
18704 return d3_scale_linearTickFormat(domain, m, format);
18705 };
18706 scale.nice = function(m) {
18707 return scale.domain(d3_scale_linearNice(domain, m));
18708 };
18709 scale.exponent = function(x) {
18710 if (!arguments.length) return exponent;
18711 powp = d3_scale_powPow(exponent = x);
18712 powb = d3_scale_powPow(1 / exponent);
18713 linear.domain(domain.map(powp));
18714 return scale;
18715 };
18716 scale.copy = function() {
18717 return d3_scale_pow(linear.copy(), exponent, domain);
18718 };
18719 return d3_scale_linearRebind(scale, linear);
18720 }
18721 function d3_scale_powPow(e) {
18722 return function(x) {
18723 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
18724 };
18725 }
18726 d3.scale.sqrt = function() {
18727 return d3.scale.pow().exponent(.5);
18728 };
18729 d3.scale.ordinal = function() {
18730 return d3_scale_ordinal([], {
18731 t: "range",
18732 a: [ [] ]
18733 });
18734 };
18735 function d3_scale_ordinal(domain, ranger) {
18736 var index, range, rangeBand;
18737 function scale(x) {
18738 return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
18739 }
18740 function steps(start, step) {
18741 return d3.range(domain.length).map(function(i) {
18742 return start + step * i;
18743 });
18744 }
18745 scale.domain = function(x) {
18746 if (!arguments.length) return domain;
18747 domain = [];
18748 index = new d3_Map();
18749 var i = -1, n = x.length, xi;
18750 while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
18751 return scale[ranger.t].apply(scale, ranger.a);
18752 };
18753 scale.range = function(x) {
18754 if (!arguments.length) return range;
18755 range = x;
18756 rangeBand = 0;
18757 ranger = {
18758 t: "range",
18759 a: arguments
18760 };
18761 return scale;
18762 };
18763 scale.rangePoints = function(x, padding) {
18764 if (arguments.length < 2) padding = 0;
18765 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
18766 0) : (stop - start) / (domain.length - 1 + padding);
18767 range = steps(start + step * padding / 2, step);
18768 rangeBand = 0;
18769 ranger = {
18770 t: "rangePoints",
18771 a: arguments
18772 };
18773 return scale;
18774 };
18775 scale.rangeRoundPoints = function(x, padding) {
18776 if (arguments.length < 2) padding = 0;
18777 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
18778 0) : (stop - start) / (domain.length - 1 + padding) | 0;
18779 range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
18780 rangeBand = 0;
18781 ranger = {
18782 t: "rangeRoundPoints",
18783 a: arguments
18784 };
18785 return scale;
18786 };
18787 scale.rangeBands = function(x, padding, outerPadding) {
18788 if (arguments.length < 2) padding = 0;
18789 if (arguments.length < 3) outerPadding = padding;
18790 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
18791 range = steps(start + step * outerPadding, step);
18792 if (reverse) range.reverse();
18793 rangeBand = step * (1 - padding);
18794 ranger = {
18795 t: "rangeBands",
18796 a: arguments
18797 };
18798 return scale;
18799 };
18800 scale.rangeRoundBands = function(x, padding, outerPadding) {
18801 if (arguments.length < 2) padding = 0;
18802 if (arguments.length < 3) outerPadding = padding;
18803 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
18804 range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
18805 if (reverse) range.reverse();
18806 rangeBand = Math.round(step * (1 - padding));
18807 ranger = {
18808 t: "rangeRoundBands",
18809 a: arguments
18810 };
18811 return scale;
18812 };
18813 scale.rangeBand = function() {
18814 return rangeBand;
18815 };
18816 scale.rangeExtent = function() {
18817 return d3_scaleExtent(ranger.a[0]);
18818 };
18819 scale.copy = function() {
18820 return d3_scale_ordinal(domain, ranger);
18821 };
18822 return scale.domain(domain);
18823 }
18824 d3.scale.category10 = function() {
18825 return d3.scale.ordinal().range(d3_category10);
18826 };
18827 d3.scale.category20 = function() {
18828 return d3.scale.ordinal().range(d3_category20);
18829 };
18830 d3.scale.category20b = function() {
18831 return d3.scale.ordinal().range(d3_category20b);
18832 };
18833 d3.scale.category20c = function() {
18834 return d3.scale.ordinal().range(d3_category20c);
18835 };
18836 var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
18837 var d3_category20 = [ 2062260, 11454440, 16744206, 16759672, 2924588, 10018698, 14034728, 16750742, 9725885, 12955861, 9197131, 12885140, 14907330, 16234194, 8355711, 13092807, 12369186, 14408589, 1556175, 10410725 ].map(d3_rgbString);
18838 var d3_category20b = [ 3750777, 5395619, 7040719, 10264286, 6519097, 9216594, 11915115, 13556636, 9202993, 12426809, 15186514, 15190932, 8666169, 11356490, 14049643, 15177372, 8077683, 10834324, 13528509, 14589654 ].map(d3_rgbString);
18839 var d3_category20c = [ 3244733, 7057110, 10406625, 13032431, 15095053, 16616764, 16625259, 16634018, 3253076, 7652470, 10607003, 13101504, 7695281, 10394312, 12369372, 14342891, 6513507, 9868950, 12434877, 14277081 ].map(d3_rgbString);
18840 d3.scale.quantile = function() {
18841 return d3_scale_quantile([], []);
18842 };
18843 function d3_scale_quantile(domain, range) {
18844 var thresholds;
18845 function rescale() {
18846 var k = 0, q = range.length;
18847 thresholds = [];
18848 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
18849 return scale;
18850 }
18851 function scale(x) {
18852 if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
18853 }
18854 scale.domain = function(x) {
18855 if (!arguments.length) return domain;
18856 domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
18857 return rescale();
18858 };
18859 scale.range = function(x) {
18860 if (!arguments.length) return range;
18861 range = x;
18862 return rescale();
18863 };
18864 scale.quantiles = function() {
18865 return thresholds;
18866 };
18867 scale.invertExtent = function(y) {
18868 y = range.indexOf(y);
18869 return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
18870 };
18871 scale.copy = function() {
18872 return d3_scale_quantile(domain, range);
18873 };
18874 return rescale();
18875 }
18876 d3.scale.quantize = function() {
18877 return d3_scale_quantize(0, 1, [ 0, 1 ]);
18878 };
18879 function d3_scale_quantize(x0, x1, range) {
18880 var kx, i;
18881 function scale(x) {
18882 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
18883 }
18884 function rescale() {
18885 kx = range.length / (x1 - x0);
18886 i = range.length - 1;
18887 return scale;
18888 }
18889 scale.domain = function(x) {
18890 if (!arguments.length) return [ x0, x1 ];
18891 x0 = +x[0];
18892 x1 = +x[x.length - 1];
18893 return rescale();
18894 };
18895 scale.range = function(x) {
18896 if (!arguments.length) return range;
18897 range = x;
18898 return rescale();
18899 };
18900 scale.invertExtent = function(y) {
18901 y = range.indexOf(y);
18902 y = y < 0 ? NaN : y / kx + x0;
18903 return [ y, y + 1 / kx ];
18904 };
18905 scale.copy = function() {
18906 return d3_scale_quantize(x0, x1, range);
18907 };
18908 return rescale();
18909 }
18910 d3.scale.threshold = function() {
18911 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
18912 };
18913 function d3_scale_threshold(domain, range) {
18914 function scale(x) {
18915 if (x <= x) return range[d3.bisect(domain, x)];
18916 }
18917 scale.domain = function(_) {
18918 if (!arguments.length) return domain;
18919 domain = _;
18920 return scale;
18921 };
18922 scale.range = function(_) {
18923 if (!arguments.length) return range;
18924 range = _;
18925 return scale;
18926 };
18927 scale.invertExtent = function(y) {
18928 y = range.indexOf(y);
18929 return [ domain[y - 1], domain[y] ];
18930 };
18931 scale.copy = function() {
18932 return d3_scale_threshold(domain, range);
18933 };
18934 return scale;
18935 }
18936 d3.scale.identity = function() {
18937 return d3_scale_identity([ 0, 1 ]);
18938 };
18939 function d3_scale_identity(domain) {
18940 function identity(x) {
18941 return +x;
18942 }
18943 identity.invert = identity;
18944 identity.domain = identity.range = function(x) {
18945 if (!arguments.length) return domain;
18946 domain = x.map(identity);
18947 return identity;
18948 };
18949 identity.ticks = function(m) {
18950 return d3_scale_linearTicks(domain, m);
18951 };
18952 identity.tickFormat = function(m, format) {
18953 return d3_scale_linearTickFormat(domain, m, format);
18954 };
18955 identity.copy = function() {
18956 return d3_scale_identity(domain);
18957 };
18958 return identity;
18959 }
18960 d3.svg = {};
18961 function d3_zero() {
18962 return 0;
18963 }
18964 d3.svg.arc = function() {
18965 var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, cornerRadius = d3_zero, padRadius = d3_svg_arcAuto, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle, padAngle = d3_svg_arcPadAngle;
18966 function arc() {
18967 var r0 = Math.max(0, +innerRadius.apply(this, arguments)), r1 = Math.max(0, +outerRadius.apply(this, arguments)), a0 = startAngle.apply(this, arguments) - halfπ, a1 = endAngle.apply(this, arguments) - halfπ, da = Math.abs(a1 - a0), cw = a0 > a1 ? 0 : 1;
18968 if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
18969 if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
18970 var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
18971 if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
18972 rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
18973 if (!cw) p1 *= -1;
18974 if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
18975 if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
18976 }
18977 if (r1) {
18978 x0 = r1 * Math.cos(a0 + p1);
18979 y0 = r1 * Math.sin(a0 + p1);
18980 x1 = r1 * Math.cos(a1 - p1);
18981 y1 = r1 * Math.sin(a1 - p1);
18982 var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
18983 if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
18984 var h1 = (a0 + a1) / 2;
18985 x0 = r1 * Math.cos(h1);
18986 y0 = r1 * Math.sin(h1);
18987 x1 = y1 = null;
18988 }
18989 } else {
18990 x0 = y0 = 0;
18991 }
18992 if (r0) {
18993 x2 = r0 * Math.cos(a1 - p0);
18994 y2 = r0 * Math.sin(a1 - p0);
18995 x3 = r0 * Math.cos(a0 + p0);
18996 y3 = r0 * Math.sin(a0 + p0);
18997 var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
18998 if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
18999 var h0 = (a0 + a1) / 2;
19000 x2 = r0 * Math.cos(h0);
19001 y2 = r0 * Math.sin(h0);
19002 x3 = y3 = null;
19003 }
19004 } else {
19005 x2 = y2 = 0;
19006 }
19007 if (da > ε && (rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
19008 cr = r0 < r1 ^ cw ? 0 : 1;
19009 var rc1 = rc, rc0 = rc;
19010 if (da < π) {
19011 var oc = x3 == null ? [ x2, y2 ] : x1 == null ? [ x0, y0 ] : d3_geom_polygonIntersect([ x0, y0 ], [ x3, y3 ], [ x1, y1 ], [ x2, y2 ]), ax = x0 - oc[0], ay = y0 - oc[1], bx = x1 - oc[0], by = y1 - oc[1], kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2), lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
19012 rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
19013 rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
19014 }
19015 if (x1 != null) {
19016 var t30 = d3_svg_arcCornerTangents(x3 == null ? [ x2, y2 ] : [ x3, y3 ], [ x0, y0 ], r1, rc1, cw), t12 = d3_svg_arcCornerTangents([ x1, y1 ], [ x2, y2 ], r1, rc1, cw);
19017 if (rc === rc1) {
19018 path.push("M", t30[0], "A", rc1, ",", rc1, " 0 0,", cr, " ", t30[1], "A", r1, ",", r1, " 0 ", 1 - cw ^ d3_svg_arcSweep(t30[1][0], t30[1][1], t12[1][0], t12[1][1]), ",", cw, " ", t12[1], "A", rc1, ",", rc1, " 0 0,", cr, " ", t12[0]);
19019 } else {
19020 path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
19021 }
19022 } else {
19023 path.push("M", x0, ",", y0);
19024 }
19025 if (x3 != null) {
19026 var t03 = d3_svg_arcCornerTangents([ x0, y0 ], [ x3, y3 ], r0, -rc0, cw), t21 = d3_svg_arcCornerTangents([ x2, y2 ], x1 == null ? [ x0, y0 ] : [ x1, y1 ], r0, -rc0, cw);
19027 if (rc === rc0) {
19028 path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t21[1], "A", r0, ",", r0, " 0 ", cw ^ d3_svg_arcSweep(t21[1][0], t21[1][1], t03[1][0], t03[1][1]), ",", 1 - cw, " ", t03[1], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
19029 } else {
19030 path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
19031 }
19032 } else {
19033 path.push("L", x2, ",", y2);
19034 }
19035 } else {
19036 path.push("M", x0, ",", y0);
19037 if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
19038 path.push("L", x2, ",", y2);
19039 if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
19040 }
19041 path.push("Z");
19042 return path.join("");
19043 }
19044 function circleSegment(r1, cw) {
19045 return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
19046 }
19047 arc.innerRadius = function(v) {
19048 if (!arguments.length) return innerRadius;
19049 innerRadius = d3_functor(v);
19050 return arc;
19051 };
19052 arc.outerRadius = function(v) {
19053 if (!arguments.length) return outerRadius;
19054 outerRadius = d3_functor(v);
19055 return arc;
19056 };
19057 arc.cornerRadius = function(v) {
19058 if (!arguments.length) return cornerRadius;
19059 cornerRadius = d3_functor(v);
19060 return arc;
19061 };
19062 arc.padRadius = function(v) {
19063 if (!arguments.length) return padRadius;
19064 padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
19065 return arc;
19066 };
19067 arc.startAngle = function(v) {
19068 if (!arguments.length) return startAngle;
19069 startAngle = d3_functor(v);
19070 return arc;
19071 };
19072 arc.endAngle = function(v) {
19073 if (!arguments.length) return endAngle;
19074 endAngle = d3_functor(v);
19075 return arc;
19076 };
19077 arc.padAngle = function(v) {
19078 if (!arguments.length) return padAngle;
19079 padAngle = d3_functor(v);
19080 return arc;
19081 };
19082 arc.centroid = function() {
19083 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
19084 return [ Math.cos(a) * r, Math.sin(a) * r ];
19085 };
19086 return arc;
19087 };
19088 var d3_svg_arcAuto = "auto";
19089 function d3_svg_arcInnerRadius(d) {
19090 return d.innerRadius;
19091 }
19092 function d3_svg_arcOuterRadius(d) {
19093 return d.outerRadius;
19094 }
19095 function d3_svg_arcStartAngle(d) {
19096 return d.startAngle;
19097 }
19098 function d3_svg_arcEndAngle(d) {
19099 return d.endAngle;
19100 }
19101 function d3_svg_arcPadAngle(d) {
19102 return d && d.padAngle;
19103 }
19104 function d3_svg_arcSweep(x0, y0, x1, y1) {
19105 return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
19106 }
19107 function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
19108 var x01 = p0[0] - p1[0], y01 = p0[1] - p1[1], lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x1 = p0[0] + ox, y1 = p0[1] + oy, x2 = p1[0] + ox, y2 = p1[1] + oy, x3 = (x1 + x2) / 2, y3 = (y1 + y2) / 2, dx = x2 - x1, dy = y2 - y1, d2 = dx * dx + dy * dy, r = r1 - rc, D = x1 * y2 - x2 * y1, d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x3, dy0 = cy0 - y3, dx1 = cx1 - x3, dy1 = cy1 - y3;
19109 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
19110 return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
19111 }
19112 function d3_svg_line(projection) {
19113 var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
19114 function line(data) {
19115 var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
19116 function segment() {
19117 segments.push("M", interpolate(projection(points), tension));
19118 }
19119 while (++i < n) {
19120 if (defined.call(this, d = data[i], i)) {
19121 points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
19122 } else if (points.length) {
19123 segment();
19124 points = [];
19125 }
19126 }
19127 if (points.length) segment();
19128 return segments.length ? segments.join("") : null;
19129 }
19130 line.x = function(_) {
19131 if (!arguments.length) return x;
19132 x = _;
19133 return line;
19134 };
19135 line.y = function(_) {
19136 if (!arguments.length) return y;
19137 y = _;
19138 return line;
19139 };
19140 line.defined = function(_) {
19141 if (!arguments.length) return defined;
19142 defined = _;
19143 return line;
19144 };
19145 line.interpolate = function(_) {
19146 if (!arguments.length) return interpolateKey;
19147 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
19148 return line;
19149 };
19150 line.tension = function(_) {
19151 if (!arguments.length) return tension;
19152 tension = _;
19153 return line;
19154 };
19155 return line;
19156 }
19157 d3.svg.line = function() {
19158 return d3_svg_line(d3_identity);
19159 };
19160 var d3_svg_lineInterpolators = d3.map({
19161 linear: d3_svg_lineLinear,
19162 "linear-closed": d3_svg_lineLinearClosed,
19163 step: d3_svg_lineStep,
19164 "step-before": d3_svg_lineStepBefore,
19165 "step-after": d3_svg_lineStepAfter,
19166 basis: d3_svg_lineBasis,
19167 "basis-open": d3_svg_lineBasisOpen,
19168 "basis-closed": d3_svg_lineBasisClosed,
19169 bundle: d3_svg_lineBundle,
19170 cardinal: d3_svg_lineCardinal,
19171 "cardinal-open": d3_svg_lineCardinalOpen,
19172 "cardinal-closed": d3_svg_lineCardinalClosed,
19173 monotone: d3_svg_lineMonotone
19174 });
19175 d3_svg_lineInterpolators.forEach(function(key, value) {
19176 value.key = key;
19177 value.closed = /-closed$/.test(key);
19178 });
19179 function d3_svg_lineLinear(points) {
19180 return points.length > 1 ? points.join("L") : points + "Z";
19181 }
19182 function d3_svg_lineLinearClosed(points) {
19183 return points.join("L") + "Z";
19184 }
19185 function d3_svg_lineStep(points) {
19186 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
19187 while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
19188 if (n > 1) path.push("H", p[0]);
19189 return path.join("");
19190 }
19191 function d3_svg_lineStepBefore(points) {
19192 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
19193 while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
19194 return path.join("");
19195 }
19196 function d3_svg_lineStepAfter(points) {
19197 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
19198 while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
19199 return path.join("");
19200 }
19201 function d3_svg_lineCardinalOpen(points, tension) {
19202 return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
19203 }
19204 function d3_svg_lineCardinalClosed(points, tension) {
19205 return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
19206 points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
19207 }
19208 function d3_svg_lineCardinal(points, tension) {
19209 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
19210 }
19211 function d3_svg_lineHermite(points, tangents) {
19212 if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
19213 return d3_svg_lineLinear(points);
19214 }
19215 var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
19216 if (quad) {
19217 path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
19218 p0 = points[1];
19219 pi = 2;
19220 }
19221 if (tangents.length > 1) {
19222 t = tangents[1];
19223 p = points[pi];
19224 pi++;
19225 path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
19226 for (var i = 2; i < tangents.length; i++, pi++) {
19227 p = points[pi];
19228 t = tangents[i];
19229 path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
19230 }
19231 }
19232 if (quad) {
19233 var lp = points[pi];
19234 path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
19235 }
19236 return path;
19237 }
19238 function d3_svg_lineCardinalTangents(points, tension) {
19239 var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
19240 while (++i < n) {
19241 p0 = p1;
19242 p1 = p2;
19243 p2 = points[i];
19244 tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
19245 }
19246 return tangents;
19247 }
19248 function d3_svg_lineBasis(points) {
19249 if (points.length < 3) return d3_svg_lineLinear(points);
19250 var i = 1, n = points.length, pi = points[0], x0 = pi[0], y0 = pi[1], px = [ x0, x0, x0, (pi = points[1])[0] ], py = [ y0, y0, y0, pi[1] ], path = [ x0, ",", y0, "L", d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
19251 points.push(points[n - 1]);
19252 while (++i <= n) {
19253 pi = points[i];
19254 px.shift();
19255 px.push(pi[0]);
19256 py.shift();
19257 py.push(pi[1]);
19258 d3_svg_lineBasisBezier(path, px, py);
19259 }
19260 points.pop();
19261 path.push("L", pi);
19262 return path.join("");
19263 }
19264 function d3_svg_lineBasisOpen(points) {
19265 if (points.length < 4) return d3_svg_lineLinear(points);
19266 var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
19267 while (++i < 3) {
19268 pi = points[i];
19269 px.push(pi[0]);
19270 py.push(pi[1]);
19271 }
19272 path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
19273 --i;
19274 while (++i < n) {
19275 pi = points[i];
19276 px.shift();
19277 px.push(pi[0]);
19278 py.shift();
19279 py.push(pi[1]);
19280 d3_svg_lineBasisBezier(path, px, py);
19281 }
19282 return path.join("");
19283 }
19284 function d3_svg_lineBasisClosed(points) {
19285 var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
19286 while (++i < 4) {
19287 pi = points[i % n];
19288 px.push(pi[0]);
19289 py.push(pi[1]);
19290 }
19291 path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
19292 --i;
19293 while (++i < m) {
19294 pi = points[i % n];
19295 px.shift();
19296 px.push(pi[0]);
19297 py.shift();
19298 py.push(pi[1]);
19299 d3_svg_lineBasisBezier(path, px, py);
19300 }
19301 return path.join("");
19302 }
19303 function d3_svg_lineBundle(points, tension) {
19304 var n = points.length - 1;
19305 if (n) {
19306 var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
19307 while (++i <= n) {
19308 p = points[i];
19309 t = i / n;
19310 p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
19311 p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
19312 }
19313 }
19314 return d3_svg_lineBasis(points);
19315 }
19316 function d3_svg_lineDot4(a, b) {
19317 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
19318 }
19319 var d3_svg_lineBasisBezier1 = [ 0, 2 / 3, 1 / 3, 0 ], d3_svg_lineBasisBezier2 = [ 0, 1 / 3, 2 / 3, 0 ], d3_svg_lineBasisBezier3 = [ 0, 1 / 6, 2 / 3, 1 / 6 ];
19320 function d3_svg_lineBasisBezier(path, x, y) {
19321 path.push("C", d3_svg_lineDot4(d3_svg_lineBasisBezier1, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier1, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, y));
19322 }
19323 function d3_svg_lineSlope(p0, p1) {
19324 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
19325 }
19326 function d3_svg_lineFiniteDifferences(points) {
19327 var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
19328 while (++i < j) {
19329 m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
19330 }
19331 m[i] = d;
19332 return m;
19333 }
19334 function d3_svg_lineMonotoneTangents(points) {
19335 var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
19336 while (++i < j) {
19337 d = d3_svg_lineSlope(points[i], points[i + 1]);
19338 if (abs(d) < ε) {
19339 m[i] = m[i + 1] = 0;
19340 } else {
19341 a = m[i] / d;
19342 b = m[i + 1] / d;
19343 s = a * a + b * b;
19344 if (s > 9) {
19345 s = d * 3 / Math.sqrt(s);
19346 m[i] = s * a;
19347 m[i + 1] = s * b;
19348 }
19349 }
19350 }
19351 i = -1;
19352 while (++i <= j) {
19353 s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
19354 tangents.push([ s || 0, m[i] * s || 0 ]);
19355 }
19356 return tangents;
19357 }
19358 function d3_svg_lineMonotone(points) {
19359 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
19360 }
19361 d3.svg.line.radial = function() {
19362 var line = d3_svg_line(d3_svg_lineRadial);
19363 line.radius = line.x, delete line.x;
19364 line.angle = line.y, delete line.y;
19365 return line;
19366 };
19367 function d3_svg_lineRadial(points) {
19368 var point, i = -1, n = points.length, r, a;
19369 while (++i < n) {
19370 point = points[i];
19371 r = point[0];
19372 a = point[1] - halfπ;
19373 point[0] = r * Math.cos(a);
19374 point[1] = r * Math.sin(a);
19375 }
19376 return points;
19377 }
19378 function d3_svg_area(projection) {
19379 var x0 = d3_geom_pointX, x1 = d3_geom_pointX, y0 = 0, y1 = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
19380 function area(data) {
19381 var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
19382 return x;
19383 } : d3_functor(x1), fy1 = y0 === y1 ? function() {
19384 return y;
19385 } : d3_functor(y1), x, y;
19386 function segment() {
19387 segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
19388 }
19389 while (++i < n) {
19390 if (defined.call(this, d = data[i], i)) {
19391 points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
19392 points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
19393 } else if (points0.length) {
19394 segment();
19395 points0 = [];
19396 points1 = [];
19397 }
19398 }
19399 if (points0.length) segment();
19400 return segments.length ? segments.join("") : null;
19401 }
19402 area.x = function(_) {
19403 if (!arguments.length) return x1;
19404 x0 = x1 = _;
19405 return area;
19406 };
19407 area.x0 = function(_) {
19408 if (!arguments.length) return x0;
19409 x0 = _;
19410 return area;
19411 };
19412 area.x1 = function(_) {
19413 if (!arguments.length) return x1;
19414 x1 = _;
19415 return area;
19416 };
19417 area.y = function(_) {
19418 if (!arguments.length) return y1;
19419 y0 = y1 = _;
19420 return area;
19421 };
19422 area.y0 = function(_) {
19423 if (!arguments.length) return y0;
19424 y0 = _;
19425 return area;
19426 };
19427 area.y1 = function(_) {
19428 if (!arguments.length) return y1;
19429 y1 = _;
19430 return area;
19431 };
19432 area.defined = function(_) {
19433 if (!arguments.length) return defined;
19434 defined = _;
19435 return area;
19436 };
19437 area.interpolate = function(_) {
19438 if (!arguments.length) return interpolateKey;
19439 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
19440 interpolateReverse = interpolate.reverse || interpolate;
19441 L = interpolate.closed ? "M" : "L";
19442 return area;
19443 };
19444 area.tension = function(_) {
19445 if (!arguments.length) return tension;
19446 tension = _;
19447 return area;
19448 };
19449 return area;
19450 }
19451 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
19452 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
19453 d3.svg.area = function() {
19454 return d3_svg_area(d3_identity);
19455 };
19456 d3.svg.area.radial = function() {
19457 var area = d3_svg_area(d3_svg_lineRadial);
19458 area.radius = area.x, delete area.x;
19459 area.innerRadius = area.x0, delete area.x0;
19460 area.outerRadius = area.x1, delete area.x1;
19461 area.angle = area.y, delete area.y;
19462 area.startAngle = area.y0, delete area.y0;
19463 area.endAngle = area.y1, delete area.y1;
19464 return area;
19465 };
19466 d3.svg.chord = function() {
19467 var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
19468 function chord(d, i) {
19469 var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
19470 return "M" + s.p0 + arc(s.r, s.p1, s.a1 - s.a0) + (equals(s, t) ? curve(s.r, s.p1, s.r, s.p0) : curve(s.r, s.p1, t.r, t.p0) + arc(t.r, t.p1, t.a1 - t.a0) + curve(t.r, t.p1, s.r, s.p0)) + "Z";
19471 }
19472 function subgroup(self, f, d, i) {
19473 var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) - halfπ, a1 = endAngle.call(self, subgroup, i) - halfπ;
19474 return {
19475 r: r,
19476 a0: a0,
19477 a1: a1,
19478 p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
19479 p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
19480 };
19481 }
19482 function equals(a, b) {
19483 return a.a0 == b.a0 && a.a1 == b.a1;
19484 }
19485 function arc(r, p, a) {
19486 return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
19487 }
19488 function curve(r0, p0, r1, p1) {
19489 return "Q 0,0 " + p1;
19490 }
19491 chord.radius = function(v) {
19492 if (!arguments.length) return radius;
19493 radius = d3_functor(v);
19494 return chord;
19495 };
19496 chord.source = function(v) {
19497 if (!arguments.length) return source;
19498 source = d3_functor(v);
19499 return chord;
19500 };
19501 chord.target = function(v) {
19502 if (!arguments.length) return target;
19503 target = d3_functor(v);
19504 return chord;
19505 };
19506 chord.startAngle = function(v) {
19507 if (!arguments.length) return startAngle;
19508 startAngle = d3_functor(v);
19509 return chord;
19510 };
19511 chord.endAngle = function(v) {
19512 if (!arguments.length) return endAngle;
19513 endAngle = d3_functor(v);
19514 return chord;
19515 };
19516 return chord;
19517 };
19518 function d3_svg_chordRadius(d) {
19519 return d.radius;
19520 }
19521 d3.svg.diagonal = function() {
19522 var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
19523 function diagonal(d, i) {
19524 var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
19525 x: p0.x,
19526 y: m
19527 }, {
19528 x: p3.x,
19529 y: m
19530 }, p3 ];
19531 p = p.map(projection);
19532 return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
19533 }
19534 diagonal.source = function(x) {
19535 if (!arguments.length) return source;
19536 source = d3_functor(x);
19537 return diagonal;
19538 };
19539 diagonal.target = function(x) {
19540 if (!arguments.length) return target;
19541 target = d3_functor(x);
19542 return diagonal;
19543 };
19544 diagonal.projection = function(x) {
19545 if (!arguments.length) return projection;
19546 projection = x;
19547 return diagonal;
19548 };
19549 return diagonal;
19550 };
19551 function d3_svg_diagonalProjection(d) {
19552 return [ d.x, d.y ];
19553 }
19554 d3.svg.diagonal.radial = function() {
19555 var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
19556 diagonal.projection = function(x) {
19557 return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
19558 };
19559 return diagonal;
19560 };
19561 function d3_svg_diagonalRadialProjection(projection) {
19562 return function() {
19563 var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
19564 return [ r * Math.cos(a), r * Math.sin(a) ];
19565 };
19566 }
19567 d3.svg.symbol = function() {
19568 var type = d3_svg_symbolType, size = d3_svg_symbolSize;
19569 function symbol(d, i) {
19570 return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
19571 }
19572 symbol.type = function(x) {
19573 if (!arguments.length) return type;
19574 type = d3_functor(x);
19575 return symbol;
19576 };
19577 symbol.size = function(x) {
19578 if (!arguments.length) return size;
19579 size = d3_functor(x);
19580 return symbol;
19581 };
19582 return symbol;
19583 };
19584 function d3_svg_symbolSize() {
19585 return 64;
19586 }
19587 function d3_svg_symbolType() {
19588 return "circle";
19589 }
19590 function d3_svg_symbolCircle(size) {
19591 var r = Math.sqrt(size / π);
19592 return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
19593 }
19594 var d3_svg_symbols = d3.map({
19595 circle: d3_svg_symbolCircle,
19596 cross: function(size) {
19597 var r = Math.sqrt(size / 5) / 2;
19598 return "M" + -3 * r + "," + -r + "H" + -r + "V" + -3 * r + "H" + r + "V" + -r + "H" + 3 * r + "V" + r + "H" + r + "V" + 3 * r + "H" + -r + "V" + r + "H" + -3 * r + "Z";
19599 },
19600 diamond: function(size) {
19601 var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
19602 return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
19603 },
19604 square: function(size) {
19605 var r = Math.sqrt(size) / 2;
19606 return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
19607 },
19608 "triangle-down": function(size) {
19609 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
19610 return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
19611 },
19612 "triangle-up": function(size) {
19613 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
19614 return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
19615 }
19616 });
19617 d3.svg.symbolTypes = d3_svg_symbols.keys();
19618 var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
19619 d3_selectionPrototype.transition = function(name) {
19620 var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
19621 time: Date.now(),
19622 ease: d3_ease_cubicInOut,
19623 delay: 0,
19624 duration: 250
19625 };
19626 for (var j = -1, m = this.length; ++j < m; ) {
19627 subgroups.push(subgroup = []);
19628 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
19629 if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
19630 subgroup.push(node);
19631 }
19632 }
19633 return d3_transition(subgroups, ns, id);
19634 };
19635 d3_selectionPrototype.interrupt = function(name) {
19636 return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
19637 };
19638 var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
19639 function d3_selection_interruptNS(ns) {
19640 return function() {
19641 var lock, activeId, active;
19642 if ((lock = this[ns]) && (active = lock[activeId = lock.active])) {
19643 active.timer.c = null;
19644 active.timer.t = NaN;
19645 if (--lock.count) delete lock[activeId]; else delete this[ns];
19646 lock.active += .5;
19647 active.event && active.event.interrupt.call(this, this.__data__, active.index);
19648 }
19649 };
19650 }
19651 function d3_transition(groups, ns, id) {
19652 d3_subclass(groups, d3_transitionPrototype);
19653 groups.namespace = ns;
19654 groups.id = id;
19655 return groups;
19656 }
19657 var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
19658 d3_transitionPrototype.call = d3_selectionPrototype.call;
19659 d3_transitionPrototype.empty = d3_selectionPrototype.empty;
19660 d3_transitionPrototype.node = d3_selectionPrototype.node;
19661 d3_transitionPrototype.size = d3_selectionPrototype.size;
19662 d3.transition = function(selection, name) {
19663 return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
19664 };
19665 d3.transition.prototype = d3_transitionPrototype;
19666 d3_transitionPrototype.select = function(selector) {
19667 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
19668 selector = d3_selection_selector(selector);
19669 for (var j = -1, m = this.length; ++j < m; ) {
19670 subgroups.push(subgroup = []);
19671 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
19672 if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
19673 if ("__data__" in node) subnode.__data__ = node.__data__;
19674 d3_transitionNode(subnode, i, ns, id, node[ns][id]);
19675 subgroup.push(subnode);
19676 } else {
19677 subgroup.push(null);
19678 }
19679 }
19680 }
19681 return d3_transition(subgroups, ns, id);
19682 };
19683 d3_transitionPrototype.selectAll = function(selector) {
19684 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
19685 selector = d3_selection_selectorAll(selector);
19686 for (var j = -1, m = this.length; ++j < m; ) {
19687 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
19688 if (node = group[i]) {
19689 transition = node[ns][id];
19690 subnodes = selector.call(node, node.__data__, i, j);
19691 subgroups.push(subgroup = []);
19692 for (var k = -1, o = subnodes.length; ++k < o; ) {
19693 if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
19694 subgroup.push(subnode);
19695 }
19696 }
19697 }
19698 }
19699 return d3_transition(subgroups, ns, id);
19700 };
19701 d3_transitionPrototype.filter = function(filter) {
19702 var subgroups = [], subgroup, group, node;
19703 if (typeof filter !== "function") filter = d3_selection_filter(filter);
19704 for (var j = 0, m = this.length; j < m; j++) {
19705 subgroups.push(subgroup = []);
19706 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
19707 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
19708 subgroup.push(node);
19709 }
19710 }
19711 }
19712 return d3_transition(subgroups, this.namespace, this.id);
19713 };
19714 d3_transitionPrototype.tween = function(name, tween) {
19715 var id = this.id, ns = this.namespace;
19716 if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
19717 return d3_selection_each(this, tween == null ? function(node) {
19718 node[ns][id].tween.remove(name);
19719 } : function(node) {
19720 node[ns][id].tween.set(name, tween);
19721 });
19722 };
19723 function d3_transition_tween(groups, name, value, tween) {
19724 var id = groups.id, ns = groups.namespace;
19725 return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
19726 node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
19727 } : (value = tween(value), function(node) {
19728 node[ns][id].tween.set(name, value);
19729 }));
19730 }
19731 d3_transitionPrototype.attr = function(nameNS, value) {
19732 if (arguments.length < 2) {
19733 for (value in nameNS) this.attr(value, nameNS[value]);
19734 return this;
19735 }
19736 var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
19737 function attrNull() {
19738 this.removeAttribute(name);
19739 }
19740 function attrNullNS() {
19741 this.removeAttributeNS(name.space, name.local);
19742 }
19743 function attrTween(b) {
19744 return b == null ? attrNull : (b += "", function() {
19745 var a = this.getAttribute(name), i;
19746 return a !== b && (i = interpolate(a, b), function(t) {
19747 this.setAttribute(name, i(t));
19748 });
19749 });
19750 }
19751 function attrTweenNS(b) {
19752 return b == null ? attrNullNS : (b += "", function() {
19753 var a = this.getAttributeNS(name.space, name.local), i;
19754 return a !== b && (i = interpolate(a, b), function(t) {
19755 this.setAttributeNS(name.space, name.local, i(t));
19756 });
19757 });
19758 }
19759 return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
19760 };
19761 d3_transitionPrototype.attrTween = function(nameNS, tween) {
19762 var name = d3.ns.qualify(nameNS);
19763 function attrTween(d, i) {
19764 var f = tween.call(this, d, i, this.getAttribute(name));
19765 return f && function(t) {
19766 this.setAttribute(name, f(t));
19767 };
19768 }
19769 function attrTweenNS(d, i) {
19770 var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
19771 return f && function(t) {
19772 this.setAttributeNS(name.space, name.local, f(t));
19773 };
19774 }
19775 return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
19776 };
19777 d3_transitionPrototype.style = function(name, value, priority) {
19778 var n = arguments.length;
19779 if (n < 3) {
19780 if (typeof name !== "string") {
19781 if (n < 2) value = "";
19782 for (priority in name) this.style(priority, name[priority], value);
19783 return this;
19784 }
19785 priority = "";
19786 }
19787 function styleNull() {
19788 this.style.removeProperty(name);
19789 }
19790 function styleString(b) {
19791 return b == null ? styleNull : (b += "", function() {
19792 var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
19793 return a !== b && (i = d3_interpolate(a, b), function(t) {
19794 this.style.setProperty(name, i(t), priority);
19795 });
19796 });
19797 }
19798 return d3_transition_tween(this, "style." + name, value, styleString);
19799 };
19800 d3_transitionPrototype.styleTween = function(name, tween, priority) {
19801 if (arguments.length < 3) priority = "";
19802 function styleTween(d, i) {
19803 var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
19804 return f && function(t) {
19805 this.style.setProperty(name, f(t), priority);
19806 };
19807 }
19808 return this.tween("style." + name, styleTween);
19809 };
19810 d3_transitionPrototype.text = function(value) {
19811 return d3_transition_tween(this, "text", value, d3_transition_text);
19812 };
19813 function d3_transition_text(b) {
19814 if (b == null) b = "";
19815 return function() {
19816 this.textContent = b;
19817 };
19818 }
19819 d3_transitionPrototype.remove = function() {
19820 var ns = this.namespace;
19821 return this.each("end.transition", function() {
19822 var p;
19823 if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
19824 });
19825 };
19826 d3_transitionPrototype.ease = function(value) {
19827 var id = this.id, ns = this.namespace;
19828 if (arguments.length < 1) return this.node()[ns][id].ease;
19829 if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
19830 return d3_selection_each(this, function(node) {
19831 node[ns][id].ease = value;
19832 });
19833 };
19834 d3_transitionPrototype.delay = function(value) {
19835 var id = this.id, ns = this.namespace;
19836 if (arguments.length < 1) return this.node()[ns][id].delay;
19837 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
19838 node[ns][id].delay = +value.call(node, node.__data__, i, j);
19839 } : (value = +value, function(node) {
19840 node[ns][id].delay = value;
19841 }));
19842 };
19843 d3_transitionPrototype.duration = function(value) {
19844 var id = this.id, ns = this.namespace;
19845 if (arguments.length < 1) return this.node()[ns][id].duration;
19846 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
19847 node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
19848 } : (value = Math.max(1, value), function(node) {
19849 node[ns][id].duration = value;
19850 }));
19851 };
19852 d3_transitionPrototype.each = function(type, listener) {
19853 var id = this.id, ns = this.namespace;
19854 if (arguments.length < 2) {
19855 var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
19856 try {
19857 d3_transitionInheritId = id;
19858 d3_selection_each(this, function(node, i, j) {
19859 d3_transitionInherit = node[ns][id];
19860 type.call(node, node.__data__, i, j);
19861 });
19862 } finally {
19863 d3_transitionInherit = inherit;
19864 d3_transitionInheritId = inheritId;
19865 }
19866 } else {
19867 d3_selection_each(this, function(node) {
19868 var transition = node[ns][id];
19869 (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
19870 });
19871 }
19872 return this;
19873 };
19874 d3_transitionPrototype.transition = function() {
19875 var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
19876 for (var j = 0, m = this.length; j < m; j++) {
19877 subgroups.push(subgroup = []);
19878 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
19879 if (node = group[i]) {
19880 transition = node[ns][id0];
19881 d3_transitionNode(node, i, ns, id1, {
19882 time: transition.time,
19883 ease: transition.ease,
19884 delay: transition.delay + transition.duration,
19885 duration: transition.duration
19886 });
19887 }
19888 subgroup.push(node);
19889 }
19890 }
19891 return d3_transition(subgroups, ns, id1);
19892 };
19893 function d3_transitionNamespace(name) {
19894 return name == null ? "__transition__" : "__transition_" + name + "__";
19895 }
19896 function d3_transitionNode(node, i, ns, id, inherit) {
19897 var lock = node[ns] || (node[ns] = {
19898 active: 0,
19899 count: 0
19900 }), transition = lock[id], time, timer, duration, ease, tweens;
19901 function schedule(elapsed) {
19902 var delay = transition.delay;
19903 timer.t = delay + time;
19904 if (delay <= elapsed) return start(elapsed - delay);
19905 timer.c = start;
19906 }
19907 function start(elapsed) {
19908 var activeId = lock.active, active = lock[activeId];
19909 if (active) {
19910 active.timer.c = null;
19911 active.timer.t = NaN;
19912 --lock.count;
19913 delete lock[activeId];
19914 active.event && active.event.interrupt.call(node, node.__data__, active.index);
19915 }
19916 for (var cancelId in lock) {
19917 if (+cancelId < id) {
19918 var cancel = lock[cancelId];
19919 cancel.timer.c = null;
19920 cancel.timer.t = NaN;
19921 --lock.count;
19922 delete lock[cancelId];
19923 }
19924 }
19925 timer.c = tick;
19926 d3_timer(function() {
19927 if (timer.c && tick(elapsed || 1)) {
19928 timer.c = null;
19929 timer.t = NaN;
19930 }
19931 return 1;
19932 }, 0, time);
19933 lock.active = id;
19934 transition.event && transition.event.start.call(node, node.__data__, i);
19935 tweens = [];
19936 transition.tween.forEach(function(key, value) {
19937 if (value = value.call(node, node.__data__, i)) {
19938 tweens.push(value);
19939 }
19940 });
19941 ease = transition.ease;
19942 duration = transition.duration;
19943 }
19944 function tick(elapsed) {
19945 var t = elapsed / duration, e = ease(t), n = tweens.length;
19946 while (n > 0) {
19947 tweens[--n].call(node, e);
19948 }
19949 if (t >= 1) {
19950 transition.event && transition.event.end.call(node, node.__data__, i);
19951 if (--lock.count) delete lock[id]; else delete node[ns];
19952 return 1;
19953 }
19954 }
19955 if (!transition) {
19956 time = inherit.time;
19957 timer = d3_timer(schedule, 0, time);
19958 transition = lock[id] = {
19959 tween: new d3_Map(),
19960 time: time,
19961 timer: timer,
19962 delay: inherit.delay,
19963 duration: inherit.duration,
19964 ease: inherit.ease,
19965 index: i
19966 };
19967 inherit = null;
19968 ++lock.count;
19969 }
19970 }
19971 d3.svg.axis = function() {
19972 var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
19973 function axis(g) {
19974 g.each(function() {
19975 var g = d3.select(this);
19976 var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
19977 var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickSpacing = Math.max(innerTickSize, 0) + tickPadding, tickTransform;
19978 var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
19979 d3.transition(path));
19980 tickEnter.append("line");
19981 tickEnter.append("text");
19982 var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text"), sign = orient === "top" || orient === "left" ? -1 : 1, x1, x2, y1, y2;
19983 if (orient === "bottom" || orient === "top") {
19984 tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
19985 text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
19986 pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
19987 } else {
19988 tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
19989 text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
19990 pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
19991 }
19992 lineEnter.attr(y2, sign * innerTickSize);
19993 textEnter.attr(y1, sign * tickSpacing);
19994 lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
19995 textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
19996 if (scale1.rangeBand) {
19997 var x = scale1, dx = x.rangeBand() / 2;
19998 scale0 = scale1 = function(d) {
19999 return x(d) + dx;
20000 };
20001 } else if (scale0.rangeBand) {
20002 scale0 = scale1;
20003 } else {
20004 tickExit.call(tickTransform, scale1, scale0);
20005 }
20006 tickEnter.call(tickTransform, scale0, scale1);
20007 tickUpdate.call(tickTransform, scale1, scale1);
20008 });
20009 }
20010 axis.scale = function(x) {
20011 if (!arguments.length) return scale;
20012 scale = x;
20013 return axis;
20014 };
20015 axis.orient = function(x) {
20016 if (!arguments.length) return orient;
20017 orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
20018 return axis;
20019 };
20020 axis.ticks = function() {
20021 if (!arguments.length) return tickArguments_;
20022 tickArguments_ = d3_array(arguments);
20023 return axis;
20024 };
20025 axis.tickValues = function(x) {
20026 if (!arguments.length) return tickValues;
20027 tickValues = x;
20028 return axis;
20029 };
20030 axis.tickFormat = function(x) {
20031 if (!arguments.length) return tickFormat_;
20032 tickFormat_ = x;
20033 return axis;
20034 };
20035 axis.tickSize = function(x) {
20036 var n = arguments.length;
20037 if (!n) return innerTickSize;
20038 innerTickSize = +x;
20039 outerTickSize = +arguments[n - 1];
20040 return axis;
20041 };
20042 axis.innerTickSize = function(x) {
20043 if (!arguments.length) return innerTickSize;
20044 innerTickSize = +x;
20045 return axis;
20046 };
20047 axis.outerTickSize = function(x) {
20048 if (!arguments.length) return outerTickSize;
20049 outerTickSize = +x;
20050 return axis;
20051 };
20052 axis.tickPadding = function(x) {
20053 if (!arguments.length) return tickPadding;
20054 tickPadding = +x;
20055 return axis;
20056 };
20057 axis.tickSubdivide = function() {
20058 return arguments.length && axis;
20059 };
20060 return axis;
20061 };
20062 var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
20063 top: 1,
20064 right: 1,
20065 bottom: 1,
20066 left: 1
20067 };
20068 function d3_svg_axisX(selection, x0, x1) {
20069 selection.attr("transform", function(d) {
20070 var v0 = x0(d);
20071 return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
20072 });
20073 }
20074 function d3_svg_axisY(selection, y0, y1) {
20075 selection.attr("transform", function(d) {
20076 var v0 = y0(d);
20077 return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
20078 });
20079 }
20080 d3.svg.brush = function() {
20081 var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, xExtent = [ 0, 0 ], yExtent = [ 0, 0 ], xExtentDomain, yExtentDomain, xClamp = true, yClamp = true, resizes = d3_svg_brushResizes[0];
20082 function brush(g) {
20083 g.each(function() {
20084 var g = d3.select(this).style("pointer-events", "all").style("-webkit-tap-highlight-color", "rgba(0,0,0,0)").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
20085 var background = g.selectAll(".background").data([ 0 ]);
20086 background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
20087 g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
20088 var resize = g.selectAll(".resize").data(resizes, d3_identity);
20089 resize.exit().remove();
20090 resize.enter().append("g").attr("class", function(d) {
20091 return "resize " + d;
20092 }).style("cursor", function(d) {
20093 return d3_svg_brushCursor[d];
20094 }).append("rect").attr("x", function(d) {
20095 return /[ew]$/.test(d) ? -3 : null;
20096 }).attr("y", function(d) {
20097 return /^[ns]/.test(d) ? -3 : null;
20098 }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
20099 resize.style("display", brush.empty() ? "none" : null);
20100 var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
20101 if (x) {
20102 range = d3_scaleRange(x);
20103 backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
20104 redrawX(gUpdate);
20105 }
20106 if (y) {
20107 range = d3_scaleRange(y);
20108 backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
20109 redrawY(gUpdate);
20110 }
20111 redraw(gUpdate);
20112 });
20113 }
20114 brush.event = function(g) {
20115 g.each(function() {
20116 var event_ = event.of(this, arguments), extent1 = {
20117 x: xExtent,
20118 y: yExtent,
20119 i: xExtentDomain,
20120 j: yExtentDomain
20121 }, extent0 = this.__chart__ || extent1;
20122 this.__chart__ = extent1;
20123 if (d3_transitionInheritId) {
20124 d3.select(this).transition().each("start.brush", function() {
20125 xExtentDomain = extent0.i;
20126 yExtentDomain = extent0.j;
20127 xExtent = extent0.x;
20128 yExtent = extent0.y;
20129 event_({
20130 type: "brushstart"
20131 });
20132 }).tween("brush:brush", function() {
20133 var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
20134 xExtentDomain = yExtentDomain = null;
20135 return function(t) {
20136 xExtent = extent1.x = xi(t);
20137 yExtent = extent1.y = yi(t);
20138 event_({
20139 type: "brush",
20140 mode: "resize"
20141 });
20142 };
20143 }).each("end.brush", function() {
20144 xExtentDomain = extent1.i;
20145 yExtentDomain = extent1.j;
20146 event_({
20147 type: "brush",
20148 mode: "resize"
20149 });
20150 event_({
20151 type: "brushend"
20152 });
20153 });
20154 } else {
20155 event_({
20156 type: "brushstart"
20157 });
20158 event_({
20159 type: "brush",
20160 mode: "resize"
20161 });
20162 event_({
20163 type: "brushend"
20164 });
20165 }
20166 });
20167 };
20168 function redraw(g) {
20169 g.selectAll(".resize").attr("transform", function(d) {
20170 return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
20171 });
20172 }
20173 function redrawX(g) {
20174 g.select(".extent").attr("x", xExtent[0]);
20175 g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
20176 }
20177 function redrawY(g) {
20178 g.select(".extent").attr("y", yExtent[0]);
20179 g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
20180 }
20181 function brushstart() {
20182 var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(target), center, origin = d3.mouse(target), offset;
20183 var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
20184 if (d3.event.changedTouches) {
20185 w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
20186 } else {
20187 w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
20188 }
20189 g.interrupt().selectAll("*").interrupt();
20190 if (dragging) {
20191 origin[0] = xExtent[0] - origin[0];
20192 origin[1] = yExtent[0] - origin[1];
20193 } else if (resizing) {
20194 var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
20195 offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
20196 origin[0] = xExtent[ex];
20197 origin[1] = yExtent[ey];
20198 } else if (d3.event.altKey) center = origin.slice();
20199 g.style("pointer-events", "none").selectAll(".resize").style("display", null);
20200 d3.select("body").style("cursor", eventTarget.style("cursor"));
20201 event_({
20202 type: "brushstart"
20203 });
20204 brushmove();
20205 function keydown() {
20206 if (d3.event.keyCode == 32) {
20207 if (!dragging) {
20208 center = null;
20209 origin[0] -= xExtent[1];
20210 origin[1] -= yExtent[1];
20211 dragging = 2;
20212 }
20213 d3_eventPreventDefault();
20214 }
20215 }
20216 function keyup() {
20217 if (d3.event.keyCode == 32 && dragging == 2) {
20218 origin[0] += xExtent[1];
20219 origin[1] += yExtent[1];
20220 dragging = 0;
20221 d3_eventPreventDefault();
20222 }
20223 }
20224 function brushmove() {
20225 var point = d3.mouse(target), moved = false;
20226 if (offset) {
20227 point[0] += offset[0];
20228 point[1] += offset[1];
20229 }
20230 if (!dragging) {
20231 if (d3.event.altKey) {
20232 if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
20233 origin[0] = xExtent[+(point[0] < center[0])];
20234 origin[1] = yExtent[+(point[1] < center[1])];
20235 } else center = null;
20236 }
20237 if (resizingX && move1(point, x, 0)) {
20238 redrawX(g);
20239 moved = true;
20240 }
20241 if (resizingY && move1(point, y, 1)) {
20242 redrawY(g);
20243 moved = true;
20244 }
20245 if (moved) {
20246 redraw(g);
20247 event_({
20248 type: "brush",
20249 mode: dragging ? "move" : "resize"
20250 });
20251 }
20252 }
20253 function move1(point, scale, i) {
20254 var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], extent = i ? yExtent : xExtent, size = extent[1] - extent[0], min, max;
20255 if (dragging) {
20256 r0 -= position;
20257 r1 -= size + position;
20258 }
20259 min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
20260 if (dragging) {
20261 max = (min += position) + size;
20262 } else {
20263 if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
20264 if (position < min) {
20265 max = min;
20266 min = position;
20267 } else {
20268 max = position;
20269 }
20270 }
20271 if (extent[0] != min || extent[1] != max) {
20272 if (i) yExtentDomain = null; else xExtentDomain = null;
20273 extent[0] = min;
20274 extent[1] = max;
20275 return true;
20276 }
20277 }
20278 function brushend() {
20279 brushmove();
20280 g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
20281 d3.select("body").style("cursor", null);
20282 w.on("mousemove.brush", null).on("mouseup.brush", null).on("touchmove.brush", null).on("touchend.brush", null).on("keydown.brush", null).on("keyup.brush", null);
20283 dragRestore();
20284 event_({
20285 type: "brushend"
20286 });
20287 }
20288 }
20289 brush.x = function(z) {
20290 if (!arguments.length) return x;
20291 x = z;
20292 resizes = d3_svg_brushResizes[!x << 1 | !y];
20293 return brush;
20294 };
20295 brush.y = function(z) {
20296 if (!arguments.length) return y;
20297 y = z;
20298 resizes = d3_svg_brushResizes[!x << 1 | !y];
20299 return brush;
20300 };
20301 brush.clamp = function(z) {
20302 if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
20303 if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
20304 return brush;
20305 };
20306 brush.extent = function(z) {
20307 var x0, x1, y0, y1, t;
20308 if (!arguments.length) {
20309 if (x) {
20310 if (xExtentDomain) {
20311 x0 = xExtentDomain[0], x1 = xExtentDomain[1];
20312 } else {
20313 x0 = xExtent[0], x1 = xExtent[1];
20314 if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
20315 if (x1 < x0) t = x0, x0 = x1, x1 = t;
20316 }
20317 }
20318 if (y) {
20319 if (yExtentDomain) {
20320 y0 = yExtentDomain[0], y1 = yExtentDomain[1];
20321 } else {
20322 y0 = yExtent[0], y1 = yExtent[1];
20323 if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
20324 if (y1 < y0) t = y0, y0 = y1, y1 = t;
20325 }
20326 }
20327 return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
20328 }
20329 if (x) {
20330 x0 = z[0], x1 = z[1];
20331 if (y) x0 = x0[0], x1 = x1[0];
20332 xExtentDomain = [ x0, x1 ];
20333 if (x.invert) x0 = x(x0), x1 = x(x1);
20334 if (x1 < x0) t = x0, x0 = x1, x1 = t;
20335 if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
20336 }
20337 if (y) {
20338 y0 = z[0], y1 = z[1];
20339 if (x) y0 = y0[1], y1 = y1[1];
20340 yExtentDomain = [ y0, y1 ];
20341 if (y.invert) y0 = y(y0), y1 = y(y1);
20342 if (y1 < y0) t = y0, y0 = y1, y1 = t;
20343 if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
20344 }
20345 return brush;
20346 };
20347 brush.clear = function() {
20348 if (!brush.empty()) {
20349 xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
20350 xExtentDomain = yExtentDomain = null;
20351 }
20352 return brush;
20353 };
20354 brush.empty = function() {
20355 return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
20356 };
20357 return d3.rebind(brush, event, "on");
20358 };
20359 var d3_svg_brushCursor = {
20360 n: "ns-resize",
20361 e: "ew-resize",
20362 s: "ns-resize",
20363 w: "ew-resize",
20364 nw: "nwse-resize",
20365 ne: "nesw-resize",
20366 se: "nwse-resize",
20367 sw: "nesw-resize"
20368 };
20369 var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
20370 var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
20371 var d3_time_formatUtc = d3_time_format.utc;
20372 var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
20373 d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
20374 function d3_time_formatIsoNative(date) {
20375 return date.toISOString();
20376 }
20377 d3_time_formatIsoNative.parse = function(string) {
20378 var date = new Date(string);
20379 return isNaN(date) ? null : date;
20380 };
20381 d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
20382 d3_time.second = d3_time_interval(function(date) {
20383 return new d3_date(Math.floor(date / 1e3) * 1e3);
20384 }, function(date, offset) {
20385 date.setTime(date.getTime() + Math.floor(offset) * 1e3);
20386 }, function(date) {
20387 return date.getSeconds();
20388 });
20389 d3_time.seconds = d3_time.second.range;
20390 d3_time.seconds.utc = d3_time.second.utc.range;
20391 d3_time.minute = d3_time_interval(function(date) {
20392 return new d3_date(Math.floor(date / 6e4) * 6e4);
20393 }, function(date, offset) {
20394 date.setTime(date.getTime() + Math.floor(offset) * 6e4);
20395 }, function(date) {
20396 return date.getMinutes();
20397 });
20398 d3_time.minutes = d3_time.minute.range;
20399 d3_time.minutes.utc = d3_time.minute.utc.range;
20400 d3_time.hour = d3_time_interval(function(date) {
20401 var timezone = date.getTimezoneOffset() / 60;
20402 return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
20403 }, function(date, offset) {
20404 date.setTime(date.getTime() + Math.floor(offset) * 36e5);
20405 }, function(date) {
20406 return date.getHours();
20407 });
20408 d3_time.hours = d3_time.hour.range;
20409 d3_time.hours.utc = d3_time.hour.utc.range;
20410 d3_time.month = d3_time_interval(function(date) {
20411 date = d3_time.day(date);
20412 date.setDate(1);
20413 return date;
20414 }, function(date, offset) {
20415 date.setMonth(date.getMonth() + offset);
20416 }, function(date) {
20417 return date.getMonth();
20418 });
20419 d3_time.months = d3_time.month.range;
20420 d3_time.months.utc = d3_time.month.utc.range;
20421 function d3_time_scale(linear, methods, format) {
20422 function scale(x) {
20423 return linear(x);
20424 }
20425 scale.invert = function(x) {
20426 return d3_time_scaleDate(linear.invert(x));
20427 };
20428 scale.domain = function(x) {
20429 if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
20430 linear.domain(x);
20431 return scale;
20432 };
20433 function tickMethod(extent, count) {
20434 var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
20435 return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
20436 return d / 31536e6;
20437 }), count)[2] ] : !i ? [ d3_time_scaleMilliseconds, d3_scale_linearTickRange(extent, count)[2] ] : methods[target / d3_time_scaleSteps[i - 1] < d3_time_scaleSteps[i] / target ? i - 1 : i];
20438 }
20439 scale.nice = function(interval, skip) {
20440 var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
20441 if (method) interval = method[0], skip = method[1];
20442 function skipped(date) {
20443 return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
20444 }
20445 return scale.domain(d3_scale_nice(domain, skip > 1 ? {
20446 floor: function(date) {
20447 while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
20448 return date;
20449 },
20450 ceil: function(date) {
20451 while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
20452 return date;
20453 }
20454 } : interval));
20455 };
20456 scale.ticks = function(interval, skip) {
20457 var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
20458 range: interval
20459 }, skip ];
20460 if (method) interval = method[0], skip = method[1];
20461 return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
20462 };
20463 scale.tickFormat = function() {
20464 return format;
20465 };
20466 scale.copy = function() {
20467 return d3_time_scale(linear.copy(), methods, format);
20468 };
20469 return d3_scale_linearRebind(scale, linear);
20470 }
20471 function d3_time_scaleDate(t) {
20472 return new Date(t);
20473 }
20474 var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
20475 var d3_time_scaleLocalMethods = [ [ d3_time.second, 1 ], [ d3_time.second, 5 ], [ d3_time.second, 15 ], [ d3_time.second, 30 ], [ d3_time.minute, 1 ], [ d3_time.minute, 5 ], [ d3_time.minute, 15 ], [ d3_time.minute, 30 ], [ d3_time.hour, 1 ], [ d3_time.hour, 3 ], [ d3_time.hour, 6 ], [ d3_time.hour, 12 ], [ d3_time.day, 1 ], [ d3_time.day, 2 ], [ d3_time.week, 1 ], [ d3_time.month, 1 ], [ d3_time.month, 3 ], [ d3_time.year, 1 ] ];
20476 var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
20477 return d.getMilliseconds();
20478 } ], [ ":%S", function(d) {
20479 return d.getSeconds();
20480 } ], [ "%I:%M", function(d) {
20481 return d.getMinutes();
20482 } ], [ "%I %p", function(d) {
20483 return d.getHours();
20484 } ], [ "%a %d", function(d) {
20485 return d.getDay() && d.getDate() != 1;
20486 } ], [ "%b %d", function(d) {
20487 return d.getDate() != 1;
20488 } ], [ "%B", function(d) {
20489 return d.getMonth();
20490 } ], [ "%Y", d3_true ] ]);
20491 var d3_time_scaleMilliseconds = {
20492 range: function(start, stop, step) {
20493 return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
20494 },
20495 floor: d3_identity,
20496 ceil: d3_identity
20497 };
20498 d3_time_scaleLocalMethods.year = d3_time.year;
20499 d3_time.scale = function() {
20500 return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
20501 };
20502 var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
20503 return [ m[0].utc, m[1] ];
20504 });
20505 var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
20506 return d.getUTCMilliseconds();
20507 } ], [ ":%S", function(d) {
20508 return d.getUTCSeconds();
20509 } ], [ "%I:%M", function(d) {
20510 return d.getUTCMinutes();
20511 } ], [ "%I %p", function(d) {
20512 return d.getUTCHours();
20513 } ], [ "%a %d", function(d) {
20514 return d.getUTCDay() && d.getUTCDate() != 1;
20515 } ], [ "%b %d", function(d) {
20516 return d.getUTCDate() != 1;
20517 } ], [ "%B", function(d) {
20518 return d.getUTCMonth();
20519 } ], [ "%Y", d3_true ] ]);
20520 d3_time_scaleUtcMethods.year = d3_time.year.utc;
20521 d3_time.scale.utc = function() {
20522 return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
20523 };
20524 d3.text = d3_xhrType(function(request) {
20525 return request.responseText;
20526 });
20527 d3.json = function(url, callback) {
20528 return d3_xhr(url, "application/json", d3_json, callback);
20529 };
20530 function d3_json(request) {
20531 return JSON.parse(request.responseText);
20532 }
20533 d3.html = function(url, callback) {
20534 return d3_xhr(url, "text/html", d3_html, callback);
20535 };
20536 function d3_html(request) {
20537 var range = d3_document.createRange();
20538 range.selectNode(d3_document.body);
20539 return range.createContextualFragment(request.responseText);
20540 }
20541 d3.xml = d3_xhrType(function(request) {
20542 return request.responseXML;
20543 });
20544 if (true) this.d3 = d3, !(__WEBPACK_AMD_DEFINE_FACTORY__ = (d3), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
20545 }();
20546
20547/***/ },
20548/* 41 */
20549/***/ function(module, exports, __webpack_require__) {
20550
20551 'use strict';
20552
20553 var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
20554
20555 exports.__esModule = true;
20556 exports.default = tooltip;
20557
20558 var _ramda = __webpack_require__(4);
20559
20560 var _utils = __webpack_require__(42);
20561
20562 var _utils2 = _interopRequireDefault(_utils);
20563
20564 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20565
20566 var _ref = _utils2.default.default || _utils2.default;
20567
20568 var prependClass = _ref.prependClass;
20569 var functor = _ref.functor;
20570
20571 var defaultOptions = {
20572 left: undefined, // mouseX
20573 top: undefined, // mouseY
20574 offset: { left: 0, top: 0 },
20575 root: undefined
20576 };
20577
20578 function tooltip(d3) {
20579 var className = arguments.length <= 1 || arguments[1] === undefined ? 'tooltip' : arguments[1];
20580 var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
20581
20582 var _defaultOptions$optio = _extends({}, defaultOptions, options);
20583
20584 var left = _defaultOptions$optio.left;
20585 var top = _defaultOptions$optio.top;
20586 var offset = _defaultOptions$optio.offset;
20587 var root = _defaultOptions$optio.root;
20588
20589 var attrs = { 'class': className };
20590 var text = function text() {
20591 return '';
20592 };
20593 var styles = {};
20594
20595 var el = undefined;
20596 var anchor = root || d3.select('body');
20597 var rootNode = anchor.node();
20598
20599 function tip(selection) {
20600 selection.on({
20601 'mouseover.tip': function mouseoverTip(node) {
20602 var _d3$mouse = d3.mouse(rootNode);
20603
20604 var mouseX = _d3$mouse[0];
20605 var mouseY = _d3$mouse[1];
20606 var x = left || mouseX + offset.left;
20607 var y = top || mouseY - offset.top;
20608
20609 anchor.selectAll('div.' + className).remove();
20610
20611 el = anchor.append('div').attr(prependClass(className)(attrs)).style(_extends({
20612 position: 'absolute',
20613 'z-index': 1001,
20614 left: x + 'px',
20615 top: y + 'px'
20616 }, styles)).html(function () {
20617 return text(node);
20618 });
20619 },
20620
20621 'mousemove.tip': function mousemoveTip(node) {
20622 var _d3$mouse2 = d3.mouse(rootNode);
20623
20624 var mouseX = _d3$mouse2[0];
20625 var mouseY = _d3$mouse2[1];
20626 var x = left || mouseX + offset.left;
20627 var y = top || mouseY - offset.top;
20628
20629 el.style({
20630 left: x + 'px',
20631 top: y + 'px'
20632 }).html(function () {
20633 return text(node);
20634 });
20635 },
20636
20637 'mouseout.tip': function mouseoutTip() {
20638 return el.remove();
20639 }
20640 });
20641 }
20642
20643 tip.attr = function setAttr(d) {
20644 if ((0, _ramda.is)(Object, d)) {
20645 attrs = _extends({}, attrs, d);
20646 }
20647 return this;
20648 };
20649
20650 tip.style = function setStyle(d) {
20651 if ((0, _ramda.is)(Object, d)) {
20652 styles = _extends({}, styles, d);
20653 }
20654 return this;
20655 };
20656
20657 tip.text = function setText(d) {
20658 text = functor(d);
20659 return this;
20660 };
20661
20662 return tip;
20663 }
20664
20665/***/ },
20666/* 42 */
20667/***/ function(module, exports, __webpack_require__) {
20668
20669 'use strict';
20670
20671 exports.__esModule = true;
20672
20673 var _prependClass = __webpack_require__(43);
20674
20675 var _prependClass2 = _interopRequireDefault(_prependClass);
20676
20677 var _functor = __webpack_require__(16);
20678
20679 var _functor2 = _interopRequireDefault(_functor);
20680
20681 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20682
20683 exports.default = {
20684 prependClass: _prependClass2.default,
20685 functor: _functor2.default
20686 };
20687
20688/***/ },
20689/* 43 */
20690/***/ function(module, exports, __webpack_require__) {
20691
20692 'use strict';
20693
20694 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
20695
20696 exports.__esModule = true;
20697 exports.default = prependClass;
20698
20699 var _ramda = __webpack_require__(4);
20700
20701 var _functor = __webpack_require__(16);
20702
20703 var _functor2 = _interopRequireDefault(_functor);
20704
20705 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20706
20707 function prependClass(className) {
20708 return (0, _ramda.mapObjIndexed)(function (value, key) {
20709 if (key === 'class') {
20710 var _ret = function () {
20711 var fn = (0, _functor2.default)(value);
20712
20713 return {
20714 v: function v(d, i) {
20715 var classNames = fn(d, i);
20716 if (classNames !== className) {
20717 return (0, _ramda.join)(' ', [className, classNames]);
20718 }
20719 return classNames;
20720 }
20721 };
20722 }();
20723
20724 if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
20725 }
20726
20727 return value;
20728 });
20729 }
20730
20731/***/ },
20732/* 44 */
20733/***/ function(module, exports, __webpack_require__) {
20734
20735 var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (root, factory) {
20736 if (true) {
20737 !(__WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
20738 } else if (typeof exports === 'object') {
20739 module.exports = factory();
20740 } else {
20741 root.deepmerge = factory();
20742 }
20743 }(this, function () {
20744
20745 return function deepmerge(target, src) {
20746 var array = Array.isArray(src);
20747 var dst = array && [] || {};
20748
20749 if (array) {
20750 target = target || [];
20751 dst = dst.concat(target);
20752 src.forEach(function(e, i) {
20753 if (typeof dst[i] === 'undefined') {
20754 dst[i] = e;
20755 } else if (typeof e === 'object') {
20756 dst[i] = deepmerge(target[i], e);
20757 } else {
20758 if (target.indexOf(e) === -1) {
20759 dst.push(e);
20760 }
20761 }
20762 });
20763 } else {
20764 if (target && typeof target === 'object') {
20765 Object.keys(target).forEach(function (key) {
20766 dst[key] = target[key];
20767 })
20768 }
20769 Object.keys(src).forEach(function (key) {
20770 if (typeof src[key] !== 'object' || !src[key]) {
20771 dst[key] = src[key];
20772 }
20773 else {
20774 if (!target[key]) {
20775 dst[key] = src[key];
20776 } else {
20777 dst[key] = deepmerge(target[key], src[key]);
20778 }
20779 }
20780 });
20781 }
20782
20783 return dst;
20784 }
20785
20786 }));
20787
20788
20789/***/ },
20790/* 45 */
20791/***/ function(module, exports, __webpack_require__) {
20792
20793 var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(Buffer) {(function (root, factory) {
20794 if (true) {
20795 // AMD
20796 !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
20797 } else if (typeof module === 'object' && module.exports) {
20798 //node
20799 module.exports = factory();
20800 } else {
20801 // Browser globals (root is window)
20802 root.fclone = factory();
20803 }
20804 }(this, function () {
20805 'use strict';
20806
20807 // see if it looks and smells like an iterable object, and do accept length === 0
20808
20809 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
20810
20811 function isArrayLike(item) {
20812 if (Array.isArray(item)) return true;
20813
20814 var len = item && item.length;
20815 return typeof len === 'number' && (len === 0 || len - 1 in item) && typeof item.indexOf === 'function';
20816 }
20817
20818 function fclone(obj, refs) {
20819 if (!obj || "object" !== (typeof obj === 'undefined' ? 'undefined' : _typeof(obj))) return obj;
20820
20821 if (obj instanceof Date) {
20822 return new Date(obj);
20823 }
20824
20825 if (typeof Buffer !== 'undefined' && Buffer.isBuffer(obj)) {
20826 return new Buffer(obj);
20827 }
20828
20829 // typed array Int32Array etc.
20830 if (/\d[a-z]*Array]$/i.test(Object.prototype.toString.call(obj))) {
20831 return obj.subarray(0);
20832 }
20833
20834 if (!refs) {
20835 refs = [];
20836 }
20837
20838 if (isArrayLike(obj)) {
20839 refs[refs.length] = obj;
20840 var _l = obj.length;
20841 var i = -1;
20842 var _copy = [];
20843
20844 while (_l > ++i) {
20845 _copy[i] = ~refs.indexOf(obj[i]) ? '[Circular]' : fclone(obj[i], refs);
20846 }
20847
20848 refs.length && refs.length--;
20849 return _copy;
20850 }
20851
20852 refs[refs.length] = obj;
20853 var copy = {};
20854
20855 if (obj instanceof Error) {
20856 copy.name = obj.name;
20857 copy.message = obj.message;
20858 copy.stack = obj.stack;
20859 }
20860
20861 var keys = Object.keys(obj);
20862 var l = keys.length;
20863
20864 while (l--) {
20865 var k = keys[l];
20866 copy[k] = ~refs.indexOf(obj[k]) ? '[Circular]' : fclone(obj[k], refs);
20867 }
20868
20869 refs.length && refs.length--;
20870 return copy;
20871 }
20872 return fclone
20873 }));
20874 /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(15).Buffer))
20875
20876/***/ },
20877/* 46 */
20878/***/ function(module, exports) {
20879
20880 exports.read = function (buffer, offset, isLE, mLen, nBytes) {
20881 var e, m
20882 var eLen = nBytes * 8 - mLen - 1
20883 var eMax = (1 << eLen) - 1
20884 var eBias = eMax >> 1
20885 var nBits = -7
20886 var i = isLE ? (nBytes - 1) : 0
20887 var d = isLE ? -1 : 1
20888 var s = buffer[offset + i]
20889
20890 i += d
20891
20892 e = s & ((1 << (-nBits)) - 1)
20893 s >>= (-nBits)
20894 nBits += eLen
20895 for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
20896
20897 m = e & ((1 << (-nBits)) - 1)
20898 e >>= (-nBits)
20899 nBits += mLen
20900 for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
20901
20902 if (e === 0) {
20903 e = 1 - eBias
20904 } else if (e === eMax) {
20905 return m ? NaN : ((s ? -1 : 1) * Infinity)
20906 } else {
20907 m = m + Math.pow(2, mLen)
20908 e = e - eBias
20909 }
20910 return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
20911 }
20912
20913 exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
20914 var e, m, c
20915 var eLen = nBytes * 8 - mLen - 1
20916 var eMax = (1 << eLen) - 1
20917 var eBias = eMax >> 1
20918 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
20919 var i = isLE ? 0 : (nBytes - 1)
20920 var d = isLE ? 1 : -1
20921 var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
20922
20923 value = Math.abs(value)
20924
20925 if (isNaN(value) || value === Infinity) {
20926 m = isNaN(value) ? 1 : 0
20927 e = eMax
20928 } else {
20929 e = Math.floor(Math.log(value) / Math.LN2)
20930 if (value * (c = Math.pow(2, -e)) < 1) {
20931 e--
20932 c *= 2
20933 }
20934 if (e + eBias >= 1) {
20935 value += rt / c
20936 } else {
20937 value += rt * Math.pow(2, 1 - eBias)
20938 }
20939 if (value * c >= 2) {
20940 e++
20941 c /= 2
20942 }
20943
20944 if (e + eBias >= eMax) {
20945 m = 0
20946 e = eMax
20947 } else if (e + eBias >= 1) {
20948 m = (value * c - 1) * Math.pow(2, mLen)
20949 e = e + eBias
20950 } else {
20951 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
20952 e = 0
20953 }
20954 }
20955
20956 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
20957
20958 e = (e << mLen) | m
20959 eLen += mLen
20960 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
20961
20962 buffer[offset + i - d] |= s * 128
20963 }
20964
20965
20966/***/ },
20967/* 47 */
20968/***/ function(module, exports) {
20969
20970 var toString = {}.toString;
20971
20972 module.exports = Array.isArray || function (arr) {
20973 return toString.call(arr) == '[object Array]';
20974 };
20975
20976
20977/***/ },
20978/* 48 */
20979/***/ function(module, exports) {
20980
20981 module.exports = (function() {
20982 function sortObject(obj, strict) {
20983 if(obj instanceof Array) {
20984 var ary;
20985 if(strict) {
20986 ary = obj.sort();
20987 } else {
20988 ary = obj;
20989 }
20990 return ary;
20991 }
20992 if(typeof obj === 'object') {
20993 var tObj = {};
20994 Object.keys(obj).sort().forEach(function(key) {
20995 tObj[key] = sortObject(obj[key]);
20996 });
20997 return tObj;
20998 }
20999 return obj;
21000 }
21001
21002 function fixArrays(obj) {
21003 var l = Object.keys(obj);
21004 var ret = [];
21005 if(l.length == l.filter(function(e) {
21006 return e.match(/^\d+$/); }).length && l.length > 0) {
21007 l.forEach(function(k) {
21008 ret.push(obj[k]);
21009 });
21010 return ret;
21011 } else {
21012 return false;
21013 }
21014 }
21015
21016 return function(obj) {
21017 return JSON.stringify(sortObject(obj, true), undefined, 2);
21018 };
21019 })();
21020
21021
21022/***/ },
21023/* 49 */
21024/***/ function(module, exports, __webpack_require__) {
21025
21026 var nativeCreate = __webpack_require__(7);
21027
21028 /** Used for built-in method references. */
21029 var objectProto = Object.prototype;
21030
21031 /**
21032 * Creates an hash object.
21033 *
21034 * @private
21035 * @returns {Object} Returns the new hash object.
21036 */
21037 function Hash() {}
21038
21039 // Avoid inheriting from `Object.prototype` when possible.
21040 Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto;
21041
21042 module.exports = Hash;
21043
21044
21045/***/ },
21046/* 50 */
21047/***/ function(module, exports, __webpack_require__) {
21048
21049 var mapClear = __webpack_require__(83),
21050 mapDelete = __webpack_require__(84),
21051 mapGet = __webpack_require__(85),
21052 mapHas = __webpack_require__(86),
21053 mapSet = __webpack_require__(87);
21054
21055 /**
21056 * Creates a map cache object to store key-value pairs.
21057 *
21058 * @private
21059 * @param {Array} [values] The values to cache.
21060 */
21061 function MapCache(values) {
21062 var index = -1,
21063 length = values ? values.length : 0;
21064
21065 this.clear();
21066 while (++index < length) {
21067 var entry = values[index];
21068 this.set(entry[0], entry[1]);
21069 }
21070 }
21071
21072 // Add functions to the `MapCache`.
21073 MapCache.prototype.clear = mapClear;
21074 MapCache.prototype['delete'] = mapDelete;
21075 MapCache.prototype.get = mapGet;
21076 MapCache.prototype.has = mapHas;
21077 MapCache.prototype.set = mapSet;
21078
21079 module.exports = MapCache;
21080
21081
21082/***/ },
21083/* 51 */
21084/***/ function(module, exports, __webpack_require__) {
21085
21086 var getNative = __webpack_require__(10),
21087 root = __webpack_require__(8);
21088
21089 /* Built-in method references that are verified to be native. */
21090 var Set = getNative(root, 'Set');
21091
21092 module.exports = Set;
21093
21094
21095/***/ },
21096/* 52 */
21097/***/ function(module, exports, __webpack_require__) {
21098
21099 var root = __webpack_require__(8);
21100
21101 /** Built-in value references. */
21102 var Uint8Array = root.Uint8Array;
21103
21104 module.exports = Uint8Array;
21105
21106
21107/***/ },
21108/* 53 */
21109/***/ function(module, exports) {
21110
21111 /**
21112 * A specialized version of `_.map` for arrays without support for iteratee
21113 * shorthands.
21114 *
21115 * @private
21116 * @param {Array} array The array to iterate over.
21117 * @param {Function} iteratee The function invoked per iteration.
21118 * @returns {Array} Returns the new mapped array.
21119 */
21120 function arrayMap(array, iteratee) {
21121 var index = -1,
21122 length = array.length,
21123 result = Array(length);
21124
21125 while (++index < length) {
21126 result[index] = iteratee(array[index], index, array);
21127 }
21128 return result;
21129 }
21130
21131 module.exports = arrayMap;
21132
21133
21134/***/ },
21135/* 54 */
21136/***/ function(module, exports) {
21137
21138 /**
21139 * A specialized version of `_.some` for arrays without support for iteratee
21140 * shorthands.
21141 *
21142 * @private
21143 * @param {Array} array The array to iterate over.
21144 * @param {Function} predicate The function invoked per iteration.
21145 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
21146 */
21147 function arraySome(array, predicate) {
21148 var index = -1,
21149 length = array.length;
21150
21151 while (++index < length) {
21152 if (predicate(array[index], index, array)) {
21153 return true;
21154 }
21155 }
21156 return false;
21157 }
21158
21159 module.exports = arraySome;
21160
21161
21162/***/ },
21163/* 55 */
21164/***/ function(module, exports, __webpack_require__) {
21165
21166 var createBaseFor = __webpack_require__(69);
21167
21168 /**
21169 * The base implementation of `baseForIn` and `baseForOwn` which iterates
21170 * over `object` properties returned by `keysFunc` invoking `iteratee` for
21171 * each property. Iteratee functions may exit iteration early by explicitly
21172 * returning `false`.
21173 *
21174 * @private
21175 * @param {Object} object The object to iterate over.
21176 * @param {Function} iteratee The function invoked per iteration.
21177 * @param {Function} keysFunc The function to get the keys of `object`.
21178 * @returns {Object} Returns `object`.
21179 */
21180 var baseFor = createBaseFor();
21181
21182 module.exports = baseFor;
21183
21184
21185/***/ },
21186/* 56 */
21187/***/ function(module, exports, __webpack_require__) {
21188
21189 var baseFor = __webpack_require__(55),
21190 keys = __webpack_require__(14);
21191
21192 /**
21193 * The base implementation of `_.forOwn` without support for iteratee shorthands.
21194 *
21195 * @private
21196 * @param {Object} object The object to iterate over.
21197 * @param {Function} iteratee The function invoked per iteration.
21198 * @returns {Object} Returns `object`.
21199 */
21200 function baseForOwn(object, iteratee) {
21201 return object && baseFor(object, iteratee, keys);
21202 }
21203
21204 module.exports = baseForOwn;
21205
21206
21207/***/ },
21208/* 57 */
21209/***/ function(module, exports) {
21210
21211 /**
21212 * The base implementation of `_.hasIn` without support for deep paths.
21213 *
21214 * @private
21215 * @param {Object} object The object to query.
21216 * @param {Array|string} key The key to check.
21217 * @returns {boolean} Returns `true` if `key` exists, else `false`.
21218 */
21219 function baseHasIn(object, key) {
21220 return key in Object(object);
21221 }
21222
21223 module.exports = baseHasIn;
21224
21225
21226/***/ },
21227/* 58 */
21228/***/ function(module, exports, __webpack_require__) {
21229
21230 var Stack = __webpack_require__(17),
21231 equalArrays = __webpack_require__(70),
21232 equalByTag = __webpack_require__(71),
21233 equalObjects = __webpack_require__(72),
21234 getTag = __webpack_require__(75),
21235 isArray = __webpack_require__(1),
21236 isHostObject = __webpack_require__(11),
21237 isTypedArray = __webpack_require__(104);
21238
21239 /** Used to compose bitmasks for comparison styles. */
21240 var PARTIAL_COMPARE_FLAG = 2;
21241
21242 /** `Object#toString` result references. */
21243 var argsTag = '[object Arguments]',
21244 arrayTag = '[object Array]',
21245 objectTag = '[object Object]';
21246
21247 /** Used for built-in method references. */
21248 var objectProto = Object.prototype;
21249
21250 /** Used to check objects for own properties. */
21251 var hasOwnProperty = objectProto.hasOwnProperty;
21252
21253 /**
21254 * A specialized version of `baseIsEqual` for arrays and objects which performs
21255 * deep comparisons and tracks traversed objects enabling objects with circular
21256 * references to be compared.
21257 *
21258 * @private
21259 * @param {Object} object The object to compare.
21260 * @param {Object} other The other object to compare.
21261 * @param {Function} equalFunc The function to determine equivalents of values.
21262 * @param {Function} [customizer] The function to customize comparisons.
21263 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
21264 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
21265 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
21266 */
21267 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
21268 var objIsArr = isArray(object),
21269 othIsArr = isArray(other),
21270 objTag = arrayTag,
21271 othTag = arrayTag;
21272
21273 if (!objIsArr) {
21274 objTag = getTag(object);
21275 if (objTag == argsTag) {
21276 objTag = objectTag;
21277 } else if (objTag != objectTag) {
21278 objIsArr = isTypedArray(object);
21279 }
21280 }
21281 if (!othIsArr) {
21282 othTag = getTag(other);
21283 if (othTag == argsTag) {
21284 othTag = objectTag;
21285 } else if (othTag != objectTag) {
21286 othIsArr = isTypedArray(other);
21287 }
21288 }
21289 var objIsObj = objTag == objectTag && !isHostObject(object),
21290 othIsObj = othTag == objectTag && !isHostObject(other),
21291 isSameTag = objTag == othTag;
21292
21293 if (isSameTag && !(objIsArr || objIsObj)) {
21294 return equalByTag(object, other, objTag, equalFunc, customizer, bitmask);
21295 }
21296 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
21297 if (!isPartial) {
21298 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
21299 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
21300
21301 if (objIsWrapped || othIsWrapped) {
21302 return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
21303 }
21304 }
21305 if (!isSameTag) {
21306 return false;
21307 }
21308 stack || (stack = new Stack);
21309 return (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack);
21310 }
21311
21312 module.exports = baseIsEqualDeep;
21313
21314
21315/***/ },
21316/* 59 */
21317/***/ function(module, exports, __webpack_require__) {
21318
21319 var Stack = __webpack_require__(17),
21320 baseIsEqual = __webpack_require__(25);
21321
21322 /** Used to compose bitmasks for comparison styles. */
21323 var UNORDERED_COMPARE_FLAG = 1,
21324 PARTIAL_COMPARE_FLAG = 2;
21325
21326 /**
21327 * The base implementation of `_.isMatch` without support for iteratee shorthands.
21328 *
21329 * @private
21330 * @param {Object} object The object to inspect.
21331 * @param {Object} source The object of property values to match.
21332 * @param {Array} matchData The property names, values, and compare flags to match.
21333 * @param {Function} [customizer] The function to customize comparisons.
21334 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
21335 */
21336 function baseIsMatch(object, source, matchData, customizer) {
21337 var index = matchData.length,
21338 length = index,
21339 noCustomizer = !customizer;
21340
21341 if (object == null) {
21342 return !length;
21343 }
21344 object = Object(object);
21345 while (index--) {
21346 var data = matchData[index];
21347 if ((noCustomizer && data[2])
21348 ? data[1] !== object[data[0]]
21349 : !(data[0] in object)
21350 ) {
21351 return false;
21352 }
21353 }
21354 while (++index < length) {
21355 data = matchData[index];
21356 var key = data[0],
21357 objValue = object[key],
21358 srcValue = data[1];
21359
21360 if (noCustomizer && data[2]) {
21361 if (objValue === undefined && !(key in object)) {
21362 return false;
21363 }
21364 } else {
21365 var stack = new Stack,
21366 result = customizer ? customizer(objValue, srcValue, key, object, source, stack) : undefined;
21367
21368 if (!(result === undefined
21369 ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
21370 : result
21371 )) {
21372 return false;
21373 }
21374 }
21375 }
21376 return true;
21377 }
21378
21379 module.exports = baseIsMatch;
21380
21381
21382/***/ },
21383/* 60 */
21384/***/ function(module, exports, __webpack_require__) {
21385
21386 var baseMatches = __webpack_require__(62),
21387 baseMatchesProperty = __webpack_require__(63),
21388 identity = __webpack_require__(99),
21389 isArray = __webpack_require__(1),
21390 property = __webpack_require__(107);
21391
21392 /**
21393 * The base implementation of `_.iteratee`.
21394 *
21395 * @private
21396 * @param {*} [value=_.identity] The value to convert to an iteratee.
21397 * @returns {Function} Returns the iteratee.
21398 */
21399 function baseIteratee(value) {
21400 var type = typeof value;
21401 if (type == 'function') {
21402 return value;
21403 }
21404 if (value == null) {
21405 return identity;
21406 }
21407 if (type == 'object') {
21408 return isArray(value)
21409 ? baseMatchesProperty(value[0], value[1])
21410 : baseMatches(value);
21411 }
21412 return property(value);
21413 }
21414
21415 module.exports = baseIteratee;
21416
21417
21418/***/ },
21419/* 61 */
21420/***/ function(module, exports) {
21421
21422 /* Built-in method references for those with the same name as other `lodash` methods. */
21423 var nativeKeys = Object.keys;
21424
21425 /**
21426 * The base implementation of `_.keys` which doesn't skip the constructor
21427 * property of prototypes or treat sparse arrays as dense.
21428 *
21429 * @private
21430 * @type Function
21431 * @param {Object} object The object to query.
21432 * @returns {Array} Returns the array of property names.
21433 */
21434 function baseKeys(object) {
21435 return nativeKeys(Object(object));
21436 }
21437
21438 module.exports = baseKeys;
21439
21440
21441/***/ },
21442/* 62 */
21443/***/ function(module, exports, __webpack_require__) {
21444
21445 var baseIsMatch = __webpack_require__(59),
21446 getMatchData = __webpack_require__(74);
21447
21448 /**
21449 * The base implementation of `_.matches` which doesn't clone `source`.
21450 *
21451 * @private
21452 * @param {Object} source The object of property values to match.
21453 * @returns {Function} Returns the new function.
21454 */
21455 function baseMatches(source) {
21456 var matchData = getMatchData(source);
21457 if (matchData.length == 1 && matchData[0][2]) {
21458 var key = matchData[0][0],
21459 value = matchData[0][1];
21460
21461 return function(object) {
21462 if (object == null) {
21463 return false;
21464 }
21465 return object[key] === value &&
21466 (value !== undefined || (key in Object(object)));
21467 };
21468 }
21469 return function(object) {
21470 return object === source || baseIsMatch(object, source, matchData);
21471 };
21472 }
21473
21474 module.exports = baseMatches;
21475
21476
21477/***/ },
21478/* 63 */
21479/***/ function(module, exports, __webpack_require__) {
21480
21481 var baseIsEqual = __webpack_require__(25),
21482 get = __webpack_require__(30),
21483 hasIn = __webpack_require__(98);
21484
21485 /** Used to compose bitmasks for comparison styles. */
21486 var UNORDERED_COMPARE_FLAG = 1,
21487 PARTIAL_COMPARE_FLAG = 2;
21488
21489 /**
21490 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
21491 *
21492 * @private
21493 * @param {string} path The path of the property to get.
21494 * @param {*} srcValue The value to match.
21495 * @returns {Function} Returns the new function.
21496 */
21497 function baseMatchesProperty(path, srcValue) {
21498 return function(object) {
21499 var objValue = get(object, path);
21500 return (objValue === undefined && objValue === srcValue)
21501 ? hasIn(object, path)
21502 : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
21503 };
21504 }
21505
21506 module.exports = baseMatchesProperty;
21507
21508
21509/***/ },
21510/* 64 */
21511/***/ function(module, exports, __webpack_require__) {
21512
21513 var baseGet = __webpack_require__(23);
21514
21515 /**
21516 * A specialized version of `baseProperty` which supports deep paths.
21517 *
21518 * @private
21519 * @param {Array|string} path The path of the property to get.
21520 * @returns {Function} Returns the new function.
21521 */
21522 function basePropertyDeep(path) {
21523 return function(object) {
21524 return baseGet(object, path);
21525 };
21526 }
21527
21528 module.exports = basePropertyDeep;
21529
21530
21531/***/ },
21532/* 65 */
21533/***/ function(module, exports) {
21534
21535 /**
21536 * The base implementation of `_.slice` without an iteratee call guard.
21537 *
21538 * @private
21539 * @param {Array} array The array to slice.
21540 * @param {number} [start=0] The start position.
21541 * @param {number} [end=array.length] The end position.
21542 * @returns {Array} Returns the slice of `array`.
21543 */
21544 function baseSlice(array, start, end) {
21545 var index = -1,
21546 length = array.length;
21547
21548 if (start < 0) {
21549 start = -start > length ? 0 : (length + start);
21550 }
21551 end = end > length ? length : end;
21552 if (end < 0) {
21553 end += length;
21554 }
21555 length = start > end ? 0 : ((end - start) >>> 0);
21556 start >>>= 0;
21557
21558 var result = Array(length);
21559 while (++index < length) {
21560 result[index] = array[index + start];
21561 }
21562 return result;
21563 }
21564
21565 module.exports = baseSlice;
21566
21567
21568/***/ },
21569/* 66 */
21570/***/ function(module, exports) {
21571
21572 /**
21573 * The base implementation of `_.times` without support for iteratee shorthands
21574 * or max array length checks.
21575 *
21576 * @private
21577 * @param {number} n The number of times to invoke `iteratee`.
21578 * @param {Function} iteratee The function invoked per iteration.
21579 * @returns {Array} Returns the array of results.
21580 */
21581 function baseTimes(n, iteratee) {
21582 var index = -1,
21583 result = Array(n);
21584
21585 while (++index < n) {
21586 result[index] = iteratee(index);
21587 }
21588 return result;
21589 }
21590
21591 module.exports = baseTimes;
21592
21593
21594/***/ },
21595/* 67 */
21596/***/ function(module, exports, __webpack_require__) {
21597
21598 var arrayMap = __webpack_require__(53);
21599
21600 /**
21601 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
21602 * of key-value pairs for `object` corresponding to the property names of `props`.
21603 *
21604 * @private
21605 * @param {Object} object The object to query.
21606 * @param {Array} props The property names to get values for.
21607 * @returns {Object} Returns the new array of key-value pairs.
21608 */
21609 function baseToPairs(object, props) {
21610 return arrayMap(props, function(key) {
21611 return [key, object[key]];
21612 });
21613 }
21614
21615 module.exports = baseToPairs;
21616
21617
21618/***/ },
21619/* 68 */
21620/***/ function(module, exports) {
21621
21622 /**
21623 * Checks if `value` is a global object.
21624 *
21625 * @private
21626 * @param {*} value The value to check.
21627 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
21628 */
21629 function checkGlobal(value) {
21630 return (value && value.Object === Object) ? value : null;
21631 }
21632
21633 module.exports = checkGlobal;
21634
21635
21636/***/ },
21637/* 69 */
21638/***/ function(module, exports) {
21639
21640 /**
21641 * Creates a base function for methods like `_.forIn`.
21642 *
21643 * @private
21644 * @param {boolean} [fromRight] Specify iterating from right to left.
21645 * @returns {Function} Returns the new base function.
21646 */
21647 function createBaseFor(fromRight) {
21648 return function(object, iteratee, keysFunc) {
21649 var index = -1,
21650 iterable = Object(object),
21651 props = keysFunc(object),
21652 length = props.length;
21653
21654 while (length--) {
21655 var key = props[fromRight ? length : ++index];
21656 if (iteratee(iterable[key], key, iterable) === false) {
21657 break;
21658 }
21659 }
21660 return object;
21661 };
21662 }
21663
21664 module.exports = createBaseFor;
21665
21666
21667/***/ },
21668/* 70 */
21669/***/ function(module, exports, __webpack_require__) {
21670
21671 var arraySome = __webpack_require__(54);
21672
21673 /** Used to compose bitmasks for comparison styles. */
21674 var UNORDERED_COMPARE_FLAG = 1,
21675 PARTIAL_COMPARE_FLAG = 2;
21676
21677 /**
21678 * A specialized version of `baseIsEqualDeep` for arrays with support for
21679 * partial deep comparisons.
21680 *
21681 * @private
21682 * @param {Array} array The array to compare.
21683 * @param {Array} other The other array to compare.
21684 * @param {Function} equalFunc The function to determine equivalents of values.
21685 * @param {Function} [customizer] The function to customize comparisons.
21686 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
21687 * @param {Object} [stack] Tracks traversed `array` and `other` objects.
21688 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
21689 */
21690 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
21691 var index = -1,
21692 isPartial = bitmask & PARTIAL_COMPARE_FLAG,
21693 isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
21694 arrLength = array.length,
21695 othLength = other.length;
21696
21697 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
21698 return false;
21699 }
21700 // Assume cyclic values are equal.
21701 var stacked = stack.get(array);
21702 if (stacked) {
21703 return stacked == other;
21704 }
21705 var result = true;
21706 stack.set(array, other);
21707
21708 // Ignore non-index properties.
21709 while (++index < arrLength) {
21710 var arrValue = array[index],
21711 othValue = other[index];
21712
21713 if (customizer) {
21714 var compared = isPartial
21715 ? customizer(othValue, arrValue, index, other, array, stack)
21716 : customizer(arrValue, othValue, index, array, other, stack);
21717 }
21718 if (compared !== undefined) {
21719 if (compared) {
21720 continue;
21721 }
21722 result = false;
21723 break;
21724 }
21725 // Recursively compare arrays (susceptible to call stack limits).
21726 if (isUnordered) {
21727 if (!arraySome(other, function(othValue) {
21728 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
21729 })) {
21730 result = false;
21731 break;
21732 }
21733 } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
21734 result = false;
21735 break;
21736 }
21737 }
21738 stack['delete'](array);
21739 return result;
21740 }
21741
21742 module.exports = equalArrays;
21743
21744
21745/***/ },
21746/* 71 */
21747/***/ function(module, exports, __webpack_require__) {
21748
21749 var Symbol = __webpack_require__(18),
21750 Uint8Array = __webpack_require__(52),
21751 mapToArray = __webpack_require__(88),
21752 setToArray = __webpack_require__(90);
21753
21754 /** Used to compose bitmasks for comparison styles. */
21755 var UNORDERED_COMPARE_FLAG = 1,
21756 PARTIAL_COMPARE_FLAG = 2;
21757
21758 /** `Object#toString` result references. */
21759 var boolTag = '[object Boolean]',
21760 dateTag = '[object Date]',
21761 errorTag = '[object Error]',
21762 mapTag = '[object Map]',
21763 numberTag = '[object Number]',
21764 regexpTag = '[object RegExp]',
21765 setTag = '[object Set]',
21766 stringTag = '[object String]',
21767 symbolTag = '[object Symbol]';
21768
21769 var arrayBufferTag = '[object ArrayBuffer]';
21770
21771 /** Used to convert symbols to primitives and strings. */
21772 var symbolProto = Symbol ? Symbol.prototype : undefined,
21773 symbolValueOf = Symbol ? symbolProto.valueOf : undefined;
21774
21775 /**
21776 * A specialized version of `baseIsEqualDeep` for comparing objects of
21777 * the same `toStringTag`.
21778 *
21779 * **Note:** This function only supports comparing values with tags of
21780 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
21781 *
21782 * @private
21783 * @param {Object} object The object to compare.
21784 * @param {Object} other The other object to compare.
21785 * @param {string} tag The `toStringTag` of the objects to compare.
21786 * @param {Function} equalFunc The function to determine equivalents of values.
21787 * @param {Function} [customizer] The function to customize comparisons.
21788 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
21789 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
21790 */
21791 function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
21792 switch (tag) {
21793 case arrayBufferTag:
21794 if ((object.byteLength != other.byteLength) ||
21795 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
21796 return false;
21797 }
21798 return true;
21799
21800 case boolTag:
21801 case dateTag:
21802 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
21803 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
21804 return +object == +other;
21805
21806 case errorTag:
21807 return object.name == other.name && object.message == other.message;
21808
21809 case numberTag:
21810 // Treat `NaN` vs. `NaN` as equal.
21811 return (object != +object) ? other != +other : object == +other;
21812
21813 case regexpTag:
21814 case stringTag:
21815 // Coerce regexes to strings and treat strings primitives and string
21816 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
21817 return object == (other + '');
21818
21819 case mapTag:
21820 var convert = mapToArray;
21821
21822 case setTag:
21823 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
21824 convert || (convert = setToArray);
21825
21826 // Recursively compare objects (susceptible to call stack limits).
21827 return (isPartial || object.size == other.size) &&
21828 equalFunc(convert(object), convert(other), customizer, bitmask | UNORDERED_COMPARE_FLAG);
21829
21830 case symbolTag:
21831 return !!Symbol && (symbolValueOf.call(object) == symbolValueOf.call(other));
21832 }
21833 return false;
21834 }
21835
21836 module.exports = equalByTag;
21837
21838
21839/***/ },
21840/* 72 */
21841/***/ function(module, exports, __webpack_require__) {
21842
21843 var baseHas = __webpack_require__(24),
21844 keys = __webpack_require__(14);
21845
21846 /** Used to compose bitmasks for comparison styles. */
21847 var PARTIAL_COMPARE_FLAG = 2;
21848
21849 /**
21850 * A specialized version of `baseIsEqualDeep` for objects with support for
21851 * partial deep comparisons.
21852 *
21853 * @private
21854 * @param {Object} object The object to compare.
21855 * @param {Object} other The other object to compare.
21856 * @param {Function} equalFunc The function to determine equivalents of values.
21857 * @param {Function} [customizer] The function to customize comparisons.
21858 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
21859 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
21860 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
21861 */
21862 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
21863 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
21864 objProps = keys(object),
21865 objLength = objProps.length,
21866 othProps = keys(other),
21867 othLength = othProps.length;
21868
21869 if (objLength != othLength && !isPartial) {
21870 return false;
21871 }
21872 var index = objLength;
21873 while (index--) {
21874 var key = objProps[index];
21875 if (!(isPartial ? key in other : baseHas(other, key))) {
21876 return false;
21877 }
21878 }
21879 // Assume cyclic values are equal.
21880 var stacked = stack.get(object);
21881 if (stacked) {
21882 return stacked == other;
21883 }
21884 var result = true;
21885 stack.set(object, other);
21886
21887 var skipCtor = isPartial;
21888 while (++index < objLength) {
21889 key = objProps[index];
21890 var objValue = object[key],
21891 othValue = other[key];
21892
21893 if (customizer) {
21894 var compared = isPartial
21895 ? customizer(othValue, objValue, key, other, object, stack)
21896 : customizer(objValue, othValue, key, object, other, stack);
21897 }
21898 // Recursively compare objects (susceptible to call stack limits).
21899 if (!(compared === undefined
21900 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
21901 : compared
21902 )) {
21903 result = false;
21904 break;
21905 }
21906 skipCtor || (skipCtor = key == 'constructor');
21907 }
21908 if (result && !skipCtor) {
21909 var objCtor = object.constructor,
21910 othCtor = other.constructor;
21911
21912 // Non `Object` object instances with different constructors are not equal.
21913 if (objCtor != othCtor &&
21914 ('constructor' in object && 'constructor' in other) &&
21915 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
21916 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
21917 result = false;
21918 }
21919 }
21920 stack['delete'](object);
21921 return result;
21922 }
21923
21924 module.exports = equalObjects;
21925
21926
21927/***/ },
21928/* 73 */
21929/***/ function(module, exports, __webpack_require__) {
21930
21931 var baseProperty = __webpack_require__(26);
21932
21933 /**
21934 * Gets the "length" property value of `object`.
21935 *
21936 * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
21937 * that affects Safari on at least iOS 8.1-8.3 ARM64.
21938 *
21939 * @private
21940 * @param {Object} object The object to query.
21941 * @returns {*} Returns the "length" value.
21942 */
21943 var getLength = baseProperty('length');
21944
21945 module.exports = getLength;
21946
21947
21948/***/ },
21949/* 74 */
21950/***/ function(module, exports, __webpack_require__) {
21951
21952 var isStrictComparable = __webpack_require__(82),
21953 toPairs = __webpack_require__(108);
21954
21955 /**
21956 * Gets the property names, values, and compare flags of `object`.
21957 *
21958 * @private
21959 * @param {Object} object The object to query.
21960 * @returns {Array} Returns the match data of `object`.
21961 */
21962 function getMatchData(object) {
21963 var result = toPairs(object),
21964 length = result.length;
21965
21966 while (length--) {
21967 result[length][2] = isStrictComparable(result[length][1]);
21968 }
21969 return result;
21970 }
21971
21972 module.exports = getMatchData;
21973
21974
21975/***/ },
21976/* 75 */
21977/***/ function(module, exports, __webpack_require__) {
21978
21979 var Map = __webpack_require__(3),
21980 Set = __webpack_require__(51);
21981
21982 /** `Object#toString` result references. */
21983 var mapTag = '[object Map]',
21984 objectTag = '[object Object]',
21985 setTag = '[object Set]';
21986
21987 /** Used for built-in method references. */
21988 var objectProto = Object.prototype;
21989
21990 /** Used to resolve the decompiled source of functions. */
21991 var funcToString = Function.prototype.toString;
21992
21993 /**
21994 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
21995 * of values.
21996 */
21997 var objectToString = objectProto.toString;
21998
21999 /** Used to detect maps and sets. */
22000 var mapCtorString = Map ? funcToString.call(Map) : '',
22001 setCtorString = Set ? funcToString.call(Set) : '';
22002
22003 /**
22004 * Gets the `toStringTag` of `value`.
22005 *
22006 * @private
22007 * @param {*} value The value to query.
22008 * @returns {string} Returns the `toStringTag`.
22009 */
22010 function getTag(value) {
22011 return objectToString.call(value);
22012 }
22013
22014 // Fallback for IE 11 providing `toStringTag` values for maps and sets.
22015 if ((Map && getTag(new Map) != mapTag) || (Set && getTag(new Set) != setTag)) {
22016 getTag = function(value) {
22017 var result = objectToString.call(value),
22018 Ctor = result == objectTag ? value.constructor : null,
22019 ctorString = typeof Ctor == 'function' ? funcToString.call(Ctor) : '';
22020
22021 if (ctorString) {
22022 if (ctorString == mapCtorString) {
22023 return mapTag;
22024 }
22025 if (ctorString == setCtorString) {
22026 return setTag;
22027 }
22028 }
22029 return result;
22030 };
22031 }
22032
22033 module.exports = getTag;
22034
22035
22036/***/ },
22037/* 76 */
22038/***/ function(module, exports, __webpack_require__) {
22039
22040 var baseToPath = __webpack_require__(27),
22041 isArguments = __webpack_require__(31),
22042 isArray = __webpack_require__(1),
22043 isIndex = __webpack_require__(29),
22044 isKey = __webpack_require__(12),
22045 isLength = __webpack_require__(9),
22046 isString = __webpack_require__(34),
22047 last = __webpack_require__(105),
22048 parent = __webpack_require__(89);
22049
22050 /**
22051 * Checks if `path` exists on `object`.
22052 *
22053 * @private
22054 * @param {Object} object The object to query.
22055 * @param {Array|string} path The path to check.
22056 * @param {Function} hasFunc The function to check properties.
22057 * @returns {boolean} Returns `true` if `path` exists, else `false`.
22058 */
22059 function hasPath(object, path, hasFunc) {
22060 if (object == null) {
22061 return false;
22062 }
22063 var result = hasFunc(object, path);
22064 if (!result && !isKey(path)) {
22065 path = baseToPath(path);
22066 object = parent(object, path);
22067 if (object != null) {
22068 path = last(path);
22069 result = hasFunc(object, path);
22070 }
22071 }
22072 var length = object ? object.length : undefined;
22073 return result || (
22074 !!length && isLength(length) && isIndex(path, length) &&
22075 (isArray(object) || isString(object) || isArguments(object))
22076 );
22077 }
22078
22079 module.exports = hasPath;
22080
22081
22082/***/ },
22083/* 77 */
22084/***/ function(module, exports, __webpack_require__) {
22085
22086 var hashHas = __webpack_require__(28);
22087
22088 /**
22089 * Removes `key` and its value from the hash.
22090 *
22091 * @private
22092 * @param {Object} hash The hash to modify.
22093 * @param {string} key The key of the value to remove.
22094 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
22095 */
22096 function hashDelete(hash, key) {
22097 return hashHas(hash, key) && delete hash[key];
22098 }
22099
22100 module.exports = hashDelete;
22101
22102
22103/***/ },
22104/* 78 */
22105/***/ function(module, exports, __webpack_require__) {
22106
22107 var nativeCreate = __webpack_require__(7);
22108
22109 /** Used to stand-in for `undefined` hash values. */
22110 var HASH_UNDEFINED = '__lodash_hash_undefined__';
22111
22112 /** Used for built-in method references. */
22113 var objectProto = Object.prototype;
22114
22115 /** Used to check objects for own properties. */
22116 var hasOwnProperty = objectProto.hasOwnProperty;
22117
22118 /**
22119 * Gets the hash value for `key`.
22120 *
22121 * @private
22122 * @param {Object} hash The hash to query.
22123 * @param {string} key The key of the value to get.
22124 * @returns {*} Returns the entry value.
22125 */
22126 function hashGet(hash, key) {
22127 if (nativeCreate) {
22128 var result = hash[key];
22129 return result === HASH_UNDEFINED ? undefined : result;
22130 }
22131 return hasOwnProperty.call(hash, key) ? hash[key] : undefined;
22132 }
22133
22134 module.exports = hashGet;
22135
22136
22137/***/ },
22138/* 79 */
22139/***/ function(module, exports, __webpack_require__) {
22140
22141 var nativeCreate = __webpack_require__(7);
22142
22143 /** Used to stand-in for `undefined` hash values. */
22144 var HASH_UNDEFINED = '__lodash_hash_undefined__';
22145
22146 /**
22147 * Sets the hash `key` to `value`.
22148 *
22149 * @private
22150 * @param {Object} hash The hash to modify.
22151 * @param {string} key The key of the value to set.
22152 * @param {*} value The value to set.
22153 */
22154 function hashSet(hash, key, value) {
22155 hash[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
22156 }
22157
22158 module.exports = hashSet;
22159
22160
22161/***/ },
22162/* 80 */
22163/***/ function(module, exports, __webpack_require__) {
22164
22165 var baseTimes = __webpack_require__(66),
22166 isArguments = __webpack_require__(31),
22167 isArray = __webpack_require__(1),
22168 isLength = __webpack_require__(9),
22169 isString = __webpack_require__(34);
22170
22171 /**
22172 * Creates an array of index keys for `object` values of arrays,
22173 * `arguments` objects, and strings, otherwise `null` is returned.
22174 *
22175 * @private
22176 * @param {Object} object The object to query.
22177 * @returns {Array|null} Returns index keys, else `null`.
22178 */
22179 function indexKeys(object) {
22180 var length = object ? object.length : undefined;
22181 if (isLength(length) &&
22182 (isArray(object) || isString(object) || isArguments(object))) {
22183 return baseTimes(length, String);
22184 }
22185 return null;
22186 }
22187
22188 module.exports = indexKeys;
22189
22190
22191/***/ },
22192/* 81 */
22193/***/ function(module, exports) {
22194
22195 /** Used for built-in method references. */
22196 var objectProto = Object.prototype;
22197
22198 /**
22199 * Checks if `value` is likely a prototype object.
22200 *
22201 * @private
22202 * @param {*} value The value to check.
22203 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
22204 */
22205 function isPrototype(value) {
22206 var Ctor = value && value.constructor,
22207 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
22208
22209 return value === proto;
22210 }
22211
22212 module.exports = isPrototype;
22213
22214
22215/***/ },
22216/* 82 */
22217/***/ function(module, exports, __webpack_require__) {
22218
22219 var isObject = __webpack_require__(13);
22220
22221 /**
22222 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
22223 *
22224 * @private
22225 * @param {*} value The value to check.
22226 * @returns {boolean} Returns `true` if `value` if suitable for strict
22227 * equality comparisons, else `false`.
22228 */
22229 function isStrictComparable(value) {
22230 return value === value && !isObject(value);
22231 }
22232
22233 module.exports = isStrictComparable;
22234
22235
22236/***/ },
22237/* 83 */
22238/***/ function(module, exports, __webpack_require__) {
22239
22240 var Hash = __webpack_require__(49),
22241 Map = __webpack_require__(3);
22242
22243 /**
22244 * Removes all key-value entries from the map.
22245 *
22246 * @private
22247 * @name clear
22248 * @memberOf MapCache
22249 */
22250 function mapClear() {
22251 this.__data__ = { 'hash': new Hash, 'map': Map ? new Map : [], 'string': new Hash };
22252 }
22253
22254 module.exports = mapClear;
22255
22256
22257/***/ },
22258/* 84 */
22259/***/ function(module, exports, __webpack_require__) {
22260
22261 var Map = __webpack_require__(3),
22262 assocDelete = __webpack_require__(19),
22263 hashDelete = __webpack_require__(77),
22264 isKeyable = __webpack_require__(6);
22265
22266 /**
22267 * Removes `key` and its value from the map.
22268 *
22269 * @private
22270 * @name delete
22271 * @memberOf MapCache
22272 * @param {string} key The key of the value to remove.
22273 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
22274 */
22275 function mapDelete(key) {
22276 var data = this.__data__;
22277 if (isKeyable(key)) {
22278 return hashDelete(typeof key == 'string' ? data.string : data.hash, key);
22279 }
22280 return Map ? data.map['delete'](key) : assocDelete(data.map, key);
22281 }
22282
22283 module.exports = mapDelete;
22284
22285
22286/***/ },
22287/* 85 */
22288/***/ function(module, exports, __webpack_require__) {
22289
22290 var Map = __webpack_require__(3),
22291 assocGet = __webpack_require__(20),
22292 hashGet = __webpack_require__(78),
22293 isKeyable = __webpack_require__(6);
22294
22295 /**
22296 * Gets the map value for `key`.
22297 *
22298 * @private
22299 * @name get
22300 * @memberOf MapCache
22301 * @param {string} key The key of the value to get.
22302 * @returns {*} Returns the entry value.
22303 */
22304 function mapGet(key) {
22305 var data = this.__data__;
22306 if (isKeyable(key)) {
22307 return hashGet(typeof key == 'string' ? data.string : data.hash, key);
22308 }
22309 return Map ? data.map.get(key) : assocGet(data.map, key);
22310 }
22311
22312 module.exports = mapGet;
22313
22314
22315/***/ },
22316/* 86 */
22317/***/ function(module, exports, __webpack_require__) {
22318
22319 var Map = __webpack_require__(3),
22320 assocHas = __webpack_require__(21),
22321 hashHas = __webpack_require__(28),
22322 isKeyable = __webpack_require__(6);
22323
22324 /**
22325 * Checks if a map value for `key` exists.
22326 *
22327 * @private
22328 * @name has
22329 * @memberOf MapCache
22330 * @param {string} key The key of the entry to check.
22331 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
22332 */
22333 function mapHas(key) {
22334 var data = this.__data__;
22335 if (isKeyable(key)) {
22336 return hashHas(typeof key == 'string' ? data.string : data.hash, key);
22337 }
22338 return Map ? data.map.has(key) : assocHas(data.map, key);
22339 }
22340
22341 module.exports = mapHas;
22342
22343
22344/***/ },
22345/* 87 */
22346/***/ function(module, exports, __webpack_require__) {
22347
22348 var Map = __webpack_require__(3),
22349 assocSet = __webpack_require__(22),
22350 hashSet = __webpack_require__(79),
22351 isKeyable = __webpack_require__(6);
22352
22353 /**
22354 * Sets the map `key` to `value`.
22355 *
22356 * @private
22357 * @name set
22358 * @memberOf MapCache
22359 * @param {string} key The key of the value to set.
22360 * @param {*} value The value to set.
22361 * @returns {Object} Returns the map cache object.
22362 */
22363 function mapSet(key, value) {
22364 var data = this.__data__;
22365 if (isKeyable(key)) {
22366 hashSet(typeof key == 'string' ? data.string : data.hash, key, value);
22367 } else if (Map) {
22368 data.map.set(key, value);
22369 } else {
22370 assocSet(data.map, key, value);
22371 }
22372 return this;
22373 }
22374
22375 module.exports = mapSet;
22376
22377
22378/***/ },
22379/* 88 */
22380/***/ function(module, exports) {
22381
22382 /**
22383 * Converts `map` to an array.
22384 *
22385 * @private
22386 * @param {Object} map The map to convert.
22387 * @returns {Array} Returns the converted array.
22388 */
22389 function mapToArray(map) {
22390 var index = -1,
22391 result = Array(map.size);
22392
22393 map.forEach(function(value, key) {
22394 result[++index] = [key, value];
22395 });
22396 return result;
22397 }
22398
22399 module.exports = mapToArray;
22400
22401
22402/***/ },
22403/* 89 */
22404/***/ function(module, exports, __webpack_require__) {
22405
22406 var baseSlice = __webpack_require__(65),
22407 get = __webpack_require__(30);
22408
22409 /**
22410 * Gets the parent value at `path` of `object`.
22411 *
22412 * @private
22413 * @param {Object} object The object to query.
22414 * @param {Array} path The path to get the parent value of.
22415 * @returns {*} Returns the parent value.
22416 */
22417 function parent(object, path) {
22418 return path.length == 1 ? object : get(object, baseSlice(path, 0, -1));
22419 }
22420
22421 module.exports = parent;
22422
22423
22424/***/ },
22425/* 90 */
22426/***/ function(module, exports) {
22427
22428 /**
22429 * Converts `set` to an array.
22430 *
22431 * @private
22432 * @param {Object} set The set to convert.
22433 * @returns {Array} Returns the converted array.
22434 */
22435 function setToArray(set) {
22436 var index = -1,
22437 result = Array(set.size);
22438
22439 set.forEach(function(value) {
22440 result[++index] = value;
22441 });
22442 return result;
22443 }
22444
22445 module.exports = setToArray;
22446
22447
22448/***/ },
22449/* 91 */
22450/***/ function(module, exports) {
22451
22452 /**
22453 * Removes all key-value entries from the stack.
22454 *
22455 * @private
22456 * @name clear
22457 * @memberOf Stack
22458 */
22459 function stackClear() {
22460 this.__data__ = { 'array': [], 'map': null };
22461 }
22462
22463 module.exports = stackClear;
22464
22465
22466/***/ },
22467/* 92 */
22468/***/ function(module, exports, __webpack_require__) {
22469
22470 var assocDelete = __webpack_require__(19);
22471
22472 /**
22473 * Removes `key` and its value from the stack.
22474 *
22475 * @private
22476 * @name delete
22477 * @memberOf Stack
22478 * @param {string} key The key of the value to remove.
22479 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
22480 */
22481 function stackDelete(key) {
22482 var data = this.__data__,
22483 array = data.array;
22484
22485 return array ? assocDelete(array, key) : data.map['delete'](key);
22486 }
22487
22488 module.exports = stackDelete;
22489
22490
22491/***/ },
22492/* 93 */
22493/***/ function(module, exports, __webpack_require__) {
22494
22495 var assocGet = __webpack_require__(20);
22496
22497 /**
22498 * Gets the stack value for `key`.
22499 *
22500 * @private
22501 * @name get
22502 * @memberOf Stack
22503 * @param {string} key The key of the value to get.
22504 * @returns {*} Returns the entry value.
22505 */
22506 function stackGet(key) {
22507 var data = this.__data__,
22508 array = data.array;
22509
22510 return array ? assocGet(array, key) : data.map.get(key);
22511 }
22512
22513 module.exports = stackGet;
22514
22515
22516/***/ },
22517/* 94 */
22518/***/ function(module, exports, __webpack_require__) {
22519
22520 var assocHas = __webpack_require__(21);
22521
22522 /**
22523 * Checks if a stack value for `key` exists.
22524 *
22525 * @private
22526 * @name has
22527 * @memberOf Stack
22528 * @param {string} key The key of the entry to check.
22529 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
22530 */
22531 function stackHas(key) {
22532 var data = this.__data__,
22533 array = data.array;
22534
22535 return array ? assocHas(array, key) : data.map.has(key);
22536 }
22537
22538 module.exports = stackHas;
22539
22540
22541/***/ },
22542/* 95 */
22543/***/ function(module, exports, __webpack_require__) {
22544
22545 var MapCache = __webpack_require__(50),
22546 assocSet = __webpack_require__(22);
22547
22548 /** Used as the size to enable large array optimizations. */
22549 var LARGE_ARRAY_SIZE = 200;
22550
22551 /**
22552 * Sets the stack `key` to `value`.
22553 *
22554 * @private
22555 * @name set
22556 * @memberOf Stack
22557 * @param {string} key The key of the value to set.
22558 * @param {*} value The value to set.
22559 * @returns {Object} Returns the stack cache object.
22560 */
22561 function stackSet(key, value) {
22562 var data = this.__data__,
22563 array = data.array;
22564
22565 if (array) {
22566 if (array.length < (LARGE_ARRAY_SIZE - 1)) {
22567 assocSet(array, key, value);
22568 } else {
22569 data.array = null;
22570 data.map = new MapCache(array);
22571 }
22572 }
22573 var map = data.map;
22574 if (map) {
22575 map.set(key, value);
22576 }
22577 return this;
22578 }
22579
22580 module.exports = stackSet;
22581
22582
22583/***/ },
22584/* 96 */
22585/***/ function(module, exports, __webpack_require__) {
22586
22587 var toString = __webpack_require__(109);
22588
22589 /** Used to match property names within property paths. */
22590 var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g;
22591
22592 /** Used to match backslashes in property paths. */
22593 var reEscapeChar = /\\(\\)?/g;
22594
22595 /**
22596 * Converts `string` to a property path array.
22597 *
22598 * @private
22599 * @param {string} string The string to convert.
22600 * @returns {Array} Returns the property path array.
22601 */
22602 function stringToPath(string) {
22603 var result = [];
22604 toString(string).replace(rePropName, function(match, number, quote, string) {
22605 result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
22606 });
22607 return result;
22608 }
22609
22610 module.exports = stringToPath;
22611
22612
22613/***/ },
22614/* 97 */
22615/***/ function(module, exports) {
22616
22617 /**
22618 * Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
22619 * comparison between two values to determine if they are equivalent.
22620 *
22621 * @static
22622 * @memberOf _
22623 * @category Lang
22624 * @param {*} value The value to compare.
22625 * @param {*} other The other value to compare.
22626 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
22627 * @example
22628 *
22629 * var object = { 'user': 'fred' };
22630 * var other = { 'user': 'fred' };
22631 *
22632 * _.eq(object, object);
22633 * // => true
22634 *
22635 * _.eq(object, other);
22636 * // => false
22637 *
22638 * _.eq('a', 'a');
22639 * // => true
22640 *
22641 * _.eq('a', Object('a'));
22642 * // => false
22643 *
22644 * _.eq(NaN, NaN);
22645 * // => true
22646 */
22647 function eq(value, other) {
22648 return value === other || (value !== value && other !== other);
22649 }
22650
22651 module.exports = eq;
22652
22653
22654/***/ },
22655/* 98 */
22656/***/ function(module, exports, __webpack_require__) {
22657
22658 var baseHasIn = __webpack_require__(57),
22659 hasPath = __webpack_require__(76);
22660
22661 /**
22662 * Checks if `path` is a direct or inherited property of `object`.
22663 *
22664 * @static
22665 * @memberOf _
22666 * @category Object
22667 * @param {Object} object The object to query.
22668 * @param {Array|string} path The path to check.
22669 * @returns {boolean} Returns `true` if `path` exists, else `false`.
22670 * @example
22671 *
22672 * var object = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
22673 *
22674 * _.hasIn(object, 'a');
22675 * // => true
22676 *
22677 * _.hasIn(object, 'a.b.c');
22678 * // => true
22679 *
22680 * _.hasIn(object, ['a', 'b', 'c']);
22681 * // => true
22682 *
22683 * _.hasIn(object, 'b');
22684 * // => false
22685 */
22686 function hasIn(object, path) {
22687 return hasPath(object, path, baseHasIn);
22688 }
22689
22690 module.exports = hasIn;
22691
22692
22693/***/ },
22694/* 99 */
22695/***/ function(module, exports) {
22696
22697 /**
22698 * This method returns the first argument provided to it.
22699 *
22700 * @static
22701 * @memberOf _
22702 * @category Util
22703 * @param {*} value Any value.
22704 * @returns {*} Returns `value`.
22705 * @example
22706 *
22707 * var object = { 'user': 'fred' };
22708 *
22709 * _.identity(object) === object;
22710 * // => true
22711 */
22712 function identity(value) {
22713 return value;
22714 }
22715
22716 module.exports = identity;
22717
22718
22719/***/ },
22720/* 100 */
22721/***/ function(module, exports, __webpack_require__) {
22722
22723 var isArrayLike = __webpack_require__(32),
22724 isObjectLike = __webpack_require__(2);
22725
22726 /**
22727 * This method is like `_.isArrayLike` except that it also checks if `value`
22728 * is an object.
22729 *
22730 * @static
22731 * @memberOf _
22732 * @type Function
22733 * @category Lang
22734 * @param {*} value The value to check.
22735 * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
22736 * @example
22737 *
22738 * _.isArrayLikeObject([1, 2, 3]);
22739 * // => true
22740 *
22741 * _.isArrayLikeObject(document.body.children);
22742 * // => true
22743 *
22744 * _.isArrayLikeObject('abc');
22745 * // => false
22746 *
22747 * _.isArrayLikeObject(_.noop);
22748 * // => false
22749 */
22750 function isArrayLikeObject(value) {
22751 return isObjectLike(value) && isArrayLike(value);
22752 }
22753
22754 module.exports = isArrayLikeObject;
22755
22756
22757/***/ },
22758/* 101 */
22759/***/ function(module, exports, __webpack_require__) {
22760
22761 var isFunction = __webpack_require__(33),
22762 isHostObject = __webpack_require__(11),
22763 isObjectLike = __webpack_require__(2);
22764
22765 /** Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). */
22766 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
22767
22768 /** Used to detect host constructors (Safari > 5). */
22769 var reIsHostCtor = /^\[object .+?Constructor\]$/;
22770
22771 /** Used for built-in method references. */
22772 var objectProto = Object.prototype;
22773
22774 /** Used to resolve the decompiled source of functions. */
22775 var funcToString = Function.prototype.toString;
22776
22777 /** Used to check objects for own properties. */
22778 var hasOwnProperty = objectProto.hasOwnProperty;
22779
22780 /** Used to detect if a method is native. */
22781 var reIsNative = RegExp('^' +
22782 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
22783 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
22784 );
22785
22786 /**
22787 * Checks if `value` is a native function.
22788 *
22789 * @static
22790 * @memberOf _
22791 * @category Lang
22792 * @param {*} value The value to check.
22793 * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
22794 * @example
22795 *
22796 * _.isNative(Array.prototype.push);
22797 * // => true
22798 *
22799 * _.isNative(_);
22800 * // => false
22801 */
22802 function isNative(value) {
22803 if (value == null) {
22804 return false;
22805 }
22806 if (isFunction(value)) {
22807 return reIsNative.test(funcToString.call(value));
22808 }
22809 return isObjectLike(value) &&
22810 (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
22811 }
22812
22813 module.exports = isNative;
22814
22815
22816/***/ },
22817/* 102 */
22818/***/ function(module, exports, __webpack_require__) {
22819
22820 var isHostObject = __webpack_require__(11),
22821 isObjectLike = __webpack_require__(2);
22822
22823 /** `Object#toString` result references. */
22824 var objectTag = '[object Object]';
22825
22826 /** Used for built-in method references. */
22827 var objectProto = Object.prototype;
22828
22829 /** Used to resolve the decompiled source of functions. */
22830 var funcToString = Function.prototype.toString;
22831
22832 /** Used to infer the `Object` constructor. */
22833 var objectCtorString = funcToString.call(Object);
22834
22835 /**
22836 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
22837 * of values.
22838 */
22839 var objectToString = objectProto.toString;
22840
22841 /** Built-in value references. */
22842 var getPrototypeOf = Object.getPrototypeOf;
22843
22844 /**
22845 * Checks if `value` is a plain object, that is, an object created by the
22846 * `Object` constructor or one with a `[[Prototype]]` of `null`.
22847 *
22848 * @static
22849 * @memberOf _
22850 * @category Lang
22851 * @param {*} value The value to check.
22852 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
22853 * @example
22854 *
22855 * function Foo() {
22856 * this.a = 1;
22857 * }
22858 *
22859 * _.isPlainObject(new Foo);
22860 * // => false
22861 *
22862 * _.isPlainObject([1, 2, 3]);
22863 * // => false
22864 *
22865 * _.isPlainObject({ 'x': 0, 'y': 0 });
22866 * // => true
22867 *
22868 * _.isPlainObject(Object.create(null));
22869 * // => true
22870 */
22871 function isPlainObject(value) {
22872 if (!isObjectLike(value) || objectToString.call(value) != objectTag || isHostObject(value)) {
22873 return false;
22874 }
22875 var proto = objectProto;
22876 if (typeof value.constructor == 'function') {
22877 proto = getPrototypeOf(value);
22878 }
22879 if (proto === null) {
22880 return true;
22881 }
22882 var Ctor = proto.constructor;
22883 return (typeof Ctor == 'function' &&
22884 Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
22885 }
22886
22887 module.exports = isPlainObject;
22888
22889
22890/***/ },
22891/* 103 */
22892/***/ function(module, exports, __webpack_require__) {
22893
22894 var isObjectLike = __webpack_require__(2);
22895
22896 /** `Object#toString` result references. */
22897 var symbolTag = '[object Symbol]';
22898
22899 /** Used for built-in method references. */
22900 var objectProto = Object.prototype;
22901
22902 /**
22903 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
22904 * of values.
22905 */
22906 var objectToString = objectProto.toString;
22907
22908 /**
22909 * Checks if `value` is classified as a `Symbol` primitive or object.
22910 *
22911 * @static
22912 * @memberOf _
22913 * @category Lang
22914 * @param {*} value The value to check.
22915 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
22916 * @example
22917 *
22918 * _.isSymbol(Symbol.iterator);
22919 * // => true
22920 *
22921 * _.isSymbol('abc');
22922 * // => false
22923 */
22924 function isSymbol(value) {
22925 return typeof value == 'symbol' ||
22926 (isObjectLike(value) && objectToString.call(value) == symbolTag);
22927 }
22928
22929 module.exports = isSymbol;
22930
22931
22932/***/ },
22933/* 104 */
22934/***/ function(module, exports, __webpack_require__) {
22935
22936 var isLength = __webpack_require__(9),
22937 isObjectLike = __webpack_require__(2);
22938
22939 /** `Object#toString` result references. */
22940 var argsTag = '[object Arguments]',
22941 arrayTag = '[object Array]',
22942 boolTag = '[object Boolean]',
22943 dateTag = '[object Date]',
22944 errorTag = '[object Error]',
22945 funcTag = '[object Function]',
22946 mapTag = '[object Map]',
22947 numberTag = '[object Number]',
22948 objectTag = '[object Object]',
22949 regexpTag = '[object RegExp]',
22950 setTag = '[object Set]',
22951 stringTag = '[object String]',
22952 weakMapTag = '[object WeakMap]';
22953
22954 var arrayBufferTag = '[object ArrayBuffer]',
22955 float32Tag = '[object Float32Array]',
22956 float64Tag = '[object Float64Array]',
22957 int8Tag = '[object Int8Array]',
22958 int16Tag = '[object Int16Array]',
22959 int32Tag = '[object Int32Array]',
22960 uint8Tag = '[object Uint8Array]',
22961 uint8ClampedTag = '[object Uint8ClampedArray]',
22962 uint16Tag = '[object Uint16Array]',
22963 uint32Tag = '[object Uint32Array]';
22964
22965 /** Used to identify `toStringTag` values of typed arrays. */
22966 var typedArrayTags = {};
22967 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
22968 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
22969 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
22970 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
22971 typedArrayTags[uint32Tag] = true;
22972 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
22973 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
22974 typedArrayTags[dateTag] = typedArrayTags[errorTag] =
22975 typedArrayTags[funcTag] = typedArrayTags[mapTag] =
22976 typedArrayTags[numberTag] = typedArrayTags[objectTag] =
22977 typedArrayTags[regexpTag] = typedArrayTags[setTag] =
22978 typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
22979
22980 /** Used for built-in method references. */
22981 var objectProto = Object.prototype;
22982
22983 /**
22984 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
22985 * of values.
22986 */
22987 var objectToString = objectProto.toString;
22988
22989 /**
22990 * Checks if `value` is classified as a typed array.
22991 *
22992 * @static
22993 * @memberOf _
22994 * @category Lang
22995 * @param {*} value The value to check.
22996 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
22997 * @example
22998 *
22999 * _.isTypedArray(new Uint8Array);
23000 * // => true
23001 *
23002 * _.isTypedArray([]);
23003 * // => false
23004 */
23005 function isTypedArray(value) {
23006 return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
23007 }
23008
23009 module.exports = isTypedArray;
23010
23011
23012/***/ },
23013/* 105 */
23014/***/ function(module, exports) {
23015
23016 /**
23017 * Gets the last element of `array`.
23018 *
23019 * @static
23020 * @memberOf _
23021 * @category Array
23022 * @param {Array} array The array to query.
23023 * @returns {*} Returns the last element of `array`.
23024 * @example
23025 *
23026 * _.last([1, 2, 3]);
23027 * // => 3
23028 */
23029 function last(array) {
23030 var length = array ? array.length : 0;
23031 return length ? array[length - 1] : undefined;
23032 }
23033
23034 module.exports = last;
23035
23036
23037/***/ },
23038/* 106 */
23039/***/ function(module, exports, __webpack_require__) {
23040
23041 var baseForOwn = __webpack_require__(56),
23042 baseIteratee = __webpack_require__(60);
23043
23044 /**
23045 * Creates an object with the same keys as `object` and values generated by
23046 * running each own enumerable property of `object` through `iteratee`. The
23047 * iteratee function is invoked with three arguments: (value, key, object).
23048 *
23049 * @static
23050 * @memberOf _
23051 * @category Object
23052 * @param {Object} object The object to iterate over.
23053 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
23054 * @returns {Object} Returns the new mapped object.
23055 * @example
23056 *
23057 * var users = {
23058 * 'fred': { 'user': 'fred', 'age': 40 },
23059 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
23060 * };
23061 *
23062 * _.mapValues(users, function(o) { return o.age; });
23063 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
23064 *
23065 * // The `_.property` iteratee shorthand.
23066 * _.mapValues(users, 'age');
23067 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
23068 */
23069 function mapValues(object, iteratee) {
23070 var result = {};
23071 iteratee = baseIteratee(iteratee, 3);
23072
23073 baseForOwn(object, function(value, key, object) {
23074 result[key] = iteratee(value, key, object);
23075 });
23076 return result;
23077 }
23078
23079 module.exports = mapValues;
23080
23081
23082/***/ },
23083/* 107 */
23084/***/ function(module, exports, __webpack_require__) {
23085
23086 var baseProperty = __webpack_require__(26),
23087 basePropertyDeep = __webpack_require__(64),
23088 isKey = __webpack_require__(12);
23089
23090 /**
23091 * Creates a function that returns the value at `path` of a given object.
23092 *
23093 * @static
23094 * @memberOf _
23095 * @category Util
23096 * @param {Array|string} path The path of the property to get.
23097 * @returns {Function} Returns the new function.
23098 * @example
23099 *
23100 * var objects = [
23101 * { 'a': { 'b': { 'c': 2 } } },
23102 * { 'a': { 'b': { 'c': 1 } } }
23103 * ];
23104 *
23105 * _.map(objects, _.property('a.b.c'));
23106 * // => [2, 1]
23107 *
23108 * _.map(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
23109 * // => [1, 2]
23110 */
23111 function property(path) {
23112 return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
23113 }
23114
23115 module.exports = property;
23116
23117
23118/***/ },
23119/* 108 */
23120/***/ function(module, exports, __webpack_require__) {
23121
23122 var baseToPairs = __webpack_require__(67),
23123 keys = __webpack_require__(14);
23124
23125 /**
23126 * Creates an array of own enumerable key-value pairs for `object`.
23127 *
23128 * @static
23129 * @memberOf _
23130 * @category Object
23131 * @param {Object} object The object to query.
23132 * @returns {Array} Returns the new array of key-value pairs.
23133 * @example
23134 *
23135 * function Foo() {
23136 * this.a = 1;
23137 * this.b = 2;
23138 * }
23139 *
23140 * Foo.prototype.c = 3;
23141 *
23142 * _.toPairs(new Foo);
23143 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
23144 */
23145 function toPairs(object) {
23146 return baseToPairs(object, keys(object));
23147 }
23148
23149 module.exports = toPairs;
23150
23151
23152/***/ },
23153/* 109 */
23154/***/ function(module, exports, __webpack_require__) {
23155
23156 var Symbol = __webpack_require__(18),
23157 isSymbol = __webpack_require__(103);
23158
23159 /** Used as references for various `Number` constants. */
23160 var INFINITY = 1 / 0;
23161
23162 /** Used to convert symbols to primitives and strings. */
23163 var symbolProto = Symbol ? Symbol.prototype : undefined,
23164 symbolToString = Symbol ? symbolProto.toString : undefined;
23165
23166 /**
23167 * Converts `value` to a string if it's not one. An empty string is returned
23168 * for `null` and `undefined` values. The sign of `-0` is preserved.
23169 *
23170 * @static
23171 * @memberOf _
23172 * @category Lang
23173 * @param {*} value The value to process.
23174 * @returns {string} Returns the string.
23175 * @example
23176 *
23177 * _.toString(null);
23178 * // => ''
23179 *
23180 * _.toString(-0);
23181 * // => '-0'
23182 *
23183 * _.toString([1, 2, 3]);
23184 * // => '1,2,3'
23185 */
23186 function toString(value) {
23187 // Exit early for strings to avoid a performance hit in some environments.
23188 if (typeof value == 'string') {
23189 return value;
23190 }
23191 if (value == null) {
23192 return '';
23193 }
23194 if (isSymbol(value)) {
23195 return Symbol ? symbolToString.call(value) : '';
23196 }
23197 var result = (value + '');
23198 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
23199 }
23200
23201 module.exports = toString;
23202
23203
23204/***/ },
23205/* 110 */
23206/***/ function(module, exports, __webpack_require__) {
23207
23208 'use strict';
23209
23210 exports.__esModule = true;
23211 exports.default = map2tree;
23212
23213 var _isArray = __webpack_require__(1);
23214
23215 var _isArray2 = _interopRequireDefault(_isArray);
23216
23217 var _isPlainObject = __webpack_require__(102);
23218
23219 var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
23220
23221 var _mapValues = __webpack_require__(106);
23222
23223 var _mapValues2 = _interopRequireDefault(_mapValues);
23224
23225 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23226
23227 function visit(parent, visitFn, childrenFn) {
23228 if (!parent) return;
23229
23230 visitFn(parent);
23231
23232 var children = childrenFn(parent);
23233 if (children) {
23234 var count = children.length;
23235 for (var i = 0; i < count; i++) {
23236 visit(children[i], visitFn, childrenFn);
23237 }
23238 }
23239 }
23240
23241 function getNode(tree, key) {
23242 var node = null;
23243
23244 visit(tree, function (d) {
23245 if (d.name === key) {
23246 node = d;
23247 }
23248 }, function (d) {
23249 return d.children;
23250 });
23251
23252 return node;
23253 }
23254
23255 function map2tree(root) {
23256 var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
23257 var tree = arguments.length <= 2 || arguments[2] === undefined ? { name: options.key || 'state', children: [] } : arguments[2];
23258
23259 if (!(0, _isPlainObject2.default)(root) && root && !root.toJS) {
23260 return {};
23261 }
23262
23263 var _options$key = options.key;
23264 var rootNodeKey = _options$key === undefined ? 'state' : _options$key;
23265 var _options$pushMethod = options.pushMethod;
23266 var pushMethod = _options$pushMethod === undefined ? 'push' : _options$pushMethod;
23267
23268 var currentNode = getNode(tree, rootNodeKey);
23269
23270 if (currentNode === null) {
23271 return {};
23272 }
23273
23274 (0, _mapValues2.default)(root && root.toJS ? root.toJS() : root, function (maybeImmutable, key) {
23275 var value = maybeImmutable && maybeImmutable.toJS ? maybeImmutable.toJS() : maybeImmutable;
23276 var newNode = { name: key };
23277
23278 if ((0, _isArray2.default)(value)) {
23279 newNode.children = [];
23280
23281 for (var i = 0; i < value.length; i++) {
23282 var _newNode$children$pus;
23283
23284 newNode.children[pushMethod]((_newNode$children$pus = {
23285 name: key + '[' + i + ']'
23286 }, _newNode$children$pus[(0, _isPlainObject2.default)(value[i]) ? 'object' : 'value'] = value[i], _newNode$children$pus));
23287 }
23288 } else if ((0, _isPlainObject2.default)(value)) {
23289 newNode.children = [];
23290 } else {
23291 newNode.value = value;
23292 }
23293
23294 currentNode.children[pushMethod](newNode);
23295
23296 map2tree(value, { key: key, pushMethod: pushMethod }, tree);
23297 });
23298
23299 return tree;
23300 }
23301
23302/***/ },
23303/* 111 */
23304/***/ function(module, exports) {
23305
23306 module.exports = function(module) {
23307 if(!module.webpackPolyfill) {
23308 module.deprecate = function() {};
23309 module.paths = [];
23310 // module.parent = undefined by default
23311 module.children = [];
23312 module.webpackPolyfill = 1;
23313 }
23314 return module;
23315 }
23316
23317
23318/***/ }
23319/******/ ])
23320});
23321;
\No newline at end of file