UNPKG

715 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__(34);
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__(91);
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__(62);
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__(105)(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__(95);
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__(23),
7900 baseKeys = __webpack_require__(55),
7901 indexKeys = __webpack_require__(74),
7902 isArrayLike = __webpack_require__(31),
7903 isIndex = __webpack_require__(28),
7904 isPrototype = __webpack_require__(75);
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 'use strict';
7961
7962 exports.__esModule = true;
7963 exports.default = functor;
7964
7965 var _ramda = __webpack_require__(4);
7966
7967 function functor(v) {
7968 return (0, _ramda.is)(Function, v) ? v : function () {
7969 return v;
7970 };
7971 }
7972
7973/***/ },
7974/* 16 */
7975/***/ function(module, exports, __webpack_require__) {
7976
7977 var stackClear = __webpack_require__(85),
7978 stackDelete = __webpack_require__(86),
7979 stackGet = __webpack_require__(87),
7980 stackHas = __webpack_require__(88),
7981 stackSet = __webpack_require__(89);
7982
7983 /**
7984 * Creates a stack cache object to store key-value pairs.
7985 *
7986 * @private
7987 * @param {Array} [values] The values to cache.
7988 */
7989 function Stack(values) {
7990 var index = -1,
7991 length = values ? values.length : 0;
7992
7993 this.clear();
7994 while (++index < length) {
7995 var entry = values[index];
7996 this.set(entry[0], entry[1]);
7997 }
7998 }
7999
8000 // Add functions to the `Stack` cache.
8001 Stack.prototype.clear = stackClear;
8002 Stack.prototype['delete'] = stackDelete;
8003 Stack.prototype.get = stackGet;
8004 Stack.prototype.has = stackHas;
8005 Stack.prototype.set = stackSet;
8006
8007 module.exports = Stack;
8008
8009
8010/***/ },
8011/* 17 */
8012/***/ function(module, exports, __webpack_require__) {
8013
8014 var root = __webpack_require__(8);
8015
8016 /** Built-in value references. */
8017 var Symbol = root.Symbol;
8018
8019 module.exports = Symbol;
8020
8021
8022/***/ },
8023/* 18 */
8024/***/ function(module, exports, __webpack_require__) {
8025
8026 var assocIndexOf = __webpack_require__(5);
8027
8028 /** Used for built-in method references. */
8029 var arrayProto = Array.prototype;
8030
8031 /** Built-in value references. */
8032 var splice = arrayProto.splice;
8033
8034 /**
8035 * Removes `key` and its value from the associative array.
8036 *
8037 * @private
8038 * @param {Array} array The array to query.
8039 * @param {string} key The key of the value to remove.
8040 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
8041 */
8042 function assocDelete(array, key) {
8043 var index = assocIndexOf(array, key);
8044 if (index < 0) {
8045 return false;
8046 }
8047 var lastIndex = array.length - 1;
8048 if (index == lastIndex) {
8049 array.pop();
8050 } else {
8051 splice.call(array, index, 1);
8052 }
8053 return true;
8054 }
8055
8056 module.exports = assocDelete;
8057
8058
8059/***/ },
8060/* 19 */
8061/***/ function(module, exports, __webpack_require__) {
8062
8063 var assocIndexOf = __webpack_require__(5);
8064
8065 /**
8066 * Gets the associative array value for `key`.
8067 *
8068 * @private
8069 * @param {Array} array The array to query.
8070 * @param {string} key The key of the value to get.
8071 * @returns {*} Returns the entry value.
8072 */
8073 function assocGet(array, key) {
8074 var index = assocIndexOf(array, key);
8075 return index < 0 ? undefined : array[index][1];
8076 }
8077
8078 module.exports = assocGet;
8079
8080
8081/***/ },
8082/* 20 */
8083/***/ function(module, exports, __webpack_require__) {
8084
8085 var assocIndexOf = __webpack_require__(5);
8086
8087 /**
8088 * Checks if an associative array value for `key` exists.
8089 *
8090 * @private
8091 * @param {Array} array The array to query.
8092 * @param {string} key The key of the entry to check.
8093 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
8094 */
8095 function assocHas(array, key) {
8096 return assocIndexOf(array, key) > -1;
8097 }
8098
8099 module.exports = assocHas;
8100
8101
8102/***/ },
8103/* 21 */
8104/***/ function(module, exports, __webpack_require__) {
8105
8106 var assocIndexOf = __webpack_require__(5);
8107
8108 /**
8109 * Sets the associative array `key` to `value`.
8110 *
8111 * @private
8112 * @param {Array} array The array to modify.
8113 * @param {string} key The key of the value to set.
8114 * @param {*} value The value to set.
8115 */
8116 function assocSet(array, key, value) {
8117 var index = assocIndexOf(array, key);
8118 if (index < 0) {
8119 array.push([key, value]);
8120 } else {
8121 array[index][1] = value;
8122 }
8123 }
8124
8125 module.exports = assocSet;
8126
8127
8128/***/ },
8129/* 22 */
8130/***/ function(module, exports, __webpack_require__) {
8131
8132 var baseToPath = __webpack_require__(26),
8133 isKey = __webpack_require__(12);
8134
8135 /**
8136 * The base implementation of `_.get` without support for default values.
8137 *
8138 * @private
8139 * @param {Object} object The object to query.
8140 * @param {Array|string} path The path of the property to get.
8141 * @returns {*} Returns the resolved value.
8142 */
8143 function baseGet(object, path) {
8144 path = isKey(path, object) ? [path + ''] : baseToPath(path);
8145
8146 var index = 0,
8147 length = path.length;
8148
8149 while (object != null && index < length) {
8150 object = object[path[index++]];
8151 }
8152 return (index && index == length) ? object : undefined;
8153 }
8154
8155 module.exports = baseGet;
8156
8157
8158/***/ },
8159/* 23 */
8160/***/ function(module, exports) {
8161
8162 /** Used for built-in method references. */
8163 var objectProto = Object.prototype;
8164
8165 /** Used to check objects for own properties. */
8166 var hasOwnProperty = objectProto.hasOwnProperty;
8167
8168 /** Built-in value references. */
8169 var getPrototypeOf = Object.getPrototypeOf;
8170
8171 /**
8172 * The base implementation of `_.has` without support for deep paths.
8173 *
8174 * @private
8175 * @param {Object} object The object to query.
8176 * @param {Array|string} key The key to check.
8177 * @returns {boolean} Returns `true` if `key` exists, else `false`.
8178 */
8179 function baseHas(object, key) {
8180 // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
8181 // that are composed entirely of index properties, return `false` for
8182 // `hasOwnProperty` checks of them.
8183 return hasOwnProperty.call(object, key) ||
8184 (typeof object == 'object' && key in object && getPrototypeOf(object) === null);
8185 }
8186
8187 module.exports = baseHas;
8188
8189
8190/***/ },
8191/* 24 */
8192/***/ function(module, exports, __webpack_require__) {
8193
8194 var baseIsEqualDeep = __webpack_require__(52),
8195 isObject = __webpack_require__(13),
8196 isObjectLike = __webpack_require__(2);
8197
8198 /**
8199 * The base implementation of `_.isEqual` which supports partial comparisons
8200 * and tracks traversed objects.
8201 *
8202 * @private
8203 * @param {*} value The value to compare.
8204 * @param {*} other The other value to compare.
8205 * @param {Function} [customizer] The function to customize comparisons.
8206 * @param {boolean} [bitmask] The bitmask of comparison flags.
8207 * The bitmask may be composed of the following flags:
8208 * 1 - Unordered comparison
8209 * 2 - Partial comparison
8210 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
8211 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
8212 */
8213 function baseIsEqual(value, other, customizer, bitmask, stack) {
8214 if (value === other) {
8215 return true;
8216 }
8217 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
8218 return value !== value && other !== other;
8219 }
8220 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
8221 }
8222
8223 module.exports = baseIsEqual;
8224
8225
8226/***/ },
8227/* 25 */
8228/***/ function(module, exports) {
8229
8230 /**
8231 * The base implementation of `_.property` without support for deep paths.
8232 *
8233 * @private
8234 * @param {string} key The key of the property to get.
8235 * @returns {Function} Returns the new function.
8236 */
8237 function baseProperty(key) {
8238 return function(object) {
8239 return object == null ? undefined : object[key];
8240 };
8241 }
8242
8243 module.exports = baseProperty;
8244
8245
8246/***/ },
8247/* 26 */
8248/***/ function(module, exports, __webpack_require__) {
8249
8250 var isArray = __webpack_require__(1),
8251 stringToPath = __webpack_require__(90);
8252
8253 /**
8254 * The base implementation of `_.toPath` which only converts `value` to a
8255 * path if it's not one.
8256 *
8257 * @private
8258 * @param {*} value The value to process.
8259 * @returns {Array} Returns the property path array.
8260 */
8261 function baseToPath(value) {
8262 return isArray(value) ? value : stringToPath(value);
8263 }
8264
8265 module.exports = baseToPath;
8266
8267
8268/***/ },
8269/* 27 */
8270/***/ function(module, exports, __webpack_require__) {
8271
8272 var nativeCreate = __webpack_require__(7);
8273
8274 /** Used for built-in method references. */
8275 var objectProto = Object.prototype;
8276
8277 /** Used to check objects for own properties. */
8278 var hasOwnProperty = objectProto.hasOwnProperty;
8279
8280 /**
8281 * Checks if a hash value for `key` exists.
8282 *
8283 * @private
8284 * @param {Object} hash The hash to query.
8285 * @param {string} key The key of the entry to check.
8286 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
8287 */
8288 function hashHas(hash, key) {
8289 return nativeCreate ? hash[key] !== undefined : hasOwnProperty.call(hash, key);
8290 }
8291
8292 module.exports = hashHas;
8293
8294
8295/***/ },
8296/* 28 */
8297/***/ function(module, exports) {
8298
8299 /** Used as references for various `Number` constants. */
8300 var MAX_SAFE_INTEGER = 9007199254740991;
8301
8302 /** Used to detect unsigned integer values. */
8303 var reIsUint = /^(?:0|[1-9]\d*)$/;
8304
8305 /**
8306 * Checks if `value` is a valid array-like index.
8307 *
8308 * @private
8309 * @param {*} value The value to check.
8310 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
8311 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
8312 */
8313 function isIndex(value, length) {
8314 value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
8315 length = length == null ? MAX_SAFE_INTEGER : length;
8316 return value > -1 && value % 1 == 0 && value < length;
8317 }
8318
8319 module.exports = isIndex;
8320
8321
8322/***/ },
8323/* 29 */
8324/***/ function(module, exports, __webpack_require__) {
8325
8326 var baseGet = __webpack_require__(22);
8327
8328 /**
8329 * Gets the value at `path` of `object`. If the resolved value is
8330 * `undefined` the `defaultValue` is used in its place.
8331 *
8332 * @static
8333 * @memberOf _
8334 * @category Object
8335 * @param {Object} object The object to query.
8336 * @param {Array|string} path The path of the property to get.
8337 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
8338 * @returns {*} Returns the resolved value.
8339 * @example
8340 *
8341 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
8342 *
8343 * _.get(object, 'a[0].b.c');
8344 * // => 3
8345 *
8346 * _.get(object, ['a', '0', 'b', 'c']);
8347 * // => 3
8348 *
8349 * _.get(object, 'a.b.c', 'default');
8350 * // => 'default'
8351 */
8352 function get(object, path, defaultValue) {
8353 var result = object == null ? undefined : baseGet(object, path);
8354 return result === undefined ? defaultValue : result;
8355 }
8356
8357 module.exports = get;
8358
8359
8360/***/ },
8361/* 30 */
8362/***/ function(module, exports, __webpack_require__) {
8363
8364 var isArrayLikeObject = __webpack_require__(94);
8365
8366 /** `Object#toString` result references. */
8367 var argsTag = '[object Arguments]';
8368
8369 /** Used for built-in method references. */
8370 var objectProto = Object.prototype;
8371
8372 /** Used to check objects for own properties. */
8373 var hasOwnProperty = objectProto.hasOwnProperty;
8374
8375 /**
8376 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
8377 * of values.
8378 */
8379 var objectToString = objectProto.toString;
8380
8381 /** Built-in value references. */
8382 var propertyIsEnumerable = objectProto.propertyIsEnumerable;
8383
8384 /**
8385 * Checks if `value` is likely an `arguments` object.
8386 *
8387 * @static
8388 * @memberOf _
8389 * @category Lang
8390 * @param {*} value The value to check.
8391 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8392 * @example
8393 *
8394 * _.isArguments(function() { return arguments; }());
8395 * // => true
8396 *
8397 * _.isArguments([1, 2, 3]);
8398 * // => false
8399 */
8400 function isArguments(value) {
8401 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
8402 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
8403 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
8404 }
8405
8406 module.exports = isArguments;
8407
8408
8409/***/ },
8410/* 31 */
8411/***/ function(module, exports, __webpack_require__) {
8412
8413 var getLength = __webpack_require__(67),
8414 isFunction = __webpack_require__(32),
8415 isLength = __webpack_require__(9);
8416
8417 /**
8418 * Checks if `value` is array-like. A value is considered array-like if it's
8419 * not a function and has a `value.length` that's an integer greater than or
8420 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
8421 *
8422 * @static
8423 * @memberOf _
8424 * @type Function
8425 * @category Lang
8426 * @param {*} value The value to check.
8427 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
8428 * @example
8429 *
8430 * _.isArrayLike([1, 2, 3]);
8431 * // => true
8432 *
8433 * _.isArrayLike(document.body.children);
8434 * // => true
8435 *
8436 * _.isArrayLike('abc');
8437 * // => true
8438 *
8439 * _.isArrayLike(_.noop);
8440 * // => false
8441 */
8442 function isArrayLike(value) {
8443 return value != null &&
8444 !(typeof value == 'function' && isFunction(value)) && isLength(getLength(value));
8445 }
8446
8447 module.exports = isArrayLike;
8448
8449
8450/***/ },
8451/* 32 */
8452/***/ function(module, exports, __webpack_require__) {
8453
8454 var isObject = __webpack_require__(13);
8455
8456 /** `Object#toString` result references. */
8457 var funcTag = '[object Function]',
8458 genTag = '[object GeneratorFunction]';
8459
8460 /** Used for built-in method references. */
8461 var objectProto = Object.prototype;
8462
8463 /**
8464 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
8465 * of values.
8466 */
8467 var objectToString = objectProto.toString;
8468
8469 /**
8470 * Checks if `value` is classified as a `Function` object.
8471 *
8472 * @static
8473 * @memberOf _
8474 * @category Lang
8475 * @param {*} value The value to check.
8476 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8477 * @example
8478 *
8479 * _.isFunction(_);
8480 * // => true
8481 *
8482 * _.isFunction(/abc/);
8483 * // => false
8484 */
8485 function isFunction(value) {
8486 // The use of `Object#toString` avoids issues with the `typeof` operator
8487 // in Safari 8 which returns 'object' for typed array constructors, and
8488 // PhantomJS 1.9 which returns 'function' for `NodeList` instances.
8489 var tag = isObject(value) ? objectToString.call(value) : '';
8490 return tag == funcTag || tag == genTag;
8491 }
8492
8493 module.exports = isFunction;
8494
8495
8496/***/ },
8497/* 33 */
8498/***/ function(module, exports, __webpack_require__) {
8499
8500 var isArray = __webpack_require__(1),
8501 isObjectLike = __webpack_require__(2);
8502
8503 /** `Object#toString` result references. */
8504 var stringTag = '[object String]';
8505
8506 /** Used for built-in method references. */
8507 var objectProto = Object.prototype;
8508
8509 /**
8510 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
8511 * of values.
8512 */
8513 var objectToString = objectProto.toString;
8514
8515 /**
8516 * Checks if `value` is classified as a `String` primitive or object.
8517 *
8518 * @static
8519 * @memberOf _
8520 * @category Lang
8521 * @param {*} value The value to check.
8522 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8523 * @example
8524 *
8525 * _.isString('abc');
8526 * // => true
8527 *
8528 * _.isString(1);
8529 * // => false
8530 */
8531 function isString(value) {
8532 return typeof value == 'string' ||
8533 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
8534 }
8535
8536 module.exports = isString;
8537
8538
8539/***/ },
8540/* 34 */
8541/***/ function(module, exports, __webpack_require__) {
8542
8543 'use strict';
8544
8545 exports.__esModule = true;
8546 exports.tree = undefined;
8547
8548 var _tree2 = __webpack_require__(36);
8549
8550 var _tree3 = _interopRequireDefault(_tree2);
8551
8552 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8553
8554 exports.tree = _tree3.default;
8555
8556/***/ },
8557/* 35 */
8558/***/ function(module, exports, __webpack_require__) {
8559
8560 'use strict';
8561
8562 exports.__esModule = true;
8563
8564 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; };
8565
8566 exports.default = sortAndSerialize;
8567
8568 var _ramda = __webpack_require__(4);
8569
8570 function sortObject(obj, strict) {
8571 if (obj instanceof Array) {
8572 var ary = void 0;
8573 if (strict) {
8574 ary = obj.sort();
8575 } else {
8576 ary = obj;
8577 }
8578 return ary;
8579 }
8580
8581 if (obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object') {
8582 var _ret = function () {
8583 var tObj = {};
8584 Object.keys(obj).sort().forEach(function (key) {
8585 return tObj[key] = sortObject(obj[key]);
8586 });
8587 return {
8588 v: tObj
8589 };
8590 }();
8591
8592 if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
8593 }
8594
8595 return obj;
8596 }
8597
8598 function sortAndSerialize(obj) {
8599 return JSON.stringify(sortObject(obj, true), undefined, 2);
8600 }
8601
8602/***/ },
8603/* 36 */
8604/***/ function(module, exports, __webpack_require__) {
8605
8606 'use strict';
8607
8608 exports.__esModule = true;
8609
8610 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; };
8611
8612 exports.default = function (DOMNode) {
8613 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
8614
8615 var _deepmerge = (0, _deepmerge3.default)(defaultOptions, options);
8616
8617 var id = _deepmerge.id;
8618 var style = _deepmerge.style;
8619 var size = _deepmerge.size;
8620 var aspectRatio = _deepmerge.aspectRatio;
8621 var initialZoom = _deepmerge.initialZoom;
8622 var margin = _deepmerge.margin;
8623 var isSorted = _deepmerge.isSorted;
8624 var widthBetweenNodesCoeff = _deepmerge.widthBetweenNodesCoeff;
8625 var heightBetweenNodesCoeff = _deepmerge.heightBetweenNodesCoeff;
8626 var transitionDuration = _deepmerge.transitionDuration;
8627 var state = _deepmerge.state;
8628 var rootKeyName = _deepmerge.rootKeyName;
8629 var pushMethod = _deepmerge.pushMethod;
8630 var tree = _deepmerge.tree;
8631 var tooltipOptions = _deepmerge.tooltipOptions;
8632 var onClickText = _deepmerge.onClickText;
8633
8634
8635 var width = size - margin.left - margin.right;
8636 var height = size * aspectRatio - margin.top - margin.bottom;
8637 var fullWidth = size;
8638 var fullHeight = size * aspectRatio;
8639
8640 var attr = {
8641 id: id,
8642 preserveAspectRatio: 'xMinYMin slice'
8643 };
8644
8645 if (!style.width) {
8646 attr.width = fullWidth;
8647 }
8648
8649 if (!style.width || !style.height) {
8650 attr.viewBox = '0 0 ' + fullWidth + ' ' + fullHeight;
8651 }
8652
8653 var root = _d4.default.select(DOMNode);
8654 var zoom = _d4.default.behavior.zoom().scaleExtent([0.1, 3]).scale(initialZoom);
8655 var vis = root.append('svg').attr(attr).style(_extends({ cursor: '-webkit-grab' }, style)).call(zoom.on('zoom', function () {
8656 var _d3$event = _d4.default.event;
8657 var translate = _d3$event.translate;
8658 var scale = _d3$event.scale;
8659
8660 vis.attr('transform', 'translate(' + translate + ')scale(' + scale + ')');
8661 })).append('g').attr({
8662 transform: 'translate(' + (margin.left + style.node.radius) + ', ' + margin.top + ') scale(' + initialZoom + ')'
8663 });
8664
8665 var layout = _d4.default.layout.tree().size([width, height]);
8666 var data = void 0;
8667
8668 if (isSorted) {
8669 layout.sort(function (a, b) {
8670 return b.name.toLowerCase() < a.name.toLowerCase() ? 1 : -1;
8671 });
8672 }
8673
8674 return function renderChart() {
8675 var nextState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : tree || state;
8676
8677 data = !tree ? (0, _map2tree2.default)(nextState, { key: rootKeyName, pushMethod: pushMethod }) : nextState;
8678
8679 if ((0, _ramda.isEmpty)(data) || !data.name) {
8680 data = { name: 'error', message: 'Please provide a state map or a tree structure' };
8681 }
8682
8683 var nodeIndex = 0;
8684 var maxLabelLength = 0;
8685
8686 (0, _utils.visit)(data, function (node) {
8687 return maxLabelLength = Math.max(node.name.length, maxLabelLength);
8688 }, function (node) {
8689 return node.children && node.children.length > 0 ? node.children : null;
8690 });
8691
8692 data.x0 = height / 2;
8693 data.y0 = 0;
8694 /*eslint-disable*/
8695 update(data);
8696 /*eslint-enable*/
8697
8698 function update(source) {
8699 var _this = this;
8700
8701 // path generator for links
8702 var diagonal = _d4.default.svg.diagonal().projection(function (d) {
8703 return [d.y, d.x];
8704 });
8705 // set tree dimensions and spacing between branches and nodes
8706 var maxNodeCountByLevel = Math.max.apply(Math, (0, _utils.getNodeGroupByDepthCount)(data));
8707
8708 layout = layout.size([maxNodeCountByLevel * 25 * heightBetweenNodesCoeff, width]);
8709
8710 var nodes = layout.nodes(data);
8711 var links = layout.links(nodes);
8712
8713 nodes.forEach(function (node) {
8714 return node.y = node.depth * (maxLabelLength * 7 * widthBetweenNodesCoeff);
8715 });
8716
8717 // process the node selection
8718 var node = vis.selectAll('g.node').property('__oldData__', function (d) {
8719 return d;
8720 }).data(nodes, function (d) {
8721 return d.id || (d.id = ++nodeIndex);
8722 });
8723
8724 var nodeEnter = node.enter().append('g').attr({
8725 'class': 'node',
8726 transform: function transform(d) {
8727 return 'translate(' + source.y0 + ',' + source.x0 + ')';
8728 }
8729 }).style({
8730 fill: style.text.colors.default,
8731 cursor: 'pointer'
8732 }).on({
8733 mouseover: function mouseover(d, i) {
8734 _d4.default.select(this).style({
8735 fill: style.text.colors.hover
8736 });
8737 },
8738 mouseout: function mouseout(d, i) {
8739 _d4.default.select(this).style({
8740 fill: style.text.colors.default
8741 });
8742 }
8743 });
8744
8745 if (!tooltipOptions.disabled) {
8746 nodeEnter.call((0, _d3tooltip2.default)(_d4.default, 'tooltip', _extends({}, tooltipOptions, { root: root })).text(function (d, i) {
8747 return (0, _utils.getTooltipString)(d, i, tooltipOptions);
8748 }).style(tooltipOptions.style));
8749 }
8750
8751 nodeEnter.append('circle').attr({
8752 'class': 'nodeCircle'
8753 }).on({
8754 click: function click(clickedNode) {
8755 if (_d4.default.event.defaultPrevented) return;
8756 update((0, _utils.toggleChildren)(clickedNode));
8757 }
8758 });
8759
8760 nodeEnter.append('text').attr({
8761 'class': 'nodeText',
8762 dy: '.35em'
8763 }).style({
8764 'fill-opacity': 0
8765 }).text(function (d) {
8766 return d.name;
8767 }).on({
8768 click: onClickText
8769 });
8770
8771 // update the text to reflect whether node has children or not
8772 node.select('text').attr({
8773 x: function x(d) {
8774 return d.children || d._children ? -(style.node.radius + 10) : style.node.radius + 10;
8775 },
8776 'text-anchor': function textAnchor(d) {
8777 return d.children || d._children ? 'end' : 'start';
8778 }
8779 }).text(function (d) {
8780 return d.name;
8781 });
8782
8783 // change the circle fill depending on whether it has children and is collapsed
8784 node.select('circle.nodeCircle').attr({
8785 r: style.node.radius
8786 }).style({
8787 stroke: 'black',
8788 'stroke-width': '1.5px',
8789 fill: function fill(d) {
8790 return d._children ? style.node.colors.collapsed : d.children ? style.node.colors.parent : style.node.colors.default;
8791 }
8792 });
8793
8794 // transition nodes to their new position
8795 var nodeUpdate = node.transition().duration(transitionDuration).attr({
8796 transform: function transform(d) {
8797 return 'translate(' + d.y + ',' + d.x + ')';
8798 }
8799 });
8800
8801 // fade the text in
8802 nodeUpdate.select('text').style('fill-opacity', 1);
8803
8804 // restore the circle
8805 nodeUpdate.select('circle').attr('r', 7);
8806
8807 // blink updated nodes
8808 nodeUpdate.filter(function (d) {
8809 // test whether the relevant properties of d match
8810 // the equivalent property of the oldData
8811 // also test whether the old data exists,
8812 // to catch the entering elements!
8813 return !_this.__oldData__ || d.value !== _this.__oldData__.value;
8814 }).style('fill-opacity', '0.3').transition().duration(100).style('fill-opacity', '1');
8815
8816 // transition exiting nodes to the parent's new position
8817 var nodeExit = node.exit().transition().duration(transitionDuration).attr({
8818 transform: function transform(d) {
8819 return 'translate(' + source.y + ',' + source.x + ')';
8820 }
8821 }).remove();
8822
8823 nodeExit.select('circle').attr('r', 0);
8824
8825 nodeExit.select('text').style('fill-opacity', 0);
8826
8827 // update the links
8828 var link = vis.selectAll('path.link').data(links, function (d) {
8829 return d.target.id;
8830 });
8831
8832 // enter any new links at the parent's previous position
8833 link.enter().insert('path', 'g').attr({
8834 'class': 'link',
8835 d: function d(_d) {
8836 var o = {
8837 x: source.x0,
8838 y: source.y0
8839 };
8840 return diagonal({
8841 source: o,
8842 target: o
8843 });
8844 }
8845 }).style(style.link);
8846
8847 // transition links to their new position
8848 link.transition().duration(transitionDuration).attr({
8849 d: diagonal
8850 });
8851
8852 // transition exiting nodes to the parent's new position
8853 link.exit().transition().duration(transitionDuration).attr({
8854 d: function d(_d2) {
8855 var o = {
8856 x: source.x,
8857 y: source.y
8858 };
8859 return diagonal({
8860 source: o,
8861 target: o
8862 });
8863 }
8864 }).remove();
8865
8866 // delete the old data once it's no longer needed
8867 node.property('__oldData__', null);
8868
8869 // stash the old positions for transition
8870 nodes.forEach(function (d) {
8871 d.x0 = d.x;
8872 d.y0 = d.y;
8873 });
8874 }
8875 };
8876 };
8877
8878 var _d3 = __webpack_require__(38);
8879
8880 var _d4 = _interopRequireDefault(_d3);
8881
8882 var _ramda = __webpack_require__(4);
8883
8884 var _map2tree = __webpack_require__(104);
8885
8886 var _map2tree2 = _interopRequireDefault(_map2tree);
8887
8888 var _deepmerge2 = __webpack_require__(42);
8889
8890 var _deepmerge3 = _interopRequireDefault(_deepmerge2);
8891
8892 var _utils = __webpack_require__(37);
8893
8894 var _d3tooltip = __webpack_require__(39);
8895
8896 var _d3tooltip2 = _interopRequireDefault(_d3tooltip);
8897
8898 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8899
8900 var defaultOptions = {
8901 state: undefined,
8902 rootKeyName: 'state',
8903 pushMethod: 'push',
8904 tree: undefined,
8905 id: 'd3svg',
8906 style: {
8907 node: {
8908 colors: {
8909 'default': '#ccc',
8910 collapsed: 'lightsteelblue',
8911 parent: 'white'
8912 },
8913 radius: 5
8914 },
8915 text: {
8916 colors: {
8917 'default': 'black',
8918 hover: 'skyblue'
8919 }
8920 },
8921 link: {
8922 stroke: '#000',
8923 fill: 'none'
8924 }
8925 },
8926 size: 500,
8927 aspectRatio: 1.0,
8928 initialZoom: 1,
8929 margin: {
8930 top: 10,
8931 right: 10,
8932 bottom: 10,
8933 left: 50
8934 },
8935 isSorted: false,
8936 heightBetweenNodesCoeff: 2,
8937 widthBetweenNodesCoeff: 1,
8938 transitionDuration: 750,
8939 onClickText: function onClickText() {},
8940 tooltipOptions: {
8941 disabled: false,
8942 left: undefined,
8943 right: undefined,
8944 offset: {
8945 left: 0,
8946 top: 0
8947 },
8948 style: undefined
8949 }
8950 };
8951
8952/***/ },
8953/* 37 */
8954/***/ function(module, exports, __webpack_require__) {
8955
8956 'use strict';
8957
8958 exports.__esModule = true;
8959 exports.collapseChildren = collapseChildren;
8960 exports.expandChildren = expandChildren;
8961 exports.toggleChildren = toggleChildren;
8962 exports.visit = visit;
8963 exports.getNodeGroupByDepthCount = getNodeGroupByDepthCount;
8964 exports.getTooltipString = getTooltipString;
8965
8966 var _ramda = __webpack_require__(4);
8967
8968 var _sortAndSerialize = __webpack_require__(35);
8969
8970 var _sortAndSerialize2 = _interopRequireDefault(_sortAndSerialize);
8971
8972 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8973
8974 function collapseChildren(node) {
8975 if (node.children) {
8976 node._children = node.children;
8977 node._children.forEach(collapseChildren);
8978 node.children = null;
8979 }
8980 }
8981
8982 function expandChildren(node) {
8983 if (node._children) {
8984 node.children = node._children;
8985 node.children.forEach(expandChildren);
8986 node._children = null;
8987 }
8988 }
8989
8990 function toggleChildren(node) {
8991 if (node.children) {
8992 node._children = node.children;
8993 node.children = null;
8994 } else if (node._children) {
8995 node.children = node._children;
8996 node._children = null;
8997 }
8998 return node;
8999 }
9000
9001 function visit(parent, visitFn, childrenFn) {
9002 if (!parent) {
9003 return;
9004 }
9005
9006 visitFn(parent);
9007
9008 var children = childrenFn(parent);
9009 if (children) {
9010 var count = children.length;
9011
9012 for (var i = 0; i < count; i++) {
9013 visit(children[i], visitFn, childrenFn);
9014 }
9015 }
9016 }
9017
9018 function getNodeGroupByDepthCount(rootNode) {
9019 var nodeGroupByDepthCount = [1];
9020
9021 var traverseFrom = function traverseFrom(node) {
9022 var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
9023
9024 if (!node.children || node.children.length === 0) {
9025 return 0;
9026 }
9027
9028 if (nodeGroupByDepthCount.length <= depth + 1) {
9029 nodeGroupByDepthCount.push(0);
9030 }
9031
9032 nodeGroupByDepthCount[depth + 1] += node.children.length;
9033
9034 node.children.forEach(function (childNode) {
9035 traverseFrom(childNode, depth + 1);
9036 });
9037 };
9038
9039 traverseFrom(rootNode);
9040 return nodeGroupByDepthCount;
9041 }
9042
9043 function getTooltipString(node, i, _ref) {
9044 var _ref$indentationSize = _ref.indentationSize;
9045 var indentationSize = _ref$indentationSize === undefined ? 4 : _ref$indentationSize;
9046
9047 if (!(0, _ramda.is)(Object, node)) return '';
9048
9049 var spacer = (0, _ramda.join)('&nbsp;&nbsp;');
9050 var cr2br = (0, _ramda.replace)(/\n/g, '<br/>');
9051 var spaces2nbsp = (0, _ramda.replace)(/\s{2}/g, spacer(new Array(indentationSize)));
9052 var json2html = (0, _ramda.pipe)(_sortAndSerialize2.default, cr2br, spaces2nbsp);
9053
9054 var children = node.children || node._children;
9055
9056 if (typeof node.value !== 'undefined') return json2html(node.value);
9057 if (typeof node.object !== 'undefined') return json2html(node.object);
9058 if (children && children.length) return 'childrenCount: ' + children.length;
9059 return 'empty';
9060 }
9061
9062/***/ },
9063/* 38 */
9064/***/ function(module, exports, __webpack_require__) {
9065
9066 var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;!function() {
9067 var d3 = {
9068 version: "3.5.17"
9069 };
9070 var d3_arraySlice = [].slice, d3_array = function(list) {
9071 return d3_arraySlice.call(list);
9072 };
9073 var d3_document = this.document;
9074 function d3_documentElement(node) {
9075 return node && (node.ownerDocument || node.document || node).documentElement;
9076 }
9077 function d3_window(node) {
9078 return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
9079 }
9080 if (d3_document) {
9081 try {
9082 d3_array(d3_document.documentElement.childNodes)[0].nodeType;
9083 } catch (e) {
9084 d3_array = function(list) {
9085 var i = list.length, array = new Array(i);
9086 while (i--) array[i] = list[i];
9087 return array;
9088 };
9089 }
9090 }
9091 if (!Date.now) Date.now = function() {
9092 return +new Date();
9093 };
9094 if (d3_document) {
9095 try {
9096 d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
9097 } catch (error) {
9098 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;
9099 d3_element_prototype.setAttribute = function(name, value) {
9100 d3_element_setAttribute.call(this, name, value + "");
9101 };
9102 d3_element_prototype.setAttributeNS = function(space, local, value) {
9103 d3_element_setAttributeNS.call(this, space, local, value + "");
9104 };
9105 d3_style_prototype.setProperty = function(name, value, priority) {
9106 d3_style_setProperty.call(this, name, value + "", priority);
9107 };
9108 }
9109 }
9110 d3.ascending = d3_ascending;
9111 function d3_ascending(a, b) {
9112 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
9113 }
9114 d3.descending = function(a, b) {
9115 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
9116 };
9117 d3.min = function(array, f) {
9118 var i = -1, n = array.length, a, b;
9119 if (arguments.length === 1) {
9120 while (++i < n) if ((b = array[i]) != null && b >= b) {
9121 a = b;
9122 break;
9123 }
9124 while (++i < n) if ((b = array[i]) != null && a > b) a = b;
9125 } else {
9126 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
9127 a = b;
9128 break;
9129 }
9130 while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
9131 }
9132 return a;
9133 };
9134 d3.max = function(array, f) {
9135 var i = -1, n = array.length, a, b;
9136 if (arguments.length === 1) {
9137 while (++i < n) if ((b = array[i]) != null && b >= b) {
9138 a = b;
9139 break;
9140 }
9141 while (++i < n) if ((b = array[i]) != null && b > a) a = b;
9142 } else {
9143 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
9144 a = b;
9145 break;
9146 }
9147 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
9148 }
9149 return a;
9150 };
9151 d3.extent = function(array, f) {
9152 var i = -1, n = array.length, a, b, c;
9153 if (arguments.length === 1) {
9154 while (++i < n) if ((b = array[i]) != null && b >= b) {
9155 a = c = b;
9156 break;
9157 }
9158 while (++i < n) if ((b = array[i]) != null) {
9159 if (a > b) a = b;
9160 if (c < b) c = b;
9161 }
9162 } else {
9163 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
9164 a = c = b;
9165 break;
9166 }
9167 while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
9168 if (a > b) a = b;
9169 if (c < b) c = b;
9170 }
9171 }
9172 return [ a, c ];
9173 };
9174 function d3_number(x) {
9175 return x === null ? NaN : +x;
9176 }
9177 function d3_numeric(x) {
9178 return !isNaN(x);
9179 }
9180 d3.sum = function(array, f) {
9181 var s = 0, n = array.length, a, i = -1;
9182 if (arguments.length === 1) {
9183 while (++i < n) if (d3_numeric(a = +array[i])) s += a;
9184 } else {
9185 while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
9186 }
9187 return s;
9188 };
9189 d3.mean = function(array, f) {
9190 var s = 0, n = array.length, a, i = -1, j = n;
9191 if (arguments.length === 1) {
9192 while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
9193 } else {
9194 while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
9195 }
9196 if (j) return s / j;
9197 };
9198 d3.quantile = function(values, p) {
9199 var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
9200 return e ? v + e * (values[h] - v) : v;
9201 };
9202 d3.median = function(array, f) {
9203 var numbers = [], n = array.length, a, i = -1;
9204 if (arguments.length === 1) {
9205 while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
9206 } else {
9207 while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
9208 }
9209 if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
9210 };
9211 d3.variance = function(array, f) {
9212 var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
9213 if (arguments.length === 1) {
9214 while (++i < n) {
9215 if (d3_numeric(a = d3_number(array[i]))) {
9216 d = a - m;
9217 m += d / ++j;
9218 s += d * (a - m);
9219 }
9220 }
9221 } else {
9222 while (++i < n) {
9223 if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
9224 d = a - m;
9225 m += d / ++j;
9226 s += d * (a - m);
9227 }
9228 }
9229 }
9230 if (j > 1) return s / (j - 1);
9231 };
9232 d3.deviation = function() {
9233 var v = d3.variance.apply(this, arguments);
9234 return v ? Math.sqrt(v) : v;
9235 };
9236 function d3_bisector(compare) {
9237 return {
9238 left: function(a, x, lo, hi) {
9239 if (arguments.length < 3) lo = 0;
9240 if (arguments.length < 4) hi = a.length;
9241 while (lo < hi) {
9242 var mid = lo + hi >>> 1;
9243 if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
9244 }
9245 return lo;
9246 },
9247 right: function(a, x, lo, hi) {
9248 if (arguments.length < 3) lo = 0;
9249 if (arguments.length < 4) hi = a.length;
9250 while (lo < hi) {
9251 var mid = lo + hi >>> 1;
9252 if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
9253 }
9254 return lo;
9255 }
9256 };
9257 }
9258 var d3_bisect = d3_bisector(d3_ascending);
9259 d3.bisectLeft = d3_bisect.left;
9260 d3.bisect = d3.bisectRight = d3_bisect.right;
9261 d3.bisector = function(f) {
9262 return d3_bisector(f.length === 1 ? function(d, x) {
9263 return d3_ascending(f(d), x);
9264 } : f);
9265 };
9266 d3.shuffle = function(array, i0, i1) {
9267 if ((m = arguments.length) < 3) {
9268 i1 = array.length;
9269 if (m < 2) i0 = 0;
9270 }
9271 var m = i1 - i0, t, i;
9272 while (m) {
9273 i = Math.random() * m-- | 0;
9274 t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
9275 }
9276 return array;
9277 };
9278 d3.permute = function(array, indexes) {
9279 var i = indexes.length, permutes = new Array(i);
9280 while (i--) permutes[i] = array[indexes[i]];
9281 return permutes;
9282 };
9283 d3.pairs = function(array) {
9284 var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
9285 while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
9286 return pairs;
9287 };
9288 d3.transpose = function(matrix) {
9289 if (!(n = matrix.length)) return [];
9290 for (var i = -1, m = d3.min(matrix, d3_transposeLength), transpose = new Array(m); ++i < m; ) {
9291 for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n; ) {
9292 row[j] = matrix[j][i];
9293 }
9294 }
9295 return transpose;
9296 };
9297 function d3_transposeLength(d) {
9298 return d.length;
9299 }
9300 d3.zip = function() {
9301 return d3.transpose(arguments);
9302 };
9303 d3.keys = function(map) {
9304 var keys = [];
9305 for (var key in map) keys.push(key);
9306 return keys;
9307 };
9308 d3.values = function(map) {
9309 var values = [];
9310 for (var key in map) values.push(map[key]);
9311 return values;
9312 };
9313 d3.entries = function(map) {
9314 var entries = [];
9315 for (var key in map) entries.push({
9316 key: key,
9317 value: map[key]
9318 });
9319 return entries;
9320 };
9321 d3.merge = function(arrays) {
9322 var n = arrays.length, m, i = -1, j = 0, merged, array;
9323 while (++i < n) j += arrays[i].length;
9324 merged = new Array(j);
9325 while (--n >= 0) {
9326 array = arrays[n];
9327 m = array.length;
9328 while (--m >= 0) {
9329 merged[--j] = array[m];
9330 }
9331 }
9332 return merged;
9333 };
9334 var abs = Math.abs;
9335 d3.range = function(start, stop, step) {
9336 if (arguments.length < 3) {
9337 step = 1;
9338 if (arguments.length < 2) {
9339 stop = start;
9340 start = 0;
9341 }
9342 }
9343 if ((stop - start) / step === Infinity) throw new Error("infinite range");
9344 var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
9345 start *= k, stop *= k, step *= k;
9346 if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
9347 return range;
9348 };
9349 function d3_range_integerScale(x) {
9350 var k = 1;
9351 while (x * k % 1) k *= 10;
9352 return k;
9353 }
9354 function d3_class(ctor, properties) {
9355 for (var key in properties) {
9356 Object.defineProperty(ctor.prototype, key, {
9357 value: properties[key],
9358 enumerable: false
9359 });
9360 }
9361 }
9362 d3.map = function(object, f) {
9363 var map = new d3_Map();
9364 if (object instanceof d3_Map) {
9365 object.forEach(function(key, value) {
9366 map.set(key, value);
9367 });
9368 } else if (Array.isArray(object)) {
9369 var i = -1, n = object.length, o;
9370 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);
9371 } else {
9372 for (var key in object) map.set(key, object[key]);
9373 }
9374 return map;
9375 };
9376 function d3_Map() {
9377 this._ = Object.create(null);
9378 }
9379 var d3_map_proto = "__proto__", d3_map_zero = "\x00";
9380 d3_class(d3_Map, {
9381 has: d3_map_has,
9382 get: function(key) {
9383 return this._[d3_map_escape(key)];
9384 },
9385 set: function(key, value) {
9386 return this._[d3_map_escape(key)] = value;
9387 },
9388 remove: d3_map_remove,
9389 keys: d3_map_keys,
9390 values: function() {
9391 var values = [];
9392 for (var key in this._) values.push(this._[key]);
9393 return values;
9394 },
9395 entries: function() {
9396 var entries = [];
9397 for (var key in this._) entries.push({
9398 key: d3_map_unescape(key),
9399 value: this._[key]
9400 });
9401 return entries;
9402 },
9403 size: d3_map_size,
9404 empty: d3_map_empty,
9405 forEach: function(f) {
9406 for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
9407 }
9408 });
9409 function d3_map_escape(key) {
9410 return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
9411 }
9412 function d3_map_unescape(key) {
9413 return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
9414 }
9415 function d3_map_has(key) {
9416 return d3_map_escape(key) in this._;
9417 }
9418 function d3_map_remove(key) {
9419 return (key = d3_map_escape(key)) in this._ && delete this._[key];
9420 }
9421 function d3_map_keys() {
9422 var keys = [];
9423 for (var key in this._) keys.push(d3_map_unescape(key));
9424 return keys;
9425 }
9426 function d3_map_size() {
9427 var size = 0;
9428 for (var key in this._) ++size;
9429 return size;
9430 }
9431 function d3_map_empty() {
9432 for (var key in this._) return false;
9433 return true;
9434 }
9435 d3.nest = function() {
9436 var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
9437 function map(mapType, array, depth) {
9438 if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
9439 var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
9440 while (++i < n) {
9441 if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
9442 values.push(object);
9443 } else {
9444 valuesByKey.set(keyValue, [ object ]);
9445 }
9446 }
9447 if (mapType) {
9448 object = mapType();
9449 setter = function(keyValue, values) {
9450 object.set(keyValue, map(mapType, values, depth));
9451 };
9452 } else {
9453 object = {};
9454 setter = function(keyValue, values) {
9455 object[keyValue] = map(mapType, values, depth);
9456 };
9457 }
9458 valuesByKey.forEach(setter);
9459 return object;
9460 }
9461 function entries(map, depth) {
9462 if (depth >= keys.length) return map;
9463 var array = [], sortKey = sortKeys[depth++];
9464 map.forEach(function(key, keyMap) {
9465 array.push({
9466 key: key,
9467 values: entries(keyMap, depth)
9468 });
9469 });
9470 return sortKey ? array.sort(function(a, b) {
9471 return sortKey(a.key, b.key);
9472 }) : array;
9473 }
9474 nest.map = function(array, mapType) {
9475 return map(mapType, array, 0);
9476 };
9477 nest.entries = function(array) {
9478 return entries(map(d3.map, array, 0), 0);
9479 };
9480 nest.key = function(d) {
9481 keys.push(d);
9482 return nest;
9483 };
9484 nest.sortKeys = function(order) {
9485 sortKeys[keys.length - 1] = order;
9486 return nest;
9487 };
9488 nest.sortValues = function(order) {
9489 sortValues = order;
9490 return nest;
9491 };
9492 nest.rollup = function(f) {
9493 rollup = f;
9494 return nest;
9495 };
9496 return nest;
9497 };
9498 d3.set = function(array) {
9499 var set = new d3_Set();
9500 if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
9501 return set;
9502 };
9503 function d3_Set() {
9504 this._ = Object.create(null);
9505 }
9506 d3_class(d3_Set, {
9507 has: d3_map_has,
9508 add: function(key) {
9509 this._[d3_map_escape(key += "")] = true;
9510 return key;
9511 },
9512 remove: d3_map_remove,
9513 values: d3_map_keys,
9514 size: d3_map_size,
9515 empty: d3_map_empty,
9516 forEach: function(f) {
9517 for (var key in this._) f.call(this, d3_map_unescape(key));
9518 }
9519 });
9520 d3.behavior = {};
9521 function d3_identity(d) {
9522 return d;
9523 }
9524 d3.rebind = function(target, source) {
9525 var i = 1, n = arguments.length, method;
9526 while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
9527 return target;
9528 };
9529 function d3_rebind(target, source, method) {
9530 return function() {
9531 var value = method.apply(source, arguments);
9532 return value === source ? target : value;
9533 };
9534 }
9535 function d3_vendorSymbol(object, name) {
9536 if (name in object) return name;
9537 name = name.charAt(0).toUpperCase() + name.slice(1);
9538 for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
9539 var prefixName = d3_vendorPrefixes[i] + name;
9540 if (prefixName in object) return prefixName;
9541 }
9542 }
9543 var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
9544 function d3_noop() {}
9545 d3.dispatch = function() {
9546 var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
9547 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
9548 return dispatch;
9549 };
9550 function d3_dispatch() {}
9551 d3_dispatch.prototype.on = function(type, listener) {
9552 var i = type.indexOf("."), name = "";
9553 if (i >= 0) {
9554 name = type.slice(i + 1);
9555 type = type.slice(0, i);
9556 }
9557 if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
9558 if (arguments.length === 2) {
9559 if (listener == null) for (type in this) {
9560 if (this.hasOwnProperty(type)) this[type].on(name, null);
9561 }
9562 return this;
9563 }
9564 };
9565 function d3_dispatch_event(dispatch) {
9566 var listeners = [], listenerByName = new d3_Map();
9567 function event() {
9568 var z = listeners, i = -1, n = z.length, l;
9569 while (++i < n) if (l = z[i].on) l.apply(this, arguments);
9570 return dispatch;
9571 }
9572 event.on = function(name, listener) {
9573 var l = listenerByName.get(name), i;
9574 if (arguments.length < 2) return l && l.on;
9575 if (l) {
9576 l.on = null;
9577 listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
9578 listenerByName.remove(name);
9579 }
9580 if (listener) listeners.push(listenerByName.set(name, {
9581 on: listener
9582 }));
9583 return dispatch;
9584 };
9585 return event;
9586 }
9587 d3.event = null;
9588 function d3_eventPreventDefault() {
9589 d3.event.preventDefault();
9590 }
9591 function d3_eventSource() {
9592 var e = d3.event, s;
9593 while (s = e.sourceEvent) e = s;
9594 return e;
9595 }
9596 function d3_eventDispatch(target) {
9597 var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
9598 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
9599 dispatch.of = function(thiz, argumentz) {
9600 return function(e1) {
9601 try {
9602 var e0 = e1.sourceEvent = d3.event;
9603 e1.target = target;
9604 d3.event = e1;
9605 dispatch[e1.type].apply(thiz, argumentz);
9606 } finally {
9607 d3.event = e0;
9608 }
9609 };
9610 };
9611 return dispatch;
9612 }
9613 d3.requote = function(s) {
9614 return s.replace(d3_requote_re, "\\$&");
9615 };
9616 var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
9617 var d3_subclass = {}.__proto__ ? function(object, prototype) {
9618 object.__proto__ = prototype;
9619 } : function(object, prototype) {
9620 for (var property in prototype) object[property] = prototype[property];
9621 };
9622 function d3_selection(groups) {
9623 d3_subclass(groups, d3_selectionPrototype);
9624 return groups;
9625 }
9626 var d3_select = function(s, n) {
9627 return n.querySelector(s);
9628 }, d3_selectAll = function(s, n) {
9629 return n.querySelectorAll(s);
9630 }, d3_selectMatches = function(n, s) {
9631 var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
9632 d3_selectMatches = function(n, s) {
9633 return d3_selectMatcher.call(n, s);
9634 };
9635 return d3_selectMatches(n, s);
9636 };
9637 if (typeof Sizzle === "function") {
9638 d3_select = function(s, n) {
9639 return Sizzle(s, n)[0] || null;
9640 };
9641 d3_selectAll = Sizzle;
9642 d3_selectMatches = Sizzle.matchesSelector;
9643 }
9644 d3.selection = function() {
9645 return d3.select(d3_document.documentElement);
9646 };
9647 var d3_selectionPrototype = d3.selection.prototype = [];
9648 d3_selectionPrototype.select = function(selector) {
9649 var subgroups = [], subgroup, subnode, group, node;
9650 selector = d3_selection_selector(selector);
9651 for (var j = -1, m = this.length; ++j < m; ) {
9652 subgroups.push(subgroup = []);
9653 subgroup.parentNode = (group = this[j]).parentNode;
9654 for (var i = -1, n = group.length; ++i < n; ) {
9655 if (node = group[i]) {
9656 subgroup.push(subnode = selector.call(node, node.__data__, i, j));
9657 if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
9658 } else {
9659 subgroup.push(null);
9660 }
9661 }
9662 }
9663 return d3_selection(subgroups);
9664 };
9665 function d3_selection_selector(selector) {
9666 return typeof selector === "function" ? selector : function() {
9667 return d3_select(selector, this);
9668 };
9669 }
9670 d3_selectionPrototype.selectAll = function(selector) {
9671 var subgroups = [], subgroup, node;
9672 selector = d3_selection_selectorAll(selector);
9673 for (var j = -1, m = this.length; ++j < m; ) {
9674 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
9675 if (node = group[i]) {
9676 subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
9677 subgroup.parentNode = node;
9678 }
9679 }
9680 }
9681 return d3_selection(subgroups);
9682 };
9683 function d3_selection_selectorAll(selector) {
9684 return typeof selector === "function" ? selector : function() {
9685 return d3_selectAll(selector, this);
9686 };
9687 }
9688 var d3_nsXhtml = "http://www.w3.org/1999/xhtml";
9689 var d3_nsPrefix = {
9690 svg: "http://www.w3.org/2000/svg",
9691 xhtml: d3_nsXhtml,
9692 xlink: "http://www.w3.org/1999/xlink",
9693 xml: "http://www.w3.org/XML/1998/namespace",
9694 xmlns: "http://www.w3.org/2000/xmlns/"
9695 };
9696 d3.ns = {
9697 prefix: d3_nsPrefix,
9698 qualify: function(name) {
9699 var i = name.indexOf(":"), prefix = name;
9700 if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
9701 return d3_nsPrefix.hasOwnProperty(prefix) ? {
9702 space: d3_nsPrefix[prefix],
9703 local: name
9704 } : name;
9705 }
9706 };
9707 d3_selectionPrototype.attr = function(name, value) {
9708 if (arguments.length < 2) {
9709 if (typeof name === "string") {
9710 var node = this.node();
9711 name = d3.ns.qualify(name);
9712 return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
9713 }
9714 for (value in name) this.each(d3_selection_attr(value, name[value]));
9715 return this;
9716 }
9717 return this.each(d3_selection_attr(name, value));
9718 };
9719 function d3_selection_attr(name, value) {
9720 name = d3.ns.qualify(name);
9721 function attrNull() {
9722 this.removeAttribute(name);
9723 }
9724 function attrNullNS() {
9725 this.removeAttributeNS(name.space, name.local);
9726 }
9727 function attrConstant() {
9728 this.setAttribute(name, value);
9729 }
9730 function attrConstantNS() {
9731 this.setAttributeNS(name.space, name.local, value);
9732 }
9733 function attrFunction() {
9734 var x = value.apply(this, arguments);
9735 if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
9736 }
9737 function attrFunctionNS() {
9738 var x = value.apply(this, arguments);
9739 if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
9740 }
9741 return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
9742 }
9743 function d3_collapse(s) {
9744 return s.trim().replace(/\s+/g, " ");
9745 }
9746 d3_selectionPrototype.classed = function(name, value) {
9747 if (arguments.length < 2) {
9748 if (typeof name === "string") {
9749 var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
9750 if (value = node.classList) {
9751 while (++i < n) if (!value.contains(name[i])) return false;
9752 } else {
9753 value = node.getAttribute("class");
9754 while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
9755 }
9756 return true;
9757 }
9758 for (value in name) this.each(d3_selection_classed(value, name[value]));
9759 return this;
9760 }
9761 return this.each(d3_selection_classed(name, value));
9762 };
9763 function d3_selection_classedRe(name) {
9764 return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
9765 }
9766 function d3_selection_classes(name) {
9767 return (name + "").trim().split(/^|\s+/);
9768 }
9769 function d3_selection_classed(name, value) {
9770 name = d3_selection_classes(name).map(d3_selection_classedName);
9771 var n = name.length;
9772 function classedConstant() {
9773 var i = -1;
9774 while (++i < n) name[i](this, value);
9775 }
9776 function classedFunction() {
9777 var i = -1, x = value.apply(this, arguments);
9778 while (++i < n) name[i](this, x);
9779 }
9780 return typeof value === "function" ? classedFunction : classedConstant;
9781 }
9782 function d3_selection_classedName(name) {
9783 var re = d3_selection_classedRe(name);
9784 return function(node, value) {
9785 if (c = node.classList) return value ? c.add(name) : c.remove(name);
9786 var c = node.getAttribute("class") || "";
9787 if (value) {
9788 re.lastIndex = 0;
9789 if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
9790 } else {
9791 node.setAttribute("class", d3_collapse(c.replace(re, " ")));
9792 }
9793 };
9794 }
9795 d3_selectionPrototype.style = function(name, value, priority) {
9796 var n = arguments.length;
9797 if (n < 3) {
9798 if (typeof name !== "string") {
9799 if (n < 2) value = "";
9800 for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
9801 return this;
9802 }
9803 if (n < 2) {
9804 var node = this.node();
9805 return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
9806 }
9807 priority = "";
9808 }
9809 return this.each(d3_selection_style(name, value, priority));
9810 };
9811 function d3_selection_style(name, value, priority) {
9812 function styleNull() {
9813 this.style.removeProperty(name);
9814 }
9815 function styleConstant() {
9816 this.style.setProperty(name, value, priority);
9817 }
9818 function styleFunction() {
9819 var x = value.apply(this, arguments);
9820 if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
9821 }
9822 return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
9823 }
9824 d3_selectionPrototype.property = function(name, value) {
9825 if (arguments.length < 2) {
9826 if (typeof name === "string") return this.node()[name];
9827 for (value in name) this.each(d3_selection_property(value, name[value]));
9828 return this;
9829 }
9830 return this.each(d3_selection_property(name, value));
9831 };
9832 function d3_selection_property(name, value) {
9833 function propertyNull() {
9834 delete this[name];
9835 }
9836 function propertyConstant() {
9837 this[name] = value;
9838 }
9839 function propertyFunction() {
9840 var x = value.apply(this, arguments);
9841 if (x == null) delete this[name]; else this[name] = x;
9842 }
9843 return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
9844 }
9845 d3_selectionPrototype.text = function(value) {
9846 return arguments.length ? this.each(typeof value === "function" ? function() {
9847 var v = value.apply(this, arguments);
9848 this.textContent = v == null ? "" : v;
9849 } : value == null ? function() {
9850 this.textContent = "";
9851 } : function() {
9852 this.textContent = value;
9853 }) : this.node().textContent;
9854 };
9855 d3_selectionPrototype.html = function(value) {
9856 return arguments.length ? this.each(typeof value === "function" ? function() {
9857 var v = value.apply(this, arguments);
9858 this.innerHTML = v == null ? "" : v;
9859 } : value == null ? function() {
9860 this.innerHTML = "";
9861 } : function() {
9862 this.innerHTML = value;
9863 }) : this.node().innerHTML;
9864 };
9865 d3_selectionPrototype.append = function(name) {
9866 name = d3_selection_creator(name);
9867 return this.select(function() {
9868 return this.appendChild(name.apply(this, arguments));
9869 });
9870 };
9871 function d3_selection_creator(name) {
9872 function create() {
9873 var document = this.ownerDocument, namespace = this.namespaceURI;
9874 return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml ? document.createElement(name) : document.createElementNS(namespace, name);
9875 }
9876 function createNS() {
9877 return this.ownerDocument.createElementNS(name.space, name.local);
9878 }
9879 return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
9880 }
9881 d3_selectionPrototype.insert = function(name, before) {
9882 name = d3_selection_creator(name);
9883 before = d3_selection_selector(before);
9884 return this.select(function() {
9885 return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
9886 });
9887 };
9888 d3_selectionPrototype.remove = function() {
9889 return this.each(d3_selectionRemove);
9890 };
9891 function d3_selectionRemove() {
9892 var parent = this.parentNode;
9893 if (parent) parent.removeChild(this);
9894 }
9895 d3_selectionPrototype.data = function(value, key) {
9896 var i = -1, n = this.length, group, node;
9897 if (!arguments.length) {
9898 value = new Array(n = (group = this[0]).length);
9899 while (++i < n) {
9900 if (node = group[i]) {
9901 value[i] = node.__data__;
9902 }
9903 }
9904 return value;
9905 }
9906 function bind(group, groupData) {
9907 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;
9908 if (key) {
9909 var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
9910 for (i = -1; ++i < n; ) {
9911 if (node = group[i]) {
9912 if (nodeByKeyValue.has(keyValue = key.call(node, node.__data__, i))) {
9913 exitNodes[i] = node;
9914 } else {
9915 nodeByKeyValue.set(keyValue, node);
9916 }
9917 keyValues[i] = keyValue;
9918 }
9919 }
9920 for (i = -1; ++i < m; ) {
9921 if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
9922 enterNodes[i] = d3_selection_dataNode(nodeData);
9923 } else if (node !== true) {
9924 updateNodes[i] = node;
9925 node.__data__ = nodeData;
9926 }
9927 nodeByKeyValue.set(keyValue, true);
9928 }
9929 for (i = -1; ++i < n; ) {
9930 if (i in keyValues && nodeByKeyValue.get(keyValues[i]) !== true) {
9931 exitNodes[i] = group[i];
9932 }
9933 }
9934 } else {
9935 for (i = -1; ++i < n0; ) {
9936 node = group[i];
9937 nodeData = groupData[i];
9938 if (node) {
9939 node.__data__ = nodeData;
9940 updateNodes[i] = node;
9941 } else {
9942 enterNodes[i] = d3_selection_dataNode(nodeData);
9943 }
9944 }
9945 for (;i < m; ++i) {
9946 enterNodes[i] = d3_selection_dataNode(groupData[i]);
9947 }
9948 for (;i < n; ++i) {
9949 exitNodes[i] = group[i];
9950 }
9951 }
9952 enterNodes.update = updateNodes;
9953 enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
9954 enter.push(enterNodes);
9955 update.push(updateNodes);
9956 exit.push(exitNodes);
9957 }
9958 var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
9959 if (typeof value === "function") {
9960 while (++i < n) {
9961 bind(group = this[i], value.call(group, group.parentNode.__data__, i));
9962 }
9963 } else {
9964 while (++i < n) {
9965 bind(group = this[i], value);
9966 }
9967 }
9968 update.enter = function() {
9969 return enter;
9970 };
9971 update.exit = function() {
9972 return exit;
9973 };
9974 return update;
9975 };
9976 function d3_selection_dataNode(data) {
9977 return {
9978 __data__: data
9979 };
9980 }
9981 d3_selectionPrototype.datum = function(value) {
9982 return arguments.length ? this.property("__data__", value) : this.property("__data__");
9983 };
9984 d3_selectionPrototype.filter = function(filter) {
9985 var subgroups = [], subgroup, group, node;
9986 if (typeof filter !== "function") filter = d3_selection_filter(filter);
9987 for (var j = 0, m = this.length; j < m; j++) {
9988 subgroups.push(subgroup = []);
9989 subgroup.parentNode = (group = this[j]).parentNode;
9990 for (var i = 0, n = group.length; i < n; i++) {
9991 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
9992 subgroup.push(node);
9993 }
9994 }
9995 }
9996 return d3_selection(subgroups);
9997 };
9998 function d3_selection_filter(selector) {
9999 return function() {
10000 return d3_selectMatches(this, selector);
10001 };
10002 }
10003 d3_selectionPrototype.order = function() {
10004 for (var j = -1, m = this.length; ++j < m; ) {
10005 for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
10006 if (node = group[i]) {
10007 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
10008 next = node;
10009 }
10010 }
10011 }
10012 return this;
10013 };
10014 d3_selectionPrototype.sort = function(comparator) {
10015 comparator = d3_selection_sortComparator.apply(this, arguments);
10016 for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
10017 return this.order();
10018 };
10019 function d3_selection_sortComparator(comparator) {
10020 if (!arguments.length) comparator = d3_ascending;
10021 return function(a, b) {
10022 return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
10023 };
10024 }
10025 d3_selectionPrototype.each = function(callback) {
10026 return d3_selection_each(this, function(node, i, j) {
10027 callback.call(node, node.__data__, i, j);
10028 });
10029 };
10030 function d3_selection_each(groups, callback) {
10031 for (var j = 0, m = groups.length; j < m; j++) {
10032 for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
10033 if (node = group[i]) callback(node, i, j);
10034 }
10035 }
10036 return groups;
10037 }
10038 d3_selectionPrototype.call = function(callback) {
10039 var args = d3_array(arguments);
10040 callback.apply(args[0] = this, args);
10041 return this;
10042 };
10043 d3_selectionPrototype.empty = function() {
10044 return !this.node();
10045 };
10046 d3_selectionPrototype.node = function() {
10047 for (var j = 0, m = this.length; j < m; j++) {
10048 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
10049 var node = group[i];
10050 if (node) return node;
10051 }
10052 }
10053 return null;
10054 };
10055 d3_selectionPrototype.size = function() {
10056 var n = 0;
10057 d3_selection_each(this, function() {
10058 ++n;
10059 });
10060 return n;
10061 };
10062 function d3_selection_enter(selection) {
10063 d3_subclass(selection, d3_selection_enterPrototype);
10064 return selection;
10065 }
10066 var d3_selection_enterPrototype = [];
10067 d3.selection.enter = d3_selection_enter;
10068 d3.selection.enter.prototype = d3_selection_enterPrototype;
10069 d3_selection_enterPrototype.append = d3_selectionPrototype.append;
10070 d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
10071 d3_selection_enterPrototype.node = d3_selectionPrototype.node;
10072 d3_selection_enterPrototype.call = d3_selectionPrototype.call;
10073 d3_selection_enterPrototype.size = d3_selectionPrototype.size;
10074 d3_selection_enterPrototype.select = function(selector) {
10075 var subgroups = [], subgroup, subnode, upgroup, group, node;
10076 for (var j = -1, m = this.length; ++j < m; ) {
10077 upgroup = (group = this[j]).update;
10078 subgroups.push(subgroup = []);
10079 subgroup.parentNode = group.parentNode;
10080 for (var i = -1, n = group.length; ++i < n; ) {
10081 if (node = group[i]) {
10082 subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
10083 subnode.__data__ = node.__data__;
10084 } else {
10085 subgroup.push(null);
10086 }
10087 }
10088 }
10089 return d3_selection(subgroups);
10090 };
10091 d3_selection_enterPrototype.insert = function(name, before) {
10092 if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
10093 return d3_selectionPrototype.insert.call(this, name, before);
10094 };
10095 function d3_selection_enterInsertBefore(enter) {
10096 var i0, j0;
10097 return function(d, i, j) {
10098 var group = enter[j].update, n = group.length, node;
10099 if (j != j0) j0 = j, i0 = 0;
10100 if (i >= i0) i0 = i + 1;
10101 while (!(node = group[i0]) && ++i0 < n) ;
10102 return node;
10103 };
10104 }
10105 d3.select = function(node) {
10106 var group;
10107 if (typeof node === "string") {
10108 group = [ d3_select(node, d3_document) ];
10109 group.parentNode = d3_document.documentElement;
10110 } else {
10111 group = [ node ];
10112 group.parentNode = d3_documentElement(node);
10113 }
10114 return d3_selection([ group ]);
10115 };
10116 d3.selectAll = function(nodes) {
10117 var group;
10118 if (typeof nodes === "string") {
10119 group = d3_array(d3_selectAll(nodes, d3_document));
10120 group.parentNode = d3_document.documentElement;
10121 } else {
10122 group = d3_array(nodes);
10123 group.parentNode = null;
10124 }
10125 return d3_selection([ group ]);
10126 };
10127 d3_selectionPrototype.on = function(type, listener, capture) {
10128 var n = arguments.length;
10129 if (n < 3) {
10130 if (typeof type !== "string") {
10131 if (n < 2) listener = false;
10132 for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
10133 return this;
10134 }
10135 if (n < 2) return (n = this.node()["__on" + type]) && n._;
10136 capture = false;
10137 }
10138 return this.each(d3_selection_on(type, listener, capture));
10139 };
10140 function d3_selection_on(type, listener, capture) {
10141 var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
10142 if (i > 0) type = type.slice(0, i);
10143 var filter = d3_selection_onFilters.get(type);
10144 if (filter) type = filter, wrap = d3_selection_onFilter;
10145 function onRemove() {
10146 var l = this[name];
10147 if (l) {
10148 this.removeEventListener(type, l, l.$);
10149 delete this[name];
10150 }
10151 }
10152 function onAdd() {
10153 var l = wrap(listener, d3_array(arguments));
10154 onRemove.call(this);
10155 this.addEventListener(type, this[name] = l, l.$ = capture);
10156 l._ = listener;
10157 }
10158 function removeAll() {
10159 var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
10160 for (var name in this) {
10161 if (match = name.match(re)) {
10162 var l = this[name];
10163 this.removeEventListener(match[1], l, l.$);
10164 delete this[name];
10165 }
10166 }
10167 }
10168 return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
10169 }
10170 var d3_selection_onFilters = d3.map({
10171 mouseenter: "mouseover",
10172 mouseleave: "mouseout"
10173 });
10174 if (d3_document) {
10175 d3_selection_onFilters.forEach(function(k) {
10176 if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
10177 });
10178 }
10179 function d3_selection_onListener(listener, argumentz) {
10180 return function(e) {
10181 var o = d3.event;
10182 d3.event = e;
10183 argumentz[0] = this.__data__;
10184 try {
10185 listener.apply(this, argumentz);
10186 } finally {
10187 d3.event = o;
10188 }
10189 };
10190 }
10191 function d3_selection_onFilter(listener, argumentz) {
10192 var l = d3_selection_onListener(listener, argumentz);
10193 return function(e) {
10194 var target = this, related = e.relatedTarget;
10195 if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
10196 l.call(target, e);
10197 }
10198 };
10199 }
10200 var d3_event_dragSelect, d3_event_dragId = 0;
10201 function d3_event_dragSuppress(node) {
10202 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);
10203 if (d3_event_dragSelect == null) {
10204 d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
10205 }
10206 if (d3_event_dragSelect) {
10207 var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
10208 style[d3_event_dragSelect] = "none";
10209 }
10210 return function(suppressClick) {
10211 w.on(name, null);
10212 if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
10213 if (suppressClick) {
10214 var off = function() {
10215 w.on(click, null);
10216 };
10217 w.on(click, function() {
10218 d3_eventPreventDefault();
10219 off();
10220 }, true);
10221 setTimeout(off, 0);
10222 }
10223 };
10224 }
10225 d3.mouse = function(container) {
10226 return d3_mousePoint(container, d3_eventSource());
10227 };
10228 var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
10229 function d3_mousePoint(container, e) {
10230 if (e.changedTouches) e = e.changedTouches[0];
10231 var svg = container.ownerSVGElement || container;
10232 if (svg.createSVGPoint) {
10233 var point = svg.createSVGPoint();
10234 if (d3_mouse_bug44083 < 0) {
10235 var window = d3_window(container);
10236 if (window.scrollX || window.scrollY) {
10237 svg = d3.select("body").append("svg").style({
10238 position: "absolute",
10239 top: 0,
10240 left: 0,
10241 margin: 0,
10242 padding: 0,
10243 border: "none"
10244 }, "important");
10245 var ctm = svg[0][0].getScreenCTM();
10246 d3_mouse_bug44083 = !(ctm.f || ctm.e);
10247 svg.remove();
10248 }
10249 }
10250 if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
10251 point.y = e.clientY;
10252 point = point.matrixTransform(container.getScreenCTM().inverse());
10253 return [ point.x, point.y ];
10254 }
10255 var rect = container.getBoundingClientRect();
10256 return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
10257 }
10258 d3.touch = function(container, touches, identifier) {
10259 if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
10260 if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
10261 if ((touch = touches[i]).identifier === identifier) {
10262 return d3_mousePoint(container, touch);
10263 }
10264 }
10265 };
10266 d3.behavior.drag = function() {
10267 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");
10268 function drag() {
10269 this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
10270 }
10271 function dragstart(id, position, subject, move, end) {
10272 return function() {
10273 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);
10274 if (origin) {
10275 dragOffset = origin.apply(that, arguments);
10276 dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
10277 } else {
10278 dragOffset = [ 0, 0 ];
10279 }
10280 dispatch({
10281 type: "dragstart"
10282 });
10283 function moved() {
10284 var position1 = position(parent, dragId), dx, dy;
10285 if (!position1) return;
10286 dx = position1[0] - position0[0];
10287 dy = position1[1] - position0[1];
10288 dragged |= dx | dy;
10289 position0 = position1;
10290 dispatch({
10291 type: "drag",
10292 x: position1[0] + dragOffset[0],
10293 y: position1[1] + dragOffset[1],
10294 dx: dx,
10295 dy: dy
10296 });
10297 }
10298 function ended() {
10299 if (!position(parent, dragId)) return;
10300 dragSubject.on(move + dragName, null).on(end + dragName, null);
10301 dragRestore(dragged);
10302 dispatch({
10303 type: "dragend"
10304 });
10305 }
10306 };
10307 }
10308 drag.origin = function(x) {
10309 if (!arguments.length) return origin;
10310 origin = x;
10311 return drag;
10312 };
10313 return d3.rebind(drag, event, "on");
10314 };
10315 function d3_behavior_dragTouchId() {
10316 return d3.event.changedTouches[0].identifier;
10317 }
10318 d3.touches = function(container, touches) {
10319 if (arguments.length < 2) touches = d3_eventSource().touches;
10320 return touches ? d3_array(touches).map(function(touch) {
10321 var point = d3_mousePoint(container, touch);
10322 point.identifier = touch.identifier;
10323 return point;
10324 }) : [];
10325 };
10326 var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
10327 function d3_sgn(x) {
10328 return x > 0 ? 1 : x < 0 ? -1 : 0;
10329 }
10330 function d3_cross2d(a, b, c) {
10331 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
10332 }
10333 function d3_acos(x) {
10334 return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
10335 }
10336 function d3_asin(x) {
10337 return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
10338 }
10339 function d3_sinh(x) {
10340 return ((x = Math.exp(x)) - 1 / x) / 2;
10341 }
10342 function d3_cosh(x) {
10343 return ((x = Math.exp(x)) + 1 / x) / 2;
10344 }
10345 function d3_tanh(x) {
10346 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
10347 }
10348 function d3_haversin(x) {
10349 return (x = Math.sin(x / 2)) * x;
10350 }
10351 var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
10352 d3.interpolateZoom = function(p0, p1) {
10353 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;
10354 if (d2 < ε2) {
10355 S = Math.log(w1 / w0) / ρ;
10356 i = function(t) {
10357 return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * t * S) ];
10358 };
10359 } else {
10360 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);
10361 S = (r1 - r0) / ρ;
10362 i = function(t) {
10363 var s = t * S, coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
10364 return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
10365 };
10366 }
10367 i.duration = S * 1e3;
10368 return i;
10369 };
10370 d3.behavior.zoom = function() {
10371 var view = {
10372 x: 0,
10373 y: 0,
10374 k: 1
10375 }, 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;
10376 if (!d3_behavior_zoomWheel) {
10377 d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
10378 return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
10379 }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
10380 return d3.event.wheelDelta;
10381 }, "mousewheel") : (d3_behavior_zoomDelta = function() {
10382 return -d3.event.detail;
10383 }, "MozMousePixelScroll");
10384 }
10385 function zoom(g) {
10386 g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
10387 }
10388 zoom.event = function(g) {
10389 g.each(function() {
10390 var dispatch = event.of(this, arguments), view1 = view;
10391 if (d3_transitionInheritId) {
10392 d3.select(this).transition().each("start.zoom", function() {
10393 view = this.__chart__ || {
10394 x: 0,
10395 y: 0,
10396 k: 1
10397 };
10398 zoomstarted(dispatch);
10399 }).tween("zoom:zoom", function() {
10400 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 ]);
10401 return function(t) {
10402 var l = i(t), k = dx / l[2];
10403 this.__chart__ = view = {
10404 x: cx - l[0] * k,
10405 y: cy - l[1] * k,
10406 k: k
10407 };
10408 zoomed(dispatch);
10409 };
10410 }).each("interrupt.zoom", function() {
10411 zoomended(dispatch);
10412 }).each("end.zoom", function() {
10413 zoomended(dispatch);
10414 });
10415 } else {
10416 this.__chart__ = view;
10417 zoomstarted(dispatch);
10418 zoomed(dispatch);
10419 zoomended(dispatch);
10420 }
10421 });
10422 };
10423 zoom.translate = function(_) {
10424 if (!arguments.length) return [ view.x, view.y ];
10425 view = {
10426 x: +_[0],
10427 y: +_[1],
10428 k: view.k
10429 };
10430 rescale();
10431 return zoom;
10432 };
10433 zoom.scale = function(_) {
10434 if (!arguments.length) return view.k;
10435 view = {
10436 x: view.x,
10437 y: view.y,
10438 k: null
10439 };
10440 scaleTo(+_);
10441 rescale();
10442 return zoom;
10443 };
10444 zoom.scaleExtent = function(_) {
10445 if (!arguments.length) return scaleExtent;
10446 scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
10447 return zoom;
10448 };
10449 zoom.center = function(_) {
10450 if (!arguments.length) return center;
10451 center = _ && [ +_[0], +_[1] ];
10452 return zoom;
10453 };
10454 zoom.size = function(_) {
10455 if (!arguments.length) return size;
10456 size = _ && [ +_[0], +_[1] ];
10457 return zoom;
10458 };
10459 zoom.duration = function(_) {
10460 if (!arguments.length) return duration;
10461 duration = +_;
10462 return zoom;
10463 };
10464 zoom.x = function(z) {
10465 if (!arguments.length) return x1;
10466 x1 = z;
10467 x0 = z.copy();
10468 view = {
10469 x: 0,
10470 y: 0,
10471 k: 1
10472 };
10473 return zoom;
10474 };
10475 zoom.y = function(z) {
10476 if (!arguments.length) return y1;
10477 y1 = z;
10478 y0 = z.copy();
10479 view = {
10480 x: 0,
10481 y: 0,
10482 k: 1
10483 };
10484 return zoom;
10485 };
10486 function location(p) {
10487 return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
10488 }
10489 function point(l) {
10490 return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
10491 }
10492 function scaleTo(s) {
10493 view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
10494 }
10495 function translateTo(p, l) {
10496 l = point(l);
10497 view.x += p[0] - l[0];
10498 view.y += p[1] - l[1];
10499 }
10500 function zoomTo(that, p, l, k) {
10501 that.__chart__ = {
10502 x: view.x,
10503 y: view.y,
10504 k: view.k
10505 };
10506 scaleTo(Math.pow(2, k));
10507 translateTo(center0 = p, l);
10508 that = d3.select(that);
10509 if (duration > 0) that = that.transition().duration(duration);
10510 that.call(zoom.event);
10511 }
10512 function rescale() {
10513 if (x1) x1.domain(x0.range().map(function(x) {
10514 return (x - view.x) / view.k;
10515 }).map(x0.invert));
10516 if (y1) y1.domain(y0.range().map(function(y) {
10517 return (y - view.y) / view.k;
10518 }).map(y0.invert));
10519 }
10520 function zoomstarted(dispatch) {
10521 if (!zooming++) dispatch({
10522 type: "zoomstart"
10523 });
10524 }
10525 function zoomed(dispatch) {
10526 rescale();
10527 dispatch({
10528 type: "zoom",
10529 scale: view.k,
10530 translate: [ view.x, view.y ]
10531 });
10532 }
10533 function zoomended(dispatch) {
10534 if (!--zooming) dispatch({
10535 type: "zoomend"
10536 }), center0 = null;
10537 }
10538 function mousedowned() {
10539 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);
10540 d3_selection_interrupt.call(that);
10541 zoomstarted(dispatch);
10542 function moved() {
10543 dragged = 1;
10544 translateTo(d3.mouse(that), location0);
10545 zoomed(dispatch);
10546 }
10547 function ended() {
10548 subject.on(mousemove, null).on(mouseup, null);
10549 dragRestore(dragged);
10550 zoomended(dispatch);
10551 }
10552 }
10553 function touchstarted() {
10554 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);
10555 started();
10556 zoomstarted(dispatch);
10557 subject.on(mousedown, null).on(touchstart, started);
10558 function relocate() {
10559 var touches = d3.touches(that);
10560 scale0 = view.k;
10561 touches.forEach(function(t) {
10562 if (t.identifier in locations0) locations0[t.identifier] = location(t);
10563 });
10564 return touches;
10565 }
10566 function started() {
10567 var target = d3.event.target;
10568 d3.select(target).on(touchmove, moved).on(touchend, ended);
10569 targets.push(target);
10570 var changed = d3.event.changedTouches;
10571 for (var i = 0, n = changed.length; i < n; ++i) {
10572 locations0[changed[i].identifier] = null;
10573 }
10574 var touches = relocate(), now = Date.now();
10575 if (touches.length === 1) {
10576 if (now - touchtime < 500) {
10577 var p = touches[0];
10578 zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
10579 d3_eventPreventDefault();
10580 }
10581 touchtime = now;
10582 } else if (touches.length > 1) {
10583 var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
10584 distance0 = dx * dx + dy * dy;
10585 }
10586 }
10587 function moved() {
10588 var touches = d3.touches(that), p0, l0, p1, l1;
10589 d3_selection_interrupt.call(that);
10590 for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
10591 p1 = touches[i];
10592 if (l1 = locations0[p1.identifier]) {
10593 if (l0) break;
10594 p0 = p1, l0 = l1;
10595 }
10596 }
10597 if (l1) {
10598 var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
10599 p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
10600 l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
10601 scaleTo(scale1 * scale0);
10602 }
10603 touchtime = null;
10604 translateTo(p0, l0);
10605 zoomed(dispatch);
10606 }
10607 function ended() {
10608 if (d3.event.touches.length) {
10609 var changed = d3.event.changedTouches;
10610 for (var i = 0, n = changed.length; i < n; ++i) {
10611 delete locations0[changed[i].identifier];
10612 }
10613 for (var identifier in locations0) {
10614 return void relocate();
10615 }
10616 }
10617 d3.selectAll(targets).on(zoomName, null);
10618 subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
10619 dragRestore();
10620 zoomended(dispatch);
10621 }
10622 }
10623 function mousewheeled() {
10624 var dispatch = event.of(this, arguments);
10625 if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
10626 translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch);
10627 mousewheelTimer = setTimeout(function() {
10628 mousewheelTimer = null;
10629 zoomended(dispatch);
10630 }, 50);
10631 d3_eventPreventDefault();
10632 scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
10633 translateTo(center0, translate0);
10634 zoomed(dispatch);
10635 }
10636 function dblclicked() {
10637 var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
10638 zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
10639 }
10640 return d3.rebind(zoom, event, "on");
10641 };
10642 var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
10643 d3.color = d3_color;
10644 function d3_color() {}
10645 d3_color.prototype.toString = function() {
10646 return this.rgb() + "";
10647 };
10648 d3.hsl = d3_hsl;
10649 function d3_hsl(h, s, l) {
10650 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);
10651 }
10652 var d3_hslPrototype = d3_hsl.prototype = new d3_color();
10653 d3_hslPrototype.brighter = function(k) {
10654 k = Math.pow(.7, arguments.length ? k : 1);
10655 return new d3_hsl(this.h, this.s, this.l / k);
10656 };
10657 d3_hslPrototype.darker = function(k) {
10658 k = Math.pow(.7, arguments.length ? k : 1);
10659 return new d3_hsl(this.h, this.s, k * this.l);
10660 };
10661 d3_hslPrototype.rgb = function() {
10662 return d3_hsl_rgb(this.h, this.s, this.l);
10663 };
10664 function d3_hsl_rgb(h, s, l) {
10665 var m1, m2;
10666 h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
10667 s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
10668 l = l < 0 ? 0 : l > 1 ? 1 : l;
10669 m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
10670 m1 = 2 * l - m2;
10671 function v(h) {
10672 if (h > 360) h -= 360; else if (h < 0) h += 360;
10673 if (h < 60) return m1 + (m2 - m1) * h / 60;
10674 if (h < 180) return m2;
10675 if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
10676 return m1;
10677 }
10678 function vv(h) {
10679 return Math.round(v(h) * 255);
10680 }
10681 return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
10682 }
10683 d3.hcl = d3_hcl;
10684 function d3_hcl(h, c, l) {
10685 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);
10686 }
10687 var d3_hclPrototype = d3_hcl.prototype = new d3_color();
10688 d3_hclPrototype.brighter = function(k) {
10689 return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
10690 };
10691 d3_hclPrototype.darker = function(k) {
10692 return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
10693 };
10694 d3_hclPrototype.rgb = function() {
10695 return d3_hcl_lab(this.h, this.c, this.l).rgb();
10696 };
10697 function d3_hcl_lab(h, c, l) {
10698 if (isNaN(h)) h = 0;
10699 if (isNaN(c)) c = 0;
10700 return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
10701 }
10702 d3.lab = d3_lab;
10703 function d3_lab(l, a, b) {
10704 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);
10705 }
10706 var d3_lab_K = 18;
10707 var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
10708 var d3_labPrototype = d3_lab.prototype = new d3_color();
10709 d3_labPrototype.brighter = function(k) {
10710 return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
10711 };
10712 d3_labPrototype.darker = function(k) {
10713 return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
10714 };
10715 d3_labPrototype.rgb = function() {
10716 return d3_lab_rgb(this.l, this.a, this.b);
10717 };
10718 function d3_lab_rgb(l, a, b) {
10719 var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
10720 x = d3_lab_xyz(x) * d3_lab_X;
10721 y = d3_lab_xyz(y) * d3_lab_Y;
10722 z = d3_lab_xyz(z) * d3_lab_Z;
10723 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));
10724 }
10725 function d3_lab_hcl(l, a, b) {
10726 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);
10727 }
10728 function d3_lab_xyz(x) {
10729 return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
10730 }
10731 function d3_xyz_lab(x) {
10732 return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
10733 }
10734 function d3_xyz_rgb(r) {
10735 return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
10736 }
10737 d3.rgb = d3_rgb;
10738 function d3_rgb(r, g, b) {
10739 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);
10740 }
10741 function d3_rgbNumber(value) {
10742 return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
10743 }
10744 function d3_rgbString(value) {
10745 return d3_rgbNumber(value) + "";
10746 }
10747 var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
10748 d3_rgbPrototype.brighter = function(k) {
10749 k = Math.pow(.7, arguments.length ? k : 1);
10750 var r = this.r, g = this.g, b = this.b, i = 30;
10751 if (!r && !g && !b) return new d3_rgb(i, i, i);
10752 if (r && r < i) r = i;
10753 if (g && g < i) g = i;
10754 if (b && b < i) b = i;
10755 return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
10756 };
10757 d3_rgbPrototype.darker = function(k) {
10758 k = Math.pow(.7, arguments.length ? k : 1);
10759 return new d3_rgb(k * this.r, k * this.g, k * this.b);
10760 };
10761 d3_rgbPrototype.hsl = function() {
10762 return d3_rgb_hsl(this.r, this.g, this.b);
10763 };
10764 d3_rgbPrototype.toString = function() {
10765 return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
10766 };
10767 function d3_rgb_hex(v) {
10768 return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
10769 }
10770 function d3_rgb_parse(format, rgb, hsl) {
10771 var r = 0, g = 0, b = 0, m1, m2, color;
10772 m1 = /([a-z]+)\((.*)\)/.exec(format = format.toLowerCase());
10773 if (m1) {
10774 m2 = m1[2].split(",");
10775 switch (m1[1]) {
10776 case "hsl":
10777 {
10778 return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
10779 }
10780
10781 case "rgb":
10782 {
10783 return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
10784 }
10785 }
10786 }
10787 if (color = d3_rgb_names.get(format)) {
10788 return rgb(color.r, color.g, color.b);
10789 }
10790 if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
10791 if (format.length === 4) {
10792 r = (color & 3840) >> 4;
10793 r = r >> 4 | r;
10794 g = color & 240;
10795 g = g >> 4 | g;
10796 b = color & 15;
10797 b = b << 4 | b;
10798 } else if (format.length === 7) {
10799 r = (color & 16711680) >> 16;
10800 g = (color & 65280) >> 8;
10801 b = color & 255;
10802 }
10803 }
10804 return rgb(r, g, b);
10805 }
10806 function d3_rgb_hsl(r, g, b) {
10807 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;
10808 if (d) {
10809 s = l < .5 ? d / (max + min) : d / (2 - max - min);
10810 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;
10811 h *= 60;
10812 } else {
10813 h = NaN;
10814 s = l > 0 && l < 1 ? 0 : h;
10815 }
10816 return new d3_hsl(h, s, l);
10817 }
10818 function d3_rgb_lab(r, g, b) {
10819 r = d3_rgb_xyz(r);
10820 g = d3_rgb_xyz(g);
10821 b = d3_rgb_xyz(b);
10822 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);
10823 return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
10824 }
10825 function d3_rgb_xyz(r) {
10826 return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
10827 }
10828 function d3_rgb_parseNumber(c) {
10829 var f = parseFloat(c);
10830 return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
10831 }
10832 var d3_rgb_names = d3.map({
10833 aliceblue: 15792383,
10834 antiquewhite: 16444375,
10835 aqua: 65535,
10836 aquamarine: 8388564,
10837 azure: 15794175,
10838 beige: 16119260,
10839 bisque: 16770244,
10840 black: 0,
10841 blanchedalmond: 16772045,
10842 blue: 255,
10843 blueviolet: 9055202,
10844 brown: 10824234,
10845 burlywood: 14596231,
10846 cadetblue: 6266528,
10847 chartreuse: 8388352,
10848 chocolate: 13789470,
10849 coral: 16744272,
10850 cornflowerblue: 6591981,
10851 cornsilk: 16775388,
10852 crimson: 14423100,
10853 cyan: 65535,
10854 darkblue: 139,
10855 darkcyan: 35723,
10856 darkgoldenrod: 12092939,
10857 darkgray: 11119017,
10858 darkgreen: 25600,
10859 darkgrey: 11119017,
10860 darkkhaki: 12433259,
10861 darkmagenta: 9109643,
10862 darkolivegreen: 5597999,
10863 darkorange: 16747520,
10864 darkorchid: 10040012,
10865 darkred: 9109504,
10866 darksalmon: 15308410,
10867 darkseagreen: 9419919,
10868 darkslateblue: 4734347,
10869 darkslategray: 3100495,
10870 darkslategrey: 3100495,
10871 darkturquoise: 52945,
10872 darkviolet: 9699539,
10873 deeppink: 16716947,
10874 deepskyblue: 49151,
10875 dimgray: 6908265,
10876 dimgrey: 6908265,
10877 dodgerblue: 2003199,
10878 firebrick: 11674146,
10879 floralwhite: 16775920,
10880 forestgreen: 2263842,
10881 fuchsia: 16711935,
10882 gainsboro: 14474460,
10883 ghostwhite: 16316671,
10884 gold: 16766720,
10885 goldenrod: 14329120,
10886 gray: 8421504,
10887 green: 32768,
10888 greenyellow: 11403055,
10889 grey: 8421504,
10890 honeydew: 15794160,
10891 hotpink: 16738740,
10892 indianred: 13458524,
10893 indigo: 4915330,
10894 ivory: 16777200,
10895 khaki: 15787660,
10896 lavender: 15132410,
10897 lavenderblush: 16773365,
10898 lawngreen: 8190976,
10899 lemonchiffon: 16775885,
10900 lightblue: 11393254,
10901 lightcoral: 15761536,
10902 lightcyan: 14745599,
10903 lightgoldenrodyellow: 16448210,
10904 lightgray: 13882323,
10905 lightgreen: 9498256,
10906 lightgrey: 13882323,
10907 lightpink: 16758465,
10908 lightsalmon: 16752762,
10909 lightseagreen: 2142890,
10910 lightskyblue: 8900346,
10911 lightslategray: 7833753,
10912 lightslategrey: 7833753,
10913 lightsteelblue: 11584734,
10914 lightyellow: 16777184,
10915 lime: 65280,
10916 limegreen: 3329330,
10917 linen: 16445670,
10918 magenta: 16711935,
10919 maroon: 8388608,
10920 mediumaquamarine: 6737322,
10921 mediumblue: 205,
10922 mediumorchid: 12211667,
10923 mediumpurple: 9662683,
10924 mediumseagreen: 3978097,
10925 mediumslateblue: 8087790,
10926 mediumspringgreen: 64154,
10927 mediumturquoise: 4772300,
10928 mediumvioletred: 13047173,
10929 midnightblue: 1644912,
10930 mintcream: 16121850,
10931 mistyrose: 16770273,
10932 moccasin: 16770229,
10933 navajowhite: 16768685,
10934 navy: 128,
10935 oldlace: 16643558,
10936 olive: 8421376,
10937 olivedrab: 7048739,
10938 orange: 16753920,
10939 orangered: 16729344,
10940 orchid: 14315734,
10941 palegoldenrod: 15657130,
10942 palegreen: 10025880,
10943 paleturquoise: 11529966,
10944 palevioletred: 14381203,
10945 papayawhip: 16773077,
10946 peachpuff: 16767673,
10947 peru: 13468991,
10948 pink: 16761035,
10949 plum: 14524637,
10950 powderblue: 11591910,
10951 purple: 8388736,
10952 rebeccapurple: 6697881,
10953 red: 16711680,
10954 rosybrown: 12357519,
10955 royalblue: 4286945,
10956 saddlebrown: 9127187,
10957 salmon: 16416882,
10958 sandybrown: 16032864,
10959 seagreen: 3050327,
10960 seashell: 16774638,
10961 sienna: 10506797,
10962 silver: 12632256,
10963 skyblue: 8900331,
10964 slateblue: 6970061,
10965 slategray: 7372944,
10966 slategrey: 7372944,
10967 snow: 16775930,
10968 springgreen: 65407,
10969 steelblue: 4620980,
10970 tan: 13808780,
10971 teal: 32896,
10972 thistle: 14204888,
10973 tomato: 16737095,
10974 turquoise: 4251856,
10975 violet: 15631086,
10976 wheat: 16113331,
10977 white: 16777215,
10978 whitesmoke: 16119285,
10979 yellow: 16776960,
10980 yellowgreen: 10145074
10981 });
10982 d3_rgb_names.forEach(function(key, value) {
10983 d3_rgb_names.set(key, d3_rgbNumber(value));
10984 });
10985 function d3_functor(v) {
10986 return typeof v === "function" ? v : function() {
10987 return v;
10988 };
10989 }
10990 d3.functor = d3_functor;
10991 d3.xhr = d3_xhrType(d3_identity);
10992 function d3_xhrType(response) {
10993 return function(url, mimeType, callback) {
10994 if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
10995 mimeType = null;
10996 return d3_xhr(url, mimeType, response, callback);
10997 };
10998 }
10999 function d3_xhr(url, mimeType, response, callback) {
11000 var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
11001 if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
11002 "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
11003 request.readyState > 3 && respond();
11004 };
11005 function respond() {
11006 var status = request.status, result;
11007 if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
11008 try {
11009 result = response.call(xhr, request);
11010 } catch (e) {
11011 dispatch.error.call(xhr, e);
11012 return;
11013 }
11014 dispatch.load.call(xhr, result);
11015 } else {
11016 dispatch.error.call(xhr, request);
11017 }
11018 }
11019 request.onprogress = function(event) {
11020 var o = d3.event;
11021 d3.event = event;
11022 try {
11023 dispatch.progress.call(xhr, request);
11024 } finally {
11025 d3.event = o;
11026 }
11027 };
11028 xhr.header = function(name, value) {
11029 name = (name + "").toLowerCase();
11030 if (arguments.length < 2) return headers[name];
11031 if (value == null) delete headers[name]; else headers[name] = value + "";
11032 return xhr;
11033 };
11034 xhr.mimeType = function(value) {
11035 if (!arguments.length) return mimeType;
11036 mimeType = value == null ? null : value + "";
11037 return xhr;
11038 };
11039 xhr.responseType = function(value) {
11040 if (!arguments.length) return responseType;
11041 responseType = value;
11042 return xhr;
11043 };
11044 xhr.response = function(value) {
11045 response = value;
11046 return xhr;
11047 };
11048 [ "get", "post" ].forEach(function(method) {
11049 xhr[method] = function() {
11050 return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
11051 };
11052 });
11053 xhr.send = function(method, data, callback) {
11054 if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
11055 request.open(method, url, true);
11056 if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
11057 if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
11058 if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
11059 if (responseType != null) request.responseType = responseType;
11060 if (callback != null) xhr.on("error", callback).on("load", function(request) {
11061 callback(null, request);
11062 });
11063 dispatch.beforesend.call(xhr, request);
11064 request.send(data == null ? null : data);
11065 return xhr;
11066 };
11067 xhr.abort = function() {
11068 request.abort();
11069 return xhr;
11070 };
11071 d3.rebind(xhr, dispatch, "on");
11072 return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
11073 }
11074 function d3_xhr_fixCallback(callback) {
11075 return callback.length === 1 ? function(error, request) {
11076 callback(error == null ? request : null);
11077 } : callback;
11078 }
11079 function d3_xhrHasResponse(request) {
11080 var type = request.responseType;
11081 return type && type !== "text" ? request.response : request.responseText;
11082 }
11083 d3.dsv = function(delimiter, mimeType) {
11084 var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
11085 function dsv(url, row, callback) {
11086 if (arguments.length < 3) callback = row, row = null;
11087 var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
11088 xhr.row = function(_) {
11089 return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
11090 };
11091 return xhr;
11092 }
11093 function response(request) {
11094 return dsv.parse(request.responseText);
11095 }
11096 function typedResponse(f) {
11097 return function(request) {
11098 return dsv.parse(request.responseText, f);
11099 };
11100 }
11101 dsv.parse = function(text, f) {
11102 var o;
11103 return dsv.parseRows(text, function(row, i) {
11104 if (o) return o(row, i - 1);
11105 var a = new Function("d", "return {" + row.map(function(name, i) {
11106 return JSON.stringify(name) + ": d[" + i + "]";
11107 }).join(",") + "}");
11108 o = f ? function(row, i) {
11109 return f(a(row), i);
11110 } : a;
11111 });
11112 };
11113 dsv.parseRows = function(text, f) {
11114 var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
11115 function token() {
11116 if (I >= N) return EOF;
11117 if (eol) return eol = false, EOL;
11118 var j = I;
11119 if (text.charCodeAt(j) === 34) {
11120 var i = j;
11121 while (i++ < N) {
11122 if (text.charCodeAt(i) === 34) {
11123 if (text.charCodeAt(i + 1) !== 34) break;
11124 ++i;
11125 }
11126 }
11127 I = i + 2;
11128 var c = text.charCodeAt(i + 1);
11129 if (c === 13) {
11130 eol = true;
11131 if (text.charCodeAt(i + 2) === 10) ++I;
11132 } else if (c === 10) {
11133 eol = true;
11134 }
11135 return text.slice(j + 1, i).replace(/""/g, '"');
11136 }
11137 while (I < N) {
11138 var c = text.charCodeAt(I++), k = 1;
11139 if (c === 10) eol = true; else if (c === 13) {
11140 eol = true;
11141 if (text.charCodeAt(I) === 10) ++I, ++k;
11142 } else if (c !== delimiterCode) continue;
11143 return text.slice(j, I - k);
11144 }
11145 return text.slice(j);
11146 }
11147 while ((t = token()) !== EOF) {
11148 var a = [];
11149 while (t !== EOL && t !== EOF) {
11150 a.push(t);
11151 t = token();
11152 }
11153 if (f && (a = f(a, n++)) == null) continue;
11154 rows.push(a);
11155 }
11156 return rows;
11157 };
11158 dsv.format = function(rows) {
11159 if (Array.isArray(rows[0])) return dsv.formatRows(rows);
11160 var fieldSet = new d3_Set(), fields = [];
11161 rows.forEach(function(row) {
11162 for (var field in row) {
11163 if (!fieldSet.has(field)) {
11164 fields.push(fieldSet.add(field));
11165 }
11166 }
11167 });
11168 return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
11169 return fields.map(function(field) {
11170 return formatValue(row[field]);
11171 }).join(delimiter);
11172 })).join("\n");
11173 };
11174 dsv.formatRows = function(rows) {
11175 return rows.map(formatRow).join("\n");
11176 };
11177 function formatRow(row) {
11178 return row.map(formatValue).join(delimiter);
11179 }
11180 function formatValue(text) {
11181 return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
11182 }
11183 return dsv;
11184 };
11185 d3.csv = d3.dsv(",", "text/csv");
11186 d3.tsv = d3.dsv(" ", "text/tab-separated-values");
11187 var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
11188 setTimeout(callback, 17);
11189 };
11190 d3.timer = function() {
11191 d3_timer.apply(this, arguments);
11192 };
11193 function d3_timer(callback, delay, then) {
11194 var n = arguments.length;
11195 if (n < 2) delay = 0;
11196 if (n < 3) then = Date.now();
11197 var time = then + delay, timer = {
11198 c: callback,
11199 t: time,
11200 n: null
11201 };
11202 if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
11203 d3_timer_queueTail = timer;
11204 if (!d3_timer_interval) {
11205 d3_timer_timeout = clearTimeout(d3_timer_timeout);
11206 d3_timer_interval = 1;
11207 d3_timer_frame(d3_timer_step);
11208 }
11209 return timer;
11210 }
11211 function d3_timer_step() {
11212 var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
11213 if (delay > 24) {
11214 if (isFinite(delay)) {
11215 clearTimeout(d3_timer_timeout);
11216 d3_timer_timeout = setTimeout(d3_timer_step, delay);
11217 }
11218 d3_timer_interval = 0;
11219 } else {
11220 d3_timer_interval = 1;
11221 d3_timer_frame(d3_timer_step);
11222 }
11223 }
11224 d3.timer.flush = function() {
11225 d3_timer_mark();
11226 d3_timer_sweep();
11227 };
11228 function d3_timer_mark() {
11229 var now = Date.now(), timer = d3_timer_queueHead;
11230 while (timer) {
11231 if (now >= timer.t && timer.c(now - timer.t)) timer.c = null;
11232 timer = timer.n;
11233 }
11234 return now;
11235 }
11236 function d3_timer_sweep() {
11237 var t0, t1 = d3_timer_queueHead, time = Infinity;
11238 while (t1) {
11239 if (t1.c) {
11240 if (t1.t < time) time = t1.t;
11241 t1 = (t0 = t1).n;
11242 } else {
11243 t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
11244 }
11245 }
11246 d3_timer_queueTail = t0;
11247 return time;
11248 }
11249 function d3_format_precision(x, p) {
11250 return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
11251 }
11252 d3.round = function(x, n) {
11253 return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
11254 };
11255 var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
11256 d3.formatPrefix = function(value, precision) {
11257 var i = 0;
11258 if (value = +value) {
11259 if (value < 0) value *= -1;
11260 if (precision) value = d3.round(value, d3_format_precision(value, precision));
11261 i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
11262 i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
11263 }
11264 return d3_formatPrefixes[8 + i / 3];
11265 };
11266 function d3_formatPrefix(d, i) {
11267 var k = Math.pow(10, abs(8 - i) * 3);
11268 return {
11269 scale: i > 8 ? function(d) {
11270 return d / k;
11271 } : function(d) {
11272 return d * k;
11273 },
11274 symbol: d
11275 };
11276 }
11277 function d3_locale_numberFormat(locale) {
11278 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) {
11279 var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
11280 while (i > 0 && g > 0) {
11281 if (length + g + 1 > width) g = Math.max(1, width - length);
11282 t.push(value.substring(i -= g, i + g));
11283 if ((length += g + 1) > width) break;
11284 g = locale_grouping[j = (j + 1) % locale_grouping.length];
11285 }
11286 return t.reverse().join(locale_thousands);
11287 } : d3_identity;
11288 return function(specifier) {
11289 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;
11290 if (precision) precision = +precision.substring(1);
11291 if (zfill || fill === "0" && align === "=") {
11292 zfill = fill = "0";
11293 align = "=";
11294 }
11295 switch (type) {
11296 case "n":
11297 comma = true;
11298 type = "g";
11299 break;
11300
11301 case "%":
11302 scale = 100;
11303 suffix = "%";
11304 type = "f";
11305 break;
11306
11307 case "p":
11308 scale = 100;
11309 suffix = "%";
11310 type = "r";
11311 break;
11312
11313 case "b":
11314 case "o":
11315 case "x":
11316 case "X":
11317 if (symbol === "#") prefix = "0" + type.toLowerCase();
11318
11319 case "c":
11320 exponent = false;
11321
11322 case "d":
11323 integer = true;
11324 precision = 0;
11325 break;
11326
11327 case "s":
11328 scale = -1;
11329 type = "r";
11330 break;
11331 }
11332 if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
11333 if (type == "r" && !precision) type = "g";
11334 if (precision != null) {
11335 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));
11336 }
11337 type = d3_format_types.get(type) || d3_format_typeDefault;
11338 var zcomma = zfill && comma;
11339 return function(value) {
11340 var fullSuffix = suffix;
11341 if (integer && value % 1) return "";
11342 var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
11343 if (scale < 0) {
11344 var unit = d3.formatPrefix(value, precision);
11345 value = unit.scale(value);
11346 fullSuffix = unit.symbol + suffix;
11347 } else {
11348 value *= scale;
11349 }
11350 value = type(value, precision);
11351 var i = value.lastIndexOf("."), before, after;
11352 if (i < 0) {
11353 var j = exponent ? value.lastIndexOf("e") : -1;
11354 if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
11355 } else {
11356 before = value.substring(0, i);
11357 after = locale_decimal + value.substring(i + 1);
11358 }
11359 if (!zfill && comma) before = formatGroup(before, Infinity);
11360 var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
11361 if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
11362 negative += prefix;
11363 value = before + after;
11364 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;
11365 };
11366 };
11367 }
11368 var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
11369 var d3_format_types = d3.map({
11370 b: function(x) {
11371 return x.toString(2);
11372 },
11373 c: function(x) {
11374 return String.fromCharCode(x);
11375 },
11376 o: function(x) {
11377 return x.toString(8);
11378 },
11379 x: function(x) {
11380 return x.toString(16);
11381 },
11382 X: function(x) {
11383 return x.toString(16).toUpperCase();
11384 },
11385 g: function(x, p) {
11386 return x.toPrecision(p);
11387 },
11388 e: function(x, p) {
11389 return x.toExponential(p);
11390 },
11391 f: function(x, p) {
11392 return x.toFixed(p);
11393 },
11394 r: function(x, p) {
11395 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))));
11396 }
11397 });
11398 function d3_format_typeDefault(x) {
11399 return x + "";
11400 }
11401 var d3_time = d3.time = {}, d3_date = Date;
11402 function d3_date_utc() {
11403 this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
11404 }
11405 d3_date_utc.prototype = {
11406 getDate: function() {
11407 return this._.getUTCDate();
11408 },
11409 getDay: function() {
11410 return this._.getUTCDay();
11411 },
11412 getFullYear: function() {
11413 return this._.getUTCFullYear();
11414 },
11415 getHours: function() {
11416 return this._.getUTCHours();
11417 },
11418 getMilliseconds: function() {
11419 return this._.getUTCMilliseconds();
11420 },
11421 getMinutes: function() {
11422 return this._.getUTCMinutes();
11423 },
11424 getMonth: function() {
11425 return this._.getUTCMonth();
11426 },
11427 getSeconds: function() {
11428 return this._.getUTCSeconds();
11429 },
11430 getTime: function() {
11431 return this._.getTime();
11432 },
11433 getTimezoneOffset: function() {
11434 return 0;
11435 },
11436 valueOf: function() {
11437 return this._.valueOf();
11438 },
11439 setDate: function() {
11440 d3_time_prototype.setUTCDate.apply(this._, arguments);
11441 },
11442 setDay: function() {
11443 d3_time_prototype.setUTCDay.apply(this._, arguments);
11444 },
11445 setFullYear: function() {
11446 d3_time_prototype.setUTCFullYear.apply(this._, arguments);
11447 },
11448 setHours: function() {
11449 d3_time_prototype.setUTCHours.apply(this._, arguments);
11450 },
11451 setMilliseconds: function() {
11452 d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
11453 },
11454 setMinutes: function() {
11455 d3_time_prototype.setUTCMinutes.apply(this._, arguments);
11456 },
11457 setMonth: function() {
11458 d3_time_prototype.setUTCMonth.apply(this._, arguments);
11459 },
11460 setSeconds: function() {
11461 d3_time_prototype.setUTCSeconds.apply(this._, arguments);
11462 },
11463 setTime: function() {
11464 d3_time_prototype.setTime.apply(this._, arguments);
11465 }
11466 };
11467 var d3_time_prototype = Date.prototype;
11468 function d3_time_interval(local, step, number) {
11469 function round(date) {
11470 var d0 = local(date), d1 = offset(d0, 1);
11471 return date - d0 < d1 - date ? d0 : d1;
11472 }
11473 function ceil(date) {
11474 step(date = local(new d3_date(date - 1)), 1);
11475 return date;
11476 }
11477 function offset(date, k) {
11478 step(date = new d3_date(+date), k);
11479 return date;
11480 }
11481 function range(t0, t1, dt) {
11482 var time = ceil(t0), times = [];
11483 if (dt > 1) {
11484 while (time < t1) {
11485 if (!(number(time) % dt)) times.push(new Date(+time));
11486 step(time, 1);
11487 }
11488 } else {
11489 while (time < t1) times.push(new Date(+time)), step(time, 1);
11490 }
11491 return times;
11492 }
11493 function range_utc(t0, t1, dt) {
11494 try {
11495 d3_date = d3_date_utc;
11496 var utc = new d3_date_utc();
11497 utc._ = t0;
11498 return range(utc, t1, dt);
11499 } finally {
11500 d3_date = Date;
11501 }
11502 }
11503 local.floor = local;
11504 local.round = round;
11505 local.ceil = ceil;
11506 local.offset = offset;
11507 local.range = range;
11508 var utc = local.utc = d3_time_interval_utc(local);
11509 utc.floor = utc;
11510 utc.round = d3_time_interval_utc(round);
11511 utc.ceil = d3_time_interval_utc(ceil);
11512 utc.offset = d3_time_interval_utc(offset);
11513 utc.range = range_utc;
11514 return local;
11515 }
11516 function d3_time_interval_utc(method) {
11517 return function(date, k) {
11518 try {
11519 d3_date = d3_date_utc;
11520 var utc = new d3_date_utc();
11521 utc._ = date;
11522 return method(utc, k)._;
11523 } finally {
11524 d3_date = Date;
11525 }
11526 };
11527 }
11528 d3_time.year = d3_time_interval(function(date) {
11529 date = d3_time.day(date);
11530 date.setMonth(0, 1);
11531 return date;
11532 }, function(date, offset) {
11533 date.setFullYear(date.getFullYear() + offset);
11534 }, function(date) {
11535 return date.getFullYear();
11536 });
11537 d3_time.years = d3_time.year.range;
11538 d3_time.years.utc = d3_time.year.utc.range;
11539 d3_time.day = d3_time_interval(function(date) {
11540 var day = new d3_date(2e3, 0);
11541 day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
11542 return day;
11543 }, function(date, offset) {
11544 date.setDate(date.getDate() + offset);
11545 }, function(date) {
11546 return date.getDate() - 1;
11547 });
11548 d3_time.days = d3_time.day.range;
11549 d3_time.days.utc = d3_time.day.utc.range;
11550 d3_time.dayOfYear = function(date) {
11551 var year = d3_time.year(date);
11552 return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
11553 };
11554 [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
11555 i = 7 - i;
11556 var interval = d3_time[day] = d3_time_interval(function(date) {
11557 (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
11558 return date;
11559 }, function(date, offset) {
11560 date.setDate(date.getDate() + Math.floor(offset) * 7);
11561 }, function(date) {
11562 var day = d3_time.year(date).getDay();
11563 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
11564 });
11565 d3_time[day + "s"] = interval.range;
11566 d3_time[day + "s"].utc = interval.utc.range;
11567 d3_time[day + "OfYear"] = function(date) {
11568 var day = d3_time.year(date).getDay();
11569 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
11570 };
11571 });
11572 d3_time.week = d3_time.sunday;
11573 d3_time.weeks = d3_time.sunday.range;
11574 d3_time.weeks.utc = d3_time.sunday.utc.range;
11575 d3_time.weekOfYear = d3_time.sundayOfYear;
11576 function d3_locale_timeFormat(locale) {
11577 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;
11578 function d3_time_format(template) {
11579 var n = template.length;
11580 function format(date) {
11581 var string = [], i = -1, j = 0, c, p, f;
11582 while (++i < n) {
11583 if (template.charCodeAt(i) === 37) {
11584 string.push(template.slice(j, i));
11585 if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
11586 if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
11587 string.push(c);
11588 j = i + 1;
11589 }
11590 }
11591 string.push(template.slice(j, i));
11592 return string.join("");
11593 }
11594 format.parse = function(string) {
11595 var d = {
11596 y: 1900,
11597 m: 0,
11598 d: 1,
11599 H: 0,
11600 M: 0,
11601 S: 0,
11602 L: 0,
11603 Z: null
11604 }, i = d3_time_parse(d, template, string, 0);
11605 if (i != string.length) return null;
11606 if ("p" in d) d.H = d.H % 12 + d.p * 12;
11607 var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
11608 if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("W" in d || "U" in d) {
11609 if (!("w" in d)) d.w = "W" in d ? 1 : 0;
11610 date.setFullYear(d.y, 0, 1);
11611 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);
11612 } else date.setFullYear(d.y, d.m, d.d);
11613 date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
11614 return localZ ? date._ : date;
11615 };
11616 format.toString = function() {
11617 return template;
11618 };
11619 return format;
11620 }
11621 function d3_time_parse(date, template, string, j) {
11622 var c, p, t, i = 0, n = template.length, m = string.length;
11623 while (i < n) {
11624 if (j >= m) return -1;
11625 c = template.charCodeAt(i++);
11626 if (c === 37) {
11627 t = template.charAt(i++);
11628 p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
11629 if (!p || (j = p(date, string, j)) < 0) return -1;
11630 } else if (c != string.charCodeAt(j++)) {
11631 return -1;
11632 }
11633 }
11634 return j;
11635 }
11636 d3_time_format.utc = function(template) {
11637 var local = d3_time_format(template);
11638 function format(date) {
11639 try {
11640 d3_date = d3_date_utc;
11641 var utc = new d3_date();
11642 utc._ = date;
11643 return local(utc);
11644 } finally {
11645 d3_date = Date;
11646 }
11647 }
11648 format.parse = function(string) {
11649 try {
11650 d3_date = d3_date_utc;
11651 var date = local.parse(string);
11652 return date && date._;
11653 } finally {
11654 d3_date = Date;
11655 }
11656 };
11657 format.toString = local.toString;
11658 return format;
11659 };
11660 d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
11661 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);
11662 locale_periods.forEach(function(p, i) {
11663 d3_time_periodLookup.set(p.toLowerCase(), i);
11664 });
11665 var d3_time_formats = {
11666 a: function(d) {
11667 return locale_shortDays[d.getDay()];
11668 },
11669 A: function(d) {
11670 return locale_days[d.getDay()];
11671 },
11672 b: function(d) {
11673 return locale_shortMonths[d.getMonth()];
11674 },
11675 B: function(d) {
11676 return locale_months[d.getMonth()];
11677 },
11678 c: d3_time_format(locale_dateTime),
11679 d: function(d, p) {
11680 return d3_time_formatPad(d.getDate(), p, 2);
11681 },
11682 e: function(d, p) {
11683 return d3_time_formatPad(d.getDate(), p, 2);
11684 },
11685 H: function(d, p) {
11686 return d3_time_formatPad(d.getHours(), p, 2);
11687 },
11688 I: function(d, p) {
11689 return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
11690 },
11691 j: function(d, p) {
11692 return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
11693 },
11694 L: function(d, p) {
11695 return d3_time_formatPad(d.getMilliseconds(), p, 3);
11696 },
11697 m: function(d, p) {
11698 return d3_time_formatPad(d.getMonth() + 1, p, 2);
11699 },
11700 M: function(d, p) {
11701 return d3_time_formatPad(d.getMinutes(), p, 2);
11702 },
11703 p: function(d) {
11704 return locale_periods[+(d.getHours() >= 12)];
11705 },
11706 S: function(d, p) {
11707 return d3_time_formatPad(d.getSeconds(), p, 2);
11708 },
11709 U: function(d, p) {
11710 return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
11711 },
11712 w: function(d) {
11713 return d.getDay();
11714 },
11715 W: function(d, p) {
11716 return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
11717 },
11718 x: d3_time_format(locale_date),
11719 X: d3_time_format(locale_time),
11720 y: function(d, p) {
11721 return d3_time_formatPad(d.getFullYear() % 100, p, 2);
11722 },
11723 Y: function(d, p) {
11724 return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
11725 },
11726 Z: d3_time_zone,
11727 "%": function() {
11728 return "%";
11729 }
11730 };
11731 var d3_time_parsers = {
11732 a: d3_time_parseWeekdayAbbrev,
11733 A: d3_time_parseWeekday,
11734 b: d3_time_parseMonthAbbrev,
11735 B: d3_time_parseMonth,
11736 c: d3_time_parseLocaleFull,
11737 d: d3_time_parseDay,
11738 e: d3_time_parseDay,
11739 H: d3_time_parseHour24,
11740 I: d3_time_parseHour24,
11741 j: d3_time_parseDayOfYear,
11742 L: d3_time_parseMilliseconds,
11743 m: d3_time_parseMonthNumber,
11744 M: d3_time_parseMinutes,
11745 p: d3_time_parseAmPm,
11746 S: d3_time_parseSeconds,
11747 U: d3_time_parseWeekNumberSunday,
11748 w: d3_time_parseWeekdayNumber,
11749 W: d3_time_parseWeekNumberMonday,
11750 x: d3_time_parseLocaleDate,
11751 X: d3_time_parseLocaleTime,
11752 y: d3_time_parseYear,
11753 Y: d3_time_parseFullYear,
11754 Z: d3_time_parseZone,
11755 "%": d3_time_parseLiteralPercent
11756 };
11757 function d3_time_parseWeekdayAbbrev(date, string, i) {
11758 d3_time_dayAbbrevRe.lastIndex = 0;
11759 var n = d3_time_dayAbbrevRe.exec(string.slice(i));
11760 return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
11761 }
11762 function d3_time_parseWeekday(date, string, i) {
11763 d3_time_dayRe.lastIndex = 0;
11764 var n = d3_time_dayRe.exec(string.slice(i));
11765 return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
11766 }
11767 function d3_time_parseMonthAbbrev(date, string, i) {
11768 d3_time_monthAbbrevRe.lastIndex = 0;
11769 var n = d3_time_monthAbbrevRe.exec(string.slice(i));
11770 return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
11771 }
11772 function d3_time_parseMonth(date, string, i) {
11773 d3_time_monthRe.lastIndex = 0;
11774 var n = d3_time_monthRe.exec(string.slice(i));
11775 return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
11776 }
11777 function d3_time_parseLocaleFull(date, string, i) {
11778 return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
11779 }
11780 function d3_time_parseLocaleDate(date, string, i) {
11781 return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
11782 }
11783 function d3_time_parseLocaleTime(date, string, i) {
11784 return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
11785 }
11786 function d3_time_parseAmPm(date, string, i) {
11787 var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
11788 return n == null ? -1 : (date.p = n, i);
11789 }
11790 return d3_time_format;
11791 }
11792 var d3_time_formatPads = {
11793 "-": "",
11794 _: " ",
11795 "0": "0"
11796 }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
11797 function d3_time_formatPad(value, fill, width) {
11798 var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
11799 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
11800 }
11801 function d3_time_formatRe(names) {
11802 return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
11803 }
11804 function d3_time_formatLookup(names) {
11805 var map = new d3_Map(), i = -1, n = names.length;
11806 while (++i < n) map.set(names[i].toLowerCase(), i);
11807 return map;
11808 }
11809 function d3_time_parseWeekdayNumber(date, string, i) {
11810 d3_time_numberRe.lastIndex = 0;
11811 var n = d3_time_numberRe.exec(string.slice(i, i + 1));
11812 return n ? (date.w = +n[0], i + n[0].length) : -1;
11813 }
11814 function d3_time_parseWeekNumberSunday(date, string, i) {
11815 d3_time_numberRe.lastIndex = 0;
11816 var n = d3_time_numberRe.exec(string.slice(i));
11817 return n ? (date.U = +n[0], i + n[0].length) : -1;
11818 }
11819 function d3_time_parseWeekNumberMonday(date, string, i) {
11820 d3_time_numberRe.lastIndex = 0;
11821 var n = d3_time_numberRe.exec(string.slice(i));
11822 return n ? (date.W = +n[0], i + n[0].length) : -1;
11823 }
11824 function d3_time_parseFullYear(date, string, i) {
11825 d3_time_numberRe.lastIndex = 0;
11826 var n = d3_time_numberRe.exec(string.slice(i, i + 4));
11827 return n ? (date.y = +n[0], i + n[0].length) : -1;
11828 }
11829 function d3_time_parseYear(date, string, i) {
11830 d3_time_numberRe.lastIndex = 0;
11831 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
11832 return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
11833 }
11834 function d3_time_parseZone(date, string, i) {
11835 return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
11836 i + 5) : -1;
11837 }
11838 function d3_time_expandYear(d) {
11839 return d + (d > 68 ? 1900 : 2e3);
11840 }
11841 function d3_time_parseMonthNumber(date, string, i) {
11842 d3_time_numberRe.lastIndex = 0;
11843 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
11844 return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
11845 }
11846 function d3_time_parseDay(date, string, i) {
11847 d3_time_numberRe.lastIndex = 0;
11848 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
11849 return n ? (date.d = +n[0], i + n[0].length) : -1;
11850 }
11851 function d3_time_parseDayOfYear(date, string, i) {
11852 d3_time_numberRe.lastIndex = 0;
11853 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
11854 return n ? (date.j = +n[0], i + n[0].length) : -1;
11855 }
11856 function d3_time_parseHour24(date, string, i) {
11857 d3_time_numberRe.lastIndex = 0;
11858 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
11859 return n ? (date.H = +n[0], i + n[0].length) : -1;
11860 }
11861 function d3_time_parseMinutes(date, string, i) {
11862 d3_time_numberRe.lastIndex = 0;
11863 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
11864 return n ? (date.M = +n[0], i + n[0].length) : -1;
11865 }
11866 function d3_time_parseSeconds(date, string, i) {
11867 d3_time_numberRe.lastIndex = 0;
11868 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
11869 return n ? (date.S = +n[0], i + n[0].length) : -1;
11870 }
11871 function d3_time_parseMilliseconds(date, string, i) {
11872 d3_time_numberRe.lastIndex = 0;
11873 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
11874 return n ? (date.L = +n[0], i + n[0].length) : -1;
11875 }
11876 function d3_time_zone(d) {
11877 var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
11878 return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
11879 }
11880 function d3_time_parseLiteralPercent(date, string, i) {
11881 d3_time_percentRe.lastIndex = 0;
11882 var n = d3_time_percentRe.exec(string.slice(i, i + 1));
11883 return n ? i + n[0].length : -1;
11884 }
11885 function d3_time_formatMulti(formats) {
11886 var n = formats.length, i = -1;
11887 while (++i < n) formats[i][0] = this(formats[i][0]);
11888 return function(date) {
11889 var i = 0, f = formats[i];
11890 while (!f[1](date)) f = formats[++i];
11891 return f[0](date);
11892 };
11893 }
11894 d3.locale = function(locale) {
11895 return {
11896 numberFormat: d3_locale_numberFormat(locale),
11897 timeFormat: d3_locale_timeFormat(locale)
11898 };
11899 };
11900 var d3_locale_enUS = d3.locale({
11901 decimal: ".",
11902 thousands: ",",
11903 grouping: [ 3 ],
11904 currency: [ "$", "" ],
11905 dateTime: "%a %b %e %X %Y",
11906 date: "%m/%d/%Y",
11907 time: "%H:%M:%S",
11908 periods: [ "AM", "PM" ],
11909 days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
11910 shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
11911 months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
11912 shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
11913 });
11914 d3.format = d3_locale_enUS.numberFormat;
11915 d3.geo = {};
11916 function d3_adder() {}
11917 d3_adder.prototype = {
11918 s: 0,
11919 t: 0,
11920 add: function(y) {
11921 d3_adderSum(y, this.t, d3_adderTemp);
11922 d3_adderSum(d3_adderTemp.s, this.s, this);
11923 if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
11924 },
11925 reset: function() {
11926 this.s = this.t = 0;
11927 },
11928 valueOf: function() {
11929 return this.s;
11930 }
11931 };
11932 var d3_adderTemp = new d3_adder();
11933 function d3_adderSum(a, b, o) {
11934 var x = o.s = a + b, bv = x - a, av = x - bv;
11935 o.t = a - av + (b - bv);
11936 }
11937 d3.geo.stream = function(object, listener) {
11938 if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
11939 d3_geo_streamObjectType[object.type](object, listener);
11940 } else {
11941 d3_geo_streamGeometry(object, listener);
11942 }
11943 };
11944 function d3_geo_streamGeometry(geometry, listener) {
11945 if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
11946 d3_geo_streamGeometryType[geometry.type](geometry, listener);
11947 }
11948 }
11949 var d3_geo_streamObjectType = {
11950 Feature: function(feature, listener) {
11951 d3_geo_streamGeometry(feature.geometry, listener);
11952 },
11953 FeatureCollection: function(object, listener) {
11954 var features = object.features, i = -1, n = features.length;
11955 while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
11956 }
11957 };
11958 var d3_geo_streamGeometryType = {
11959 Sphere: function(object, listener) {
11960 listener.sphere();
11961 },
11962 Point: function(object, listener) {
11963 object = object.coordinates;
11964 listener.point(object[0], object[1], object[2]);
11965 },
11966 MultiPoint: function(object, listener) {
11967 var coordinates = object.coordinates, i = -1, n = coordinates.length;
11968 while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
11969 },
11970 LineString: function(object, listener) {
11971 d3_geo_streamLine(object.coordinates, listener, 0);
11972 },
11973 MultiLineString: function(object, listener) {
11974 var coordinates = object.coordinates, i = -1, n = coordinates.length;
11975 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
11976 },
11977 Polygon: function(object, listener) {
11978 d3_geo_streamPolygon(object.coordinates, listener);
11979 },
11980 MultiPolygon: function(object, listener) {
11981 var coordinates = object.coordinates, i = -1, n = coordinates.length;
11982 while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
11983 },
11984 GeometryCollection: function(object, listener) {
11985 var geometries = object.geometries, i = -1, n = geometries.length;
11986 while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
11987 }
11988 };
11989 function d3_geo_streamLine(coordinates, listener, closed) {
11990 var i = -1, n = coordinates.length - closed, coordinate;
11991 listener.lineStart();
11992 while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
11993 listener.lineEnd();
11994 }
11995 function d3_geo_streamPolygon(coordinates, listener) {
11996 var i = -1, n = coordinates.length;
11997 listener.polygonStart();
11998 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
11999 listener.polygonEnd();
12000 }
12001 d3.geo.area = function(object) {
12002 d3_geo_areaSum = 0;
12003 d3.geo.stream(object, d3_geo_area);
12004 return d3_geo_areaSum;
12005 };
12006 var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
12007 var d3_geo_area = {
12008 sphere: function() {
12009 d3_geo_areaSum += 4 * π;
12010 },
12011 point: d3_noop,
12012 lineStart: d3_noop,
12013 lineEnd: d3_noop,
12014 polygonStart: function() {
12015 d3_geo_areaRingSum.reset();
12016 d3_geo_area.lineStart = d3_geo_areaRingStart;
12017 },
12018 polygonEnd: function() {
12019 var area = 2 * d3_geo_areaRingSum;
12020 d3_geo_areaSum += area < 0 ? 4 * π + area : area;
12021 d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
12022 }
12023 };
12024 function d3_geo_areaRingStart() {
12025 var λ00, φ00, λ0, cosφ0, sinφ0;
12026 d3_geo_area.point = function(λ, φ) {
12027 d3_geo_area.point = nextPoint;
12028 λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
12029 sinφ0 = Math.sin(φ);
12030 };
12031 function nextPoint(λ, φ) {
12032 λ *= d3_radians;
12033 φ = φ * d3_radians / 2 + π / 4;
12034 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λ);
12035 d3_geo_areaRingSum.add(Math.atan2(v, u));
12036 λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
12037 }
12038 d3_geo_area.lineEnd = function() {
12039 nextPoint(λ00, φ00);
12040 };
12041 }
12042 function d3_geo_cartesian(spherical) {
12043 var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
12044 return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
12045 }
12046 function d3_geo_cartesianDot(a, b) {
12047 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
12048 }
12049 function d3_geo_cartesianCross(a, b) {
12050 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] ];
12051 }
12052 function d3_geo_cartesianAdd(a, b) {
12053 a[0] += b[0];
12054 a[1] += b[1];
12055 a[2] += b[2];
12056 }
12057 function d3_geo_cartesianScale(vector, k) {
12058 return [ vector[0] * k, vector[1] * k, vector[2] * k ];
12059 }
12060 function d3_geo_cartesianNormalize(d) {
12061 var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
12062 d[0] /= l;
12063 d[1] /= l;
12064 d[2] /= l;
12065 }
12066 function d3_geo_spherical(cartesian) {
12067 return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
12068 }
12069 function d3_geo_sphericalEqual(a, b) {
12070 return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
12071 }
12072 d3.geo.bounds = function() {
12073 var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
12074 var bound = {
12075 point: point,
12076 lineStart: lineStart,
12077 lineEnd: lineEnd,
12078 polygonStart: function() {
12079 bound.point = ringPoint;
12080 bound.lineStart = ringStart;
12081 bound.lineEnd = ringEnd;
12082 dλSum = 0;
12083 d3_geo_area.polygonStart();
12084 },
12085 polygonEnd: function() {
12086 d3_geo_area.polygonEnd();
12087 bound.point = point;
12088 bound.lineStart = lineStart;
12089 bound.lineEnd = lineEnd;
12090 if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
12091 range[0] = λ0, range[1] = λ1;
12092 }
12093 };
12094 function point(λ, φ) {
12095 ranges.push(range = [ λ0 = λ, λ1 = λ ]);
12096 if (φ < φ0) φ0 = φ;
12097 if (φ > φ1) φ1 = φ;
12098 }
12099 function linePoint(λ, φ) {
12100 var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
12101 if (p0) {
12102 var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
12103 d3_geo_cartesianNormalize(inflection);
12104 inflection = d3_geo_spherical(inflection);
12105 var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
12106 if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
12107 var φi = inflection[1] * d3_degrees;
12108 if (φi > φ1) φ1 = φi;
12109 } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
12110 var φi = -inflection[1] * d3_degrees;
12111 if (φi < φ0) φ0 = φi;
12112 } else {
12113 if (φ < φ0) φ0 = φ;
12114 if (φ > φ1) φ1 = φ;
12115 }
12116 if (antimeridian) {
12117 if (λ < λ_) {
12118 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
12119 } else {
12120 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
12121 }
12122 } else {
12123 if (λ1 >= λ0) {
12124 if (λ < λ0) λ0 = λ;
12125 if (λ > λ1) λ1 = λ;
12126 } else {
12127 if (λ > λ_) {
12128 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
12129 } else {
12130 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
12131 }
12132 }
12133 }
12134 } else {
12135 point(λ, φ);
12136 }
12137 p0 = p, λ_ = λ;
12138 }
12139 function lineStart() {
12140 bound.point = linePoint;
12141 }
12142 function lineEnd() {
12143 range[0] = λ0, range[1] = λ1;
12144 bound.point = point;
12145 p0 = null;
12146 }
12147 function ringPoint(λ, φ) {
12148 if (p0) {
12149 var dλ = λ - λ_;
12150 dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
12151 } else λ__ = λ, φ__ = φ;
12152 d3_geo_area.point(λ, φ);
12153 linePoint(λ, φ);
12154 }
12155 function ringStart() {
12156 d3_geo_area.lineStart();
12157 }
12158 function ringEnd() {
12159 ringPoint(λ__, φ__);
12160 d3_geo_area.lineEnd();
12161 if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
12162 range[0] = λ0, range[1] = λ1;
12163 p0 = null;
12164 }
12165 function angle(λ0, λ1) {
12166 return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
12167 }
12168 function compareRanges(a, b) {
12169 return a[0] - b[0];
12170 }
12171 function withinRange(x, range) {
12172 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
12173 }
12174 return function(feature) {
12175 φ1 = λ1 = -(λ0 = φ0 = Infinity);
12176 ranges = [];
12177 d3.geo.stream(feature, bound);
12178 var n = ranges.length;
12179 if (n) {
12180 ranges.sort(compareRanges);
12181 for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
12182 b = ranges[i];
12183 if (withinRange(b[0], a) || withinRange(b[1], a)) {
12184 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
12185 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
12186 } else {
12187 merged.push(a = b);
12188 }
12189 }
12190 var best = -Infinity, dλ;
12191 for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
12192 b = merged[i];
12193 if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
12194 }
12195 }
12196 ranges = range = null;
12197 return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
12198 };
12199 }();
12200 d3.geo.centroid = function(object) {
12201 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;
12202 d3.geo.stream(object, d3_geo_centroid);
12203 var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
12204 if (m < ε2) {
12205 x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
12206 if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
12207 m = x * x + y * y + z * z;
12208 if (m < ε2) return [ NaN, NaN ];
12209 }
12210 return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
12211 };
12212 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;
12213 var d3_geo_centroid = {
12214 sphere: d3_noop,
12215 point: d3_geo_centroidPoint,
12216 lineStart: d3_geo_centroidLineStart,
12217 lineEnd: d3_geo_centroidLineEnd,
12218 polygonStart: function() {
12219 d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
12220 },
12221 polygonEnd: function() {
12222 d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
12223 }
12224 };
12225 function d3_geo_centroidPoint(λ, φ) {
12226 λ *= d3_radians;
12227 var cosφ = Math.cos(φ *= d3_radians);
12228 d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
12229 }
12230 function d3_geo_centroidPointXYZ(x, y, z) {
12231 ++d3_geo_centroidW0;
12232 d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
12233 d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
12234 d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
12235 }
12236 function d3_geo_centroidLineStart() {
12237 var x0, y0, z0;
12238 d3_geo_centroid.point = function(λ, φ) {
12239 λ *= d3_radians;
12240 var cosφ = Math.cos(φ *= d3_radians);
12241 x0 = cosφ * Math.cos(λ);
12242 y0 = cosφ * Math.sin(λ);
12243 z0 = Math.sin(φ);
12244 d3_geo_centroid.point = nextPoint;
12245 d3_geo_centroidPointXYZ(x0, y0, z0);
12246 };
12247 function nextPoint(λ, φ) {
12248 λ *= d3_radians;
12249 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);
12250 d3_geo_centroidW1 += w;
12251 d3_geo_centroidX1 += w * (x0 + (x0 = x));
12252 d3_geo_centroidY1 += w * (y0 + (y0 = y));
12253 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
12254 d3_geo_centroidPointXYZ(x0, y0, z0);
12255 }
12256 }
12257 function d3_geo_centroidLineEnd() {
12258 d3_geo_centroid.point = d3_geo_centroidPoint;
12259 }
12260 function d3_geo_centroidRingStart() {
12261 var λ00, φ00, x0, y0, z0;
12262 d3_geo_centroid.point = function(λ, φ) {
12263 λ00 = λ, φ00 = φ;
12264 d3_geo_centroid.point = nextPoint;
12265 λ *= d3_radians;
12266 var cosφ = Math.cos(φ *= d3_radians);
12267 x0 = cosφ * Math.cos(λ);
12268 y0 = cosφ * Math.sin(λ);
12269 z0 = Math.sin(φ);
12270 d3_geo_centroidPointXYZ(x0, y0, z0);
12271 };
12272 d3_geo_centroid.lineEnd = function() {
12273 nextPoint(λ00, φ00);
12274 d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
12275 d3_geo_centroid.point = d3_geo_centroidPoint;
12276 };
12277 function nextPoint(λ, φ) {
12278 λ *= d3_radians;
12279 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);
12280 d3_geo_centroidX2 += v * cx;
12281 d3_geo_centroidY2 += v * cy;
12282 d3_geo_centroidZ2 += v * cz;
12283 d3_geo_centroidW1 += w;
12284 d3_geo_centroidX1 += w * (x0 + (x0 = x));
12285 d3_geo_centroidY1 += w * (y0 + (y0 = y));
12286 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
12287 d3_geo_centroidPointXYZ(x0, y0, z0);
12288 }
12289 }
12290 function d3_geo_compose(a, b) {
12291 function compose(x, y) {
12292 return x = a(x, y), b(x[0], x[1]);
12293 }
12294 if (a.invert && b.invert) compose.invert = function(x, y) {
12295 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
12296 };
12297 return compose;
12298 }
12299 function d3_true() {
12300 return true;
12301 }
12302 function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
12303 var subject = [], clip = [];
12304 segments.forEach(function(segment) {
12305 if ((n = segment.length - 1) <= 0) return;
12306 var n, p0 = segment[0], p1 = segment[n];
12307 if (d3_geo_sphericalEqual(p0, p1)) {
12308 listener.lineStart();
12309 for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
12310 listener.lineEnd();
12311 return;
12312 }
12313 var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
12314 a.o = b;
12315 subject.push(a);
12316 clip.push(b);
12317 a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
12318 b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
12319 a.o = b;
12320 subject.push(a);
12321 clip.push(b);
12322 });
12323 clip.sort(compare);
12324 d3_geo_clipPolygonLinkCircular(subject);
12325 d3_geo_clipPolygonLinkCircular(clip);
12326 if (!subject.length) return;
12327 for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
12328 clip[i].e = entry = !entry;
12329 }
12330 var start = subject[0], points, point;
12331 while (1) {
12332 var current = start, isSubject = true;
12333 while (current.v) if ((current = current.n) === start) return;
12334 points = current.z;
12335 listener.lineStart();
12336 do {
12337 current.v = current.o.v = true;
12338 if (current.e) {
12339 if (isSubject) {
12340 for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
12341 } else {
12342 interpolate(current.x, current.n.x, 1, listener);
12343 }
12344 current = current.n;
12345 } else {
12346 if (isSubject) {
12347 points = current.p.z;
12348 for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
12349 } else {
12350 interpolate(current.x, current.p.x, -1, listener);
12351 }
12352 current = current.p;
12353 }
12354 current = current.o;
12355 points = current.z;
12356 isSubject = !isSubject;
12357 } while (!current.v);
12358 listener.lineEnd();
12359 }
12360 }
12361 function d3_geo_clipPolygonLinkCircular(array) {
12362 if (!(n = array.length)) return;
12363 var n, i = 0, a = array[0], b;
12364 while (++i < n) {
12365 a.n = b = array[i];
12366 b.p = a;
12367 a = b;
12368 }
12369 a.n = b = array[0];
12370 b.p = a;
12371 }
12372 function d3_geo_clipPolygonIntersection(point, points, other, entry) {
12373 this.x = point;
12374 this.z = points;
12375 this.o = other;
12376 this.e = entry;
12377 this.v = false;
12378 this.n = this.p = null;
12379 }
12380 function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
12381 return function(rotate, listener) {
12382 var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
12383 var clip = {
12384 point: point,
12385 lineStart: lineStart,
12386 lineEnd: lineEnd,
12387 polygonStart: function() {
12388 clip.point = pointRing;
12389 clip.lineStart = ringStart;
12390 clip.lineEnd = ringEnd;
12391 segments = [];
12392 polygon = [];
12393 },
12394 polygonEnd: function() {
12395 clip.point = point;
12396 clip.lineStart = lineStart;
12397 clip.lineEnd = lineEnd;
12398 segments = d3.merge(segments);
12399 var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
12400 if (segments.length) {
12401 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
12402 d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
12403 } else if (clipStartInside) {
12404 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
12405 listener.lineStart();
12406 interpolate(null, null, 1, listener);
12407 listener.lineEnd();
12408 }
12409 if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
12410 segments = polygon = null;
12411 },
12412 sphere: function() {
12413 listener.polygonStart();
12414 listener.lineStart();
12415 interpolate(null, null, 1, listener);
12416 listener.lineEnd();
12417 listener.polygonEnd();
12418 }
12419 };
12420 function point(λ, φ) {
12421 var point = rotate(λ, φ);
12422 if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
12423 }
12424 function pointLine(λ, φ) {
12425 var point = rotate(λ, φ);
12426 line.point(point[0], point[1]);
12427 }
12428 function lineStart() {
12429 clip.point = pointLine;
12430 line.lineStart();
12431 }
12432 function lineEnd() {
12433 clip.point = point;
12434 line.lineEnd();
12435 }
12436 var segments;
12437 var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
12438 function pointRing(λ, φ) {
12439 ring.push([ λ, φ ]);
12440 var point = rotate(λ, φ);
12441 ringListener.point(point[0], point[1]);
12442 }
12443 function ringStart() {
12444 ringListener.lineStart();
12445 ring = [];
12446 }
12447 function ringEnd() {
12448 pointRing(ring[0][0], ring[0][1]);
12449 ringListener.lineEnd();
12450 var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
12451 ring.pop();
12452 polygon.push(ring);
12453 ring = null;
12454 if (!n) return;
12455 if (clean & 1) {
12456 segment = ringSegments[0];
12457 var n = segment.length - 1, i = -1, point;
12458 if (n > 0) {
12459 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
12460 listener.lineStart();
12461 while (++i < n) listener.point((point = segment[i])[0], point[1]);
12462 listener.lineEnd();
12463 }
12464 return;
12465 }
12466 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
12467 segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
12468 }
12469 return clip;
12470 };
12471 }
12472 function d3_geo_clipSegmentLength1(segment) {
12473 return segment.length > 1;
12474 }
12475 function d3_geo_clipBufferListener() {
12476 var lines = [], line;
12477 return {
12478 lineStart: function() {
12479 lines.push(line = []);
12480 },
12481 point: function(λ, φ) {
12482 line.push([ λ, φ ]);
12483 },
12484 lineEnd: d3_noop,
12485 buffer: function() {
12486 var buffer = lines;
12487 lines = [];
12488 line = null;
12489 return buffer;
12490 },
12491 rejoin: function() {
12492 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
12493 }
12494 };
12495 }
12496 function d3_geo_clipSort(a, b) {
12497 return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
12498 }
12499 var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
12500 function d3_geo_clipAntimeridianLine(listener) {
12501 var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
12502 return {
12503 lineStart: function() {
12504 listener.lineStart();
12505 clean = 1;
12506 },
12507 point: function(λ1, φ1) {
12508 var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
12509 if (abs(dλ - π) < ε) {
12510 listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
12511 listener.point(sλ0, φ0);
12512 listener.lineEnd();
12513 listener.lineStart();
12514 listener.point(sλ1, φ0);
12515 listener.point(λ1, φ0);
12516 clean = 0;
12517 } else if (sλ0 !== sλ1 && dλ >= π) {
12518 if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
12519 if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
12520 φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
12521 listener.point(sλ0, φ0);
12522 listener.lineEnd();
12523 listener.lineStart();
12524 listener.point(sλ1, φ0);
12525 clean = 0;
12526 }
12527 listener.point(λ0 = λ1, φ0 = φ1);
12528 sλ0 = sλ1;
12529 },
12530 lineEnd: function() {
12531 listener.lineEnd();
12532 λ0 = φ0 = NaN;
12533 },
12534 clean: function() {
12535 return 2 - clean;
12536 }
12537 };
12538 }
12539 function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
12540 var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
12541 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;
12542 }
12543 function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
12544 var φ;
12545 if (from == null) {
12546 φ = direction * halfπ;
12547 listener.point(-π, φ);
12548 listener.point(0, φ);
12549 listener.point(π, φ);
12550 listener.point(π, 0);
12551 listener.point(π, -φ);
12552 listener.point(0, -φ);
12553 listener.point(-π, -φ);
12554 listener.point(-π, 0);
12555 listener.point(-π, φ);
12556 } else if (abs(from[0] - to[0]) > ε) {
12557 var s = from[0] < to[0] ? π : -π;
12558 φ = direction * s / 2;
12559 listener.point(-s, φ);
12560 listener.point(0, φ);
12561 listener.point(s, φ);
12562 } else {
12563 listener.point(to[0], to[1]);
12564 }
12565 }
12566 function d3_geo_pointInPolygon(point, polygon) {
12567 var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
12568 d3_geo_areaRingSum.reset();
12569 for (var i = 0, n = polygon.length; i < n; ++i) {
12570 var ring = polygon[i], m = ring.length;
12571 if (!m) continue;
12572 var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
12573 while (true) {
12574 if (j === m) j = 0;
12575 point = ring[j];
12576 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φ;
12577 d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
12578 polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
12579 if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
12580 var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
12581 d3_geo_cartesianNormalize(arc);
12582 var intersection = d3_geo_cartesianCross(meridianNormal, arc);
12583 d3_geo_cartesianNormalize(intersection);
12584 var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
12585 if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
12586 winding += antimeridian ^ dλ >= 0 ? 1 : -1;
12587 }
12588 }
12589 if (!j++) break;
12590 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
12591 }
12592 }
12593 return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < -ε) ^ winding & 1;
12594 }
12595 function d3_geo_clipCircle(radius) {
12596 var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
12597 return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
12598 function visible(λ, φ) {
12599 return Math.cos(λ) * Math.cos(φ) > cr;
12600 }
12601 function clipLine(listener) {
12602 var point0, c0, v0, v00, clean;
12603 return {
12604 lineStart: function() {
12605 v00 = v0 = false;
12606 clean = 1;
12607 },
12608 point: function(λ, φ) {
12609 var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
12610 if (!point0 && (v00 = v0 = v)) listener.lineStart();
12611 if (v !== v0) {
12612 point2 = intersect(point0, point1);
12613 if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
12614 point1[0] += ε;
12615 point1[1] += ε;
12616 v = visible(point1[0], point1[1]);
12617 }
12618 }
12619 if (v !== v0) {
12620 clean = 0;
12621 if (v) {
12622 listener.lineStart();
12623 point2 = intersect(point1, point0);
12624 listener.point(point2[0], point2[1]);
12625 } else {
12626 point2 = intersect(point0, point1);
12627 listener.point(point2[0], point2[1]);
12628 listener.lineEnd();
12629 }
12630 point0 = point2;
12631 } else if (notHemisphere && point0 && smallRadius ^ v) {
12632 var t;
12633 if (!(c & c0) && (t = intersect(point1, point0, true))) {
12634 clean = 0;
12635 if (smallRadius) {
12636 listener.lineStart();
12637 listener.point(t[0][0], t[0][1]);
12638 listener.point(t[1][0], t[1][1]);
12639 listener.lineEnd();
12640 } else {
12641 listener.point(t[1][0], t[1][1]);
12642 listener.lineEnd();
12643 listener.lineStart();
12644 listener.point(t[0][0], t[0][1]);
12645 }
12646 }
12647 }
12648 if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
12649 listener.point(point1[0], point1[1]);
12650 }
12651 point0 = point1, v0 = v, c0 = c;
12652 },
12653 lineEnd: function() {
12654 if (v0) listener.lineEnd();
12655 point0 = null;
12656 },
12657 clean: function() {
12658 return clean | (v00 && v0) << 1;
12659 }
12660 };
12661 }
12662 function intersect(a, b, two) {
12663 var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
12664 var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
12665 if (!determinant) return !two && a;
12666 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);
12667 d3_geo_cartesianAdd(A, B);
12668 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);
12669 if (t2 < 0) return;
12670 var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
12671 d3_geo_cartesianAdd(q, A);
12672 q = d3_geo_spherical(q);
12673 if (!two) return q;
12674 var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
12675 if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
12676 var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
12677 if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
12678 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)) {
12679 var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
12680 d3_geo_cartesianAdd(q1, A);
12681 return [ q, d3_geo_spherical(q1) ];
12682 }
12683 }
12684 function code(λ, φ) {
12685 var r = smallRadius ? radius : π - radius, code = 0;
12686 if (λ < -r) code |= 1; else if (λ > r) code |= 2;
12687 if (φ < -r) code |= 4; else if (φ > r) code |= 8;
12688 return code;
12689 }
12690 }
12691 function d3_geom_clipLine(x0, y0, x1, y1) {
12692 return function(line) {
12693 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;
12694 r = x0 - ax;
12695 if (!dx && r > 0) return;
12696 r /= dx;
12697 if (dx < 0) {
12698 if (r < t0) return;
12699 if (r < t1) t1 = r;
12700 } else if (dx > 0) {
12701 if (r > t1) return;
12702 if (r > t0) t0 = r;
12703 }
12704 r = x1 - ax;
12705 if (!dx && r < 0) return;
12706 r /= dx;
12707 if (dx < 0) {
12708 if (r > t1) return;
12709 if (r > t0) t0 = r;
12710 } else if (dx > 0) {
12711 if (r < t0) return;
12712 if (r < t1) t1 = r;
12713 }
12714 r = y0 - ay;
12715 if (!dy && r > 0) return;
12716 r /= dy;
12717 if (dy < 0) {
12718 if (r < t0) return;
12719 if (r < t1) t1 = r;
12720 } else if (dy > 0) {
12721 if (r > t1) return;
12722 if (r > t0) t0 = r;
12723 }
12724 r = y1 - ay;
12725 if (!dy && r < 0) return;
12726 r /= dy;
12727 if (dy < 0) {
12728 if (r > t1) return;
12729 if (r > t0) t0 = r;
12730 } else if (dy > 0) {
12731 if (r < t0) return;
12732 if (r < t1) t1 = r;
12733 }
12734 if (t0 > 0) line.a = {
12735 x: ax + t0 * dx,
12736 y: ay + t0 * dy
12737 };
12738 if (t1 < 1) line.b = {
12739 x: ax + t1 * dx,
12740 y: ay + t1 * dy
12741 };
12742 return line;
12743 };
12744 }
12745 var d3_geo_clipExtentMAX = 1e9;
12746 d3.geo.clipExtent = function() {
12747 var x0, y0, x1, y1, stream, clip, clipExtent = {
12748 stream: function(output) {
12749 if (stream) stream.valid = false;
12750 stream = clip(output);
12751 stream.valid = true;
12752 return stream;
12753 },
12754 extent: function(_) {
12755 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
12756 clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
12757 if (stream) stream.valid = false, stream = null;
12758 return clipExtent;
12759 }
12760 };
12761 return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
12762 };
12763 function d3_geo_clipExtent(x0, y0, x1, y1) {
12764 return function(listener) {
12765 var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
12766 var clip = {
12767 point: point,
12768 lineStart: lineStart,
12769 lineEnd: lineEnd,
12770 polygonStart: function() {
12771 listener = bufferListener;
12772 segments = [];
12773 polygon = [];
12774 clean = true;
12775 },
12776 polygonEnd: function() {
12777 listener = listener_;
12778 segments = d3.merge(segments);
12779 var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
12780 if (inside || visible) {
12781 listener.polygonStart();
12782 if (inside) {
12783 listener.lineStart();
12784 interpolate(null, null, 1, listener);
12785 listener.lineEnd();
12786 }
12787 if (visible) {
12788 d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
12789 }
12790 listener.polygonEnd();
12791 }
12792 segments = polygon = ring = null;
12793 }
12794 };
12795 function insidePolygon(p) {
12796 var wn = 0, n = polygon.length, y = p[1];
12797 for (var i = 0; i < n; ++i) {
12798 for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
12799 b = v[j];
12800 if (a[1] <= y) {
12801 if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
12802 } else {
12803 if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
12804 }
12805 a = b;
12806 }
12807 }
12808 return wn !== 0;
12809 }
12810 function interpolate(from, to, direction, listener) {
12811 var a = 0, a1 = 0;
12812 if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
12813 do {
12814 listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
12815 } while ((a = (a + direction + 4) % 4) !== a1);
12816 } else {
12817 listener.point(to[0], to[1]);
12818 }
12819 }
12820 function pointVisible(x, y) {
12821 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
12822 }
12823 function point(x, y) {
12824 if (pointVisible(x, y)) listener.point(x, y);
12825 }
12826 var x__, y__, v__, x_, y_, v_, first, clean;
12827 function lineStart() {
12828 clip.point = linePoint;
12829 if (polygon) polygon.push(ring = []);
12830 first = true;
12831 v_ = false;
12832 x_ = y_ = NaN;
12833 }
12834 function lineEnd() {
12835 if (segments) {
12836 linePoint(x__, y__);
12837 if (v__ && v_) bufferListener.rejoin();
12838 segments.push(bufferListener.buffer());
12839 }
12840 clip.point = point;
12841 if (v_) listener.lineEnd();
12842 }
12843 function linePoint(x, y) {
12844 x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
12845 y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
12846 var v = pointVisible(x, y);
12847 if (polygon) ring.push([ x, y ]);
12848 if (first) {
12849 x__ = x, y__ = y, v__ = v;
12850 first = false;
12851 if (v) {
12852 listener.lineStart();
12853 listener.point(x, y);
12854 }
12855 } else {
12856 if (v && v_) listener.point(x, y); else {
12857 var l = {
12858 a: {
12859 x: x_,
12860 y: y_
12861 },
12862 b: {
12863 x: x,
12864 y: y
12865 }
12866 };
12867 if (clipLine(l)) {
12868 if (!v_) {
12869 listener.lineStart();
12870 listener.point(l.a.x, l.a.y);
12871 }
12872 listener.point(l.b.x, l.b.y);
12873 if (!v) listener.lineEnd();
12874 clean = false;
12875 } else if (v) {
12876 listener.lineStart();
12877 listener.point(x, y);
12878 clean = false;
12879 }
12880 }
12881 }
12882 x_ = x, y_ = y, v_ = v;
12883 }
12884 return clip;
12885 };
12886 function corner(p, direction) {
12887 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;
12888 }
12889 function compare(a, b) {
12890 return comparePoints(a.x, b.x);
12891 }
12892 function comparePoints(a, b) {
12893 var ca = corner(a, 1), cb = corner(b, 1);
12894 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];
12895 }
12896 }
12897 function d3_geo_conic(projectAt) {
12898 var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
12899 p.parallels = function(_) {
12900 if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
12901 return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
12902 };
12903 return p;
12904 }
12905 function d3_geo_conicEqualArea(φ0, φ1) {
12906 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;
12907 function forward(λ, φ) {
12908 var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
12909 return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
12910 }
12911 forward.invert = function(x, y) {
12912 var ρ0_y = ρ0 - y;
12913 return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
12914 };
12915 return forward;
12916 }
12917 (d3.geo.conicEqualArea = function() {
12918 return d3_geo_conic(d3_geo_conicEqualArea);
12919 }).raw = d3_geo_conicEqualArea;
12920 d3.geo.albers = function() {
12921 return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
12922 };
12923 d3.geo.albersUsa = function() {
12924 var lower48 = d3.geo.albers();
12925 var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
12926 var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
12927 var point, pointStream = {
12928 point: function(x, y) {
12929 point = [ x, y ];
12930 }
12931 }, lower48Point, alaskaPoint, hawaiiPoint;
12932 function albersUsa(coordinates) {
12933 var x = coordinates[0], y = coordinates[1];
12934 point = null;
12935 (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
12936 return point;
12937 }
12938 albersUsa.invert = function(coordinates) {
12939 var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
12940 return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
12941 };
12942 albersUsa.stream = function(stream) {
12943 var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
12944 return {
12945 point: function(x, y) {
12946 lower48Stream.point(x, y);
12947 alaskaStream.point(x, y);
12948 hawaiiStream.point(x, y);
12949 },
12950 sphere: function() {
12951 lower48Stream.sphere();
12952 alaskaStream.sphere();
12953 hawaiiStream.sphere();
12954 },
12955 lineStart: function() {
12956 lower48Stream.lineStart();
12957 alaskaStream.lineStart();
12958 hawaiiStream.lineStart();
12959 },
12960 lineEnd: function() {
12961 lower48Stream.lineEnd();
12962 alaskaStream.lineEnd();
12963 hawaiiStream.lineEnd();
12964 },
12965 polygonStart: function() {
12966 lower48Stream.polygonStart();
12967 alaskaStream.polygonStart();
12968 hawaiiStream.polygonStart();
12969 },
12970 polygonEnd: function() {
12971 lower48Stream.polygonEnd();
12972 alaskaStream.polygonEnd();
12973 hawaiiStream.polygonEnd();
12974 }
12975 };
12976 };
12977 albersUsa.precision = function(_) {
12978 if (!arguments.length) return lower48.precision();
12979 lower48.precision(_);
12980 alaska.precision(_);
12981 hawaii.precision(_);
12982 return albersUsa;
12983 };
12984 albersUsa.scale = function(_) {
12985 if (!arguments.length) return lower48.scale();
12986 lower48.scale(_);
12987 alaska.scale(_ * .35);
12988 hawaii.scale(_);
12989 return albersUsa.translate(lower48.translate());
12990 };
12991 albersUsa.translate = function(_) {
12992 if (!arguments.length) return lower48.translate();
12993 var k = lower48.scale(), x = +_[0], y = +_[1];
12994 lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
12995 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;
12996 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;
12997 return albersUsa;
12998 };
12999 return albersUsa.scale(1070);
13000 };
13001 var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
13002 point: d3_noop,
13003 lineStart: d3_noop,
13004 lineEnd: d3_noop,
13005 polygonStart: function() {
13006 d3_geo_pathAreaPolygon = 0;
13007 d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
13008 },
13009 polygonEnd: function() {
13010 d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
13011 d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
13012 }
13013 };
13014 function d3_geo_pathAreaRingStart() {
13015 var x00, y00, x0, y0;
13016 d3_geo_pathArea.point = function(x, y) {
13017 d3_geo_pathArea.point = nextPoint;
13018 x00 = x0 = x, y00 = y0 = y;
13019 };
13020 function nextPoint(x, y) {
13021 d3_geo_pathAreaPolygon += y0 * x - x0 * y;
13022 x0 = x, y0 = y;
13023 }
13024 d3_geo_pathArea.lineEnd = function() {
13025 nextPoint(x00, y00);
13026 };
13027 }
13028 var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
13029 var d3_geo_pathBounds = {
13030 point: d3_geo_pathBoundsPoint,
13031 lineStart: d3_noop,
13032 lineEnd: d3_noop,
13033 polygonStart: d3_noop,
13034 polygonEnd: d3_noop
13035 };
13036 function d3_geo_pathBoundsPoint(x, y) {
13037 if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
13038 if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
13039 if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
13040 if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
13041 }
13042 function d3_geo_pathBuffer() {
13043 var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
13044 var stream = {
13045 point: point,
13046 lineStart: function() {
13047 stream.point = pointLineStart;
13048 },
13049 lineEnd: lineEnd,
13050 polygonStart: function() {
13051 stream.lineEnd = lineEndPolygon;
13052 },
13053 polygonEnd: function() {
13054 stream.lineEnd = lineEnd;
13055 stream.point = point;
13056 },
13057 pointRadius: function(_) {
13058 pointCircle = d3_geo_pathBufferCircle(_);
13059 return stream;
13060 },
13061 result: function() {
13062 if (buffer.length) {
13063 var result = buffer.join("");
13064 buffer = [];
13065 return result;
13066 }
13067 }
13068 };
13069 function point(x, y) {
13070 buffer.push("M", x, ",", y, pointCircle);
13071 }
13072 function pointLineStart(x, y) {
13073 buffer.push("M", x, ",", y);
13074 stream.point = pointLine;
13075 }
13076 function pointLine(x, y) {
13077 buffer.push("L", x, ",", y);
13078 }
13079 function lineEnd() {
13080 stream.point = point;
13081 }
13082 function lineEndPolygon() {
13083 buffer.push("Z");
13084 }
13085 return stream;
13086 }
13087 function d3_geo_pathBufferCircle(radius) {
13088 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
13089 }
13090 var d3_geo_pathCentroid = {
13091 point: d3_geo_pathCentroidPoint,
13092 lineStart: d3_geo_pathCentroidLineStart,
13093 lineEnd: d3_geo_pathCentroidLineEnd,
13094 polygonStart: function() {
13095 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
13096 },
13097 polygonEnd: function() {
13098 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
13099 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
13100 d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
13101 }
13102 };
13103 function d3_geo_pathCentroidPoint(x, y) {
13104 d3_geo_centroidX0 += x;
13105 d3_geo_centroidY0 += y;
13106 ++d3_geo_centroidZ0;
13107 }
13108 function d3_geo_pathCentroidLineStart() {
13109 var x0, y0;
13110 d3_geo_pathCentroid.point = function(x, y) {
13111 d3_geo_pathCentroid.point = nextPoint;
13112 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
13113 };
13114 function nextPoint(x, y) {
13115 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
13116 d3_geo_centroidX1 += z * (x0 + x) / 2;
13117 d3_geo_centroidY1 += z * (y0 + y) / 2;
13118 d3_geo_centroidZ1 += z;
13119 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
13120 }
13121 }
13122 function d3_geo_pathCentroidLineEnd() {
13123 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
13124 }
13125 function d3_geo_pathCentroidRingStart() {
13126 var x00, y00, x0, y0;
13127 d3_geo_pathCentroid.point = function(x, y) {
13128 d3_geo_pathCentroid.point = nextPoint;
13129 d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
13130 };
13131 function nextPoint(x, y) {
13132 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
13133 d3_geo_centroidX1 += z * (x0 + x) / 2;
13134 d3_geo_centroidY1 += z * (y0 + y) / 2;
13135 d3_geo_centroidZ1 += z;
13136 z = y0 * x - x0 * y;
13137 d3_geo_centroidX2 += z * (x0 + x);
13138 d3_geo_centroidY2 += z * (y0 + y);
13139 d3_geo_centroidZ2 += z * 3;
13140 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
13141 }
13142 d3_geo_pathCentroid.lineEnd = function() {
13143 nextPoint(x00, y00);
13144 };
13145 }
13146 function d3_geo_pathContext(context) {
13147 var pointRadius = 4.5;
13148 var stream = {
13149 point: point,
13150 lineStart: function() {
13151 stream.point = pointLineStart;
13152 },
13153 lineEnd: lineEnd,
13154 polygonStart: function() {
13155 stream.lineEnd = lineEndPolygon;
13156 },
13157 polygonEnd: function() {
13158 stream.lineEnd = lineEnd;
13159 stream.point = point;
13160 },
13161 pointRadius: function(_) {
13162 pointRadius = _;
13163 return stream;
13164 },
13165 result: d3_noop
13166 };
13167 function point(x, y) {
13168 context.moveTo(x + pointRadius, y);
13169 context.arc(x, y, pointRadius, 0, τ);
13170 }
13171 function pointLineStart(x, y) {
13172 context.moveTo(x, y);
13173 stream.point = pointLine;
13174 }
13175 function pointLine(x, y) {
13176 context.lineTo(x, y);
13177 }
13178 function lineEnd() {
13179 stream.point = point;
13180 }
13181 function lineEndPolygon() {
13182 context.closePath();
13183 }
13184 return stream;
13185 }
13186 function d3_geo_resample(project) {
13187 var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
13188 function resample(stream) {
13189 return (maxDepth ? resampleRecursive : resampleNone)(stream);
13190 }
13191 function resampleNone(stream) {
13192 return d3_geo_transformPoint(stream, function(x, y) {
13193 x = project(x, y);
13194 stream.point(x[0], x[1]);
13195 });
13196 }
13197 function resampleRecursive(stream) {
13198 var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
13199 var resample = {
13200 point: point,
13201 lineStart: lineStart,
13202 lineEnd: lineEnd,
13203 polygonStart: function() {
13204 stream.polygonStart();
13205 resample.lineStart = ringStart;
13206 },
13207 polygonEnd: function() {
13208 stream.polygonEnd();
13209 resample.lineStart = lineStart;
13210 }
13211 };
13212 function point(x, y) {
13213 x = project(x, y);
13214 stream.point(x[0], x[1]);
13215 }
13216 function lineStart() {
13217 x0 = NaN;
13218 resample.point = linePoint;
13219 stream.lineStart();
13220 }
13221 function linePoint(λ, φ) {
13222 var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
13223 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);
13224 stream.point(x0, y0);
13225 }
13226 function lineEnd() {
13227 resample.point = point;
13228 stream.lineEnd();
13229 }
13230 function ringStart() {
13231 lineStart();
13232 resample.point = ringPoint;
13233 resample.lineEnd = ringEnd;
13234 }
13235 function ringPoint(λ, φ) {
13236 linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
13237 resample.point = linePoint;
13238 }
13239 function ringEnd() {
13240 resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
13241 resample.lineEnd = lineEnd;
13242 lineEnd();
13243 }
13244 return resample;
13245 }
13246 function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
13247 var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
13248 if (d2 > 4 * δ2 && depth--) {
13249 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;
13250 if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
13251 resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
13252 stream.point(x2, y2);
13253 resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
13254 }
13255 }
13256 }
13257 resample.precision = function(_) {
13258 if (!arguments.length) return Math.sqrt(δ2);
13259 maxDepth = (δ2 = _ * _) > 0 && 16;
13260 return resample;
13261 };
13262 return resample;
13263 }
13264 d3.geo.path = function() {
13265 var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
13266 function path(object) {
13267 if (object) {
13268 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
13269 if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
13270 d3.geo.stream(object, cacheStream);
13271 }
13272 return contextStream.result();
13273 }
13274 path.area = function(object) {
13275 d3_geo_pathAreaSum = 0;
13276 d3.geo.stream(object, projectStream(d3_geo_pathArea));
13277 return d3_geo_pathAreaSum;
13278 };
13279 path.centroid = function(object) {
13280 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;
13281 d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
13282 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 ];
13283 };
13284 path.bounds = function(object) {
13285 d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
13286 d3.geo.stream(object, projectStream(d3_geo_pathBounds));
13287 return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
13288 };
13289 path.projection = function(_) {
13290 if (!arguments.length) return projection;
13291 projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
13292 return reset();
13293 };
13294 path.context = function(_) {
13295 if (!arguments.length) return context;
13296 contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
13297 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
13298 return reset();
13299 };
13300 path.pointRadius = function(_) {
13301 if (!arguments.length) return pointRadius;
13302 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
13303 return path;
13304 };
13305 function reset() {
13306 cacheStream = null;
13307 return path;
13308 }
13309 return path.projection(d3.geo.albersUsa()).context(null);
13310 };
13311 function d3_geo_pathProjectStream(project) {
13312 var resample = d3_geo_resample(function(x, y) {
13313 return project([ x * d3_degrees, y * d3_degrees ]);
13314 });
13315 return function(stream) {
13316 return d3_geo_projectionRadians(resample(stream));
13317 };
13318 }
13319 d3.geo.transform = function(methods) {
13320 return {
13321 stream: function(stream) {
13322 var transform = new d3_geo_transform(stream);
13323 for (var k in methods) transform[k] = methods[k];
13324 return transform;
13325 }
13326 };
13327 };
13328 function d3_geo_transform(stream) {
13329 this.stream = stream;
13330 }
13331 d3_geo_transform.prototype = {
13332 point: function(x, y) {
13333 this.stream.point(x, y);
13334 },
13335 sphere: function() {
13336 this.stream.sphere();
13337 },
13338 lineStart: function() {
13339 this.stream.lineStart();
13340 },
13341 lineEnd: function() {
13342 this.stream.lineEnd();
13343 },
13344 polygonStart: function() {
13345 this.stream.polygonStart();
13346 },
13347 polygonEnd: function() {
13348 this.stream.polygonEnd();
13349 }
13350 };
13351 function d3_geo_transformPoint(stream, point) {
13352 return {
13353 point: point,
13354 sphere: function() {
13355 stream.sphere();
13356 },
13357 lineStart: function() {
13358 stream.lineStart();
13359 },
13360 lineEnd: function() {
13361 stream.lineEnd();
13362 },
13363 polygonStart: function() {
13364 stream.polygonStart();
13365 },
13366 polygonEnd: function() {
13367 stream.polygonEnd();
13368 }
13369 };
13370 }
13371 d3.geo.projection = d3_geo_projection;
13372 d3.geo.projectionMutator = d3_geo_projectionMutator;
13373 function d3_geo_projection(project) {
13374 return d3_geo_projectionMutator(function() {
13375 return project;
13376 })();
13377 }
13378 function d3_geo_projectionMutator(projectAt) {
13379 var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
13380 x = project(x, y);
13381 return [ x[0] * k + δx, δy - x[1] * k ];
13382 }), 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;
13383 function projection(point) {
13384 point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
13385 return [ point[0] * k + δx, δy - point[1] * k ];
13386 }
13387 function invert(point) {
13388 point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
13389 return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
13390 }
13391 projection.stream = function(output) {
13392 if (stream) stream.valid = false;
13393 stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
13394 stream.valid = true;
13395 return stream;
13396 };
13397 projection.clipAngle = function(_) {
13398 if (!arguments.length) return clipAngle;
13399 preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
13400 return invalidate();
13401 };
13402 projection.clipExtent = function(_) {
13403 if (!arguments.length) return clipExtent;
13404 clipExtent = _;
13405 postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
13406 return invalidate();
13407 };
13408 projection.scale = function(_) {
13409 if (!arguments.length) return k;
13410 k = +_;
13411 return reset();
13412 };
13413 projection.translate = function(_) {
13414 if (!arguments.length) return [ x, y ];
13415 x = +_[0];
13416 y = +_[1];
13417 return reset();
13418 };
13419 projection.center = function(_) {
13420 if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
13421 λ = _[0] % 360 * d3_radians;
13422 φ = _[1] % 360 * d3_radians;
13423 return reset();
13424 };
13425 projection.rotate = function(_) {
13426 if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
13427 δλ = _[0] % 360 * d3_radians;
13428 δφ = _[1] % 360 * d3_radians;
13429 δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
13430 return reset();
13431 };
13432 d3.rebind(projection, projectResample, "precision");
13433 function reset() {
13434 projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
13435 var center = project(λ, φ);
13436 δx = x - center[0] * k;
13437 δy = y + center[1] * k;
13438 return invalidate();
13439 }
13440 function invalidate() {
13441 if (stream) stream.valid = false, stream = null;
13442 return projection;
13443 }
13444 return function() {
13445 project = projectAt.apply(this, arguments);
13446 projection.invert = project.invert && invert;
13447 return reset();
13448 };
13449 }
13450 function d3_geo_projectionRadians(stream) {
13451 return d3_geo_transformPoint(stream, function(x, y) {
13452 stream.point(x * d3_radians, y * d3_radians);
13453 });
13454 }
13455 function d3_geo_equirectangular(λ, φ) {
13456 return [ λ, φ ];
13457 }
13458 (d3.geo.equirectangular = function() {
13459 return d3_geo_projection(d3_geo_equirectangular);
13460 }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
13461 d3.geo.rotation = function(rotate) {
13462 rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
13463 function forward(coordinates) {
13464 coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
13465 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
13466 }
13467 forward.invert = function(coordinates) {
13468 coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
13469 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
13470 };
13471 return forward;
13472 };
13473 function d3_geo_identityRotation(λ, φ) {
13474 return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
13475 }
13476 d3_geo_identityRotation.invert = d3_geo_equirectangular;
13477 function d3_geo_rotation(δλ, δφ, δγ) {
13478 return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
13479 }
13480 function d3_geo_forwardRotationλ(δλ) {
13481 return function(λ, φ) {
13482 return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
13483 };
13484 }
13485 function d3_geo_rotationλ(δλ) {
13486 var rotation = d3_geo_forwardRotationλ(δλ);
13487 rotation.invert = d3_geo_forwardRotationλ(-δλ);
13488 return rotation;
13489 }
13490 function d3_geo_rotationφγ(δφ, δγ) {
13491 var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
13492 function rotation(λ, φ) {
13493 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
13494 return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
13495 }
13496 rotation.invert = function(λ, φ) {
13497 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
13498 return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
13499 };
13500 return rotation;
13501 }
13502 d3.geo.circle = function() {
13503 var origin = [ 0, 0 ], angle, precision = 6, interpolate;
13504 function circle() {
13505 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 = [];
13506 interpolate(null, null, 1, {
13507 point: function(x, y) {
13508 ring.push(x = rotate(x, y));
13509 x[0] *= d3_degrees, x[1] *= d3_degrees;
13510 }
13511 });
13512 return {
13513 type: "Polygon",
13514 coordinates: [ ring ]
13515 };
13516 }
13517 circle.origin = function(x) {
13518 if (!arguments.length) return origin;
13519 origin = x;
13520 return circle;
13521 };
13522 circle.angle = function(x) {
13523 if (!arguments.length) return angle;
13524 interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
13525 return circle;
13526 };
13527 circle.precision = function(_) {
13528 if (!arguments.length) return precision;
13529 interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
13530 return circle;
13531 };
13532 return circle.angle(90);
13533 };
13534 function d3_geo_circleInterpolate(radius, precision) {
13535 var cr = Math.cos(radius), sr = Math.sin(radius);
13536 return function(from, to, direction, listener) {
13537 var step = direction * precision;
13538 if (from != null) {
13539 from = d3_geo_circleAngle(cr, from);
13540 to = d3_geo_circleAngle(cr, to);
13541 if (direction > 0 ? from < to : from > to) from += direction * τ;
13542 } else {
13543 from = radius + direction * τ;
13544 to = radius - .5 * step;
13545 }
13546 for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
13547 listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
13548 }
13549 };
13550 }
13551 function d3_geo_circleAngle(cr, point) {
13552 var a = d3_geo_cartesian(point);
13553 a[0] -= cr;
13554 d3_geo_cartesianNormalize(a);
13555 var angle = d3_acos(-a[1]);
13556 return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
13557 }
13558 d3.geo.distance = function(a, b) {
13559 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;
13560 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Δλ);
13561 };
13562 d3.geo.graticule = function() {
13563 var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
13564 function graticule() {
13565 return {
13566 type: "MultiLineString",
13567 coordinates: lines()
13568 };
13569 }
13570 function lines() {
13571 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) {
13572 return abs(x % DX) > ε;
13573 }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
13574 return abs(y % DY) > ε;
13575 }).map(y));
13576 }
13577 graticule.lines = function() {
13578 return lines().map(function(coordinates) {
13579 return {
13580 type: "LineString",
13581 coordinates: coordinates
13582 };
13583 });
13584 };
13585 graticule.outline = function() {
13586 return {
13587 type: "Polygon",
13588 coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
13589 };
13590 };
13591 graticule.extent = function(_) {
13592 if (!arguments.length) return graticule.minorExtent();
13593 return graticule.majorExtent(_).minorExtent(_);
13594 };
13595 graticule.majorExtent = function(_) {
13596 if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
13597 X0 = +_[0][0], X1 = +_[1][0];
13598 Y0 = +_[0][1], Y1 = +_[1][1];
13599 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
13600 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
13601 return graticule.precision(precision);
13602 };
13603 graticule.minorExtent = function(_) {
13604 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
13605 x0 = +_[0][0], x1 = +_[1][0];
13606 y0 = +_[0][1], y1 = +_[1][1];
13607 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
13608 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
13609 return graticule.precision(precision);
13610 };
13611 graticule.step = function(_) {
13612 if (!arguments.length) return graticule.minorStep();
13613 return graticule.majorStep(_).minorStep(_);
13614 };
13615 graticule.majorStep = function(_) {
13616 if (!arguments.length) return [ DX, DY ];
13617 DX = +_[0], DY = +_[1];
13618 return graticule;
13619 };
13620 graticule.minorStep = function(_) {
13621 if (!arguments.length) return [ dx, dy ];
13622 dx = +_[0], dy = +_[1];
13623 return graticule;
13624 };
13625 graticule.precision = function(_) {
13626 if (!arguments.length) return precision;
13627 precision = +_;
13628 x = d3_geo_graticuleX(y0, y1, 90);
13629 y = d3_geo_graticuleY(x0, x1, precision);
13630 X = d3_geo_graticuleX(Y0, Y1, 90);
13631 Y = d3_geo_graticuleY(X0, X1, precision);
13632 return graticule;
13633 };
13634 return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
13635 };
13636 function d3_geo_graticuleX(y0, y1, dy) {
13637 var y = d3.range(y0, y1 - ε, dy).concat(y1);
13638 return function(x) {
13639 return y.map(function(y) {
13640 return [ x, y ];
13641 });
13642 };
13643 }
13644 function d3_geo_graticuleY(x0, x1, dx) {
13645 var x = d3.range(x0, x1 - ε, dx).concat(x1);
13646 return function(y) {
13647 return x.map(function(x) {
13648 return [ x, y ];
13649 });
13650 };
13651 }
13652 function d3_source(d) {
13653 return d.source;
13654 }
13655 function d3_target(d) {
13656 return d.target;
13657 }
13658 d3.geo.greatArc = function() {
13659 var source = d3_source, source_, target = d3_target, target_;
13660 function greatArc() {
13661 return {
13662 type: "LineString",
13663 coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
13664 };
13665 }
13666 greatArc.distance = function() {
13667 return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
13668 };
13669 greatArc.source = function(_) {
13670 if (!arguments.length) return source;
13671 source = _, source_ = typeof _ === "function" ? null : _;
13672 return greatArc;
13673 };
13674 greatArc.target = function(_) {
13675 if (!arguments.length) return target;
13676 target = _, target_ = typeof _ === "function" ? null : _;
13677 return greatArc;
13678 };
13679 greatArc.precision = function() {
13680 return arguments.length ? greatArc : 0;
13681 };
13682 return greatArc;
13683 };
13684 d3.geo.interpolate = function(source, target) {
13685 return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
13686 };
13687 function d3_geo_interpolate(x0, y0, x1, y1) {
13688 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);
13689 var interpolate = d ? function(t) {
13690 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;
13691 return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
13692 } : function() {
13693 return [ x0 * d3_degrees, y0 * d3_degrees ];
13694 };
13695 interpolate.distance = d;
13696 return interpolate;
13697 }
13698 d3.geo.length = function(object) {
13699 d3_geo_lengthSum = 0;
13700 d3.geo.stream(object, d3_geo_length);
13701 return d3_geo_lengthSum;
13702 };
13703 var d3_geo_lengthSum;
13704 var d3_geo_length = {
13705 sphere: d3_noop,
13706 point: d3_noop,
13707 lineStart: d3_geo_lengthLineStart,
13708 lineEnd: d3_noop,
13709 polygonStart: d3_noop,
13710 polygonEnd: d3_noop
13711 };
13712 function d3_geo_lengthLineStart() {
13713 var λ0, sinφ0, cosφ0;
13714 d3_geo_length.point = function(λ, φ) {
13715 λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
13716 d3_geo_length.point = nextPoint;
13717 };
13718 d3_geo_length.lineEnd = function() {
13719 d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
13720 };
13721 function nextPoint(λ, φ) {
13722 var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
13723 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Δλ);
13724 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
13725 }
13726 }
13727 function d3_geo_azimuthal(scale, angle) {
13728 function azimuthal(λ, φ) {
13729 var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
13730 return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
13731 }
13732 azimuthal.invert = function(x, y) {
13733 var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
13734 return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
13735 };
13736 return azimuthal;
13737 }
13738 var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
13739 return Math.sqrt(2 / (1 + cosλcosφ));
13740 }, function(ρ) {
13741 return 2 * Math.asin(ρ / 2);
13742 });
13743 (d3.geo.azimuthalEqualArea = function() {
13744 return d3_geo_projection(d3_geo_azimuthalEqualArea);
13745 }).raw = d3_geo_azimuthalEqualArea;
13746 var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
13747 var c = Math.acos(cosλcosφ);
13748 return c && c / Math.sin(c);
13749 }, d3_identity);
13750 (d3.geo.azimuthalEquidistant = function() {
13751 return d3_geo_projection(d3_geo_azimuthalEquidistant);
13752 }).raw = d3_geo_azimuthalEquidistant;
13753 function d3_geo_conicConformal(φ0, φ1) {
13754 var cosφ0 = Math.cos(φ0), t = function(φ) {
13755 return Math.tan(π / 4 + φ / 2);
13756 }, 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;
13757 if (!n) return d3_geo_mercator;
13758 function forward(λ, φ) {
13759 if (F > 0) {
13760 if (φ < -halfπ + ε) φ = -halfπ + ε;
13761 } else {
13762 if (φ > halfπ - ε) φ = halfπ - ε;
13763 }
13764 var ρ = F / Math.pow(t(φ), n);
13765 return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
13766 }
13767 forward.invert = function(x, y) {
13768 var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
13769 return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
13770 };
13771 return forward;
13772 }
13773 (d3.geo.conicConformal = function() {
13774 return d3_geo_conic(d3_geo_conicConformal);
13775 }).raw = d3_geo_conicConformal;
13776 function d3_geo_conicEquidistant(φ0, φ1) {
13777 var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
13778 if (abs(n) < ε) return d3_geo_equirectangular;
13779 function forward(λ, φ) {
13780 var ρ = G - φ;
13781 return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
13782 }
13783 forward.invert = function(x, y) {
13784 var ρ0_y = G - y;
13785 return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
13786 };
13787 return forward;
13788 }
13789 (d3.geo.conicEquidistant = function() {
13790 return d3_geo_conic(d3_geo_conicEquidistant);
13791 }).raw = d3_geo_conicEquidistant;
13792 var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
13793 return 1 / cosλcosφ;
13794 }, Math.atan);
13795 (d3.geo.gnomonic = function() {
13796 return d3_geo_projection(d3_geo_gnomonic);
13797 }).raw = d3_geo_gnomonic;
13798 function d3_geo_mercator(λ, φ) {
13799 return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
13800 }
13801 d3_geo_mercator.invert = function(x, y) {
13802 return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
13803 };
13804 function d3_geo_mercatorProjection(project) {
13805 var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
13806 m.scale = function() {
13807 var v = scale.apply(m, arguments);
13808 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
13809 };
13810 m.translate = function() {
13811 var v = translate.apply(m, arguments);
13812 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
13813 };
13814 m.clipExtent = function(_) {
13815 var v = clipExtent.apply(m, arguments);
13816 if (v === m) {
13817 if (clipAuto = _ == null) {
13818 var k = π * scale(), t = translate();
13819 clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
13820 }
13821 } else if (clipAuto) {
13822 v = null;
13823 }
13824 return v;
13825 };
13826 return m.clipExtent(null);
13827 }
13828 (d3.geo.mercator = function() {
13829 return d3_geo_mercatorProjection(d3_geo_mercator);
13830 }).raw = d3_geo_mercator;
13831 var d3_geo_orthographic = d3_geo_azimuthal(function() {
13832 return 1;
13833 }, Math.asin);
13834 (d3.geo.orthographic = function() {
13835 return d3_geo_projection(d3_geo_orthographic);
13836 }).raw = d3_geo_orthographic;
13837 var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
13838 return 1 / (1 + cosλcosφ);
13839 }, function(ρ) {
13840 return 2 * Math.atan(ρ);
13841 });
13842 (d3.geo.stereographic = function() {
13843 return d3_geo_projection(d3_geo_stereographic);
13844 }).raw = d3_geo_stereographic;
13845 function d3_geo_transverseMercator(λ, φ) {
13846 return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
13847 }
13848 d3_geo_transverseMercator.invert = function(x, y) {
13849 return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
13850 };
13851 (d3.geo.transverseMercator = function() {
13852 var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
13853 projection.center = function(_) {
13854 return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
13855 };
13856 projection.rotate = function(_) {
13857 return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
13858 [ _[0], _[1], _[2] - 90 ]);
13859 };
13860 return rotate([ 0, 0, 90 ]);
13861 }).raw = d3_geo_transverseMercator;
13862 d3.geom = {};
13863 function d3_geom_pointX(d) {
13864 return d[0];
13865 }
13866 function d3_geom_pointY(d) {
13867 return d[1];
13868 }
13869 d3.geom.hull = function(vertices) {
13870 var x = d3_geom_pointX, y = d3_geom_pointY;
13871 if (arguments.length) return hull(vertices);
13872 function hull(data) {
13873 if (data.length < 3) return [];
13874 var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
13875 for (i = 0; i < n; i++) {
13876 points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
13877 }
13878 points.sort(d3_geom_hullOrder);
13879 for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
13880 var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
13881 var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
13882 for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
13883 for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
13884 return polygon;
13885 }
13886 hull.x = function(_) {
13887 return arguments.length ? (x = _, hull) : x;
13888 };
13889 hull.y = function(_) {
13890 return arguments.length ? (y = _, hull) : y;
13891 };
13892 return hull;
13893 };
13894 function d3_geom_hullUpper(points) {
13895 var n = points.length, hull = [ 0, 1 ], hs = 2;
13896 for (var i = 2; i < n; i++) {
13897 while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
13898 hull[hs++] = i;
13899 }
13900 return hull.slice(0, hs);
13901 }
13902 function d3_geom_hullOrder(a, b) {
13903 return a[0] - b[0] || a[1] - b[1];
13904 }
13905 d3.geom.polygon = function(coordinates) {
13906 d3_subclass(coordinates, d3_geom_polygonPrototype);
13907 return coordinates;
13908 };
13909 var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
13910 d3_geom_polygonPrototype.area = function() {
13911 var i = -1, n = this.length, a, b = this[n - 1], area = 0;
13912 while (++i < n) {
13913 a = b;
13914 b = this[i];
13915 area += a[1] * b[0] - a[0] * b[1];
13916 }
13917 return area * .5;
13918 };
13919 d3_geom_polygonPrototype.centroid = function(k) {
13920 var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
13921 if (!arguments.length) k = -1 / (6 * this.area());
13922 while (++i < n) {
13923 a = b;
13924 b = this[i];
13925 c = a[0] * b[1] - b[0] * a[1];
13926 x += (a[0] + b[0]) * c;
13927 y += (a[1] + b[1]) * c;
13928 }
13929 return [ x * k, y * k ];
13930 };
13931 d3_geom_polygonPrototype.clip = function(subject) {
13932 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;
13933 while (++i < n) {
13934 input = subject.slice();
13935 subject.length = 0;
13936 b = this[i];
13937 c = input[(m = input.length - closed) - 1];
13938 j = -1;
13939 while (++j < m) {
13940 d = input[j];
13941 if (d3_geom_polygonInside(d, a, b)) {
13942 if (!d3_geom_polygonInside(c, a, b)) {
13943 subject.push(d3_geom_polygonIntersect(c, d, a, b));
13944 }
13945 subject.push(d);
13946 } else if (d3_geom_polygonInside(c, a, b)) {
13947 subject.push(d3_geom_polygonIntersect(c, d, a, b));
13948 }
13949 c = d;
13950 }
13951 if (closed) subject.push(subject[0]);
13952 a = b;
13953 }
13954 return subject;
13955 };
13956 function d3_geom_polygonInside(p, a, b) {
13957 return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
13958 }
13959 function d3_geom_polygonIntersect(c, d, a, b) {
13960 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);
13961 return [ x1 + ua * x21, y1 + ua * y21 ];
13962 }
13963 function d3_geom_polygonClosed(coordinates) {
13964 var a = coordinates[0], b = coordinates[coordinates.length - 1];
13965 return !(a[0] - b[0] || a[1] - b[1]);
13966 }
13967 var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
13968 function d3_geom_voronoiBeach() {
13969 d3_geom_voronoiRedBlackNode(this);
13970 this.edge = this.site = this.circle = null;
13971 }
13972 function d3_geom_voronoiCreateBeach(site) {
13973 var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
13974 beach.site = site;
13975 return beach;
13976 }
13977 function d3_geom_voronoiDetachBeach(beach) {
13978 d3_geom_voronoiDetachCircle(beach);
13979 d3_geom_voronoiBeaches.remove(beach);
13980 d3_geom_voronoiBeachPool.push(beach);
13981 d3_geom_voronoiRedBlackNode(beach);
13982 }
13983 function d3_geom_voronoiRemoveBeach(beach) {
13984 var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
13985 x: x,
13986 y: y
13987 }, previous = beach.P, next = beach.N, disappearing = [ beach ];
13988 d3_geom_voronoiDetachBeach(beach);
13989 var lArc = previous;
13990 while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
13991 previous = lArc.P;
13992 disappearing.unshift(lArc);
13993 d3_geom_voronoiDetachBeach(lArc);
13994 lArc = previous;
13995 }
13996 disappearing.unshift(lArc);
13997 d3_geom_voronoiDetachCircle(lArc);
13998 var rArc = next;
13999 while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
14000 next = rArc.N;
14001 disappearing.push(rArc);
14002 d3_geom_voronoiDetachBeach(rArc);
14003 rArc = next;
14004 }
14005 disappearing.push(rArc);
14006 d3_geom_voronoiDetachCircle(rArc);
14007 var nArcs = disappearing.length, iArc;
14008 for (iArc = 1; iArc < nArcs; ++iArc) {
14009 rArc = disappearing[iArc];
14010 lArc = disappearing[iArc - 1];
14011 d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
14012 }
14013 lArc = disappearing[0];
14014 rArc = disappearing[nArcs - 1];
14015 rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
14016 d3_geom_voronoiAttachCircle(lArc);
14017 d3_geom_voronoiAttachCircle(rArc);
14018 }
14019 function d3_geom_voronoiAddBeach(site) {
14020 var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
14021 while (node) {
14022 dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
14023 if (dxl > ε) node = node.L; else {
14024 dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
14025 if (dxr > ε) {
14026 if (!node.R) {
14027 lArc = node;
14028 break;
14029 }
14030 node = node.R;
14031 } else {
14032 if (dxl > -ε) {
14033 lArc = node.P;
14034 rArc = node;
14035 } else if (dxr > -ε) {
14036 lArc = node;
14037 rArc = node.N;
14038 } else {
14039 lArc = rArc = node;
14040 }
14041 break;
14042 }
14043 }
14044 }
14045 var newArc = d3_geom_voronoiCreateBeach(site);
14046 d3_geom_voronoiBeaches.insert(lArc, newArc);
14047 if (!lArc && !rArc) return;
14048 if (lArc === rArc) {
14049 d3_geom_voronoiDetachCircle(lArc);
14050 rArc = d3_geom_voronoiCreateBeach(lArc.site);
14051 d3_geom_voronoiBeaches.insert(newArc, rArc);
14052 newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
14053 d3_geom_voronoiAttachCircle(lArc);
14054 d3_geom_voronoiAttachCircle(rArc);
14055 return;
14056 }
14057 if (!rArc) {
14058 newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
14059 return;
14060 }
14061 d3_geom_voronoiDetachCircle(lArc);
14062 d3_geom_voronoiDetachCircle(rArc);
14063 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 = {
14064 x: (cy * hb - by * hc) / d + ax,
14065 y: (bx * hc - cx * hb) / d + ay
14066 };
14067 d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
14068 newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
14069 rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
14070 d3_geom_voronoiAttachCircle(lArc);
14071 d3_geom_voronoiAttachCircle(rArc);
14072 }
14073 function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
14074 var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
14075 if (!pby2) return rfocx;
14076 var lArc = arc.P;
14077 if (!lArc) return -Infinity;
14078 site = lArc.site;
14079 var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
14080 if (!plby2) return lfocx;
14081 var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
14082 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
14083 return (rfocx + lfocx) / 2;
14084 }
14085 function d3_geom_voronoiRightBreakPoint(arc, directrix) {
14086 var rArc = arc.N;
14087 if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
14088 var site = arc.site;
14089 return site.y === directrix ? site.x : Infinity;
14090 }
14091 function d3_geom_voronoiCell(site) {
14092 this.site = site;
14093 this.edges = [];
14094 }
14095 d3_geom_voronoiCell.prototype.prepare = function() {
14096 var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
14097 while (iHalfEdge--) {
14098 edge = halfEdges[iHalfEdge].edge;
14099 if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
14100 }
14101 halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
14102 return halfEdges.length;
14103 };
14104 function d3_geom_voronoiCloseCells(extent) {
14105 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;
14106 while (iCell--) {
14107 cell = cells[iCell];
14108 if (!cell || !cell.prepare()) continue;
14109 halfEdges = cell.edges;
14110 nHalfEdges = halfEdges.length;
14111 iHalfEdge = 0;
14112 while (iHalfEdge < nHalfEdges) {
14113 end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
14114 start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
14115 if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
14116 halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
14117 x: x0,
14118 y: abs(x2 - x0) < ε ? y2 : y1
14119 } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
14120 x: abs(y2 - y1) < ε ? x2 : x1,
14121 y: y1
14122 } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
14123 x: x1,
14124 y: abs(x2 - x1) < ε ? y2 : y0
14125 } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
14126 x: abs(y2 - y0) < ε ? x2 : x0,
14127 y: y0
14128 } : null), cell.site, null));
14129 ++nHalfEdges;
14130 }
14131 }
14132 }
14133 }
14134 function d3_geom_voronoiHalfEdgeOrder(a, b) {
14135 return b.angle - a.angle;
14136 }
14137 function d3_geom_voronoiCircle() {
14138 d3_geom_voronoiRedBlackNode(this);
14139 this.x = this.y = this.arc = this.site = this.cy = null;
14140 }
14141 function d3_geom_voronoiAttachCircle(arc) {
14142 var lArc = arc.P, rArc = arc.N;
14143 if (!lArc || !rArc) return;
14144 var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
14145 if (lSite === rSite) return;
14146 var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
14147 var d = 2 * (ax * cy - ay * cx);
14148 if (d >= -ε2) return;
14149 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;
14150 var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
14151 circle.arc = arc;
14152 circle.site = cSite;
14153 circle.x = x + bx;
14154 circle.y = cy + Math.sqrt(x * x + y * y);
14155 circle.cy = cy;
14156 arc.circle = circle;
14157 var before = null, node = d3_geom_voronoiCircles._;
14158 while (node) {
14159 if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
14160 if (node.L) node = node.L; else {
14161 before = node.P;
14162 break;
14163 }
14164 } else {
14165 if (node.R) node = node.R; else {
14166 before = node;
14167 break;
14168 }
14169 }
14170 }
14171 d3_geom_voronoiCircles.insert(before, circle);
14172 if (!before) d3_geom_voronoiFirstCircle = circle;
14173 }
14174 function d3_geom_voronoiDetachCircle(arc) {
14175 var circle = arc.circle;
14176 if (circle) {
14177 if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
14178 d3_geom_voronoiCircles.remove(circle);
14179 d3_geom_voronoiCirclePool.push(circle);
14180 d3_geom_voronoiRedBlackNode(circle);
14181 arc.circle = null;
14182 }
14183 }
14184 function d3_geom_voronoiClipEdges(extent) {
14185 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;
14186 while (i--) {
14187 e = edges[i];
14188 if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
14189 e.a = e.b = null;
14190 edges.splice(i, 1);
14191 }
14192 }
14193 }
14194 function d3_geom_voronoiConnectEdge(edge, extent) {
14195 var vb = edge.b;
14196 if (vb) return true;
14197 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;
14198 if (ry === ly) {
14199 if (fx < x0 || fx >= x1) return;
14200 if (lx > rx) {
14201 if (!va) va = {
14202 x: fx,
14203 y: y0
14204 }; else if (va.y >= y1) return;
14205 vb = {
14206 x: fx,
14207 y: y1
14208 };
14209 } else {
14210 if (!va) va = {
14211 x: fx,
14212 y: y1
14213 }; else if (va.y < y0) return;
14214 vb = {
14215 x: fx,
14216 y: y0
14217 };
14218 }
14219 } else {
14220 fm = (lx - rx) / (ry - ly);
14221 fb = fy - fm * fx;
14222 if (fm < -1 || fm > 1) {
14223 if (lx > rx) {
14224 if (!va) va = {
14225 x: (y0 - fb) / fm,
14226 y: y0
14227 }; else if (va.y >= y1) return;
14228 vb = {
14229 x: (y1 - fb) / fm,
14230 y: y1
14231 };
14232 } else {
14233 if (!va) va = {
14234 x: (y1 - fb) / fm,
14235 y: y1
14236 }; else if (va.y < y0) return;
14237 vb = {
14238 x: (y0 - fb) / fm,
14239 y: y0
14240 };
14241 }
14242 } else {
14243 if (ly < ry) {
14244 if (!va) va = {
14245 x: x0,
14246 y: fm * x0 + fb
14247 }; else if (va.x >= x1) return;
14248 vb = {
14249 x: x1,
14250 y: fm * x1 + fb
14251 };
14252 } else {
14253 if (!va) va = {
14254 x: x1,
14255 y: fm * x1 + fb
14256 }; else if (va.x < x0) return;
14257 vb = {
14258 x: x0,
14259 y: fm * x0 + fb
14260 };
14261 }
14262 }
14263 }
14264 edge.a = va;
14265 edge.b = vb;
14266 return true;
14267 }
14268 function d3_geom_voronoiEdge(lSite, rSite) {
14269 this.l = lSite;
14270 this.r = rSite;
14271 this.a = this.b = null;
14272 }
14273 function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
14274 var edge = new d3_geom_voronoiEdge(lSite, rSite);
14275 d3_geom_voronoiEdges.push(edge);
14276 if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
14277 if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
14278 d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
14279 d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
14280 return edge;
14281 }
14282 function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
14283 var edge = new d3_geom_voronoiEdge(lSite, null);
14284 edge.a = va;
14285 edge.b = vb;
14286 d3_geom_voronoiEdges.push(edge);
14287 return edge;
14288 }
14289 function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
14290 if (!edge.a && !edge.b) {
14291 edge.a = vertex;
14292 edge.l = lSite;
14293 edge.r = rSite;
14294 } else if (edge.l === rSite) {
14295 edge.b = vertex;
14296 } else {
14297 edge.a = vertex;
14298 }
14299 }
14300 function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
14301 var va = edge.a, vb = edge.b;
14302 this.edge = edge;
14303 this.site = lSite;
14304 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);
14305 }
14306 d3_geom_voronoiHalfEdge.prototype = {
14307 start: function() {
14308 return this.edge.l === this.site ? this.edge.a : this.edge.b;
14309 },
14310 end: function() {
14311 return this.edge.l === this.site ? this.edge.b : this.edge.a;
14312 }
14313 };
14314 function d3_geom_voronoiRedBlackTree() {
14315 this._ = null;
14316 }
14317 function d3_geom_voronoiRedBlackNode(node) {
14318 node.U = node.C = node.L = node.R = node.P = node.N = null;
14319 }
14320 d3_geom_voronoiRedBlackTree.prototype = {
14321 insert: function(after, node) {
14322 var parent, grandpa, uncle;
14323 if (after) {
14324 node.P = after;
14325 node.N = after.N;
14326 if (after.N) after.N.P = node;
14327 after.N = node;
14328 if (after.R) {
14329 after = after.R;
14330 while (after.L) after = after.L;
14331 after.L = node;
14332 } else {
14333 after.R = node;
14334 }
14335 parent = after;
14336 } else if (this._) {
14337 after = d3_geom_voronoiRedBlackFirst(this._);
14338 node.P = null;
14339 node.N = after;
14340 after.P = after.L = node;
14341 parent = after;
14342 } else {
14343 node.P = node.N = null;
14344 this._ = node;
14345 parent = null;
14346 }
14347 node.L = node.R = null;
14348 node.U = parent;
14349 node.C = true;
14350 after = node;
14351 while (parent && parent.C) {
14352 grandpa = parent.U;
14353 if (parent === grandpa.L) {
14354 uncle = grandpa.R;
14355 if (uncle && uncle.C) {
14356 parent.C = uncle.C = false;
14357 grandpa.C = true;
14358 after = grandpa;
14359 } else {
14360 if (after === parent.R) {
14361 d3_geom_voronoiRedBlackRotateLeft(this, parent);
14362 after = parent;
14363 parent = after.U;
14364 }
14365 parent.C = false;
14366 grandpa.C = true;
14367 d3_geom_voronoiRedBlackRotateRight(this, grandpa);
14368 }
14369 } else {
14370 uncle = grandpa.L;
14371 if (uncle && uncle.C) {
14372 parent.C = uncle.C = false;
14373 grandpa.C = true;
14374 after = grandpa;
14375 } else {
14376 if (after === parent.L) {
14377 d3_geom_voronoiRedBlackRotateRight(this, parent);
14378 after = parent;
14379 parent = after.U;
14380 }
14381 parent.C = false;
14382 grandpa.C = true;
14383 d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
14384 }
14385 }
14386 parent = after.U;
14387 }
14388 this._.C = false;
14389 },
14390 remove: function(node) {
14391 if (node.N) node.N.P = node.P;
14392 if (node.P) node.P.N = node.N;
14393 node.N = node.P = null;
14394 var parent = node.U, sibling, left = node.L, right = node.R, next, red;
14395 if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
14396 if (parent) {
14397 if (parent.L === node) parent.L = next; else parent.R = next;
14398 } else {
14399 this._ = next;
14400 }
14401 if (left && right) {
14402 red = next.C;
14403 next.C = node.C;
14404 next.L = left;
14405 left.U = next;
14406 if (next !== right) {
14407 parent = next.U;
14408 next.U = node.U;
14409 node = next.R;
14410 parent.L = node;
14411 next.R = right;
14412 right.U = next;
14413 } else {
14414 next.U = parent;
14415 parent = next;
14416 node = next.R;
14417 }
14418 } else {
14419 red = node.C;
14420 node = next;
14421 }
14422 if (node) node.U = parent;
14423 if (red) return;
14424 if (node && node.C) {
14425 node.C = false;
14426 return;
14427 }
14428 do {
14429 if (node === this._) break;
14430 if (node === parent.L) {
14431 sibling = parent.R;
14432 if (sibling.C) {
14433 sibling.C = false;
14434 parent.C = true;
14435 d3_geom_voronoiRedBlackRotateLeft(this, parent);
14436 sibling = parent.R;
14437 }
14438 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
14439 if (!sibling.R || !sibling.R.C) {
14440 sibling.L.C = false;
14441 sibling.C = true;
14442 d3_geom_voronoiRedBlackRotateRight(this, sibling);
14443 sibling = parent.R;
14444 }
14445 sibling.C = parent.C;
14446 parent.C = sibling.R.C = false;
14447 d3_geom_voronoiRedBlackRotateLeft(this, parent);
14448 node = this._;
14449 break;
14450 }
14451 } else {
14452 sibling = parent.L;
14453 if (sibling.C) {
14454 sibling.C = false;
14455 parent.C = true;
14456 d3_geom_voronoiRedBlackRotateRight(this, parent);
14457 sibling = parent.L;
14458 }
14459 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
14460 if (!sibling.L || !sibling.L.C) {
14461 sibling.R.C = false;
14462 sibling.C = true;
14463 d3_geom_voronoiRedBlackRotateLeft(this, sibling);
14464 sibling = parent.L;
14465 }
14466 sibling.C = parent.C;
14467 parent.C = sibling.L.C = false;
14468 d3_geom_voronoiRedBlackRotateRight(this, parent);
14469 node = this._;
14470 break;
14471 }
14472 }
14473 sibling.C = true;
14474 node = parent;
14475 parent = parent.U;
14476 } while (!node.C);
14477 if (node) node.C = false;
14478 }
14479 };
14480 function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
14481 var p = node, q = node.R, parent = p.U;
14482 if (parent) {
14483 if (parent.L === p) parent.L = q; else parent.R = q;
14484 } else {
14485 tree._ = q;
14486 }
14487 q.U = parent;
14488 p.U = q;
14489 p.R = q.L;
14490 if (p.R) p.R.U = p;
14491 q.L = p;
14492 }
14493 function d3_geom_voronoiRedBlackRotateRight(tree, node) {
14494 var p = node, q = node.L, parent = p.U;
14495 if (parent) {
14496 if (parent.L === p) parent.L = q; else parent.R = q;
14497 } else {
14498 tree._ = q;
14499 }
14500 q.U = parent;
14501 p.U = q;
14502 p.L = q.R;
14503 if (p.L) p.L.U = p;
14504 q.R = p;
14505 }
14506 function d3_geom_voronoiRedBlackFirst(node) {
14507 while (node.L) node = node.L;
14508 return node;
14509 }
14510 function d3_geom_voronoi(sites, bbox) {
14511 var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
14512 d3_geom_voronoiEdges = [];
14513 d3_geom_voronoiCells = new Array(sites.length);
14514 d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
14515 d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
14516 while (true) {
14517 circle = d3_geom_voronoiFirstCircle;
14518 if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
14519 if (site.x !== x0 || site.y !== y0) {
14520 d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
14521 d3_geom_voronoiAddBeach(site);
14522 x0 = site.x, y0 = site.y;
14523 }
14524 site = sites.pop();
14525 } else if (circle) {
14526 d3_geom_voronoiRemoveBeach(circle.arc);
14527 } else {
14528 break;
14529 }
14530 }
14531 if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
14532 var diagram = {
14533 cells: d3_geom_voronoiCells,
14534 edges: d3_geom_voronoiEdges
14535 };
14536 d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
14537 return diagram;
14538 }
14539 function d3_geom_voronoiVertexOrder(a, b) {
14540 return b.y - a.y || b.x - a.x;
14541 }
14542 d3.geom.voronoi = function(points) {
14543 var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
14544 if (points) return voronoi(points);
14545 function voronoi(data) {
14546 var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
14547 d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
14548 var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
14549 var s = e.start();
14550 return [ s.x, s.y ];
14551 }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
14552 polygon.point = data[i];
14553 });
14554 return polygons;
14555 }
14556 function sites(data) {
14557 return data.map(function(d, i) {
14558 return {
14559 x: Math.round(fx(d, i) / ε) * ε,
14560 y: Math.round(fy(d, i) / ε) * ε,
14561 i: i
14562 };
14563 });
14564 }
14565 voronoi.links = function(data) {
14566 return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
14567 return edge.l && edge.r;
14568 }).map(function(edge) {
14569 return {
14570 source: data[edge.l.i],
14571 target: data[edge.r.i]
14572 };
14573 });
14574 };
14575 voronoi.triangles = function(data) {
14576 var triangles = [];
14577 d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
14578 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;
14579 while (++j < m) {
14580 e0 = e1;
14581 s0 = s1;
14582 e1 = edges[j].edge;
14583 s1 = e1.l === site ? e1.r : e1.l;
14584 if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
14585 triangles.push([ data[i], data[s0.i], data[s1.i] ]);
14586 }
14587 }
14588 });
14589 return triangles;
14590 };
14591 voronoi.x = function(_) {
14592 return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
14593 };
14594 voronoi.y = function(_) {
14595 return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
14596 };
14597 voronoi.clipExtent = function(_) {
14598 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
14599 clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
14600 return voronoi;
14601 };
14602 voronoi.size = function(_) {
14603 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
14604 return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
14605 };
14606 return voronoi;
14607 };
14608 var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
14609 function d3_geom_voronoiTriangleArea(a, b, c) {
14610 return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
14611 }
14612 d3.geom.delaunay = function(vertices) {
14613 return d3.geom.voronoi().triangles(vertices);
14614 };
14615 d3.geom.quadtree = function(points, x1, y1, x2, y2) {
14616 var x = d3_geom_pointX, y = d3_geom_pointY, compat;
14617 if (compat = arguments.length) {
14618 x = d3_geom_quadtreeCompatX;
14619 y = d3_geom_quadtreeCompatY;
14620 if (compat === 3) {
14621 y2 = y1;
14622 x2 = x1;
14623 y1 = x1 = 0;
14624 }
14625 return quadtree(points);
14626 }
14627 function quadtree(data) {
14628 var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
14629 if (x1 != null) {
14630 x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
14631 } else {
14632 x2_ = y2_ = -(x1_ = y1_ = Infinity);
14633 xs = [], ys = [];
14634 n = data.length;
14635 if (compat) for (i = 0; i < n; ++i) {
14636 d = data[i];
14637 if (d.x < x1_) x1_ = d.x;
14638 if (d.y < y1_) y1_ = d.y;
14639 if (d.x > x2_) x2_ = d.x;
14640 if (d.y > y2_) y2_ = d.y;
14641 xs.push(d.x);
14642 ys.push(d.y);
14643 } else for (i = 0; i < n; ++i) {
14644 var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
14645 if (x_ < x1_) x1_ = x_;
14646 if (y_ < y1_) y1_ = y_;
14647 if (x_ > x2_) x2_ = x_;
14648 if (y_ > y2_) y2_ = y_;
14649 xs.push(x_);
14650 ys.push(y_);
14651 }
14652 }
14653 var dx = x2_ - x1_, dy = y2_ - y1_;
14654 if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
14655 function insert(n, d, x, y, x1, y1, x2, y2) {
14656 if (isNaN(x) || isNaN(y)) return;
14657 if (n.leaf) {
14658 var nx = n.x, ny = n.y;
14659 if (nx != null) {
14660 if (abs(nx - x) + abs(ny - y) < .01) {
14661 insertChild(n, d, x, y, x1, y1, x2, y2);
14662 } else {
14663 var nPoint = n.point;
14664 n.x = n.y = n.point = null;
14665 insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
14666 insertChild(n, d, x, y, x1, y1, x2, y2);
14667 }
14668 } else {
14669 n.x = x, n.y = y, n.point = d;
14670 }
14671 } else {
14672 insertChild(n, d, x, y, x1, y1, x2, y2);
14673 }
14674 }
14675 function insertChild(n, d, x, y, x1, y1, x2, y2) {
14676 var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
14677 n.leaf = false;
14678 n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
14679 if (right) x1 = xm; else x2 = xm;
14680 if (below) y1 = ym; else y2 = ym;
14681 insert(n, d, x, y, x1, y1, x2, y2);
14682 }
14683 var root = d3_geom_quadtreeNode();
14684 root.add = function(d) {
14685 insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
14686 };
14687 root.visit = function(f) {
14688 d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
14689 };
14690 root.find = function(point) {
14691 return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
14692 };
14693 i = -1;
14694 if (x1 == null) {
14695 while (++i < n) {
14696 insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
14697 }
14698 --i;
14699 } else data.forEach(root.add);
14700 xs = ys = data = d = null;
14701 return root;
14702 }
14703 quadtree.x = function(_) {
14704 return arguments.length ? (x = _, quadtree) : x;
14705 };
14706 quadtree.y = function(_) {
14707 return arguments.length ? (y = _, quadtree) : y;
14708 };
14709 quadtree.extent = function(_) {
14710 if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
14711 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
14712 y2 = +_[1][1];
14713 return quadtree;
14714 };
14715 quadtree.size = function(_) {
14716 if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
14717 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
14718 return quadtree;
14719 };
14720 return quadtree;
14721 };
14722 function d3_geom_quadtreeCompatX(d) {
14723 return d.x;
14724 }
14725 function d3_geom_quadtreeCompatY(d) {
14726 return d.y;
14727 }
14728 function d3_geom_quadtreeNode() {
14729 return {
14730 leaf: true,
14731 nodes: [],
14732 point: null,
14733 x: null,
14734 y: null
14735 };
14736 }
14737 function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
14738 if (!f(node, x1, y1, x2, y2)) {
14739 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
14740 if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
14741 if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
14742 if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
14743 if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
14744 }
14745 }
14746 function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
14747 var minDistance2 = Infinity, closestPoint;
14748 (function find(node, x1, y1, x2, y2) {
14749 if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
14750 if (point = node.point) {
14751 var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
14752 if (distance2 < minDistance2) {
14753 var distance = Math.sqrt(minDistance2 = distance2);
14754 x0 = x - distance, y0 = y - distance;
14755 x3 = x + distance, y3 = y + distance;
14756 closestPoint = point;
14757 }
14758 }
14759 var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
14760 for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
14761 if (node = children[i & 3]) switch (i & 3) {
14762 case 0:
14763 find(node, x1, y1, xm, ym);
14764 break;
14765
14766 case 1:
14767 find(node, xm, y1, x2, ym);
14768 break;
14769
14770 case 2:
14771 find(node, x1, ym, xm, y2);
14772 break;
14773
14774 case 3:
14775 find(node, xm, ym, x2, y2);
14776 break;
14777 }
14778 }
14779 })(root, x0, y0, x3, y3);
14780 return closestPoint;
14781 }
14782 d3.interpolateRgb = d3_interpolateRgb;
14783 function d3_interpolateRgb(a, b) {
14784 a = d3.rgb(a);
14785 b = d3.rgb(b);
14786 var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
14787 return function(t) {
14788 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));
14789 };
14790 }
14791 d3.interpolateObject = d3_interpolateObject;
14792 function d3_interpolateObject(a, b) {
14793 var i = {}, c = {}, k;
14794 for (k in a) {
14795 if (k in b) {
14796 i[k] = d3_interpolate(a[k], b[k]);
14797 } else {
14798 c[k] = a[k];
14799 }
14800 }
14801 for (k in b) {
14802 if (!(k in a)) {
14803 c[k] = b[k];
14804 }
14805 }
14806 return function(t) {
14807 for (k in i) c[k] = i[k](t);
14808 return c;
14809 };
14810 }
14811 d3.interpolateNumber = d3_interpolateNumber;
14812 function d3_interpolateNumber(a, b) {
14813 a = +a, b = +b;
14814 return function(t) {
14815 return a * (1 - t) + b * t;
14816 };
14817 }
14818 d3.interpolateString = d3_interpolateString;
14819 function d3_interpolateString(a, b) {
14820 var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
14821 a = a + "", b = b + "";
14822 while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
14823 if ((bs = bm.index) > bi) {
14824 bs = b.slice(bi, bs);
14825 if (s[i]) s[i] += bs; else s[++i] = bs;
14826 }
14827 if ((am = am[0]) === (bm = bm[0])) {
14828 if (s[i]) s[i] += bm; else s[++i] = bm;
14829 } else {
14830 s[++i] = null;
14831 q.push({
14832 i: i,
14833 x: d3_interpolateNumber(am, bm)
14834 });
14835 }
14836 bi = d3_interpolate_numberB.lastIndex;
14837 }
14838 if (bi < b.length) {
14839 bs = b.slice(bi);
14840 if (s[i]) s[i] += bs; else s[++i] = bs;
14841 }
14842 return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
14843 return b(t) + "";
14844 }) : function() {
14845 return b;
14846 } : (b = q.length, function(t) {
14847 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
14848 return s.join("");
14849 });
14850 }
14851 var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
14852 d3.interpolate = d3_interpolate;
14853 function d3_interpolate(a, b) {
14854 var i = d3.interpolators.length, f;
14855 while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
14856 return f;
14857 }
14858 d3.interpolators = [ function(a, b) {
14859 var t = typeof b;
14860 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);
14861 } ];
14862 d3.interpolateArray = d3_interpolateArray;
14863 function d3_interpolateArray(a, b) {
14864 var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
14865 for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
14866 for (;i < na; ++i) c[i] = a[i];
14867 for (;i < nb; ++i) c[i] = b[i];
14868 return function(t) {
14869 for (i = 0; i < n0; ++i) c[i] = x[i](t);
14870 return c;
14871 };
14872 }
14873 var d3_ease_default = function() {
14874 return d3_identity;
14875 };
14876 var d3_ease = d3.map({
14877 linear: d3_ease_default,
14878 poly: d3_ease_poly,
14879 quad: function() {
14880 return d3_ease_quad;
14881 },
14882 cubic: function() {
14883 return d3_ease_cubic;
14884 },
14885 sin: function() {
14886 return d3_ease_sin;
14887 },
14888 exp: function() {
14889 return d3_ease_exp;
14890 },
14891 circle: function() {
14892 return d3_ease_circle;
14893 },
14894 elastic: d3_ease_elastic,
14895 back: d3_ease_back,
14896 bounce: function() {
14897 return d3_ease_bounce;
14898 }
14899 });
14900 var d3_ease_mode = d3.map({
14901 "in": d3_identity,
14902 out: d3_ease_reverse,
14903 "in-out": d3_ease_reflect,
14904 "out-in": function(f) {
14905 return d3_ease_reflect(d3_ease_reverse(f));
14906 }
14907 });
14908 d3.ease = function(name) {
14909 var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
14910 t = d3_ease.get(t) || d3_ease_default;
14911 m = d3_ease_mode.get(m) || d3_identity;
14912 return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
14913 };
14914 function d3_ease_clamp(f) {
14915 return function(t) {
14916 return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
14917 };
14918 }
14919 function d3_ease_reverse(f) {
14920 return function(t) {
14921 return 1 - f(1 - t);
14922 };
14923 }
14924 function d3_ease_reflect(f) {
14925 return function(t) {
14926 return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
14927 };
14928 }
14929 function d3_ease_quad(t) {
14930 return t * t;
14931 }
14932 function d3_ease_cubic(t) {
14933 return t * t * t;
14934 }
14935 function d3_ease_cubicInOut(t) {
14936 if (t <= 0) return 0;
14937 if (t >= 1) return 1;
14938 var t2 = t * t, t3 = t2 * t;
14939 return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
14940 }
14941 function d3_ease_poly(e) {
14942 return function(t) {
14943 return Math.pow(t, e);
14944 };
14945 }
14946 function d3_ease_sin(t) {
14947 return 1 - Math.cos(t * halfπ);
14948 }
14949 function d3_ease_exp(t) {
14950 return Math.pow(2, 10 * (t - 1));
14951 }
14952 function d3_ease_circle(t) {
14953 return 1 - Math.sqrt(1 - t * t);
14954 }
14955 function d3_ease_elastic(a, p) {
14956 var s;
14957 if (arguments.length < 2) p = .45;
14958 if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
14959 return function(t) {
14960 return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
14961 };
14962 }
14963 function d3_ease_back(s) {
14964 if (!s) s = 1.70158;
14965 return function(t) {
14966 return t * t * ((s + 1) * t - s);
14967 };
14968 }
14969 function d3_ease_bounce(t) {
14970 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;
14971 }
14972 d3.interpolateHcl = d3_interpolateHcl;
14973 function d3_interpolateHcl(a, b) {
14974 a = d3.hcl(a);
14975 b = d3.hcl(b);
14976 var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
14977 if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
14978 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
14979 return function(t) {
14980 return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
14981 };
14982 }
14983 d3.interpolateHsl = d3_interpolateHsl;
14984 function d3_interpolateHsl(a, b) {
14985 a = d3.hsl(a);
14986 b = d3.hsl(b);
14987 var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
14988 if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
14989 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
14990 return function(t) {
14991 return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
14992 };
14993 }
14994 d3.interpolateLab = d3_interpolateLab;
14995 function d3_interpolateLab(a, b) {
14996 a = d3.lab(a);
14997 b = d3.lab(b);
14998 var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
14999 return function(t) {
15000 return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
15001 };
15002 }
15003 d3.interpolateRound = d3_interpolateRound;
15004 function d3_interpolateRound(a, b) {
15005 b -= a;
15006 return function(t) {
15007 return Math.round(a + b * t);
15008 };
15009 }
15010 d3.transform = function(string) {
15011 var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
15012 return (d3.transform = function(string) {
15013 if (string != null) {
15014 g.setAttribute("transform", string);
15015 var t = g.transform.baseVal.consolidate();
15016 }
15017 return new d3_transform(t ? t.matrix : d3_transformIdentity);
15018 })(string);
15019 };
15020 function d3_transform(m) {
15021 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;
15022 if (r0[0] * r1[1] < r1[0] * r0[1]) {
15023 r0[0] *= -1;
15024 r0[1] *= -1;
15025 kx *= -1;
15026 kz *= -1;
15027 }
15028 this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
15029 this.translate = [ m.e, m.f ];
15030 this.scale = [ kx, ky ];
15031 this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
15032 }
15033 d3_transform.prototype.toString = function() {
15034 return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
15035 };
15036 function d3_transformDot(a, b) {
15037 return a[0] * b[0] + a[1] * b[1];
15038 }
15039 function d3_transformNormalize(a) {
15040 var k = Math.sqrt(d3_transformDot(a, a));
15041 if (k) {
15042 a[0] /= k;
15043 a[1] /= k;
15044 }
15045 return k;
15046 }
15047 function d3_transformCombine(a, b, k) {
15048 a[0] += k * b[0];
15049 a[1] += k * b[1];
15050 return a;
15051 }
15052 var d3_transformIdentity = {
15053 a: 1,
15054 b: 0,
15055 c: 0,
15056 d: 1,
15057 e: 0,
15058 f: 0
15059 };
15060 d3.interpolateTransform = d3_interpolateTransform;
15061 function d3_interpolateTransformPop(s) {
15062 return s.length ? s.pop() + "," : "";
15063 }
15064 function d3_interpolateTranslate(ta, tb, s, q) {
15065 if (ta[0] !== tb[0] || ta[1] !== tb[1]) {
15066 var i = s.push("translate(", null, ",", null, ")");
15067 q.push({
15068 i: i - 4,
15069 x: d3_interpolateNumber(ta[0], tb[0])
15070 }, {
15071 i: i - 2,
15072 x: d3_interpolateNumber(ta[1], tb[1])
15073 });
15074 } else if (tb[0] || tb[1]) {
15075 s.push("translate(" + tb + ")");
15076 }
15077 }
15078 function d3_interpolateRotate(ra, rb, s, q) {
15079 if (ra !== rb) {
15080 if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
15081 q.push({
15082 i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2,
15083 x: d3_interpolateNumber(ra, rb)
15084 });
15085 } else if (rb) {
15086 s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")");
15087 }
15088 }
15089 function d3_interpolateSkew(wa, wb, s, q) {
15090 if (wa !== wb) {
15091 q.push({
15092 i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2,
15093 x: d3_interpolateNumber(wa, wb)
15094 });
15095 } else if (wb) {
15096 s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")");
15097 }
15098 }
15099 function d3_interpolateScale(ka, kb, s, q) {
15100 if (ka[0] !== kb[0] || ka[1] !== kb[1]) {
15101 var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")");
15102 q.push({
15103 i: i - 4,
15104 x: d3_interpolateNumber(ka[0], kb[0])
15105 }, {
15106 i: i - 2,
15107 x: d3_interpolateNumber(ka[1], kb[1])
15108 });
15109 } else if (kb[0] !== 1 || kb[1] !== 1) {
15110 s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")");
15111 }
15112 }
15113 function d3_interpolateTransform(a, b) {
15114 var s = [], q = [];
15115 a = d3.transform(a), b = d3.transform(b);
15116 d3_interpolateTranslate(a.translate, b.translate, s, q);
15117 d3_interpolateRotate(a.rotate, b.rotate, s, q);
15118 d3_interpolateSkew(a.skew, b.skew, s, q);
15119 d3_interpolateScale(a.scale, b.scale, s, q);
15120 a = b = null;
15121 return function(t) {
15122 var i = -1, n = q.length, o;
15123 while (++i < n) s[(o = q[i]).i] = o.x(t);
15124 return s.join("");
15125 };
15126 }
15127 function d3_uninterpolateNumber(a, b) {
15128 b = (b -= a = +a) || 1 / b;
15129 return function(x) {
15130 return (x - a) / b;
15131 };
15132 }
15133 function d3_uninterpolateClamp(a, b) {
15134 b = (b -= a = +a) || 1 / b;
15135 return function(x) {
15136 return Math.max(0, Math.min(1, (x - a) / b));
15137 };
15138 }
15139 d3.layout = {};
15140 d3.layout.bundle = function() {
15141 return function(links) {
15142 var paths = [], i = -1, n = links.length;
15143 while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
15144 return paths;
15145 };
15146 };
15147 function d3_layout_bundlePath(link) {
15148 var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
15149 while (start !== lca) {
15150 start = start.parent;
15151 points.push(start);
15152 }
15153 var k = points.length;
15154 while (end !== lca) {
15155 points.splice(k, 0, end);
15156 end = end.parent;
15157 }
15158 return points;
15159 }
15160 function d3_layout_bundleAncestors(node) {
15161 var ancestors = [], parent = node.parent;
15162 while (parent != null) {
15163 ancestors.push(node);
15164 node = parent;
15165 parent = parent.parent;
15166 }
15167 ancestors.push(node);
15168 return ancestors;
15169 }
15170 function d3_layout_bundleLeastCommonAncestor(a, b) {
15171 if (a === b) return a;
15172 var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
15173 while (aNode === bNode) {
15174 sharedNode = aNode;
15175 aNode = aNodes.pop();
15176 bNode = bNodes.pop();
15177 }
15178 return sharedNode;
15179 }
15180 d3.layout.chord = function() {
15181 var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
15182 function relayout() {
15183 var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
15184 chords = [];
15185 groups = [];
15186 k = 0, i = -1;
15187 while (++i < n) {
15188 x = 0, j = -1;
15189 while (++j < n) {
15190 x += matrix[i][j];
15191 }
15192 groupSums.push(x);
15193 subgroupIndex.push(d3.range(n));
15194 k += x;
15195 }
15196 if (sortGroups) {
15197 groupIndex.sort(function(a, b) {
15198 return sortGroups(groupSums[a], groupSums[b]);
15199 });
15200 }
15201 if (sortSubgroups) {
15202 subgroupIndex.forEach(function(d, i) {
15203 d.sort(function(a, b) {
15204 return sortSubgroups(matrix[i][a], matrix[i][b]);
15205 });
15206 });
15207 }
15208 k = (τ - padding * n) / k;
15209 x = 0, i = -1;
15210 while (++i < n) {
15211 x0 = x, j = -1;
15212 while (++j < n) {
15213 var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
15214 subgroups[di + "-" + dj] = {
15215 index: di,
15216 subindex: dj,
15217 startAngle: a0,
15218 endAngle: a1,
15219 value: v
15220 };
15221 }
15222 groups[di] = {
15223 index: di,
15224 startAngle: x0,
15225 endAngle: x,
15226 value: groupSums[di]
15227 };
15228 x += padding;
15229 }
15230 i = -1;
15231 while (++i < n) {
15232 j = i - 1;
15233 while (++j < n) {
15234 var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
15235 if (source.value || target.value) {
15236 chords.push(source.value < target.value ? {
15237 source: target,
15238 target: source
15239 } : {
15240 source: source,
15241 target: target
15242 });
15243 }
15244 }
15245 }
15246 if (sortChords) resort();
15247 }
15248 function resort() {
15249 chords.sort(function(a, b) {
15250 return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
15251 });
15252 }
15253 chord.matrix = function(x) {
15254 if (!arguments.length) return matrix;
15255 n = (matrix = x) && matrix.length;
15256 chords = groups = null;
15257 return chord;
15258 };
15259 chord.padding = function(x) {
15260 if (!arguments.length) return padding;
15261 padding = x;
15262 chords = groups = null;
15263 return chord;
15264 };
15265 chord.sortGroups = function(x) {
15266 if (!arguments.length) return sortGroups;
15267 sortGroups = x;
15268 chords = groups = null;
15269 return chord;
15270 };
15271 chord.sortSubgroups = function(x) {
15272 if (!arguments.length) return sortSubgroups;
15273 sortSubgroups = x;
15274 chords = null;
15275 return chord;
15276 };
15277 chord.sortChords = function(x) {
15278 if (!arguments.length) return sortChords;
15279 sortChords = x;
15280 if (chords) resort();
15281 return chord;
15282 };
15283 chord.chords = function() {
15284 if (!chords) relayout();
15285 return chords;
15286 };
15287 chord.groups = function() {
15288 if (!groups) relayout();
15289 return groups;
15290 };
15291 return chord;
15292 };
15293 d3.layout.force = function() {
15294 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;
15295 function repulse(node) {
15296 return function(quad, x1, _, x2) {
15297 if (quad.point !== node) {
15298 var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
15299 if (dw * dw / theta2 < dn) {
15300 if (dn < chargeDistance2) {
15301 var k = quad.charge / dn;
15302 node.px -= dx * k;
15303 node.py -= dy * k;
15304 }
15305 return true;
15306 }
15307 if (quad.point && dn && dn < chargeDistance2) {
15308 var k = quad.pointCharge / dn;
15309 node.px -= dx * k;
15310 node.py -= dy * k;
15311 }
15312 }
15313 return !quad.charge;
15314 };
15315 }
15316 force.tick = function() {
15317 if ((alpha *= .99) < .005) {
15318 timer = null;
15319 event.end({
15320 type: "end",
15321 alpha: alpha = 0
15322 });
15323 return true;
15324 }
15325 var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
15326 for (i = 0; i < m; ++i) {
15327 o = links[i];
15328 s = o.source;
15329 t = o.target;
15330 x = t.x - s.x;
15331 y = t.y - s.y;
15332 if (l = x * x + y * y) {
15333 l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
15334 x *= l;
15335 y *= l;
15336 t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5);
15337 t.y -= y * k;
15338 s.x += x * (k = 1 - k);
15339 s.y += y * k;
15340 }
15341 }
15342 if (k = alpha * gravity) {
15343 x = size[0] / 2;
15344 y = size[1] / 2;
15345 i = -1;
15346 if (k) while (++i < n) {
15347 o = nodes[i];
15348 o.x += (x - o.x) * k;
15349 o.y += (y - o.y) * k;
15350 }
15351 }
15352 if (charge) {
15353 d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
15354 i = -1;
15355 while (++i < n) {
15356 if (!(o = nodes[i]).fixed) {
15357 q.visit(repulse(o));
15358 }
15359 }
15360 }
15361 i = -1;
15362 while (++i < n) {
15363 o = nodes[i];
15364 if (o.fixed) {
15365 o.x = o.px;
15366 o.y = o.py;
15367 } else {
15368 o.x -= (o.px - (o.px = o.x)) * friction;
15369 o.y -= (o.py - (o.py = o.y)) * friction;
15370 }
15371 }
15372 event.tick({
15373 type: "tick",
15374 alpha: alpha
15375 });
15376 };
15377 force.nodes = function(x) {
15378 if (!arguments.length) return nodes;
15379 nodes = x;
15380 return force;
15381 };
15382 force.links = function(x) {
15383 if (!arguments.length) return links;
15384 links = x;
15385 return force;
15386 };
15387 force.size = function(x) {
15388 if (!arguments.length) return size;
15389 size = x;
15390 return force;
15391 };
15392 force.linkDistance = function(x) {
15393 if (!arguments.length) return linkDistance;
15394 linkDistance = typeof x === "function" ? x : +x;
15395 return force;
15396 };
15397 force.distance = force.linkDistance;
15398 force.linkStrength = function(x) {
15399 if (!arguments.length) return linkStrength;
15400 linkStrength = typeof x === "function" ? x : +x;
15401 return force;
15402 };
15403 force.friction = function(x) {
15404 if (!arguments.length) return friction;
15405 friction = +x;
15406 return force;
15407 };
15408 force.charge = function(x) {
15409 if (!arguments.length) return charge;
15410 charge = typeof x === "function" ? x : +x;
15411 return force;
15412 };
15413 force.chargeDistance = function(x) {
15414 if (!arguments.length) return Math.sqrt(chargeDistance2);
15415 chargeDistance2 = x * x;
15416 return force;
15417 };
15418 force.gravity = function(x) {
15419 if (!arguments.length) return gravity;
15420 gravity = +x;
15421 return force;
15422 };
15423 force.theta = function(x) {
15424 if (!arguments.length) return Math.sqrt(theta2);
15425 theta2 = x * x;
15426 return force;
15427 };
15428 force.alpha = function(x) {
15429 if (!arguments.length) return alpha;
15430 x = +x;
15431 if (alpha) {
15432 if (x > 0) {
15433 alpha = x;
15434 } else {
15435 timer.c = null, timer.t = NaN, timer = null;
15436 event.end({
15437 type: "end",
15438 alpha: alpha = 0
15439 });
15440 }
15441 } else if (x > 0) {
15442 event.start({
15443 type: "start",
15444 alpha: alpha = x
15445 });
15446 timer = d3_timer(force.tick);
15447 }
15448 return force;
15449 };
15450 force.start = function() {
15451 var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
15452 for (i = 0; i < n; ++i) {
15453 (o = nodes[i]).index = i;
15454 o.weight = 0;
15455 }
15456 for (i = 0; i < m; ++i) {
15457 o = links[i];
15458 if (typeof o.source == "number") o.source = nodes[o.source];
15459 if (typeof o.target == "number") o.target = nodes[o.target];
15460 ++o.source.weight;
15461 ++o.target.weight;
15462 }
15463 for (i = 0; i < n; ++i) {
15464 o = nodes[i];
15465 if (isNaN(o.x)) o.x = position("x", w);
15466 if (isNaN(o.y)) o.y = position("y", h);
15467 if (isNaN(o.px)) o.px = o.x;
15468 if (isNaN(o.py)) o.py = o.y;
15469 }
15470 distances = [];
15471 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;
15472 strengths = [];
15473 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;
15474 charges = [];
15475 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;
15476 function position(dimension, size) {
15477 if (!neighbors) {
15478 neighbors = new Array(n);
15479 for (j = 0; j < n; ++j) {
15480 neighbors[j] = [];
15481 }
15482 for (j = 0; j < m; ++j) {
15483 var o = links[j];
15484 neighbors[o.source.index].push(o.target);
15485 neighbors[o.target.index].push(o.source);
15486 }
15487 }
15488 var candidates = neighbors[i], j = -1, l = candidates.length, x;
15489 while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
15490 return Math.random() * size;
15491 }
15492 return force.resume();
15493 };
15494 force.resume = function() {
15495 return force.alpha(.1);
15496 };
15497 force.stop = function() {
15498 return force.alpha(0);
15499 };
15500 force.drag = function() {
15501 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);
15502 if (!arguments.length) return drag;
15503 this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
15504 };
15505 function dragmove(d) {
15506 d.px = d3.event.x, d.py = d3.event.y;
15507 force.resume();
15508 }
15509 return d3.rebind(force, event, "on");
15510 };
15511 function d3_layout_forceDragstart(d) {
15512 d.fixed |= 2;
15513 }
15514 function d3_layout_forceDragend(d) {
15515 d.fixed &= ~6;
15516 }
15517 function d3_layout_forceMouseover(d) {
15518 d.fixed |= 4;
15519 d.px = d.x, d.py = d.y;
15520 }
15521 function d3_layout_forceMouseout(d) {
15522 d.fixed &= ~4;
15523 }
15524 function d3_layout_forceAccumulate(quad, alpha, charges) {
15525 var cx = 0, cy = 0;
15526 quad.charge = 0;
15527 if (!quad.leaf) {
15528 var nodes = quad.nodes, n = nodes.length, i = -1, c;
15529 while (++i < n) {
15530 c = nodes[i];
15531 if (c == null) continue;
15532 d3_layout_forceAccumulate(c, alpha, charges);
15533 quad.charge += c.charge;
15534 cx += c.charge * c.cx;
15535 cy += c.charge * c.cy;
15536 }
15537 }
15538 if (quad.point) {
15539 if (!quad.leaf) {
15540 quad.point.x += Math.random() - .5;
15541 quad.point.y += Math.random() - .5;
15542 }
15543 var k = alpha * charges[quad.point.index];
15544 quad.charge += quad.pointCharge = k;
15545 cx += k * quad.point.x;
15546 cy += k * quad.point.y;
15547 }
15548 quad.cx = cx / quad.charge;
15549 quad.cy = cy / quad.charge;
15550 }
15551 var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
15552 d3.layout.hierarchy = function() {
15553 var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
15554 function hierarchy(root) {
15555 var stack = [ root ], nodes = [], node;
15556 root.depth = 0;
15557 while ((node = stack.pop()) != null) {
15558 nodes.push(node);
15559 if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
15560 var n, childs, child;
15561 while (--n >= 0) {
15562 stack.push(child = childs[n]);
15563 child.parent = node;
15564 child.depth = node.depth + 1;
15565 }
15566 if (value) node.value = 0;
15567 node.children = childs;
15568 } else {
15569 if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
15570 delete node.children;
15571 }
15572 }
15573 d3_layout_hierarchyVisitAfter(root, function(node) {
15574 var childs, parent;
15575 if (sort && (childs = node.children)) childs.sort(sort);
15576 if (value && (parent = node.parent)) parent.value += node.value;
15577 });
15578 return nodes;
15579 }
15580 hierarchy.sort = function(x) {
15581 if (!arguments.length) return sort;
15582 sort = x;
15583 return hierarchy;
15584 };
15585 hierarchy.children = function(x) {
15586 if (!arguments.length) return children;
15587 children = x;
15588 return hierarchy;
15589 };
15590 hierarchy.value = function(x) {
15591 if (!arguments.length) return value;
15592 value = x;
15593 return hierarchy;
15594 };
15595 hierarchy.revalue = function(root) {
15596 if (value) {
15597 d3_layout_hierarchyVisitBefore(root, function(node) {
15598 if (node.children) node.value = 0;
15599 });
15600 d3_layout_hierarchyVisitAfter(root, function(node) {
15601 var parent;
15602 if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
15603 if (parent = node.parent) parent.value += node.value;
15604 });
15605 }
15606 return root;
15607 };
15608 return hierarchy;
15609 };
15610 function d3_layout_hierarchyRebind(object, hierarchy) {
15611 d3.rebind(object, hierarchy, "sort", "children", "value");
15612 object.nodes = object;
15613 object.links = d3_layout_hierarchyLinks;
15614 return object;
15615 }
15616 function d3_layout_hierarchyVisitBefore(node, callback) {
15617 var nodes = [ node ];
15618 while ((node = nodes.pop()) != null) {
15619 callback(node);
15620 if ((children = node.children) && (n = children.length)) {
15621 var n, children;
15622 while (--n >= 0) nodes.push(children[n]);
15623 }
15624 }
15625 }
15626 function d3_layout_hierarchyVisitAfter(node, callback) {
15627 var nodes = [ node ], nodes2 = [];
15628 while ((node = nodes.pop()) != null) {
15629 nodes2.push(node);
15630 if ((children = node.children) && (n = children.length)) {
15631 var i = -1, n, children;
15632 while (++i < n) nodes.push(children[i]);
15633 }
15634 }
15635 while ((node = nodes2.pop()) != null) {
15636 callback(node);
15637 }
15638 }
15639 function d3_layout_hierarchyChildren(d) {
15640 return d.children;
15641 }
15642 function d3_layout_hierarchyValue(d) {
15643 return d.value;
15644 }
15645 function d3_layout_hierarchySort(a, b) {
15646 return b.value - a.value;
15647 }
15648 function d3_layout_hierarchyLinks(nodes) {
15649 return d3.merge(nodes.map(function(parent) {
15650 return (parent.children || []).map(function(child) {
15651 return {
15652 source: parent,
15653 target: child
15654 };
15655 });
15656 }));
15657 }
15658 d3.layout.partition = function() {
15659 var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
15660 function position(node, x, dx, dy) {
15661 var children = node.children;
15662 node.x = x;
15663 node.y = node.depth * dy;
15664 node.dx = dx;
15665 node.dy = dy;
15666 if (children && (n = children.length)) {
15667 var i = -1, n, c, d;
15668 dx = node.value ? dx / node.value : 0;
15669 while (++i < n) {
15670 position(c = children[i], x, d = c.value * dx, dy);
15671 x += d;
15672 }
15673 }
15674 }
15675 function depth(node) {
15676 var children = node.children, d = 0;
15677 if (children && (n = children.length)) {
15678 var i = -1, n;
15679 while (++i < n) d = Math.max(d, depth(children[i]));
15680 }
15681 return 1 + d;
15682 }
15683 function partition(d, i) {
15684 var nodes = hierarchy.call(this, d, i);
15685 position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
15686 return nodes;
15687 }
15688 partition.size = function(x) {
15689 if (!arguments.length) return size;
15690 size = x;
15691 return partition;
15692 };
15693 return d3_layout_hierarchyRebind(partition, hierarchy);
15694 };
15695 d3.layout.pie = function() {
15696 var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
15697 function pie(data) {
15698 var n = data.length, values = data.map(function(d, i) {
15699 return +value.call(pie, d, i);
15700 }), 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;
15701 if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
15702 return values[j] - values[i];
15703 } : function(i, j) {
15704 return sort(data[i], data[j]);
15705 });
15706 index.forEach(function(i) {
15707 arcs[i] = {
15708 data: data[i],
15709 value: v = values[i],
15710 startAngle: a,
15711 endAngle: a += v * k + pa,
15712 padAngle: p
15713 };
15714 });
15715 return arcs;
15716 }
15717 pie.value = function(_) {
15718 if (!arguments.length) return value;
15719 value = _;
15720 return pie;
15721 };
15722 pie.sort = function(_) {
15723 if (!arguments.length) return sort;
15724 sort = _;
15725 return pie;
15726 };
15727 pie.startAngle = function(_) {
15728 if (!arguments.length) return startAngle;
15729 startAngle = _;
15730 return pie;
15731 };
15732 pie.endAngle = function(_) {
15733 if (!arguments.length) return endAngle;
15734 endAngle = _;
15735 return pie;
15736 };
15737 pie.padAngle = function(_) {
15738 if (!arguments.length) return padAngle;
15739 padAngle = _;
15740 return pie;
15741 };
15742 return pie;
15743 };
15744 var d3_layout_pieSortByValue = {};
15745 d3.layout.stack = function() {
15746 var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
15747 function stack(data, index) {
15748 if (!(n = data.length)) return data;
15749 var series = data.map(function(d, i) {
15750 return values.call(stack, d, i);
15751 });
15752 var points = series.map(function(d) {
15753 return d.map(function(v, i) {
15754 return [ x.call(stack, v, i), y.call(stack, v, i) ];
15755 });
15756 });
15757 var orders = order.call(stack, points, index);
15758 series = d3.permute(series, orders);
15759 points = d3.permute(points, orders);
15760 var offsets = offset.call(stack, points, index);
15761 var m = series[0].length, n, i, j, o;
15762 for (j = 0; j < m; ++j) {
15763 out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
15764 for (i = 1; i < n; ++i) {
15765 out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
15766 }
15767 }
15768 return data;
15769 }
15770 stack.values = function(x) {
15771 if (!arguments.length) return values;
15772 values = x;
15773 return stack;
15774 };
15775 stack.order = function(x) {
15776 if (!arguments.length) return order;
15777 order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
15778 return stack;
15779 };
15780 stack.offset = function(x) {
15781 if (!arguments.length) return offset;
15782 offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
15783 return stack;
15784 };
15785 stack.x = function(z) {
15786 if (!arguments.length) return x;
15787 x = z;
15788 return stack;
15789 };
15790 stack.y = function(z) {
15791 if (!arguments.length) return y;
15792 y = z;
15793 return stack;
15794 };
15795 stack.out = function(z) {
15796 if (!arguments.length) return out;
15797 out = z;
15798 return stack;
15799 };
15800 return stack;
15801 };
15802 function d3_layout_stackX(d) {
15803 return d.x;
15804 }
15805 function d3_layout_stackY(d) {
15806 return d.y;
15807 }
15808 function d3_layout_stackOut(d, y0, y) {
15809 d.y0 = y0;
15810 d.y = y;
15811 }
15812 var d3_layout_stackOrders = d3.map({
15813 "inside-out": function(data) {
15814 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) {
15815 return max[a] - max[b];
15816 }), top = 0, bottom = 0, tops = [], bottoms = [];
15817 for (i = 0; i < n; ++i) {
15818 j = index[i];
15819 if (top < bottom) {
15820 top += sums[j];
15821 tops.push(j);
15822 } else {
15823 bottom += sums[j];
15824 bottoms.push(j);
15825 }
15826 }
15827 return bottoms.reverse().concat(tops);
15828 },
15829 reverse: function(data) {
15830 return d3.range(data.length).reverse();
15831 },
15832 "default": d3_layout_stackOrderDefault
15833 });
15834 var d3_layout_stackOffsets = d3.map({
15835 silhouette: function(data) {
15836 var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
15837 for (j = 0; j < m; ++j) {
15838 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
15839 if (o > max) max = o;
15840 sums.push(o);
15841 }
15842 for (j = 0; j < m; ++j) {
15843 y0[j] = (max - sums[j]) / 2;
15844 }
15845 return y0;
15846 },
15847 wiggle: function(data) {
15848 var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
15849 y0[0] = o = o0 = 0;
15850 for (j = 1; j < m; ++j) {
15851 for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
15852 for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
15853 for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
15854 s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
15855 }
15856 s2 += s3 * data[i][j][1];
15857 }
15858 y0[j] = o -= s1 ? s2 / s1 * dx : 0;
15859 if (o < o0) o0 = o;
15860 }
15861 for (j = 0; j < m; ++j) y0[j] -= o0;
15862 return y0;
15863 },
15864 expand: function(data) {
15865 var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
15866 for (j = 0; j < m; ++j) {
15867 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
15868 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;
15869 }
15870 for (j = 0; j < m; ++j) y0[j] = 0;
15871 return y0;
15872 },
15873 zero: d3_layout_stackOffsetZero
15874 });
15875 function d3_layout_stackOrderDefault(data) {
15876 return d3.range(data.length);
15877 }
15878 function d3_layout_stackOffsetZero(data) {
15879 var j = -1, m = data[0].length, y0 = [];
15880 while (++j < m) y0[j] = 0;
15881 return y0;
15882 }
15883 function d3_layout_stackMaxIndex(array) {
15884 var i = 1, j = 0, v = array[0][1], k, n = array.length;
15885 for (;i < n; ++i) {
15886 if ((k = array[i][1]) > v) {
15887 j = i;
15888 v = k;
15889 }
15890 }
15891 return j;
15892 }
15893 function d3_layout_stackReduceSum(d) {
15894 return d.reduce(d3_layout_stackSum, 0);
15895 }
15896 function d3_layout_stackSum(p, d) {
15897 return p + d[1];
15898 }
15899 d3.layout.histogram = function() {
15900 var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
15901 function histogram(data, i) {
15902 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;
15903 while (++i < m) {
15904 bin = bins[i] = [];
15905 bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
15906 bin.y = 0;
15907 }
15908 if (m > 0) {
15909 i = -1;
15910 while (++i < n) {
15911 x = values[i];
15912 if (x >= range[0] && x <= range[1]) {
15913 bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
15914 bin.y += k;
15915 bin.push(data[i]);
15916 }
15917 }
15918 }
15919 return bins;
15920 }
15921 histogram.value = function(x) {
15922 if (!arguments.length) return valuer;
15923 valuer = x;
15924 return histogram;
15925 };
15926 histogram.range = function(x) {
15927 if (!arguments.length) return ranger;
15928 ranger = d3_functor(x);
15929 return histogram;
15930 };
15931 histogram.bins = function(x) {
15932 if (!arguments.length) return binner;
15933 binner = typeof x === "number" ? function(range) {
15934 return d3_layout_histogramBinFixed(range, x);
15935 } : d3_functor(x);
15936 return histogram;
15937 };
15938 histogram.frequency = function(x) {
15939 if (!arguments.length) return frequency;
15940 frequency = !!x;
15941 return histogram;
15942 };
15943 return histogram;
15944 };
15945 function d3_layout_histogramBinSturges(range, values) {
15946 return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
15947 }
15948 function d3_layout_histogramBinFixed(range, n) {
15949 var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
15950 while (++x <= n) f[x] = m * x + b;
15951 return f;
15952 }
15953 function d3_layout_histogramRange(values) {
15954 return [ d3.min(values), d3.max(values) ];
15955 }
15956 d3.layout.pack = function() {
15957 var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
15958 function pack(d, i) {
15959 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() {
15960 return radius;
15961 };
15962 root.x = root.y = 0;
15963 d3_layout_hierarchyVisitAfter(root, function(d) {
15964 d.r = +r(d.value);
15965 });
15966 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
15967 if (padding) {
15968 var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
15969 d3_layout_hierarchyVisitAfter(root, function(d) {
15970 d.r += dr;
15971 });
15972 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
15973 d3_layout_hierarchyVisitAfter(root, function(d) {
15974 d.r -= dr;
15975 });
15976 }
15977 d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
15978 return nodes;
15979 }
15980 pack.size = function(_) {
15981 if (!arguments.length) return size;
15982 size = _;
15983 return pack;
15984 };
15985 pack.radius = function(_) {
15986 if (!arguments.length) return radius;
15987 radius = _ == null || typeof _ === "function" ? _ : +_;
15988 return pack;
15989 };
15990 pack.padding = function(_) {
15991 if (!arguments.length) return padding;
15992 padding = +_;
15993 return pack;
15994 };
15995 return d3_layout_hierarchyRebind(pack, hierarchy);
15996 };
15997 function d3_layout_packSort(a, b) {
15998 return a.value - b.value;
15999 }
16000 function d3_layout_packInsert(a, b) {
16001 var c = a._pack_next;
16002 a._pack_next = b;
16003 b._pack_prev = a;
16004 b._pack_next = c;
16005 c._pack_prev = b;
16006 }
16007 function d3_layout_packSplice(a, b) {
16008 a._pack_next = b;
16009 b._pack_prev = a;
16010 }
16011 function d3_layout_packIntersects(a, b) {
16012 var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
16013 return .999 * dr * dr > dx * dx + dy * dy;
16014 }
16015 function d3_layout_packSiblings(node) {
16016 if (!(nodes = node.children) || !(n = nodes.length)) return;
16017 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
16018 function bound(node) {
16019 xMin = Math.min(node.x - node.r, xMin);
16020 xMax = Math.max(node.x + node.r, xMax);
16021 yMin = Math.min(node.y - node.r, yMin);
16022 yMax = Math.max(node.y + node.r, yMax);
16023 }
16024 nodes.forEach(d3_layout_packLink);
16025 a = nodes[0];
16026 a.x = -a.r;
16027 a.y = 0;
16028 bound(a);
16029 if (n > 1) {
16030 b = nodes[1];
16031 b.x = b.r;
16032 b.y = 0;
16033 bound(b);
16034 if (n > 2) {
16035 c = nodes[2];
16036 d3_layout_packPlace(a, b, c);
16037 bound(c);
16038 d3_layout_packInsert(a, c);
16039 a._pack_prev = c;
16040 d3_layout_packInsert(c, b);
16041 b = a._pack_next;
16042 for (i = 3; i < n; i++) {
16043 d3_layout_packPlace(a, b, c = nodes[i]);
16044 var isect = 0, s1 = 1, s2 = 1;
16045 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
16046 if (d3_layout_packIntersects(j, c)) {
16047 isect = 1;
16048 break;
16049 }
16050 }
16051 if (isect == 1) {
16052 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
16053 if (d3_layout_packIntersects(k, c)) {
16054 break;
16055 }
16056 }
16057 }
16058 if (isect) {
16059 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
16060 i--;
16061 } else {
16062 d3_layout_packInsert(a, c);
16063 b = c;
16064 bound(c);
16065 }
16066 }
16067 }
16068 }
16069 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
16070 for (i = 0; i < n; i++) {
16071 c = nodes[i];
16072 c.x -= cx;
16073 c.y -= cy;
16074 cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
16075 }
16076 node.r = cr;
16077 nodes.forEach(d3_layout_packUnlink);
16078 }
16079 function d3_layout_packLink(node) {
16080 node._pack_next = node._pack_prev = node;
16081 }
16082 function d3_layout_packUnlink(node) {
16083 delete node._pack_next;
16084 delete node._pack_prev;
16085 }
16086 function d3_layout_packTransform(node, x, y, k) {
16087 var children = node.children;
16088 node.x = x += k * node.x;
16089 node.y = y += k * node.y;
16090 node.r *= k;
16091 if (children) {
16092 var i = -1, n = children.length;
16093 while (++i < n) d3_layout_packTransform(children[i], x, y, k);
16094 }
16095 }
16096 function d3_layout_packPlace(a, b, c) {
16097 var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
16098 if (db && (dx || dy)) {
16099 var da = b.r + c.r, dc = dx * dx + dy * dy;
16100 da *= da;
16101 db *= db;
16102 var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
16103 c.x = a.x + x * dx + y * dy;
16104 c.y = a.y + x * dy - y * dx;
16105 } else {
16106 c.x = a.x + db;
16107 c.y = a.y;
16108 }
16109 }
16110 d3.layout.tree = function() {
16111 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
16112 function tree(d, i) {
16113 var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
16114 d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
16115 d3_layout_hierarchyVisitBefore(root1, secondWalk);
16116 if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
16117 var left = root0, right = root0, bottom = root0;
16118 d3_layout_hierarchyVisitBefore(root0, function(node) {
16119 if (node.x < left.x) left = node;
16120 if (node.x > right.x) right = node;
16121 if (node.depth > bottom.depth) bottom = node;
16122 });
16123 var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
16124 d3_layout_hierarchyVisitBefore(root0, function(node) {
16125 node.x = (node.x + tx) * kx;
16126 node.y = node.depth * ky;
16127 });
16128 }
16129 return nodes;
16130 }
16131 function wrapTree(root0) {
16132 var root1 = {
16133 A: null,
16134 children: [ root0 ]
16135 }, queue = [ root1 ], node1;
16136 while ((node1 = queue.pop()) != null) {
16137 for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
16138 queue.push((children[i] = child = {
16139 _: children[i],
16140 parent: node1,
16141 children: (child = children[i].children) && child.slice() || [],
16142 A: null,
16143 a: null,
16144 z: 0,
16145 m: 0,
16146 c: 0,
16147 s: 0,
16148 t: null,
16149 i: i
16150 }).a = child);
16151 }
16152 }
16153 return root1.children[0];
16154 }
16155 function firstWalk(v) {
16156 var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
16157 if (children.length) {
16158 d3_layout_treeShift(v);
16159 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
16160 if (w) {
16161 v.z = w.z + separation(v._, w._);
16162 v.m = v.z - midpoint;
16163 } else {
16164 v.z = midpoint;
16165 }
16166 } else if (w) {
16167 v.z = w.z + separation(v._, w._);
16168 }
16169 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
16170 }
16171 function secondWalk(v) {
16172 v._.x = v.z + v.parent.m;
16173 v.m += v.parent.m;
16174 }
16175 function apportion(v, w, ancestor) {
16176 if (w) {
16177 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;
16178 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
16179 vom = d3_layout_treeLeft(vom);
16180 vop = d3_layout_treeRight(vop);
16181 vop.a = v;
16182 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
16183 if (shift > 0) {
16184 d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
16185 sip += shift;
16186 sop += shift;
16187 }
16188 sim += vim.m;
16189 sip += vip.m;
16190 som += vom.m;
16191 sop += vop.m;
16192 }
16193 if (vim && !d3_layout_treeRight(vop)) {
16194 vop.t = vim;
16195 vop.m += sim - sop;
16196 }
16197 if (vip && !d3_layout_treeLeft(vom)) {
16198 vom.t = vip;
16199 vom.m += sip - som;
16200 ancestor = v;
16201 }
16202 }
16203 return ancestor;
16204 }
16205 function sizeNode(node) {
16206 node.x *= size[0];
16207 node.y = node.depth * size[1];
16208 }
16209 tree.separation = function(x) {
16210 if (!arguments.length) return separation;
16211 separation = x;
16212 return tree;
16213 };
16214 tree.size = function(x) {
16215 if (!arguments.length) return nodeSize ? null : size;
16216 nodeSize = (size = x) == null ? sizeNode : null;
16217 return tree;
16218 };
16219 tree.nodeSize = function(x) {
16220 if (!arguments.length) return nodeSize ? size : null;
16221 nodeSize = (size = x) == null ? null : sizeNode;
16222 return tree;
16223 };
16224 return d3_layout_hierarchyRebind(tree, hierarchy);
16225 };
16226 function d3_layout_treeSeparation(a, b) {
16227 return a.parent == b.parent ? 1 : 2;
16228 }
16229 function d3_layout_treeLeft(v) {
16230 var children = v.children;
16231 return children.length ? children[0] : v.t;
16232 }
16233 function d3_layout_treeRight(v) {
16234 var children = v.children, n;
16235 return (n = children.length) ? children[n - 1] : v.t;
16236 }
16237 function d3_layout_treeMove(wm, wp, shift) {
16238 var change = shift / (wp.i - wm.i);
16239 wp.c -= change;
16240 wp.s += shift;
16241 wm.c += change;
16242 wp.z += shift;
16243 wp.m += shift;
16244 }
16245 function d3_layout_treeShift(v) {
16246 var shift = 0, change = 0, children = v.children, i = children.length, w;
16247 while (--i >= 0) {
16248 w = children[i];
16249 w.z += shift;
16250 w.m += shift;
16251 shift += w.s + (change += w.c);
16252 }
16253 }
16254 function d3_layout_treeAncestor(vim, v, ancestor) {
16255 return vim.a.parent === v.parent ? vim.a : ancestor;
16256 }
16257 d3.layout.cluster = function() {
16258 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
16259 function cluster(d, i) {
16260 var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
16261 d3_layout_hierarchyVisitAfter(root, function(node) {
16262 var children = node.children;
16263 if (children && children.length) {
16264 node.x = d3_layout_clusterX(children);
16265 node.y = d3_layout_clusterY(children);
16266 } else {
16267 node.x = previousNode ? x += separation(node, previousNode) : 0;
16268 node.y = 0;
16269 previousNode = node;
16270 }
16271 });
16272 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;
16273 d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
16274 node.x = (node.x - root.x) * size[0];
16275 node.y = (root.y - node.y) * size[1];
16276 } : function(node) {
16277 node.x = (node.x - x0) / (x1 - x0) * size[0];
16278 node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
16279 });
16280 return nodes;
16281 }
16282 cluster.separation = function(x) {
16283 if (!arguments.length) return separation;
16284 separation = x;
16285 return cluster;
16286 };
16287 cluster.size = function(x) {
16288 if (!arguments.length) return nodeSize ? null : size;
16289 nodeSize = (size = x) == null;
16290 return cluster;
16291 };
16292 cluster.nodeSize = function(x) {
16293 if (!arguments.length) return nodeSize ? size : null;
16294 nodeSize = (size = x) != null;
16295 return cluster;
16296 };
16297 return d3_layout_hierarchyRebind(cluster, hierarchy);
16298 };
16299 function d3_layout_clusterY(children) {
16300 return 1 + d3.max(children, function(child) {
16301 return child.y;
16302 });
16303 }
16304 function d3_layout_clusterX(children) {
16305 return children.reduce(function(x, child) {
16306 return x + child.x;
16307 }, 0) / children.length;
16308 }
16309 function d3_layout_clusterLeft(node) {
16310 var children = node.children;
16311 return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
16312 }
16313 function d3_layout_clusterRight(node) {
16314 var children = node.children, n;
16315 return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
16316 }
16317 d3.layout.treemap = function() {
16318 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));
16319 function scale(children, k) {
16320 var i = -1, n = children.length, child, area;
16321 while (++i < n) {
16322 area = (child = children[i]).value * (k < 0 ? 0 : k);
16323 child.area = isNaN(area) || area <= 0 ? 0 : area;
16324 }
16325 }
16326 function squarify(node) {
16327 var children = node.children;
16328 if (children && children.length) {
16329 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;
16330 scale(remaining, rect.dx * rect.dy / node.value);
16331 row.area = 0;
16332 while ((n = remaining.length) > 0) {
16333 row.push(child = remaining[n - 1]);
16334 row.area += child.area;
16335 if (mode !== "squarify" || (score = worst(row, u)) <= best) {
16336 remaining.pop();
16337 best = score;
16338 } else {
16339 row.area -= row.pop().area;
16340 position(row, u, rect, false);
16341 u = Math.min(rect.dx, rect.dy);
16342 row.length = row.area = 0;
16343 best = Infinity;
16344 }
16345 }
16346 if (row.length) {
16347 position(row, u, rect, true);
16348 row.length = row.area = 0;
16349 }
16350 children.forEach(squarify);
16351 }
16352 }
16353 function stickify(node) {
16354 var children = node.children;
16355 if (children && children.length) {
16356 var rect = pad(node), remaining = children.slice(), child, row = [];
16357 scale(remaining, rect.dx * rect.dy / node.value);
16358 row.area = 0;
16359 while (child = remaining.pop()) {
16360 row.push(child);
16361 row.area += child.area;
16362 if (child.z != null) {
16363 position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
16364 row.length = row.area = 0;
16365 }
16366 }
16367 children.forEach(stickify);
16368 }
16369 }
16370 function worst(row, u) {
16371 var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
16372 while (++i < n) {
16373 if (!(r = row[i].area)) continue;
16374 if (r < rmin) rmin = r;
16375 if (r > rmax) rmax = r;
16376 }
16377 s *= s;
16378 u *= u;
16379 return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
16380 }
16381 function position(row, u, rect, flush) {
16382 var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
16383 if (u == rect.dx) {
16384 if (flush || v > rect.dy) v = rect.dy;
16385 while (++i < n) {
16386 o = row[i];
16387 o.x = x;
16388 o.y = y;
16389 o.dy = v;
16390 x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
16391 }
16392 o.z = true;
16393 o.dx += rect.x + rect.dx - x;
16394 rect.y += v;
16395 rect.dy -= v;
16396 } else {
16397 if (flush || v > rect.dx) v = rect.dx;
16398 while (++i < n) {
16399 o = row[i];
16400 o.x = x;
16401 o.y = y;
16402 o.dx = v;
16403 y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
16404 }
16405 o.z = false;
16406 o.dy += rect.y + rect.dy - y;
16407 rect.x += v;
16408 rect.dx -= v;
16409 }
16410 }
16411 function treemap(d) {
16412 var nodes = stickies || hierarchy(d), root = nodes[0];
16413 root.x = root.y = 0;
16414 if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;
16415 if (stickies) hierarchy.revalue(root);
16416 scale([ root ], root.dx * root.dy / root.value);
16417 (stickies ? stickify : squarify)(root);
16418 if (sticky) stickies = nodes;
16419 return nodes;
16420 }
16421 treemap.size = function(x) {
16422 if (!arguments.length) return size;
16423 size = x;
16424 return treemap;
16425 };
16426 treemap.padding = function(x) {
16427 if (!arguments.length) return padding;
16428 function padFunction(node) {
16429 var p = x.call(treemap, node, node.depth);
16430 return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
16431 }
16432 function padConstant(node) {
16433 return d3_layout_treemapPad(node, x);
16434 }
16435 var type;
16436 pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
16437 padConstant) : padConstant;
16438 return treemap;
16439 };
16440 treemap.round = function(x) {
16441 if (!arguments.length) return round != Number;
16442 round = x ? Math.round : Number;
16443 return treemap;
16444 };
16445 treemap.sticky = function(x) {
16446 if (!arguments.length) return sticky;
16447 sticky = x;
16448 stickies = null;
16449 return treemap;
16450 };
16451 treemap.ratio = function(x) {
16452 if (!arguments.length) return ratio;
16453 ratio = x;
16454 return treemap;
16455 };
16456 treemap.mode = function(x) {
16457 if (!arguments.length) return mode;
16458 mode = x + "";
16459 return treemap;
16460 };
16461 return d3_layout_hierarchyRebind(treemap, hierarchy);
16462 };
16463 function d3_layout_treemapPadNull(node) {
16464 return {
16465 x: node.x,
16466 y: node.y,
16467 dx: node.dx,
16468 dy: node.dy
16469 };
16470 }
16471 function d3_layout_treemapPad(node, padding) {
16472 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];
16473 if (dx < 0) {
16474 x += dx / 2;
16475 dx = 0;
16476 }
16477 if (dy < 0) {
16478 y += dy / 2;
16479 dy = 0;
16480 }
16481 return {
16482 x: x,
16483 y: y,
16484 dx: dx,
16485 dy: dy
16486 };
16487 }
16488 d3.random = {
16489 normal: function(µ, σ) {
16490 var n = arguments.length;
16491 if (n < 2) σ = 1;
16492 if (n < 1) µ = 0;
16493 return function() {
16494 var x, y, r;
16495 do {
16496 x = Math.random() * 2 - 1;
16497 y = Math.random() * 2 - 1;
16498 r = x * x + y * y;
16499 } while (!r || r > 1);
16500 return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
16501 };
16502 },
16503 logNormal: function() {
16504 var random = d3.random.normal.apply(d3, arguments);
16505 return function() {
16506 return Math.exp(random());
16507 };
16508 },
16509 bates: function(m) {
16510 var random = d3.random.irwinHall(m);
16511 return function() {
16512 return random() / m;
16513 };
16514 },
16515 irwinHall: function(m) {
16516 return function() {
16517 for (var s = 0, j = 0; j < m; j++) s += Math.random();
16518 return s;
16519 };
16520 }
16521 };
16522 d3.scale = {};
16523 function d3_scaleExtent(domain) {
16524 var start = domain[0], stop = domain[domain.length - 1];
16525 return start < stop ? [ start, stop ] : [ stop, start ];
16526 }
16527 function d3_scaleRange(scale) {
16528 return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
16529 }
16530 function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
16531 var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
16532 return function(x) {
16533 return i(u(x));
16534 };
16535 }
16536 function d3_scale_nice(domain, nice) {
16537 var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
16538 if (x1 < x0) {
16539 dx = i0, i0 = i1, i1 = dx;
16540 dx = x0, x0 = x1, x1 = dx;
16541 }
16542 domain[i0] = nice.floor(x0);
16543 domain[i1] = nice.ceil(x1);
16544 return domain;
16545 }
16546 function d3_scale_niceStep(step) {
16547 return step ? {
16548 floor: function(x) {
16549 return Math.floor(x / step) * step;
16550 },
16551 ceil: function(x) {
16552 return Math.ceil(x / step) * step;
16553 }
16554 } : d3_scale_niceIdentity;
16555 }
16556 var d3_scale_niceIdentity = {
16557 floor: d3_identity,
16558 ceil: d3_identity
16559 };
16560 function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
16561 var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
16562 if (domain[k] < domain[0]) {
16563 domain = domain.slice().reverse();
16564 range = range.slice().reverse();
16565 }
16566 while (++j <= k) {
16567 u.push(uninterpolate(domain[j - 1], domain[j]));
16568 i.push(interpolate(range[j - 1], range[j]));
16569 }
16570 return function(x) {
16571 var j = d3.bisect(domain, x, 1, k) - 1;
16572 return i[j](u[j](x));
16573 };
16574 }
16575 d3.scale.linear = function() {
16576 return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
16577 };
16578 function d3_scale_linear(domain, range, interpolate, clamp) {
16579 var output, input;
16580 function rescale() {
16581 var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
16582 output = linear(domain, range, uninterpolate, interpolate);
16583 input = linear(range, domain, uninterpolate, d3_interpolate);
16584 return scale;
16585 }
16586 function scale(x) {
16587 return output(x);
16588 }
16589 scale.invert = function(y) {
16590 return input(y);
16591 };
16592 scale.domain = function(x) {
16593 if (!arguments.length) return domain;
16594 domain = x.map(Number);
16595 return rescale();
16596 };
16597 scale.range = function(x) {
16598 if (!arguments.length) return range;
16599 range = x;
16600 return rescale();
16601 };
16602 scale.rangeRound = function(x) {
16603 return scale.range(x).interpolate(d3_interpolateRound);
16604 };
16605 scale.clamp = function(x) {
16606 if (!arguments.length) return clamp;
16607 clamp = x;
16608 return rescale();
16609 };
16610 scale.interpolate = function(x) {
16611 if (!arguments.length) return interpolate;
16612 interpolate = x;
16613 return rescale();
16614 };
16615 scale.ticks = function(m) {
16616 return d3_scale_linearTicks(domain, m);
16617 };
16618 scale.tickFormat = function(m, format) {
16619 return d3_scale_linearTickFormat(domain, m, format);
16620 };
16621 scale.nice = function(m) {
16622 d3_scale_linearNice(domain, m);
16623 return rescale();
16624 };
16625 scale.copy = function() {
16626 return d3_scale_linear(domain, range, interpolate, clamp);
16627 };
16628 return rescale();
16629 }
16630 function d3_scale_linearRebind(scale, linear) {
16631 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
16632 }
16633 function d3_scale_linearNice(domain, m) {
16634 d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
16635 d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
16636 return domain;
16637 }
16638 function d3_scale_linearTickRange(domain, m) {
16639 if (m == null) m = 10;
16640 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;
16641 if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
16642 extent[0] = Math.ceil(extent[0] / step) * step;
16643 extent[1] = Math.floor(extent[1] / step) * step + step * .5;
16644 extent[2] = step;
16645 return extent;
16646 }
16647 function d3_scale_linearTicks(domain, m) {
16648 return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
16649 }
16650 function d3_scale_linearTickFormat(domain, m, format) {
16651 var range = d3_scale_linearTickRange(domain, m);
16652 if (format) {
16653 var match = d3_format_re.exec(format);
16654 match.shift();
16655 if (match[8] === "s") {
16656 var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
16657 if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
16658 match[8] = "f";
16659 format = d3.format(match.join(""));
16660 return function(d) {
16661 return format(prefix.scale(d)) + prefix.symbol;
16662 };
16663 }
16664 if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
16665 format = match.join("");
16666 } else {
16667 format = ",." + d3_scale_linearPrecision(range[2]) + "f";
16668 }
16669 return d3.format(format);
16670 }
16671 var d3_scale_linearFormatSignificant = {
16672 s: 1,
16673 g: 1,
16674 p: 1,
16675 r: 1,
16676 e: 1
16677 };
16678 function d3_scale_linearPrecision(value) {
16679 return -Math.floor(Math.log(value) / Math.LN10 + .01);
16680 }
16681 function d3_scale_linearFormatPrecision(type, range) {
16682 var p = d3_scale_linearPrecision(range[2]);
16683 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;
16684 }
16685 d3.scale.log = function() {
16686 return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
16687 };
16688 function d3_scale_log(linear, base, positive, domain) {
16689 function log(x) {
16690 return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
16691 }
16692 function pow(x) {
16693 return positive ? Math.pow(base, x) : -Math.pow(base, -x);
16694 }
16695 function scale(x) {
16696 return linear(log(x));
16697 }
16698 scale.invert = function(x) {
16699 return pow(linear.invert(x));
16700 };
16701 scale.domain = function(x) {
16702 if (!arguments.length) return domain;
16703 positive = x[0] >= 0;
16704 linear.domain((domain = x.map(Number)).map(log));
16705 return scale;
16706 };
16707 scale.base = function(_) {
16708 if (!arguments.length) return base;
16709 base = +_;
16710 linear.domain(domain.map(log));
16711 return scale;
16712 };
16713 scale.nice = function() {
16714 var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
16715 linear.domain(niced);
16716 domain = niced.map(pow);
16717 return scale;
16718 };
16719 scale.ticks = function() {
16720 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;
16721 if (isFinite(j - i)) {
16722 if (positive) {
16723 for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
16724 ticks.push(pow(i));
16725 } else {
16726 ticks.push(pow(i));
16727 for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
16728 }
16729 for (i = 0; ticks[i] < u; i++) {}
16730 for (j = ticks.length; ticks[j - 1] > v; j--) {}
16731 ticks = ticks.slice(i, j);
16732 }
16733 return ticks;
16734 };
16735 scale.tickFormat = function(n, format) {
16736 if (!arguments.length) return d3_scale_logFormat;
16737 if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
16738 var k = Math.max(1, base * n / scale.ticks().length);
16739 return function(d) {
16740 var i = d / pow(Math.round(log(d)));
16741 if (i * base < base - .5) i *= base;
16742 return i <= k ? format(d) : "";
16743 };
16744 };
16745 scale.copy = function() {
16746 return d3_scale_log(linear.copy(), base, positive, domain);
16747 };
16748 return d3_scale_linearRebind(scale, linear);
16749 }
16750 var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
16751 floor: function(x) {
16752 return -Math.ceil(-x);
16753 },
16754 ceil: function(x) {
16755 return -Math.floor(-x);
16756 }
16757 };
16758 d3.scale.pow = function() {
16759 return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
16760 };
16761 function d3_scale_pow(linear, exponent, domain) {
16762 var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
16763 function scale(x) {
16764 return linear(powp(x));
16765 }
16766 scale.invert = function(x) {
16767 return powb(linear.invert(x));
16768 };
16769 scale.domain = function(x) {
16770 if (!arguments.length) return domain;
16771 linear.domain((domain = x.map(Number)).map(powp));
16772 return scale;
16773 };
16774 scale.ticks = function(m) {
16775 return d3_scale_linearTicks(domain, m);
16776 };
16777 scale.tickFormat = function(m, format) {
16778 return d3_scale_linearTickFormat(domain, m, format);
16779 };
16780 scale.nice = function(m) {
16781 return scale.domain(d3_scale_linearNice(domain, m));
16782 };
16783 scale.exponent = function(x) {
16784 if (!arguments.length) return exponent;
16785 powp = d3_scale_powPow(exponent = x);
16786 powb = d3_scale_powPow(1 / exponent);
16787 linear.domain(domain.map(powp));
16788 return scale;
16789 };
16790 scale.copy = function() {
16791 return d3_scale_pow(linear.copy(), exponent, domain);
16792 };
16793 return d3_scale_linearRebind(scale, linear);
16794 }
16795 function d3_scale_powPow(e) {
16796 return function(x) {
16797 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
16798 };
16799 }
16800 d3.scale.sqrt = function() {
16801 return d3.scale.pow().exponent(.5);
16802 };
16803 d3.scale.ordinal = function() {
16804 return d3_scale_ordinal([], {
16805 t: "range",
16806 a: [ [] ]
16807 });
16808 };
16809 function d3_scale_ordinal(domain, ranger) {
16810 var index, range, rangeBand;
16811 function scale(x) {
16812 return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
16813 }
16814 function steps(start, step) {
16815 return d3.range(domain.length).map(function(i) {
16816 return start + step * i;
16817 });
16818 }
16819 scale.domain = function(x) {
16820 if (!arguments.length) return domain;
16821 domain = [];
16822 index = new d3_Map();
16823 var i = -1, n = x.length, xi;
16824 while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
16825 return scale[ranger.t].apply(scale, ranger.a);
16826 };
16827 scale.range = function(x) {
16828 if (!arguments.length) return range;
16829 range = x;
16830 rangeBand = 0;
16831 ranger = {
16832 t: "range",
16833 a: arguments
16834 };
16835 return scale;
16836 };
16837 scale.rangePoints = function(x, padding) {
16838 if (arguments.length < 2) padding = 0;
16839 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
16840 0) : (stop - start) / (domain.length - 1 + padding);
16841 range = steps(start + step * padding / 2, step);
16842 rangeBand = 0;
16843 ranger = {
16844 t: "rangePoints",
16845 a: arguments
16846 };
16847 return scale;
16848 };
16849 scale.rangeRoundPoints = function(x, padding) {
16850 if (arguments.length < 2) padding = 0;
16851 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
16852 0) : (stop - start) / (domain.length - 1 + padding) | 0;
16853 range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
16854 rangeBand = 0;
16855 ranger = {
16856 t: "rangeRoundPoints",
16857 a: arguments
16858 };
16859 return scale;
16860 };
16861 scale.rangeBands = function(x, padding, outerPadding) {
16862 if (arguments.length < 2) padding = 0;
16863 if (arguments.length < 3) outerPadding = padding;
16864 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
16865 range = steps(start + step * outerPadding, step);
16866 if (reverse) range.reverse();
16867 rangeBand = step * (1 - padding);
16868 ranger = {
16869 t: "rangeBands",
16870 a: arguments
16871 };
16872 return scale;
16873 };
16874 scale.rangeRoundBands = function(x, padding, outerPadding) {
16875 if (arguments.length < 2) padding = 0;
16876 if (arguments.length < 3) outerPadding = padding;
16877 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
16878 range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
16879 if (reverse) range.reverse();
16880 rangeBand = Math.round(step * (1 - padding));
16881 ranger = {
16882 t: "rangeRoundBands",
16883 a: arguments
16884 };
16885 return scale;
16886 };
16887 scale.rangeBand = function() {
16888 return rangeBand;
16889 };
16890 scale.rangeExtent = function() {
16891 return d3_scaleExtent(ranger.a[0]);
16892 };
16893 scale.copy = function() {
16894 return d3_scale_ordinal(domain, ranger);
16895 };
16896 return scale.domain(domain);
16897 }
16898 d3.scale.category10 = function() {
16899 return d3.scale.ordinal().range(d3_category10);
16900 };
16901 d3.scale.category20 = function() {
16902 return d3.scale.ordinal().range(d3_category20);
16903 };
16904 d3.scale.category20b = function() {
16905 return d3.scale.ordinal().range(d3_category20b);
16906 };
16907 d3.scale.category20c = function() {
16908 return d3.scale.ordinal().range(d3_category20c);
16909 };
16910 var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
16911 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);
16912 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);
16913 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);
16914 d3.scale.quantile = function() {
16915 return d3_scale_quantile([], []);
16916 };
16917 function d3_scale_quantile(domain, range) {
16918 var thresholds;
16919 function rescale() {
16920 var k = 0, q = range.length;
16921 thresholds = [];
16922 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
16923 return scale;
16924 }
16925 function scale(x) {
16926 if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
16927 }
16928 scale.domain = function(x) {
16929 if (!arguments.length) return domain;
16930 domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
16931 return rescale();
16932 };
16933 scale.range = function(x) {
16934 if (!arguments.length) return range;
16935 range = x;
16936 return rescale();
16937 };
16938 scale.quantiles = function() {
16939 return thresholds;
16940 };
16941 scale.invertExtent = function(y) {
16942 y = range.indexOf(y);
16943 return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
16944 };
16945 scale.copy = function() {
16946 return d3_scale_quantile(domain, range);
16947 };
16948 return rescale();
16949 }
16950 d3.scale.quantize = function() {
16951 return d3_scale_quantize(0, 1, [ 0, 1 ]);
16952 };
16953 function d3_scale_quantize(x0, x1, range) {
16954 var kx, i;
16955 function scale(x) {
16956 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
16957 }
16958 function rescale() {
16959 kx = range.length / (x1 - x0);
16960 i = range.length - 1;
16961 return scale;
16962 }
16963 scale.domain = function(x) {
16964 if (!arguments.length) return [ x0, x1 ];
16965 x0 = +x[0];
16966 x1 = +x[x.length - 1];
16967 return rescale();
16968 };
16969 scale.range = function(x) {
16970 if (!arguments.length) return range;
16971 range = x;
16972 return rescale();
16973 };
16974 scale.invertExtent = function(y) {
16975 y = range.indexOf(y);
16976 y = y < 0 ? NaN : y / kx + x0;
16977 return [ y, y + 1 / kx ];
16978 };
16979 scale.copy = function() {
16980 return d3_scale_quantize(x0, x1, range);
16981 };
16982 return rescale();
16983 }
16984 d3.scale.threshold = function() {
16985 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
16986 };
16987 function d3_scale_threshold(domain, range) {
16988 function scale(x) {
16989 if (x <= x) return range[d3.bisect(domain, x)];
16990 }
16991 scale.domain = function(_) {
16992 if (!arguments.length) return domain;
16993 domain = _;
16994 return scale;
16995 };
16996 scale.range = function(_) {
16997 if (!arguments.length) return range;
16998 range = _;
16999 return scale;
17000 };
17001 scale.invertExtent = function(y) {
17002 y = range.indexOf(y);
17003 return [ domain[y - 1], domain[y] ];
17004 };
17005 scale.copy = function() {
17006 return d3_scale_threshold(domain, range);
17007 };
17008 return scale;
17009 }
17010 d3.scale.identity = function() {
17011 return d3_scale_identity([ 0, 1 ]);
17012 };
17013 function d3_scale_identity(domain) {
17014 function identity(x) {
17015 return +x;
17016 }
17017 identity.invert = identity;
17018 identity.domain = identity.range = function(x) {
17019 if (!arguments.length) return domain;
17020 domain = x.map(identity);
17021 return identity;
17022 };
17023 identity.ticks = function(m) {
17024 return d3_scale_linearTicks(domain, m);
17025 };
17026 identity.tickFormat = function(m, format) {
17027 return d3_scale_linearTickFormat(domain, m, format);
17028 };
17029 identity.copy = function() {
17030 return d3_scale_identity(domain);
17031 };
17032 return identity;
17033 }
17034 d3.svg = {};
17035 function d3_zero() {
17036 return 0;
17037 }
17038 d3.svg.arc = function() {
17039 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;
17040 function arc() {
17041 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;
17042 if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
17043 if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
17044 var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
17045 if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
17046 rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
17047 if (!cw) p1 *= -1;
17048 if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
17049 if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
17050 }
17051 if (r1) {
17052 x0 = r1 * Math.cos(a0 + p1);
17053 y0 = r1 * Math.sin(a0 + p1);
17054 x1 = r1 * Math.cos(a1 - p1);
17055 y1 = r1 * Math.sin(a1 - p1);
17056 var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
17057 if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
17058 var h1 = (a0 + a1) / 2;
17059 x0 = r1 * Math.cos(h1);
17060 y0 = r1 * Math.sin(h1);
17061 x1 = y1 = null;
17062 }
17063 } else {
17064 x0 = y0 = 0;
17065 }
17066 if (r0) {
17067 x2 = r0 * Math.cos(a1 - p0);
17068 y2 = r0 * Math.sin(a1 - p0);
17069 x3 = r0 * Math.cos(a0 + p0);
17070 y3 = r0 * Math.sin(a0 + p0);
17071 var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
17072 if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
17073 var h0 = (a0 + a1) / 2;
17074 x2 = r0 * Math.cos(h0);
17075 y2 = r0 * Math.sin(h0);
17076 x3 = y3 = null;
17077 }
17078 } else {
17079 x2 = y2 = 0;
17080 }
17081 if (da > ε && (rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
17082 cr = r0 < r1 ^ cw ? 0 : 1;
17083 var rc1 = rc, rc0 = rc;
17084 if (da < π) {
17085 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]);
17086 rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
17087 rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
17088 }
17089 if (x1 != null) {
17090 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);
17091 if (rc === rc1) {
17092 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]);
17093 } else {
17094 path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
17095 }
17096 } else {
17097 path.push("M", x0, ",", y0);
17098 }
17099 if (x3 != null) {
17100 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);
17101 if (rc === rc0) {
17102 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]);
17103 } else {
17104 path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
17105 }
17106 } else {
17107 path.push("L", x2, ",", y2);
17108 }
17109 } else {
17110 path.push("M", x0, ",", y0);
17111 if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
17112 path.push("L", x2, ",", y2);
17113 if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
17114 }
17115 path.push("Z");
17116 return path.join("");
17117 }
17118 function circleSegment(r1, cw) {
17119 return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
17120 }
17121 arc.innerRadius = function(v) {
17122 if (!arguments.length) return innerRadius;
17123 innerRadius = d3_functor(v);
17124 return arc;
17125 };
17126 arc.outerRadius = function(v) {
17127 if (!arguments.length) return outerRadius;
17128 outerRadius = d3_functor(v);
17129 return arc;
17130 };
17131 arc.cornerRadius = function(v) {
17132 if (!arguments.length) return cornerRadius;
17133 cornerRadius = d3_functor(v);
17134 return arc;
17135 };
17136 arc.padRadius = function(v) {
17137 if (!arguments.length) return padRadius;
17138 padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
17139 return arc;
17140 };
17141 arc.startAngle = function(v) {
17142 if (!arguments.length) return startAngle;
17143 startAngle = d3_functor(v);
17144 return arc;
17145 };
17146 arc.endAngle = function(v) {
17147 if (!arguments.length) return endAngle;
17148 endAngle = d3_functor(v);
17149 return arc;
17150 };
17151 arc.padAngle = function(v) {
17152 if (!arguments.length) return padAngle;
17153 padAngle = d3_functor(v);
17154 return arc;
17155 };
17156 arc.centroid = function() {
17157 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
17158 return [ Math.cos(a) * r, Math.sin(a) * r ];
17159 };
17160 return arc;
17161 };
17162 var d3_svg_arcAuto = "auto";
17163 function d3_svg_arcInnerRadius(d) {
17164 return d.innerRadius;
17165 }
17166 function d3_svg_arcOuterRadius(d) {
17167 return d.outerRadius;
17168 }
17169 function d3_svg_arcStartAngle(d) {
17170 return d.startAngle;
17171 }
17172 function d3_svg_arcEndAngle(d) {
17173 return d.endAngle;
17174 }
17175 function d3_svg_arcPadAngle(d) {
17176 return d && d.padAngle;
17177 }
17178 function d3_svg_arcSweep(x0, y0, x1, y1) {
17179 return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
17180 }
17181 function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
17182 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;
17183 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
17184 return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
17185 }
17186 function d3_svg_line(projection) {
17187 var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
17188 function line(data) {
17189 var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
17190 function segment() {
17191 segments.push("M", interpolate(projection(points), tension));
17192 }
17193 while (++i < n) {
17194 if (defined.call(this, d = data[i], i)) {
17195 points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
17196 } else if (points.length) {
17197 segment();
17198 points = [];
17199 }
17200 }
17201 if (points.length) segment();
17202 return segments.length ? segments.join("") : null;
17203 }
17204 line.x = function(_) {
17205 if (!arguments.length) return x;
17206 x = _;
17207 return line;
17208 };
17209 line.y = function(_) {
17210 if (!arguments.length) return y;
17211 y = _;
17212 return line;
17213 };
17214 line.defined = function(_) {
17215 if (!arguments.length) return defined;
17216 defined = _;
17217 return line;
17218 };
17219 line.interpolate = function(_) {
17220 if (!arguments.length) return interpolateKey;
17221 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
17222 return line;
17223 };
17224 line.tension = function(_) {
17225 if (!arguments.length) return tension;
17226 tension = _;
17227 return line;
17228 };
17229 return line;
17230 }
17231 d3.svg.line = function() {
17232 return d3_svg_line(d3_identity);
17233 };
17234 var d3_svg_lineInterpolators = d3.map({
17235 linear: d3_svg_lineLinear,
17236 "linear-closed": d3_svg_lineLinearClosed,
17237 step: d3_svg_lineStep,
17238 "step-before": d3_svg_lineStepBefore,
17239 "step-after": d3_svg_lineStepAfter,
17240 basis: d3_svg_lineBasis,
17241 "basis-open": d3_svg_lineBasisOpen,
17242 "basis-closed": d3_svg_lineBasisClosed,
17243 bundle: d3_svg_lineBundle,
17244 cardinal: d3_svg_lineCardinal,
17245 "cardinal-open": d3_svg_lineCardinalOpen,
17246 "cardinal-closed": d3_svg_lineCardinalClosed,
17247 monotone: d3_svg_lineMonotone
17248 });
17249 d3_svg_lineInterpolators.forEach(function(key, value) {
17250 value.key = key;
17251 value.closed = /-closed$/.test(key);
17252 });
17253 function d3_svg_lineLinear(points) {
17254 return points.length > 1 ? points.join("L") : points + "Z";
17255 }
17256 function d3_svg_lineLinearClosed(points) {
17257 return points.join("L") + "Z";
17258 }
17259 function d3_svg_lineStep(points) {
17260 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
17261 while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
17262 if (n > 1) path.push("H", p[0]);
17263 return path.join("");
17264 }
17265 function d3_svg_lineStepBefore(points) {
17266 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
17267 while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
17268 return path.join("");
17269 }
17270 function d3_svg_lineStepAfter(points) {
17271 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
17272 while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
17273 return path.join("");
17274 }
17275 function d3_svg_lineCardinalOpen(points, tension) {
17276 return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
17277 }
17278 function d3_svg_lineCardinalClosed(points, tension) {
17279 return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
17280 points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
17281 }
17282 function d3_svg_lineCardinal(points, tension) {
17283 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
17284 }
17285 function d3_svg_lineHermite(points, tangents) {
17286 if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
17287 return d3_svg_lineLinear(points);
17288 }
17289 var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
17290 if (quad) {
17291 path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
17292 p0 = points[1];
17293 pi = 2;
17294 }
17295 if (tangents.length > 1) {
17296 t = tangents[1];
17297 p = points[pi];
17298 pi++;
17299 path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
17300 for (var i = 2; i < tangents.length; i++, pi++) {
17301 p = points[pi];
17302 t = tangents[i];
17303 path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
17304 }
17305 }
17306 if (quad) {
17307 var lp = points[pi];
17308 path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
17309 }
17310 return path;
17311 }
17312 function d3_svg_lineCardinalTangents(points, tension) {
17313 var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
17314 while (++i < n) {
17315 p0 = p1;
17316 p1 = p2;
17317 p2 = points[i];
17318 tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
17319 }
17320 return tangents;
17321 }
17322 function d3_svg_lineBasis(points) {
17323 if (points.length < 3) return d3_svg_lineLinear(points);
17324 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) ];
17325 points.push(points[n - 1]);
17326 while (++i <= n) {
17327 pi = points[i];
17328 px.shift();
17329 px.push(pi[0]);
17330 py.shift();
17331 py.push(pi[1]);
17332 d3_svg_lineBasisBezier(path, px, py);
17333 }
17334 points.pop();
17335 path.push("L", pi);
17336 return path.join("");
17337 }
17338 function d3_svg_lineBasisOpen(points) {
17339 if (points.length < 4) return d3_svg_lineLinear(points);
17340 var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
17341 while (++i < 3) {
17342 pi = points[i];
17343 px.push(pi[0]);
17344 py.push(pi[1]);
17345 }
17346 path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
17347 --i;
17348 while (++i < n) {
17349 pi = points[i];
17350 px.shift();
17351 px.push(pi[0]);
17352 py.shift();
17353 py.push(pi[1]);
17354 d3_svg_lineBasisBezier(path, px, py);
17355 }
17356 return path.join("");
17357 }
17358 function d3_svg_lineBasisClosed(points) {
17359 var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
17360 while (++i < 4) {
17361 pi = points[i % n];
17362 px.push(pi[0]);
17363 py.push(pi[1]);
17364 }
17365 path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
17366 --i;
17367 while (++i < m) {
17368 pi = points[i % n];
17369 px.shift();
17370 px.push(pi[0]);
17371 py.shift();
17372 py.push(pi[1]);
17373 d3_svg_lineBasisBezier(path, px, py);
17374 }
17375 return path.join("");
17376 }
17377 function d3_svg_lineBundle(points, tension) {
17378 var n = points.length - 1;
17379 if (n) {
17380 var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
17381 while (++i <= n) {
17382 p = points[i];
17383 t = i / n;
17384 p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
17385 p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
17386 }
17387 }
17388 return d3_svg_lineBasis(points);
17389 }
17390 function d3_svg_lineDot4(a, b) {
17391 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
17392 }
17393 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 ];
17394 function d3_svg_lineBasisBezier(path, x, y) {
17395 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));
17396 }
17397 function d3_svg_lineSlope(p0, p1) {
17398 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
17399 }
17400 function d3_svg_lineFiniteDifferences(points) {
17401 var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
17402 while (++i < j) {
17403 m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
17404 }
17405 m[i] = d;
17406 return m;
17407 }
17408 function d3_svg_lineMonotoneTangents(points) {
17409 var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
17410 while (++i < j) {
17411 d = d3_svg_lineSlope(points[i], points[i + 1]);
17412 if (abs(d) < ε) {
17413 m[i] = m[i + 1] = 0;
17414 } else {
17415 a = m[i] / d;
17416 b = m[i + 1] / d;
17417 s = a * a + b * b;
17418 if (s > 9) {
17419 s = d * 3 / Math.sqrt(s);
17420 m[i] = s * a;
17421 m[i + 1] = s * b;
17422 }
17423 }
17424 }
17425 i = -1;
17426 while (++i <= j) {
17427 s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
17428 tangents.push([ s || 0, m[i] * s || 0 ]);
17429 }
17430 return tangents;
17431 }
17432 function d3_svg_lineMonotone(points) {
17433 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
17434 }
17435 d3.svg.line.radial = function() {
17436 var line = d3_svg_line(d3_svg_lineRadial);
17437 line.radius = line.x, delete line.x;
17438 line.angle = line.y, delete line.y;
17439 return line;
17440 };
17441 function d3_svg_lineRadial(points) {
17442 var point, i = -1, n = points.length, r, a;
17443 while (++i < n) {
17444 point = points[i];
17445 r = point[0];
17446 a = point[1] - halfπ;
17447 point[0] = r * Math.cos(a);
17448 point[1] = r * Math.sin(a);
17449 }
17450 return points;
17451 }
17452 function d3_svg_area(projection) {
17453 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;
17454 function area(data) {
17455 var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
17456 return x;
17457 } : d3_functor(x1), fy1 = y0 === y1 ? function() {
17458 return y;
17459 } : d3_functor(y1), x, y;
17460 function segment() {
17461 segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
17462 }
17463 while (++i < n) {
17464 if (defined.call(this, d = data[i], i)) {
17465 points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
17466 points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
17467 } else if (points0.length) {
17468 segment();
17469 points0 = [];
17470 points1 = [];
17471 }
17472 }
17473 if (points0.length) segment();
17474 return segments.length ? segments.join("") : null;
17475 }
17476 area.x = function(_) {
17477 if (!arguments.length) return x1;
17478 x0 = x1 = _;
17479 return area;
17480 };
17481 area.x0 = function(_) {
17482 if (!arguments.length) return x0;
17483 x0 = _;
17484 return area;
17485 };
17486 area.x1 = function(_) {
17487 if (!arguments.length) return x1;
17488 x1 = _;
17489 return area;
17490 };
17491 area.y = function(_) {
17492 if (!arguments.length) return y1;
17493 y0 = y1 = _;
17494 return area;
17495 };
17496 area.y0 = function(_) {
17497 if (!arguments.length) return y0;
17498 y0 = _;
17499 return area;
17500 };
17501 area.y1 = function(_) {
17502 if (!arguments.length) return y1;
17503 y1 = _;
17504 return area;
17505 };
17506 area.defined = function(_) {
17507 if (!arguments.length) return defined;
17508 defined = _;
17509 return area;
17510 };
17511 area.interpolate = function(_) {
17512 if (!arguments.length) return interpolateKey;
17513 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
17514 interpolateReverse = interpolate.reverse || interpolate;
17515 L = interpolate.closed ? "M" : "L";
17516 return area;
17517 };
17518 area.tension = function(_) {
17519 if (!arguments.length) return tension;
17520 tension = _;
17521 return area;
17522 };
17523 return area;
17524 }
17525 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
17526 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
17527 d3.svg.area = function() {
17528 return d3_svg_area(d3_identity);
17529 };
17530 d3.svg.area.radial = function() {
17531 var area = d3_svg_area(d3_svg_lineRadial);
17532 area.radius = area.x, delete area.x;
17533 area.innerRadius = area.x0, delete area.x0;
17534 area.outerRadius = area.x1, delete area.x1;
17535 area.angle = area.y, delete area.y;
17536 area.startAngle = area.y0, delete area.y0;
17537 area.endAngle = area.y1, delete area.y1;
17538 return area;
17539 };
17540 d3.svg.chord = function() {
17541 var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
17542 function chord(d, i) {
17543 var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
17544 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";
17545 }
17546 function subgroup(self, f, d, i) {
17547 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π;
17548 return {
17549 r: r,
17550 a0: a0,
17551 a1: a1,
17552 p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
17553 p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
17554 };
17555 }
17556 function equals(a, b) {
17557 return a.a0 == b.a0 && a.a1 == b.a1;
17558 }
17559 function arc(r, p, a) {
17560 return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
17561 }
17562 function curve(r0, p0, r1, p1) {
17563 return "Q 0,0 " + p1;
17564 }
17565 chord.radius = function(v) {
17566 if (!arguments.length) return radius;
17567 radius = d3_functor(v);
17568 return chord;
17569 };
17570 chord.source = function(v) {
17571 if (!arguments.length) return source;
17572 source = d3_functor(v);
17573 return chord;
17574 };
17575 chord.target = function(v) {
17576 if (!arguments.length) return target;
17577 target = d3_functor(v);
17578 return chord;
17579 };
17580 chord.startAngle = function(v) {
17581 if (!arguments.length) return startAngle;
17582 startAngle = d3_functor(v);
17583 return chord;
17584 };
17585 chord.endAngle = function(v) {
17586 if (!arguments.length) return endAngle;
17587 endAngle = d3_functor(v);
17588 return chord;
17589 };
17590 return chord;
17591 };
17592 function d3_svg_chordRadius(d) {
17593 return d.radius;
17594 }
17595 d3.svg.diagonal = function() {
17596 var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
17597 function diagonal(d, i) {
17598 var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
17599 x: p0.x,
17600 y: m
17601 }, {
17602 x: p3.x,
17603 y: m
17604 }, p3 ];
17605 p = p.map(projection);
17606 return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
17607 }
17608 diagonal.source = function(x) {
17609 if (!arguments.length) return source;
17610 source = d3_functor(x);
17611 return diagonal;
17612 };
17613 diagonal.target = function(x) {
17614 if (!arguments.length) return target;
17615 target = d3_functor(x);
17616 return diagonal;
17617 };
17618 diagonal.projection = function(x) {
17619 if (!arguments.length) return projection;
17620 projection = x;
17621 return diagonal;
17622 };
17623 return diagonal;
17624 };
17625 function d3_svg_diagonalProjection(d) {
17626 return [ d.x, d.y ];
17627 }
17628 d3.svg.diagonal.radial = function() {
17629 var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
17630 diagonal.projection = function(x) {
17631 return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
17632 };
17633 return diagonal;
17634 };
17635 function d3_svg_diagonalRadialProjection(projection) {
17636 return function() {
17637 var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
17638 return [ r * Math.cos(a), r * Math.sin(a) ];
17639 };
17640 }
17641 d3.svg.symbol = function() {
17642 var type = d3_svg_symbolType, size = d3_svg_symbolSize;
17643 function symbol(d, i) {
17644 return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
17645 }
17646 symbol.type = function(x) {
17647 if (!arguments.length) return type;
17648 type = d3_functor(x);
17649 return symbol;
17650 };
17651 symbol.size = function(x) {
17652 if (!arguments.length) return size;
17653 size = d3_functor(x);
17654 return symbol;
17655 };
17656 return symbol;
17657 };
17658 function d3_svg_symbolSize() {
17659 return 64;
17660 }
17661 function d3_svg_symbolType() {
17662 return "circle";
17663 }
17664 function d3_svg_symbolCircle(size) {
17665 var r = Math.sqrt(size / π);
17666 return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
17667 }
17668 var d3_svg_symbols = d3.map({
17669 circle: d3_svg_symbolCircle,
17670 cross: function(size) {
17671 var r = Math.sqrt(size / 5) / 2;
17672 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";
17673 },
17674 diamond: function(size) {
17675 var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
17676 return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
17677 },
17678 square: function(size) {
17679 var r = Math.sqrt(size) / 2;
17680 return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
17681 },
17682 "triangle-down": function(size) {
17683 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
17684 return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
17685 },
17686 "triangle-up": function(size) {
17687 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
17688 return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
17689 }
17690 });
17691 d3.svg.symbolTypes = d3_svg_symbols.keys();
17692 var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
17693 d3_selectionPrototype.transition = function(name) {
17694 var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
17695 time: Date.now(),
17696 ease: d3_ease_cubicInOut,
17697 delay: 0,
17698 duration: 250
17699 };
17700 for (var j = -1, m = this.length; ++j < m; ) {
17701 subgroups.push(subgroup = []);
17702 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
17703 if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
17704 subgroup.push(node);
17705 }
17706 }
17707 return d3_transition(subgroups, ns, id);
17708 };
17709 d3_selectionPrototype.interrupt = function(name) {
17710 return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
17711 };
17712 var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
17713 function d3_selection_interruptNS(ns) {
17714 return function() {
17715 var lock, activeId, active;
17716 if ((lock = this[ns]) && (active = lock[activeId = lock.active])) {
17717 active.timer.c = null;
17718 active.timer.t = NaN;
17719 if (--lock.count) delete lock[activeId]; else delete this[ns];
17720 lock.active += .5;
17721 active.event && active.event.interrupt.call(this, this.__data__, active.index);
17722 }
17723 };
17724 }
17725 function d3_transition(groups, ns, id) {
17726 d3_subclass(groups, d3_transitionPrototype);
17727 groups.namespace = ns;
17728 groups.id = id;
17729 return groups;
17730 }
17731 var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
17732 d3_transitionPrototype.call = d3_selectionPrototype.call;
17733 d3_transitionPrototype.empty = d3_selectionPrototype.empty;
17734 d3_transitionPrototype.node = d3_selectionPrototype.node;
17735 d3_transitionPrototype.size = d3_selectionPrototype.size;
17736 d3.transition = function(selection, name) {
17737 return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
17738 };
17739 d3.transition.prototype = d3_transitionPrototype;
17740 d3_transitionPrototype.select = function(selector) {
17741 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
17742 selector = d3_selection_selector(selector);
17743 for (var j = -1, m = this.length; ++j < m; ) {
17744 subgroups.push(subgroup = []);
17745 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
17746 if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
17747 if ("__data__" in node) subnode.__data__ = node.__data__;
17748 d3_transitionNode(subnode, i, ns, id, node[ns][id]);
17749 subgroup.push(subnode);
17750 } else {
17751 subgroup.push(null);
17752 }
17753 }
17754 }
17755 return d3_transition(subgroups, ns, id);
17756 };
17757 d3_transitionPrototype.selectAll = function(selector) {
17758 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
17759 selector = d3_selection_selectorAll(selector);
17760 for (var j = -1, m = this.length; ++j < m; ) {
17761 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
17762 if (node = group[i]) {
17763 transition = node[ns][id];
17764 subnodes = selector.call(node, node.__data__, i, j);
17765 subgroups.push(subgroup = []);
17766 for (var k = -1, o = subnodes.length; ++k < o; ) {
17767 if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
17768 subgroup.push(subnode);
17769 }
17770 }
17771 }
17772 }
17773 return d3_transition(subgroups, ns, id);
17774 };
17775 d3_transitionPrototype.filter = function(filter) {
17776 var subgroups = [], subgroup, group, node;
17777 if (typeof filter !== "function") filter = d3_selection_filter(filter);
17778 for (var j = 0, m = this.length; j < m; j++) {
17779 subgroups.push(subgroup = []);
17780 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
17781 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
17782 subgroup.push(node);
17783 }
17784 }
17785 }
17786 return d3_transition(subgroups, this.namespace, this.id);
17787 };
17788 d3_transitionPrototype.tween = function(name, tween) {
17789 var id = this.id, ns = this.namespace;
17790 if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
17791 return d3_selection_each(this, tween == null ? function(node) {
17792 node[ns][id].tween.remove(name);
17793 } : function(node) {
17794 node[ns][id].tween.set(name, tween);
17795 });
17796 };
17797 function d3_transition_tween(groups, name, value, tween) {
17798 var id = groups.id, ns = groups.namespace;
17799 return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
17800 node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
17801 } : (value = tween(value), function(node) {
17802 node[ns][id].tween.set(name, value);
17803 }));
17804 }
17805 d3_transitionPrototype.attr = function(nameNS, value) {
17806 if (arguments.length < 2) {
17807 for (value in nameNS) this.attr(value, nameNS[value]);
17808 return this;
17809 }
17810 var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
17811 function attrNull() {
17812 this.removeAttribute(name);
17813 }
17814 function attrNullNS() {
17815 this.removeAttributeNS(name.space, name.local);
17816 }
17817 function attrTween(b) {
17818 return b == null ? attrNull : (b += "", function() {
17819 var a = this.getAttribute(name), i;
17820 return a !== b && (i = interpolate(a, b), function(t) {
17821 this.setAttribute(name, i(t));
17822 });
17823 });
17824 }
17825 function attrTweenNS(b) {
17826 return b == null ? attrNullNS : (b += "", function() {
17827 var a = this.getAttributeNS(name.space, name.local), i;
17828 return a !== b && (i = interpolate(a, b), function(t) {
17829 this.setAttributeNS(name.space, name.local, i(t));
17830 });
17831 });
17832 }
17833 return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
17834 };
17835 d3_transitionPrototype.attrTween = function(nameNS, tween) {
17836 var name = d3.ns.qualify(nameNS);
17837 function attrTween(d, i) {
17838 var f = tween.call(this, d, i, this.getAttribute(name));
17839 return f && function(t) {
17840 this.setAttribute(name, f(t));
17841 };
17842 }
17843 function attrTweenNS(d, i) {
17844 var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
17845 return f && function(t) {
17846 this.setAttributeNS(name.space, name.local, f(t));
17847 };
17848 }
17849 return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
17850 };
17851 d3_transitionPrototype.style = function(name, value, priority) {
17852 var n = arguments.length;
17853 if (n < 3) {
17854 if (typeof name !== "string") {
17855 if (n < 2) value = "";
17856 for (priority in name) this.style(priority, name[priority], value);
17857 return this;
17858 }
17859 priority = "";
17860 }
17861 function styleNull() {
17862 this.style.removeProperty(name);
17863 }
17864 function styleString(b) {
17865 return b == null ? styleNull : (b += "", function() {
17866 var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
17867 return a !== b && (i = d3_interpolate(a, b), function(t) {
17868 this.style.setProperty(name, i(t), priority);
17869 });
17870 });
17871 }
17872 return d3_transition_tween(this, "style." + name, value, styleString);
17873 };
17874 d3_transitionPrototype.styleTween = function(name, tween, priority) {
17875 if (arguments.length < 3) priority = "";
17876 function styleTween(d, i) {
17877 var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
17878 return f && function(t) {
17879 this.style.setProperty(name, f(t), priority);
17880 };
17881 }
17882 return this.tween("style." + name, styleTween);
17883 };
17884 d3_transitionPrototype.text = function(value) {
17885 return d3_transition_tween(this, "text", value, d3_transition_text);
17886 };
17887 function d3_transition_text(b) {
17888 if (b == null) b = "";
17889 return function() {
17890 this.textContent = b;
17891 };
17892 }
17893 d3_transitionPrototype.remove = function() {
17894 var ns = this.namespace;
17895 return this.each("end.transition", function() {
17896 var p;
17897 if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
17898 });
17899 };
17900 d3_transitionPrototype.ease = function(value) {
17901 var id = this.id, ns = this.namespace;
17902 if (arguments.length < 1) return this.node()[ns][id].ease;
17903 if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
17904 return d3_selection_each(this, function(node) {
17905 node[ns][id].ease = value;
17906 });
17907 };
17908 d3_transitionPrototype.delay = function(value) {
17909 var id = this.id, ns = this.namespace;
17910 if (arguments.length < 1) return this.node()[ns][id].delay;
17911 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
17912 node[ns][id].delay = +value.call(node, node.__data__, i, j);
17913 } : (value = +value, function(node) {
17914 node[ns][id].delay = value;
17915 }));
17916 };
17917 d3_transitionPrototype.duration = function(value) {
17918 var id = this.id, ns = this.namespace;
17919 if (arguments.length < 1) return this.node()[ns][id].duration;
17920 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
17921 node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
17922 } : (value = Math.max(1, value), function(node) {
17923 node[ns][id].duration = value;
17924 }));
17925 };
17926 d3_transitionPrototype.each = function(type, listener) {
17927 var id = this.id, ns = this.namespace;
17928 if (arguments.length < 2) {
17929 var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
17930 try {
17931 d3_transitionInheritId = id;
17932 d3_selection_each(this, function(node, i, j) {
17933 d3_transitionInherit = node[ns][id];
17934 type.call(node, node.__data__, i, j);
17935 });
17936 } finally {
17937 d3_transitionInherit = inherit;
17938 d3_transitionInheritId = inheritId;
17939 }
17940 } else {
17941 d3_selection_each(this, function(node) {
17942 var transition = node[ns][id];
17943 (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
17944 });
17945 }
17946 return this;
17947 };
17948 d3_transitionPrototype.transition = function() {
17949 var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
17950 for (var j = 0, m = this.length; j < m; j++) {
17951 subgroups.push(subgroup = []);
17952 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
17953 if (node = group[i]) {
17954 transition = node[ns][id0];
17955 d3_transitionNode(node, i, ns, id1, {
17956 time: transition.time,
17957 ease: transition.ease,
17958 delay: transition.delay + transition.duration,
17959 duration: transition.duration
17960 });
17961 }
17962 subgroup.push(node);
17963 }
17964 }
17965 return d3_transition(subgroups, ns, id1);
17966 };
17967 function d3_transitionNamespace(name) {
17968 return name == null ? "__transition__" : "__transition_" + name + "__";
17969 }
17970 function d3_transitionNode(node, i, ns, id, inherit) {
17971 var lock = node[ns] || (node[ns] = {
17972 active: 0,
17973 count: 0
17974 }), transition = lock[id], time, timer, duration, ease, tweens;
17975 function schedule(elapsed) {
17976 var delay = transition.delay;
17977 timer.t = delay + time;
17978 if (delay <= elapsed) return start(elapsed - delay);
17979 timer.c = start;
17980 }
17981 function start(elapsed) {
17982 var activeId = lock.active, active = lock[activeId];
17983 if (active) {
17984 active.timer.c = null;
17985 active.timer.t = NaN;
17986 --lock.count;
17987 delete lock[activeId];
17988 active.event && active.event.interrupt.call(node, node.__data__, active.index);
17989 }
17990 for (var cancelId in lock) {
17991 if (+cancelId < id) {
17992 var cancel = lock[cancelId];
17993 cancel.timer.c = null;
17994 cancel.timer.t = NaN;
17995 --lock.count;
17996 delete lock[cancelId];
17997 }
17998 }
17999 timer.c = tick;
18000 d3_timer(function() {
18001 if (timer.c && tick(elapsed || 1)) {
18002 timer.c = null;
18003 timer.t = NaN;
18004 }
18005 return 1;
18006 }, 0, time);
18007 lock.active = id;
18008 transition.event && transition.event.start.call(node, node.__data__, i);
18009 tweens = [];
18010 transition.tween.forEach(function(key, value) {
18011 if (value = value.call(node, node.__data__, i)) {
18012 tweens.push(value);
18013 }
18014 });
18015 ease = transition.ease;
18016 duration = transition.duration;
18017 }
18018 function tick(elapsed) {
18019 var t = elapsed / duration, e = ease(t), n = tweens.length;
18020 while (n > 0) {
18021 tweens[--n].call(node, e);
18022 }
18023 if (t >= 1) {
18024 transition.event && transition.event.end.call(node, node.__data__, i);
18025 if (--lock.count) delete lock[id]; else delete node[ns];
18026 return 1;
18027 }
18028 }
18029 if (!transition) {
18030 time = inherit.time;
18031 timer = d3_timer(schedule, 0, time);
18032 transition = lock[id] = {
18033 tween: new d3_Map(),
18034 time: time,
18035 timer: timer,
18036 delay: inherit.delay,
18037 duration: inherit.duration,
18038 ease: inherit.ease,
18039 index: i
18040 };
18041 inherit = null;
18042 ++lock.count;
18043 }
18044 }
18045 d3.svg.axis = function() {
18046 var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
18047 function axis(g) {
18048 g.each(function() {
18049 var g = d3.select(this);
18050 var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
18051 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;
18052 var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
18053 d3.transition(path));
18054 tickEnter.append("line");
18055 tickEnter.append("text");
18056 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;
18057 if (orient === "bottom" || orient === "top") {
18058 tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
18059 text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
18060 pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
18061 } else {
18062 tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
18063 text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
18064 pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
18065 }
18066 lineEnter.attr(y2, sign * innerTickSize);
18067 textEnter.attr(y1, sign * tickSpacing);
18068 lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
18069 textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
18070 if (scale1.rangeBand) {
18071 var x = scale1, dx = x.rangeBand() / 2;
18072 scale0 = scale1 = function(d) {
18073 return x(d) + dx;
18074 };
18075 } else if (scale0.rangeBand) {
18076 scale0 = scale1;
18077 } else {
18078 tickExit.call(tickTransform, scale1, scale0);
18079 }
18080 tickEnter.call(tickTransform, scale0, scale1);
18081 tickUpdate.call(tickTransform, scale1, scale1);
18082 });
18083 }
18084 axis.scale = function(x) {
18085 if (!arguments.length) return scale;
18086 scale = x;
18087 return axis;
18088 };
18089 axis.orient = function(x) {
18090 if (!arguments.length) return orient;
18091 orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
18092 return axis;
18093 };
18094 axis.ticks = function() {
18095 if (!arguments.length) return tickArguments_;
18096 tickArguments_ = d3_array(arguments);
18097 return axis;
18098 };
18099 axis.tickValues = function(x) {
18100 if (!arguments.length) return tickValues;
18101 tickValues = x;
18102 return axis;
18103 };
18104 axis.tickFormat = function(x) {
18105 if (!arguments.length) return tickFormat_;
18106 tickFormat_ = x;
18107 return axis;
18108 };
18109 axis.tickSize = function(x) {
18110 var n = arguments.length;
18111 if (!n) return innerTickSize;
18112 innerTickSize = +x;
18113 outerTickSize = +arguments[n - 1];
18114 return axis;
18115 };
18116 axis.innerTickSize = function(x) {
18117 if (!arguments.length) return innerTickSize;
18118 innerTickSize = +x;
18119 return axis;
18120 };
18121 axis.outerTickSize = function(x) {
18122 if (!arguments.length) return outerTickSize;
18123 outerTickSize = +x;
18124 return axis;
18125 };
18126 axis.tickPadding = function(x) {
18127 if (!arguments.length) return tickPadding;
18128 tickPadding = +x;
18129 return axis;
18130 };
18131 axis.tickSubdivide = function() {
18132 return arguments.length && axis;
18133 };
18134 return axis;
18135 };
18136 var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
18137 top: 1,
18138 right: 1,
18139 bottom: 1,
18140 left: 1
18141 };
18142 function d3_svg_axisX(selection, x0, x1) {
18143 selection.attr("transform", function(d) {
18144 var v0 = x0(d);
18145 return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
18146 });
18147 }
18148 function d3_svg_axisY(selection, y0, y1) {
18149 selection.attr("transform", function(d) {
18150 var v0 = y0(d);
18151 return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
18152 });
18153 }
18154 d3.svg.brush = function() {
18155 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];
18156 function brush(g) {
18157 g.each(function() {
18158 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);
18159 var background = g.selectAll(".background").data([ 0 ]);
18160 background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
18161 g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
18162 var resize = g.selectAll(".resize").data(resizes, d3_identity);
18163 resize.exit().remove();
18164 resize.enter().append("g").attr("class", function(d) {
18165 return "resize " + d;
18166 }).style("cursor", function(d) {
18167 return d3_svg_brushCursor[d];
18168 }).append("rect").attr("x", function(d) {
18169 return /[ew]$/.test(d) ? -3 : null;
18170 }).attr("y", function(d) {
18171 return /^[ns]/.test(d) ? -3 : null;
18172 }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
18173 resize.style("display", brush.empty() ? "none" : null);
18174 var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
18175 if (x) {
18176 range = d3_scaleRange(x);
18177 backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
18178 redrawX(gUpdate);
18179 }
18180 if (y) {
18181 range = d3_scaleRange(y);
18182 backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
18183 redrawY(gUpdate);
18184 }
18185 redraw(gUpdate);
18186 });
18187 }
18188 brush.event = function(g) {
18189 g.each(function() {
18190 var event_ = event.of(this, arguments), extent1 = {
18191 x: xExtent,
18192 y: yExtent,
18193 i: xExtentDomain,
18194 j: yExtentDomain
18195 }, extent0 = this.__chart__ || extent1;
18196 this.__chart__ = extent1;
18197 if (d3_transitionInheritId) {
18198 d3.select(this).transition().each("start.brush", function() {
18199 xExtentDomain = extent0.i;
18200 yExtentDomain = extent0.j;
18201 xExtent = extent0.x;
18202 yExtent = extent0.y;
18203 event_({
18204 type: "brushstart"
18205 });
18206 }).tween("brush:brush", function() {
18207 var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
18208 xExtentDomain = yExtentDomain = null;
18209 return function(t) {
18210 xExtent = extent1.x = xi(t);
18211 yExtent = extent1.y = yi(t);
18212 event_({
18213 type: "brush",
18214 mode: "resize"
18215 });
18216 };
18217 }).each("end.brush", function() {
18218 xExtentDomain = extent1.i;
18219 yExtentDomain = extent1.j;
18220 event_({
18221 type: "brush",
18222 mode: "resize"
18223 });
18224 event_({
18225 type: "brushend"
18226 });
18227 });
18228 } else {
18229 event_({
18230 type: "brushstart"
18231 });
18232 event_({
18233 type: "brush",
18234 mode: "resize"
18235 });
18236 event_({
18237 type: "brushend"
18238 });
18239 }
18240 });
18241 };
18242 function redraw(g) {
18243 g.selectAll(".resize").attr("transform", function(d) {
18244 return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
18245 });
18246 }
18247 function redrawX(g) {
18248 g.select(".extent").attr("x", xExtent[0]);
18249 g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
18250 }
18251 function redrawY(g) {
18252 g.select(".extent").attr("y", yExtent[0]);
18253 g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
18254 }
18255 function brushstart() {
18256 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;
18257 var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
18258 if (d3.event.changedTouches) {
18259 w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
18260 } else {
18261 w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
18262 }
18263 g.interrupt().selectAll("*").interrupt();
18264 if (dragging) {
18265 origin[0] = xExtent[0] - origin[0];
18266 origin[1] = yExtent[0] - origin[1];
18267 } else if (resizing) {
18268 var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
18269 offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
18270 origin[0] = xExtent[ex];
18271 origin[1] = yExtent[ey];
18272 } else if (d3.event.altKey) center = origin.slice();
18273 g.style("pointer-events", "none").selectAll(".resize").style("display", null);
18274 d3.select("body").style("cursor", eventTarget.style("cursor"));
18275 event_({
18276 type: "brushstart"
18277 });
18278 brushmove();
18279 function keydown() {
18280 if (d3.event.keyCode == 32) {
18281 if (!dragging) {
18282 center = null;
18283 origin[0] -= xExtent[1];
18284 origin[1] -= yExtent[1];
18285 dragging = 2;
18286 }
18287 d3_eventPreventDefault();
18288 }
18289 }
18290 function keyup() {
18291 if (d3.event.keyCode == 32 && dragging == 2) {
18292 origin[0] += xExtent[1];
18293 origin[1] += yExtent[1];
18294 dragging = 0;
18295 d3_eventPreventDefault();
18296 }
18297 }
18298 function brushmove() {
18299 var point = d3.mouse(target), moved = false;
18300 if (offset) {
18301 point[0] += offset[0];
18302 point[1] += offset[1];
18303 }
18304 if (!dragging) {
18305 if (d3.event.altKey) {
18306 if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
18307 origin[0] = xExtent[+(point[0] < center[0])];
18308 origin[1] = yExtent[+(point[1] < center[1])];
18309 } else center = null;
18310 }
18311 if (resizingX && move1(point, x, 0)) {
18312 redrawX(g);
18313 moved = true;
18314 }
18315 if (resizingY && move1(point, y, 1)) {
18316 redrawY(g);
18317 moved = true;
18318 }
18319 if (moved) {
18320 redraw(g);
18321 event_({
18322 type: "brush",
18323 mode: dragging ? "move" : "resize"
18324 });
18325 }
18326 }
18327 function move1(point, scale, i) {
18328 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;
18329 if (dragging) {
18330 r0 -= position;
18331 r1 -= size + position;
18332 }
18333 min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
18334 if (dragging) {
18335 max = (min += position) + size;
18336 } else {
18337 if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
18338 if (position < min) {
18339 max = min;
18340 min = position;
18341 } else {
18342 max = position;
18343 }
18344 }
18345 if (extent[0] != min || extent[1] != max) {
18346 if (i) yExtentDomain = null; else xExtentDomain = null;
18347 extent[0] = min;
18348 extent[1] = max;
18349 return true;
18350 }
18351 }
18352 function brushend() {
18353 brushmove();
18354 g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
18355 d3.select("body").style("cursor", null);
18356 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);
18357 dragRestore();
18358 event_({
18359 type: "brushend"
18360 });
18361 }
18362 }
18363 brush.x = function(z) {
18364 if (!arguments.length) return x;
18365 x = z;
18366 resizes = d3_svg_brushResizes[!x << 1 | !y];
18367 return brush;
18368 };
18369 brush.y = function(z) {
18370 if (!arguments.length) return y;
18371 y = z;
18372 resizes = d3_svg_brushResizes[!x << 1 | !y];
18373 return brush;
18374 };
18375 brush.clamp = function(z) {
18376 if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
18377 if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
18378 return brush;
18379 };
18380 brush.extent = function(z) {
18381 var x0, x1, y0, y1, t;
18382 if (!arguments.length) {
18383 if (x) {
18384 if (xExtentDomain) {
18385 x0 = xExtentDomain[0], x1 = xExtentDomain[1];
18386 } else {
18387 x0 = xExtent[0], x1 = xExtent[1];
18388 if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
18389 if (x1 < x0) t = x0, x0 = x1, x1 = t;
18390 }
18391 }
18392 if (y) {
18393 if (yExtentDomain) {
18394 y0 = yExtentDomain[0], y1 = yExtentDomain[1];
18395 } else {
18396 y0 = yExtent[0], y1 = yExtent[1];
18397 if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
18398 if (y1 < y0) t = y0, y0 = y1, y1 = t;
18399 }
18400 }
18401 return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
18402 }
18403 if (x) {
18404 x0 = z[0], x1 = z[1];
18405 if (y) x0 = x0[0], x1 = x1[0];
18406 xExtentDomain = [ x0, x1 ];
18407 if (x.invert) x0 = x(x0), x1 = x(x1);
18408 if (x1 < x0) t = x0, x0 = x1, x1 = t;
18409 if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
18410 }
18411 if (y) {
18412 y0 = z[0], y1 = z[1];
18413 if (x) y0 = y0[1], y1 = y1[1];
18414 yExtentDomain = [ y0, y1 ];
18415 if (y.invert) y0 = y(y0), y1 = y(y1);
18416 if (y1 < y0) t = y0, y0 = y1, y1 = t;
18417 if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
18418 }
18419 return brush;
18420 };
18421 brush.clear = function() {
18422 if (!brush.empty()) {
18423 xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
18424 xExtentDomain = yExtentDomain = null;
18425 }
18426 return brush;
18427 };
18428 brush.empty = function() {
18429 return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
18430 };
18431 return d3.rebind(brush, event, "on");
18432 };
18433 var d3_svg_brushCursor = {
18434 n: "ns-resize",
18435 e: "ew-resize",
18436 s: "ns-resize",
18437 w: "ew-resize",
18438 nw: "nwse-resize",
18439 ne: "nesw-resize",
18440 se: "nwse-resize",
18441 sw: "nesw-resize"
18442 };
18443 var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
18444 var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
18445 var d3_time_formatUtc = d3_time_format.utc;
18446 var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
18447 d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
18448 function d3_time_formatIsoNative(date) {
18449 return date.toISOString();
18450 }
18451 d3_time_formatIsoNative.parse = function(string) {
18452 var date = new Date(string);
18453 return isNaN(date) ? null : date;
18454 };
18455 d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
18456 d3_time.second = d3_time_interval(function(date) {
18457 return new d3_date(Math.floor(date / 1e3) * 1e3);
18458 }, function(date, offset) {
18459 date.setTime(date.getTime() + Math.floor(offset) * 1e3);
18460 }, function(date) {
18461 return date.getSeconds();
18462 });
18463 d3_time.seconds = d3_time.second.range;
18464 d3_time.seconds.utc = d3_time.second.utc.range;
18465 d3_time.minute = d3_time_interval(function(date) {
18466 return new d3_date(Math.floor(date / 6e4) * 6e4);
18467 }, function(date, offset) {
18468 date.setTime(date.getTime() + Math.floor(offset) * 6e4);
18469 }, function(date) {
18470 return date.getMinutes();
18471 });
18472 d3_time.minutes = d3_time.minute.range;
18473 d3_time.minutes.utc = d3_time.minute.utc.range;
18474 d3_time.hour = d3_time_interval(function(date) {
18475 var timezone = date.getTimezoneOffset() / 60;
18476 return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
18477 }, function(date, offset) {
18478 date.setTime(date.getTime() + Math.floor(offset) * 36e5);
18479 }, function(date) {
18480 return date.getHours();
18481 });
18482 d3_time.hours = d3_time.hour.range;
18483 d3_time.hours.utc = d3_time.hour.utc.range;
18484 d3_time.month = d3_time_interval(function(date) {
18485 date = d3_time.day(date);
18486 date.setDate(1);
18487 return date;
18488 }, function(date, offset) {
18489 date.setMonth(date.getMonth() + offset);
18490 }, function(date) {
18491 return date.getMonth();
18492 });
18493 d3_time.months = d3_time.month.range;
18494 d3_time.months.utc = d3_time.month.utc.range;
18495 function d3_time_scale(linear, methods, format) {
18496 function scale(x) {
18497 return linear(x);
18498 }
18499 scale.invert = function(x) {
18500 return d3_time_scaleDate(linear.invert(x));
18501 };
18502 scale.domain = function(x) {
18503 if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
18504 linear.domain(x);
18505 return scale;
18506 };
18507 function tickMethod(extent, count) {
18508 var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
18509 return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
18510 return d / 31536e6;
18511 }), 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];
18512 }
18513 scale.nice = function(interval, skip) {
18514 var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
18515 if (method) interval = method[0], skip = method[1];
18516 function skipped(date) {
18517 return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
18518 }
18519 return scale.domain(d3_scale_nice(domain, skip > 1 ? {
18520 floor: function(date) {
18521 while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
18522 return date;
18523 },
18524 ceil: function(date) {
18525 while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
18526 return date;
18527 }
18528 } : interval));
18529 };
18530 scale.ticks = function(interval, skip) {
18531 var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
18532 range: interval
18533 }, skip ];
18534 if (method) interval = method[0], skip = method[1];
18535 return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
18536 };
18537 scale.tickFormat = function() {
18538 return format;
18539 };
18540 scale.copy = function() {
18541 return d3_time_scale(linear.copy(), methods, format);
18542 };
18543 return d3_scale_linearRebind(scale, linear);
18544 }
18545 function d3_time_scaleDate(t) {
18546 return new Date(t);
18547 }
18548 var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
18549 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 ] ];
18550 var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
18551 return d.getMilliseconds();
18552 } ], [ ":%S", function(d) {
18553 return d.getSeconds();
18554 } ], [ "%I:%M", function(d) {
18555 return d.getMinutes();
18556 } ], [ "%I %p", function(d) {
18557 return d.getHours();
18558 } ], [ "%a %d", function(d) {
18559 return d.getDay() && d.getDate() != 1;
18560 } ], [ "%b %d", function(d) {
18561 return d.getDate() != 1;
18562 } ], [ "%B", function(d) {
18563 return d.getMonth();
18564 } ], [ "%Y", d3_true ] ]);
18565 var d3_time_scaleMilliseconds = {
18566 range: function(start, stop, step) {
18567 return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
18568 },
18569 floor: d3_identity,
18570 ceil: d3_identity
18571 };
18572 d3_time_scaleLocalMethods.year = d3_time.year;
18573 d3_time.scale = function() {
18574 return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
18575 };
18576 var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
18577 return [ m[0].utc, m[1] ];
18578 });
18579 var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
18580 return d.getUTCMilliseconds();
18581 } ], [ ":%S", function(d) {
18582 return d.getUTCSeconds();
18583 } ], [ "%I:%M", function(d) {
18584 return d.getUTCMinutes();
18585 } ], [ "%I %p", function(d) {
18586 return d.getUTCHours();
18587 } ], [ "%a %d", function(d) {
18588 return d.getUTCDay() && d.getUTCDate() != 1;
18589 } ], [ "%b %d", function(d) {
18590 return d.getUTCDate() != 1;
18591 } ], [ "%B", function(d) {
18592 return d.getUTCMonth();
18593 } ], [ "%Y", d3_true ] ]);
18594 d3_time_scaleUtcMethods.year = d3_time.year.utc;
18595 d3_time.scale.utc = function() {
18596 return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
18597 };
18598 d3.text = d3_xhrType(function(request) {
18599 return request.responseText;
18600 });
18601 d3.json = function(url, callback) {
18602 return d3_xhr(url, "application/json", d3_json, callback);
18603 };
18604 function d3_json(request) {
18605 return JSON.parse(request.responseText);
18606 }
18607 d3.html = function(url, callback) {
18608 return d3_xhr(url, "text/html", d3_html, callback);
18609 };
18610 function d3_html(request) {
18611 var range = d3_document.createRange();
18612 range.selectNode(d3_document.body);
18613 return range.createContextualFragment(request.responseText);
18614 }
18615 d3.xml = d3_xhrType(function(request) {
18616 return request.responseXML;
18617 });
18618 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;
18619 }();
18620
18621/***/ },
18622/* 39 */
18623/***/ function(module, exports, __webpack_require__) {
18624
18625 'use strict';
18626
18627 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; };
18628
18629 exports.__esModule = true;
18630 exports.default = tooltip;
18631
18632 var _ramda = __webpack_require__(4);
18633
18634 var _utils = __webpack_require__(40);
18635
18636 var _utils2 = _interopRequireDefault(_utils);
18637
18638 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18639
18640 var _ref = _utils2.default.default || _utils2.default;
18641
18642 var prependClass = _ref.prependClass;
18643 var functor = _ref.functor;
18644
18645 var defaultOptions = {
18646 left: undefined, // mouseX
18647 top: undefined, // mouseY
18648 offset: { left: 0, top: 0 },
18649 root: undefined
18650 };
18651
18652 function tooltip(d3) {
18653 var className = arguments.length <= 1 || arguments[1] === undefined ? 'tooltip' : arguments[1];
18654 var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
18655
18656 var _defaultOptions$optio = _extends({}, defaultOptions, options);
18657
18658 var left = _defaultOptions$optio.left;
18659 var top = _defaultOptions$optio.top;
18660 var offset = _defaultOptions$optio.offset;
18661 var root = _defaultOptions$optio.root;
18662
18663 var attrs = { 'class': className };
18664 var text = function text() {
18665 return '';
18666 };
18667 var styles = {};
18668
18669 var el = undefined;
18670 var anchor = root || d3.select('body');
18671 var rootNode = anchor.node();
18672
18673 function tip(selection) {
18674 selection.on({
18675 'mouseover.tip': function mouseoverTip(node) {
18676 var _d3$mouse = d3.mouse(rootNode);
18677
18678 var mouseX = _d3$mouse[0];
18679 var mouseY = _d3$mouse[1];
18680 var x = left || mouseX + offset.left;
18681 var y = top || mouseY - offset.top;
18682
18683 anchor.selectAll('div.' + className).remove();
18684
18685 el = anchor.append('div').attr(prependClass(className)(attrs)).style(_extends({
18686 position: 'absolute',
18687 'z-index': 1001,
18688 left: x + 'px',
18689 top: y + 'px'
18690 }, styles)).html(function () {
18691 return text(node);
18692 });
18693 },
18694
18695 'mousemove.tip': function mousemoveTip(node) {
18696 var _d3$mouse2 = d3.mouse(rootNode);
18697
18698 var mouseX = _d3$mouse2[0];
18699 var mouseY = _d3$mouse2[1];
18700 var x = left || mouseX + offset.left;
18701 var y = top || mouseY - offset.top;
18702
18703 el.style({
18704 left: x + 'px',
18705 top: y + 'px'
18706 }).html(function () {
18707 return text(node);
18708 });
18709 },
18710
18711 'mouseout.tip': function mouseoutTip() {
18712 return el.remove();
18713 }
18714 });
18715 }
18716
18717 tip.attr = function setAttr(d) {
18718 if ((0, _ramda.is)(Object, d)) {
18719 attrs = _extends({}, attrs, d);
18720 }
18721 return this;
18722 };
18723
18724 tip.style = function setStyle(d) {
18725 if ((0, _ramda.is)(Object, d)) {
18726 styles = _extends({}, styles, d);
18727 }
18728 return this;
18729 };
18730
18731 tip.text = function setText(d) {
18732 text = functor(d);
18733 return this;
18734 };
18735
18736 return tip;
18737 }
18738
18739/***/ },
18740/* 40 */
18741/***/ function(module, exports, __webpack_require__) {
18742
18743 'use strict';
18744
18745 exports.__esModule = true;
18746
18747 var _prependClass = __webpack_require__(41);
18748
18749 var _prependClass2 = _interopRequireDefault(_prependClass);
18750
18751 var _functor = __webpack_require__(15);
18752
18753 var _functor2 = _interopRequireDefault(_functor);
18754
18755 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18756
18757 exports.default = {
18758 prependClass: _prependClass2.default,
18759 functor: _functor2.default
18760 };
18761
18762/***/ },
18763/* 41 */
18764/***/ function(module, exports, __webpack_require__) {
18765
18766 'use strict';
18767
18768 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; };
18769
18770 exports.__esModule = true;
18771 exports.default = prependClass;
18772
18773 var _ramda = __webpack_require__(4);
18774
18775 var _functor = __webpack_require__(15);
18776
18777 var _functor2 = _interopRequireDefault(_functor);
18778
18779 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18780
18781 function prependClass(className) {
18782 return (0, _ramda.mapObjIndexed)(function (value, key) {
18783 if (key === 'class') {
18784 var _ret = function () {
18785 var fn = (0, _functor2.default)(value);
18786
18787 return {
18788 v: function v(d, i) {
18789 var classNames = fn(d, i);
18790 if (classNames !== className) {
18791 return (0, _ramda.join)(' ', [className, classNames]);
18792 }
18793 return classNames;
18794 }
18795 };
18796 }();
18797
18798 if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
18799 }
18800
18801 return value;
18802 });
18803 }
18804
18805/***/ },
18806/* 42 */
18807/***/ function(module, exports, __webpack_require__) {
18808
18809 var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (root, factory) {
18810 if (true) {
18811 !(__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__));
18812 } else if (typeof exports === 'object') {
18813 module.exports = factory();
18814 } else {
18815 root.deepmerge = factory();
18816 }
18817 }(this, function () {
18818
18819 return function deepmerge(target, src) {
18820 var array = Array.isArray(src);
18821 var dst = array && [] || {};
18822
18823 if (array) {
18824 target = target || [];
18825 dst = dst.concat(target);
18826 src.forEach(function(e, i) {
18827 if (typeof dst[i] === 'undefined') {
18828 dst[i] = e;
18829 } else if (typeof e === 'object') {
18830 dst[i] = deepmerge(target[i], e);
18831 } else {
18832 if (target.indexOf(e) === -1) {
18833 dst.push(e);
18834 }
18835 }
18836 });
18837 } else {
18838 if (target && typeof target === 'object') {
18839 Object.keys(target).forEach(function (key) {
18840 dst[key] = target[key];
18841 })
18842 }
18843 Object.keys(src).forEach(function (key) {
18844 if (typeof src[key] !== 'object' || !src[key]) {
18845 dst[key] = src[key];
18846 }
18847 else {
18848 if (!target[key]) {
18849 dst[key] = src[key];
18850 } else {
18851 dst[key] = deepmerge(target[key], src[key]);
18852 }
18853 }
18854 });
18855 }
18856
18857 return dst;
18858 }
18859
18860 }));
18861
18862
18863/***/ },
18864/* 43 */
18865/***/ function(module, exports, __webpack_require__) {
18866
18867 var nativeCreate = __webpack_require__(7);
18868
18869 /** Used for built-in method references. */
18870 var objectProto = Object.prototype;
18871
18872 /**
18873 * Creates an hash object.
18874 *
18875 * @private
18876 * @returns {Object} Returns the new hash object.
18877 */
18878 function Hash() {}
18879
18880 // Avoid inheriting from `Object.prototype` when possible.
18881 Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto;
18882
18883 module.exports = Hash;
18884
18885
18886/***/ },
18887/* 44 */
18888/***/ function(module, exports, __webpack_require__) {
18889
18890 var mapClear = __webpack_require__(77),
18891 mapDelete = __webpack_require__(78),
18892 mapGet = __webpack_require__(79),
18893 mapHas = __webpack_require__(80),
18894 mapSet = __webpack_require__(81);
18895
18896 /**
18897 * Creates a map cache object to store key-value pairs.
18898 *
18899 * @private
18900 * @param {Array} [values] The values to cache.
18901 */
18902 function MapCache(values) {
18903 var index = -1,
18904 length = values ? values.length : 0;
18905
18906 this.clear();
18907 while (++index < length) {
18908 var entry = values[index];
18909 this.set(entry[0], entry[1]);
18910 }
18911 }
18912
18913 // Add functions to the `MapCache`.
18914 MapCache.prototype.clear = mapClear;
18915 MapCache.prototype['delete'] = mapDelete;
18916 MapCache.prototype.get = mapGet;
18917 MapCache.prototype.has = mapHas;
18918 MapCache.prototype.set = mapSet;
18919
18920 module.exports = MapCache;
18921
18922
18923/***/ },
18924/* 45 */
18925/***/ function(module, exports, __webpack_require__) {
18926
18927 var getNative = __webpack_require__(10),
18928 root = __webpack_require__(8);
18929
18930 /* Built-in method references that are verified to be native. */
18931 var Set = getNative(root, 'Set');
18932
18933 module.exports = Set;
18934
18935
18936/***/ },
18937/* 46 */
18938/***/ function(module, exports, __webpack_require__) {
18939
18940 var root = __webpack_require__(8);
18941
18942 /** Built-in value references. */
18943 var Uint8Array = root.Uint8Array;
18944
18945 module.exports = Uint8Array;
18946
18947
18948/***/ },
18949/* 47 */
18950/***/ function(module, exports) {
18951
18952 /**
18953 * A specialized version of `_.map` for arrays without support for iteratee
18954 * shorthands.
18955 *
18956 * @private
18957 * @param {Array} array The array to iterate over.
18958 * @param {Function} iteratee The function invoked per iteration.
18959 * @returns {Array} Returns the new mapped array.
18960 */
18961 function arrayMap(array, iteratee) {
18962 var index = -1,
18963 length = array.length,
18964 result = Array(length);
18965
18966 while (++index < length) {
18967 result[index] = iteratee(array[index], index, array);
18968 }
18969 return result;
18970 }
18971
18972 module.exports = arrayMap;
18973
18974
18975/***/ },
18976/* 48 */
18977/***/ function(module, exports) {
18978
18979 /**
18980 * A specialized version of `_.some` for arrays without support for iteratee
18981 * shorthands.
18982 *
18983 * @private
18984 * @param {Array} array The array to iterate over.
18985 * @param {Function} predicate The function invoked per iteration.
18986 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
18987 */
18988 function arraySome(array, predicate) {
18989 var index = -1,
18990 length = array.length;
18991
18992 while (++index < length) {
18993 if (predicate(array[index], index, array)) {
18994 return true;
18995 }
18996 }
18997 return false;
18998 }
18999
19000 module.exports = arraySome;
19001
19002
19003/***/ },
19004/* 49 */
19005/***/ function(module, exports, __webpack_require__) {
19006
19007 var createBaseFor = __webpack_require__(63);
19008
19009 /**
19010 * The base implementation of `baseForIn` and `baseForOwn` which iterates
19011 * over `object` properties returned by `keysFunc` invoking `iteratee` for
19012 * each property. Iteratee functions may exit iteration early by explicitly
19013 * returning `false`.
19014 *
19015 * @private
19016 * @param {Object} object The object to iterate over.
19017 * @param {Function} iteratee The function invoked per iteration.
19018 * @param {Function} keysFunc The function to get the keys of `object`.
19019 * @returns {Object} Returns `object`.
19020 */
19021 var baseFor = createBaseFor();
19022
19023 module.exports = baseFor;
19024
19025
19026/***/ },
19027/* 50 */
19028/***/ function(module, exports, __webpack_require__) {
19029
19030 var baseFor = __webpack_require__(49),
19031 keys = __webpack_require__(14);
19032
19033 /**
19034 * The base implementation of `_.forOwn` without support for iteratee shorthands.
19035 *
19036 * @private
19037 * @param {Object} object The object to iterate over.
19038 * @param {Function} iteratee The function invoked per iteration.
19039 * @returns {Object} Returns `object`.
19040 */
19041 function baseForOwn(object, iteratee) {
19042 return object && baseFor(object, iteratee, keys);
19043 }
19044
19045 module.exports = baseForOwn;
19046
19047
19048/***/ },
19049/* 51 */
19050/***/ function(module, exports) {
19051
19052 /**
19053 * The base implementation of `_.hasIn` without support for deep paths.
19054 *
19055 * @private
19056 * @param {Object} object The object to query.
19057 * @param {Array|string} key The key to check.
19058 * @returns {boolean} Returns `true` if `key` exists, else `false`.
19059 */
19060 function baseHasIn(object, key) {
19061 return key in Object(object);
19062 }
19063
19064 module.exports = baseHasIn;
19065
19066
19067/***/ },
19068/* 52 */
19069/***/ function(module, exports, __webpack_require__) {
19070
19071 var Stack = __webpack_require__(16),
19072 equalArrays = __webpack_require__(64),
19073 equalByTag = __webpack_require__(65),
19074 equalObjects = __webpack_require__(66),
19075 getTag = __webpack_require__(69),
19076 isArray = __webpack_require__(1),
19077 isHostObject = __webpack_require__(11),
19078 isTypedArray = __webpack_require__(98);
19079
19080 /** Used to compose bitmasks for comparison styles. */
19081 var PARTIAL_COMPARE_FLAG = 2;
19082
19083 /** `Object#toString` result references. */
19084 var argsTag = '[object Arguments]',
19085 arrayTag = '[object Array]',
19086 objectTag = '[object Object]';
19087
19088 /** Used for built-in method references. */
19089 var objectProto = Object.prototype;
19090
19091 /** Used to check objects for own properties. */
19092 var hasOwnProperty = objectProto.hasOwnProperty;
19093
19094 /**
19095 * A specialized version of `baseIsEqual` for arrays and objects which performs
19096 * deep comparisons and tracks traversed objects enabling objects with circular
19097 * references to be compared.
19098 *
19099 * @private
19100 * @param {Object} object The object to compare.
19101 * @param {Object} other The other object to compare.
19102 * @param {Function} equalFunc The function to determine equivalents of values.
19103 * @param {Function} [customizer] The function to customize comparisons.
19104 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
19105 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
19106 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
19107 */
19108 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
19109 var objIsArr = isArray(object),
19110 othIsArr = isArray(other),
19111 objTag = arrayTag,
19112 othTag = arrayTag;
19113
19114 if (!objIsArr) {
19115 objTag = getTag(object);
19116 if (objTag == argsTag) {
19117 objTag = objectTag;
19118 } else if (objTag != objectTag) {
19119 objIsArr = isTypedArray(object);
19120 }
19121 }
19122 if (!othIsArr) {
19123 othTag = getTag(other);
19124 if (othTag == argsTag) {
19125 othTag = objectTag;
19126 } else if (othTag != objectTag) {
19127 othIsArr = isTypedArray(other);
19128 }
19129 }
19130 var objIsObj = objTag == objectTag && !isHostObject(object),
19131 othIsObj = othTag == objectTag && !isHostObject(other),
19132 isSameTag = objTag == othTag;
19133
19134 if (isSameTag && !(objIsArr || objIsObj)) {
19135 return equalByTag(object, other, objTag, equalFunc, customizer, bitmask);
19136 }
19137 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
19138 if (!isPartial) {
19139 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
19140 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
19141
19142 if (objIsWrapped || othIsWrapped) {
19143 return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
19144 }
19145 }
19146 if (!isSameTag) {
19147 return false;
19148 }
19149 stack || (stack = new Stack);
19150 return (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack);
19151 }
19152
19153 module.exports = baseIsEqualDeep;
19154
19155
19156/***/ },
19157/* 53 */
19158/***/ function(module, exports, __webpack_require__) {
19159
19160 var Stack = __webpack_require__(16),
19161 baseIsEqual = __webpack_require__(24);
19162
19163 /** Used to compose bitmasks for comparison styles. */
19164 var UNORDERED_COMPARE_FLAG = 1,
19165 PARTIAL_COMPARE_FLAG = 2;
19166
19167 /**
19168 * The base implementation of `_.isMatch` without support for iteratee shorthands.
19169 *
19170 * @private
19171 * @param {Object} object The object to inspect.
19172 * @param {Object} source The object of property values to match.
19173 * @param {Array} matchData The property names, values, and compare flags to match.
19174 * @param {Function} [customizer] The function to customize comparisons.
19175 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
19176 */
19177 function baseIsMatch(object, source, matchData, customizer) {
19178 var index = matchData.length,
19179 length = index,
19180 noCustomizer = !customizer;
19181
19182 if (object == null) {
19183 return !length;
19184 }
19185 object = Object(object);
19186 while (index--) {
19187 var data = matchData[index];
19188 if ((noCustomizer && data[2])
19189 ? data[1] !== object[data[0]]
19190 : !(data[0] in object)
19191 ) {
19192 return false;
19193 }
19194 }
19195 while (++index < length) {
19196 data = matchData[index];
19197 var key = data[0],
19198 objValue = object[key],
19199 srcValue = data[1];
19200
19201 if (noCustomizer && data[2]) {
19202 if (objValue === undefined && !(key in object)) {
19203 return false;
19204 }
19205 } else {
19206 var stack = new Stack,
19207 result = customizer ? customizer(objValue, srcValue, key, object, source, stack) : undefined;
19208
19209 if (!(result === undefined
19210 ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
19211 : result
19212 )) {
19213 return false;
19214 }
19215 }
19216 }
19217 return true;
19218 }
19219
19220 module.exports = baseIsMatch;
19221
19222
19223/***/ },
19224/* 54 */
19225/***/ function(module, exports, __webpack_require__) {
19226
19227 var baseMatches = __webpack_require__(56),
19228 baseMatchesProperty = __webpack_require__(57),
19229 identity = __webpack_require__(93),
19230 isArray = __webpack_require__(1),
19231 property = __webpack_require__(101);
19232
19233 /**
19234 * The base implementation of `_.iteratee`.
19235 *
19236 * @private
19237 * @param {*} [value=_.identity] The value to convert to an iteratee.
19238 * @returns {Function} Returns the iteratee.
19239 */
19240 function baseIteratee(value) {
19241 var type = typeof value;
19242 if (type == 'function') {
19243 return value;
19244 }
19245 if (value == null) {
19246 return identity;
19247 }
19248 if (type == 'object') {
19249 return isArray(value)
19250 ? baseMatchesProperty(value[0], value[1])
19251 : baseMatches(value);
19252 }
19253 return property(value);
19254 }
19255
19256 module.exports = baseIteratee;
19257
19258
19259/***/ },
19260/* 55 */
19261/***/ function(module, exports) {
19262
19263 /* Built-in method references for those with the same name as other `lodash` methods. */
19264 var nativeKeys = Object.keys;
19265
19266 /**
19267 * The base implementation of `_.keys` which doesn't skip the constructor
19268 * property of prototypes or treat sparse arrays as dense.
19269 *
19270 * @private
19271 * @type Function
19272 * @param {Object} object The object to query.
19273 * @returns {Array} Returns the array of property names.
19274 */
19275 function baseKeys(object) {
19276 return nativeKeys(Object(object));
19277 }
19278
19279 module.exports = baseKeys;
19280
19281
19282/***/ },
19283/* 56 */
19284/***/ function(module, exports, __webpack_require__) {
19285
19286 var baseIsMatch = __webpack_require__(53),
19287 getMatchData = __webpack_require__(68);
19288
19289 /**
19290 * The base implementation of `_.matches` which doesn't clone `source`.
19291 *
19292 * @private
19293 * @param {Object} source The object of property values to match.
19294 * @returns {Function} Returns the new function.
19295 */
19296 function baseMatches(source) {
19297 var matchData = getMatchData(source);
19298 if (matchData.length == 1 && matchData[0][2]) {
19299 var key = matchData[0][0],
19300 value = matchData[0][1];
19301
19302 return function(object) {
19303 if (object == null) {
19304 return false;
19305 }
19306 return object[key] === value &&
19307 (value !== undefined || (key in Object(object)));
19308 };
19309 }
19310 return function(object) {
19311 return object === source || baseIsMatch(object, source, matchData);
19312 };
19313 }
19314
19315 module.exports = baseMatches;
19316
19317
19318/***/ },
19319/* 57 */
19320/***/ function(module, exports, __webpack_require__) {
19321
19322 var baseIsEqual = __webpack_require__(24),
19323 get = __webpack_require__(29),
19324 hasIn = __webpack_require__(92);
19325
19326 /** Used to compose bitmasks for comparison styles. */
19327 var UNORDERED_COMPARE_FLAG = 1,
19328 PARTIAL_COMPARE_FLAG = 2;
19329
19330 /**
19331 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
19332 *
19333 * @private
19334 * @param {string} path The path of the property to get.
19335 * @param {*} srcValue The value to match.
19336 * @returns {Function} Returns the new function.
19337 */
19338 function baseMatchesProperty(path, srcValue) {
19339 return function(object) {
19340 var objValue = get(object, path);
19341 return (objValue === undefined && objValue === srcValue)
19342 ? hasIn(object, path)
19343 : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
19344 };
19345 }
19346
19347 module.exports = baseMatchesProperty;
19348
19349
19350/***/ },
19351/* 58 */
19352/***/ function(module, exports, __webpack_require__) {
19353
19354 var baseGet = __webpack_require__(22);
19355
19356 /**
19357 * A specialized version of `baseProperty` which supports deep paths.
19358 *
19359 * @private
19360 * @param {Array|string} path The path of the property to get.
19361 * @returns {Function} Returns the new function.
19362 */
19363 function basePropertyDeep(path) {
19364 return function(object) {
19365 return baseGet(object, path);
19366 };
19367 }
19368
19369 module.exports = basePropertyDeep;
19370
19371
19372/***/ },
19373/* 59 */
19374/***/ function(module, exports) {
19375
19376 /**
19377 * The base implementation of `_.slice` without an iteratee call guard.
19378 *
19379 * @private
19380 * @param {Array} array The array to slice.
19381 * @param {number} [start=0] The start position.
19382 * @param {number} [end=array.length] The end position.
19383 * @returns {Array} Returns the slice of `array`.
19384 */
19385 function baseSlice(array, start, end) {
19386 var index = -1,
19387 length = array.length;
19388
19389 if (start < 0) {
19390 start = -start > length ? 0 : (length + start);
19391 }
19392 end = end > length ? length : end;
19393 if (end < 0) {
19394 end += length;
19395 }
19396 length = start > end ? 0 : ((end - start) >>> 0);
19397 start >>>= 0;
19398
19399 var result = Array(length);
19400 while (++index < length) {
19401 result[index] = array[index + start];
19402 }
19403 return result;
19404 }
19405
19406 module.exports = baseSlice;
19407
19408
19409/***/ },
19410/* 60 */
19411/***/ function(module, exports) {
19412
19413 /**
19414 * The base implementation of `_.times` without support for iteratee shorthands
19415 * or max array length checks.
19416 *
19417 * @private
19418 * @param {number} n The number of times to invoke `iteratee`.
19419 * @param {Function} iteratee The function invoked per iteration.
19420 * @returns {Array} Returns the array of results.
19421 */
19422 function baseTimes(n, iteratee) {
19423 var index = -1,
19424 result = Array(n);
19425
19426 while (++index < n) {
19427 result[index] = iteratee(index);
19428 }
19429 return result;
19430 }
19431
19432 module.exports = baseTimes;
19433
19434
19435/***/ },
19436/* 61 */
19437/***/ function(module, exports, __webpack_require__) {
19438
19439 var arrayMap = __webpack_require__(47);
19440
19441 /**
19442 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
19443 * of key-value pairs for `object` corresponding to the property names of `props`.
19444 *
19445 * @private
19446 * @param {Object} object The object to query.
19447 * @param {Array} props The property names to get values for.
19448 * @returns {Object} Returns the new array of key-value pairs.
19449 */
19450 function baseToPairs(object, props) {
19451 return arrayMap(props, function(key) {
19452 return [key, object[key]];
19453 });
19454 }
19455
19456 module.exports = baseToPairs;
19457
19458
19459/***/ },
19460/* 62 */
19461/***/ function(module, exports) {
19462
19463 /**
19464 * Checks if `value` is a global object.
19465 *
19466 * @private
19467 * @param {*} value The value to check.
19468 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
19469 */
19470 function checkGlobal(value) {
19471 return (value && value.Object === Object) ? value : null;
19472 }
19473
19474 module.exports = checkGlobal;
19475
19476
19477/***/ },
19478/* 63 */
19479/***/ function(module, exports) {
19480
19481 /**
19482 * Creates a base function for methods like `_.forIn`.
19483 *
19484 * @private
19485 * @param {boolean} [fromRight] Specify iterating from right to left.
19486 * @returns {Function} Returns the new base function.
19487 */
19488 function createBaseFor(fromRight) {
19489 return function(object, iteratee, keysFunc) {
19490 var index = -1,
19491 iterable = Object(object),
19492 props = keysFunc(object),
19493 length = props.length;
19494
19495 while (length--) {
19496 var key = props[fromRight ? length : ++index];
19497 if (iteratee(iterable[key], key, iterable) === false) {
19498 break;
19499 }
19500 }
19501 return object;
19502 };
19503 }
19504
19505 module.exports = createBaseFor;
19506
19507
19508/***/ },
19509/* 64 */
19510/***/ function(module, exports, __webpack_require__) {
19511
19512 var arraySome = __webpack_require__(48);
19513
19514 /** Used to compose bitmasks for comparison styles. */
19515 var UNORDERED_COMPARE_FLAG = 1,
19516 PARTIAL_COMPARE_FLAG = 2;
19517
19518 /**
19519 * A specialized version of `baseIsEqualDeep` for arrays with support for
19520 * partial deep comparisons.
19521 *
19522 * @private
19523 * @param {Array} array The array to compare.
19524 * @param {Array} other The other array to compare.
19525 * @param {Function} equalFunc The function to determine equivalents of values.
19526 * @param {Function} [customizer] The function to customize comparisons.
19527 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
19528 * @param {Object} [stack] Tracks traversed `array` and `other` objects.
19529 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
19530 */
19531 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
19532 var index = -1,
19533 isPartial = bitmask & PARTIAL_COMPARE_FLAG,
19534 isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
19535 arrLength = array.length,
19536 othLength = other.length;
19537
19538 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
19539 return false;
19540 }
19541 // Assume cyclic values are equal.
19542 var stacked = stack.get(array);
19543 if (stacked) {
19544 return stacked == other;
19545 }
19546 var result = true;
19547 stack.set(array, other);
19548
19549 // Ignore non-index properties.
19550 while (++index < arrLength) {
19551 var arrValue = array[index],
19552 othValue = other[index];
19553
19554 if (customizer) {
19555 var compared = isPartial
19556 ? customizer(othValue, arrValue, index, other, array, stack)
19557 : customizer(arrValue, othValue, index, array, other, stack);
19558 }
19559 if (compared !== undefined) {
19560 if (compared) {
19561 continue;
19562 }
19563 result = false;
19564 break;
19565 }
19566 // Recursively compare arrays (susceptible to call stack limits).
19567 if (isUnordered) {
19568 if (!arraySome(other, function(othValue) {
19569 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
19570 })) {
19571 result = false;
19572 break;
19573 }
19574 } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
19575 result = false;
19576 break;
19577 }
19578 }
19579 stack['delete'](array);
19580 return result;
19581 }
19582
19583 module.exports = equalArrays;
19584
19585
19586/***/ },
19587/* 65 */
19588/***/ function(module, exports, __webpack_require__) {
19589
19590 var Symbol = __webpack_require__(17),
19591 Uint8Array = __webpack_require__(46),
19592 mapToArray = __webpack_require__(82),
19593 setToArray = __webpack_require__(84);
19594
19595 /** Used to compose bitmasks for comparison styles. */
19596 var UNORDERED_COMPARE_FLAG = 1,
19597 PARTIAL_COMPARE_FLAG = 2;
19598
19599 /** `Object#toString` result references. */
19600 var boolTag = '[object Boolean]',
19601 dateTag = '[object Date]',
19602 errorTag = '[object Error]',
19603 mapTag = '[object Map]',
19604 numberTag = '[object Number]',
19605 regexpTag = '[object RegExp]',
19606 setTag = '[object Set]',
19607 stringTag = '[object String]',
19608 symbolTag = '[object Symbol]';
19609
19610 var arrayBufferTag = '[object ArrayBuffer]';
19611
19612 /** Used to convert symbols to primitives and strings. */
19613 var symbolProto = Symbol ? Symbol.prototype : undefined,
19614 symbolValueOf = Symbol ? symbolProto.valueOf : undefined;
19615
19616 /**
19617 * A specialized version of `baseIsEqualDeep` for comparing objects of
19618 * the same `toStringTag`.
19619 *
19620 * **Note:** This function only supports comparing values with tags of
19621 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
19622 *
19623 * @private
19624 * @param {Object} object The object to compare.
19625 * @param {Object} other The other object to compare.
19626 * @param {string} tag The `toStringTag` of the objects to compare.
19627 * @param {Function} equalFunc The function to determine equivalents of values.
19628 * @param {Function} [customizer] The function to customize comparisons.
19629 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
19630 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
19631 */
19632 function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
19633 switch (tag) {
19634 case arrayBufferTag:
19635 if ((object.byteLength != other.byteLength) ||
19636 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
19637 return false;
19638 }
19639 return true;
19640
19641 case boolTag:
19642 case dateTag:
19643 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
19644 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
19645 return +object == +other;
19646
19647 case errorTag:
19648 return object.name == other.name && object.message == other.message;
19649
19650 case numberTag:
19651 // Treat `NaN` vs. `NaN` as equal.
19652 return (object != +object) ? other != +other : object == +other;
19653
19654 case regexpTag:
19655 case stringTag:
19656 // Coerce regexes to strings and treat strings primitives and string
19657 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
19658 return object == (other + '');
19659
19660 case mapTag:
19661 var convert = mapToArray;
19662
19663 case setTag:
19664 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
19665 convert || (convert = setToArray);
19666
19667 // Recursively compare objects (susceptible to call stack limits).
19668 return (isPartial || object.size == other.size) &&
19669 equalFunc(convert(object), convert(other), customizer, bitmask | UNORDERED_COMPARE_FLAG);
19670
19671 case symbolTag:
19672 return !!Symbol && (symbolValueOf.call(object) == symbolValueOf.call(other));
19673 }
19674 return false;
19675 }
19676
19677 module.exports = equalByTag;
19678
19679
19680/***/ },
19681/* 66 */
19682/***/ function(module, exports, __webpack_require__) {
19683
19684 var baseHas = __webpack_require__(23),
19685 keys = __webpack_require__(14);
19686
19687 /** Used to compose bitmasks for comparison styles. */
19688 var PARTIAL_COMPARE_FLAG = 2;
19689
19690 /**
19691 * A specialized version of `baseIsEqualDeep` for objects with support for
19692 * partial deep comparisons.
19693 *
19694 * @private
19695 * @param {Object} object The object to compare.
19696 * @param {Object} other The other object to compare.
19697 * @param {Function} equalFunc The function to determine equivalents of values.
19698 * @param {Function} [customizer] The function to customize comparisons.
19699 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
19700 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
19701 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
19702 */
19703 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
19704 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
19705 objProps = keys(object),
19706 objLength = objProps.length,
19707 othProps = keys(other),
19708 othLength = othProps.length;
19709
19710 if (objLength != othLength && !isPartial) {
19711 return false;
19712 }
19713 var index = objLength;
19714 while (index--) {
19715 var key = objProps[index];
19716 if (!(isPartial ? key in other : baseHas(other, key))) {
19717 return false;
19718 }
19719 }
19720 // Assume cyclic values are equal.
19721 var stacked = stack.get(object);
19722 if (stacked) {
19723 return stacked == other;
19724 }
19725 var result = true;
19726 stack.set(object, other);
19727
19728 var skipCtor = isPartial;
19729 while (++index < objLength) {
19730 key = objProps[index];
19731 var objValue = object[key],
19732 othValue = other[key];
19733
19734 if (customizer) {
19735 var compared = isPartial
19736 ? customizer(othValue, objValue, key, other, object, stack)
19737 : customizer(objValue, othValue, key, object, other, stack);
19738 }
19739 // Recursively compare objects (susceptible to call stack limits).
19740 if (!(compared === undefined
19741 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
19742 : compared
19743 )) {
19744 result = false;
19745 break;
19746 }
19747 skipCtor || (skipCtor = key == 'constructor');
19748 }
19749 if (result && !skipCtor) {
19750 var objCtor = object.constructor,
19751 othCtor = other.constructor;
19752
19753 // Non `Object` object instances with different constructors are not equal.
19754 if (objCtor != othCtor &&
19755 ('constructor' in object && 'constructor' in other) &&
19756 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
19757 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
19758 result = false;
19759 }
19760 }
19761 stack['delete'](object);
19762 return result;
19763 }
19764
19765 module.exports = equalObjects;
19766
19767
19768/***/ },
19769/* 67 */
19770/***/ function(module, exports, __webpack_require__) {
19771
19772 var baseProperty = __webpack_require__(25);
19773
19774 /**
19775 * Gets the "length" property value of `object`.
19776 *
19777 * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
19778 * that affects Safari on at least iOS 8.1-8.3 ARM64.
19779 *
19780 * @private
19781 * @param {Object} object The object to query.
19782 * @returns {*} Returns the "length" value.
19783 */
19784 var getLength = baseProperty('length');
19785
19786 module.exports = getLength;
19787
19788
19789/***/ },
19790/* 68 */
19791/***/ function(module, exports, __webpack_require__) {
19792
19793 var isStrictComparable = __webpack_require__(76),
19794 toPairs = __webpack_require__(102);
19795
19796 /**
19797 * Gets the property names, values, and compare flags of `object`.
19798 *
19799 * @private
19800 * @param {Object} object The object to query.
19801 * @returns {Array} Returns the match data of `object`.
19802 */
19803 function getMatchData(object) {
19804 var result = toPairs(object),
19805 length = result.length;
19806
19807 while (length--) {
19808 result[length][2] = isStrictComparable(result[length][1]);
19809 }
19810 return result;
19811 }
19812
19813 module.exports = getMatchData;
19814
19815
19816/***/ },
19817/* 69 */
19818/***/ function(module, exports, __webpack_require__) {
19819
19820 var Map = __webpack_require__(3),
19821 Set = __webpack_require__(45);
19822
19823 /** `Object#toString` result references. */
19824 var mapTag = '[object Map]',
19825 objectTag = '[object Object]',
19826 setTag = '[object Set]';
19827
19828 /** Used for built-in method references. */
19829 var objectProto = Object.prototype;
19830
19831 /** Used to resolve the decompiled source of functions. */
19832 var funcToString = Function.prototype.toString;
19833
19834 /**
19835 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
19836 * of values.
19837 */
19838 var objectToString = objectProto.toString;
19839
19840 /** Used to detect maps and sets. */
19841 var mapCtorString = Map ? funcToString.call(Map) : '',
19842 setCtorString = Set ? funcToString.call(Set) : '';
19843
19844 /**
19845 * Gets the `toStringTag` of `value`.
19846 *
19847 * @private
19848 * @param {*} value The value to query.
19849 * @returns {string} Returns the `toStringTag`.
19850 */
19851 function getTag(value) {
19852 return objectToString.call(value);
19853 }
19854
19855 // Fallback for IE 11 providing `toStringTag` values for maps and sets.
19856 if ((Map && getTag(new Map) != mapTag) || (Set && getTag(new Set) != setTag)) {
19857 getTag = function(value) {
19858 var result = objectToString.call(value),
19859 Ctor = result == objectTag ? value.constructor : null,
19860 ctorString = typeof Ctor == 'function' ? funcToString.call(Ctor) : '';
19861
19862 if (ctorString) {
19863 if (ctorString == mapCtorString) {
19864 return mapTag;
19865 }
19866 if (ctorString == setCtorString) {
19867 return setTag;
19868 }
19869 }
19870 return result;
19871 };
19872 }
19873
19874 module.exports = getTag;
19875
19876
19877/***/ },
19878/* 70 */
19879/***/ function(module, exports, __webpack_require__) {
19880
19881 var baseToPath = __webpack_require__(26),
19882 isArguments = __webpack_require__(30),
19883 isArray = __webpack_require__(1),
19884 isIndex = __webpack_require__(28),
19885 isKey = __webpack_require__(12),
19886 isLength = __webpack_require__(9),
19887 isString = __webpack_require__(33),
19888 last = __webpack_require__(99),
19889 parent = __webpack_require__(83);
19890
19891 /**
19892 * Checks if `path` exists on `object`.
19893 *
19894 * @private
19895 * @param {Object} object The object to query.
19896 * @param {Array|string} path The path to check.
19897 * @param {Function} hasFunc The function to check properties.
19898 * @returns {boolean} Returns `true` if `path` exists, else `false`.
19899 */
19900 function hasPath(object, path, hasFunc) {
19901 if (object == null) {
19902 return false;
19903 }
19904 var result = hasFunc(object, path);
19905 if (!result && !isKey(path)) {
19906 path = baseToPath(path);
19907 object = parent(object, path);
19908 if (object != null) {
19909 path = last(path);
19910 result = hasFunc(object, path);
19911 }
19912 }
19913 var length = object ? object.length : undefined;
19914 return result || (
19915 !!length && isLength(length) && isIndex(path, length) &&
19916 (isArray(object) || isString(object) || isArguments(object))
19917 );
19918 }
19919
19920 module.exports = hasPath;
19921
19922
19923/***/ },
19924/* 71 */
19925/***/ function(module, exports, __webpack_require__) {
19926
19927 var hashHas = __webpack_require__(27);
19928
19929 /**
19930 * Removes `key` and its value from the hash.
19931 *
19932 * @private
19933 * @param {Object} hash The hash to modify.
19934 * @param {string} key The key of the value to remove.
19935 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
19936 */
19937 function hashDelete(hash, key) {
19938 return hashHas(hash, key) && delete hash[key];
19939 }
19940
19941 module.exports = hashDelete;
19942
19943
19944/***/ },
19945/* 72 */
19946/***/ function(module, exports, __webpack_require__) {
19947
19948 var nativeCreate = __webpack_require__(7);
19949
19950 /** Used to stand-in for `undefined` hash values. */
19951 var HASH_UNDEFINED = '__lodash_hash_undefined__';
19952
19953 /** Used for built-in method references. */
19954 var objectProto = Object.prototype;
19955
19956 /** Used to check objects for own properties. */
19957 var hasOwnProperty = objectProto.hasOwnProperty;
19958
19959 /**
19960 * Gets the hash value for `key`.
19961 *
19962 * @private
19963 * @param {Object} hash The hash to query.
19964 * @param {string} key The key of the value to get.
19965 * @returns {*} Returns the entry value.
19966 */
19967 function hashGet(hash, key) {
19968 if (nativeCreate) {
19969 var result = hash[key];
19970 return result === HASH_UNDEFINED ? undefined : result;
19971 }
19972 return hasOwnProperty.call(hash, key) ? hash[key] : undefined;
19973 }
19974
19975 module.exports = hashGet;
19976
19977
19978/***/ },
19979/* 73 */
19980/***/ function(module, exports, __webpack_require__) {
19981
19982 var nativeCreate = __webpack_require__(7);
19983
19984 /** Used to stand-in for `undefined` hash values. */
19985 var HASH_UNDEFINED = '__lodash_hash_undefined__';
19986
19987 /**
19988 * Sets the hash `key` to `value`.
19989 *
19990 * @private
19991 * @param {Object} hash The hash to modify.
19992 * @param {string} key The key of the value to set.
19993 * @param {*} value The value to set.
19994 */
19995 function hashSet(hash, key, value) {
19996 hash[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
19997 }
19998
19999 module.exports = hashSet;
20000
20001
20002/***/ },
20003/* 74 */
20004/***/ function(module, exports, __webpack_require__) {
20005
20006 var baseTimes = __webpack_require__(60),
20007 isArguments = __webpack_require__(30),
20008 isArray = __webpack_require__(1),
20009 isLength = __webpack_require__(9),
20010 isString = __webpack_require__(33);
20011
20012 /**
20013 * Creates an array of index keys for `object` values of arrays,
20014 * `arguments` objects, and strings, otherwise `null` is returned.
20015 *
20016 * @private
20017 * @param {Object} object The object to query.
20018 * @returns {Array|null} Returns index keys, else `null`.
20019 */
20020 function indexKeys(object) {
20021 var length = object ? object.length : undefined;
20022 if (isLength(length) &&
20023 (isArray(object) || isString(object) || isArguments(object))) {
20024 return baseTimes(length, String);
20025 }
20026 return null;
20027 }
20028
20029 module.exports = indexKeys;
20030
20031
20032/***/ },
20033/* 75 */
20034/***/ function(module, exports) {
20035
20036 /** Used for built-in method references. */
20037 var objectProto = Object.prototype;
20038
20039 /**
20040 * Checks if `value` is likely a prototype object.
20041 *
20042 * @private
20043 * @param {*} value The value to check.
20044 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
20045 */
20046 function isPrototype(value) {
20047 var Ctor = value && value.constructor,
20048 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
20049
20050 return value === proto;
20051 }
20052
20053 module.exports = isPrototype;
20054
20055
20056/***/ },
20057/* 76 */
20058/***/ function(module, exports, __webpack_require__) {
20059
20060 var isObject = __webpack_require__(13);
20061
20062 /**
20063 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
20064 *
20065 * @private
20066 * @param {*} value The value to check.
20067 * @returns {boolean} Returns `true` if `value` if suitable for strict
20068 * equality comparisons, else `false`.
20069 */
20070 function isStrictComparable(value) {
20071 return value === value && !isObject(value);
20072 }
20073
20074 module.exports = isStrictComparable;
20075
20076
20077/***/ },
20078/* 77 */
20079/***/ function(module, exports, __webpack_require__) {
20080
20081 var Hash = __webpack_require__(43),
20082 Map = __webpack_require__(3);
20083
20084 /**
20085 * Removes all key-value entries from the map.
20086 *
20087 * @private
20088 * @name clear
20089 * @memberOf MapCache
20090 */
20091 function mapClear() {
20092 this.__data__ = { 'hash': new Hash, 'map': Map ? new Map : [], 'string': new Hash };
20093 }
20094
20095 module.exports = mapClear;
20096
20097
20098/***/ },
20099/* 78 */
20100/***/ function(module, exports, __webpack_require__) {
20101
20102 var Map = __webpack_require__(3),
20103 assocDelete = __webpack_require__(18),
20104 hashDelete = __webpack_require__(71),
20105 isKeyable = __webpack_require__(6);
20106
20107 /**
20108 * Removes `key` and its value from the map.
20109 *
20110 * @private
20111 * @name delete
20112 * @memberOf MapCache
20113 * @param {string} key The key of the value to remove.
20114 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
20115 */
20116 function mapDelete(key) {
20117 var data = this.__data__;
20118 if (isKeyable(key)) {
20119 return hashDelete(typeof key == 'string' ? data.string : data.hash, key);
20120 }
20121 return Map ? data.map['delete'](key) : assocDelete(data.map, key);
20122 }
20123
20124 module.exports = mapDelete;
20125
20126
20127/***/ },
20128/* 79 */
20129/***/ function(module, exports, __webpack_require__) {
20130
20131 var Map = __webpack_require__(3),
20132 assocGet = __webpack_require__(19),
20133 hashGet = __webpack_require__(72),
20134 isKeyable = __webpack_require__(6);
20135
20136 /**
20137 * Gets the map value for `key`.
20138 *
20139 * @private
20140 * @name get
20141 * @memberOf MapCache
20142 * @param {string} key The key of the value to get.
20143 * @returns {*} Returns the entry value.
20144 */
20145 function mapGet(key) {
20146 var data = this.__data__;
20147 if (isKeyable(key)) {
20148 return hashGet(typeof key == 'string' ? data.string : data.hash, key);
20149 }
20150 return Map ? data.map.get(key) : assocGet(data.map, key);
20151 }
20152
20153 module.exports = mapGet;
20154
20155
20156/***/ },
20157/* 80 */
20158/***/ function(module, exports, __webpack_require__) {
20159
20160 var Map = __webpack_require__(3),
20161 assocHas = __webpack_require__(20),
20162 hashHas = __webpack_require__(27),
20163 isKeyable = __webpack_require__(6);
20164
20165 /**
20166 * Checks if a map value for `key` exists.
20167 *
20168 * @private
20169 * @name has
20170 * @memberOf MapCache
20171 * @param {string} key The key of the entry to check.
20172 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
20173 */
20174 function mapHas(key) {
20175 var data = this.__data__;
20176 if (isKeyable(key)) {
20177 return hashHas(typeof key == 'string' ? data.string : data.hash, key);
20178 }
20179 return Map ? data.map.has(key) : assocHas(data.map, key);
20180 }
20181
20182 module.exports = mapHas;
20183
20184
20185/***/ },
20186/* 81 */
20187/***/ function(module, exports, __webpack_require__) {
20188
20189 var Map = __webpack_require__(3),
20190 assocSet = __webpack_require__(21),
20191 hashSet = __webpack_require__(73),
20192 isKeyable = __webpack_require__(6);
20193
20194 /**
20195 * Sets the map `key` to `value`.
20196 *
20197 * @private
20198 * @name set
20199 * @memberOf MapCache
20200 * @param {string} key The key of the value to set.
20201 * @param {*} value The value to set.
20202 * @returns {Object} Returns the map cache object.
20203 */
20204 function mapSet(key, value) {
20205 var data = this.__data__;
20206 if (isKeyable(key)) {
20207 hashSet(typeof key == 'string' ? data.string : data.hash, key, value);
20208 } else if (Map) {
20209 data.map.set(key, value);
20210 } else {
20211 assocSet(data.map, key, value);
20212 }
20213 return this;
20214 }
20215
20216 module.exports = mapSet;
20217
20218
20219/***/ },
20220/* 82 */
20221/***/ function(module, exports) {
20222
20223 /**
20224 * Converts `map` to an array.
20225 *
20226 * @private
20227 * @param {Object} map The map to convert.
20228 * @returns {Array} Returns the converted array.
20229 */
20230 function mapToArray(map) {
20231 var index = -1,
20232 result = Array(map.size);
20233
20234 map.forEach(function(value, key) {
20235 result[++index] = [key, value];
20236 });
20237 return result;
20238 }
20239
20240 module.exports = mapToArray;
20241
20242
20243/***/ },
20244/* 83 */
20245/***/ function(module, exports, __webpack_require__) {
20246
20247 var baseSlice = __webpack_require__(59),
20248 get = __webpack_require__(29);
20249
20250 /**
20251 * Gets the parent value at `path` of `object`.
20252 *
20253 * @private
20254 * @param {Object} object The object to query.
20255 * @param {Array} path The path to get the parent value of.
20256 * @returns {*} Returns the parent value.
20257 */
20258 function parent(object, path) {
20259 return path.length == 1 ? object : get(object, baseSlice(path, 0, -1));
20260 }
20261
20262 module.exports = parent;
20263
20264
20265/***/ },
20266/* 84 */
20267/***/ function(module, exports) {
20268
20269 /**
20270 * Converts `set` to an array.
20271 *
20272 * @private
20273 * @param {Object} set The set to convert.
20274 * @returns {Array} Returns the converted array.
20275 */
20276 function setToArray(set) {
20277 var index = -1,
20278 result = Array(set.size);
20279
20280 set.forEach(function(value) {
20281 result[++index] = value;
20282 });
20283 return result;
20284 }
20285
20286 module.exports = setToArray;
20287
20288
20289/***/ },
20290/* 85 */
20291/***/ function(module, exports) {
20292
20293 /**
20294 * Removes all key-value entries from the stack.
20295 *
20296 * @private
20297 * @name clear
20298 * @memberOf Stack
20299 */
20300 function stackClear() {
20301 this.__data__ = { 'array': [], 'map': null };
20302 }
20303
20304 module.exports = stackClear;
20305
20306
20307/***/ },
20308/* 86 */
20309/***/ function(module, exports, __webpack_require__) {
20310
20311 var assocDelete = __webpack_require__(18);
20312
20313 /**
20314 * Removes `key` and its value from the stack.
20315 *
20316 * @private
20317 * @name delete
20318 * @memberOf Stack
20319 * @param {string} key The key of the value to remove.
20320 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
20321 */
20322 function stackDelete(key) {
20323 var data = this.__data__,
20324 array = data.array;
20325
20326 return array ? assocDelete(array, key) : data.map['delete'](key);
20327 }
20328
20329 module.exports = stackDelete;
20330
20331
20332/***/ },
20333/* 87 */
20334/***/ function(module, exports, __webpack_require__) {
20335
20336 var assocGet = __webpack_require__(19);
20337
20338 /**
20339 * Gets the stack value for `key`.
20340 *
20341 * @private
20342 * @name get
20343 * @memberOf Stack
20344 * @param {string} key The key of the value to get.
20345 * @returns {*} Returns the entry value.
20346 */
20347 function stackGet(key) {
20348 var data = this.__data__,
20349 array = data.array;
20350
20351 return array ? assocGet(array, key) : data.map.get(key);
20352 }
20353
20354 module.exports = stackGet;
20355
20356
20357/***/ },
20358/* 88 */
20359/***/ function(module, exports, __webpack_require__) {
20360
20361 var assocHas = __webpack_require__(20);
20362
20363 /**
20364 * Checks if a stack value for `key` exists.
20365 *
20366 * @private
20367 * @name has
20368 * @memberOf Stack
20369 * @param {string} key The key of the entry to check.
20370 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
20371 */
20372 function stackHas(key) {
20373 var data = this.__data__,
20374 array = data.array;
20375
20376 return array ? assocHas(array, key) : data.map.has(key);
20377 }
20378
20379 module.exports = stackHas;
20380
20381
20382/***/ },
20383/* 89 */
20384/***/ function(module, exports, __webpack_require__) {
20385
20386 var MapCache = __webpack_require__(44),
20387 assocSet = __webpack_require__(21);
20388
20389 /** Used as the size to enable large array optimizations. */
20390 var LARGE_ARRAY_SIZE = 200;
20391
20392 /**
20393 * Sets the stack `key` to `value`.
20394 *
20395 * @private
20396 * @name set
20397 * @memberOf Stack
20398 * @param {string} key The key of the value to set.
20399 * @param {*} value The value to set.
20400 * @returns {Object} Returns the stack cache object.
20401 */
20402 function stackSet(key, value) {
20403 var data = this.__data__,
20404 array = data.array;
20405
20406 if (array) {
20407 if (array.length < (LARGE_ARRAY_SIZE - 1)) {
20408 assocSet(array, key, value);
20409 } else {
20410 data.array = null;
20411 data.map = new MapCache(array);
20412 }
20413 }
20414 var map = data.map;
20415 if (map) {
20416 map.set(key, value);
20417 }
20418 return this;
20419 }
20420
20421 module.exports = stackSet;
20422
20423
20424/***/ },
20425/* 90 */
20426/***/ function(module, exports, __webpack_require__) {
20427
20428 var toString = __webpack_require__(103);
20429
20430 /** Used to match property names within property paths. */
20431 var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g;
20432
20433 /** Used to match backslashes in property paths. */
20434 var reEscapeChar = /\\(\\)?/g;
20435
20436 /**
20437 * Converts `string` to a property path array.
20438 *
20439 * @private
20440 * @param {string} string The string to convert.
20441 * @returns {Array} Returns the property path array.
20442 */
20443 function stringToPath(string) {
20444 var result = [];
20445 toString(string).replace(rePropName, function(match, number, quote, string) {
20446 result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
20447 });
20448 return result;
20449 }
20450
20451 module.exports = stringToPath;
20452
20453
20454/***/ },
20455/* 91 */
20456/***/ function(module, exports) {
20457
20458 /**
20459 * Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
20460 * comparison between two values to determine if they are equivalent.
20461 *
20462 * @static
20463 * @memberOf _
20464 * @category Lang
20465 * @param {*} value The value to compare.
20466 * @param {*} other The other value to compare.
20467 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
20468 * @example
20469 *
20470 * var object = { 'user': 'fred' };
20471 * var other = { 'user': 'fred' };
20472 *
20473 * _.eq(object, object);
20474 * // => true
20475 *
20476 * _.eq(object, other);
20477 * // => false
20478 *
20479 * _.eq('a', 'a');
20480 * // => true
20481 *
20482 * _.eq('a', Object('a'));
20483 * // => false
20484 *
20485 * _.eq(NaN, NaN);
20486 * // => true
20487 */
20488 function eq(value, other) {
20489 return value === other || (value !== value && other !== other);
20490 }
20491
20492 module.exports = eq;
20493
20494
20495/***/ },
20496/* 92 */
20497/***/ function(module, exports, __webpack_require__) {
20498
20499 var baseHasIn = __webpack_require__(51),
20500 hasPath = __webpack_require__(70);
20501
20502 /**
20503 * Checks if `path` is a direct or inherited property of `object`.
20504 *
20505 * @static
20506 * @memberOf _
20507 * @category Object
20508 * @param {Object} object The object to query.
20509 * @param {Array|string} path The path to check.
20510 * @returns {boolean} Returns `true` if `path` exists, else `false`.
20511 * @example
20512 *
20513 * var object = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
20514 *
20515 * _.hasIn(object, 'a');
20516 * // => true
20517 *
20518 * _.hasIn(object, 'a.b.c');
20519 * // => true
20520 *
20521 * _.hasIn(object, ['a', 'b', 'c']);
20522 * // => true
20523 *
20524 * _.hasIn(object, 'b');
20525 * // => false
20526 */
20527 function hasIn(object, path) {
20528 return hasPath(object, path, baseHasIn);
20529 }
20530
20531 module.exports = hasIn;
20532
20533
20534/***/ },
20535/* 93 */
20536/***/ function(module, exports) {
20537
20538 /**
20539 * This method returns the first argument provided to it.
20540 *
20541 * @static
20542 * @memberOf _
20543 * @category Util
20544 * @param {*} value Any value.
20545 * @returns {*} Returns `value`.
20546 * @example
20547 *
20548 * var object = { 'user': 'fred' };
20549 *
20550 * _.identity(object) === object;
20551 * // => true
20552 */
20553 function identity(value) {
20554 return value;
20555 }
20556
20557 module.exports = identity;
20558
20559
20560/***/ },
20561/* 94 */
20562/***/ function(module, exports, __webpack_require__) {
20563
20564 var isArrayLike = __webpack_require__(31),
20565 isObjectLike = __webpack_require__(2);
20566
20567 /**
20568 * This method is like `_.isArrayLike` except that it also checks if `value`
20569 * is an object.
20570 *
20571 * @static
20572 * @memberOf _
20573 * @type Function
20574 * @category Lang
20575 * @param {*} value The value to check.
20576 * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
20577 * @example
20578 *
20579 * _.isArrayLikeObject([1, 2, 3]);
20580 * // => true
20581 *
20582 * _.isArrayLikeObject(document.body.children);
20583 * // => true
20584 *
20585 * _.isArrayLikeObject('abc');
20586 * // => false
20587 *
20588 * _.isArrayLikeObject(_.noop);
20589 * // => false
20590 */
20591 function isArrayLikeObject(value) {
20592 return isObjectLike(value) && isArrayLike(value);
20593 }
20594
20595 module.exports = isArrayLikeObject;
20596
20597
20598/***/ },
20599/* 95 */
20600/***/ function(module, exports, __webpack_require__) {
20601
20602 var isFunction = __webpack_require__(32),
20603 isHostObject = __webpack_require__(11),
20604 isObjectLike = __webpack_require__(2);
20605
20606 /** Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). */
20607 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
20608
20609 /** Used to detect host constructors (Safari > 5). */
20610 var reIsHostCtor = /^\[object .+?Constructor\]$/;
20611
20612 /** Used for built-in method references. */
20613 var objectProto = Object.prototype;
20614
20615 /** Used to resolve the decompiled source of functions. */
20616 var funcToString = Function.prototype.toString;
20617
20618 /** Used to check objects for own properties. */
20619 var hasOwnProperty = objectProto.hasOwnProperty;
20620
20621 /** Used to detect if a method is native. */
20622 var reIsNative = RegExp('^' +
20623 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
20624 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
20625 );
20626
20627 /**
20628 * Checks if `value` is a native function.
20629 *
20630 * @static
20631 * @memberOf _
20632 * @category Lang
20633 * @param {*} value The value to check.
20634 * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
20635 * @example
20636 *
20637 * _.isNative(Array.prototype.push);
20638 * // => true
20639 *
20640 * _.isNative(_);
20641 * // => false
20642 */
20643 function isNative(value) {
20644 if (value == null) {
20645 return false;
20646 }
20647 if (isFunction(value)) {
20648 return reIsNative.test(funcToString.call(value));
20649 }
20650 return isObjectLike(value) &&
20651 (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
20652 }
20653
20654 module.exports = isNative;
20655
20656
20657/***/ },
20658/* 96 */
20659/***/ function(module, exports, __webpack_require__) {
20660
20661 var isHostObject = __webpack_require__(11),
20662 isObjectLike = __webpack_require__(2);
20663
20664 /** `Object#toString` result references. */
20665 var objectTag = '[object Object]';
20666
20667 /** Used for built-in method references. */
20668 var objectProto = Object.prototype;
20669
20670 /** Used to resolve the decompiled source of functions. */
20671 var funcToString = Function.prototype.toString;
20672
20673 /** Used to infer the `Object` constructor. */
20674 var objectCtorString = funcToString.call(Object);
20675
20676 /**
20677 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
20678 * of values.
20679 */
20680 var objectToString = objectProto.toString;
20681
20682 /** Built-in value references. */
20683 var getPrototypeOf = Object.getPrototypeOf;
20684
20685 /**
20686 * Checks if `value` is a plain object, that is, an object created by the
20687 * `Object` constructor or one with a `[[Prototype]]` of `null`.
20688 *
20689 * @static
20690 * @memberOf _
20691 * @category Lang
20692 * @param {*} value The value to check.
20693 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
20694 * @example
20695 *
20696 * function Foo() {
20697 * this.a = 1;
20698 * }
20699 *
20700 * _.isPlainObject(new Foo);
20701 * // => false
20702 *
20703 * _.isPlainObject([1, 2, 3]);
20704 * // => false
20705 *
20706 * _.isPlainObject({ 'x': 0, 'y': 0 });
20707 * // => true
20708 *
20709 * _.isPlainObject(Object.create(null));
20710 * // => true
20711 */
20712 function isPlainObject(value) {
20713 if (!isObjectLike(value) || objectToString.call(value) != objectTag || isHostObject(value)) {
20714 return false;
20715 }
20716 var proto = objectProto;
20717 if (typeof value.constructor == 'function') {
20718 proto = getPrototypeOf(value);
20719 }
20720 if (proto === null) {
20721 return true;
20722 }
20723 var Ctor = proto.constructor;
20724 return (typeof Ctor == 'function' &&
20725 Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
20726 }
20727
20728 module.exports = isPlainObject;
20729
20730
20731/***/ },
20732/* 97 */
20733/***/ function(module, exports, __webpack_require__) {
20734
20735 var isObjectLike = __webpack_require__(2);
20736
20737 /** `Object#toString` result references. */
20738 var symbolTag = '[object Symbol]';
20739
20740 /** Used for built-in method references. */
20741 var objectProto = Object.prototype;
20742
20743 /**
20744 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
20745 * of values.
20746 */
20747 var objectToString = objectProto.toString;
20748
20749 /**
20750 * Checks if `value` is classified as a `Symbol` primitive or object.
20751 *
20752 * @static
20753 * @memberOf _
20754 * @category Lang
20755 * @param {*} value The value to check.
20756 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
20757 * @example
20758 *
20759 * _.isSymbol(Symbol.iterator);
20760 * // => true
20761 *
20762 * _.isSymbol('abc');
20763 * // => false
20764 */
20765 function isSymbol(value) {
20766 return typeof value == 'symbol' ||
20767 (isObjectLike(value) && objectToString.call(value) == symbolTag);
20768 }
20769
20770 module.exports = isSymbol;
20771
20772
20773/***/ },
20774/* 98 */
20775/***/ function(module, exports, __webpack_require__) {
20776
20777 var isLength = __webpack_require__(9),
20778 isObjectLike = __webpack_require__(2);
20779
20780 /** `Object#toString` result references. */
20781 var argsTag = '[object Arguments]',
20782 arrayTag = '[object Array]',
20783 boolTag = '[object Boolean]',
20784 dateTag = '[object Date]',
20785 errorTag = '[object Error]',
20786 funcTag = '[object Function]',
20787 mapTag = '[object Map]',
20788 numberTag = '[object Number]',
20789 objectTag = '[object Object]',
20790 regexpTag = '[object RegExp]',
20791 setTag = '[object Set]',
20792 stringTag = '[object String]',
20793 weakMapTag = '[object WeakMap]';
20794
20795 var arrayBufferTag = '[object ArrayBuffer]',
20796 float32Tag = '[object Float32Array]',
20797 float64Tag = '[object Float64Array]',
20798 int8Tag = '[object Int8Array]',
20799 int16Tag = '[object Int16Array]',
20800 int32Tag = '[object Int32Array]',
20801 uint8Tag = '[object Uint8Array]',
20802 uint8ClampedTag = '[object Uint8ClampedArray]',
20803 uint16Tag = '[object Uint16Array]',
20804 uint32Tag = '[object Uint32Array]';
20805
20806 /** Used to identify `toStringTag` values of typed arrays. */
20807 var typedArrayTags = {};
20808 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
20809 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
20810 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
20811 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
20812 typedArrayTags[uint32Tag] = true;
20813 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
20814 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
20815 typedArrayTags[dateTag] = typedArrayTags[errorTag] =
20816 typedArrayTags[funcTag] = typedArrayTags[mapTag] =
20817 typedArrayTags[numberTag] = typedArrayTags[objectTag] =
20818 typedArrayTags[regexpTag] = typedArrayTags[setTag] =
20819 typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
20820
20821 /** Used for built-in method references. */
20822 var objectProto = Object.prototype;
20823
20824 /**
20825 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
20826 * of values.
20827 */
20828 var objectToString = objectProto.toString;
20829
20830 /**
20831 * Checks if `value` is classified as a typed array.
20832 *
20833 * @static
20834 * @memberOf _
20835 * @category Lang
20836 * @param {*} value The value to check.
20837 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
20838 * @example
20839 *
20840 * _.isTypedArray(new Uint8Array);
20841 * // => true
20842 *
20843 * _.isTypedArray([]);
20844 * // => false
20845 */
20846 function isTypedArray(value) {
20847 return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
20848 }
20849
20850 module.exports = isTypedArray;
20851
20852
20853/***/ },
20854/* 99 */
20855/***/ function(module, exports) {
20856
20857 /**
20858 * Gets the last element of `array`.
20859 *
20860 * @static
20861 * @memberOf _
20862 * @category Array
20863 * @param {Array} array The array to query.
20864 * @returns {*} Returns the last element of `array`.
20865 * @example
20866 *
20867 * _.last([1, 2, 3]);
20868 * // => 3
20869 */
20870 function last(array) {
20871 var length = array ? array.length : 0;
20872 return length ? array[length - 1] : undefined;
20873 }
20874
20875 module.exports = last;
20876
20877
20878/***/ },
20879/* 100 */
20880/***/ function(module, exports, __webpack_require__) {
20881
20882 var baseForOwn = __webpack_require__(50),
20883 baseIteratee = __webpack_require__(54);
20884
20885 /**
20886 * Creates an object with the same keys as `object` and values generated by
20887 * running each own enumerable property of `object` through `iteratee`. The
20888 * iteratee function is invoked with three arguments: (value, key, object).
20889 *
20890 * @static
20891 * @memberOf _
20892 * @category Object
20893 * @param {Object} object The object to iterate over.
20894 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
20895 * @returns {Object} Returns the new mapped object.
20896 * @example
20897 *
20898 * var users = {
20899 * 'fred': { 'user': 'fred', 'age': 40 },
20900 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
20901 * };
20902 *
20903 * _.mapValues(users, function(o) { return o.age; });
20904 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
20905 *
20906 * // The `_.property` iteratee shorthand.
20907 * _.mapValues(users, 'age');
20908 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
20909 */
20910 function mapValues(object, iteratee) {
20911 var result = {};
20912 iteratee = baseIteratee(iteratee, 3);
20913
20914 baseForOwn(object, function(value, key, object) {
20915 result[key] = iteratee(value, key, object);
20916 });
20917 return result;
20918 }
20919
20920 module.exports = mapValues;
20921
20922
20923/***/ },
20924/* 101 */
20925/***/ function(module, exports, __webpack_require__) {
20926
20927 var baseProperty = __webpack_require__(25),
20928 basePropertyDeep = __webpack_require__(58),
20929 isKey = __webpack_require__(12);
20930
20931 /**
20932 * Creates a function that returns the value at `path` of a given object.
20933 *
20934 * @static
20935 * @memberOf _
20936 * @category Util
20937 * @param {Array|string} path The path of the property to get.
20938 * @returns {Function} Returns the new function.
20939 * @example
20940 *
20941 * var objects = [
20942 * { 'a': { 'b': { 'c': 2 } } },
20943 * { 'a': { 'b': { 'c': 1 } } }
20944 * ];
20945 *
20946 * _.map(objects, _.property('a.b.c'));
20947 * // => [2, 1]
20948 *
20949 * _.map(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
20950 * // => [1, 2]
20951 */
20952 function property(path) {
20953 return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
20954 }
20955
20956 module.exports = property;
20957
20958
20959/***/ },
20960/* 102 */
20961/***/ function(module, exports, __webpack_require__) {
20962
20963 var baseToPairs = __webpack_require__(61),
20964 keys = __webpack_require__(14);
20965
20966 /**
20967 * Creates an array of own enumerable key-value pairs for `object`.
20968 *
20969 * @static
20970 * @memberOf _
20971 * @category Object
20972 * @param {Object} object The object to query.
20973 * @returns {Array} Returns the new array of key-value pairs.
20974 * @example
20975 *
20976 * function Foo() {
20977 * this.a = 1;
20978 * this.b = 2;
20979 * }
20980 *
20981 * Foo.prototype.c = 3;
20982 *
20983 * _.toPairs(new Foo);
20984 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
20985 */
20986 function toPairs(object) {
20987 return baseToPairs(object, keys(object));
20988 }
20989
20990 module.exports = toPairs;
20991
20992
20993/***/ },
20994/* 103 */
20995/***/ function(module, exports, __webpack_require__) {
20996
20997 var Symbol = __webpack_require__(17),
20998 isSymbol = __webpack_require__(97);
20999
21000 /** Used as references for various `Number` constants. */
21001 var INFINITY = 1 / 0;
21002
21003 /** Used to convert symbols to primitives and strings. */
21004 var symbolProto = Symbol ? Symbol.prototype : undefined,
21005 symbolToString = Symbol ? symbolProto.toString : undefined;
21006
21007 /**
21008 * Converts `value` to a string if it's not one. An empty string is returned
21009 * for `null` and `undefined` values. The sign of `-0` is preserved.
21010 *
21011 * @static
21012 * @memberOf _
21013 * @category Lang
21014 * @param {*} value The value to process.
21015 * @returns {string} Returns the string.
21016 * @example
21017 *
21018 * _.toString(null);
21019 * // => ''
21020 *
21021 * _.toString(-0);
21022 * // => '-0'
21023 *
21024 * _.toString([1, 2, 3]);
21025 * // => '1,2,3'
21026 */
21027 function toString(value) {
21028 // Exit early for strings to avoid a performance hit in some environments.
21029 if (typeof value == 'string') {
21030 return value;
21031 }
21032 if (value == null) {
21033 return '';
21034 }
21035 if (isSymbol(value)) {
21036 return Symbol ? symbolToString.call(value) : '';
21037 }
21038 var result = (value + '');
21039 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
21040 }
21041
21042 module.exports = toString;
21043
21044
21045/***/ },
21046/* 104 */
21047/***/ function(module, exports, __webpack_require__) {
21048
21049 'use strict';
21050
21051 exports.__esModule = true;
21052 exports.default = map2tree;
21053
21054 var _isArray = __webpack_require__(1);
21055
21056 var _isArray2 = _interopRequireDefault(_isArray);
21057
21058 var _isPlainObject = __webpack_require__(96);
21059
21060 var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
21061
21062 var _mapValues = __webpack_require__(100);
21063
21064 var _mapValues2 = _interopRequireDefault(_mapValues);
21065
21066 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21067
21068 function visit(parent, visitFn, childrenFn) {
21069 if (!parent) return;
21070
21071 visitFn(parent);
21072
21073 var children = childrenFn(parent);
21074 if (children) {
21075 var count = children.length;
21076 for (var i = 0; i < count; i++) {
21077 visit(children[i], visitFn, childrenFn);
21078 }
21079 }
21080 }
21081
21082 function getNode(tree, key) {
21083 var node = null;
21084
21085 visit(tree, function (d) {
21086 if (d.name === key) {
21087 node = d;
21088 }
21089 }, function (d) {
21090 return d.children;
21091 });
21092
21093 return node;
21094 }
21095
21096 function map2tree(root) {
21097 var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
21098 var tree = arguments.length <= 2 || arguments[2] === undefined ? { name: options.key || 'state', children: [] } : arguments[2];
21099
21100 if (!(0, _isPlainObject2.default)(root) && root && !root.toJS) {
21101 return {};
21102 }
21103
21104 var _options$key = options.key;
21105 var rootNodeKey = _options$key === undefined ? 'state' : _options$key;
21106 var _options$pushMethod = options.pushMethod;
21107 var pushMethod = _options$pushMethod === undefined ? 'push' : _options$pushMethod;
21108
21109 var currentNode = getNode(tree, rootNodeKey);
21110
21111 if (currentNode === null) {
21112 return {};
21113 }
21114
21115 (0, _mapValues2.default)(root && root.toJS ? root.toJS() : root, function (maybeImmutable, key) {
21116 var value = maybeImmutable && maybeImmutable.toJS ? maybeImmutable.toJS() : maybeImmutable;
21117 var newNode = { name: key };
21118
21119 if ((0, _isArray2.default)(value)) {
21120 newNode.children = [];
21121
21122 for (var i = 0; i < value.length; i++) {
21123 var _newNode$children$pus;
21124
21125 newNode.children[pushMethod]((_newNode$children$pus = {
21126 name: key + '[' + i + ']'
21127 }, _newNode$children$pus[(0, _isPlainObject2.default)(value[i]) ? 'object' : 'value'] = value[i], _newNode$children$pus));
21128 }
21129 } else if ((0, _isPlainObject2.default)(value)) {
21130 newNode.children = [];
21131 } else {
21132 newNode.value = value;
21133 }
21134
21135 currentNode.children[pushMethod](newNode);
21136
21137 map2tree(value, { key: key, pushMethod: pushMethod }, tree);
21138 });
21139
21140 return tree;
21141 }
21142
21143/***/ },
21144/* 105 */
21145/***/ function(module, exports) {
21146
21147 module.exports = function(module) {
21148 if(!module.webpackPolyfill) {
21149 module.deprecate = function() {};
21150 module.paths = [];
21151 // module.parent = undefined by default
21152 module.children = [];
21153 module.webpackPolyfill = 1;
21154 }
21155 return module;
21156 }
21157
21158
21159/***/ }
21160/******/ ])
21161});
21162;
\No newline at end of file